예제 #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
//*******************************************************************
// read_dir                                                  PRIVATE
//-------------------------------------------------------------------
// Rekursywne odczytywanie calej zawartosci wskazanego katalogu.
// Odczytana zawrtosc katalogu jest zapamietywania w hash-tablicy.
//*******************************************************************
void QBtCompareDirsDialog::read_dir( const QString& in_parent,
                                     const QString& in_dir,
                                     DirMap& out_data ) const
{
   static const int sflag = QDir::AllDirs
                          | QDir::Files
                          | QDir::NoDotAndDotDot
                          | QDir::Readable
                          | QDir::Writable
                          | QDir::Hidden;
                   
   const QDir dir( in_dir, "*", QDir::Unsorted, QFlags<QDir::Filter>( sflag ) );
   const QFileInfoList items = dir.entryInfoList();

   FileMap files_map = FileMap();
   QFileInfoList::const_iterator it = items.begin();
   const QFileInfoList::const_iterator end = items.end();
   while( continue_ && ( it != end ) ) {
      if( it->isDir() ) read_dir( in_parent, it->absoluteFilePath(), out_data );
      else              files_map.insert( it->fileName(), *it );
      ++it;
   }
   QString path = in_dir;
   out_data.insert( path.remove( in_parent ), files_map );
}
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;
}