|
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 * Zhiqiang Yang <zhiqiang.yang@nokia.com> |
|
14 * |
|
15 * Description: |
|
16 * The source file of the file manager utilities on windows |
|
17 */ |
|
18 |
|
19 #include <windows.h> |
|
20 |
|
21 #include "fmutils.h" |
|
22 #include <QDir> |
|
23 #include <QFileInfo> |
|
24 #include <QDesktopServices> |
|
25 #include <QUrl> |
|
26 #include <QVariant> |
|
27 |
|
28 #define BURCONFIGFILE "burconfig.xml" |
|
29 |
|
30 QString FmUtils::getDriveNameFromPath( const QString &path ) |
|
31 { |
|
32 if( path.length() <3 ) { |
|
33 return QString(); |
|
34 } |
|
35 return path.left( 3 ); |
|
36 } |
|
37 |
|
38 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName ) |
|
39 { |
|
40 quint64 size = 0; |
|
41 quint64 freeSize = 0; |
|
42 QString driver = driverName; |
|
43 |
|
44 driver.replace( '/', "\\" ); |
|
45 if ( driver.right(1) != "\\" ) { |
|
46 driver.append( "\\" ); |
|
47 } |
|
48 GetDiskFreeSpaceEx( (LPCWSTR)driver.constData(), |
|
49 (PULARGE_INTEGER)&freeSize, |
|
50 (PULARGE_INTEGER)&size, |
|
51 0 ); |
|
52 |
|
53 TCHAR volumeName[MAX_PATH + 1] = { 0 }; |
|
54 GetVolumeInformation( (LPCWSTR)driver.constData(), |
|
55 &volumeName[0], |
|
56 MAX_PATH + 1, |
|
57 0, |
|
58 0, |
|
59 0, |
|
60 0, |
|
61 0 ); |
|
62 |
|
63 return FmDriverInfo( size, freeSize, driverName, QString::fromWCharArray( &volumeName[0] ) ); |
|
64 } |
|
65 |
|
66 QString FmUtils::formatStorageSize( quint64 size ) |
|
67 { |
|
68 if ( size < 1000 ) { |
|
69 return QString::number( size ) + " B"; |
|
70 } else if ( size < 1000 * 1000 ) { |
|
71 return QString::number( size / 1024.0, 'f', 2 ) + " KB"; |
|
72 } else if ( size < 1000 * 1000 * 1000 ) { |
|
73 return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB"; |
|
74 } else { |
|
75 return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB"; |
|
76 } |
|
77 } |
|
78 |
|
79 quint32 FmUtils::getDriverState( const QString &driverName ) |
|
80 { |
|
81 quint32 state( 0 ); |
|
82 |
|
83 QString driver = driverName; |
|
84 |
|
85 driver.replace( '/', "\\" ); |
|
86 if ( driver.right(1) != "\\" ) { |
|
87 driver.append( "\\" ); |
|
88 } |
|
89 |
|
90 quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() ); |
|
91 |
|
92 if ( drvStatus == DRIVE_REMOVABLE ) { |
|
93 state |= FmDriverInfo::EDriveRemovable; |
|
94 } |
|
95 |
|
96 return state; |
|
97 |
|
98 } |
|
99 |
|
100 int FmUtils::removeDrivePwd( const QString &driverName, const QString &Pwd ) |
|
101 { |
|
102 Q_UNUSED( driverName ); |
|
103 Q_UNUSED( Pwd ); |
|
104 return 0; |
|
105 } |
|
106 |
|
107 int FmUtils::unlockDrive( const QString &driverName, const QString &Pwd ) |
|
108 { |
|
109 Q_UNUSED( driverName ); |
|
110 Q_UNUSED( Pwd ); |
|
111 return 0; |
|
112 } |
|
113 |
|
114 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd) |
|
115 { |
|
116 Q_UNUSED( driverName ); |
|
117 Q_UNUSED( oldPwd ); |
|
118 Q_UNUSED( newPwd ); |
|
119 return 0; |
|
120 } |
|
121 |
|
122 void FmUtils::emptyPwd( QString &pwd ) |
|
123 { |
|
124 Q_UNUSED( pwd ); |
|
125 } |
|
126 |
|
127 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName) |
|
128 { |
|
129 Q_UNUSED( driverName ); |
|
130 Q_UNUSED( newVolumeName ); |
|
131 return 0; |
|
132 } |
|
133 |
|
134 int FmUtils::ejectDrive( const QString &driverName ) |
|
135 { |
|
136 Q_UNUSED( driverName ); |
|
137 return 0; |
|
138 } |
|
139 int FmUtils::formatDrive( const QString &driverName ) |
|
140 { |
|
141 Q_UNUSED( driverName ); |
|
142 return 0; |
|
143 } |
|
144 |
|
145 QString FmUtils::getFileType( const QString &filePath ) |
|
146 { |
|
147 Q_UNUSED( filePath ); |
|
148 return QString( "" ); |
|
149 } |
|
150 |
|
151 quint64 FmUtils::getDriveDetailsResult( const QString &folderPath, const QString &extension ) |
|
152 { |
|
153 Q_UNUSED( folderPath ); |
|
154 Q_UNUSED( extension ); |
|
155 return 0; |
|
156 } |
|
157 |
|
158 bool FmUtils::isDriveC( const QString &driverName ) |
|
159 { |
|
160 Q_UNUSED( driverName ); |
|
161 return false; |
|
162 } |
|
163 |
|
164 void FmUtils::createDefaultFolders( const QString &driverName ) |
|
165 { |
|
166 Q_UNUSED( driverName ); |
|
167 } |
|
168 |
|
169 QString FmUtils::fillPathWithSplash( const QString &filePath ) |
|
170 { |
|
171 QString newFilePath( filePath ); |
|
172 if( filePath.isEmpty() ) { |
|
173 return newFilePath; |
|
174 } |
|
175 |
|
176 if( filePath.at( filePath.length()-1 ) != QChar( '/' ) ){ |
|
177 newFilePath.append( QChar( '/' ) ); |
|
178 } |
|
179 return newFilePath; |
|
180 } |
|
181 |
|
182 QString FmUtils::removePathSplash( const QString &filePath ) |
|
183 { |
|
184 QString newFilePath( filePath ); |
|
185 if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) { |
|
186 newFilePath = filePath.left( filePath.length() - 1 ); |
|
187 } |
|
188 return newFilePath; |
|
189 } |
|
190 |
|
191 bool FmUtils::checkDriveFilter( const QString &driveName ) |
|
192 { |
|
193 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
|
194 if( driveName.contains( "D:" ) || driveName.contains( "Z:" ) ) { |
|
195 return false; |
|
196 } |
|
197 #endif |
|
198 return true; |
|
199 } |
|
200 |
|
201 QString FmUtils::checkDriveToFolderFilter( const QString &path ) |
|
202 { |
|
203 QFileInfo fileInfo( path ); |
|
204 if( !fileInfo.exists() ) { |
|
205 return QString(); |
|
206 } |
|
207 |
|
208 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
|
209 QString checkedPath = fillPathWithSplash( path ); |
|
210 if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) { |
|
211 checkedPath += QString( "data/" ); |
|
212 QFileInfo fileInfo( checkedPath ); |
|
213 if( !fileInfo.exists() ) { |
|
214 return QString(); |
|
215 } |
|
216 return checkedPath; |
|
217 } |
|
218 #endif |
|
219 return path; |
|
220 |
|
221 } |
|
222 |
|
223 QString FmUtils::checkFolderToDriveFilter( const QString &path ) |
|
224 { |
|
225 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
|
226 QString logString; |
|
227 logString = QString( "checkFolderToDriveFilter: " ) + path; |
|
228 FmLogger::log( logString ); |
|
229 QString checkedPath = fillPathWithSplash( path ); |
|
230 |
|
231 logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath; |
|
232 FmLogger::log( logString ); |
|
233 |
|
234 if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) { |
|
235 FmLogger::log( QString( " change from c:/data/ to C:/" ) ); |
|
236 return QString( "C:/" ); |
|
237 } |
|
238 #endif |
|
239 return path; |
|
240 |
|
241 } |
|
242 |
|
243 bool FmUtils::isPathAccessabel( const QString &path ) |
|
244 { |
|
245 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ |
|
246 if(path.contains("D:")) |
|
247 return false; |
|
248 #endif |
|
249 QFileInfo fileInfo( path ); |
|
250 |
|
251 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
|
252 if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) && |
|
253 !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) { |
|
254 return false; |
|
255 } |
|
256 if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) { |
|
257 return false; |
|
258 } |
|
259 if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) { |
|
260 return false; |
|
261 } |
|
262 #endif |
|
263 if( !fileInfo.exists() ) { |
|
264 return false; |
|
265 } |
|
266 return true; |
|
267 } |
|
268 |
|
269 bool FmUtils::isDriveAvailable( const QString &path ) |
|
270 { |
|
271 QFileInfo fileInfo( path ); |
|
272 if( !fileInfo.exists() ) { |
|
273 return false; |
|
274 } |
|
275 return true; |
|
276 } |
|
277 |
|
278 void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive ) |
|
279 { |
|
280 QFileInfoList infoList = QDir::drives(); |
|
281 |
|
282 foreach( QFileInfo fileInfo, infoList ) { |
|
283 QString driveName = fileInfo.absolutePath(); |
|
284 if( checkDriveFilter( driveName ) ) { |
|
285 if( !isHideUnAvailableDrive ) { |
|
286 driveList.append( driveName ); |
|
287 } |
|
288 else if ( isDriveAvailable( driveName ) ) { |
|
289 driveList.append( driveName ); |
|
290 } |
|
291 } |
|
292 } |
|
293 return; |
|
294 } |
|
295 |
|
296 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ) |
|
297 { |
|
298 QString ret; |
|
299 QString tempDriveName = fillPathWithSplash( driveName ); |
|
300 |
|
301 ret = removePathSplash( driveName ); |
|
302 |
|
303 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); |
|
304 QString volumeName = driverInfo.volumeName(); |
|
305 |
|
306 if( volumeName.isEmpty() && isFillWithDefaultVolume ){ |
|
307 quint32 driveState = FmUtils::getDriverState( tempDriveName ); |
|
308 if( !( driveState & FmDriverInfo::EDriveNotPresent ) ){ |
|
309 if( driveState & FmDriverInfo::EDriveRemovable ) { |
|
310 if( driveState & FmDriverInfo::EDriveMassStorage ) { |
|
311 volumeName.append( QObject::tr( "Mass Storage" ) ); |
|
312 } |
|
313 else{ |
|
314 volumeName.append( QObject::tr( "Memory Card" ) ); |
|
315 } |
|
316 } |
|
317 else{ |
|
318 volumeName.append( QObject::tr( "Phone Memory" ) ); |
|
319 } |
|
320 } |
|
321 } |
|
322 |
|
323 ret += QString( " " ) + volumeName; |
|
324 return ret; |
|
325 } |
|
326 |
|
327 int FmUtils::launchFile( const QString &filePath ) |
|
328 { |
|
329 if( QDesktopServices::openUrl( QUrl::fromLocalFile( filePath ) ) ) { |
|
330 return FmErrNone; |
|
331 } else { |
|
332 return FmErrGeneral; |
|
333 } |
|
334 } |
|
335 |
|
336 void FmUtils::sendFiles( QList<QVariant> filePathList ) |
|
337 { |
|
338 Q_UNUSED( filePathList ); |
|
339 } |
|
340 |
|
341 QString FmUtils::getBurConfigPath( QString appPath ) |
|
342 { |
|
343 QFileInfo fileInfo( appPath ); |
|
344 QString testString = fileInfo.absolutePath(); |
|
345 QString path = fillPathWithSplash( fileInfo.absolutePath() ); |
|
346 path = path + QString( "src/filemanager/" ); |
|
347 path = path + QString( BURCONFIGFILE ); |
|
348 return path; |
|
349 } |