filemanager/src/filemanager/src/components/fmdrivedetailstype.cpp
branchRCL_3
changeset 21 65326cf895ed
parent 20 491b3ed49290
child 22 f5c50b8af68c
equal deleted inserted replaced
20:491b3ed49290 21:65326cf895ed
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  * 
       
    12  * Contributors:
       
    13  *     
       
    14  * 
       
    15  * Description:
       
    16  *      The source file of the drive details type
       
    17  */
       
    18 
       
    19 #include "fmdrivedetailstype.h"
       
    20 #include "fmfiletyperecognizer.h"
       
    21 #include "fmutils.h"
       
    22 
       
    23 #include <QDir>
       
    24 #include <QFileInfo>
       
    25 #include <QStringList>
       
    26 
       
    27 int FmDriveDetailsContent::querySizeofContent( const QString &driveName,
       
    28         QList<FmDriveDetailsSize*> &detailsSizeList, volatile bool *isStopped )
       
    29 {      
       
    30     int err = FmErrNone;
       
    31     detailsSizeList.clear();
       
    32     err = getDataSizeByTraversePath( driveName, detailsSizeList, isStopped );
       
    33     if( err != FmErrNone ) {
       
    34         return err;
       
    35     }
       
    36     
       
    37     QStringList dataPathList;
       
    38     dataPathList.append( QString( FmViewDetail_Contacts ) );    
       
    39     FmDriveDetailsDataGroup driveDetailsDataGroup( FmDriveDetailsSize::ETypeContacts, dataPathList );
       
    40     
       
    41     err = getDataSizeByAbsolutePath(driveName, driveDetailsDataGroup, detailsSizeList, isStopped);
       
    42     if( err != FmErrNone ) {
       
    43         return err;
       
    44     }
       
    45     
       
    46     return FmErrNone;
       
    47 }
       
    48 int FmDriveDetailsContent::getDataSizeByTraversePath( const QString &driveName,
       
    49             QList<FmDriveDetailsSize*> &detailsSizeList, volatile bool *isStopped )
       
    50 {
       
    51     qint64 imageSize( 0 );
       
    52     qint64 soundSize( 0 );
       
    53     qint64 midpJavaSize( 0 );
       
    54     qint64 nativeAppsSize( 0 );
       
    55     qint64 videoSize( 0 );
       
    56     qint64 documentsSize( 0 );
       
    57    
       
    58     FmFileTypeRecognizer fileTypeRecognizer;
       
    59     
       
    60     QList<QDir> dirs;
       
    61     dirs.append( QDir( driveName ) );
       
    62     
       
    63     // traverse the whole drive
       
    64     while (!dirs.isEmpty()) {
       
    65         QDir::Filters filter = QDir::NoDotAndDotDot | QDir::AllEntries;
       
    66         // do not summarize system and hidden files, these size will go into others category
       
    67         // if( isSysHiddenIncluded ) {
       
    68         // filter = filter | QDir::Hidden | QDir::System;
       
    69         // }
       
    70 
       
    71         QFileInfoList infoList = dirs.first().entryInfoList( filter );
       
    72         for ( QFileInfoList::const_iterator it = infoList.begin(); it != infoList.end(); ++it ) {
       
    73             if ( *isStopped ){
       
    74                 return FmErrCancel;
       
    75             }
       
    76             
       
    77             if ( it->isFile() ) {
       
    78             FmFileTypeRecognizer::FileType fileType = 
       
    79                     fileTypeRecognizer.getType( it->absoluteFilePath() );
       
    80             switch ( fileType )
       
    81                 {
       
    82                 case FmFileTypeRecognizer::FileTypeImage:
       
    83                     imageSize += it->size();
       
    84                     break;
       
    85                 case FmFileTypeRecognizer::FileTypeTone:
       
    86                     soundSize += it->size();
       
    87                     break;
       
    88                 case FmFileTypeRecognizer::FileTypeJava:
       
    89                     midpJavaSize += it->size();
       
    90                     break;
       
    91                 case FmFileTypeRecognizer::FileTypeSisx:
       
    92                     nativeAppsSize += it->size();
       
    93                     break;
       
    94                 case FmFileTypeRecognizer::FileTypeVideo:
       
    95                     videoSize += it->size();
       
    96                     break;
       
    97                 case FmFileTypeRecognizer::FileTypeText:
       
    98                     documentsSize += it->size();
       
    99                     break;
       
   100                 default:
       
   101                     // do not need handle other type 
       
   102                     break;
       
   103                 }
       
   104             }
       
   105             else if ( it->isDir() ) {
       
   106                 dirs.append( QDir( it->absoluteFilePath() ) );
       
   107             } 
       
   108         }
       
   109         dirs.removeFirst();
       
   110     }
       
   111        
       
   112     // store result to detailsSizeList.
       
   113     detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeImages, imageSize ) ) ;
       
   114     detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeSoundFiles, soundSize ) );
       
   115     detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeMidpJava, midpJavaSize ) );
       
   116     detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeNativeApps, nativeAppsSize ) );
       
   117     detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeVideos, videoSize ) );
       
   118     detailsSizeList.append( new FmDriveDetailsSize( FmDriveDetailsSize::ETypeDocuments, documentsSize ) );
       
   119     return FmErrNone;
       
   120 }
       
   121 
       
   122 int FmDriveDetailsContent::getDataSizeByAbsolutePath( const QString &driveName,
       
   123         const FmDriveDetailsDataGroup &dataGroup,
       
   124             QList<FmDriveDetailsSize*> &detailsSizeList, volatile bool *isStopped )
       
   125 {
       
   126     quint64 totalSize = 0;
       
   127     QStringList typeFilter = dataGroup.pathList();
       
   128     
       
   129     for( QStringList::const_iterator it = typeFilter.begin(); 
       
   130            it!= typeFilter.end(); ++it ) {
       
   131         if ( *isStopped ){
       
   132             return FmErrCancel;
       
   133         }        
       
   134         QString driver(FmUtils::removePathSplash(FmUtils::getDriveNameFromPath(driveName)));
       
   135         QFileInfo fileInfo(QString(driver + (*it)));
       
   136         if (fileInfo.exists()) {
       
   137             totalSize += fileInfo.size();
       
   138         }
       
   139     }
       
   140  
       
   141     detailsSizeList.append( new FmDriveDetailsSize( dataGroup.dataType(), totalSize ) );
       
   142     return FmErrNone;
       
   143 }
       
   144 
       
   145 int FmFolderDetails::queryDetailOfContentList( const QStringList folderPathList,int &numofFolders, 
       
   146                                     int &numofFiles, quint64 &totalSize,
       
   147                                     volatile bool *isStopped, bool isSysHiddenIncluded )
       
   148 {
       
   149     numofFolders = 0;
       
   150     numofFiles = 0;
       
   151     totalSize = 0;
       
   152 
       
   153     int tempNumofFolders = 0;
       
   154     int tempNumofFiles = 0;
       
   155     quint64 tempSize = 0;
       
   156 
       
   157     int ret = FmErrNone;
       
   158 
       
   159     foreach( const QString& folderPath, folderPathList ) {
       
   160         QFileInfo fileInfo( folderPath );
       
   161         if( fileInfo.isDir() ){
       
   162             int tempNumofSubFolders = 0;
       
   163             ret = getNumofSubfolders( folderPath, tempNumofSubFolders,
       
   164                 tempNumofFiles, tempSize, isStopped, isSysHiddenIncluded );
       
   165             tempNumofFolders = tempNumofSubFolders + 1; // add itself to folder count;
       
   166         } else if( fileInfo.isFile() ) {
       
   167             tempNumofFiles = 1;
       
   168             tempSize = fileInfo.size();
       
   169             ret = FmErrNone;
       
   170         } else {
       
   171             ret = FmErrIsNotFileOrFolder;
       
   172         }
       
   173         if( ret != FmErrNone ) {
       
   174             return ret;
       
   175         }
       
   176         numofFolders+= tempNumofFolders;
       
   177         numofFiles  += tempNumofFiles;
       
   178         totalSize   += tempSize;
       
   179 
       
   180         tempNumofFolders = 0;
       
   181         tempNumofFiles      = 0;
       
   182         tempSize    = 0;
       
   183     }
       
   184 
       
   185     return ret;
       
   186 }
       
   187 
       
   188 int FmFolderDetails::getNumofSubfolders( const QString &folderPath, int &numofSubFolders, 
       
   189                                           int &numofFiles, quint64 &sizeofFolder,
       
   190                                           volatile bool *isStopped, bool isSysHiddenIncluded )
       
   191 {
       
   192     numofSubFolders = 0;
       
   193     numofFiles = 0;
       
   194     sizeofFolder = 0;
       
   195 
       
   196     QList<QDir> dirs;
       
   197     dirs.append( QDir( folderPath ) );
       
   198     
       
   199     while (!dirs.isEmpty()) {
       
   200         QDir::Filters filter = QDir::NoDotAndDotDot | QDir::AllEntries;
       
   201         if( isSysHiddenIncluded ) {
       
   202             filter = filter | QDir::Hidden | QDir::System;
       
   203         }
       
   204 
       
   205         QFileInfoList infoList = dirs.first().entryInfoList( filter );
       
   206         for ( QFileInfoList::const_iterator it = infoList.begin(); it != infoList.end(); ++it ) {
       
   207             if ( *isStopped ){
       
   208                 return FmErrCancel;
       
   209             }
       
   210             
       
   211             if ( it->isFile() ) {
       
   212                 ++numofFiles;
       
   213                 sizeofFolder += it->size();
       
   214             }
       
   215             else if ( it->isDir() ) {
       
   216                 ++numofSubFolders;
       
   217                 dirs.append( QDir( it->absoluteFilePath() ) );
       
   218             } 
       
   219         }
       
   220         
       
   221         dirs.removeFirst();
       
   222     }
       
   223     
       
   224     return FmErrNone;
       
   225 }