email/mail/EditorSrc/cmsgmailrestoreattmsgsop.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:  State machine -based operation for restoring attached messages.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cmsgmailrestoreattmsgsop.h"
       
    22 #include "MsgMailEditorDocument.h"
       
    23 #include "MailLog.h"
       
    24 #include <MsgEditorAppUi.rsg>       // resource identifiers
       
    25 #include <MsgMailEditor.rsg>
       
    26 #include <MsgAttachmentModel.h>
       
    27 
       
    28 _LIT8(KMessageMimeType, "message/rfc822");
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMsgMailRestoreAttMsgsOp::CMsgMailRestoreAttMsgsOp
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMsgMailRestoreAttMsgsOp::CMsgMailRestoreAttMsgsOp(
       
    39     CMsgMailEditorDocument& aDocument )
       
    40     : CMsgMailBaseOp( aDocument )
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMsgMailRestoreAttMsgsOp::ConstructL
       
    46 // Symbian 2nd phase constructor can leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CMsgMailRestoreAttMsgsOp::ConstructL()
       
    50     {
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMsgMailRestoreAttMsgsOp::NewL
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CMsgMailRestoreAttMsgsOp* CMsgMailRestoreAttMsgsOp::NewL(
       
    59     CMsgMailEditorDocument& aDocument )
       
    60     {
       
    61     CMsgMailRestoreAttMsgsOp* self =
       
    62         new( ELeave ) CMsgMailRestoreAttMsgsOp( aDocument );
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 // Destructor
       
    72 CMsgMailRestoreAttMsgsOp::~CMsgMailRestoreAttMsgsOp()
       
    73     {
       
    74     LOG( "CMsgMailRestoreAttMsgsOp::~CMsgMailRestoreAttMsgsOp" );
       
    75     Cancel();
       
    76     }
       
    77     
       
    78 // -----------------------------------------------------------------------------
       
    79 // CMsgMailRestoreAttMsgsOp::HandleStateActionL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMsgMailRestoreAttMsgsOp::HandleStateActionL()
       
    83     {
       
    84     switch ( iState )
       
    85         {
       
    86         case EGetMsgDigestEntries:
       
    87             {
       
    88             GetMsgDigestEntriesL();
       
    89             break;
       
    90             }
       
    91         case EPrepareAddAttMsgs:
       
    92             {
       
    93             PrepareAddAttMsgsL();
       
    94             break;
       
    95             }
       
    96         case EAddAttMsgs:
       
    97             {
       
    98             AddAttMsgsL();
       
    99             break;
       
   100             }                               
       
   101         default:
       
   102             {
       
   103             // should never come here
       
   104             ASSERT( EFalse );
       
   105             break;
       
   106             }
       
   107         }
       
   108     }
       
   109     
       
   110 // -----------------------------------------------------------------------------
       
   111 // CMsgMailRestoreAttMsgsOp::SetNextState
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CMsgMailRestoreAttMsgsOp::SetNextState()
       
   115     {
       
   116     switch ( iState )
       
   117         {
       
   118         case EIdleState:
       
   119             {
       
   120             iState = EGetMsgDigestEntries;
       
   121             break;
       
   122             }
       
   123         case EGetMsgDigestEntries:
       
   124             {
       
   125             iState = EPrepareAddAttMsgs;
       
   126             break;
       
   127             }
       
   128         case EPrepareAddAttMsgs: // fall through
       
   129         case EAddAttMsgs:
       
   130             {
       
   131             if ( iIndex < iEntries->Count() )
       
   132                 {
       
   133                 iState = EAddAttMsgs;
       
   134                 }
       
   135             else
       
   136                 {
       
   137                 iState = EIdleState;
       
   138                 }
       
   139             break;
       
   140             }            
       
   141         default:
       
   142             {            
       
   143             iState = EIdleState;
       
   144             break;
       
   145             }
       
   146         }        
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CMsgMailRestoreAttMsgsOp::HandleOperationCancel
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CMsgMailRestoreAttMsgsOp::HandleOperationCancel()
       
   154     {
       
   155     LOG( "CMsgMailRestoreAttMsgsOp::HandleOperationCancel" );
       
   156     if ( iState == EGetMsgDigestEntries )
       
   157         {
       
   158         LOG( "HandleOperationCancel, canceling message operation" );
       
   159         TRAP_IGNORE( iDocument.MessageL().Cancel() );
       
   160         }
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CMsgMailRestoreAttMsgsOp::HandleStateActionError
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TBool CMsgMailRestoreAttMsgsOp::HandleStateActionError( TInt /*aError*/ )
       
   168     {
       
   169     TBool retVal( EFalse );
       
   170     LOG( "CMsgMailRestoreAttMsgsOp::HandleStateActionError" );
       
   171     if ( iState == EAddAttMsgs )
       
   172         { // record the problem and return ETrue to indicate that operation
       
   173           // can be continued
       
   174         iInvalidAttaMsgCount++;
       
   175         retVal = ETrue;
       
   176         }
       
   177     return retVal;
       
   178     }
       
   179     
       
   180 // -----------------------------------------------------------------------------
       
   181 // CMsgMailRestoreAttMsgsOp::GetMsgDigestEntriesL
       
   182 // -----------------------------------------------------------------------------
       
   183 //    
       
   184 void CMsgMailRestoreAttMsgsOp::GetMsgDigestEntriesL()
       
   185     {    
       
   186     iDocument.MessageL().GetMessageDigestEntriesL( iStatus,
       
   187                                                    iDocument.Entry().Id() );
       
   188     SetActive();
       
   189     }
       
   190     
       
   191 // -----------------------------------------------------------------------------
       
   192 // CMsgMailRestoreAttMsgsOp::PrepareAddAttMsgsL
       
   193 // -----------------------------------------------------------------------------
       
   194 //    
       
   195 void CMsgMailRestoreAttMsgsOp::PrepareAddAttMsgsL()
       
   196     {    
       
   197     iEntries = &( iDocument.MessageL().Selection() );
       
   198     // initialize counters and index
       
   199     iAllAttaMsgCount = iEntries->Count();
       
   200     iInvalidAttaMsgCount = 0;    
       
   201     iIndex = 0;
       
   202     CompleteStateAction();
       
   203     }
       
   204     
       
   205 // -----------------------------------------------------------------------------
       
   206 // CMsgMailRestoreAttMsgsOp::AddAttMsgsL
       
   207 // -----------------------------------------------------------------------------
       
   208 //    
       
   209 void CMsgMailRestoreAttMsgsOp::AddAttMsgsL()
       
   210     {    
       
   211     DoAddAttMsgL( iIndex );
       
   212     iIndex++; // increase index for next iteration
       
   213     CompleteStateAction();
       
   214     }    
       
   215     
       
   216 // -----------------------------------------------------------------------------
       
   217 // CMsgMailRestoreAttMsgsOp::DoAddAttMsgL
       
   218 // -----------------------------------------------------------------------------
       
   219 //    
       
   220 void CMsgMailRestoreAttMsgsOp::DoAddAttMsgL( TInt aIndex ) const
       
   221     {
       
   222     ASSERT( iEntries && aIndex < iEntries->Count() );
       
   223     const TDataType messageMimeType( KMessageMimeType );
       
   224     const TMsvId messId( iEntries->At( aIndex ) );
       
   225     CMsvEntry* parententry= iDocument.Session().GetEntryL( messId );
       
   226     CleanupStack::PushL( parententry );
       
   227     const TMsvEntry entry( parententry->Entry() );
       
   228     iDocument.AttachmentModel().AddAttachmentL( entry.iDescription,
       
   229                                                 entry.iSize,
       
   230                                                 messId,
       
   231                                                 entry.Complete(),
       
   232                                                 messageMimeType );
       
   233     CleanupStack::PopAndDestroy(parententry); // parententry
       
   234     }        
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CMsgMailRestoreAttMsgsOp::CountAllAttaMsgs
       
   238 // -----------------------------------------------------------------------------
       
   239 //    
       
   240 TInt CMsgMailRestoreAttMsgsOp::CountAllAttaMsgs() const
       
   241     {
       
   242     return iAllAttaMsgCount;
       
   243     }
       
   244     
       
   245 // -----------------------------------------------------------------------------
       
   246 // CMsgMailRestoreAttMsgsOp::CountInvalidAttaMsgs
       
   247 // -----------------------------------------------------------------------------
       
   248 //    
       
   249 TInt CMsgMailRestoreAttMsgsOp::CountInvalidAttaMsgs() const
       
   250     {
       
   251     return iInvalidAttaMsgCount;
       
   252     }
       
   253         
       
   254 // End Of File