filemanager/src/inc/fmutils_s60.cpp
changeset 37 15bc28c9dd51
parent 16 ada7962b4308
child 46 d58987eac7e8
equal deleted inserted replaced
16:ada7962b4308 37:15bc28c9dd51
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *     Zhiqiang Yang <zhiqiang.yang@nokia.com>
    13 *     Zhiqiang Yang <zhiqiang.yang@nokia.com>
    14 * 
    14 * 
    15 * Description:
    15 * Description:
    16 *     The source file of the file manager utilities
    16 *     The source file of the file manager utilities on Symbian
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 #include "fmutils.h"
    20 #include "fmutils.h"
       
    21 #include "fmcommon.h"
    21 #include "fms60utils.h"
    22 #include "fms60utils.h"
    22 #include "fmcommon.h"
    23 
    23 
    24 #include <apgcli.h>
    24 #include <QRegExp>
    25 #include <sysutil.h>
    25 
    26 #include <f32file.h>
    26 #include <coemain.h>
    27 #include <coemain.h>
       
    28 #include <pathinfo.h>
    27 #include <driveinfo.h>
    29 #include <driveinfo.h>
    28 #include <e32property.h>
    30 #include <e32property.h>
    29 #include <coreapplicationuisdomainpskeys.h>
    31 #include <coreapplicationuisdomainpskeys.h>
    30 #include <f32file.h>
    32 
    31 #include <apgcli.h>
    33 #include <QDir>
    32 #include <pathinfo.h>
    34 #include <QFile>
    33 #include <CDirectoryLocalizer.h>
    35 #include <QRegExp>
    34 #include <XQConversions>
       
    35 #include <QStringList>
    36 #include <QStringList>
    36 #include <QFileInfoList>
    37 #include <QFileInfoList>
    37 #include <QDir>
    38 
    38 #include <QFile>
    39 #include <xqappmgr.h>
    39 
    40 #include <XQConversions>
    40 #include <xqaiwrequest.h>
    41 #include <xqaiwrequest.h>
    41 #include <xqappmgr.h>
    42 
    42 
    43 #include <shareui.h>
    43 #include <shareuidialog.h>
    44 #include <hbglobal.h>
       
    45 #include <hbdirectorynamelocalizer.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 /*!
    48 {
    50     query drive info and status for \a driveName
    49     if( path.length() <3 ) {
    51     return \a FmDriverInfo
    50         return QString();
    52 */
    51     }
    53 FmDriverInfo FmUtils::queryDriverInfo( const QString &driveName )
    52     return path.left( 3 );
    54 {
    53 }
    55     if( driveName.isEmpty() ) {
    54 
    56         return FmDriverInfo( 0, 0, driveName, QString(), FmDriverInfo::EDriveNotPresent );
    55 QString FmUtils::getDriveLetterFromPath( const QString &path )
    57     }
    56 {
       
    57 	if( path.length() <2 ) {
       
    58         return QString();
       
    59     }
       
    60     return path.left( 1 );
       
    61 }
       
    62 
       
    63 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
       
    64 {
       
    65     CCoeEnv *env = CCoeEnv::Static();
    58     CCoeEnv *env = CCoeEnv::Static();
    66     RFs& fs = env->FsSession();
    59     RFs& fs = env->FsSession();
    67 
    60 
    68     TVolumeInfo volumeInfo;
    61     TVolumeInfo volumeInfo;
    69     TInt drive = 0;
    62     TInt drive = 0;
    70     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
    63     drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
    71 
    64 
    72     quint32 state( 0 );
    65     quint32 state( 0 );
    73     int err = fs.Volume( volumeInfo, drive );
    66     
       
    67     int volumeInfoErr( KErrNone );
       
    68     int driveInfoErr( KErrNone );
       
    69     int errorCode( KErrNone );
       
    70     volumeInfoErr = fs.Volume( volumeInfo, drive );
       
    71     errorCode = volumeInfoErr;
    74     QString volumeName( (QChar*)( volumeInfo.iName.Des().Ptr() ), volumeInfo.iName.Length() );
    72     QString volumeName( (QChar*)( volumeInfo.iName.Des().Ptr() ), volumeInfo.iName.Length() );
    75 
    73     
    76     if( err == KErrNone ) {
    74     TDriveInfo driveInfo;
    77         TDriveInfo driveInfo = volumeInfo.iDrive;
    75     if( volumeInfoErr == KErrNone ) {
       
    76         driveInfo = volumeInfo.iDrive;
       
    77     } else {
       
    78         driveInfoErr = fs.Drive( driveInfo, drive );
       
    79         if( driveInfoErr != KErrNone ) {
       
    80             errorCode = driveInfoErr;
       
    81         }
       
    82     }
       
    83     
       
    84     if( volumeInfoErr == KErrNone || driveInfoErr == KErrNone ) {
       
    85         //TDriveInfo driveInfo = volumeInfo.iDrive;
    78     
    86     
    79         quint32 drvStatus( 0 );
    87         quint32 drvStatus( 0 );
    80         err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
    88         int err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
    81         if( err == KErrNone ) {
    89         if( err == KErrNone ) {
    82             QString logString = driverName +':'+ QString::number( drvStatus);
       
    83             FmLogger::log(logString);
       
    84             
    90             
    85             if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
    91             if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
    86                  ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
    92                  ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
    87                 // Handle mass storage bits here
    93                 // Handle mass storage bits here
       
    94                 state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable;
       
    95             }
    88         
    96         
    89                 state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable;
    97             if ( drvStatus & DriveInfo::EDriveUsbMemory )
    90             }
    98                 {
    91         
    99                 state |= FmDriverInfo::EDriveUsbMemory;
       
   100                 }
       
   101             
       
   102             if ( drvStatus & DriveInfo::EDriveRemote )
       
   103                 {
       
   104                 state |= FmDriverInfo::EDriveRemote;
       
   105                 }
    92             
   106             
    93             if ( drvStatus & DriveInfo::EDriveRom ){
   107             if ( drvStatus & DriveInfo::EDriveRom ){
    94                 state |= FmDriverInfo::EDriveRom;  
   108                 state |= FmDriverInfo::EDriveRom;  
    95             }
   109             }
    96             
   110             
   121             
   135             
   122             if( driveInfo.iType == EMediaNotPresent ){
   136             if( driveInfo.iType == EMediaNotPresent ){
   123                 state |= FmDriverInfo::EDriveNotPresent;    
   137                 state |= FmDriverInfo::EDriveNotPresent;    
   124             }
   138             }
   125         }
   139         }
   126     }
   140         // If memory card is not ready but type is present,
   127     //handle error code
   141         // then check if it is reserved.
   128     switch( err )
   142         if( err == KErrNone && volumeInfoErr == KErrNotReady &&
       
   143             driveInfo.iType != EMediaNotPresent )
       
   144             {
       
   145             // Check USB file transfer state
       
   146             TInt prop( ECoreAppUIsUSBFileTransferUninitialized );
       
   147             RProperty::Get(
       
   148                 KPSUidCoreApplicationUIs,
       
   149                 KCoreAppUIsUSBFileTransfer, prop );
       
   150             if ( prop == ECoreAppUIsUSBFileTransferActive )
       
   151                 {
       
   152                 errorCode = KErrInUse; // Reserved for file transfer
       
   153                 }
       
   154             }
       
   155         if( err!= KErrNone )
       
   156             {
       
   157             errorCode = err;
       
   158             }
       
   159     }
       
   160 
       
   161     // handle error code
       
   162     // volumeInfoErr will occur while drive is lock,corrupted...
       
   163     // driveInfoErr can not be promoted for locked, corrupted drive.
       
   164     // so we can not use driveInfoErr to justify EDriveAvailable
       
   165     switch( errorCode )
   129     {
   166     {
   130     case KErrNone:
   167     case KErrNone:
   131         state |= FmDriverInfo::EDriveAvailable;
   168         // this drive could be used as it is not be locked, or corrupt.
       
   169         state |= FmDriverInfo::EDriveAvailable; 
   132         break;
   170         break;
   133     case KErrLocked:
   171     case KErrLocked:
   134         state |= FmDriverInfo::EDriveLocked;
   172         state |= FmDriverInfo::EDriveLocked;
   135         break;
   173         break;
   136     case KErrCorrupt:
   174     case KErrCorrupt:
   137         state |= FmDriverInfo::EDriveCorrupted;
   175         state |= FmDriverInfo::EDriveCorrupted;
   138         break;
   176         break;
       
   177     case KErrInUse:
       
   178         state |= FmDriverInfo::EDriveInUse;
       
   179         break;
   139     default: // other errors
   180     default: // other errors
   140         state |= FmDriverInfo::EDriveNotPresent;
   181         state |= FmDriverInfo::EDriveNotPresent;
   141         break;
   182         break;
   142     }
   183     }
   143     return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driverName, volumeName, state );
   184     QString logString ( "FmUtils::queryDriverInfo_" + driveName + 
   144 }
   185             "_volumeInfoErr:" + QString::number( volumeInfoErr ) +
   145 
   186             "_driveInfoErr:" + QString::number( driveInfoErr ) +
   146 QString FmUtils::formatStorageSize( quint64 size )
   187             "_errorCode:" + QString::number( errorCode ) + 
   147 {
   188             "_driveSatus:" + QString::number( state ) );
   148 	if ( size < 1000 ) {
   189     FM_LOG( logString );
   149 		return QString::number( size ) + " B";
   190     return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driveName, volumeName, state );
   150 	} else if ( size < 1000 * 1000 ) {
   191 }
   151 		return QString::number( size / 1024.0, 'f', 2 ) + " KB";
   192 
   152 	} else if ( size < 1000 * 1000 * 1000 ) {
   193 /*!
   153 		return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB";
   194     remove drive password for \a driveName
   154 	} else {
   195     \a Pwd is original password.
   155 	    return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB";	    
   196 */
   156 	}
   197 int FmUtils::removeDrivePwd( const QString &driveName,  const QString &Pwd )
   157 }
   198 {
   158 /*
   199     if( driveName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) {
   159 quint32 FmUtils::getDriverState( const QString &driverName )
   200         return FmErrWrongParam;
   160 {    
   201     }
   161     CCoeEnv *env = CCoeEnv::Static();
   202     QString logString = "Drive name:" + driveName;
   162     RFs& fs = env->FsSession();
   203     FM_LOG( logString );
   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 
       
   234 int FmUtils::removeDrivePwd( const QString &driverName,  const QString &Pwd )
       
   235 {
       
   236     QString logString = "Drive name:" + driverName;
       
   237     FmLogger::log( logString );
       
   238     logString = "Password:" + Pwd;
   204     logString = "Password:" + Pwd;
   239     FmLogger::log( logString );
   205     FM_LOG( logString );
   240 
   206 
   241     CCoeEnv *env = CCoeEnv::Static();
   207     CCoeEnv *env = CCoeEnv::Static();
   242 	RFs& fs = env->FsSession();
   208 	RFs& fs = env->FsSession();
   243 
   209 
   244     TInt drive = 0;
   210     TInt drive = 0;
   245 
   211 
   246 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   212     drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
   247 
   213 
   248     HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
   214     HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
   249     TMediaPassword password;   
   215     TMediaPassword password;   
   250     TPtr ptrPassword16( password16->Des() );  
   216     TPtr ptrPassword16( password16->Des() );  
   251     FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
   217     FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
   252 
   218 
   253     int err( fs.ClearPassword( drive, password ) );
   219     int err( fs.ClearPassword( drive, password ) );
   254 
   220 
   255     logString = "Drive:" + QString::number( drive );
   221     logString = "Drive:" + QString::number( drive );
   256     FmLogger::log( logString );
   222     FM_LOG( logString );
   257 
   223 
   258     logString = "Clear password error:" + QString::number( err );
   224     logString = "Clear password error:" + QString::number( err );
   259     FmLogger::log( logString );
   225     FM_LOG( logString );
       
   226 
       
   227     delete password16;
   260 
   228 
   261     if( err == KErrNone ){
   229     if( err == KErrNone ){
   262         return FmErrNone;   
   230         return FmErrNone;   
   263     }
   231     }
   264     else if( err == KErrAccessDenied ){
   232     else if( err == KErrAccessDenied ){
   267     else{
   235     else{
   268         return FmErrUnKnown;
   236         return FmErrUnKnown;
   269     }
   237     }
   270 }
   238 }
   271 
   239 
   272 int FmUtils::unlockDrive( const QString &driverName,  const QString &Pwd )
   240 /*!
   273 {
   241     Unlock drive \a driveName with provided password \a Pwd
   274     QString logString = "Drive name:" + driverName;
   242 */
   275     FmLogger::log( logString );
   243 int FmUtils::unlockDrive( const QString &driveName,  const QString &Pwd )
       
   244 {
       
   245     if( driveName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) {
       
   246         return FmErrWrongParam;
       
   247     }
       
   248     QString logString = "Drive name:" + driveName;
       
   249     FM_LOG( logString );
   276     logString = "Password:" + Pwd;
   250     logString = "Password:" + Pwd;
   277     FmLogger::log( logString );
   251     FM_LOG( logString );
   278 
   252 
   279     CCoeEnv *env = CCoeEnv::Static();
   253     CCoeEnv *env = CCoeEnv::Static();
   280 	RFs& fs = env->FsSession();
   254 	RFs& fs = env->FsSession();
   281 
   255 
   282     TInt drive = 0;
   256     TInt drive = 0;
   283 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   257 	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
   284     
   258     
   285     HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
   259     HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
   286     TMediaPassword password;   
   260     TMediaPassword password;   
   287     TPtr ptrPassword16( password16->Des() );  
   261     TPtr ptrPassword16( password16->Des() );  
   288     FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
   262     FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
   289 
   263 
   290     int err( fs.UnlockDrive( drive, password, ETrue) );
   264     int err( fs.UnlockDrive( drive, password, ETrue) );
   291 
   265 
   292     logString = "Drive:" + QString::number( drive );
   266     logString = "Drive:" + QString::number( drive );
   293     FmLogger::log( logString );
   267     FM_LOG( logString );
   294     logString = "Unlock drive error:" + QString::number( err );
   268     logString = "Unlock drive error:" + QString::number( err );
   295     FmLogger::log( logString );
   269     FM_LOG( logString );
       
   270 
       
   271     delete password16;
   296 
   272 
   297     if( err == KErrNone ){
   273     if( err == KErrNone ){
   298         return FmErrNone;   
   274         return FmErrNone;   
   299     }
   275     }
   300     else if( err == KErrAccessDenied ){
   276     else if( err == KErrAccessDenied ){
   309     else{
   285     else{
   310         return FmErrUnKnown;
   286         return FmErrUnKnown;
   311     }
   287     }
   312 }
   288 }
   313 
   289 
   314 int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd )
   290 /*!
   315 {
   291     Check if \a pwd is the right password for drive \a driveName
   316     QString logString = "checkDrivePwd Drive name:" + driverName;
   292 */
       
   293 int FmUtils::checkDrivePwd( const QString &driveName, const QString &pwd )
       
   294 {
       
   295     if( driveName.isEmpty() || pwd.length() > FmMaxLengthofDrivePassword ) {
       
   296         return FmErrWrongParam;
       
   297     }
       
   298     QString logString = "checkDrivePwd Drive name:" + driveName;
   317     logString += " password:" + pwd;
   299     logString += " password:" + pwd;
   318     FmLogger::log( logString );
   300     FM_LOG( logString );
   319 
   301 
   320     return setDrivePwd( driverName, pwd, pwd );
   302     return setDrivePwd( driveName, pwd, pwd );
   321 }
   303 }
   322 
   304 
   323 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
   305 /*!
   324 {
   306     Set new password \a newPwd for drive \a driveName. \a oldPwd is old password
   325     QString logString = "setDrivePwd Drive name:" + driverName ;
   307 */
       
   308 int FmUtils::setDrivePwd( const QString &driveName, const QString &oldPwd, const QString &newPwd)
       
   309 {
       
   310     if( driveName.isEmpty() || 
       
   311         oldPwd.length() > FmMaxLengthofDrivePassword || newPwd.length() > FmMaxLengthofDrivePassword  ) {
       
   312         return FmErrWrongParam;
       
   313     }
       
   314     QString logString = "setDrivePwd Drive name:" + driveName ;
   326     logString += " Old password:" + oldPwd;
   315     logString += " Old password:" + oldPwd;
   327     logString += " New password:" + newPwd;
   316     logString += " New password:" + newPwd;
   328     FmLogger::log( logString );
   317     FM_LOG( logString );
   329 
   318 
   330     CCoeEnv *env = CCoeEnv::Static();
   319     CCoeEnv *env = CCoeEnv::Static();
   331 	RFs& fs = env->FsSession();
   320 	RFs& fs = env->FsSession();
   332 
   321 
   333     TInt drive = 0;
   322     TInt drive = 0;
   334 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   323 	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
   335 	
   324 	
   336     HBufC* newPassword16 = XQConversions::qStringToS60Desc( newPwd);
   325     HBufC* newPassword16 = XQConversions::qStringToS60Desc( newPwd);
   337     HBufC* oldPassword16 = XQConversions::qStringToS60Desc( oldPwd );
   326     HBufC* oldPassword16 = XQConversions::qStringToS60Desc( oldPwd );
   338 
   327 
   339     TMediaPassword oldPassword;
   328     TMediaPassword oldPassword;
   346     FmS60Utils::ConvertCharsToPwd( ptrOldPassword16, oldPassword );
   335     FmS60Utils::ConvertCharsToPwd( ptrOldPassword16, oldPassword );
   347 
   336 
   348     int err( fs.LockDrive( drive, oldPassword, newPassword, ETrue ) );
   337     int err( fs.LockDrive( drive, oldPassword, newPassword, ETrue ) );
   349 
   338 
   350     logString = "Drive:" + QString::number( drive );
   339     logString = "Drive:" + QString::number( drive );
   351     FmLogger::log( logString );
   340     FM_LOG( logString );
   352     logString = "Password set error:" + QString::number( err );
   341     logString = "Password set error:" + QString::number( err );
   353     FmLogger::log( logString );
   342     FM_LOG( logString );
   354 
   343 
       
   344     delete newPassword16;
       
   345     delete oldPassword16;
   355     if( err == KErrNone ){
   346     if( err == KErrNone ){
   356         return FmErrNone;   
   347         return FmErrNone;   
   357     }
   348     }
   358     else if( err == KErrNotSupported ){
   349     else if( err == KErrNotSupported ){
   359         return FmErrNotSupported;
   350         return FmErrNotSupported;
   361     else{
   352     else{
   362         return FmErrUnKnown;
   353         return FmErrUnKnown;
   363     }
   354     }
   364 }
   355 }
   365 
   356 
       
   357 /*!
       
   358     Set \a pwd as empty password
       
   359 */
   366 void FmUtils::emptyPwd( QString &pwd )
   360 void FmUtils::emptyPwd( QString &pwd )
   367 {
   361 {
   368     TPtr des ( ( XQConversions::qStringToS60Desc( pwd ) )->Des() );
   362     TBuf< FmMaxLengthofDrivePassword > nullPwd;
   369     des.FillZ( des.MaxLength() );
   363     nullPwd.FillZ( nullPwd.MaxLength() );
   370     des.Zero();
   364     nullPwd.Zero();
   371     pwd = XQConversions::s60DescToQString( des );
   365     pwd = XQConversions::s60DescToQString( nullPwd );
   372 }
   366 }
   373 
   367 
   374 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
   368 /*!
   375 {
   369     Set drive volume for drive \a driveName
   376     foreach( QChar ch, newVolumeName )
   370 */
       
   371 int FmUtils::renameDrive( const QString &driveName, const QString &newVolumeName)
       
   372 {
       
   373     if( driveName.isEmpty() ) {
       
   374         return FmErrWrongParam;
       
   375     }
       
   376     foreach( const QChar &ch, newVolumeName )
   377     {
   377     {
   378         bool a = ch.isSpace();
   378         bool a = ch.isSpace();
   379         bool b = ch.isLetterOrNumber();
   379         bool b = ch.isLetterOrNumber();
   380         // If not alphadigit or space, return error
   380         // If not alphadigit or space, return error
   381         if( !ch.isLetterOrNumber() && !ch.isSpace() )
   381         if( !ch.isLetterOrNumber() && !ch.isSpace() )
   386         
   386         
   387     CCoeEnv *env = CCoeEnv::Static();
   387     CCoeEnv *env = CCoeEnv::Static();
   388 	RFs& fs = env->FsSession();
   388 	RFs& fs = env->FsSession();
   389 
   389 
   390     TInt drive = 0;
   390     TInt drive = 0;
   391 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   391 	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
   392 
   392 
   393     TPtr newName ( ( XQConversions::qStringToS60Desc( newVolumeName ) )->Des() );
   393     TPtr newName ( ( XQConversions::qStringToS60Desc( newVolumeName ) )->Des() );
   394 
   394 
   395     int err( fs.SetVolumeLabel( newName, drive ));
   395     int err( fs.SetVolumeLabel( newName, drive ));
   396     
   396     
   397     QString logString = "Rename error:" + QString::number( err );
   397     QString logString = "Rename error:" + QString::number( err );
   398     FmLogger::log( logString );
   398     FM_LOG( logString );
   399 
   399 
   400     if( err == KErrNone ){
   400     if( err == KErrNone ){
   401         return FmErrNone;   
   401         return FmErrNone;   
   402     }
   402     }
   403     else if( err == KErrNotReady ){
   403     else if( err == KErrNotReady ){
   406     else{
   406     else{
   407         return FmErrUnKnown;
   407         return FmErrUnKnown;
   408     }
   408     }
   409 }
   409 }
   410 
   410 
   411 void FmUtils::ejectDrive( const QString &driverName )
   411 /*!
   412 {
   412     Eject drive \a driveName
       
   413 */
       
   414 int FmUtils::ejectDrive( const QString &driveName )
       
   415 {
       
   416     if( driveName.isEmpty() ) {
       
   417         return FmErrWrongParam;
       
   418     }
   413     QString logString = "FmUtils::ejectDrive start";
   419     QString logString = "FmUtils::ejectDrive start";
   414     FmLogger::log( logString );
   420     FM_LOG( logString );
   415 
   421 
   416     TInt drive = 0;
   422     TInt drive = 0;
   417 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   423 	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
   418 
   424 
   419     const int KDriveShift = 16;
   425     const int KDriveShift = 16;
   420 
   426 
   421     // Let SysAp handle eject
   427     // Let SysAp handle eject
   422     RProperty::Set(
   428     RProperty::Set(
   423         KPSUidCoreApplicationUIs,
   429         KPSUidCoreApplicationUIs,
   424         KCoreAppUIsMmcRemovedWithoutEject,
   430         KCoreAppUIsMmcRemovedWithoutEject,
   425         ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
   431         ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
   426         );
   432         );
   427 }
   433     return FmErrNone;
   428 
   434 }
   429 QString FmUtils::getFileType( const QString &filePath  )
   435 
   430 {
   436 /*!
   431     RApaLsSession apaSession;
   437     Check if drive \a driveName is accessable for user
   432     TDataType dataType;
   438 */
   433     TUid appUid;
   439 bool FmUtils::checkDriveAccessFilter( const QString &driveName )
   434     
   440 {
   435     TBuf<128> mimeTypeBuf;
   441     if( driveName.isEmpty() ) {
   436         
   442         return false;
   437     int err = apaSession.Connect();
   443     }
   438     
   444     FmDriverInfo driveInfo = queryDriverInfo( driveName );
   439     if ( err == KErrNone ){   
   445     if( ( driveInfo.driveState()& FmDriverInfo::EDriveRam ) ||
   440         err = apaSession.AppForDocument( XQConversions::qStringToS60Desc( filePath )->Des(), 
   446         ( driveInfo.driveState()& FmDriverInfo::EDriveRom ) ) {
   441                                          appUid, dataType );
   447         return false;
   442         
   448     }
   443         if( err == KErrNone ){
   449     return true;
   444             mimeTypeBuf.Copy(dataType.Des8());
   450 }
   445         }  
   451 
   446     }
   452 /*!
   447     
   453     This function should be called to adjust path if user goto a drive.
   448     apaSession.Close();
   454     data folder will be append to C:\ becuase user could only view C:\data instead C:\ 
   449     return XQConversions::s60DescToQString( mimeTypeBuf );
   455 */
   450 }
   456 QString FmUtils::checkDriveToFolderFilter( const QString &path )
   451 
   457 {
   452 quint64 FmUtils::getDriveDetailsResult( const QString &folderPath, const QString &extension )
   458     QString checkedPath = fillPathWithSplash( path );
   453 {
   459     if( checkedPath.compare( Drive_C, Qt::CaseInsensitive ) == 0 ) {
       
   460         checkedPath += QString( "data" ) + QDir::separator();
       
   461         return checkedPath;
       
   462     }
       
   463     return path;
       
   464 
       
   465 }
       
   466 
       
   467 /*!
       
   468     This function should be called to adjust path if user back to up level path.
       
   469     If user is at C:\data then path level should be returned as C:\
       
   470     Becuase C:\data is root path for C drive 
       
   471 */
       
   472 QString FmUtils::checkFolderToDriveFilter( const QString &path )
       
   473 {
       
   474     QString logString;
       
   475     logString = QString( "checkFolderToDriveFilter: " ) + path;
       
   476     FM_LOG( logString );
       
   477     QString checkedPath = fillPathWithSplash( path );
       
   478 
       
   479     logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
       
   480     FM_LOG( logString );
       
   481     
       
   482     if( checkedPath.compare( Folder_C_Data, Qt::CaseInsensitive ) == 0 ) {
       
   483         FM_LOG( QString( " change from c:/data/ to C:/" ) );
       
   484         return Drive_C;
       
   485     }
       
   486     return path;
       
   487 
       
   488 }
       
   489 
       
   490 /*!
       
   491     Check if \a path is accessable for user
       
   492 */
       
   493 int FmUtils::isPathAccessabel( const QString &path )
       
   494 {
       
   495     // Used to check if path is accessable, very important feature
       
   496     // and will return filemanager error.
       
   497     FM_LOG( QString( "isPathAccessabel:" ) + path );
       
   498     if( path.isEmpty() ) {
       
   499         return FmErrPathNotExist;
       
   500     }
       
   501 
       
   502     // used to filter locked/ejected/corrupted drive
       
   503     // check if drive is available, no matter if it is a drive, a folder, or a file.
       
   504     if( !isDriveAvailable( path ) ) {
       
   505         FM_LOG( QString( "isPathAccessabel false: path is drive and not available" ) );
       
   506         return FmErrDriveNotAvailable;
       
   507     }
       
   508 
       
   509     QFileInfo fileInfo( path );
       
   510 
       
   511     if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) &&
       
   512         !fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) {
       
   513         FM_LOG( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
       
   514         return FmErrPathDenied;
       
   515     }
       
   516     if( !checkDriveAccessFilter( FmUtils::getDriveNameFromPath( fileInfo.absoluteFilePath() ) ) ){
       
   517         return FmErrDriveDenied;
       
   518     }
       
   519     if( !fileInfo.exists() ) {
       
   520         FM_LOG( QString( "isPathAccessabel false: path not exist" ) );
       
   521         return FmErrPathNotExist;
       
   522     }
       
   523     FM_LOG( QString( "isPathAccessabel FmErrNone" ) );
       
   524     return FmErrNone;
       
   525 }
       
   526 
       
   527 /*!
       
   528     Check if drive related to \a path is available.
       
   529     This function should not check if path is available. Only responsible for checking drive  
       
   530     When MMC is not inserted, also return false
       
   531 */
       
   532 bool FmUtils::isDriveAvailable( const QString &path )
       
   533 {
       
   534     FM_LOG( QString( "isDriveAvailable:" ) + path );
       
   535     if( path.isEmpty() ) {
       
   536         return false;
       
   537     }
       
   538     FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
       
   539     if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
       
   540         FM_LOG( QString( "isDriveAvailable true" ) );
       
   541         return true;
       
   542     }
       
   543     FM_LOG( QString( "isDriveAvailable false" ) );
       
   544     return false;
       
   545 }
       
   546 
       
   547 /*!
       
   548     Check if \a folderPath is default folder for system
       
   549 */
       
   550 bool FmUtils::isDefaultFolder( const QString &folderPath  )
       
   551 {
       
   552     HBufC *path = XQConversions::qStringToS60Desc( folderPath );
       
   553     TPtrC desFolderPath( path->Des() );
       
   554     
       
   555     bool ret( true );
       
   556     TInt pathType( PathInfo::PathType( desFolderPath ) );
       
   557     switch( pathType ){
       
   558        case PathInfo::ENotSystemPath:{
       
   559            QString locString( localize( folderPath ) );
       
   560             if ( locString.isEmpty() ){
       
   561                 ret = false;
       
   562                 break;
       
   563             }
       
   564             ret = true;
       
   565             break;
       
   566             }
       
   567         case PathInfo::EPhoneMemoryRootPath: // FALL THROUGH
       
   568         case PathInfo::EMemoryCardRootPath: // FALL THROUGH
       
   569         case PathInfo::ERomRootPath:{
       
   570             ret = false;
       
   571             break;
       
   572         }
       
   573         // Accept other folders
       
   574         default:{
       
   575             ret = true;
       
   576             break;
       
   577         }
       
   578     }
       
   579     delete path;
       
   580     return ret;
       
   581 }
       
   582 
       
   583 /*!
       
   584     Create system default folders for drive \a driveName.
       
   585     Default folders should be created after format a drive.
       
   586 */
       
   587 void FmUtils::createDefaultFolders( const QString &driveName )
       
   588 {
       
   589     if( driveName.isEmpty() ) {
       
   590         return;
       
   591     }
   454     int err;
   592     int err;
   455     
   593     
   456     RFs fs;
       
   457     err = fs.Connect();
       
   458     
       
   459     QString string( formatPath( folderPath ) );
       
   460 
       
   461     TPtrC desFolderPath( XQConversions::qStringToS60Desc( string )->Des() );
       
   462     TPtrC ptrExtension( XQConversions::qStringToS60Desc( extension )->Des() );
       
   463     
       
   464     CDir* results = 0;
       
   465     TParse parse;
       
   466     
       
   467     quint64 size = 0;
       
   468     
       
   469     const TInt pathlength = ptrExtension.Length() + desFolderPath.Length();
       
   470     
       
   471     if ( pathlength > KMaxFileName ){
       
   472         err = KErrNotFound;   
       
   473     }
       
   474     else{
       
   475         err = fs.Parse( ptrExtension, desFolderPath, parse );
       
   476         err = fs.GetDir( parse.FullName(), KEntryAttMaskSupported|KEntryAttAllowUid, 
       
   477             ESortNone, results );
       
   478         
       
   479         TDesC des = parse.FullName();
       
   480         
       
   481         if (err == KErrNotFound)
       
   482             {
       
   483             return 0;
       
   484             }
       
   485     }
       
   486     
       
   487     if ( results ){
       
   488         CleanupStack::PushL(results);
       
   489 
       
   490         // Go through all files in the list and tell subclass
       
   491         TFileName file;
       
   492         const TInt count = results->Count();
       
   493         for( TInt i=0; i<count; ++i ){
       
   494             const TEntry& entry = (*results)[i];
       
   495             file = desFolderPath;
       
   496             file += entry.iName;
       
   497             size += entry.iSize;          
       
   498         }
       
   499         CleanupStack::PopAndDestroy(results);
       
   500     }
       
   501     
       
   502     fs.Close();
       
   503     
       
   504     return size;  
       
   505 }
       
   506 
       
   507 bool FmUtils::isDriveC( const QString &driverName )
       
   508 {
       
   509     TInt drive = 0;
   594     TInt drive = 0;
   510     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   595     drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
   511     if( drive == EDriveC ){
       
   512         return true;
       
   513     }
       
   514     else{
       
   515         return false;
       
   516     }
       
   517    
       
   518 }
       
   519 
       
   520 bool FmUtils::isDrive( const QString &path )
       
   521 {
       
   522    bool ret( false );
       
   523    if( path.length() <= 3 && path.length() >=2 ) {
       
   524        ret = true;
       
   525    }
       
   526    
       
   527    return ret;   
       
   528 }
       
   529 
       
   530 void FmUtils::createDefaultFolders( const QString &driverName )
       
   531 {
       
   532     int err;
       
   533     
       
   534     TInt drive = 0;
       
   535     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   536     
   596     
   537     RFs fs;
   597     RFs fs;
   538     err = fs.Connect();
   598     err = fs.Connect();
   539     
   599     
   540     if( err != KErrNone ){
   600     if( err != KErrNone ){
   593         }
   653         }
   594     }
   654     }
   595     CleanupStack::PopAndDestroy( array );
   655     CleanupStack::PopAndDestroy( array );
   596 }
   656 }
   597 
   657 
   598 QString FmUtils::fillPathWithSplash( const QString &filePath )
   658 /*!
   599 {
   659     In Symbian system, default folders will be localized.
   600     QString newFilePath( filePath );
   660     So localize is used to check if a path is a default folder
   601     if( filePath.isEmpty() ) {
   661     \sa isDefaultFolder
   602         return newFilePath;
   662 */
   603     }
   663 QString FmUtils::localize( const QString &path )
   604 
   664 {
   605     if( filePath.at( filePath.length()-1 ) != QChar( '/' ) ){
   665     // HbDirectoryNameLocalizer can not recognize path with \ in the end
   606         newFilePath.append( QChar( '/' ) );
   666     QString locPath( removePathSplash( path ) );
   607     }
   667     
   608     return newFilePath;
   668     HbDirectoryNameLocalizer localizer;
   609 }
   669     return localizer.translate( locPath );
   610 
   670 }
   611 QString FmUtils::removePathSplash( const QString &filePath )
   671 
   612 {
   672 /*!
   613     QString newFilePath( filePath );
   673     set the \a desFile attributes as the same with \a srcFile
   614     if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) {
   674 */
   615         newFilePath = filePath.left( filePath.length() - 1 );
   675 int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile )
   616     }
   676 {
   617     return newFilePath;
   677     RFs fsSession;
   618 }
   678     User::LeaveIfError( fsSession.Connect() ); 
   619 
   679     CleanupClosePushL( fsSession );
   620 // used to filter drive which need be hide.
   680     RFile64 src;
   621 bool FmUtils::checkDriveFilter( const QString &driveName )
   681     RFile64 des;
   622 {
   682     HBufC *buf1 = XQConversions::qStringToS60Desc( removePathSplash( formatPath( srcFile ) ) );
   623     if( driveName.contains( "D:" ) || driveName.contains( "Z:" ) ) {
   683     HBufC *buf2 = XQConversions::qStringToS60Desc( removePathSplash( formatPath( desFile ) ) );
       
   684     User::LeaveIfError( src.Open( fsSession, *buf1, EFileRead | EFileShareReadersOnly ) );
       
   685     User::LeaveIfError( des.Open( fsSession, *buf2, EFileWrite | EFileShareExclusive ) );
       
   686     TTime mod;
       
   687     int err = src.Modified( mod );;
       
   688     if ( err == FmErrNone ) {
       
   689         err = des.SetModified( mod );    
       
   690     }
       
   691     TUint att( 0 );
       
   692     if ( err == FmErrNone ) {
       
   693         err = src.Att( att );        
       
   694     }
       
   695     if ( err == FmErrNone ) {
       
   696         des.SetAtt( att, ( ~att ) & KEntryAttMaskSupported );
       
   697     }    
       
   698     src.Close();
       
   699     des.Close();
       
   700     fsSession.Close();
       
   701     CleanupStack::PopAndDestroy(); // fsSession
       
   702     return err;
       
   703 }
       
   704 
       
   705 /*!
       
   706     judge whether there is enough space on \a targetDrive for \a size.
       
   707     return true if has, false if not.
       
   708 */
       
   709 bool FmUtils::hasEnoughSpace( const QString &targetDrive, qint64 size )
       
   710 {
       
   711     RFs fsSession;
       
   712     QT_TRAP_THROWING( fsSession.Connect() ); 
       
   713     CleanupClosePushL( fsSession );
       
   714     TInt dstDrv(0);
       
   715     HBufC* hbuf = XQConversions::qStringToS60Desc( targetDrive );
       
   716     QT_TRAP_THROWING( RFs::CharToDrive( hbuf->operator [](0), dstDrv ) );
       
   717     bool ret = !SysUtil::DiskSpaceBelowCriticalLevelL( &fsSession,  size , dstDrv );
       
   718     CleanupStack::PopAndDestroy(); // fsSession
       
   719     return ret;
       
   720     
       
   721 }
       
   722 
       
   723 /*!
       
   724     move one file insice the same drive, from \a source to \a target.
       
   725     return KErrNone if successful, otherwise one of the other system-wide error codes.
       
   726 */
       
   727 int FmUtils::moveInsideDrive( const QString &source, const QString &target )
       
   728 {
       
   729     RFs fsSession;
       
   730     QT_TRAP_THROWING( fsSession.Connect() ); 
       
   731     CleanupClosePushL( fsSession );
       
   732     HBufC* oldName = XQConversions::qStringToS60Desc( source );
       
   733     HBufC* newName = XQConversions::qStringToS60Desc( target );
       
   734     int ret = fsSession.Rename( *oldName, *newName );
       
   735     CleanupStack::PopAndDestroy(); // fsSession
       
   736     return ret;    
       
   737 }
       
   738 
       
   739 /*!
       
   740    Launch a file with associated application.
       
   741 */
       
   742 int FmUtils::launchFile( const QString &filePath )
       
   743 
       
   744 {
       
   745     QFile file( filePath );
       
   746     if( !file.exists() ) {
   624         return false;
   747         return false;
   625     }
   748     }
   626     return true;
   749         
   627 }
       
   628 
       
   629 QString FmUtils::checkDriveToFolderFilter( const QString &path )
       
   630 {
       
   631     /*
       
   632     QFileInfo fileInfo( path );
       
   633     if( !fileInfo.exists() ) {
       
   634             return QString();
       
   635         }
       
   636     */
       
   637     QString checkedPath = fillPathWithSplash( path );
       
   638     if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) {
       
   639         checkedPath += QString( "data/" );
       
   640         return checkedPath;
       
   641     }
       
   642     return path;
       
   643 
       
   644 }
       
   645 
       
   646 QString FmUtils::checkFolderToDriveFilter( const QString &path )
       
   647 {
       
   648     QString logString;
       
   649     logString = QString( "checkFolderToDriveFilter: " ) + path;
       
   650     FmLogger::log( logString );
       
   651     QString checkedPath = fillPathWithSplash( path );
       
   652 
       
   653     logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
       
   654     FmLogger::log( logString );
       
   655     
       
   656     if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) {
       
   657         FmLogger::log( QString( " change from c:/data/ to C:/" ) );
       
   658         return QString( "C:/" );
       
   659     }
       
   660     return path;
       
   661 
       
   662 }
       
   663 
       
   664 bool FmUtils::isPathAccessabel( const QString &path )
       
   665 {
       
   666     FmLogger::log( QString( "isPathAccessabel:" ) + path );
       
   667     if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive
       
   668         FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
       
   669         return false;
       
   670     }
       
   671     QFileInfo fileInfo( path );
       
   672     if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) &&
       
   673         !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) {
       
   674         FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
       
   675         return false;
       
   676     }
       
   677     if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) {
       
   678         FmLogger::log( QString( "isPathAccessabel false: path contain D" ) );
       
   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     }
       
   685     if( !fileInfo.exists() ) {
       
   686         FmLogger::log( QString( "isPathAccessabel false: path not exist" ) );
       
   687         return false;
       
   688     }
       
   689     FmLogger::log( QString( "isPathAccessabel true" ) );
       
   690     return true;
       
   691 }
       
   692 
       
   693 // only used to check drive, when MMC is not inserted, also return false
       
   694 bool FmUtils::isDriveAvailable( const QString &path )
       
   695 {
       
   696     FmLogger::log( QString( "isDriveAvailable:" ) + path );
       
   697     FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
       
   698     if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
       
   699         FmLogger::log( QString( "isDriveAvailable true" ) );
       
   700         return true;
       
   701     }
       
   702     FmLogger::log( QString( "isDriveAvailable false" ) );
       
   703     return false;
       
   704 }
       
   705 
       
   706 void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive )
       
   707 {
       
   708     if( isHideUnAvailableDrive ) {
       
   709         FmLogger::log( QString( "getDriveList HideUnAvailableDrive_true" ) );
       
   710     } else {
       
   711         FmLogger::log( QString( "getDriveList HideUnAvailableDrive_false" ) );
       
   712     }
       
   713     QFileInfoList infoList = QDir::drives();
       
   714 
       
   715     foreach( QFileInfo fileInfo, infoList ) {
       
   716         QString driveName = fileInfo.absolutePath();
       
   717         if( checkDriveFilter( driveName ) ) {
       
   718             if( !isHideUnAvailableDrive ) {
       
   719                 driveList.append( driveName );
       
   720             }
       
   721             else if ( isDriveAvailable( driveName ) ) {
       
   722                 driveList.append( driveName );
       
   723             }
       
   724         }
       
   725     }
       
   726     return;
       
   727 }
       
   728 
       
   729 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
       
   730 {
       
   731     QString ret;
       
   732     QString tempDriveName = fillPathWithSplash( driveName );
       
   733 
       
   734     ret = removePathSplash( driveName );
       
   735     
       
   736     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
       
   737     QString volumeName = driverInfo.volumeName();
       
   738 
       
   739     if( volumeName.isEmpty() && isFillWithDefaultVolume ){
       
   740     FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState();
       
   741         if( driveState & FmDriverInfo::EDriveAvailable ){
       
   742             if( driveState & FmDriverInfo::EDriveRemovable ) {
       
   743                 if( driveState & FmDriverInfo::EDriveMassStorage ) {
       
   744                     volumeName.append( QObject::tr( "Mass Storage" ) );  
       
   745                 }
       
   746                 else{
       
   747                     volumeName.append( QObject::tr( "Memory Card" ) );
       
   748                 }
       
   749             }
       
   750             else{
       
   751                 volumeName.append( QObject::tr( "Phone Memory" ) );
       
   752             }
       
   753         }
       
   754     }
       
   755 
       
   756     ret += QString( " " ) + volumeName;
       
   757     return ret;
       
   758 }
       
   759 
       
   760 int FmUtils::launchFile( const QString &filePath )
       
   761 {
       
   762     QFile file( filePath );
       
   763     XQApplicationManager mAiwMgr;
   750     XQApplicationManager mAiwMgr;
   764     XQAiwRequest *request = mAiwMgr.create(file);
   751     XQAiwRequest *request = mAiwMgr.create(file);
   765     if ( request == 0 ) {
   752     if ( request == 0 ) {
   766         // No handlers for the URI
   753         // No handlers for the URI
   767         return FmErrUnKnown;
   754         return FmErrUnKnown;
   785     
   772     
   786     delete request;
   773     delete request;
   787     return FmErrNone;
   774     return FmErrNone;
   788 }
   775 }
   789 
   776 
       
   777 /*!
       
   778     Send files( \a filePathList ) with share ui.
       
   779 */
   790 void FmUtils::sendFiles( QStringList &filePathList )
   780 void FmUtils::sendFiles( QStringList &filePathList )
   791 {
   781 {
   792     ShareUi shareui;
   782     ShareUi shareui;
   793     shareui.send( filePathList, false );
   783     shareui.send( filePathList, false );
   794 }
   784 }
   795 
   785 
       
   786 /*!
       
   787     return path for backup restore config file.
       
   788     Currently \a appPath is not used.
       
   789 */
   796 QString FmUtils::getBurConfigPath( QString appPath )
   790 QString FmUtils::getBurConfigPath( QString appPath )
   797 {
   791 {
   798     Q_UNUSED( appPath );
   792     Q_UNUSED( appPath );
   799     QString path( BURCONFIGFILE );
   793     QString path( BURCONFIGFILE );
   800     return path;
   794     return path;
   801 }
   795 }
   802 
   796 
   803 bool FmUtils::isPathEqual( const QString &pathFst, const QString &pathLast )
   797 /*!
   804 {
   798     return MetaData string for \a filePath
   805     QString fst( fillPathWithSplash( pathFst ) );
   799 */
   806     QString last( fillPathWithSplash( pathLast ) );
   800 QString FmUtils::getFileType( const QString &filePath  )
   807     if( fst.compare( last, Qt::CaseInsensitive ) == 0 ) {
   801 {
       
   802     RApaLsSession apaSession;
       
   803     TDataType dataType;
       
   804     TUid appUid;
       
   805     
       
   806     TBuf<128> mimeTypeBuf;
       
   807         
       
   808     int err = apaSession.Connect();
       
   809     
       
   810     if ( err == KErrNone ){   
       
   811         err = apaSession.AppForDocument( XQConversions::qStringToS60Desc( filePath )->Des(), 
       
   812                                          appUid, dataType );
       
   813         
       
   814         if( err == KErrNone ){
       
   815             mimeTypeBuf.Copy(dataType.Des8());
       
   816         }  
       
   817     }
       
   818     
       
   819     apaSession.Close();
       
   820     return XQConversions::s60DescToQString( mimeTypeBuf );
       
   821 }
       
   822 
       
   823 /*!
       
   824     Check if drive \a driveName is drive C
       
   825 */
       
   826 bool FmUtils::isDriveC( const QString &driveName )
       
   827 {
       
   828     if( driveName.isEmpty() ) {
       
   829         return false;
       
   830     }
       
   831     TInt drive = 0;
       
   832     drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   833     if( drive == EDriveC ){
   808         return true;
   834         return true;
   809     }
   835     }
   810     return false;
   836     else{
   811 }
   837         return false;
   812 
   838     }
   813 bool FmUtils::isDefaultFolder( const QString &folderPath  )
   839    
   814 {
   840 }
   815     TPtrC desFolderPath( XQConversions::qStringToS60Desc( folderPath )->Des() );
   841 
   816     
   842 /*!
   817     TInt pathType( PathInfo::PathType( desFolderPath ) );
   843     return max file name length
   818     switch( pathType ){
   844 */
   819        case PathInfo::ENotSystemPath:{
   845 int FmUtils::getMaxFileNameLength()
   820            QString locString( Localize( folderPath ) );
   846 {
   821             if ( locString.isEmpty() ){
   847     return KMaxFileName;
   822                 return false;
   848 }
   823             }
   849 
   824             return true;
   850 /*!
   825             }
   851     Check if length of \a path is exceed max path length. 
   826         case PathInfo::EPhoneMemoryRootPath: // FALL THROUGH
   852 */
   827         case PathInfo::EMemoryCardRootPath: // FALL THROUGH
   853 bool FmUtils::checkMaxPathLength( const QString& path )
   828         case PathInfo::ERomRootPath:{
   854 {
   829             return false;
   855     if( path.length() > KMaxPath ) {
   830         }
   856         return false;
   831         // Accept other folders
   857     }
   832         default:{
   858     return true;
   833             return true;
   859 }
   834         }
       
   835     }
       
   836 }
       
   837 
       
   838 QString FmUtils::Localize( const QString &path )
       
   839 {
       
   840     QString locPath = formatPath( path );
       
   841 
       
   842     TPtrC desPath( XQConversions::qStringToS60Desc( locPath )->Des() );
       
   843     CDirectoryLocalizer *localizer = CDirectoryLocalizer::NewL();
       
   844 
       
   845     localizer->SetFullPath( desPath );
       
   846     if( localizer->IsLocalized() ){   
       
   847         return XQConversions::s60DescToQString( localizer->LocalizedName() );
       
   848     }
       
   849     
       
   850     return QString();
       
   851 }
       
   852 
       
   853 QString FmUtils::formatPath( const QString &path  )
       
   854 {
       
   855     QString formatPath = path;
       
   856     QRegExp regExp( "/" );
       
   857     formatPath.replace( regExp, "\\" );
       
   858     
       
   859     if( path.right( 1 )!= "\\"){
       
   860         formatPath.append( "\\" );
       
   861     }
       
   862     return formatPath;
       
   863 }