コード例 #1
0
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;
}
コード例 #2
0
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;
}