filemanager/App/src/CFileManagerRestoreView.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  View for restore settings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StringLoader.h>
       
    22 #include <aknlists.h>
       
    23 #include <akntitle.h>
       
    24 #include <CFileManagerEngine.h>
       
    25 #include <filemanager.rsg>
       
    26 #include <FileManagerDlgUtils.h>
       
    27 #include <CFileManagerRestoreSettings.h>
       
    28 #include <FileManagerDebug.h>
       
    29 #include "CFileManagerRestoreView.h"
       
    30 #include "CFileManagerSettingListContainer.h"
       
    31 #include "CFileManagerDocument.h"
       
    32 #include "CFileManagerAppUi.h"
       
    33 #include "FileManager.hrh"
       
    34 
       
    35 // CONSTANTS
       
    36 const TUid CFileManagerRestoreView::KDeleteBackups = { EDeleteBackups };
       
    37 const TInt KMaxSelection = 64;
       
    38 
       
    39 // ======== MEMBER FUNCTIONS ========
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // CFileManagerRestoreView::CFileManagerRestoreView
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 CFileManagerRestoreView::CFileManagerRestoreView()
       
    46     {
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // CFileManagerRestoreView::NewLC
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 CFileManagerRestoreView* CFileManagerRestoreView::NewLC()
       
    54     {
       
    55     CFileManagerRestoreView* self = new( ELeave ) CFileManagerRestoreView();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL( R_FILEMANAGER_RESTORE_VIEW );
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CFileManagerRestoreView::~CFileManagerRestoreView
       
    63 // ----------------------------------------------------------------------------
       
    64 // 
       
    65 CFileManagerRestoreView::~CFileManagerRestoreView()
       
    66     {
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CFileManagerRestoreView::DoActivateL
       
    71 // ----------------------------------------------------------------------------
       
    72 // 
       
    73 void CFileManagerRestoreView::DoActivateL(
       
    74         const TVwsViewId& aPrevViewId,
       
    75         TUid aCustomMessageId,
       
    76         const TDesC8& aCustomMessage )
       
    77     {
       
    78     FUNC_LOG
       
    79 
       
    80     iSelection = 0; // Reset stored list selection
       
    81     iDeleteBackups = ( aCustomMessageId == KDeleteBackups );
       
    82 
       
    83     CFileManagerViewBase::DoActivateL(
       
    84         aPrevViewId, aCustomMessageId, aCustomMessage );
       
    85 
       
    86     static_cast< CFileManagerAppUi* >( AppUi() )->SetTitleL(
       
    87         iDeleteBackups ?
       
    88         R_QTN_FMGR_DELETE_BACKUP_TITLE : R_QTN_FMGR_RESTORE_TITLE );
       
    89 
       
    90     CFileManagerRestoreSettings& settings( iEngine.RestoreSettingsL() );
       
    91     settings.RefreshL();
       
    92 
       
    93     iContainer->RefreshListL( iIndex );
       
    94 
       
    95     CEikButtonGroupContainer* cba = Cba();
       
    96     cba->SetCommandSetL(R_AVKON_SOFTKEYS_OK_CANCEL__MARK );
       
    97     cba->MakeCommandVisible( EAknSoftkeyOk, EFalse );
       
    98     cba->MakeCommandVisible( EAknSoftkeyMark, ETrue );
       
    99 
       
   100     if ( !iContainer->ListBoxNumberOfItems() )
       
   101         {
       
   102         cba->MakeCommandVisible( EAknSoftkeyMark, EFalse );
       
   103         }
       
   104     cba->DrawDeferred();
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CFileManagerRestoreView::DoDeactivate
       
   109 // ----------------------------------------------------------------------------
       
   110 // 
       
   111 void CFileManagerRestoreView::DoDeactivate()
       
   112     {
       
   113     FUNC_LOG
       
   114 
       
   115     CFileManagerViewBase::DoDeactivate();
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CFileManagerRestoreView::DirectoryChangedL
       
   120 // ----------------------------------------------------------------------------
       
   121 // 
       
   122 void CFileManagerRestoreView::DirectoryChangedL()
       
   123     {
       
   124     FUNC_LOG
       
   125 
       
   126     if ( iContainer )
       
   127         {
       
   128         CFileManagerRestoreSettings& settings( iEngine.RestoreSettingsL() );
       
   129         settings.RefreshL();
       
   130         iContainer->RefreshListL( iIndex );
       
   131         RestoreSelectionL();
       
   132         }
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------------------------
       
   136 // CFileManagerRestoreView::Id
       
   137 // ----------------------------------------------------------------------------
       
   138 // 
       
   139 TUid CFileManagerRestoreView::Id() const
       
   140     {
       
   141     return CFileManagerAppUi::KFileManagerRestoreViewId;
       
   142     }
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CFileManagerRestoreView::CreateContainerL
       
   146 // ----------------------------------------------------------------------------
       
   147 // 
       
   148 CFileManagerContainerBase* CFileManagerRestoreView::CreateContainerL()
       
   149     {
       
   150     CFileManagerRestoreSettings& settings( iEngine.RestoreSettingsL() );
       
   151     CFileManagerContainerBase* container =
       
   152         CFileManagerSettingListContainer::NewL(
       
   153             ClientRect(),
       
   154             iIndex,
       
   155             CFileManagerSettingListContainer::EListRestore,
       
   156             &settings );
       
   157     container->SetEmptyTextL( R_QTN_FMGR_RESTORE_NO_BACKUPS );
       
   158     return container;
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CFileManagerRestoreView::HandleCommandL
       
   163 // ----------------------------------------------------------------------------
       
   164 // 
       
   165 void CFileManagerRestoreView::HandleCommandL( TInt aCommand )
       
   166     {
       
   167     switch( aCommand )
       
   168         {
       
   169         case EAknSoftkeySelect: // FALLTHROUGH
       
   170         case EAknSoftkeyMark: // FALLTHROUGH
       
   171         case EAknSoftkeyUnmark: // FALLTHROUGH
       
   172         case EFileManagerSelectionKey: // FALLTHROUGH
       
   173         case EFileManagerToggleMark: // FALLTHROUGH
       
   174         case EFileManagerOpen:
       
   175             {
       
   176             CmdSelectL();
       
   177             break;
       
   178             }
       
   179         case EAknSoftkeyOk:
       
   180             {
       
   181             CmdOkL();
       
   182             break;
       
   183             }
       
   184         case EAknSoftkeyCancel: // FALLTHROUGH
       
   185         case EAknSoftkeyBack:
       
   186             {
       
   187             CmdCancelL();
       
   188             break;
       
   189             }
       
   190         case EFileManagerCheckMark:
       
   191             {
       
   192             CmdCheckMarkL();
       
   193             break;
       
   194             }
       
   195         default:
       
   196             {
       
   197             break;
       
   198             }
       
   199         }
       
   200     }
       
   201 
       
   202 // ----------------------------------------------------------------------------
       
   203 // CFileManagerRestoreView::CmdOkL
       
   204 // ----------------------------------------------------------------------------
       
   205 // 
       
   206 void CFileManagerRestoreView::CmdOkL()
       
   207     {
       
   208     if ( !iContainer )
       
   209         {
       
   210         return;
       
   211         }
       
   212 
       
   213     TBool isSystemStateNormal = static_cast< CFileManagerAppUi* >( AppUi() )->IsSystemStateNormal();
       
   214     if ( !isSystemStateNormal )
       
   215         {
       
   216         FileManagerDlgUtils::ShowErrorNoteL( R_QTN_FMGR_SYSTEM_NOT_READY );
       
   217         return;
       
   218         }
       
   219 
       
   220     const CArrayFix< TInt >* items = iContainer->ListBoxSelectionIndexes();
       
   221 
       
   222     TInt count( items->Count() );
       
   223 
       
   224     if ( count )
       
   225         {
       
   226         if( FileManagerDlgUtils::ShowConfirmQueryWithYesNoL(
       
   227                 iDeleteBackups ?
       
   228                 R_QTN_FMGR_DELETE_BACKUP_QUERY : R_QTN_FMGR_RESTORE_QUERY ) )
       
   229             {
       
   230             if ( !CheckPhoneState() )
       
   231                 {
       
   232                 FileManagerDlgUtils::ShowErrorNoteL( R_QTN_CRITICAL_ERROR );
       
   233                 }
       
   234             else
       
   235                 {
       
   236                 TUint64 selection( 0 );
       
   237                 for ( TInt i( 0 ); i < count; ++i )
       
   238                     {
       
   239                     selection |= ( ( TUint64 ) 1 ) << ( ( *items )[ i ] );
       
   240                     }
       
   241     
       
   242                 CFileManagerRestoreSettings& settings(
       
   243                     iEngine.RestoreSettingsL() );
       
   244                 settings.SetSelection( selection );
       
   245     
       
   246                 if ( iDeleteBackups )
       
   247                     {
       
   248                     // Delete selected backups and close this view
       
   249                     iEngine.DeleteBackupsL();
       
   250                     iIndex = 0;
       
   251                     static_cast< CFileManagerAppUi* >(
       
   252                         AppUi() )->CloseRestoreViewL();
       
   253                     }
       
   254                 else
       
   255                     {
       
   256                     // Start restoring selected backups
       
   257                     TRAPD( err, StartProcessL( ERestoreProcess ) );
       
   258                     if ( err == KErrCorrupt )
       
   259                         {
       
   260                         FileManagerDlgUtils::ShowErrorNoteL(
       
   261                             R_QTN_FMGR_ERROR_CORRUPTED_BACKUP_FILE );
       
   262                         }
       
   263                     else
       
   264                         {
       
   265                         User::LeaveIfError( err );
       
   266                         }
       
   267                     }
       
   268                 }
       
   269             }
       
   270         }
       
   271     else
       
   272         {
       
   273         CmdCancelL();
       
   274         }
       
   275     }
       
   276 
       
   277 // ----------------------------------------------------------------------------
       
   278 // CFileManagerRestoreView::CmdCancelL
       
   279 // ----------------------------------------------------------------------------
       
   280 // 
       
   281 void CFileManagerRestoreView::CmdCancelL()
       
   282     {
       
   283     iIndex = 0;
       
   284     static_cast< CFileManagerAppUi* >( AppUi() )->CloseRestoreViewL();
       
   285     }
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // CFileManagerRestoreView::CmdSelectL
       
   289 // ----------------------------------------------------------------------------
       
   290 // 
       
   291 void CFileManagerRestoreView::CmdSelectL()
       
   292     {
       
   293     if ( !iContainer )
       
   294         {
       
   295         return;
       
   296         }
       
   297     if ( !iContainer->ListBoxNumberOfItems() )
       
   298         {
       
   299         return;
       
   300         }
       
   301     TInt index( iContainer->ListBoxCurrentItemIndex() );
       
   302     iContainer->ListBoxToggleItemL( index );
       
   303     iSelection ^= ( ( TUint64 ) 1 ) << index; // Toggle stored list selection
       
   304     UpdateCbaFromSelectionL();
       
   305     }
       
   306 
       
   307 // ----------------------------------------------------------------------------
       
   308 // CFileManagerRestoreView::CmdCheckMarkL
       
   309 // ----------------------------------------------------------------------------
       
   310 // 
       
   311 void CFileManagerRestoreView::CmdCheckMarkL()
       
   312     {
       
   313     if ( !iContainer )
       
   314         {
       
   315         return;
       
   316         }
       
   317     TInt mskTextId( R_QTN_MSK_MARK );
       
   318     if ( iContainer->ListBoxIsItemSelected(
       
   319             iContainer->ListBoxCurrentItemIndex() ) )
       
   320         {
       
   321         mskTextId = R_QTN_MSK_UNMARK;
       
   322         }
       
   323     
       
   324     SetCbaMskTextL( mskTextId );
       
   325     }
       
   326 
       
   327 // ----------------------------------------------------------------------------
       
   328 // CFileManagerRestoreView::ProcessFinishedL
       
   329 // ----------------------------------------------------------------------------
       
   330 // 
       
   331 void CFileManagerRestoreView::ProcessFinishedL(
       
   332         TInt aError, const TDesC& aName )
       
   333     {
       
   334     TBool isRestore( iActiveProcess == ERestoreProcess );
       
   335 
       
   336     CFileManagerViewBase::ProcessFinishedL( aError, aName );
       
   337 
       
   338     // Exit when restore finished
       
   339     if ( isRestore )
       
   340         {
       
   341         CmdCancelL();
       
   342         }
       
   343     }
       
   344 
       
   345 // ----------------------------------------------------------------------------
       
   346 // CFileManagerRestoreView::NotifyForegroundStatusChange
       
   347 // ----------------------------------------------------------------------------
       
   348 //
       
   349 void CFileManagerRestoreView::NotifyForegroundStatusChange(
       
   350         TBool aForeground )
       
   351     {
       
   352     FUNC_LOG
       
   353 
       
   354     if ( aForeground )
       
   355         {
       
   356         TRAP_IGNORE( RefreshSettingsL() );
       
   357         }
       
   358     }
       
   359 
       
   360 // ----------------------------------------------------------------------------
       
   361 // CFileManagerRestoreView::RefreshSettingsL
       
   362 // ----------------------------------------------------------------------------
       
   363 //
       
   364 void CFileManagerRestoreView::RefreshSettingsL()
       
   365     {
       
   366     FUNC_LOG
       
   367 
       
   368     DirectoryChangedL();
       
   369     }
       
   370 
       
   371 // ----------------------------------------------------------------------------
       
   372 // CFileManagerRestoreView::RestoreSelectionL
       
   373 // ----------------------------------------------------------------------------
       
   374 //
       
   375 void CFileManagerRestoreView::RestoreSelectionL()
       
   376     {
       
   377     if ( !iContainer )
       
   378         {
       
   379         return;
       
   380         }
       
   381     const CArrayFix< TInt >* items = iContainer->ListBoxSelectionIndexes();
       
   382     for ( TInt i( 0 ); i < KMaxSelection; ++i )
       
   383         {
       
   384         if ( iSelection & ( ( ( TUint64 ) 1 ) << i ) )
       
   385             {
       
   386             iContainer->ListBoxSelectItemL( i );
       
   387             }
       
   388         else
       
   389             {
       
   390             iContainer->ListBoxDeselectItem( i );
       
   391             }
       
   392         }
       
   393     UpdateCbaFromSelectionL();
       
   394     }
       
   395 
       
   396 // ----------------------------------------------------------------------------
       
   397 // CFileManagerRestoreView::UpdateCbaFromSelectionL
       
   398 // ----------------------------------------------------------------------------
       
   399 //
       
   400 void CFileManagerRestoreView::UpdateCbaFromSelectionL()
       
   401     {
       
   402     if ( !iContainer )
       
   403         {
       
   404         return;
       
   405         }
       
   406     CmdCheckMarkL();
       
   407     CEikButtonGroupContainer* cba = Cba();
       
   408     TBool hasItem(iContainer->ListBoxNumberOfItems());
       
   409     const CArrayFix< TInt >* items = iContainer->ListBoxSelectionIndexes();
       
   410     if ( hasItem && items->Count() )
       
   411         {
       
   412         cba->MakeCommandVisible( EAknSoftkeyOk, ETrue );
       
   413         }
       
   414     else
       
   415         {
       
   416         cba->MakeCommandVisible( EAknSoftkeyOk, EFalse );
       
   417         }
       
   418     cba->DrawDeferred();
       
   419     }
       
   420 
       
   421 // ----------------------------------------------------------------------------
       
   422 // CFileManagerRestoreView::UpdateCbaL
       
   423 // ----------------------------------------------------------------------------
       
   424 //
       
   425 void CFileManagerRestoreView::UpdateCbaL()
       
   426     {
       
   427     CEikButtonGroupContainer* cba = Cba();
       
   428     TBool hasItem(iContainer->ListBoxNumberOfItems());
       
   429     cba->MakeCommandVisible( EAknSoftkeyMark, hasItem );
       
   430     TBool hasSelecttionItem( hasItem && ( iContainer->ListBoxSelectionIndexesCount() ) );
       
   431     cba->MakeCommandVisible( EAknSoftkeyOk, hasSelecttionItem );
       
   432     cba->DrawDeferred();
       
   433     }
       
   434     
       
   435 //  End of File