void djvFileBrowserModel::dirUpdate()
{
    //DJV_DEBUG("djvFileBrowserModel::dirUpdate");
    //DJV_DEBUG_PRINT("path = " << _p->path);

    // Get directory contents.

    _p->list = djvFileInfoUtil::list(_p->path, _p->sequence);

    // Add parent directory.

    if (djvFileInfo(_p->path).exists())
    {
        _p->list.push_front(djvFileInfo(_p->path + ".."));
    }
    
    //DJV_DEBUG_PRINT("list = " << _p->list.count());
    //Q_FOREACH(const djvFileInfo & fileInfo, _p->list)
    //    DJV_DEBUG_PRINT("fileInfo = " << fileInfo << " " << fileInfo.type());
}
djvFileInfo djvFileBrowserModel::fileInfo(const QModelIndex & index) const
{
    //DJV_DEBUG("djvFileBrowserModel::fileInfo");
    //DJV_DEBUG_PRINT("index = " << index.isValid());
    
    djvFileInfo * fileInfo = 0;
    
    if (index.isValid())
        fileInfo = (djvFileInfo *)index.internalPointer();
    
    return fileInfo ? *fileInfo : djvFileInfo();
}
Beispiel #3
0
djvFileInfoList djvFileInfoUtil::list(
    const QString &       path,
    djvSequence::COMPRESS compress)
{
    //DJV_DEBUG("djvFileInfoUtil::list");
    //DJV_DEBUG_PRINT("path = " << path);
    //DJV_DEBUG_PRINT("compress = " << compress);
    
    djvFileInfoList out;

    djvFileInfo * cache = 0;

    QString fixedPath = fixPath(path);

#if defined(DJV_WINDOWS)

    WIN32_FIND_DATA data;

    HANDLE h = FindFirstFileEx(
        QString(fixedPath + "*").toLatin1().data(),
        FindExInfoBasic,
        &data,
        FindExSearchNameMatch,
        NULL,
        FIND_FIRST_EX_LARGE_FETCH);

    if (h != INVALID_HANDLE_VALUE)
    {
        const char * p = data.cFileName;
        size_t l = strlen(p);

        if (! isDotDir(p, l))
        {
            out.append(djvFileInfo(fixedPath + QString(p)));
        }

        while (FindNextFile(h, &data))
        {
            p = data.cFileName;
            l = strlen(p);

            if (! isDotDir(p, l))
            {
                if (! out.count())
                {
                    out.append(djvFileInfo(fixedPath + QString(p)));
                }
                else
                {
                    const djvFileInfo tmp(fixedPath + QString(p));

                    int i = 0;

                    if (compress && cache)
                    {
                        if (! cache->addSequence(tmp))
                        {
                            cache = 0;
                        }
                    }

                    if (compress && ! cache)
                    {
                        for (; i < out.count(); ++i)
                        {
                            if (out[i].addSequence(tmp))
                            {
                                cache = &out[i];

                                break;
                            }
                        }
                    }

                    if (! compress || i == out.count())
                    {
                        out.append(tmp);
                    }
                }
            }
        }

        FindClose(h);
    }

/*#elif defined(DJV_LINUX)

    struct linux_dirent64
    {
       ino64_t        d_ino;
       off64_t        d_off;
       unsigned short d_reclen;
       unsigned char  d_type;
       char           d_name[];
    };

    int fd = open(path.toLatin1().data(), O_RDONLY | O_DIRECTORY);
        
    if (fd != -1)
    {
        djvMemoryBuffer<quint8> buf(djvMemory::megabyte);

        quint8 * p = buf.data();

        while (1)
        {
            int readCount = syscall(SYS_getdents64, fd, p, buf.size());
                                    
            if (-1 == readCount)
                break;

            if (0 == readCount)
                break;
            
            for (int i = 0; i < readCount;)
            {
                struct linux_dirent64 * de = (struct linux_dirent64 *)(p + i);
                
                if (de->d_ino != DT_UNKNOWN)
                {
                    size_t l = strlen(de->d_name);

                    if (! isDotDir(de->d_name, l))
                    {
                        if (! out.count())
                        {
                            out.append(djvFileInfo(fixedPath + de->d_name));
                        }
                        else
                        {
                            const djvFileInfo tmp(fixedPath + de->d_name);

                            int i = 0;

                            if (compress && cache)
                            {
                                if (! cache->addSequence(tmp))
                                {
                                    cache = 0;
                                }
                            }

                            if (compress && ! cache)
                            {
                                for (; i < out.count(); ++i)
                                {
                                    if (out[i].addSequence(tmp))
                                    {
                                        cache = &out[i];

                                        break;
                                    }
                                }
                            }

                            if (! compress || i == out.count())
                            {
                                out.append(tmp);
                            }
                        }
                    }
                }
                
                i += de->d_reclen;
            }
        }
        
        close (fd);
    }

*/
#else // DJV_WINDOWS

    DIR * dir = opendir(path.toLatin1().data());
    
    if (dir)
    {
        struct dirent * de = 0;
        
        while ((de = readdir(dir)) != 0)
        {
            const char * p = de->d_name;
            const int l = strlen(p);
            
            if (! isDotDir(p, l))
            {
                if (! out.count())
                {
                    out.append(djvFileInfo(fixedPath + QString(p)));
                }
                else
                {
                    const djvFileInfo tmp(fixedPath + QString(p));

                    int i = 0;

                    if (compress && cache)
                    {
                        if (! cache->addSequence(tmp))
                        {
                            cache = 0;
                        }
                    }

                    if (compress && ! cache)
                    {
                        for (; i < out.count(); ++i)
                        {
                            if (out[i].addSequence(tmp))
                            {
                                cache = &out[i];

                                break;
                            }
                        }
                    }

                    if (! compress || i == out.count())
                    {
                        out.append(tmp);
                    }
                }
            }
        }
    
        closedir(dir);
    }
    
#endif // DJV_WINDOWS
        
    for (int i = 0; i < out.count(); ++i)
    {
        out[i]._sequence.sort();
    }

    if (djvSequence::COMPRESS_RANGE == compress)
    {
        for (int i = 0; i < out.count(); ++i)
        {
            if (out[i]._sequence.frames.count())
            {
                out[i]._sequence.setFrames(
                    out[i]._sequence.start(),
                    out[i]._sequence.end());
            }
        }
    }

    for (int i = 0; i < out.count(); ++i)
    {
        if (djvFileInfo::SEQUENCE == out[i].type())
        {
            out[i]._number = djvSequenceUtil::sequenceToString(out[i]._sequence);
        }
    }

    return out;
}