filemanager/src/inc/fmutils_s60.cpp
changeset 14 1957042d8c7e
child 16 ada7962b4308
equal deleted inserted replaced
1:d1daf54a55b5 14:1957042d8c7e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *     Zhiqiang Yang <zhiqiang.yang@nokia.com>
       
    14 * 
       
    15 * Description:
       
    16 *     The source file of the file manager utilities
       
    17 */
       
    18 
       
    19 
       
    20 #include "fmutils.h"
       
    21 #include "fms60utils.h"
       
    22 #include "fmcommon.h"
       
    23 
       
    24 #include <QRegExp>
       
    25 
       
    26 #include <coemain.h>
       
    27 #include <driveinfo.h>
       
    28 #include <e32property.h>
       
    29 #include <coreapplicationuisdomainpskeys.h>
       
    30 #include <f32file.h>
       
    31 #include <apgcli.h>
       
    32 #include <pathinfo.h>
       
    33 #include <XQConversions>
       
    34 #include <QStringList>
       
    35 #include <QFileInfoList>
       
    36 #include <QDir>
       
    37 #include <QFile>
       
    38 
       
    39 #include <xqaiwrequest.h>
       
    40 #include <xqappmgr.h>
       
    41 
       
    42 #include <shareuidialog.h>
       
    43 
       
    44 #define BURCONFIGFILE  "z:/private/2002BCC0/burconfig.xml"
       
    45 
       
    46 QString FmUtils::getDriveNameFromPath( const QString &path )
       
    47 {
       
    48     if( path.length() <3 ) {
       
    49         return QString();
       
    50     }
       
    51     return path.left( 3 );
       
    52 }
       
    53 
       
    54 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
       
    55 {
       
    56 	CCoeEnv *env = CCoeEnv::Static();
       
    57 	RFs& fs = env->FsSession();
       
    58 
       
    59 	TVolumeInfo volumeInfo;
       
    60 	TInt drive = 0;
       
    61 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
    62 
       
    63 	fs.Volume( volumeInfo, drive );
       
    64     QString volumeName( (QChar*)( volumeInfo.iName.Des().Ptr() ), volumeInfo.iName.Length() );
       
    65 	
       
    66 	return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driverName, volumeName );
       
    67 }
       
    68 
       
    69 QString FmUtils::formatStorageSize( quint64 size )
       
    70 {
       
    71 	if ( size < 1000 ) {
       
    72 		return QString::number( size ) + " B";
       
    73 	} else if ( size < 1000 * 1000 ) {
       
    74 		return QString::number( size / 1024.0, 'f', 2 ) + " KB";
       
    75 	} else if ( size < 1000 * 1000 * 1000 ) {
       
    76 		return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB";
       
    77 	} else {
       
    78 	    return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB";	    
       
    79 	}
       
    80 }
       
    81 quint32 FmUtils::getDriverState( const QString &driverName )
       
    82 {    
       
    83     quint32 state( 0 );
       
    84     CCoeEnv *env = CCoeEnv::Static();
       
    85 	RFs& fs = env->FsSession();
       
    86 
       
    87 	TVolumeInfo volumeInfo;
       
    88 	TInt drive = 0;
       
    89 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
    90 
       
    91 	int err = fs.Volume( volumeInfo, drive );
       
    92 
       
    93 	//handle error code
       
    94 	if( err != KErrNone ) {
       
    95             state |= FmDriverInfo::EDriveNotPresent;
       
    96 	}
       
    97 	if ( err == KErrLocked ) {
       
    98             state |= FmDriverInfo::EDriveLocked;
       
    99 	}
       
   100 	
       
   101     TDriveInfo driveInfo = volumeInfo.iDrive;
       
   102 
       
   103     quint32 drvStatus( 0 );
       
   104     DriveInfo::GetDriveStatus( fs, drive, drvStatus );
       
   105 
       
   106     QString logString = driverName +':'+ QString::number( drvStatus);
       
   107     FmLogger::log(logString);
       
   108     
       
   109     if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
       
   110          ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
       
   111         // Handle mass storage bits here
       
   112 
       
   113         state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable;
       
   114     }
       
   115 
       
   116     
       
   117     if ( drvStatus & DriveInfo::EDriveRom ){
       
   118         state |= FmDriverInfo::EDriveRom;  
       
   119     }
       
   120     
       
   121     if ( drvStatus & DriveInfo::EDriveRam ){
       
   122         state |= FmDriverInfo::EDriveRam;  
       
   123     }
       
   124 
       
   125     if ( driveInfo.iMediaAtt & KMediaAttFormattable ){
       
   126         state |= FmDriverInfo::EDriveFormattable;
       
   127     }
       
   128     if ( driveInfo.iMediaAtt & KMediaAttWriteProtected ){
       
   129         state |= FmDriverInfo::EDriveWriteProtected;
       
   130     }
       
   131     if ( driveInfo.iMediaAtt & KMediaAttHasPassword ){
       
   132         state |= FmDriverInfo::EDrivePasswordProtected;
       
   133     }    
       
   134     if ( driveInfo.iMediaAtt & KMediaAttLocked ){
       
   135         state |= FmDriverInfo::EDriveLocked;
       
   136     }
       
   137 
       
   138     if ( driveInfo.iDriveAtt & KDriveAttRemovable ){
       
   139         state |= FmDriverInfo::EDriveRemovable;
       
   140 
       
   141         if ( drvStatus & DriveInfo::EDriveSwEjectable ){
       
   142             state |= FmDriverInfo::EDriveEjectable;
       
   143         }
       
   144     }
       
   145     
       
   146     if( driveInfo.iType == EMediaNotPresent ){
       
   147         state |= FmDriverInfo::EDriveNotPresent;    
       
   148     }
       
   149     
       
   150     return state;
       
   151 
       
   152 }
       
   153 
       
   154 int FmUtils::removeDrivePwd( const QString &driverName,  const QString &Pwd )
       
   155 {
       
   156     QString logString = "Drive name:" + driverName;
       
   157     FmLogger::log( logString );
       
   158     logString = "Password:" + Pwd;
       
   159     FmLogger::log( logString );
       
   160 
       
   161     CCoeEnv *env = CCoeEnv::Static();
       
   162 	RFs& fs = env->FsSession();
       
   163 
       
   164     TInt drive = 0;
       
   165 
       
   166 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   167 
       
   168     HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
       
   169     TMediaPassword password;   
       
   170     TPtr ptrPassword16( password16->Des() );  
       
   171     FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
       
   172 
       
   173     int err( fs.ClearPassword( drive, password ) );
       
   174 
       
   175     logString = "Drive:" + QString::number( drive );
       
   176     FmLogger::log( logString );
       
   177 
       
   178     logString = "Clear password error:" + QString::number( err );
       
   179     FmLogger::log( logString );
       
   180 
       
   181     return err;
       
   182 }
       
   183 
       
   184 int FmUtils::unlockDrive( const QString &driverName,  const QString &Pwd )
       
   185 {
       
   186     QString logString = "Drive name:" + driverName;
       
   187     FmLogger::log( logString );
       
   188     logString = "Password:" + Pwd;
       
   189     FmLogger::log( logString );
       
   190 
       
   191     CCoeEnv *env = CCoeEnv::Static();
       
   192 	RFs& fs = env->FsSession();
       
   193 
       
   194     TInt drive = 0;
       
   195 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   196     
       
   197     HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
       
   198     TMediaPassword password;   
       
   199     TPtr ptrPassword16( password16->Des() );  
       
   200     FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
       
   201 
       
   202     int err( fs.UnlockDrive( drive, password, ETrue) );
       
   203 
       
   204     logString = "Drive:" + QString::number( drive );
       
   205     FmLogger::log( logString );
       
   206     logString = "Unlock drive error:" + QString::number( err );
       
   207     FmLogger::log( logString );
       
   208 
       
   209     return err;
       
   210 }
       
   211 
       
   212 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
       
   213 {
       
   214     QString logString = "Drive name:" + driverName;
       
   215     FmLogger::log( logString );
       
   216     logString = "Old password:" + oldPwd;
       
   217     FmLogger::log( logString );
       
   218     logString = "New password:" + newPwd;
       
   219     FmLogger::log( logString );
       
   220 
       
   221     CCoeEnv *env = CCoeEnv::Static();
       
   222 	RFs& fs = env->FsSession();
       
   223 
       
   224     TInt drive = 0;
       
   225 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   226 	
       
   227     HBufC* newPassword16 = XQConversions::qStringToS60Desc( newPwd);
       
   228     HBufC* oldPassword16 = XQConversions::qStringToS60Desc( oldPwd );
       
   229 
       
   230     TMediaPassword oldPassword;
       
   231     TMediaPassword newPassword;
       
   232     
       
   233     TPtr ptrNewPassword16( newPassword16->Des() );
       
   234     TPtr ptrOldPassword16( oldPassword16->Des() );
       
   235     
       
   236     FmS60Utils::ConvertCharsToPwd( ptrNewPassword16, newPassword );
       
   237     FmS60Utils::ConvertCharsToPwd( ptrOldPassword16, oldPassword );
       
   238 
       
   239     //oldPassword.FillZ(oldPassword.MaxLength());
       
   240     //oldPassword.Zero();
       
   241     //newPassword.Copy(_L8("A"));
       
   242 
       
   243     int err( fs.LockDrive( drive, oldPassword, newPassword, ETrue ) );
       
   244 
       
   245     logString = "Drive:" + QString::number( drive );
       
   246     FmLogger::log( logString );
       
   247     logString = "Password set error:" + QString::number( err );
       
   248     FmLogger::log( logString );
       
   249 
       
   250     return err;
       
   251 }
       
   252 
       
   253 void FmUtils::emptyPwd( QString &pwd )
       
   254 {
       
   255     TPtr des ( ( XQConversions::qStringToS60Desc( pwd ) )->Des() );
       
   256     des.FillZ( des.MaxLength() );
       
   257     des.Zero();
       
   258     pwd = XQConversions::s60DescToQString( des );
       
   259 }
       
   260 
       
   261 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
       
   262 {
       
   263     CCoeEnv *env = CCoeEnv::Static();
       
   264 	RFs& fs = env->FsSession();
       
   265 
       
   266     TInt drive = 0;
       
   267 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   268 
       
   269     TPtr newName ( ( XQConversions::qStringToS60Desc( newVolumeName ) )->Des() );
       
   270 
       
   271     int err( fs.SetVolumeLabel( newName, drive ));
       
   272     
       
   273     QString logString = "Rename error:" + QString::number( err );
       
   274     FmLogger::log( logString );
       
   275 
       
   276     return err;
       
   277 }
       
   278 
       
   279 int FmUtils::ejectDrive( const QString &driverName )
       
   280 {
       
   281     CCoeEnv *env = CCoeEnv::Static();
       
   282     RFs& fs = env->FsSession();
       
   283 
       
   284     TInt drive = 0;
       
   285 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   286 
       
   287     const int KDriveShift = 16;
       
   288     
       
   289     TFileName fileSystemName;
       
   290     TInt err = fs.FileSystemName( fileSystemName, drive );
       
   291 
       
   292     RProperty::Set(
       
   293         KPSUidCoreApplicationUIs,
       
   294         KCoreAppUIsMmcRemovedWithoutEject,
       
   295         ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
       
   296         );
       
   297     
       
   298     err = fs.DismountFileSystem( fileSystemName, drive );
       
   299     
       
   300     if (err == KErrNone){
       
   301         // remount the file system
       
   302         err = fs.MountFileSystem( fileSystemName, drive );
       
   303         
       
   304         if (err == KErrInUse){
       
   305             // try to remount after a while if locked
       
   306             User::After(1000000);
       
   307             err = fs.MountFileSystem( fileSystemName, drive );
       
   308         }                
       
   309     }
       
   310     
       
   311     return err;
       
   312 }
       
   313 
       
   314 int FmUtils::formatDrive( const QString &driverName )
       
   315 {
       
   316     RFormat format;
       
   317 
       
   318 //    CCoeEnv *env = CCoeEnv::Static();
       
   319 //	RFs& fs = env->FsSession();
       
   320     
       
   321     RFs fs;
       
   322     int err = fs.Connect();
       
   323     
       
   324     if( err != KErrNone ){
       
   325         return FmErrTypeFormatFailed;
       
   326     }
       
   327 
       
   328     TInt drive = 0;
       
   329 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   330 
       
   331     TDriveName formatDriveName( TDriveUnit( drive ).Name() );
       
   332 
       
   333     int finalValue = 0;
       
   334     
       
   335     format.Close();
       
   336 
       
   337     err = format.Open(
       
   338         fs, formatDriveName, EFullFormat | ESpecialFormat, finalValue );
       
   339     
       
   340     QString logString = "Format open error:" + QString::number( err );
       
   341     FmLogger::log( logString );
       
   342     
       
   343     if( err == KErrLocked ){
       
   344         err = fs.ErasePassword( drive );
       
   345         
       
   346         logString = "ErasePassword error:" + QString::number( err );
       
   347         FmLogger::log( logString );
       
   348         
       
   349         if( err == KErrNone ){
       
   350             err = format.Open(
       
   351                fs, formatDriveName, EFullFormat, finalValue ); 
       
   352             
       
   353             logString = "Second format open error:" + QString::number( err );
       
   354             FmLogger::log( logString );
       
   355         }
       
   356     }
       
   357     
       
   358     if (err == KErrInUse){
       
   359         TBool reallyFormat = ETrue;
       
   360         if (reallyFormat)
       
   361             {
       
   362             err = format.Open(
       
   363                     fs, formatDriveName, EFullFormat | EForceFormat, finalValue );
       
   364             
       
   365             logString = "Reallyformat open error:" + QString::number( err );
       
   366             FmLogger::log( logString );
       
   367             }
       
   368     }
       
   369     
       
   370     TFullName fsName;
       
   371     if ( err == KErrNone )
       
   372         {
       
   373         err = fs.FileSystemName( fsName, drive  );
       
   374         
       
   375         logString = "FileSystemName error:" + QString::number( err );
       
   376         FmLogger::log( logString );
       
   377 
       
   378         if ( err == KErrNone && fsName.Length() > 0 )
       
   379             {
       
   380             // Prevent SysAp shutting down applications
       
   381             RProperty::Set(
       
   382                     KPSUidCoreApplicationUIs,
       
   383                     KCoreAppUIsMmcRemovedWithoutEject,
       
   384                     ECoreAppUIsEjectCommandUsed );
       
   385             
       
   386             logString = "Prevent SysAp shutting down applications" ;
       
   387             FmLogger::log( logString );
       
   388             }
       
   389         else
       
   390             {
       
   391             // Don't continue with format if there is no file system name
       
   392             // or file system name could not be obtained.
       
   393             err = KErrCancel;
       
   394             
       
   395             logString = "Format cancel:" + QString::number( err );
       
   396             FmLogger::log( logString );
       
   397             }
       
   398         }
       
   399     
       
   400     if( err == KErrNone &&  finalValue ){
       
   401     
       
   402         while ( finalValue ){        
       
   403             logString = "Format tracks:" + QString::number( finalValue );
       
   404             FmLogger::log( logString );
       
   405             
       
   406             err = format.Next( finalValue );
       
   407             
       
   408             if( err != KErrNone ){ 
       
   409                 logString = "Format error:" + QString::number( err );
       
   410                 FmLogger::log( logString );
       
   411                 break; 
       
   412             }
       
   413         }
       
   414     }
       
   415     
       
   416     if( !finalValue || err != KErrNone ){
       
   417         format.Close();        
       
   418         fs.Close();
       
   419         
       
   420         createDefaultFolders( driverName );
       
   421     }
       
   422 
       
   423     return FmErrNone;
       
   424 }
       
   425 
       
   426 QString FmUtils::getFileType( const QString &filePath  )
       
   427 {
       
   428     RApaLsSession apaSession;
       
   429     TDataType dataType;
       
   430     TUid appUid;
       
   431     
       
   432     TBuf<128> mimeTypeBuf;
       
   433         
       
   434     int err = apaSession.Connect();
       
   435     
       
   436     if ( err == KErrNone ){   
       
   437         err = apaSession.AppForDocument( XQConversions::qStringToS60Desc( filePath )->Des(), 
       
   438                                          appUid, dataType );
       
   439         
       
   440         if( err == KErrNone ){
       
   441             mimeTypeBuf.Copy(dataType.Des8());
       
   442         }  
       
   443     }
       
   444     
       
   445     apaSession.Close();
       
   446     return XQConversions::s60DescToQString( mimeTypeBuf );
       
   447 }
       
   448 
       
   449 quint64 FmUtils::getDriveDetailsResult( const QString &folderPath, const QString &extension )
       
   450 {
       
   451     int err;
       
   452 //    CCoeEnv *env = CCoeEnv::Static();
       
   453 //    RFs& fs = env->FsSession();
       
   454     
       
   455     RFs fs;
       
   456     err = fs.Connect();
       
   457     
       
   458     QString string( folderPath );
       
   459     
       
   460     QRegExp regExp( "/" );
       
   461     string.replace( regExp, "\\" );
       
   462     
       
   463     if( string.right( 1 )!= "\\"){
       
   464         string.append( "\\" );
       
   465     }
       
   466 
       
   467     TPtrC desFolderPath( XQConversions::qStringToS60Desc( string )->Des() );
       
   468     TPtrC ptrExtension( XQConversions::qStringToS60Desc( extension )->Des() );
       
   469     
       
   470     CDir* results = 0;
       
   471     TParse parse;
       
   472     
       
   473     quint64 size = 0;
       
   474     
       
   475     const TInt pathlength = ptrExtension.Length() + desFolderPath.Length();
       
   476     
       
   477     if ( pathlength > KMaxFileName ){
       
   478         err = KErrNotFound;   
       
   479     }
       
   480     else{
       
   481         err = fs.Parse( ptrExtension, desFolderPath, parse );
       
   482         err = fs.GetDir( parse.FullName(), KEntryAttMaskSupported|KEntryAttAllowUid, 
       
   483             ESortNone, results );
       
   484         
       
   485         TDesC des = parse.FullName();
       
   486         
       
   487         if (err == KErrNotFound)
       
   488             {
       
   489             return 0;
       
   490             }
       
   491     }
       
   492     
       
   493     if ( results ){
       
   494         CleanupStack::PushL(results);
       
   495 
       
   496         // Go through all files in the list and tell subclass
       
   497         TFileName file;
       
   498         const TInt count = results->Count();
       
   499         for( TInt i=0; i<count; ++i ){
       
   500             const TEntry& entry = (*results)[i];
       
   501             file = desFolderPath;
       
   502             file += entry.iName;
       
   503             size += entry.iSize;          
       
   504         }
       
   505         CleanupStack::PopAndDestroy(results);
       
   506     }
       
   507     
       
   508     fs.Close();
       
   509     
       
   510     return size;  
       
   511 }
       
   512 
       
   513 bool FmUtils::isDriveC( const QString &driverName )
       
   514 {
       
   515     TInt drive = 0;
       
   516     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   517     if( drive == EDriveC ){
       
   518         return true;
       
   519     }
       
   520     else{
       
   521         return false;
       
   522     }
       
   523    
       
   524 }
       
   525 
       
   526 void FmUtils::createDefaultFolders( const QString &driverName )
       
   527 {
       
   528     int err;
       
   529     
       
   530     TInt drive = 0;
       
   531     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   532     
       
   533     RFs fs;
       
   534     err = fs.Connect();
       
   535     
       
   536     if( err != KErrNone ){
       
   537         return;
       
   538     }
       
   539     
       
   540     quint32 drvStatus( 0 );
       
   541     err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
       
   542     if ( !( drvStatus & DriveInfo::EDriveUserVisible ) ||
       
   543         ( drvStatus & ( DriveInfo::EDriveRemote |
       
   544                         DriveInfo::EDriveReadOnly |
       
   545                         DriveInfo::EDriveUsbMemory ) ) ){
       
   546             return; 
       
   547         }
       
   548     
       
   549     TEntry entry;
       
   550     CDesCArray* array = PathInfo::GetListOfPathsLC( drive );
       
   551     
       
   552     TInt count( array->MdcaCount() );
       
   553     for ( TInt i( 0 ); i < count; ++i )
       
   554         {
       
   555         TPtrC fullPath( array->MdcaPoint( i ) );
       
   556         TBool allow( ETrue );
       
   557 
       
   558         if ( drvStatus & DriveInfo::EDriveRemovable )
       
   559             {
       
   560             // Filter few folder types from physically removable memory cards
       
   561             TInt pathType( PathInfo::PathType( fullPath ) );
       
   562             switch( pathType )
       
   563                 {
       
   564                 case PathInfo::EGamesPath: // FALL THROUGH
       
   565                 case PathInfo::EInstallsPath: // FALL THROUGH
       
   566                 case PathInfo::EGsmPicturesPath: // FALL THROUGH
       
   567                 case PathInfo::EMmsBackgroundImagesPath: // FALL THROUGH
       
   568                 case PathInfo::EPresenceLogosPath:
       
   569                     {
       
   570                     allow = EFalse;
       
   571                     }
       
   572                 default:
       
   573                     {
       
   574                     break;
       
   575                     }
       
   576                 }
       
   577             }
       
   578 
       
   579         if ( allow ){
       
   580             fs.MkDirAll( fullPath ); // Ignore error
       
   581 
       
   582             if ( fs.Entry( fullPath, entry ) == KErrNone ){
       
   583                 if( entry.IsHidden() ){
       
   584                 // If setting fails, File Manager can still go on
       
   585                     fs.SetEntry(
       
   586                          fullPath, entry.iModified, 0, KEntryAttHidden );
       
   587                 }
       
   588             }
       
   589         }
       
   590     }
       
   591     CleanupStack::PopAndDestroy( array );
       
   592 }
       
   593 
       
   594 QString FmUtils::fillPathWithSplash( const QString &filePath )
       
   595 {
       
   596     QString newFilePath( filePath );
       
   597     if( filePath.isEmpty() ) {
       
   598         return newFilePath;
       
   599     }
       
   600 
       
   601     if( filePath.at( filePath.length()-1 ) != QChar( '/' ) ){
       
   602         newFilePath.append( QChar( '/' ) );
       
   603     }
       
   604     return newFilePath;
       
   605 }
       
   606 
       
   607 QString FmUtils::removePathSplash( const QString &filePath )
       
   608 {
       
   609     QString newFilePath( filePath );
       
   610     if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) {
       
   611         newFilePath = filePath.left( filePath.length() - 1 );
       
   612     }
       
   613     return newFilePath;
       
   614 }
       
   615 
       
   616 bool FmUtils::checkDriveFilter( const QString &driveName )
       
   617 {
       
   618     if( driveName.contains( "D:" ) || driveName.contains( "Z:" ) ) {
       
   619         return false;
       
   620     }
       
   621     return true;
       
   622 }
       
   623 
       
   624 QString FmUtils::checkDriveToFolderFilter( const QString &path )
       
   625 {
       
   626     QFileInfo fileInfo( path );
       
   627     if( !fileInfo.exists() ) {
       
   628             return QString();
       
   629         }
       
   630 
       
   631     QString checkedPath = fillPathWithSplash( path );
       
   632     if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) {
       
   633         checkedPath += QString( "data/" );
       
   634         return checkedPath;
       
   635     }
       
   636     return path;
       
   637 
       
   638 }
       
   639 
       
   640 QString FmUtils::checkFolderToDriveFilter( const QString &path )
       
   641 {
       
   642     QString logString;
       
   643     logString = QString( "checkFolderToDriveFilter: " ) + path;
       
   644     FmLogger::log( logString );
       
   645     QString checkedPath = fillPathWithSplash( path );
       
   646 
       
   647     logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
       
   648     FmLogger::log( logString );
       
   649     
       
   650     if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) {
       
   651         FmLogger::log( QString( " change from c:/data/ to C:/" ) );
       
   652         return QString( "C:/" );
       
   653     }
       
   654     return path;
       
   655 
       
   656 }
       
   657 
       
   658 bool FmUtils::isPathAccessabel( const QString &path )
       
   659 {
       
   660     QFileInfo fileInfo( path );
       
   661     if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) &&
       
   662         !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) {
       
   663         return false;
       
   664     }
       
   665     if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) {
       
   666         return false;
       
   667     }
       
   668     if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) {
       
   669         return false;
       
   670     }
       
   671     if( !fileInfo.exists() ) {
       
   672         return false;
       
   673     }
       
   674     return true;
       
   675 }
       
   676 
       
   677 bool FmUtils::isDriveAvailable( const QString &path )
       
   678 {
       
   679     QFileInfo fileInfo( path );
       
   680     if( !fileInfo.exists() ) {
       
   681         return false;
       
   682     }
       
   683     return true;
       
   684 }
       
   685 
       
   686 void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive )
       
   687 {
       
   688     QFileInfoList infoList = QDir::drives();
       
   689 
       
   690     foreach( QFileInfo fileInfo, infoList ) {
       
   691         QString driveName = fileInfo.absolutePath();
       
   692         if( checkDriveFilter( driveName ) ) {
       
   693             if( !isHideUnAvailableDrive ) {
       
   694                 driveList.append( driveName );
       
   695             }
       
   696             else if ( isDriveAvailable( driveName ) ) {
       
   697                 driveList.append( driveName );
       
   698             }
       
   699         }
       
   700     }
       
   701     return;
       
   702 }
       
   703 
       
   704 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
       
   705 {
       
   706     QString ret;
       
   707     QString tempDriveName = fillPathWithSplash( driveName );
       
   708 
       
   709     ret = removePathSplash( driveName );
       
   710     
       
   711     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
       
   712     QString volumeName = driverInfo.volumeName();
       
   713 
       
   714     if( volumeName.isEmpty() && isFillWithDefaultVolume ){
       
   715         quint32 driveState = FmUtils::getDriverState( tempDriveName );
       
   716         if( !( driveState & FmDriverInfo::EDriveNotPresent ) ){
       
   717             if( driveState & FmDriverInfo::EDriveRemovable ) {
       
   718                 if( driveState & FmDriverInfo::EDriveMassStorage ) {
       
   719                     volumeName.append( QObject::tr( "Mass Storage" ) );  
       
   720                 }
       
   721                 else{
       
   722                     volumeName.append( QObject::tr( "Memory Card" ) );
       
   723                 }
       
   724             }
       
   725             else{
       
   726                 volumeName.append( QObject::tr( "Phone Memory" ) );
       
   727             }
       
   728         }
       
   729     }
       
   730 
       
   731     ret += QString( " " ) + volumeName;
       
   732     return ret;
       
   733 }
       
   734 
       
   735 int FmUtils::launchFile( const QString &filePath )
       
   736 {
       
   737     QFile file( filePath );
       
   738     XQApplicationManager mAiwMgr;
       
   739     XQAiwRequest *request = mAiwMgr.create(file);
       
   740     if ( request == 0 ) {
       
   741         // No handlers for the URI
       
   742         return FmErrUnKnown;
       
   743     }
       
   744     
       
   745     // Set function parameters
       
   746     QList<QVariant> args;
       
   747     args << file.fileName();
       
   748     request->setArguments(args);
       
   749     
       
   750     // Send the request
       
   751     bool res = request->send();
       
   752     if  (!res) 
       
   753     {
       
   754        // Request failed. 
       
   755       int error = request->lastError();
       
   756       
       
   757       delete request;
       
   758       return FmErrUnKnown;
       
   759     }
       
   760     
       
   761     delete request;
       
   762     return FmErrNone;
       
   763 }
       
   764 
       
   765 void FmUtils::sendFiles( QList<QVariant> filePathList )
       
   766 {
       
   767     ShareUi shareui;
       
   768     shareui.init( filePathList, false );
       
   769 }
       
   770 
       
   771 QString FmUtils::getBurConfigPath( QString appPath )
       
   772 {
       
   773     Q_UNUSED( appPath );
       
   774     QString path( BURCONFIGFILE );
       
   775     return path;
       
   776 }