Пример #1
0
QVector<QString> FileUtils::getAllFiles(const QString &path)
{
    QVector<QString> result;
    QDir dir(path);
    QFileInfoList fileInfoLists = dir.entryInfoList();
    QFileInfoList::const_iterator iterator = fileInfoLists.constBegin();

    for(; iterator != fileInfoLists.constEnd(); iterator++)
    {
        QString filename = iterator->fileName();

        if (!filename.startsWith("."))
        {
            if (iterator->isDir())
            {
                result += getAllFiles(iterator->absoluteFilePath());
            }
            else if (iterator->isFile())
            {
                result.push_back(iterator->absoluteFilePath());
            }
            else
            {
                //
            }
        }
    }

    return result;
}
Пример #2
0
void NewFormWidget::loadFrom(const QString &path, bool resourceFile, const QString &uiExtension,
                       const QString &selectedItem, QTreeWidgetItem *&selectedItemFound)
{
    const QDir dir(path);

    if (!dir.exists())
        return;

    // Iterate through the directory and add the templates
    const QFileInfoList list = dir.entryInfoList(QStringList(QLatin1String("*.") + uiExtension),
                                                 QDir::Files);

    if (list.isEmpty())
        return;

    const QChar separator = resourceFile ? QChar(QLatin1Char('/'))
                                         : QDir::separator();
    QTreeWidgetItem *root = new QTreeWidgetItem(m_ui->treeWidget);
    root->setFlags(root->flags() & ~Qt::ItemIsSelectable);
    // Try to get something that is easy to read.
    QString visiblePath = path;
    int index = visiblePath.lastIndexOf(separator);
    if (index != -1) {
        // try to find a second slash, just to be a bit better.
        const int index2 = visiblePath.lastIndexOf(separator, index - 1);
        if (index2 != -1)
            index = index2;
        visiblePath = visiblePath.mid(index + 1);
        visiblePath = QDir::toNativeSeparators(visiblePath);
    }

    const QChar underscore = QLatin1Char('_');
    const QChar blank = QLatin1Char(' ');
    root->setText(0, visiblePath.replace(underscore, blank));
    root->setToolTip(0, path);

    const QFileInfoList::const_iterator lcend = list.constEnd();
    for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it) {
        if (!it->isFile())
            continue;

        QTreeWidgetItem *item = new QTreeWidgetItem(root);
        const QString text = it->baseName().replace(underscore, blank);
        if (selectedItemFound == 0 && text == selectedItem)
            selectedItemFound = item;
        item->setText(0, text);
        item->setData(0, TemplateNameRole, it->absoluteFilePath());
    }
}
int FmDriveDetailsContent::getDataSizeByAbsolutePath( const QString &driveName,
        const FmDriveDetailsDataGroup &dataGroup,
            QList<FmDriveDetailsSize*> &detailsSizeList, volatile bool *isStopped )
{
    quint64 totalSize = 0;
    QStringList typeFilter = dataGroup.pathList();
    
    for( QStringList::const_iterator it = typeFilter.begin(); 
           it!= typeFilter.end(); ++it ) {
        if ( *isStopped ){
            return FmErrCancel;
        }        
        QString driver(FmUtils::removePathSplash(FmUtils::getDriveNameFromPath(driveName)));
        QFileInfo fileInfo(QString(driver + (*it)));
        if (fileInfo.exists()) {
            if (fileInfo.isFile()) {
                totalSize += fileInfo.size();    
            } else if (fileInfo.isDir()) {
                QList<QDir> dirs;
                dirs.append(QDir(fileInfo.absolutePath()));
                // traverse the whole path
                while (!dirs.isEmpty()) {
                    QDir::Filters filter = QDir::NoDotAndDotDot | QDir::AllEntries;
                    QFileInfoList infoList = dirs.first().entryInfoList( filter );
                    for ( QFileInfoList::const_iterator it = infoList.begin(); it != infoList.end(); ++it ) {
                        if ( *isStopped ){
                            return FmErrCancel;
                        }                        
                        if ( it->isFile() ) {
                            totalSize += it->size();  
                        }
                        else if ( it->isDir() ) {
                            dirs.append( QDir( it->absoluteFilePath() ) );
                        } 
                    }
                    dirs.removeFirst();
                }
            }
            
        }
    }
 
    detailsSizeList.append( new FmDriveDetailsSize( dataGroup.dataType(), totalSize ) );
    return FmErrNone;
}
Пример #4
0
QVector<QString> FileUtils::getAllImageFiles(const QString & path)
{
    QVector<QString> result;
    QDir dir(path);
    QFileInfoList fileInfoLists = dir.entryInfoList();
    QFileInfoList::const_iterator iterator = fileInfoLists.constBegin();

    for(; iterator != fileInfoLists.constEnd(); iterator++)
    {
        QString filename = iterator->fileName();

        if (!filename.startsWith("."))
        {
            if (iterator->isDir())
            {
                result += getAllImageFiles(iterator->absoluteFilePath());
            }
            else if (iterator->isFile())
            {
                QString ext = iterator->completeSuffix();
                QString extLower = ext.toLower();
                if (extLower.endsWith("png") ||
                        extLower.endsWith("jpg") ||
                        extLower.endsWith("jpeg"))
                {
                    result.push_back(iterator->absoluteFilePath());
                }
            }
            else
            {
                //
            }
        }
    }

    return result;
}
int FmDriveDetailsContent::getDataSizeByTraversePath( const QString &driveName,
            QList<FmDriveDetailsSize*> &detailsSizeList, volatile bool *isStopped )
{
    qint64 imageSize( 0 );
    qint64 soundSize( 0 );
    qint64 midpJavaSize( 0 );
    qint64 nativeAppsSize( 0 );
    qint64 videoSize( 0 );
    qint64 documentsSize( 0 );
   
    FmFileTypeRecognizer fileTypeRecognizer;
    
    QList<QDir> dirs;
    dirs.append( QDir( driveName ) );
    
    // traverse the whole drive
    while (!dirs.isEmpty()) {
        QDir::Filters filter = QDir::NoDotAndDotDot | QDir::AllEntries;
        // do not summarize system and hidden files, these size will go into others category
        // if( isSysHiddenIncluded ) {
        // filter = filter | QDir::Hidden | QDir::System;
        // }

        QFileInfoList infoList = dirs.first().entryInfoList( filter );
        for ( QFileInfoList::const_iterator it = infoList.begin(); it != infoList.end(); ++it ) {
            if ( *isStopped ){
                return FmErrCancel;
            }
            
            if ( it->isFile() ) {
            FmFileTypeRecognizer::FileType fileType = 
                    fileTypeRecognizer.getType( it->absoluteFilePath() );
            switch ( fileType )
                {
                case FmFileTypeRecognizer::FileTypeImage:
                    imageSize += it->size();
                    break;
                case FmFileTypeRecognizer::FileTypeTone:
                    soundSize += it->size();
                    break;
                case FmFileTypeRecognizer::FileTypeJava:
                    midpJavaSize += it->size();
                    break;
                case FmFileTypeRecognizer::FileTypeSisx:
                    nativeAppsSize += it->size();
                    break;
                case FmFileTypeRecognizer::FileTypeVideo:
                    videoSize += it->size();
                    break;
                case FmFileTypeRecognizer::FileTypeText:
                    documentsSize += it->size();
                    break;
                default:
                    // do not need handle other type 
                    break;
                }
            }
            else if ( it->isDir() ) {
                dirs.append( QDir( it->absoluteFilePath() ) );
            } 
        }
        dirs.removeFirst();
    }
       
    // store result to detailsSizeList.
    detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeImages, imageSize ) ) ;
    detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeSoundFiles, soundSize ) );
    detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeMidpJava, midpJavaSize ) );
    detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeNativeApps, nativeAppsSize ) );
    detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeVideos, videoSize ) );
    detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeDocuments, documentsSize ) );
    return FmErrNone;
}