filemanager/src/inc/fmutils_s60.cpp
changeset 27 df183af6b92f
parent 25 b7bfdea70ca2
child 32 39cf9ced4cc4
equal deleted inserted replaced
25:b7bfdea70ca2 27:df183af6b92f
    92         if( driveInfoErr != KErrNone ) {
    92         if( driveInfoErr != KErrNone ) {
    93             errorCode = driveInfoErr;
    93             errorCode = driveInfoErr;
    94         }
    94         }
    95     }
    95     }
    96     
    96     
    97     if( volumeName == KErrNone || driveInfoErr == KErrNone ) {
    97     if( volumeInfoErr == KErrNone || driveInfoErr == KErrNone ) {
    98         //TDriveInfo driveInfo = volumeInfo.iDrive;
    98         //TDriveInfo driveInfo = volumeInfo.iDrive;
    99     
    99     
   100         quint32 drvStatus( 0 );
   100         quint32 drvStatus( 0 );
   101         int err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
   101         int err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
   102         if( err == KErrNone ) {
   102         if( err == KErrNone ) {
   682 }
   682 }
   683 
   683 
   684 int FmUtils::isPathAccessabel( const QString &path )
   684 int FmUtils::isPathAccessabel( const QString &path )
   685 {
   685 {
   686     // Used to check if path is accessable, very important feature
   686     // Used to check if path is accessable, very important feature
   687 	// and will return filemanager error.
   687     // and will return filemanager error.
   688     FmLogger::log( QString( "isPathAccessabel:" ) + path );
   688     FmLogger::log( QString( "isPathAccessabel:" ) + path );
   689     if( path.isEmpty() ) {
   689     if( path.isEmpty() ) {
   690         return FmErrPathNotExist;
   690         return FmErrPathNotExist;
   691     }
   691     }
   692     if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive
   692 
       
   693     // used to filter locked/ejected/corrupted drive
       
   694     // check if drive is available, no matter if it is a drive, a folder, or a file.
       
   695     if( !isDriveAvailable( path ) ) {
   693         FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
   696         FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
   694         return FmErrDriveNotAvailable;
   697         return FmErrDriveNotAvailable;
   695     }
   698     }
       
   699 
   696     QFileInfo fileInfo( path );
   700     QFileInfo fileInfo( path );
   697     if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) &&
   701     if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) &&
   698         !fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) {
   702         !fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) {
   699         FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
   703         FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
   700         return FmErrPathDenied;
   704         return FmErrPathDenied;
   915     if( path.length() > KMaxPath ) {
   919     if( path.length() > KMaxPath ) {
   916         return false;
   920         return false;
   917     }
   921     }
   918     return true;
   922     return true;
   919 }
   923 }
       
   924 
   920 bool FmUtils::checkFolderFileName( const QString& name )
   925 bool FmUtils::checkFolderFileName( const QString& name )
   921 {
   926 {
   922     if( name.endsWith( QChar('.'),  Qt::CaseInsensitive ) ) {
   927     // trim space firest, because there may be some spaces after "." ,  it is also not valid
       
   928     QString trimmedName( name.trimmed() );
       
   929 	if( trimmedName.isEmpty() ) {
       
   930 		return false;
       
   931 	}
       
   932     if( trimmedName.endsWith( QChar('.'),  Qt::CaseInsensitive ) ) {
   923         return false;
   933         return false;
   924     }
   934     }
   925     if( name.contains( QChar('\\'), Qt::CaseInsensitive ) ||
   935     if( trimmedName.contains( QChar('\\'), Qt::CaseInsensitive ) ||
   926         name.contains( QChar('/'),  Qt::CaseInsensitive ) ||
   936         trimmedName.contains( QChar('/'),  Qt::CaseInsensitive ) ||
   927         name.contains( QChar(':'),  Qt::CaseInsensitive ) ||
   937         trimmedName.contains( QChar(':'),  Qt::CaseInsensitive ) ||
   928         name.contains( QChar('*'),  Qt::CaseInsensitive ) ||
   938         trimmedName.contains( QChar('*'),  Qt::CaseInsensitive ) ||
   929         name.contains( QChar('?'),  Qt::CaseInsensitive ) ||
   939         trimmedName.contains( QChar('?'),  Qt::CaseInsensitive ) ||
   930         name.contains( QChar('\"'), Qt::CaseInsensitive ) ||
   940         trimmedName.contains( QChar('\"'), Qt::CaseInsensitive ) ||
   931         name.contains( QChar('<'),  Qt::CaseInsensitive ) ||
   941         trimmedName.contains( QChar('<'),  Qt::CaseInsensitive ) ||
   932         name.contains( QChar('>'),  Qt::CaseInsensitive ) ||
   942         trimmedName.contains( QChar('>'),  Qt::CaseInsensitive ) ||
   933         name.contains( QChar('|'),  Qt::CaseInsensitive ) ){
   943         trimmedName.contains( QChar('|'),  Qt::CaseInsensitive ) ){
   934         return false;
   944         return false;
   935     }
   945     }
       
   946     // use orignal name to exam max size of file name
   936     if( name.length() > KMaxFileName ) {
   947     if( name.length() > KMaxFileName ) {
   937         return false;
   948         return false;
   938     }
   949     }
   939     return true;
   950     return true;
   940 }
   951 }
   941 
   952 
   942 bool FmUtils::checkNewFolderOrFile( const QString &path, QString &errString )
   953 bool FmUtils::checkNewFolderOrFile( const QString &fileName, const QString &path, QString &errString )
   943 {
   954 {
       
   955     // first check if fileName is valid, then check if path length is valid, and check if file/foler is existed at last
   944     QFileInfo fileInfo( path );
   956     QFileInfo fileInfo( path );
   945     bool ret( true );   
   957     bool ret( true );   
   946     if (!FmUtils::checkFolderFileName( fileInfo.fileName() ) ) {
   958     if (!FmUtils::checkFolderFileName( fileName ) ) {
   947         errString = hbTrId( "Invalid file or folder name!" );
   959         errString = hbTrId( "Invalid file or folder name!" );
   948         ret = false;
   960         ret = false;
   949     } else if( !FmUtils::checkMaxPathLength( path ) ) {
   961     } else if( !FmUtils::checkMaxPathLength( path ) ) {
   950         errString = hbTrId( "the path you specified is too long!" );
   962         errString = hbTrId( "the path you specified is too long!" );
   951         ret = false;
   963         ret = false;
   953         errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() );
   965         errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() );
   954         ret = false;
   966         ret = false;
   955     }
   967     }
   956     return ret;
   968     return ret;
   957 }
   969 }
       
   970 
       
   971 QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName )
       
   972 {
       
   973     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName );
       
   974           
       
   975     QString volumeName = driverInfo.volumeName();    
       
   976     //save the volume status, whether it is default name
       
   977     defaultName = false;
       
   978     //volume name may be null if not set, it will be set at least for one time in the following while cycling.
       
   979     if ( ( volumeName.isEmpty() ) &&
       
   980             ( driverInfo.driveState() & FmDriverInfo::EDriveAvailable ) ) {
       
   981         defaultName = true;
       
   982         if ( driverInfo.driveState() & FmDriverInfo::EDriveRemovable ) {
       
   983             if ( driverInfo.driveState() & FmDriverInfo::EDriveUsbMemory ) {
       
   984                 volumeName = hbTrId("USB memory");            
       
   985             } else if ( driverInfo.driveState() & FmDriverInfo::EDriveMassStorage ) {
       
   986                 volumeName = hbTrId("Mass storage"); 
       
   987             }
       
   988             else {
       
   989                 volumeName = hbTrId("Memory card");
       
   990             }
       
   991         } else {
       
   992             volumeName = hbTrId("Device memory");
       
   993         }
       
   994     }
       
   995     return volumeName;
       
   996 }