filemanager/src/inc/fmutils_s60.cpp
changeset 25 b7bfdea70ca2
parent 16 ada7962b4308
child 27 df183af6b92f
equal deleted inserted replaced
16:ada7962b4308 25:b7bfdea70ca2
    35 #include <QStringList>
    35 #include <QStringList>
    36 #include <QFileInfoList>
    36 #include <QFileInfoList>
    37 #include <QDir>
    37 #include <QDir>
    38 #include <QFile>
    38 #include <QFile>
    39 
    39 
       
    40 #include <hbglobal.h>
       
    41 
    40 #include <xqaiwrequest.h>
    42 #include <xqaiwrequest.h>
    41 #include <xqappmgr.h>
    43 #include <xqappmgr.h>
    42 
    44 
    43 #include <shareuidialog.h>
    45 #include <shareui.h>
    44 
    46 
    45 #define BURCONFIGFILE  "z:/private/2002BCC0/burconfig.xml"
    47 #define BURCONFIGFILE  "z:/private/2002BCC0/burconfig.xml"
    46 
    48 
    47 QString FmUtils::getDriveNameFromPath( const QString &path )
    49 QString FmUtils::getDriveNameFromPath( const QString &path )
    48 {
    50 {
    49     if( path.length() <3 ) {
    51     // fillPathWithSplash make sure path length will be at least 3 if it is not empty.
       
    52     QString checkedPath( fillPathWithSplash( path ) );
       
    53     if( checkedPath.length() < 3 ) {
    50         return QString();
    54         return QString();
    51     }
    55     }
    52     return path.left( 3 );
    56     return checkedPath.left( 3 );
    53 }
    57 }
    54 
    58 
    55 QString FmUtils::getDriveLetterFromPath( const QString &path )
    59 QString FmUtils::getDriveLetterFromPath( const QString &path )
    56 {
    60 {
    57 	if( path.length() <2 ) {
    61 	if( path.length() <2 ) {
    60     return path.left( 1 );
    64     return path.left( 1 );
    61 }
    65 }
    62 
    66 
    63 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
    67 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
    64 {
    68 {
       
    69     if( driverName.isEmpty() ) {
       
    70         return FmDriverInfo( 0, 0, driverName, QString(), FmDriverInfo::EDriveNotPresent );
       
    71     }
    65     CCoeEnv *env = CCoeEnv::Static();
    72     CCoeEnv *env = CCoeEnv::Static();
    66     RFs& fs = env->FsSession();
    73     RFs& fs = env->FsSession();
    67 
    74 
    68     TVolumeInfo volumeInfo;
    75     TVolumeInfo volumeInfo;
    69     TInt drive = 0;
    76     TInt drive = 0;
    70     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
    77     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
    71 
    78 
    72     quint32 state( 0 );
    79     quint32 state( 0 );
    73     int err = fs.Volume( volumeInfo, drive );
    80     int volumeInfoErr( KErrNone );
       
    81     int driveInfoErr( KErrNone );
       
    82     int errorCode( KErrNone );
       
    83     volumeInfoErr = fs.Volume( volumeInfo, drive );
       
    84     errorCode = volumeInfoErr;
    74     QString volumeName( (QChar*)( volumeInfo.iName.Des().Ptr() ), volumeInfo.iName.Length() );
    85     QString volumeName( (QChar*)( volumeInfo.iName.Des().Ptr() ), volumeInfo.iName.Length() );
    75 
    86     
    76     if( err == KErrNone ) {
    87     TDriveInfo driveInfo;
    77         TDriveInfo driveInfo = volumeInfo.iDrive;
    88     if( volumeInfoErr == KErrNone ) {
       
    89         driveInfo = volumeInfo.iDrive;
       
    90     } else {
       
    91         driveInfoErr = fs.Drive( driveInfo, drive );
       
    92         if( driveInfoErr != KErrNone ) {
       
    93             errorCode = driveInfoErr;
       
    94         }
       
    95     }
       
    96     
       
    97     if( volumeName == KErrNone || driveInfoErr == KErrNone ) {
       
    98         //TDriveInfo driveInfo = volumeInfo.iDrive;
    78     
    99     
    79         quint32 drvStatus( 0 );
   100         quint32 drvStatus( 0 );
    80         err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
   101         int err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
    81         if( err == KErrNone ) {
   102         if( err == KErrNone ) {
    82             QString logString = driverName +':'+ QString::number( drvStatus);
       
    83             FmLogger::log(logString);
       
    84             
   103             
    85             if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
   104             if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
    86                  ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
   105                  ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
    87                 // Handle mass storage bits here
   106                 // Handle mass storage bits here
    88         
   107         
    89                 state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable;
   108                 state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable;
    90             }
   109             }
    91         
   110         
    92             
   111             if ( drvStatus & DriveInfo::EDriveUsbMemory )
       
   112                 {
       
   113                 state |= FmDriverInfo::EDriveUsbMemory;
       
   114                 }
       
   115 
    93             if ( drvStatus & DriveInfo::EDriveRom ){
   116             if ( drvStatus & DriveInfo::EDriveRom ){
    94                 state |= FmDriverInfo::EDriveRom;  
   117                 state |= FmDriverInfo::EDriveRom;  
    95             }
   118             }
    96             
   119             
    97             if ( drvStatus & DriveInfo::EDriveRam ){
   120             if ( drvStatus & DriveInfo::EDriveRam ){
   121             
   144             
   122             if( driveInfo.iType == EMediaNotPresent ){
   145             if( driveInfo.iType == EMediaNotPresent ){
   123                 state |= FmDriverInfo::EDriveNotPresent;    
   146                 state |= FmDriverInfo::EDriveNotPresent;    
   124             }
   147             }
   125         }
   148         }
   126     }
   149         // If memory card is not ready but type is present,
   127     //handle error code
   150         // then check if it is reserved.
   128     switch( err )
   151         if( err == KErrNone && volumeInfoErr == KErrNotReady &&
       
   152             driveInfo.iType != EMediaNotPresent )
       
   153             {
       
   154             // Check USB file transfer state
       
   155             TInt prop( ECoreAppUIsUSBFileTransferUninitialized );
       
   156             RProperty::Get(
       
   157                 KPSUidCoreApplicationUIs,
       
   158                 KCoreAppUIsUSBFileTransfer, prop );
       
   159             if ( prop == ECoreAppUIsUSBFileTransferActive )
       
   160                 {
       
   161                 errorCode = KErrInUse; // Reserved for file transfer
       
   162                 }
       
   163             }
       
   164         if( err!= KErrNone )
       
   165             {
       
   166             errorCode = err;
       
   167             }
       
   168     }
       
   169 
       
   170     // handle error code
       
   171     // volumeInfoErr will occur while drive is lock,corrupted...
       
   172     // driveInfoErr can not be promoted for locked, corrupted drive.
       
   173     // so we can not use driveInfoErr to justify EDriveAvailable
       
   174     switch( errorCode )
   129     {
   175     {
   130     case KErrNone:
   176     case KErrNone:
   131         state |= FmDriverInfo::EDriveAvailable;
   177         // this drive could be used as it is not be locked, or corrupt.
       
   178         state |= FmDriverInfo::EDriveAvailable; 
   132         break;
   179         break;
   133     case KErrLocked:
   180     case KErrLocked:
   134         state |= FmDriverInfo::EDriveLocked;
   181         state |= FmDriverInfo::EDriveLocked;
   135         break;
   182         break;
   136     case KErrCorrupt:
   183     case KErrCorrupt:
   137         state |= FmDriverInfo::EDriveCorrupted;
   184         state |= FmDriverInfo::EDriveCorrupted;
   138         break;
   185         break;
       
   186     case KErrInUse:
       
   187         state |= FmDriverInfo::EDriveInUse;
       
   188         break;
   139     default: // other errors
   189     default: // other errors
   140         state |= FmDriverInfo::EDriveNotPresent;
   190         state |= FmDriverInfo::EDriveNotPresent;
   141         break;
   191         break;
   142     }
   192     }
       
   193     QString logString ( "FmUtils::queryDriverInfo_" + driverName + 
       
   194             "_volumeInfoErr:" + QString::number( volumeInfoErr ) +
       
   195             "_driveInfoErr:" + QString::number( driveInfoErr ) +
       
   196             "_errorCode:" + QString::number( errorCode ) + 
       
   197             "_driveSatus:" + QString::number( state ) );
       
   198     FmLogger::log( logString );
   143     return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driverName, volumeName, state );
   199     return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driverName, volumeName, state );
   144 }
   200 }
   145 
   201 
   146 QString FmUtils::formatStorageSize( quint64 size )
   202 QString FmUtils::formatStorageSize( quint64 size )
   147 {
   203 {
   153 		return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB";
   209 		return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB";
   154 	} else {
   210 	} else {
   155 	    return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB";	    
   211 	    return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB";	    
   156 	}
   212 	}
   157 }
   213 }
   158 /*
       
   159 quint32 FmUtils::getDriverState( const QString &driverName )
       
   160 {    
       
   161     CCoeEnv *env = CCoeEnv::Static();
       
   162     RFs& fs = env->FsSession();
       
   163 
       
   164     TVolumeInfo volumeInfo;
       
   165     TInt drive = 0;
       
   166     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   167 
       
   168     quint32 state( 0 );
       
   169     int err = fs.Volume( volumeInfo, drive );
       
   170     QString volumeName( (QChar*)( volumeInfo.iName.Des().Ptr() ), volumeInfo.iName.Length() );
       
   171 
       
   172     //handle error code
       
   173 	if( err != KErrNone ) {
       
   174             state |= FmDriverInfo::EDriveNotPresent;
       
   175 	}
       
   176 	if ( err == KErrLocked ) {
       
   177             state |= FmDriverInfo::EDriveLocked;
       
   178 	}
       
   179 	
       
   180     TDriveInfo driveInfo = volumeInfo.iDrive;
       
   181 
       
   182     quint32 drvStatus( 0 );
       
   183     DriveInfo::GetDriveStatus( fs, drive, drvStatus );
       
   184 
       
   185     QString logString = driverName +':'+ QString::number( drvStatus);
       
   186     FmLogger::log(logString);
       
   187     
       
   188     if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
       
   189          ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
       
   190         // Handle mass storage bits here
       
   191 
       
   192         state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable;
       
   193     }
       
   194 
       
   195     
       
   196     if ( drvStatus & DriveInfo::EDriveRom ){
       
   197         state |= FmDriverInfo::EDriveRom;  
       
   198     }
       
   199     
       
   200     if ( drvStatus & DriveInfo::EDriveRam ){
       
   201         state |= FmDriverInfo::EDriveRam;  
       
   202     }
       
   203 
       
   204     if ( driveInfo.iMediaAtt & KMediaAttFormattable ){
       
   205         state |= FmDriverInfo::EDriveFormattable;
       
   206     }
       
   207     if ( driveInfo.iMediaAtt & KMediaAttWriteProtected ){
       
   208         state |= FmDriverInfo::EDriveWriteProtected;
       
   209     }
       
   210     if ( driveInfo.iMediaAtt & KMediaAttHasPassword ){
       
   211         state |= FmDriverInfo::EDrivePasswordProtected;
       
   212     }    
       
   213     if ( driveInfo.iMediaAtt & KMediaAttLocked ){
       
   214         state |= FmDriverInfo::EDriveLocked;
       
   215     }
       
   216 
       
   217     if ( driveInfo.iDriveAtt & KDriveAttRemovable ){
       
   218         state |= FmDriverInfo::EDriveRemovable;
       
   219 
       
   220         if ( drvStatus & DriveInfo::EDriveSwEjectable ){
       
   221             state |= FmDriverInfo::EDriveEjectable;
       
   222         }
       
   223     }
       
   224     
       
   225     if( driveInfo.iType == EMediaNotPresent ){
       
   226         state |= FmDriverInfo::EDriveNotPresent;    
       
   227     }
       
   228     
       
   229     return state;
       
   230 
       
   231 }
       
   232 */
       
   233 
   214 
   234 int FmUtils::removeDrivePwd( const QString &driverName,  const QString &Pwd )
   215 int FmUtils::removeDrivePwd( const QString &driverName,  const QString &Pwd )
   235 {
   216 {
       
   217     if( driverName.isEmpty() ) {
       
   218         return FmErrWrongParam;
       
   219     }
   236     QString logString = "Drive name:" + driverName;
   220     QString logString = "Drive name:" + driverName;
   237     FmLogger::log( logString );
   221     FmLogger::log( logString );
   238     logString = "Password:" + Pwd;
   222     logString = "Password:" + Pwd;
   239     FmLogger::log( logString );
   223     FmLogger::log( logString );
   240 
   224 
   269     }
   253     }
   270 }
   254 }
   271 
   255 
   272 int FmUtils::unlockDrive( const QString &driverName,  const QString &Pwd )
   256 int FmUtils::unlockDrive( const QString &driverName,  const QString &Pwd )
   273 {
   257 {
       
   258     if( driverName.isEmpty() ) {
       
   259         return FmErrWrongParam;
       
   260     }
   274     QString logString = "Drive name:" + driverName;
   261     QString logString = "Drive name:" + driverName;
   275     FmLogger::log( logString );
   262     FmLogger::log( logString );
   276     logString = "Password:" + Pwd;
   263     logString = "Password:" + Pwd;
   277     FmLogger::log( logString );
   264     FmLogger::log( logString );
   278 
   265 
   311     }
   298     }
   312 }
   299 }
   313 
   300 
   314 int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd )
   301 int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd )
   315 {
   302 {
       
   303     if( driverName.isEmpty() ) {
       
   304         return FmErrWrongParam;
       
   305     }
   316     QString logString = "checkDrivePwd Drive name:" + driverName;
   306     QString logString = "checkDrivePwd Drive name:" + driverName;
   317     logString += " password:" + pwd;
   307     logString += " password:" + pwd;
   318     FmLogger::log( logString );
   308     FmLogger::log( logString );
   319 
   309 
   320     return setDrivePwd( driverName, pwd, pwd );
   310     return setDrivePwd( driverName, pwd, pwd );
   321 }
   311 }
   322 
   312 
   323 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
   313 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
   324 {
   314 {
       
   315     if( driverName.isEmpty() ) {
       
   316         return FmErrWrongParam;
       
   317     }
   325     QString logString = "setDrivePwd Drive name:" + driverName ;
   318     QString logString = "setDrivePwd Drive name:" + driverName ;
   326     logString += " Old password:" + oldPwd;
   319     logString += " Old password:" + oldPwd;
   327     logString += " New password:" + newPwd;
   320     logString += " New password:" + newPwd;
   328     FmLogger::log( logString );
   321     FmLogger::log( logString );
   329 
   322 
   371     pwd = XQConversions::s60DescToQString( des );
   364     pwd = XQConversions::s60DescToQString( des );
   372 }
   365 }
   373 
   366 
   374 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
   367 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
   375 {
   368 {
   376     foreach( QChar ch, newVolumeName )
   369     if( driverName.isEmpty() ) {
       
   370         return FmErrWrongParam;
       
   371     }
       
   372     foreach( const QChar &ch, newVolumeName )
   377     {
   373     {
   378         bool a = ch.isSpace();
   374         bool a = ch.isSpace();
   379         bool b = ch.isLetterOrNumber();
   375         bool b = ch.isLetterOrNumber();
   380         // If not alphadigit or space, return error
   376         // If not alphadigit or space, return error
   381         if( !ch.isLetterOrNumber() && !ch.isSpace() )
   377         if( !ch.isLetterOrNumber() && !ch.isSpace() )
   406     else{
   402     else{
   407         return FmErrUnKnown;
   403         return FmErrUnKnown;
   408     }
   404     }
   409 }
   405 }
   410 
   406 
   411 void FmUtils::ejectDrive( const QString &driverName )
   407 int FmUtils::ejectDrive( const QString &driverName )
   412 {
   408 {
       
   409     if( driverName.isEmpty() ) {
       
   410         return FmErrWrongParam;
       
   411     }
   413     QString logString = "FmUtils::ejectDrive start";
   412     QString logString = "FmUtils::ejectDrive start";
   414     FmLogger::log( logString );
   413     FmLogger::log( logString );
   415 
   414 
   416     TInt drive = 0;
   415     TInt drive = 0;
   417 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   416 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   422     RProperty::Set(
   421     RProperty::Set(
   423         KPSUidCoreApplicationUIs,
   422         KPSUidCoreApplicationUIs,
   424         KCoreAppUIsMmcRemovedWithoutEject,
   423         KCoreAppUIsMmcRemovedWithoutEject,
   425         ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
   424         ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
   426         );
   425         );
       
   426     return FmErrNone;
   427 }
   427 }
   428 
   428 
   429 QString FmUtils::getFileType( const QString &filePath  )
   429 QString FmUtils::getFileType( const QString &filePath  )
   430 {
   430 {
   431     RApaLsSession apaSession;
   431     RApaLsSession apaSession;
   504     return size;  
   504     return size;  
   505 }
   505 }
   506 
   506 
   507 bool FmUtils::isDriveC( const QString &driverName )
   507 bool FmUtils::isDriveC( const QString &driverName )
   508 {
   508 {
       
   509     if( driverName.isEmpty() ) {
       
   510         return false;
       
   511     }
   509     TInt drive = 0;
   512     TInt drive = 0;
   510     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   513     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   511     if( drive == EDriveC ){
   514     if( drive == EDriveC ){
   512         return true;
   515         return true;
   513     }
   516     }
   527    return ret;   
   530    return ret;   
   528 }
   531 }
   529 
   532 
   530 void FmUtils::createDefaultFolders( const QString &driverName )
   533 void FmUtils::createDefaultFolders( const QString &driverName )
   531 {
   534 {
       
   535     if( driverName.isEmpty() ) {
       
   536         return;
       
   537     }
   532     int err;
   538     int err;
   533     
   539     
   534     TInt drive = 0;
   540     TInt drive = 0;
   535     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   541     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   536     
   542     
   595     CleanupStack::PopAndDestroy( array );
   601     CleanupStack::PopAndDestroy( array );
   596 }
   602 }
   597 
   603 
   598 QString FmUtils::fillPathWithSplash( const QString &filePath )
   604 QString FmUtils::fillPathWithSplash( const QString &filePath )
   599 {
   605 {
   600     QString newFilePath( filePath );
   606 	QString newFilePath;
   601     if( filePath.isEmpty() ) {
   607     if( filePath.isEmpty() ) {
   602         return newFilePath;
   608         return newFilePath;
   603     }
   609     }
   604 
   610 
   605     if( filePath.at( filePath.length()-1 ) != QChar( '/' ) ){
   611     foreach( QChar ch, filePath ) {
   606         newFilePath.append( QChar( '/' ) );
   612         if( ch == QChar('\\') || ch == QChar('/') ) {
   607     }
   613 			newFilePath.append( QDir::separator() );
       
   614         } else {
       
   615             newFilePath.append( ch );
       
   616         }
       
   617     }
       
   618     
       
   619     if( newFilePath.right( 1 )!= QDir::separator() ){
       
   620         newFilePath.append( QDir::separator() );
       
   621     }
       
   622     
   608     return newFilePath;
   623     return newFilePath;
   609 }
   624 }
   610 
   625 
   611 QString FmUtils::removePathSplash( const QString &filePath )
   626 QString FmUtils::removePathSplash( const QString &filePath )
   612 {
   627 {
   615         newFilePath = filePath.left( filePath.length() - 1 );
   630         newFilePath = filePath.left( filePath.length() - 1 );
   616     }
   631     }
   617     return newFilePath;
   632     return newFilePath;
   618 }
   633 }
   619 
   634 
   620 // used to filter drive which need be hide.
   635 // filter un-accessable drive
   621 bool FmUtils::checkDriveFilter( const QString &driveName )
   636 bool FmUtils::checkDriveAccessFilter( const QString &driveName )
   622 {
   637 {
   623     if( driveName.contains( "D:" ) || driveName.contains( "Z:" ) ) {
   638     if( driveName.isEmpty() ) {
       
   639         return false;
       
   640     }
       
   641     FmDriverInfo driveInfo = queryDriverInfo( driveName );
       
   642     if( ( driveInfo.driveState()& FmDriverInfo::EDriveRam ) ||
       
   643         ( driveInfo.driveState()& FmDriverInfo::EDriveRom ) ) {
   624         return false;
   644         return false;
   625     }
   645     }
   626     return true;
   646     return true;
   627 }
   647 }
   628 
   648 
   633     if( !fileInfo.exists() ) {
   653     if( !fileInfo.exists() ) {
   634             return QString();
   654             return QString();
   635         }
   655         }
   636     */
   656     */
   637     QString checkedPath = fillPathWithSplash( path );
   657     QString checkedPath = fillPathWithSplash( path );
   638     if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) {
   658     if( checkedPath.compare( Drive_C, Qt::CaseInsensitive ) == 0 ) {
   639         checkedPath += QString( "data/" );
   659         checkedPath += QString( "data" ) + QDir::separator();
   640         return checkedPath;
   660         return checkedPath;
   641     }
   661     }
   642     return path;
   662     return path;
   643 
   663 
   644 }
   664 }
   651     QString checkedPath = fillPathWithSplash( path );
   671     QString checkedPath = fillPathWithSplash( path );
   652 
   672 
   653     logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
   673     logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
   654     FmLogger::log( logString );
   674     FmLogger::log( logString );
   655     
   675     
   656     if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) {
   676     if( checkedPath.compare( Folder_C_Data, Qt::CaseInsensitive ) == 0 ) {
   657         FmLogger::log( QString( " change from c:/data/ to C:/" ) );
   677         FmLogger::log( QString( " change from c:/data/ to C:/" ) );
   658         return QString( "C:/" );
   678         return Drive_C;
   659     }
   679     }
   660     return path;
   680     return path;
   661 
   681 
   662 }
   682 }
   663 
   683 
   664 bool FmUtils::isPathAccessabel( const QString &path )
   684 int FmUtils::isPathAccessabel( const QString &path )
   665 {
   685 {
       
   686     // Used to check if path is accessable, very important feature
       
   687 	// and will return filemanager error.
   666     FmLogger::log( QString( "isPathAccessabel:" ) + path );
   688     FmLogger::log( QString( "isPathAccessabel:" ) + path );
       
   689     if( path.isEmpty() ) {
       
   690         return FmErrPathNotExist;
       
   691     }
   667     if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive
   692     if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive
   668         FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
   693         FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
   669         return false;
   694         return FmErrDriveNotAvailable;
   670     }
   695     }
   671     QFileInfo fileInfo( path );
   696     QFileInfo fileInfo( path );
   672     if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) &&
   697     if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) &&
   673         !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) {
   698         !fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) {
   674         FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
   699         FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
   675         return false;
   700         return FmErrPathDenied;
   676     }
   701     }
   677     if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) {
   702     if( !checkDriveAccessFilter( FmUtils::getDriveNameFromPath( fileInfo.absoluteFilePath() ) ) ){
   678         FmLogger::log( QString( "isPathAccessabel false: path contain D" ) );
   703         return FmErrDriveDenied;
   679         return false;
       
   680     }
       
   681     if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) {
       
   682         FmLogger::log( QString( "isPathAccessabel false: path contain Z" ) );
       
   683         return false;
       
   684     }
   704     }
   685     if( !fileInfo.exists() ) {
   705     if( !fileInfo.exists() ) {
   686         FmLogger::log( QString( "isPathAccessabel false: path not exist" ) );
   706         FmLogger::log( QString( "isPathAccessabel false: path not exist" ) );
   687         return false;
   707         return FmErrPathNotExist;
   688     }
   708     }
   689     FmLogger::log( QString( "isPathAccessabel true" ) );
   709     FmLogger::log( QString( "isPathAccessabel FmErrNone" ) );
   690     return true;
   710     return FmErrNone;
   691 }
   711 }
   692 
   712 
   693 // only used to check drive, when MMC is not inserted, also return false
   713 // only used to check drive, when MMC is not inserted, also return false
   694 bool FmUtils::isDriveAvailable( const QString &path )
   714 bool FmUtils::isDriveAvailable( const QString &path )
   695 {
   715 {
   696     FmLogger::log( QString( "isDriveAvailable:" ) + path );
   716     FmLogger::log( QString( "isDriveAvailable:" ) + path );
       
   717     if( path.isEmpty() ) {
       
   718         return false;
       
   719     }
   697     FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
   720     FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
   698     if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
   721     if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
   699         FmLogger::log( QString( "isDriveAvailable true" ) );
   722         FmLogger::log( QString( "isDriveAvailable true" ) );
   700         return true;
   723         return true;
   701     }
   724     }
   712     }
   735     }
   713     QFileInfoList infoList = QDir::drives();
   736     QFileInfoList infoList = QDir::drives();
   714 
   737 
   715     foreach( QFileInfo fileInfo, infoList ) {
   738     foreach( QFileInfo fileInfo, infoList ) {
   716         QString driveName = fileInfo.absolutePath();
   739         QString driveName = fileInfo.absolutePath();
   717         if( checkDriveFilter( driveName ) ) {
   740         if( checkDriveAccessFilter( driveName ) ) {
   718             if( !isHideUnAvailableDrive ) {
   741             if( !isHideUnAvailableDrive ) {
   719                 driveList.append( driveName );
   742                 driveList.append( driveName );
   720             }
   743             }
   721             else if ( isDriveAvailable( driveName ) ) {
   744             else if ( isDriveAvailable( driveName ) ) {
   722                 driveList.append( driveName );
   745                 driveList.append( driveName );
   727 }
   750 }
   728 
   751 
   729 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
   752 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
   730 {
   753 {
   731     QString ret;
   754     QString ret;
       
   755     if( driveName.isEmpty() ) {
       
   756         return ret;
       
   757     }
   732     QString tempDriveName = fillPathWithSplash( driveName );
   758     QString tempDriveName = fillPathWithSplash( driveName );
   733 
   759 
   734     ret = removePathSplash( driveName );
   760     QString checkedDriveName( removePathSplash( driveName ) );
   735     
   761     
   736     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
   762     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
   737     QString volumeName = driverInfo.volumeName();
   763     QString volumeName = driverInfo.volumeName();
   738 
   764 
   739     if( volumeName.isEmpty() && isFillWithDefaultVolume ){
   765     if( volumeName.isEmpty() && isFillWithDefaultVolume ){
   740     FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState();
   766     FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState();
   741         if( driveState & FmDriverInfo::EDriveAvailable ){
   767         if( driveState & FmDriverInfo::EDriveAvailable ){
   742             if( driveState & FmDriverInfo::EDriveRemovable ) {
   768             if( driveState & FmDriverInfo::EDriveRemovable ) {
   743                 if( driveState & FmDriverInfo::EDriveMassStorage ) {
   769                 if( driveState & FmDriverInfo::EDriveMassStorage ) {
   744                     volumeName.append( QObject::tr( "Mass Storage" ) );  
   770                     // Mass Storage
       
   771                     ret = hbTrId( "txt_fmgr_dblist_1_mass_storage" ).arg( checkedDriveName );  
       
   772                 } else if( driveState & FmDriverInfo::EDriveUsbMemory ) {
       
   773                     // USB Memory
       
   774                     ret = hbTrId( "txt_fmgr_dblist_1_usb_memory" ).arg( checkedDriveName );
       
   775                 } else{
       
   776                     // Memory Card
       
   777                     ret = hbTrId( "txt_fmgr_dblist_1_memory_card" ).arg( checkedDriveName );
   745                 }
   778                 }
   746                 else{
   779             } else{
   747                     volumeName.append( QObject::tr( "Memory Card" ) );
   780                 // phone memory
   748                 }
   781                 ret = hbTrId( "txt_fmgr_dblist_1_device_memory" ).arg( checkedDriveName );
   749             }
   782             }
   750             else{
   783         }  
   751                 volumeName.append( QObject::tr( "Phone Memory" ) );
   784     }
   752             }
   785     
   753         }
   786     if( ret.isEmpty() ) {
   754     }
   787         // set ret as volumeName
   755 
   788         // txt_fmgr_dblist_1_2 is not correct, can not use.
   756     ret += QString( " " ) + volumeName;
   789         ret = hbTrId( "%1 %2" ).arg( checkedDriveName ).arg( volumeName );
       
   790     }
   757     return ret;
   791     return ret;
   758 }
   792 }
   759 
   793 
   760 int FmUtils::launchFile( const QString &filePath )
   794 int FmUtils::launchFile( const QString &filePath )
   761 {
   795 {
   762     QFile file( filePath );
   796     QFile file( filePath );
       
   797     if( !file.exists() ) {
       
   798         return false;
       
   799     }
       
   800         
   763     XQApplicationManager mAiwMgr;
   801     XQApplicationManager mAiwMgr;
   764     XQAiwRequest *request = mAiwMgr.create(file);
   802     XQAiwRequest *request = mAiwMgr.create(file);
   765     if ( request == 0 ) {
   803     if ( request == 0 ) {
   766         // No handlers for the URI
   804         // No handlers for the URI
   767         return FmErrUnKnown;
   805         return FmErrUnKnown;
   850     return QString();
   888     return QString();
   851 }
   889 }
   852 
   890 
   853 QString FmUtils::formatPath( const QString &path  )
   891 QString FmUtils::formatPath( const QString &path  )
   854 {
   892 {
   855     QString formatPath = path;
   893     QString formatPath;
   856     QRegExp regExp( "/" );
   894 	foreach( QChar ch, path ) {
   857     formatPath.replace( regExp, "\\" );
   895 		if( ch == QChar('\\') || ch == QChar('/') ) {
   858     
   896 			formatPath.append( QDir::separator() );
   859     if( path.right( 1 )!= "\\"){
   897 		} else {
   860         formatPath.append( "\\" );
   898 			formatPath.append( ch );
       
   899 		}
       
   900     }
       
   901 
       
   902     if( formatPath.right( 1 ) != QDir::separator() ){
       
   903         formatPath.append( QDir::separator() );
   861     }
   904     }
   862     return formatPath;
   905     return formatPath;
   863 }
   906 }
       
   907 
       
   908 int FmUtils::getMaxFileNameLength()
       
   909 {
       
   910     return KMaxFileName;
       
   911 }
       
   912 
       
   913 bool FmUtils::checkMaxPathLength( const QString& path )
       
   914 {
       
   915     if( path.length() > KMaxPath ) {
       
   916         return false;
       
   917     }
       
   918     return true;
       
   919 }
       
   920 bool FmUtils::checkFolderFileName( const QString& name )
       
   921 {
       
   922     if( name.endsWith( QChar('.'),  Qt::CaseInsensitive ) ) {
       
   923         return false;
       
   924     }
       
   925     if( name.contains( QChar('\\'), Qt::CaseInsensitive ) ||
       
   926         name.contains( QChar('/'),  Qt::CaseInsensitive ) ||
       
   927         name.contains( QChar(':'),  Qt::CaseInsensitive ) ||
       
   928         name.contains( QChar('*'),  Qt::CaseInsensitive ) ||
       
   929         name.contains( QChar('?'),  Qt::CaseInsensitive ) ||
       
   930         name.contains( QChar('\"'), Qt::CaseInsensitive ) ||
       
   931         name.contains( QChar('<'),  Qt::CaseInsensitive ) ||
       
   932         name.contains( QChar('>'),  Qt::CaseInsensitive ) ||
       
   933         name.contains( QChar('|'),  Qt::CaseInsensitive ) ){
       
   934         return false;
       
   935     }
       
   936     if( name.length() > KMaxFileName ) {
       
   937         return false;
       
   938     }
       
   939     return true;
       
   940 }
       
   941 
       
   942 bool FmUtils::checkNewFolderOrFile( const QString &path, QString &errString )
       
   943 {
       
   944     QFileInfo fileInfo( path );
       
   945     bool ret( true );   
       
   946     if (!FmUtils::checkFolderFileName( fileInfo.fileName() ) ) {
       
   947         errString = hbTrId( "Invalid file or folder name!" );
       
   948         ret = false;
       
   949     } else if( !FmUtils::checkMaxPathLength( path ) ) {
       
   950         errString = hbTrId( "the path you specified is too long!" );
       
   951         ret = false;
       
   952     } else if (fileInfo.exists()) {
       
   953         errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() );
       
   954         ret = false;
       
   955     }
       
   956     return ret;
       
   957 }