filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp
changeset 48 1bebd60c0f00
parent 35 060d0b1ab845
equal deleted inserted replaced
44:22e202702210 48:1bebd60c0f00
    17 
    17 
    18 #include "fmoperationformat.h"
    18 #include "fmoperationformat.h"
    19 #include "fmcommon.h"
    19 #include "fmcommon.h"
    20 #include "fmoperationbase.h"
    20 #include "fmoperationbase.h"
    21 #include "fmutils.h"
    21 #include "fmutils.h"
       
    22 #include "fmviewmanager.h"
       
    23 #include "fmserviceutils.h"
    22 
    24 
    23 #include <QString>
    25 #include <QString>
       
    26 #include <QSettings>
    24 
    27 
    25 #include <f32file.h>
    28 #include <f32file.h>
    26 #include <e32property.h>
    29 #include <e32property.h>
    27 #include <coreapplicationuisdomainpskeys.h>
    30 #include <coreapplicationuisdomainpskeys.h>
    28 
    31 
    69     
    72     
    70     if( mDriverName.isEmpty() ) {
    73     if( mDriverName.isEmpty() ) {
    71         emit notifyError( FmErrWrongParam, QString() );
    74         emit notifyError( FmErrWrongParam, QString() );
    72         return;
    75         return;
    73     }
    76     }
       
    77     FmViewManager::viewManager()->serviceUtils()->closeApps();
       
    78     
    74     
    79     
    75     RFormat format;
    80     RFormat format;
    76     
    81     
    77     RFs fs;
    82     RFs fs;
    78     int err = fs.Connect();
    83     int err = fs.Connect();
    82         return;
    87         return;
    83     }
    88     }
    84 
    89 
    85     TInt drive = 0;
    90     TInt drive = 0;
    86     drive = mDriverName[0].toUpper().toAscii() - 'A' + EDriveA;
    91     drive = mDriverName[0].toUpper().toAscii() - 'A' + EDriveA;
    87 
    92     // save volume name for MassStorage
       
    93     storeVolumeName( drive );
       
    94     
    88     TDriveName formatDriveName( TDriveUnit( drive ).Name() );
    95     TDriveName formatDriveName( TDriveUnit( drive ).Name() );
    89 
    96 
    90     int finalValue = 0;
    97     int finalValue = 0;
    91     
    98     
    92     format.Close();
    99     format.Close();
   194     
   201     
   195     if( !finalValue || err != KErrNone ){
   202     if( !finalValue || err != KErrNone ){
   196         format.Close();        
   203         format.Close();        
   197         fs.Close();
   204         fs.Close();
   198         
   205         
       
   206         // restore volume name for MassStorage
       
   207         restoreVolumeName( drive );
   199         FmUtils::createDefaultFolders( mDriverName );
   208         FmUtils::createDefaultFolders( mDriverName );
   200     }
   209     }
   201 
   210 
   202     if( err == KErrNone ){
   211     FmViewManager::viewManager()->serviceUtils()->restartApps();
   203         emit notifyFinish();        
   212     
   204     }
       
   205     else{
       
   206         emit notifyError( FmErrTypeFormatFailed, QString() );
       
   207     }
       
   208     // refresh drive space no care if cancel, error or finished.
   213     // refresh drive space no care if cancel, error or finished.
   209     // as filemanger cannot notify drive space changed
   214     // as filemanger cannot notify drive space changed
   210     // do not refresh path as QFileSystemModel will do auto-refresh
   215     // do not refresh path as QFileSystemModel will do auto-refresh
   211     emit driveSpaceChanged();    
   216     emit driveSpaceChanged();   
   212     
   217     if( err == KErrNone ){
   213 }
   218         emit notifyFinish();        
       
   219     }
       
   220     else{
       
   221         emit notifyError( FmErrTypeFormatFailed, QString() );
       
   222     }
       
   223 }
       
   224 
       
   225 void FmOperationFormat::storeVolumeName( int drive )
       
   226 {
       
   227     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( FmUtils::numberToDriveName( drive ) );
       
   228     if ( driverInfo.driveType() == FmDriverInfo::EDriveTypeMassStorage )
       
   229     {
       
   230         QString volumeName( driverInfo.volumeName() );
       
   231         QSettings settings( "Nokia", "FileManager" );
       
   232         settings.beginGroup( "Settings" );
       
   233         settings.setValue( "MassStorageDriveNumber", drive );
       
   234         settings.setValue( "MassStorageVolumeName", volumeName );
       
   235         settings.endGroup();
       
   236     }
       
   237 }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CFileManagerEngine::RestoreVolumeNameL()
       
   241 //
       
   242 // -----------------------------------------------------------------------------
       
   243 //  
       
   244 void FmOperationFormat::restoreVolumeName( int drive )
       
   245 {
       
   246 
       
   247     FmDriverInfo driveInfo = FmUtils::queryDriverInfo( FmUtils::numberToDriveName( drive ));
       
   248     if ( driveInfo.driveType() == FmDriverInfo::EDriveTypeMassStorage )
       
   249     {
       
   250         QSettings settings("Nokia", "FileManager");
       
   251         settings.beginGroup("Settings");
       
   252         int massStorageDriveNumber    = settings.value( "MassStorageDriveNumber", -1 ).toInt();
       
   253         QString massStorageVolumeName = settings.value( "MassStorageVolumeName", QString() ).toString();
       
   254         settings.endGroup();
       
   255     
       
   256         if ( ( !massStorageVolumeName.isEmpty() ) &&
       
   257                 ( massStorageDriveNumber == drive ) )
       
   258         {
       
   259             FmUtils::renameDrive( FmUtils::numberToDriveName( drive ), massStorageVolumeName );
       
   260         }
       
   261     }
       
   262 }