예제 #1
0
bool GalleryFilter::TestFilter(const QString& dir, const GalleryFilter& flt,
                               int *dirCount, int *imageCount, int *movieCount)
{
    QStringList splitFD;
    const QFileInfo *fi;

    QDir d(dir);
    QString currDir = d.absolutePath();
    QFileInfoList list = d.entryInfoList(GalleryUtil::GetMediaFilter(),
                                         QDir::Files | QDir::AllDirs |
                                         QDir::NoDotAndDotDot,
                                         (QDir::SortFlag)flt.getSort());

    if (list.isEmpty())
        return false;

    if (!flt.getDirFilter().isEmpty())
        splitFD = flt.getDirFilter().split(":");

    for (QFileInfoList::const_iterator it = list.begin();
         it != list.end(); ++it)
    {
        fi = &(*it);

        // remove these already-resized pictures.
        if ((fi->fileName().indexOf(".thumb.") > 0) ||
            (fi->fileName().indexOf(".sized.") > 0) ||
            (fi->fileName().indexOf(".highlight.") > 0))
            continue;

        // skip filtered directory
        if (fi->isDir())
        {
            if (!splitFD.filter(fi->fileName(), Qt::CaseInsensitive).isEmpty())
                continue;

            // add directory
            (*dirCount)++;
            GalleryFilter::TestFilter(QDir::cleanPath(fi->absoluteFilePath()),
                                      flt, dirCount, imageCount, movieCount);
        }
        else
        {
            if (GalleryUtil::IsImage(fi->absoluteFilePath()) &&
                flt.getTypeFilter() != kTypeFilterMoviesOnly)
                (*imageCount)++;
            else if (GalleryUtil::IsMovie(fi->absoluteFilePath()) &&
                     flt.getTypeFilter() != kTypeFilterImagesOnly)
                (*movieCount)++;
        }
    }

    return true;
}
예제 #2
0
bool GalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir,
                                const GalleryFilter& flt, bool recurse,
                                ThumbHash *itemHash, ThumbGenerator* thumbGen)
{
    QString blah = dir;
    QDir d(blah);
    QString currDir = d.absolutePath();
    QStringList splitFD;

    bool isGallery;
    QFileInfoList gList = d.entryInfoList(QStringList("serial*.dat"),
                                          QDir::Files);
    isGallery = (gList.count() != 0);

    // Create .thumbcache dir if neccesary
    if (thumbGen)
        thumbGen->getThumbcacheDir(currDir);

    QFileInfoList list = d.entryInfoList(GetMediaFilter(),
                                         QDir::Files | QDir::AllDirs |
                                         QDir::NoDotAndDotDot,
                                         (QDir::SortFlag)flt.getSort());

    if (list.isEmpty())
        return false;

    QFileInfoList::const_iterator it = list.begin();
    const QFileInfo *fi;

    if (thumbGen)
    {
        thumbGen->cancel();
        thumbGen->setDirectory(currDir, isGallery);
    }

    if (!flt.getDirFilter().isEmpty())
    {
        splitFD = flt.getDirFilter().split(":");
    }

    while (it != list.end())
    {
        fi = &(*it);
        ++it;

        // remove these already-resized pictures.
        if (isGallery && (
                (fi->fileName().indexOf(".thumb.") > 0) ||
                (fi->fileName().indexOf(".sized.") > 0) ||
                (fi->fileName().indexOf(".highlight.") > 0)))
            continue;

        // skip filtered directory
        if (fi->isDir() &&
             !splitFD.filter(fi->fileName(), Qt::CaseInsensitive).isEmpty())
            continue;

        if (fi->isDir() && recurse)
        {
            LoadDirectory(itemList, QDir::cleanPath(fi->absoluteFilePath()),
                          flt, true, itemHash, thumbGen);
        }
        else
        {
            if ((GalleryUtil::IsImage(fi->absoluteFilePath()) &&
                 flt.getTypeFilter() == kTypeFilterMoviesOnly) ||
                (GalleryUtil::IsMovie(fi->absoluteFilePath()) &&
                 flt.getTypeFilter() == kTypeFilterImagesOnly))
                continue;

            ThumbItem *item = new ThumbItem(fi->fileName(),
                QDir::cleanPath(fi->absoluteFilePath()), fi->isDir());

            itemList.append(item);

            if (itemHash)
                itemHash->insert(item->GetName(), item);

            if (thumbGen)
                thumbGen->addFile(item->GetName());
        }
    }

    return isGallery;
}