email/mail/EditorSrc/cmsgmailrestoreattasop.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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 *           State machine -based operation for restoring message's attachments.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "cmsgmailrestoreattasop.h"
       
    23 #include "cmsgmailrestoreattaop.h"
       
    24 #include "MsgMailEditorDocument.h"
       
    25 #include "MailLog.h"
       
    26 #include <mmsvattachmentmanager.h>
       
    27 #include <MsgAttachmentModel.h>
       
    28 #include <caf/caferr.h>
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMsgMailRestoreAttasOp::CMsgMailRestoreAttasOp
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMsgMailRestoreAttasOp::CMsgMailRestoreAttasOp(
       
    39     CMsgMailEditorDocument& aDocument )
       
    40     : CMsgMailBaseOp( aDocument )
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMsgMailRestoreAttasOp::ConstructL
       
    46 // Symbian 2nd phase constructor can leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CMsgMailRestoreAttasOp::ConstructL()
       
    50     {    
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMsgMailRestoreAttasOp::NewL
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CMsgMailRestoreAttasOp* CMsgMailRestoreAttasOp::NewL(
       
    59     CMsgMailEditorDocument& aDocument )
       
    60     {
       
    61     CMsgMailRestoreAttasOp* self =
       
    62         new( ELeave ) CMsgMailRestoreAttasOp( aDocument );
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     
       
    66     CleanupStack::Pop(self);
       
    67     return self;
       
    68     }
       
    69 
       
    70 // Destructor
       
    71 CMsgMailRestoreAttasOp::~CMsgMailRestoreAttasOp()
       
    72     {
       
    73     LOG( "CMsgMailRestoreAttasOp::~CMsgMailRestoreAttasOp" );
       
    74     Cancel();
       
    75     // just to be sure that allocations are freed:    
       
    76     delete iRestoreOneAtta;
       
    77     }
       
    78     
       
    79 // -----------------------------------------------------------------------------
       
    80 // CMsgMailRestoreAttasOp::HandleStateActionL
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CMsgMailRestoreAttasOp::HandleStateActionL()
       
    84     {
       
    85     switch ( iState )
       
    86         {
       
    87         case EInitialize:
       
    88             {
       
    89             InitializeL();
       
    90             break;
       
    91             }
       
    92         case ERestoreAtta:
       
    93             {
       
    94             RestoreAttaL();
       
    95             break;
       
    96             }        
       
    97         case EFinalize:
       
    98             {
       
    99             Finalize();
       
   100             break;
       
   101             }            
       
   102         default:
       
   103             {
       
   104             // should never come here
       
   105             ASSERT( EFalse );
       
   106             break;
       
   107             }
       
   108         }
       
   109     }
       
   110     
       
   111 // -----------------------------------------------------------------------------
       
   112 // CMsgMailRestoreAttasOp::SetNextState
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CMsgMailRestoreAttasOp::SetNextState()
       
   116     {
       
   117     switch ( iState )
       
   118         {
       
   119         case EIdleState:
       
   120             {
       
   121             iState = EInitialize;
       
   122             break;
       
   123             }
       
   124         case EInitialize:
       
   125             {
       
   126             if ( iManager->AttachmentCount() > 0 )
       
   127                 {
       
   128                 iState = ERestoreAtta;
       
   129                 }
       
   130             else
       
   131                 {
       
   132                 iState = EFinalize;
       
   133                 }
       
   134             break;
       
   135             }
       
   136         case ERestoreAtta:
       
   137             {
       
   138             if ( iIndex < iManager->AttachmentCount() )
       
   139                 { // proceed to next attachment
       
   140                 iState = ERestoreAtta;
       
   141                 }
       
   142             else
       
   143                 { // all attas handled -> finalize operation
       
   144                 iState = EFinalize;
       
   145                 }
       
   146             break;
       
   147             }                        
       
   148         case EFinalize: // fall through
       
   149         default:
       
   150             {            
       
   151             iState = EIdleState;
       
   152             break;
       
   153             }
       
   154         }        
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CMsgMailRestoreAttasOp::HandleOperationCancel
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CMsgMailRestoreAttasOp::HandleOperationCancel()
       
   162     {
       
   163     LOG( "CMsgMailRestoreAttasOp::HandleOperationCancel" );
       
   164     // deletion cancels possibly running asynchronous task
       
   165     delete iRestoreOneAtta;
       
   166     iRestoreOneAtta = NULL;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CMsgMailRestoreAttasOp::HandleStateActionError
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TBool CMsgMailRestoreAttasOp::HandleStateActionError( TInt aError )
       
   174     {
       
   175     TBool retVal( EFalse );
       
   176     LOG( "CMsgMailRestoreAttasOp::HandleStateActionError" );
       
   177     if ( iState == ERestoreAtta )
       
   178         { // record the problem and return ETrue to indicate that operation
       
   179           // can be continued
       
   180         if ( aError == KErrCANoPermission )
       
   181             {
       
   182             iDRMAttaCount++;
       
   183             // atta was removed and rest of the attachments move in the list,
       
   184             // so we must adjust index properly
       
   185             iIndex--;
       
   186             }
       
   187         else
       
   188             {
       
   189             iInvalidAttaCount++;
       
   190             }
       
   191         retVal = ETrue;
       
   192         }
       
   193     return retVal;
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CMsgMailRestoreAttasOp::InitializeL
       
   198 // -----------------------------------------------------------------------------
       
   199 //    
       
   200 void CMsgMailRestoreAttasOp::InitializeL()
       
   201     {
       
   202     LOG( "CMsgMailRestoreAttasOp::InitializeL" );
       
   203 	iManager = &( iDocument.GetAttachmentManagerL() );    
       
   204     iAllAttaCount = iManager->AttachmentCount();
       
   205     iDRMAttaCount = 0;
       
   206     iInvalidAttaCount = 0;
       
   207     iIndex = 0; // in the beginning we start with index 0
       
   208     // hide confirmation note when restoring
       
   209     iDocument.SetConfirmation( EFalse );    
       
   210     iDocument.AttachmentModel().Reset();    
       
   211     CompleteStateAction();
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CMsgMailRestoreAttasOp::RestoreAttaL
       
   216 // -----------------------------------------------------------------------------
       
   217 //    
       
   218 void CMsgMailRestoreAttasOp::RestoreAttaL()
       
   219     {
       
   220     LOG( "CMsgMailRestoreAttasOp::RestoreAttaL" );
       
   221     delete iRestoreOneAtta;
       
   222     iRestoreOneAtta = NULL;    
       
   223     iRestoreOneAtta = CMsgMailRestoreAttaOp::NewL( iIndex, iDocument );
       
   224     iRestoreOneAtta->StartOp( iStatus ); // will complete when atta restored
       
   225     SetActive();
       
   226     iIndex++; // increment index by one for each new atta    
       
   227     }
       
   228         
       
   229 // -----------------------------------------------------------------------------
       
   230 // CMsgMailRestoreAttasOp::Finalize
       
   231 // -----------------------------------------------------------------------------
       
   232 //    
       
   233 void CMsgMailRestoreAttasOp::Finalize()
       
   234     {
       
   235     delete iRestoreOneAtta;
       
   236     iRestoreOneAtta = NULL;        
       
   237     LOG( "CMsgMailRestoreAttasOp::Finalize" );
       
   238     iDocument.SetConfirmation( ETrue );
       
   239     // this was updated incorrectly to ETrue in Document's NotifyChanges
       
   240     iDocument.SetChanged( EFalse );
       
   241     CompleteStateAction();
       
   242     }    
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CMsgMailRestoreAttasOp::CountAllAttas
       
   246 // -----------------------------------------------------------------------------
       
   247 //    
       
   248 TInt CMsgMailRestoreAttasOp::CountAllAttas() const
       
   249     {
       
   250     return iAllAttaCount;
       
   251     }
       
   252     
       
   253 // -----------------------------------------------------------------------------
       
   254 // CMsgMailRestoreAttasOp::CountDRMAttas
       
   255 // -----------------------------------------------------------------------------
       
   256 //    
       
   257 TInt CMsgMailRestoreAttasOp::CountDRMAttas() const
       
   258     {
       
   259     return iDRMAttaCount;
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CMsgMailRestoreAttasOp::CountInvalidAttas
       
   264 // -----------------------------------------------------------------------------
       
   265 //    
       
   266 TInt CMsgMailRestoreAttasOp::CountInvalidAttas() const
       
   267     {
       
   268     return iInvalidAttaCount;
       
   269     }
       
   270         
       
   271 // End Of File