messagingappbase/mcesettings/src/MceSettingsMoveprogress.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     Starts copy/move message store progress dialog and transfer handler
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 
       
    24 #include <eikprogi.h>           // CEikProgressInfo
       
    25 #include <aknnotewrappers.h>    // CAknErrorNote
       
    26 
       
    27 #include "MceSettingsMoveProgress.h"    // CMceMoveProgress
       
    28 #include "MceSettingsGeneralSettingsDialog.h" // CMceGeneralSettingsDialog
       
    29 #include "MceSettingsIds.hrh"
       
    30 #include <MceSettings.rsg>
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KMceCancelButton        = 2;
       
    34 const TInt KMceTransferComplete    = 100;
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // C++ default constructor can NOT contain any code that
       
    39 // might leave.
       
    40 //
       
    41 
       
    42 // ----------------------------------------------------
       
    43 // CMceMoveProgress::Constructor
       
    44 //
       
    45 //
       
    46 // ----------------------------------------------------
       
    47 CMceMoveProgress::CMceMoveProgress( CMsvSession*& aSession, 
       
    48                   MMsvSessionObserver& aObserver, 
       
    49                   TInt& aSource, 
       
    50                   const TInt& aTarget,
       
    51                   TBool aDeleteCopiedStore, 
       
    52                   CMceGeneralSettingsDialog& aGeneralSettings, 
       
    53                   TBool aDeleteOnly )
       
    54                     :iSession(aSession), iObserver(aObserver), iSource(aSource), iTarget(aTarget), 
       
    55                     iDeleteCopiedStore(aDeleteCopiedStore), iCopyOperation(ETrue), 
       
    56                     iGeneralSettings (aGeneralSettings), iDeleteOnly (aDeleteOnly)
       
    57     {
       
    58     __DECLARE_NAME(_S( "CMceMoveProgress") );
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------
       
    62 // CMceMoveProgress::Constructor
       
    63 //
       
    64 //
       
    65 // ----------------------------------------------------
       
    66 CMceMoveProgress* CMceMoveProgress::NewL(
       
    67     CMsvSession*& aSession,
       
    68     MMsvSessionObserver& aObserver, TInt& aSource, const TInt& aTarget,
       
    69     TBool aDeleteCopiedStore, CMceGeneralSettingsDialog& aGeneralSettings, TBool aDeleteOnly )
       
    70     {
       
    71     CMceMoveProgress* self=new ( ELeave ) CMceMoveProgress( aSession, 
       
    72                                                                     aObserver, 
       
    73                                                                     aSource, 
       
    74                                                                     aTarget,
       
    75                                                                     aDeleteCopiedStore, 
       
    76                                                                     aGeneralSettings, 
       
    77                                                                     aDeleteOnly );
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL(); 
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------
       
    85 // CMceMoveProgress::ConstructL
       
    86 //
       
    87 //
       
    88 // ----------------------------------------------------
       
    89 void CMceMoveProgress::ConstructL()
       
    90     {
       
    91     ;// Nothing
       
    92     }
       
    93 
       
    94 
       
    95 // ----------------------------------------------------
       
    96 // CMceMoveProgress::Destructor
       
    97 //
       
    98 //
       
    99 // ----------------------------------------------------
       
   100 CMceMoveProgress::~CMceMoveProgress()
       
   101     {
       
   102     delete iProgressTimer;
       
   103     iProgressTimer = NULL;
       
   104     delete iHandler;
       
   105     iHandler = NULL;
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------
       
   109 // CMceMoveProgress::InitializingL
       
   110 // Starts transfering message store
       
   111 //
       
   112 // ----------------------------------------------------
       
   113 void CMceMoveProgress::InitializingL()
       
   114     {
       
   115     TRAPD( err2, TransferingL() );
       
   116     if ( err2 )
       
   117        {
       
   118        if ( iProgressTimer )
       
   119             {
       
   120             iProgressTimer->Cancel();
       
   121             }
       
   122 
       
   123        if ( iHandler )
       
   124             {
       
   125             iHandler->Cancel();
       
   126             }
       
   127 
       
   128         // debug this
       
   129         // obsolete
       
   130         iObserver.HandleSessionEventL( MMsvSessionObserver::EMsvServerReady, NULL, NULL, NULL ); 
       
   131 
       
   132         User::LeaveIfError( err2 );
       
   133         }
       
   134     }
       
   135 
       
   136 // ----------------------------------------------------
       
   137 // CMceMoveProgress::TransferingL
       
   138 // Starts transfer thread
       
   139 //
       
   140 // ----------------------------------------------------
       
   141 void CMceMoveProgress::TransferingL()
       
   142     {
       
   143     iProgressDialog = new ( ELeave ) CMceMoveProgressDialog( REINTERPRET_CAST( CEikDialog**,
       
   144                     &iProgressDialog ),ETrue );
       
   145 
       
   146     iProgressDialog->SetCallback( this );
       
   147 
       
   148     iProgressDialog->PrepareLC( R_MCE_MOVE_PROGRESS );
       
   149     iProgressInfo = iProgressDialog->GetProgressInfoL();
       
   150 
       
   151     iProgressInfo->SetFinalValue( KMceTransferComplete );
       
   152 
       
   153     // messaging progress watching class
       
   154     iProgressTimer=CMsvRemoteOperationProgress::NewL( *this );
       
   155 
       
   156     if ( !iDeleteCopiedStore )
       
   157        {
       
   158        // copy messages
       
   159        HBufC* text = StringLoader::LoadLC( R_MCE_COPYING_MESSAGES, CCoeEnv::Static() );
       
   160        iProgressDialog->SetCurrentLabelL( EMceSettingsMoveProgressBar, *text );
       
   161        CleanupStack::PopAndDestroy( text );
       
   162        }
       
   163 
       
   164     // Active object kicking off the message store transfer thread
       
   165     iHandler=CMceMessageTransHandler::NewL(*this, iSession, iTarget, iSource, iDeleteCopiedStore);
       
   166 
       
   167     // Set the operation: copying the store
       
   168     CMsvOperation* operation = NULL;
       
   169     TDriveUnit targetUnit(iTarget);
       
   170     operation = iSession->CopyStoreL( targetUnit, iHandler->iStatus );
       
   171     iHandler->SetOperation( operation );
       
   172 
       
   173     // show the messaging progress
       
   174     ExecuteLD();
       
   175     
       
   176 #if 0
       
   177     if ( iDeleteCopiedStore )
       
   178     	{
       
   179     	// Delete the old store
       
   180     	TDriveUnit sourceUnit( iSource );
       
   181     	operation = iSession->DeleteStoreL( sourceUnit, iHandler->iStatus );
       
   182     	iHandler->SetOperation( operation );
       
   183     	}
       
   184 #endif
       
   185     }
       
   186 
       
   187 
       
   188 // ----------------------------------------------------
       
   189 // CMceMoveProgress::UpdateRemoteOpProgressL
       
   190 // from MMsvRemoteOperationProgressObserver
       
   191 //
       
   192 // ----------------------------------------------------
       
   193 void CMceMoveProgress::UpdateRemoteOpProgressL()
       
   194     {
       
   195     //This doesn't leave - need L as it is virtual
       
   196     if ( !iHandler )
       
   197         {
       
   198         return;
       
   199         }
       
   200     const TInt percentageDone=iHandler->ProgressL();
       
   201     CEikProgressInfo* progressBar=iProgressDialog->GetProgressInfoL();
       
   202     progressBar->SetAndDraw( percentageDone );
       
   203     }
       
   204 
       
   205 // ----------------------------------------------------
       
   206 // CMceMoveProgress::DisableCancelL
       
   207 // from MMceMsgTransHandlerObserver
       
   208 //
       
   209 // ----------------------------------------------------
       
   210 void CMceMoveProgress::DisableCancelL()
       
   211     {
       
   212     CMceMoveProgressDialog* dialog = STATIC_CAST( CMceMoveProgressDialog*, iProgressDialog );
       
   213     dialog->DisableCancelL();
       
   214     }
       
   215 
       
   216 // ----------------------------------------------------
       
   217 // CMceMoveProgress::CopyCompleteL
       
   218 // from MMceMsgTransHandlerObserver
       
   219 // 
       
   220 // ----------------------------------------------------
       
   221 void CMceMoveProgress::CopyCompleteL( TInt aErr )
       
   222     {
       
   223     //This is actually a non-leaving function - need the L because it is a virtual function    
       
   224     // For  EVSG-7V89T5
       
   225     CMceMoveProgress::DisableCancelL();
       
   226     iGeneralSettings.SetTransferError( aErr );// Catches the error when failed moving message store( aErr );
       
   227     UpdateRemoteOpProgressL();
       
   228     if (aErr!=KErrNone)
       
   229     	{
       
   230     	if ( aErr == KErrDiskFull )
       
   231        		{
       
   232        		CAknQueryDialog* lowmemoryDialog = CAknQueryDialog::NewL();
       
   233        		// Not enough memory
       
   234        		lowmemoryDialog->ExecuteLD( R_MCE_NOT_ENOUGH_MEMORY );
       
   235        		}
       
   236     	else
       
   237         	{
       
   238         	// Other error cases: KErrAccessDenied 
       
   239         	// Todo: if necessary add to CMceGeneralSettingsDialog::MoveMessageStoreL
       
   240         	// in order to prevent messaging close.        	
       
   241         	HBufC* text = StringLoader::LoadLC( R_MCE_SETTINGS_CANNOT_MOVE_STORE, 
       
   242         	                                                           CCoeEnv::Static() );
       
   243         	CAknErrorNote* note = new (ELeave) CAknErrorNote();
       
   244         	note->ExecuteLD(*text);
       
   245         	CleanupStack::PopAndDestroy( text );
       
   246         	}
       
   247     	}
       
   248     else
       
   249     	{
       
   250     	// The store has has been copied. Only change message store on success
       
   251 #ifdef RD_MULTIPLE_DRIVE
       
   252         iGeneralSettings.ChangeMessageStoreL( iTarget );
       
   253 #else
       
   254         iGeneralSettings.ChangeMessageStoreL();
       
   255 #endif //RD_MULTIPLE_DRIVE
       
   256         iGeneralSettings.UpdateMemorySelectionL();
       
   257     	iSource=iTarget;
       
   258     	}    
       
   259     }
       
   260 
       
   261 // ----------------------------------------------------
       
   262 // CMceMoveProgress::TransferCompleteL
       
   263 // from MMceMsgTransHandlerObserver
       
   264 //
       
   265 // ----------------------------------------------------
       
   266 void CMceMoveProgress::TransferCompleteL( TInt /*aErr*/ )
       
   267     {
       
   268     iProgressTimer->Cancel();
       
   269     iHandler->Cancel();
       
   270 
       
   271     iObserver.HandleSessionEventL( MMsvSessionObserver::EMsvServerReady, NULL, NULL, NULL );
       
   272 
       
   273     iProgressDialog->ProcessFinishedL();
       
   274 
       
   275     delete iProgressDialog;
       
   276     iProgressDialog = NULL;
       
   277 
       
   278     // Copy operation competed
       
   279     iCopyOperation = EFalse;
       
   280 
       
   281     delete this;
       
   282     }
       
   283 
       
   284 // ----------------------------------------------------
       
   285 // CMceMoveProgress::DialogDismissedL
       
   286 // from MProgressDialogCallback
       
   287 //
       
   288 // ----------------------------------------------------
       
   289 void CMceMoveProgress::DialogDismissedL( TInt aButtonId )
       
   290     {
       
   291     iProgressTimer->Cancel();
       
   292     iHandler->Cancel();
       
   293 
       
   294     iObserver.HandleSessionEventL( MMsvSessionObserver::EMsvServerReady, NULL, NULL, NULL );
       
   295 
       
   296     if ( aButtonId == EAknSoftkeyCancel )
       
   297         {
       
   298         // cancel has been pressed
       
   299         delete this;
       
   300         }
       
   301     }
       
   302 
       
   303 // ----------------------------------------------------
       
   304 // CMceMoveProgress::ExecuteLD
       
   305 // starts copy/move progress dialog
       
   306 //
       
   307 // ----------------------------------------------------
       
   308 void CMceMoveProgress::ExecuteLD()
       
   309     {
       
   310     User::After(1000000); // Allow the message server to complete the pending operations
       
   311     iProgressDialog->RunDlgLD( CAknNoteDialog::ENoTone );
       
   312     }
       
   313 
       
   314 
       
   315 // ----------------------------------------------------
       
   316 // CMceMoveProgressDialog::DisableCancelL
       
   317 // disables Cancel button in copy/move progress dialog
       
   318 //
       
   319 // ----------------------------------------------------
       
   320 void CMceMoveProgressDialog::DisableCancelL()
       
   321     {
       
   322     HBufC *emptysoftkey = CCoeEnv::Static()->AllocReadResourceL( R_TEXT_SOFTKEY_EMPTY );
       
   323     CleanupStack::PushL( emptysoftkey );
       
   324     ButtonGroupContainer().SetCommandL( KMceCancelButton,EAknSoftkeyEmpty, *emptysoftkey );
       
   325     CleanupStack::PopAndDestroy( emptysoftkey );
       
   326     ButtonGroupContainer().DrawNow();
       
   327     }
       
   328 
       
   329 
       
   330 //  End of File