filemanager/src/fmbkupenginewrapper/private/symbian/fmbkupengine_p.cpp
branchRCL_3
changeset 38 491b3ed49290
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
       
     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  *     
       
    14  * 
       
    15  * Description:
       
    16  *      The source file of the backup engine implement for symbian
       
    17  */
       
    18 
       
    19 #include "fmbkupengine_p.h"
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <coreapplicationuisdomainpskeys.h>
       
    23 #include <coemain.h>
       
    24 #include <apgwgnam.h>
       
    25 #include <apgtask.h>
       
    26 #include <bautils.h>
       
    27 #include <tz.h>
       
    28 #include <babackup.h>
       
    29 #include <pathinfo.h>
       
    30 #include <sysutil.h>
       
    31 #ifdef RD_MULTIPLE_DRIVE
       
    32 #include <driveinfo.h>
       
    33 #endif // RD_MULTIPLE_DRIVE
       
    34 #include <e32property.h>
       
    35 #include <centralrepository.h>
       
    36 #include "CMMCScBkupEngine.h"
       
    37 #include "MMCScBkupOperations.h"
       
    38 #include "CMMCScBkupArchiveInfo.h"
       
    39 #include "filemanagerprivatecrkeys.h"
       
    40 
       
    41 #include <eikdef.h>
       
    42 #include <eikenv.h>
       
    43 
       
    44 #include "fmcommon.h"
       
    45 
       
    46 #include <f32file.h>
       
    47 
       
    48 /*
       
    49 #include "cfilemanageritemproperties.h"
       
    50 #include "cfilemanagerbackupsettings.h"
       
    51 #include "filemanagerprivatecrkeys.h"
       
    52 #include "bkupengine.hrh"
       
    53 #include "filemanagerdebug.h"
       
    54 #include "cfilemanagercommondefinitions.h"
       
    55 #include "filemanageruid.h"
       
    56 #include "filemanagerprivatepskeys.h"
       
    57 */
       
    58 
       
    59 const TInt KFmgrSystemDrive = EDriveC;
       
    60 
       
    61 FmBkupEnginePrivate::FmBkupEnginePrivate(FmBkupEngine* bkupEngine): q(bkupEngine),
       
    62     iError( KErrNone )
       
    63 {
       
    64     iDrvAndOpList = new ( ELeave ) CArrayFixFlat<TBkupDrivesAndOperation> ( 10 ) ;
       
    65     iBkupCategoryList = new RPointerArray<CBkupCategory> ( 10 );
       
    66     iFs.Connect();
       
    67     iBkupEngine = CMMCScBkupEngine::NewL( iFs );
       
    68 }
       
    69 
       
    70 FmBkupEnginePrivate::~FmBkupEnginePrivate()
       
    71 {
       
    72 	delete iDrvAndOpList;
       
    73 	
       
    74 	iBkupCategoryList->ResetAndDestroy();
       
    75     delete iBkupCategoryList;
       
    76     
       
    77     delete iBkupEngine;
       
    78     iFs.Close();
       
    79 }
       
    80 
       
    81 TUint32 FmBkupEnginePrivate::FmgrToBkupMask(
       
    82         const TUint32 aFmrgMask )
       
    83     {
       
    84     TUint32 ret( 0 );
       
    85 
       
    86     for( TInt i( 0 ); i < KMaskLookupLen; ++i )
       
    87         {
       
    88         if ( ( aFmrgMask & FmBkupEngineCommon::EFileManagerBackupContentAll ) ||
       
    89             ( aFmrgMask & KMaskLookup[ i ].iFmgrMask ) )
       
    90             {
       
    91             ret |= KMaskLookup[ i ].iBkupMask;
       
    92             }
       
    93         }
       
    94     return ret;
       
    95     }
       
    96 
       
    97 bool FmBkupEnginePrivate::startBackup(QList<FmBkupDrivesAndOperation* > drivesAndOperationList,
       
    98 	    QList<FmBkupBackupCategory*> backupCategoryList,
       
    99 	    QString drive, quint32 content)
       
   100 {
       
   101     FM_LOG( "FmBkupEnginePrivate::startBackup_with drive: " + drive +
       
   102             "_number:" + QString::number(DriverNameToNumber( drive )));
       
   103     if( drive.isEmpty() ) {
       
   104         iError = KErrPathNotFound;
       
   105         FM_LOG( "FmBkupEnginePrivate::startBackup_with return with KErrPathNotFound because drive is empty" );
       
   106         return false;
       
   107     }
       
   108     QStringList backupableDriveList;
       
   109     getBackupDriveList( backupableDriveList );
       
   110     if( !backupableDriveList.contains( drive, Qt::CaseInsensitive ) ) {
       
   111         iError = KErrPathNotFound;
       
   112         FM_LOG( "FmBkupEnginePrivate::startBackup_with return with KErrPathNotFound because drive is not available" );
       
   113         return false;
       
   114     }
       
   115     QString logString;
       
   116     logString = "startBackup";
       
   117     FM_LOG( logString );
       
   118     iDrvAndOpList->Reset();
       
   119     iBkupCategoryList->ResetAndDestroy();
       
   120 	
       
   121     logString = "startBackup_driveroperation count:" + QString::number(drivesAndOperationList.count());
       
   122     FM_LOG( logString );
       
   123     
       
   124     for( QList<FmBkupDrivesAndOperation* >::iterator it = drivesAndOperationList.begin();
       
   125         it != drivesAndOperationList.end(); ++it ) {
       
   126 		FmBkupDrivesAndOperation* fmDrvAndOp = *it;
       
   127 		TBkupDrivesAndOperation drvAndOp;
       
   128 		drvAndOp.setOwnerDataType( fmDrvAndOp->ownerDataType() );
       
   129 		drvAndOp.setDrvCategories( fmDrvAndOp->drvCategories() );
       
   130 		iDrvAndOpList->AppendL( drvAndOp );
       
   131 		}
       
   132 
       
   133     logString = "startBackup_backupCategoryList count:" + QString::number(backupCategoryList.count());
       
   134     FM_LOG( logString );
       
   135 
       
   136 	
       
   137 	for( QList<FmBkupBackupCategory* >::iterator it = backupCategoryList.begin();
       
   138 		    it != backupCategoryList.end(); ++it ) {
       
   139         FmBkupBackupCategory* fmbkupCategory = *it;
       
   140         CBkupCategory* category = CBkupCategory::NewL();
       
   141         
       
   142         category->setCategory( fmbkupCategory->category() );
       
   143         
       
   144         HBufC *archiveName = HBufC::NewL( fmbkupCategory->archive_name().length() );
       
   145         *archiveName = fmbkupCategory->archive_name().utf16();
       
   146         category->setArchive_name( *archiveName );
       
   147         delete archiveName;
       
   148         
       
   149         category->setSpecial_flags( fmbkupCategory->special_flags() );
       
   150         category->setExclude_special_flags( fmbkupCategory->exclude_special_flags() );
       
   151         
       
   152         for( QList<unsigned int>::const_iterator it = fmbkupCategory->uids()->begin();
       
   153                 it != fmbkupCategory->uids()->end(); ++it ) {
       
   154             unsigned int value = *it;
       
   155             category->addUids( value );	
       
   156         }
       
   157         
       
   158         
       
   159         for( QList<unsigned int>::const_iterator it = fmbkupCategory->exclude_uids()->begin();
       
   160                 it != fmbkupCategory->exclude_uids()->end(); ++it ) {
       
   161             unsigned int value = *it; //( *ex_uidsList )[i];
       
   162             category->addExclude_uids( value );	
       
   163         }
       
   164         
       
   165         
       
   166         iBkupCategoryList->AppendL( category );
       
   167         }
       
   168 	
       
   169 	TUint32 bkupContent( FmgrToBkupMask( content ) );
       
   170 	//TUint32 bkupContent = 63;
       
   171 	
       
   172     logString = "startBackup_new param";
       
   173     FM_LOG( logString );
       
   174 
       
   175 	CMMCScBkupOpParamsBackupFull* params =
       
   176         CMMCScBkupOpParamsBackupFull::NewL(
       
   177             iDrvAndOpList,
       
   178             iBkupCategoryList,
       
   179             TDriveNumber( DriverNameToNumber( drive ) ),
       
   180             bkupContent );
       
   181     
       
   182     mProcess = FmBkupEngine::ProcessBackup;
       
   183 
       
   184 
       
   185     logString = "startBackup_param ok";
       
   186     FM_LOG( logString );
       
   187 
       
   188     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   189     CEikonEnv* eikonEnv = (STATIC_CAST(CEikonEnv*,coeEnv));
       
   190     eikonEnv->SetSystem(ETrue);
       
   191 
       
   192     logString = "startBackup_StartOperationL";
       
   193     FM_LOG( logString );
       
   194 
       
   195     QList< FmRestoreInfo > restoreInfoList;
       
   196     GetRestoreInfoArray( drivesAndOperationList, restoreInfoList, drive );
       
   197     
       
   198     for ( TInt i( 0 ); i < restoreInfoList.count(); ++i )
       
   199         {        
       
   200         bool toContinue = false;
       
   201         FmRestoreInfo &info = restoreInfoList[ i ];
       
   202         TUint32 existContent( FmgrToBkupMask( info.content() ) );
       
   203         if ( bkupContent & existContent )
       
   204             {            
       
   205             notifyBackupFilesExistInternal( toContinue );
       
   206             if (!toContinue)
       
   207                 {
       
   208                 iError = KErrAlreadyExists;
       
   209                 return false;
       
   210                 }
       
   211             else
       
   212                 {
       
   213                 break;
       
   214                 }
       
   215             }
       
   216         }
       
   217     
       
   218     
       
   219     TRAPD( err, iBkupEngine->StartOperationL(
       
   220         EMMCScBkupOperationTypeFullBackup, *this, params ) );
       
   221 
       
   222     logString = "startBackup_end with error:" + QString::number(err) ;
       
   223     FM_LOG( logString );
       
   224     return (err == KErrNone);
       
   225 }
       
   226 
       
   227 void FmBkupEnginePrivate::cancelBackup()
       
   228 {
       
   229 	QString logString  = "cancelBackup";
       
   230 	FM_LOG(logString);
       
   231 	switch( mProcess )
       
   232     {
       
   233     case FmBkupEngine::ProcessBackup: // FALLTHROUGH
       
   234     case FmBkupEngine::ProcessRestore:
       
   235         {
       
   236 //        PublishBurStatus( EFileManagerBkupStatusUnset );
       
   237         iBkupEngine->CancelOperation();
       
   238         break;
       
   239         }
       
   240     default:
       
   241         {
       
   242         break;
       
   243         }
       
   244     }
       
   245 }
       
   246 
       
   247 
       
   248 void FmBkupEnginePrivate::notifyPreparingInternal()
       
   249 {
       
   250     iError = KErrNone;
       
   251     bool cancelable = false;
       
   252     switch( mProcess )
       
   253     {
       
   254         case FmBkupEngine::ProcessBackup:
       
   255             cancelable = false;
       
   256             break;
       
   257         case FmBkupEngine::ProcessRestore:
       
   258             cancelable = false;
       
   259             break;
       
   260         case FmBkupEngine::ProcessNone:
       
   261         default:
       
   262         Q_ASSERT( false );
       
   263     }
       
   264         
       
   265     emit notifyPreparing( cancelable );
       
   266 }
       
   267 
       
   268 void FmBkupEnginePrivate::notifyStartInternal( int aTotalCount )
       
   269 {
       
   270     iError = KErrNone;
       
   271     
       
   272     bool cancelable = false;
       
   273     switch( mProcess )
       
   274     {
       
   275         case FmBkupEngine::ProcessBackup:
       
   276             cancelable = true;
       
   277             break;
       
   278         case FmBkupEngine::ProcessRestore:
       
   279             cancelable = false;
       
   280             break;
       
   281         case FmBkupEngine::ProcessNone:
       
   282         default:
       
   283         Q_ASSERT( false );
       
   284     }
       
   285     emit notifyStart( cancelable, aTotalCount );
       
   286 }
       
   287 
       
   288 
       
   289 void FmBkupEnginePrivate::notifyUpdateInternal( int aCount )
       
   290     {
       
   291     emit notifyUpdate( aCount ); 
       
   292     }
       
   293 
       
   294 void FmBkupEnginePrivate::notifyFinishInternal()
       
   295     {
       
   296 //    iEngine.ClearDriveInfo();
       
   297 //    PublishBurStatus( EFileManagerBkupStatusUnset );
       
   298    /* CCoeEnv* coeEnv = CCoeEnv::Static();
       
   299     iEikonEnv->SetSystem( EFalse);
       
   300     */
       
   301     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   302     CEikonEnv* eikonEnv = (STATIC_CAST(CEikonEnv*,coeEnv));
       
   303     eikonEnv->SetSystem(EFalse);
       
   304     mProcess = FmBkupEngine::ProcessNone;
       
   305     emit notifyFinish( error() );
       
   306     }
       
   307  
       
   308 
       
   309 void FmBkupEnginePrivate::notifyMemoryLowInternal( int memoryValue, int &userError )
       
   310 	{
       
   311 	emit notifyMemoryLow( memoryValue, userError );
       
   312 	}
       
   313 
       
   314 void FmBkupEnginePrivate::notifyBackupFilesExistInternal( bool &isContinue )
       
   315     {
       
   316     emit notifyBackupFilesExist( isContinue );
       
   317     }
       
   318 
       
   319 TInt FmBkupEnginePrivate::HandleBkupEngineEventL(
       
   320         MMMCScBkupEngineObserver::TEvent aEvent, TInt aAssociatedData )
       
   321     {
       
   322     QString logString;
       
   323     TInt ret( KErrNone );
       
   324     switch( aEvent )
       
   325         {
       
   326         case MMMCScBkupEngineObserver::ECommonOperationStarting:
       
   327             {
       
   328             logString  = "ECommonOperationStarting";
       
   329 
       
   330             iFinalValue = KMaxTInt;
       
   331 //            notifyStartInternal( KMaxTInt );
       
   332             notifyPreparingInternal();
       
   333             break;
       
   334             }
       
   335         case MMMCScBkupEngineObserver::ECommonSizeOfTaskUnderstood:
       
   336             {
       
   337             logString  = "ECommonSizeOfTaskUnderstood";
       
   338             iFinalValue = aAssociatedData;
       
   339             notifyStartInternal( aAssociatedData );
       
   340             break;
       
   341             }
       
   342         case MMMCScBkupEngineObserver::ECommonOperationPrepareEnded:
       
   343             {
       
   344             logString  = "ECommonOperationPrepareEnded";
       
   345 //            PublishBurStatus( EFileManagerBkupStatusUnset );
       
   346             // In order to show finished dialog prior SysAp's note,
       
   347             // notify observer already at prepare-ended state.
       
   348             if( mProcess == FmBkupEngine::ProcessRestore )
       
   349                 {
       
   350                 if ( iFinalValue )
       
   351                     {
       
   352                     notifyUpdateInternal( iFinalValue );
       
   353                     }
       
   354                 notifyFinishInternal();
       
   355                 }
       
   356             break;
       
   357             }
       
   358         case MMMCScBkupEngineObserver::ECommonOperationEnded:
       
   359             {
       
   360             logString  = "ECommonOperationEnded";
       
   361 //            PublishBurStatus( EFileManagerBkupStatusUnset );
       
   362             if( mProcess != FmBkupEngine::ProcessRestore && mProcess != FmBkupEngine::ProcessNone )
       
   363                 {
       
   364                 if ( iFinalValue )
       
   365                     {
       
   366                 notifyUpdateInternal( iFinalValue );
       
   367                     }
       
   368                 notifyFinishInternal();
       
   369                 }
       
   370             break;
       
   371             }
       
   372         case MMMCScBkupEngineObserver::ECommonOperationError:
       
   373             {
       
   374             logString  = "ECommonOperationError";
       
   375             iError = aAssociatedData;
       
   376             break;
       
   377             }
       
   378         case MMMCScBkupEngineObserver::ECommonProgress:
       
   379             {
       
   380             logString  = "ECommonProgress:" + QString::number( aAssociatedData );
       
   381             notifyUpdateInternal( aAssociatedData );
       
   382             break;
       
   383             }
       
   384         case MMMCScBkupEngineObserver::EBackupAnalysingData:
       
   385             {
       
   386             logString  = "EBackupAnalysingData:" + QString::number( aAssociatedData );
       
   387             if ( mProcess == FmBkupEngine::ProcessBackup )
       
   388                 {
       
   389 					int userError = FmErrNone;
       
   390 					notifyMemoryLowInternal( aAssociatedData, userError );
       
   391                     switch( userError )
       
   392                     {
       
   393                     case FmErrDiskFull:
       
   394                         ret = KErrDiskFull;
       
   395                         break;
       
   396                     case FmErrCancel:
       
   397                         ret = KErrCancel;
       
   398                         break;
       
   399                     default:
       
   400                         break;
       
   401                     }
       
   402                 }
       
   403             break;
       
   404             }
       
   405         default:
       
   406             {
       
   407             logString  = "default";
       
   408             break;
       
   409             }
       
   410         }
       
   411     FM_LOG( logString );
       
   412     return ret;
       
   413     }
       
   414 
       
   415 int FmBkupEnginePrivate::error()
       
   416 {
       
   417     FM_LOG( "FmBkupEnginePrivate::error:" + QString::number( iError ) );
       
   418     switch (iError) 
       
   419     {
       
   420     case KErrNone: 
       
   421         return FmErrNone;
       
   422     case KErrNotFound:
       
   423         return FmErrNotFound;
       
   424     case KErrDiskFull:
       
   425         return FmErrDiskFull;
       
   426     case KErrAlreadyExists:
       
   427         return FmErrAlreadyExists;
       
   428     case KErrCancel:
       
   429         return FmErrCancel;
       
   430     case KErrPathNotFound:
       
   431         return FmErrPathNotFound;
       
   432     case KErrLocked:
       
   433         return FmErrLocked;
       
   434     case KErrCorrupt:
       
   435         return FmErrCorrupt;
       
   436     case KErrNotReady:
       
   437         return FmErrNotReady;
       
   438     case KErrDisMounted:
       
   439         return FmErrDisMounted;
       
   440     default: 
       
   441         return FmErrUnKnown;
       
   442     }    
       
   443 }
       
   444 
       
   445 
       
   446 
       
   447 
       
   448 
       
   449 int FmBkupEnginePrivate::deleteBackup( QList<FmBkupDrivesAndOperation* > drivesAndOperationList )
       
   450 {
       
   451     iError = FmErrNone;
       
   452 
       
   453     QList< FmRestoreInfo > selection;
       
   454     FmRestoreSettings& rstSettings( *( q->RestoreSettingsL() ) );
       
   455     rstSettings.GetSelectionL( selection );
       
   456 
       
   457     iBkupCategoryList->ResetAndDestroy();
       
   458     for( QList<FmBkupDrivesAndOperation* >::iterator it = drivesAndOperationList.begin();
       
   459         it != drivesAndOperationList.end(); ++it )
       
   460         {
       
   461         FmBkupDrivesAndOperation* fmDrvAndOp = *it;
       
   462         TBkupDrivesAndOperation drvAndOp;
       
   463         drvAndOp.setOwnerDataType( fmDrvAndOp->ownerDataType() );
       
   464         drvAndOp.setDrvCategories( fmDrvAndOp->drvCategories() );
       
   465         iDrvAndOpList->AppendL( drvAndOp );
       
   466         }
       
   467     ////////
       
   468 
       
   469     CMMCScBkupOpParamsRestoreFull* params =
       
   470         CMMCScBkupOpParamsRestoreFull::NewL(
       
   471                 iDrvAndOpList, FmBkupEngine::EBUCatAllSeparately );
       
   472     CleanupStack::PushL( params );
       
   473 
       
   474     // Get list of all archives
       
   475     RPointerArray< CMMCScBkupArchiveInfo > archives;
       
   476     TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
       
   477     CleanupStack::PushL( cleanupItem );
       
   478     iBkupEngine->ListArchivesL(
       
   479         archives,
       
   480         params,
       
   481         AllowedDriveAttMatchMask());
       
   482     
       
   483     TInt i( 0 );
       
   484     while ( i < archives.Count() )
       
   485             {
       
   486             TBool remove( ETrue );
       
   487 
       
   488             // Compare archives category and drive
       
   489             CMMCScBkupArchiveInfo* archiveInfo = archives[ i ];
       
   490             TUint32 fmgrContent(
       
   491                 BkupToFmgrMask( archiveInfo->Category().iFlags ) );
       
   492             TInt drive( archiveInfo->Drive() );
       
   493 
       
   494             TInt count( selection.count() );
       
   495             for( TInt j( 0 ); j < count; ++j )
       
   496                 {
       
   497                 const FmRestoreInfo& info( selection[ j ] );
       
   498                 if ( ( drive == DriverNameToNumber( info.drive() ) ) && ( fmgrContent & info.content() ) )
       
   499                     {
       
   500                     // Found user selected archive
       
   501                     // Do not check this archive again
       
   502                     selection.removeAt( j );
       
   503                     remove = EFalse;
       
   504                     break;
       
   505                     }
       
   506                 }
       
   507             if ( remove )
       
   508                 {
       
   509                 // Remove non selected archive
       
   510                 archives.Remove( i );
       
   511                 delete archiveInfo;
       
   512                 }
       
   513             else
       
   514                 {
       
   515                 // Move to next archive
       
   516                 ++i;
       
   517                 }
       
   518             }
       
   519     
       
   520     iBkupEngine->DeleteArchivesL( archives );
       
   521     
       
   522     CleanupStack::Pop( &archives );
       
   523     archives.Close();
       
   524     CleanupStack::PopAndDestroy( params );
       
   525     
       
   526     return iError;
       
   527 }
       
   528 
       
   529 
       
   530 bool FmBkupEnginePrivate::StartRestoreL( QList<FmBkupDrivesAndOperation* > drivesAndOperationList )
       
   531     {
       
   532     TBool diskFull( SysUtil::DiskSpaceBelowCriticalLevelL(
       
   533         &iFs, 0, KFmgrSystemDrive ) );
       
   534     if ( diskFull )
       
   535         {
       
   536         mProcess = FmBkupEngine::ProcessRestore;
       
   537         notifyStartInternal( KMaxTInt );
       
   538         iError = KErrDiskFull;
       
   539         notifyFinishInternal();
       
   540         mProcess = FmBkupEngine::ProcessNone;
       
   541         return false;
       
   542         }
       
   543 ///////
       
   544     iDrvAndOpList->Reset();
       
   545     iBkupCategoryList->ResetAndDestroy();
       
   546     
       
   547     for( QList<FmBkupDrivesAndOperation* >::iterator it = drivesAndOperationList.begin();
       
   548         it != drivesAndOperationList.end(); ++it )
       
   549         {
       
   550         FmBkupDrivesAndOperation* fmDrvAndOp = *it;
       
   551         TBkupDrivesAndOperation drvAndOp;
       
   552         drvAndOp.setOwnerDataType( fmDrvAndOp->ownerDataType() );
       
   553         drvAndOp.setDrvCategories( fmDrvAndOp->drvCategories() );
       
   554         iDrvAndOpList->AppendL( drvAndOp );
       
   555         }
       
   556     ////////
       
   557 
       
   558     // Create restore params - ownership is transferred to
       
   559     // secure backup engine
       
   560 
       
   561 #ifdef RD_FILE_MANAGER_BACKUP
       
   562 
       
   563     CMMCScBkupOpParamsRestoreFull* params =
       
   564         CMMCScBkupOpParamsRestoreFull::NewL(
       
   565                 iDrvAndOpList,
       
   566             FmBkupEngine::EBUCatAllSeparately );
       
   567 //    CleanupStack::PopAndDestroy(); // driveReader
       
   568     CleanupStack::PushL( params );
       
   569 
       
   570     // Get list of all archives
       
   571     RPointerArray< CMMCScBkupArchiveInfo > archives;
       
   572     TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
       
   573     CleanupStack::PushL( cleanupItem );
       
   574     iBkupEngine->ListArchivesL(
       
   575         archives,
       
   576         params,
       
   577         AllowedDriveAttMatchMask() );
       
   578 
       
   579     // Get user set restore selection
       
   580     QList< FmRestoreInfo > selection;
       
   581 //    CleanupClosePushL( selection );
       
   582     FmRestoreSettings& rstSettings( *( q->RestoreSettingsL() ) );
       
   583     rstSettings.GetSelectionL( selection );
       
   584 
       
   585     // Remove non user selected archives
       
   586     TInt i( 0 );
       
   587     while ( i < archives.Count() )
       
   588         {
       
   589         TBool remove( ETrue );
       
   590 
       
   591         // Compare archives category and drive
       
   592         CMMCScBkupArchiveInfo* archiveInfo = archives[ i ];
       
   593         TUint32 fmgrContent(
       
   594             BkupToFmgrMask( archiveInfo->Category().iFlags ) );
       
   595         TInt drive( archiveInfo->Drive() );
       
   596 
       
   597         TInt count( selection.count() );
       
   598         for( TInt j( 0 ); j < count; ++j )
       
   599             {
       
   600             const FmRestoreInfo& info( selection[ j ] );
       
   601             if ( ( drive == DriverNameToNumber( info.drive() ) ) && ( fmgrContent & info.content() ) )
       
   602                 {
       
   603                 // Found user selected archive
       
   604                 // Do not check this archive again
       
   605                 selection.removeAt( j );
       
   606                 remove = EFalse;
       
   607                 break;
       
   608                 }
       
   609             }
       
   610         if ( remove )
       
   611             {
       
   612             // Remove non selected archive
       
   613             archives.Remove( i );
       
   614             delete archiveInfo;
       
   615             }
       
   616         else
       
   617             {
       
   618             // Move to next archive
       
   619             ++i;
       
   620             }
       
   621         }
       
   622 
       
   623 //    CleanupStack::PopAndDestroy( &selection );
       
   624     params->SetArchiveInfosL( archives );
       
   625     CleanupStack::Pop( &archives );
       
   626     archives.Close();
       
   627     CleanupStack::Pop( params );
       
   628 
       
   629 #else // RD_FILE_MANAGER_BACKUP
       
   630 
       
   631     CMMCScBkupOpParamsRestoreFull* params =
       
   632         CMMCScBkupOpParamsRestoreFull::NewL( driveReader, EBUCatAllInOne );
       
   633     CleanupStack::PopAndDestroy(); // driveReader
       
   634 
       
   635     FmBackupSettings& bkupSettings( *( q->BackupSettingsL() ) );
       
   636     // Get list of all archives
       
   637     RPointerArray< CMMCScBkupArchiveInfo > archives;
       
   638     TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
       
   639     CleanupStack::PushL( cleanupItem );
       
   640     iBkupEngine->ListArchivesL(
       
   641         archives,
       
   642         params,
       
   643         bkupSettings.AllowedDriveAttMatchMask() );
       
   644     params->SetArchiveInfosL( archives );
       
   645     CleanupStack::Pop( &archives );
       
   646 
       
   647 #endif // RD_FILE_MANAGER_BACKUP
       
   648 
       
   649     // Start the process - engine owns the parameters immediately
       
   650     mProcess = FmBkupEngine::ProcessRestore;
       
   651     PublishBurStatus( EFileManagerBkupStatusRestore );
       
   652     
       
   653     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   654        CEikonEnv* eikonEnv = (STATIC_CAST(CEikonEnv*,coeEnv));
       
   655        eikonEnv->SetSystem(ETrue);
       
   656        
       
   657     TRAPD( err, iBkupEngine->StartOperationL(
       
   658         EMMCScBkupOperationTypeFullRestore, *this, params ) );
       
   659     if ( err != KErrNone )
       
   660         {
       
   661         PublishBurStatus( EFileManagerBkupStatusUnset );
       
   662         mProcess = FmBkupEngine::ProcessNone;
       
   663         User::Leave( err );
       
   664         }
       
   665     return true;
       
   666     }
       
   667 
       
   668 void FmBkupEnginePrivate::GetRestoreInfoArray( QList<FmBkupDrivesAndOperation* > drivesAndOperationList,
       
   669         QList< FmRestoreInfo > &restoreInfoList,
       
   670         const QString& aDrive )
       
   671     {
       
   672     int targetDrive = DriverNameToNumber( aDrive );    
       
   673 
       
   674     restoreInfoList.clear();
       
   675     
       
   676     ///////
       
   677     iDrvAndOpList->Reset();
       
   678     iBkupCategoryList->ResetAndDestroy();
       
   679     
       
   680     for( QList<FmBkupDrivesAndOperation* >::iterator it = drivesAndOperationList.begin();
       
   681         it != drivesAndOperationList.end(); ++it )
       
   682         {
       
   683         FmBkupDrivesAndOperation* fmDrvAndOp = *it;
       
   684         TBkupDrivesAndOperation drvAndOp;
       
   685         drvAndOp.setOwnerDataType( fmDrvAndOp->ownerDataType() );
       
   686         drvAndOp.setDrvCategories( fmDrvAndOp->drvCategories() );
       
   687         iDrvAndOpList->AppendL( drvAndOp );
       
   688         }
       
   689     ////////
       
   690 
       
   691     CMMCScBkupOpParamsRestoreFull* params =
       
   692         CMMCScBkupOpParamsRestoreFull::NewL(
       
   693                 iDrvAndOpList, FmBkupEngine::EBUCatAllSeparately );
       
   694     CleanupStack::PushL( params );
       
   695 
       
   696     // Get list of all archives
       
   697     RPointerArray< CMMCScBkupArchiveInfo > archives;
       
   698     TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
       
   699     CleanupStack::PushL( cleanupItem );
       
   700     iBkupEngine->ListArchivesL(
       
   701         archives,
       
   702         params,
       
   703         AllowedDriveAttMatchMask(),
       
   704         targetDrive );
       
   705 
       
   706     // Fill restore info
       
   707     TInt count( archives.Count() );
       
   708 //    restoreInfoList.ReserveL( count );
       
   709 
       
   710     for( TInt i( 0 ); i < count; ++i )
       
   711         {
       
   712         // Content
       
   713         CMMCScBkupArchiveInfo& archiveInfo( *archives[ i ] );
       
   714         
       
   715         TUint32 iContent = BkupToFmgrMask( archiveInfo.Category().iFlags );
       
   716         TTime iTime = archiveInfo.DateTime();
       
   717         TInt iDrive = archiveInfo.Drive();
       
   718         TDateTime iDateTime = iTime.DateTime();
       
   719         
       
   720         int h       = iDateTime.Hour();
       
   721         int m       = iDateTime.Minute();
       
   722         int s       = iDateTime.Second();
       
   723         int year    = iDateTime.Year();
       
   724         int month   = iDateTime.Month() + 1;
       
   725         int day     = iDateTime.Day()+1;
       
   726         QTime time( h, m, s);
       
   727         QDate date( year, month, day );
       
   728         
       
   729         QDateTime dateTime( date, time );
       
   730         dateTime = dateTime.toLocalTime();
       
   731         
       
   732         FmRestoreInfo restoreInfo( iContent, dateTime, NumberToDriverName( iDrive ) );
       
   733         restoreInfoList.append( restoreInfo );
       
   734         }
       
   735 
       
   736     CleanupStack::PopAndDestroy( &archives );
       
   737     CleanupStack::PopAndDestroy( params );
       
   738     }
       
   739 
       
   740 TUint32 FmBkupEnginePrivate::BkupToFmgrMask(
       
   741         const TUint32 aBkupMask )
       
   742     {
       
   743     TUint32 ret( 0 );
       
   744 
       
   745     for( TInt i( 0 ); i < KMaskLookupLen; ++i )
       
   746         {
       
   747         if ( aBkupMask & KMaskLookup[ i ].iBkupMask )
       
   748             {
       
   749             ret |= KMaskLookup[ i ].iFmgrMask;
       
   750             }
       
   751         }
       
   752     return ret;
       
   753     }
       
   754 
       
   755 void FmBkupEnginePrivate::ResetAndDestroyArchives( TAny* aPtr )
       
   756     {
       
   757     RPointerArray< CMMCScBkupArchiveInfo >* archive = 
       
   758         static_cast< RPointerArray< CMMCScBkupArchiveInfo >* >( aPtr );
       
   759     archive->ResetAndDestroy();
       
   760     archive->Close();
       
   761     }
       
   762 
       
   763 TUint32 FmBkupEnginePrivate::AllowedDriveAttMatchMask() const
       
   764     {
       
   765     return KDriveAttRemovable;//KDriveAttRemovable;
       
   766     }
       
   767 
       
   768 TInt FmBkupEnginePrivate::DriverNameToNumber( QString driverName )
       
   769     {
       
   770         if( driverName.isEmpty() ) {
       
   771             return KErrNotFound;
       
   772         }
       
   773         TInt drive = 0;
       
   774         drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
   775         return drive;
       
   776     }
       
   777 QString FmBkupEnginePrivate::NumberToDriverName( TInt driver )
       
   778     {
       
   779         QChar driverChar( driver - EDriveA + 'A' );
       
   780         QString driverName = QString( driverChar ) + ':';
       
   781         return driverName;
       
   782     }
       
   783 
       
   784 void FmBkupEnginePrivate::getBackupDriveList( QStringList &driveList )
       
   785     {
       
   786     TUint32 driveAttMask( AllowedDriveAttMatchMask() );
       
   787     RFs fs;
       
   788     fs.Connect();
       
   789     for ( TInt i( 0 ); i < KMaxDrives; ++i )
       
   790         {
       
   791         TDriveInfo driveInfo;
       
   792         if ( fs.Drive( driveInfo, i ) == KErrNone )
       
   793             {
       
   794             // Do not allow backup for internal drives
       
   795             TUint driveStatus( 0 );
       
   796             DriveInfo::GetDriveStatus( fs, i, driveStatus );
       
   797             if ( driveStatus & DriveInfo::EDriveInternal )
       
   798                 {
       
   799                 continue;
       
   800                 }
       
   801             if ( driveInfo.iDriveAtt & driveAttMask )
       
   802                 {
       
   803                 driveList.append( NumberToDriverName( i ) );
       
   804                 }
       
   805             }
       
   806         }
       
   807     fs.Close();
       
   808     }
       
   809 
       
   810 // -----------------------------------------------------------------------------
       
   811 // CFileManagerEngine::PublishBurStatus()
       
   812 //
       
   813 // -----------------------------------------------------------------------------
       
   814 //  
       
   815 void FmBkupEnginePrivate::PublishBurStatus( TInt aType )
       
   816     {
       
   817     Q_UNUSED( aType );
       
   818     /*
       
   819    _LIT_SECURITY_POLICY_S0( KFileManagerBkupWritePolicy, KFileManagerUID3 );
       
   820    _LIT_SECURITY_POLICY_PASS( KFileManagerBkupReadPolicy );
       
   821 
       
   822     TInt err( RProperty::Set(
       
   823         KPSUidFileManagerStatus, KFileManagerBkupStatus, aType ) );
       
   824     if ( err != KErrNone )
       
   825         {
       
   826         err = RProperty::Define(
       
   827             KPSUidFileManagerStatus, KFileManagerBkupStatus,
       
   828             RProperty::EInt, KFileManagerBkupReadPolicy,
       
   829             KFileManagerBkupWritePolicy );
       
   830         if ( err == KErrNone || err == KErrAlreadyExists )
       
   831             {
       
   832             err = RProperty::Set(
       
   833                 KPSUidFileManagerStatus, KFileManagerBkupStatus, aType );
       
   834             }
       
   835         }
       
   836     LOG_IF_ERROR1(
       
   837         err, "FileManagerRemovableDriveHandler::PublishBurStatus-err=%d", err )
       
   838         */
       
   839     }