|         |      1 /* | 
|         |      2 * Copyright (c) 2006 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 * Description:  Handler for scheduled backup | 
|         |     15 * | 
|         |     16 */ | 
|         |     17  | 
|         |     18  | 
|         |     19 // #define FILE_MANAGER_POWER_SAVING_MODE | 
|         |     20  | 
|         |     21 // INCLUDE FILES | 
|         |     22 #include <StringLoader.h> | 
|         |     23 #include <centralrepository.h> | 
|         |     24 #include <avkon.hrh> | 
|         |     25 #include <avkon.rsg> | 
|         |     26 #include <FileManager.rsg> | 
|         |     27 #include <FileManagerDebug.h> | 
|         |     28 #include <FileManagerPrivateCRKeys.h> | 
|         |     29 #include <CFileManagerEngine.h> | 
|         |     30 #include <CFileManagerBackupSettings.h> | 
|         |     31 #include <MFileManagerProcessObserver.h> | 
|         |     32 #include <CFileManagerGlobalDlg.h> | 
|         |     33 #ifdef FILE_MANAGER_POWER_SAVING_MODE | 
|         |     34  #include <psmsrvdomaincrkeys.h> | 
|         |     35 #endif // FILE_MANAGER_POWER_SAVING_MODE | 
|         |     36 #include "CFileManagerSchBackupHandler.h" | 
|         |     37 #include "MFileManagerSchBackupObserver.h" | 
|         |     38  | 
|         |     39  | 
|         |     40 // ======== MEMBER FUNCTIONS ======== | 
|         |     41  | 
|         |     42 // ---------------------------------------------------------------------------- | 
|         |     43 // CFileManagerSchBackupHandler::CFileManagerSchBackupHandler | 
|         |     44 // ---------------------------------------------------------------------------- | 
|         |     45 // | 
|         |     46 CFileManagerSchBackupHandler::CFileManagerSchBackupHandler( | 
|         |     47         CFileManagerEngine& aEngine ) : | 
|         |     48     iEngine( aEngine ) | 
|         |     49     { | 
|         |     50     } | 
|         |     51  | 
|         |     52 // ---------------------------------------------------------------------------- | 
|         |     53 // CFileManagerSchBackupHandler::NewL | 
|         |     54 // ---------------------------------------------------------------------------- | 
|         |     55 // | 
|         |     56 CFileManagerSchBackupHandler* CFileManagerSchBackupHandler::NewL( | 
|         |     57         CFileManagerEngine& aEngine ) | 
|         |     58     { | 
|         |     59     CFileManagerSchBackupHandler* self = | 
|         |     60         new( ELeave ) CFileManagerSchBackupHandler( aEngine ); | 
|         |     61     CleanupStack::PushL( self ); | 
|         |     62     self->ConstructL(); | 
|         |     63     CleanupStack::Pop( self ); | 
|         |     64     return self; | 
|         |     65     } | 
|         |     66  | 
|         |     67 // ---------------------------------------------------------------------------- | 
|         |     68 // CFileManagerSchBackupHandler::ConstructL | 
|         |     69 // ---------------------------------------------------------------------------- | 
|         |     70 //  | 
|         |     71 void CFileManagerSchBackupHandler::ConstructL() | 
|         |     72     { | 
|         |     73     FUNC_LOG | 
|         |     74  | 
|         |     75     iGlobalDlg = CFileManagerGlobalDlg::NewL(); | 
|         |     76     iGlobalDlg->SetObserver( this ); | 
|         |     77  | 
|         |     78    	iCenRep = CRepository::NewL( KCRUidFileManagerSettings ); | 
|         |     79     } | 
|         |     80  | 
|         |     81 // ---------------------------------------------------------------------------- | 
|         |     82 // CFileManagerSchBackupHandler::~CFileManagerSchBackupHandler | 
|         |     83 // ---------------------------------------------------------------------------- | 
|         |     84 //  | 
|         |     85 CFileManagerSchBackupHandler::~CFileManagerSchBackupHandler() | 
|         |     86     { | 
|         |     87     FUNC_LOG | 
|         |     88  | 
|         |     89     delete iGlobalDlg; | 
|         |     90     delete iCenRep; | 
|         |     91     } | 
|         |     92  | 
|         |     93 // ---------------------------------------------------------------------------- | 
|         |     94 // CFileManagerSchBackupHandler::HandleGlobalDlgResult | 
|         |     95 // ---------------------------------------------------------------------------- | 
|         |     96 //  | 
|         |     97 void CFileManagerSchBackupHandler::HandleGlobalDlgResult( | 
|         |     98         TInt aDlgType, | 
|         |     99         TInt aDlgResult ) | 
|         |    100     { | 
|         |    101     INFO_LOG2( | 
|         |    102         "CFileManagerSchBackupHandler::HandleGlobalDlgResult-aDlgType=%d,aDlgResult=%d", | 
|         |    103         aDlgType, aDlgResult ) | 
|         |    104     TInt err( KErrNone ); | 
|         |    105     switch ( aDlgType  ) | 
|         |    106         { | 
|         |    107         case CFileManagerGlobalDlg::ECountdownQuery: | 
|         |    108             { | 
|         |    109             if ( aDlgResult == EAknSoftkeyYes ) | 
|         |    110                 { | 
|         |    111                 // Backup was accepted | 
|         |    112                 StartBackup(); | 
|         |    113  | 
|         |    114                 err = iCenRep->Set( | 
|         |    115                     KFileManagerLastSchBackupStatus, | 
|         |    116                     EFileManagerSchBackupStatusInProgress ); | 
|         |    117                 } | 
|         |    118             else | 
|         |    119                 { | 
|         |    120                 // Backup was rejected | 
|         |    121                 InformObserver( KErrCancel ); | 
|         |    122                 CancelBackupStarter(); | 
|         |    123                 } | 
|         |    124             break; | 
|         |    125             } | 
|         |    126         case CFileManagerGlobalDlg::EProgressDialog: | 
|         |    127             { | 
|         |    128             // Backup was canceled | 
|         |    129             iEngine.CancelProcess( | 
|         |    130                 MFileManagerProcessObserver::ESchBackupProcess ); | 
|         |    131             InformObserver( KErrCancel ); | 
|         |    132             CancelBackupStarter(); | 
|         |    133             break; | 
|         |    134             } | 
|         |    135         default: | 
|         |    136             { | 
|         |    137             InformObserver( aDlgResult ); | 
|         |    138             break; | 
|         |    139             } | 
|         |    140         } | 
|         |    141          | 
|         |    142     LOG_IF_ERROR1( err, | 
|         |    143         "CFileManagerSchBackupHandler::HandleGlobalDlgResult-err=%d", err ) | 
|         |    144  | 
|         |    145     } | 
|         |    146  | 
|         |    147 // ---------------------------------------------------------------------------- | 
|         |    148 // CFileManagerSchBackupHandler::StartBackupWithConfirmL | 
|         |    149 // ---------------------------------------------------------------------------- | 
|         |    150 // | 
|         |    151 void CFileManagerSchBackupHandler::StartBackupWithConfirmL() | 
|         |    152     { | 
|         |    153     TBool psmOn( EFalse ); | 
|         |    154     TRAPD( err, psmOn = IsPowerSavingModeOnL() ); | 
|         |    155     if ( psmOn && err == KErrNone ) | 
|         |    156         { | 
|         |    157         iGlobalDlg->ShowDialogL( | 
|         |    158             CFileManagerGlobalDlg::EQueryWithInfoIcon, | 
|         |    159             R_QTN_FMGR_SCHEDULED_BACKUP_CANCELLED_PS, | 
|         |    160             R_AVKON_SOFTKEYS_OK_EMPTY ); | 
|         |    161         CancelBackupStarter(); | 
|         |    162         return; | 
|         |    163         } | 
|         |    164  | 
|         |    165     // Show cancelable global confirm countdown before starting backup. | 
|         |    166     // Backup is started only if accepted or countdown has expired. | 
|         |    167     iGlobalDlg->ShowDialogL( | 
|         |    168         CFileManagerGlobalDlg::ECountdownQuery, | 
|         |    169         R_QTN_FMGR_SCHEDULED_BACKUP_QUERY ); | 
|         |    170     } | 
|         |    171  | 
|         |    172 // ---------------------------------------------------------------------------- | 
|         |    173 // CFileManagerSchBackupHandler::StartBackupL | 
|         |    174 // ---------------------------------------------------------------------------- | 
|         |    175 // | 
|         |    176 void CFileManagerSchBackupHandler::StartBackupL() | 
|         |    177     { | 
|         |    178     TBool drvAvailable( ETrue ); | 
|         |    179     TRAPD( err, drvAvailable = IsTargetDriveAvailableL() ); | 
|         |    180     if ( !drvAvailable && err == KErrNone ) | 
|         |    181         { | 
|         |    182         iGlobalDlg->ShowDialogL( | 
|         |    183             CFileManagerGlobalDlg::EQueryWithWarningIcon, | 
|         |    184             R_QTN_FMGR_SCHEDULED_BACKUP_ERROR, | 
|         |    185             R_AVKON_SOFTKEYS_OK_EMPTY ); | 
|         |    186         CancelBackupStarter(); | 
|         |    187         return; | 
|         |    188         } | 
|         |    189  | 
|         |    190     CFileManagerBackupSettings& settings( iEngine.BackupSettingsL() ); | 
|         |    191     HBufC* text = StringLoader::LoadLC( | 
|         |    192         R_QTN_FMGR_SCHEDULED_BACKUP_PROGRESS, | 
|         |    193         iEngine.DriveName( settings.TargetDrive() ) ); | 
|         |    194  | 
|         |    195     iGlobalDlg->ShowDialogL( | 
|         |    196         CFileManagerGlobalDlg::EProgressDialog, | 
|         |    197         *text ); | 
|         |    198  | 
|         |    199     CleanupStack::PopAndDestroy( text ); | 
|         |    200  | 
|         |    201     iEngine.StartBackupProcessL( | 
|         |    202         MFileManagerProcessObserver::ESchBackupProcess ); | 
|         |    203     } | 
|         |    204  | 
|         |    205 // ---------------------------------------------------------------------------- | 
|         |    206 // CFileManagerSchBackupHandler::SetObserver | 
|         |    207 // ---------------------------------------------------------------------------- | 
|         |    208 // | 
|         |    209 void CFileManagerSchBackupHandler::SetObserver( | 
|         |    210         MFileManagerSchBackupObserver* aObserver ) | 
|         |    211     { | 
|         |    212     iObserver = aObserver; | 
|         |    213     } | 
|         |    214  | 
|         |    215 // ---------------------------------------------------------------------------- | 
|         |    216 // CFileManagerSchBackupHandler::StartBackupWithConfirm | 
|         |    217 // ---------------------------------------------------------------------------- | 
|         |    218 // | 
|         |    219 void CFileManagerSchBackupHandler::StartBackupWithConfirm() | 
|         |    220     { | 
|         |    221     FUNC_LOG | 
|         |    222  | 
|         |    223     if ( iBackupOngoing ) | 
|         |    224         { | 
|         |    225         return; | 
|         |    226         } | 
|         |    227  | 
|         |    228     iBackupOngoing = ETrue; | 
|         |    229  | 
|         |    230     TRAPD( err, StartBackupWithConfirmL() ); | 
|         |    231     if ( err != KErrNone ) | 
|         |    232         { | 
|         |    233         InformObserver( err ); | 
|         |    234         } | 
|         |    235     else | 
|         |    236         { | 
|         |    237         // Confirm scheduled backup start state | 
|         |    238         TInt err( iCenRep->Set( | 
|         |    239             KFileManagerLastSchBackupStatus, | 
|         |    240             EFileManagerSchBackupStatusInProgress ) ); | 
|         |    241  | 
|         |    242         LOG_IF_ERROR1( err, | 
|         |    243             "CFileManagerSchBackupHandler::StartBackupWithConfirm-err=%d", err ) | 
|         |    244  | 
|         |    245         } | 
|         |    246     } | 
|         |    247  | 
|         |    248 // ---------------------------------------------------------------------------- | 
|         |    249 // CFileManagerSchBackupHandler::StartBackup | 
|         |    250 // ---------------------------------------------------------------------------- | 
|         |    251 // | 
|         |    252 void CFileManagerSchBackupHandler::StartBackup() | 
|         |    253     { | 
|         |    254     FUNC_LOG | 
|         |    255  | 
|         |    256     TRAPD( err, StartBackupL() ); | 
|         |    257     if ( err != KErrNone ) | 
|         |    258         { | 
|         |    259         InformObserver( err ); | 
|         |    260         } | 
|         |    261     } | 
|         |    262  | 
|         |    263 // ---------------------------------------------------------------------------- | 
|         |    264 // CFileManagerSchBackupHandler::InformObserver | 
|         |    265 // ---------------------------------------------------------------------------- | 
|         |    266 // | 
|         |    267 void CFileManagerSchBackupHandler::InformObserver( const TInt aValue ) | 
|         |    268     { | 
|         |    269     INFO_LOG1( "CFileManagerSchBackupHandler::InformObserver-aValue=%d", aValue ) | 
|         |    270  | 
|         |    271     iBackupOngoing = EFalse; | 
|         |    272     if ( iObserver ) | 
|         |    273         { | 
|         |    274         TRAP_IGNORE( iObserver->SchBackupFinishedL( aValue ) ); | 
|         |    275         } | 
|         |    276     } | 
|         |    277  | 
|         |    278 // ---------------------------------------------------------------------------- | 
|         |    279 // CFileManagerSchBackupHandler::ProcessFinishedL | 
|         |    280 // ---------------------------------------------------------------------------- | 
|         |    281 // | 
|         |    282 void CFileManagerSchBackupHandler::ProcessFinishedL( | 
|         |    283         TInt aError, const TDesC& /*aName*/ ) | 
|         |    284     { | 
|         |    285     INFO_LOG1( "CFileManagerSchBackupHandler::ProcessFinishedL-aError=%d", | 
|         |    286         aError ) | 
|         |    287  | 
|         |    288     iGlobalDlg->CancelDialog(); | 
|         |    289     TInt err( KErrNone ); | 
|         |    290     if ( aError == KErrCancel ) | 
|         |    291         { | 
|         |    292         CancelBackupStarter(); | 
|         |    293         } | 
|         |    294     else if ( aError != KErrNone  ) | 
|         |    295         { | 
|         |    296         iGlobalDlg->ShowDialogL( | 
|         |    297             CFileManagerGlobalDlg::EErrorNote, | 
|         |    298             R_QTN_CRITICAL_ERROR ); | 
|         |    299              | 
|         |    300         err = iCenRep->Set( | 
|         |    301             KFileManagerLastSchBackupStatus, | 
|         |    302             EFileManagerSchBackupStatusFailed ); | 
|         |    303         } | 
|         |    304     else | 
|         |    305         { | 
|         |    306         iGlobalDlg->ShowDialogL( | 
|         |    307             CFileManagerGlobalDlg::EInfoNote, | 
|         |    308             R_QTN_BACKUP_COMPLETED ); | 
|         |    309  | 
|         |    310         err = iCenRep->Set( | 
|         |    311             KFileManagerLastSchBackupStatus, | 
|         |    312             EFileManagerSchBackupStatusOk ); | 
|         |    313         } | 
|         |    314  | 
|         |    315     LOG_IF_ERROR1( err, | 
|         |    316         "CFileManagerSchBackupHandler::ProcessFinishedL-err=%d", err ) | 
|         |    317  | 
|         |    318     InformObserver( aError ); | 
|         |    319  | 
|         |    320     } | 
|         |    321  | 
|         |    322 // ---------------------------------------------------------------------------- | 
|         |    323 // CFileManagerSchBackupHandler::ProcessAdvanceL | 
|         |    324 // ---------------------------------------------------------------------------- | 
|         |    325 // | 
|         |    326 void CFileManagerSchBackupHandler::ProcessAdvanceL( TInt aValue ) | 
|         |    327     { | 
|         |    328     iGlobalDlg->UpdateProgressDialog( aValue ); | 
|         |    329     } | 
|         |    330  | 
|         |    331 // ---------------------------------------------------------------------------- | 
|         |    332 // CFileManagerSchBackupHandler::ProcessStartedL | 
|         |    333 // ---------------------------------------------------------------------------- | 
|         |    334 // | 
|         |    335 void CFileManagerSchBackupHandler::ProcessStartedL( TInt aFinalValue ) | 
|         |    336     { | 
|         |    337     FUNC_LOG | 
|         |    338      | 
|         |    339     iGlobalDlg->UpdateProgressDialog( 0, aFinalValue ); | 
|         |    340     } | 
|         |    341  | 
|         |    342 // ---------------------------------------------------------------------------- | 
|         |    343 // CFileManagerSchBackupHandler::CancelBackupStarter | 
|         |    344 // ---------------------------------------------------------------------------- | 
|         |    345 // | 
|         |    346 void CFileManagerSchBackupHandler::CancelBackupStarter() | 
|         |    347     { | 
|         |    348     TInt err( iCenRep->Set( | 
|         |    349         KFileManagerLastSchBackupStatus, | 
|         |    350         EFileManagerSchBackupStatusCanceled ) ); | 
|         |    351     LOG_IF_ERROR1( err, | 
|         |    352         "CFileManagerSchBackupHandler::CancelBackupStarter-err=%d", err ) | 
|         |    353     } | 
|         |    354  | 
|         |    355 // ---------------------------------------------------------------------------- | 
|         |    356 // CFileManagerSchBackupHandler::IsPowerSavingModeOnL | 
|         |    357 // ---------------------------------------------------------------------------- | 
|         |    358 // | 
|         |    359 TBool CFileManagerSchBackupHandler::IsPowerSavingModeOnL() | 
|         |    360     { | 
|         |    361     TBool ret( EFalse ); | 
|         |    362 #ifdef FILE_MANAGER_POWER_SAVING_MODE | 
|         |    363     // Check power saving mode before start | 
|         |    364     CRepository* psmCenRep = CRepository::NewLC( KCRUidPowerSaveMode ); | 
|         |    365     TInt psmMode( 0 ); | 
|         |    366     User::LeaveIfError( psmCenRep->Get( KPsmCurrentMode, psmMode ) ); | 
|         |    367     if ( psmMode ) | 
|         |    368         { | 
|         |    369         ERROR_LOG1( | 
|         |    370             "CFileManagerSchBackupHandler::IsPowerSavingModeOnL-PsmMode=%d", | 
|         |    371             psmMode ) | 
|         |    372         ret = ETrue; | 
|         |    373         } | 
|         |    374     CleanupStack::PopAndDestroy( psmCenRep ); | 
|         |    375 #endif // FILE_MANAGER_POWER_SAVING_MODE | 
|         |    376     return ret; | 
|         |    377     } | 
|         |    378  | 
|         |    379 // ---------------------------------------------------------------------------- | 
|         |    380 // CFileManagerSchBackupHandler::IsTargetDriveAvailableL | 
|         |    381 // ---------------------------------------------------------------------------- | 
|         |    382 // | 
|         |    383 TBool CFileManagerSchBackupHandler::IsTargetDriveAvailableL() | 
|         |    384     { | 
|         |    385     // Start backup with cancelable global progress dialog | 
|         |    386     CFileManagerBackupSettings& settings( iEngine.BackupSettingsL() ); | 
|         |    387  | 
|         |    388     // Check is target drive available | 
|         |    389     TBool ret( ETrue ); | 
|         |    390     TFileManagerDriveInfo info; | 
|         |    391     iEngine.GetDriveInfoL( settings.TargetDrive(), info ); | 
|         |    392     if ( !( info.iState & TFileManagerDriveInfo::EDrivePresent ) || | 
|         |    393          ( info.iState & | 
|         |    394             ( TFileManagerDriveInfo::EDriveLocked | | 
|         |    395               TFileManagerDriveInfo::EDriveCorrupted | | 
|         |    396               TFileManagerDriveInfo::EDriveWriteProtected ) ) ) | 
|         |    397         { | 
|         |    398         ERROR_LOG1( | 
|         |    399             "CFileManagerSchBackupHandler::IsTargetDriveAvailableL-DrvState=%d", | 
|         |    400             info.iState ) | 
|         |    401         ret = EFalse; | 
|         |    402         } | 
|         |    403     return ret; | 
|         |    404     } | 
|         |    405  | 
|         |    406 //  End of File   |