filemanager/src/inc/fmutils_win.cpp
changeset 24 1d0c87b42e2e
parent 18 edd66bde63a4
child 29 b3155376f2b4
equal deleted inserted replaced
21:15299bc55001 24:1d0c87b42e2e
    24 #include <QDesktopServices>
    24 #include <QDesktopServices>
    25 #include <QUrl>
    25 #include <QUrl>
    26 #include <QVariant>
    26 #include <QVariant>
    27 
    27 
    28 #define BURCONFIGFILE  "burconfig.xml"
    28 #define BURCONFIGFILE  "burconfig.xml"
       
    29 const int KMaxFileName=0x100;
       
    30 const int KMaxPath=0x100;
    29 
    31 
    30 QString FmUtils::getDriveNameFromPath( const QString &path )
    32 QString FmUtils::getDriveNameFromPath( const QString &path )
    31 {
    33 {
    32     if( path.length() <3 ) {
    34     if( path.length() <3 ) {
    33         return QString();
    35         return QString();
    71     quint32 state( 0 );
    73     quint32 state( 0 );
    72     quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() );
    74     quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() );
    73     if ( drvStatus == DRIVE_REMOVABLE  ) {
    75     if ( drvStatus == DRIVE_REMOVABLE  ) {
    74         state |= FmDriverInfo::EDriveRemovable;
    76         state |= FmDriverInfo::EDriveRemovable;
    75     }
    77     }
       
    78 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_
       
    79 	if ( driverName.contains( "D", Qt::CaseInsensitive )  ) {
       
    80 		state |= FmDriverInfo::EDriveNotPresent;
       
    81     }
       
    82 #endif
       
    83 
       
    84 #ifdef _DEBUG_LOCKED_DRIVE_Z
       
    85 	if ( driverName.contains( "Z", Qt::CaseInsensitive )  ) {
       
    86 		state |= FmDriverInfo::EDriveLocked;
       
    87     }
       
    88 #endif
       
    89 	if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) &&
       
    90 		!(state&FmDriverInfo::EDriveCorrupted) ) {
       
    91 		state |= FmDriverInfo::EDriveAvailable;
       
    92 	}
    76     return FmDriverInfo( size, freeSize, driverName, QString::fromWCharArray( &volumeName[0] ), state );
    93     return FmDriverInfo( size, freeSize, driverName, QString::fromWCharArray( &volumeName[0] ), state );
    77 }
    94 }
    78 
    95 
    79 QString FmUtils::formatStorageSize( quint64 size )
    96 QString FmUtils::formatStorageSize( quint64 size )
    80 {
    97 {
   271 
   288 
   272 }
   289 }
   273 
   290 
   274 bool FmUtils::isPathAccessabel( const QString &path )
   291 bool FmUtils::isPathAccessabel( const QString &path )
   275 {
   292 {
   276 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_
   293     if(!isDriveAvailable( path ) ) { //used to filter locked drive
   277     if(path.contains("D:"))
   294         return false;
   278         return false;
   295     }
   279 #endif
   296 
   280     QFileInfo fileInfo( path );
   297     QFileInfo fileInfo( path );
   281 
   298 
   282 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_
   299 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_
   283     if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) &&
   300     if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) &&
   284         !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) {
   301         !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) {
   297     return true;
   314     return true;
   298 }
   315 }
   299 
   316 
   300 bool FmUtils::isDriveAvailable( const QString &path )
   317 bool FmUtils::isDriveAvailable( const QString &path )
   301 {
   318 {
   302     QFileInfo fileInfo( path );
   319 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_
   303     if( !fileInfo.exists() ) {
   320 	if(path.contains("D:"))
   304         return false;
   321 		return false;
   305     }
   322 #endif
   306     return true;
   323 #ifdef _DEBUG_LOCKED_DRIVE_Z
       
   324 	if(path.contains("Z:"))
       
   325 		return false;
       
   326 #endif
       
   327 	return true;
   307 }
   328 }
   308 
   329 
   309 void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive )
   330 void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive )
   310 {
   331 {
   311     QFileInfoList infoList = QDir::drives();
   332     QFileInfoList infoList = QDir::drives();
   398 QString FmUtils::formatPath( const QString &path  )
   419 QString FmUtils::formatPath( const QString &path  )
   399 {
   420 {
   400     Q_UNUSED( path );
   421     Q_UNUSED( path );
   401     return false;
   422     return false;
   402 }
   423 }
       
   424 
       
   425 int FmUtils::getMaxFileNameLength()
       
   426 {
       
   427 	return KMaxFileName;
       
   428 }
       
   429 
       
   430 bool FmUtils::checkMaxPathLength( const QString& path )
       
   431 {
       
   432 	if( path.length() > KMaxPath ) {
       
   433 		return false;
       
   434 	}
       
   435 	return true;
       
   436 }
       
   437 bool FmUtils::checkFolderFileName( const QString& name )
       
   438 {
       
   439     if( name.endsWith( QChar('.'),  Qt::CaseInsensitive ) ) {
       
   440         return false;
       
   441     }
       
   442     if( name.contains( QChar('\\'), Qt::CaseInsensitive ) ||
       
   443         name.contains( QChar('/'),  Qt::CaseInsensitive ) ||
       
   444         name.contains( QChar(':'),  Qt::CaseInsensitive ) ||
       
   445         name.contains( QChar('*'),  Qt::CaseInsensitive ) ||
       
   446         name.contains( QChar('?'),  Qt::CaseInsensitive ) ||
       
   447         name.contains( QChar('\"'), Qt::CaseInsensitive ) ||
       
   448         name.contains( QChar('<'),  Qt::CaseInsensitive ) ||
       
   449         name.contains( QChar('>'),  Qt::CaseInsensitive ) ||
       
   450         name.contains( QChar('|'),  Qt::CaseInsensitive ) ){
       
   451         return false;
       
   452     }
       
   453     if( name.length() > KMaxFileName ) {
       
   454         return false;
       
   455     }
       
   456     return true;
       
   457 }