15 * Description: |
15 * Description: |
16 * The source file of the drive details type |
16 * The source file of the drive details type |
17 */ |
17 */ |
18 |
18 |
19 #include "fmdrivedetailstype.h" |
19 #include "fmdrivedetailstype.h" |
|
20 #include "fmfiletyperecognizer.h" |
20 #include "fmutils.h" |
21 #include "fmutils.h" |
21 |
22 |
22 #include <QDir> |
23 #include <QDir> |
23 #include <QFileInfo> |
24 #include <QFileInfo> |
24 #include <QStringList> |
25 #include <QStringList> |
25 |
26 |
26 QList<FmDriveDetailsDataGroup*> FmDriveDetailsContent::queryDetailsContent() |
|
27 { |
|
28 QStringList typeFilters; |
|
29 QList< FmDriveDetailsDataGroup* > dataGroupList; |
|
30 typeFilters.append( QString( "*.bmp" ) ); |
|
31 typeFilters.append( QString( "*.gif" ) ); |
|
32 typeFilters.append( QString( "*.jpe" ) ); |
|
33 typeFilters.append( QString( "*.jpeg" ) ); |
|
34 typeFilters.append( QString( "*.jpg" ) ); |
|
35 typeFilters.append( QString( "*.ota" ) ); |
|
36 typeFilters.append( QString( "*.png" ) ); |
|
37 typeFilters.append( QString( "*.tif" ) ); |
|
38 typeFilters.append( QString( "*.tiff" ) ); |
|
39 typeFilters.append( QString( "*.wbmp" ) ); |
|
40 typeFilters.append( QString( "*.wmf" ) ); |
|
41 typeFilters.append( QString( "*.jp2" ) ); |
|
42 typeFilters.append( QString( "*.jpg2" ) ); |
|
43 typeFilters.append( QString( "*.jp3" ) ); |
|
44 typeFilters.append( QString( "*.ico" ) ); |
|
45 typeFilters.append( QString( "*.vcf" ) ); |
|
46 |
|
47 dataGroupList.append( new FmDriveDetailsDataGroup( FmDriveDetailsDataGroup::EGroupImages, typeFilters )); |
|
48 |
|
49 typeFilters.clear(); |
|
50 typeFilters.append( QString( "*.aac" ) ); |
|
51 typeFilters.append( QString( "*.amr" ) ); |
|
52 typeFilters.append( QString( "*.au" ) ); |
|
53 typeFilters.append( QString( "*.awb" ) ); |
|
54 typeFilters.append( QString( "*.mid" ) ); |
|
55 typeFilters.append( QString( "*.mp3" ) ); |
|
56 typeFilters.append( QString( "*.ra" ) ); |
|
57 typeFilters.append( QString( "*.rmf" ) ); |
|
58 typeFilters.append( QString( "*.rng" ) ); |
|
59 typeFilters.append( QString( "*.snd" ) ); |
|
60 typeFilters.append( QString( "*.wav" ) ); |
|
61 typeFilters.append( QString( "*.wve" ) ); |
|
62 typeFilters.append( QString( "*.wma" ) ); |
|
63 typeFilters.append( QString( "*.m4a" ) ); |
|
64 typeFilters.append( QString( "*.ott" ) ); |
|
65 typeFilters.append( QString( "*.mxmf" ) ); |
|
66 |
|
67 dataGroupList.append( new FmDriveDetailsDataGroup( FmDriveDetailsDataGroup::EGroupSoundFiles, typeFilters )); |
|
68 |
|
69 typeFilters.clear(); |
|
70 typeFilters.append( QString( "*.jad" ) ); |
|
71 typeFilters.append( QString( "*.jar" ) ); |
|
72 |
|
73 dataGroupList.append( new FmDriveDetailsDataGroup( FmDriveDetailsDataGroup::EGroupMidpJava, typeFilters )); |
|
74 |
|
75 typeFilters.clear(); |
|
76 typeFilters.append( QString( "*.sis" ) ); |
|
77 typeFilters.append( QString( "*.sisx" ) ); |
|
78 |
|
79 dataGroupList.append( new FmDriveDetailsDataGroup( FmDriveDetailsDataGroup::EGroupNativeApps, typeFilters )); |
|
80 |
|
81 typeFilters.clear(); |
|
82 typeFilters.append( QString( "*.3gp" ) ); |
|
83 typeFilters.append( QString( "*.mp4" ) ); |
|
84 typeFilters.append( QString( "*.nim" ) ); |
|
85 typeFilters.append( QString( "*.rm" ) ); |
|
86 typeFilters.append( QString( "*.rv" ) ); |
|
87 typeFilters.append( QString( "*.wmv" ) ); |
|
88 typeFilters.append( QString( "*.3g2" ) ); |
|
89 |
|
90 dataGroupList.append( new FmDriveDetailsDataGroup( FmDriveDetailsDataGroup::EGroupVideos, typeFilters )); |
|
91 |
|
92 typeFilters.clear(); |
|
93 typeFilters.append( QString( "*.doc" ) ); |
|
94 typeFilters.append( QString( "*.pdf" ) ); |
|
95 typeFilters.append( QString( "*.pps" ) ); |
|
96 typeFilters.append( QString( "*.ppt" ) ); |
|
97 typeFilters.append( QString( "*.txt" ) ); |
|
98 typeFilters.append( QString( "*.xls" ) ); |
|
99 |
|
100 dataGroupList.append( new FmDriveDetailsDataGroup( FmDriveDetailsDataGroup::EGroupDocuments, typeFilters )); |
|
101 |
|
102 typeFilters.clear(); |
|
103 typeFilters.append( QString( "*.vcs" ) ); |
|
104 |
|
105 dataGroupList.append( new FmDriveDetailsDataGroup( FmDriveDetailsDataGroup::EGroupCalendar, typeFilters )); |
|
106 |
|
107 return dataGroupList; |
|
108 |
|
109 } |
|
110 |
|
111 int FmDriveDetailsContent::querySizeofContent( const QString &driveName, |
27 int FmDriveDetailsContent::querySizeofContent( const QString &driveName, |
112 QList<FmDriveDetailsSize*> &detailsSizeList, volatile bool *isStopped ) |
28 QList<FmDriveDetailsSize*> &detailsSizeList, volatile bool *isStopped ) |
113 { |
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 { |
114 quint64 totalSize = 0; |
126 quint64 totalSize = 0; |
115 |
127 QStringList typeFilter = dataGroup.pathList(); |
116 QString path; |
128 |
117 path.clear(); |
129 for( QStringList::const_iterator it = typeFilter.begin(); |
118 |
130 it!= typeFilter.end(); ++it ) { |
119 if( FmUtils::isDriveC( driveName )){ |
|
120 path = QString( "c:\\Data\\" ); |
|
121 } |
|
122 else{ |
|
123 path = driveName; |
|
124 } |
|
125 |
|
126 QList< FmDriveDetailsDataGroup* > dataGroupList = queryDetailsContent(); |
|
127 |
|
128 QStringList typeFilter; |
|
129 detailsSizeList.clear(); |
|
130 QDir dir( path ); |
|
131 |
|
132 for( QList< FmDriveDetailsDataGroup* >::iterator it = dataGroupList.begin(); |
|
133 it!= dataGroupList.end(); ++it ){ |
|
134 if ( *isStopped ){ |
131 if ( *isStopped ){ |
135 return FmErrCancel; |
132 return FmErrCancel; |
136 } |
133 } |
137 totalSize = 0; |
134 QString driver(FmUtils::removePathSplash(FmUtils::getDriveNameFromPath(driveName))); |
138 typeFilter = ( *it )->typeFilters(); |
135 QFileInfo fileInfo(QString(driver + (*it))); |
139 |
136 if (fileInfo.exists()) { |
140 QList<QDir> dirs; |
137 totalSize += fileInfo.size(); |
141 dirs.append( QDir( path ) ); |
138 } |
142 |
139 } |
143 while (!dirs.isEmpty()) { |
140 |
144 QFileInfoList infoList = dirs.first().entryInfoList( QDir::NoDotAndDotDot | QDir::AllEntries ); |
141 detailsSizeList.append( new FmDriveDetailsSize( dataGroup.dataType(), totalSize ) ); |
145 QFileInfoList filterInforList = dirs.first().entryInfoList( typeFilter, QDir::NoDotAndDotDot | QDir::Files ); |
|
146 |
|
147 for ( QFileInfoList::Iterator it = filterInforList.begin(); it != filterInforList.end(); ++it ) { |
|
148 if ( *isStopped ){ |
|
149 return FmErrCancel; |
|
150 } |
|
151 |
|
152 if ( it->isFile() ) { |
|
153 totalSize += it->size(); |
|
154 } |
|
155 } |
|
156 |
|
157 for ( QFileInfoList::Iterator it = infoList.begin(); it != infoList.end(); ++it ) { |
|
158 if ( *isStopped ){ |
|
159 return FmErrCancel; |
|
160 } |
|
161 |
|
162 if ( it->isDir() ) { |
|
163 dirs.append( QDir( it->absoluteFilePath() ) ); |
|
164 } |
|
165 } |
|
166 |
|
167 dirs.removeFirst(); |
|
168 } |
|
169 |
|
170 detailsSizeList.append( new FmDriveDetailsSize( ( *it )->dataGroups(), totalSize ) ); |
|
171 } |
|
172 return FmErrNone; |
142 return FmErrNone; |
173 } |
143 } |
174 |
144 |
175 int FmFolderDetails::queryDetailOfContentList( const QStringList folderPathList,int &numofFolders, |
145 int FmFolderDetails::queryDetailOfContentList( const QStringList folderPathList,int &numofFolders, |
176 int &numofFiles, quint64 &totalSize, |
146 int &numofFiles, quint64 &totalSize, |