23 #include <QFileInfo> |
23 #include <QFileInfo> |
24 #include <QDesktopServices> |
24 #include <QDesktopServices> |
25 #include <QUrl> |
25 #include <QUrl> |
26 #include <QVariant> |
26 #include <QVariant> |
27 |
27 |
|
28 #include <hbglobal.h> |
|
29 |
28 #define BURCONFIGFILE "burconfig.xml" |
30 #define BURCONFIGFILE "burconfig.xml" |
29 const int KMaxFileName=0x100; |
31 const int KMaxFileName=0x100; |
30 const int KMaxPath=0x100; |
32 const int KMaxPath=0x100; |
31 |
33 |
32 QString FmUtils::getDriveNameFromPath( const QString &path ) |
34 QString FmUtils::getDriveNameFromPath( const QString &path ) |
74 quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() ); |
76 quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() ); |
75 if ( drvStatus == DRIVE_REMOVABLE ) { |
77 if ( drvStatus == DRIVE_REMOVABLE ) { |
76 state |= FmDriverInfo::EDriveRemovable; |
78 state |= FmDriverInfo::EDriveRemovable; |
77 } |
79 } |
78 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ |
80 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ |
79 if ( driverName.contains( "D", Qt::CaseInsensitive ) ) { |
81 if ( driverName.contains( Drive_D, Qt::CaseInsensitive ) ) { |
80 state |= FmDriverInfo::EDriveNotPresent; |
82 state |= FmDriverInfo::EDriveNotPresent; |
81 } |
83 } |
82 #endif |
84 #endif |
83 |
85 |
84 #ifdef _DEBUG_LOCKED_DRIVE_Z |
86 #ifdef _DEBUG_LOCKED_DRIVE_Z |
85 if ( driverName.contains( "Z", Qt::CaseInsensitive ) ) { |
87 if ( driverName.contains( Drive_Z, Qt::CaseInsensitive ) ) { |
86 state |= FmDriverInfo::EDriveLocked; |
88 state |= FmDriverInfo::EDriveLocked; |
87 } |
89 } |
88 #endif |
90 #endif |
89 if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) && |
91 if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) && |
90 !(state&FmDriverInfo::EDriveCorrupted) ) { |
92 !(state&FmDriverInfo::EDriveCorrupted) ) { |
103 return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB"; |
105 return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB"; |
104 } else { |
106 } else { |
105 return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB"; |
107 return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB"; |
106 } |
108 } |
107 } |
109 } |
|
110 |
108 /* |
111 /* |
109 quint32 FmUtils::getDriverState( const QString &driverName ) |
112 quint32 FmUtils::getDriverState( const QString &driverName ) |
110 { |
113 { |
111 quint32 state( 0 ); |
114 quint32 state( 0 ); |
112 |
115 |
247 newFilePath = filePath.left( filePath.length() - 1 ); |
251 newFilePath = filePath.left( filePath.length() - 1 ); |
248 } |
252 } |
249 return newFilePath; |
253 return newFilePath; |
250 } |
254 } |
251 |
255 |
252 bool FmUtils::checkDriveFilter( const QString &driveName ) |
256 bool FmUtils::checkDriveAccessFilter( const QString &driveName ) |
253 { |
257 { |
254 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
258 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
255 if( driveName.contains( "D:" ) || driveName.contains( "Z:" ) ) { |
259 if( driveName.contains( Drive_D, Qt::CaseInsensitive ) || driveName.contains( Drive_Z, Qt::CaseInsensitive ) ) { |
256 return false; |
260 return false; |
257 } |
261 } |
258 #endif |
262 #endif |
259 return true; |
263 return true; |
260 } |
264 } |
320 if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) { |
324 if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) { |
321 return false; |
325 return false; |
322 } |
326 } |
323 #endif |
327 #endif |
324 if( !fileInfo.exists() ) { |
328 if( !fileInfo.exists() ) { |
325 return false; |
329 return FmErrPathNotExist; |
326 } |
330 } |
327 return true; |
331 return FmErrNone; |
328 } |
332 } |
329 |
333 |
330 bool FmUtils::isDriveAvailable( const QString &path ) |
334 bool FmUtils::isDriveAvailable( const QString &path ) |
331 { |
335 { |
332 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ |
336 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ |
333 if(path.contains("D:")) |
337 if(path.contains(Drive_D, Qt::CaseInsensitive)) |
334 return false; |
338 return false; |
335 #endif |
339 #endif |
336 #ifdef _DEBUG_LOCKED_DRIVE_Z |
340 #ifdef _DEBUG_LOCKED_DRIVE_Z |
337 if(path.contains("Z:")) |
341 if(path.contains(Drive_Z, Qt::CaseInsensitive)) |
338 return false; |
342 return false; |
339 #endif |
343 #endif |
340 return true; |
344 return true; |
341 } |
345 } |
342 |
346 |
344 { |
348 { |
345 QFileInfoList infoList = QDir::drives(); |
349 QFileInfoList infoList = QDir::drives(); |
346 |
350 |
347 foreach( QFileInfo fileInfo, infoList ) { |
351 foreach( QFileInfo fileInfo, infoList ) { |
348 QString driveName = fileInfo.absolutePath(); |
352 QString driveName = fileInfo.absolutePath(); |
349 if( checkDriveFilter( driveName ) ) { |
353 if( checkDriveAccessFilter( driveName ) ) { |
350 if( !isHideUnAvailableDrive ) { |
354 if( !isHideUnAvailableDrive ) { |
351 driveList.append( driveName ); |
355 driveList.append( driveName ); |
352 } |
356 } |
353 else if ( isDriveAvailable( driveName ) ) { |
357 else if ( isDriveAvailable( driveName ) ) { |
354 driveList.append( driveName ); |
358 driveList.append( driveName ); |
361 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ) |
365 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ) |
362 { |
366 { |
363 QString ret; |
367 QString ret; |
364 QString tempDriveName = fillPathWithSplash( driveName ); |
368 QString tempDriveName = fillPathWithSplash( driveName ); |
365 |
369 |
366 ret = removePathSplash( driveName ); |
370 QString checkedDriveName( removePathSplash( driveName ) ); |
367 |
371 |
368 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); |
372 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); |
369 QString volumeName = driverInfo.volumeName(); |
373 QString volumeName = driverInfo.volumeName(); |
370 |
374 |
371 if( volumeName.isEmpty() && isFillWithDefaultVolume ){ |
375 if( volumeName.isEmpty() && isFillWithDefaultVolume ){ |
372 FmDriverInfo::DriveState driveState = FmUtils::queryDriverInfo( tempDriveName ).FmDriverInfo::driveState(); |
376 FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState(); |
373 if( !( driveState & FmDriverInfo::EDriveNotPresent ) ){ |
377 if( driveState & FmDriverInfo::EDriveAvailable ){ |
374 if( driveState & FmDriverInfo::EDriveRemovable ) { |
378 if( driveState & FmDriverInfo::EDriveRemovable ) { |
375 if( driveState & FmDriverInfo::EDriveMassStorage ) { |
379 if( driveState & FmDriverInfo::EDriveMassStorage ) { |
376 volumeName.append( QObject::tr( "Mass Storage" ) ); |
380 // Mass Storage |
|
381 ret = hbTrId( "txt_fmgr_dblist_1_mass_storage" ).arg( checkedDriveName ); |
|
382 } else if( driveState & FmDriverInfo::EDriveUsbMemory ) { |
|
383 // USB Memory |
|
384 ret = hbTrId( "txt_fmgr_dblist_1_usb_memory" ).arg( checkedDriveName ); |
|
385 } else{ |
|
386 // Memory Card |
|
387 ret = hbTrId( "txt_fmgr_dblist_1_memory_card" ).arg( checkedDriveName ); |
377 } |
388 } |
378 else{ |
389 } else{ |
379 volumeName.append( QObject::tr( "Memory Card" ) ); |
390 // phone memory |
380 } |
391 ret = hbTrId( "txt_fmgr_dblist_1_device_memory" ).arg( checkedDriveName ); |
381 } |
|
382 else{ |
|
383 volumeName.append( QObject::tr( "Phone Memory" ) ); |
|
384 } |
392 } |
385 } |
393 } |
386 } |
394 } else { |
387 |
395 ret = hbTrId( "txt_fmgr_dblist_1_2" ).arg( checkedDriveName ).arg( volumeName ); |
388 ret += QString( " " ) + volumeName; |
396 } |
389 return ret; |
397 return ret; |
390 } |
398 } |
391 |
399 |
392 int FmUtils::launchFile( const QString &filePath ) |
400 int FmUtils::launchFile( const QString &filePath ) |
393 { |
401 { |
477 if( name.length() > KMaxFileName ) { |
485 if( name.length() > KMaxFileName ) { |
478 return false; |
486 return false; |
479 } |
487 } |
480 return true; |
488 return true; |
481 } |
489 } |
|
490 |
|
491 bool FmUtils::checkNewFolderOrFile( const QString &path, QString &errString ) |
|
492 { |
|
493 QFileInfo fileInfo( path ); |
|
494 bool ret( true ); |
|
495 if (!FmUtils::checkFolderFileName( fileInfo.fileName() ) ) { |
|
496 errString = hbTrId( "Invalid file or folder name, try again!" ); |
|
497 ret = false; |
|
498 } else if( !FmUtils::checkMaxPathLength( path ) ) { |
|
499 errString = hbTrId( "the path you specified is too long, try again!" ); |
|
500 ret = false; |
|
501 } else if (fileInfo.exists()) { |
|
502 errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() ); |
|
503 ret = false; |
|
504 } |
|
505 return ret; |
|
506 } |