email/mail/EditorSrc/cmsgmailrestoresuperop.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 attachments and attached 
       
    16 * 		messages.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "cmsgmailrestoresuperop.h"
       
    24 #include "MsgMailEditorDocument.h"
       
    25 #include "cmsgmailrestoreattmsgsop.h"
       
    26 #include "cmsgmailrestoreattasop.h"
       
    27 #include "MailUtils.h"
       
    28 #include "MailLog.h"
       
    29 #include <MsgEditorAppUi.rsg>       // resource identifiers
       
    30 #include <MsgMailEditor.rsg>
       
    31 #include <featmgr.h>                    // FeatureManager
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CMsgMailRestoreSuperOp::CMsgMailRestoreSuperOp
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMsgMailRestoreSuperOp::CMsgMailRestoreSuperOp(
       
    42     CMsgMailEditorDocument& aDocument )
       
    43     : CMsgMailBaseOp( aDocument )
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CMsgMailRestoreSuperOp::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CMsgMailRestoreSuperOp::ConstructL()
       
    53     {
       
    54     
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CMsgMailRestoreSuperOp::NewL
       
    59 // Two-phased constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CMsgMailRestoreSuperOp* CMsgMailRestoreSuperOp::NewL(
       
    63     CMsgMailEditorDocument& aDocument )
       
    64     {
       
    65     CMsgMailRestoreSuperOp* self =
       
    66         new( ELeave ) CMsgMailRestoreSuperOp( aDocument );
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     
       
    70     CleanupStack::Pop(self);
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // Destructor
       
    76 CMsgMailRestoreSuperOp::~CMsgMailRestoreSuperOp()
       
    77     {
       
    78     LOG( "CMsgMailRestoreSuperOp::~CMsgMailRestoreSuperOp" );
       
    79     Cancel();
       
    80     delete iRestoreAttMsgsOp;
       
    81     delete iRestoreAttasOp; 
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CMsgMailRestoreSuperOp::HandleStateActionL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CMsgMailRestoreSuperOp::HandleStateActionL()
       
    89     {
       
    90     switch ( iState )
       
    91         {
       
    92         case ERestoreAttachments:
       
    93             {            
       
    94             RestoreAttachmentsL();
       
    95             break;
       
    96             }
       
    97         case ERestoreAttachedMsgs:
       
    98             {            
       
    99             RestoreAttachedMsgsL();
       
   100             break;
       
   101             }
       
   102         default:
       
   103             {
       
   104             // should never come here
       
   105             ASSERT( EFalse );
       
   106             break;
       
   107             }
       
   108         }
       
   109     }
       
   110     
       
   111 // -----------------------------------------------------------------------------
       
   112 // CMsgMailRestoreSuperOp::SetNextState
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CMsgMailRestoreSuperOp::SetNextState()
       
   116     {
       
   117     switch ( iState )
       
   118         {
       
   119         case EIdleState:
       
   120             {
       
   121             iState = ERestoreAttachments;
       
   122             break;
       
   123             }        
       
   124         case ERestoreAttachments:
       
   125             {
       
   126             iState = ERestoreAttachedMsgs;
       
   127             break;
       
   128             }        
       
   129         case ERestoreAttachedMsgs:
       
   130         default:
       
   131             {            
       
   132             iState = EIdleState;
       
   133             break;
       
   134             }
       
   135         }        
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CMsgMailRestoreSuperOp::HandleOperationCancel
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CMsgMailRestoreSuperOp::HandleOperationCancel()
       
   143     {
       
   144     LOG( "CMsgMailRestoreSuperOp::HandleOperationCancel, deleting iRestoreAttasOp" );    
       
   145     delete iRestoreAttasOp;
       
   146     iRestoreAttasOp = NULL;
       
   147     LOG( "CHandleOperationCancel, ...deleting iRestoreAttMsgsOp..." );
       
   148     delete iRestoreAttMsgsOp;
       
   149     iRestoreAttMsgsOp = NULL;
       
   150     LOG( "HandleOperationCancel, ...finished" );        
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CMsgMailRestoreSuperOp::RestoreAttachmentsL
       
   155 // -----------------------------------------------------------------------------
       
   156 //    
       
   157 void CMsgMailRestoreSuperOp::RestoreAttachmentsL()
       
   158     {
       
   159     delete iRestoreAttasOp;
       
   160     iRestoreAttasOp = NULL;
       
   161     iRestoreAttasOp = CMsgMailRestoreAttasOp::NewL( iDocument );    
       
   162     iRestoreAttasOp->StartOp( iStatus );
       
   163     SetActive();
       
   164     }
       
   165     
       
   166 // -----------------------------------------------------------------------------
       
   167 // CMsgMailRestoreSuperOp::RestoreAttachedMsgsL
       
   168 // -----------------------------------------------------------------------------
       
   169 //    
       
   170 void CMsgMailRestoreSuperOp::RestoreAttachedMsgsL()
       
   171     {
       
   172     delete iRestoreAttMsgsOp;
       
   173     iRestoreAttMsgsOp = NULL;
       
   174     iRestoreAttMsgsOp = CMsgMailRestoreAttMsgsOp::NewL( iDocument );        
       
   175     iRestoreAttMsgsOp->StartOp( iStatus );
       
   176     SetActive();
       
   177     }
       
   178     
       
   179 // ----------------------------------------------------------------------------
       
   180 //  CMsgMailRestoreSuperOp::ShowNoteIfInvalidAttaL()
       
   181 // ----------------------------------------------------------------------------
       
   182 //
       
   183 TBool CMsgMailRestoreSuperOp::ShowNoteIfInvalidAttaL() const
       
   184     {
       
   185     TBool retVal( EFalse );
       
   186     TInt attachmentCount = iRestoreAttasOp->CountAllAttas();
       
   187     attachmentCount += iRestoreAttMsgsOp->CountAllAttaMsgs();
       
   188     TInt invalidAttachmentCount = iRestoreAttasOp->CountInvalidAttas();
       
   189     invalidAttachmentCount += iRestoreAttMsgsOp->CountInvalidAttaMsgs();
       
   190     
       
   191     TInt resourceId( NULL );   
       
   192     switch ( invalidAttachmentCount )
       
   193         {
       
   194         case 0:
       
   195             // Do nothing
       
   196             break;
       
   197         case 1:
       
   198             resourceId = attachmentCount != invalidAttachmentCount ?
       
   199                          R_MAIL_ONE_INVALID_ATTACHMENT :
       
   200                          R_MAIL_INVALID_ATTACHMENT;
       
   201             break;
       
   202         default:
       
   203             resourceId = attachmentCount != invalidAttachmentCount ?
       
   204                          R_MAIL_FEW_INVALID_ATTACHMENTS :
       
   205                          R_MAIL_ALL_INVALID_ATTACHMENTS;
       
   206             break;
       
   207         }
       
   208     // Corrupted info note
       
   209     if ( resourceId )
       
   210         {
       
   211         MailUtils::InformationNoteL( resourceId );
       
   212         retVal = ETrue;
       
   213         }
       
   214     return retVal;
       
   215     }
       
   216     
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 // CMsgMailRestoreSuperOp::ShowNoteIfDRMAttaL
       
   220 // ----------------------------------------------------------------------------
       
   221 //
       
   222 TBool CMsgMailRestoreSuperOp::ShowNoteIfDRMAttaL() const
       
   223     {
       
   224     TBool retVal( EFalse );
       
   225     if ( FeatureManager::FeatureSupported( KFeatureIdDrmFull ) )
       
   226         {
       
   227         TInt drmAttaCount = iRestoreAttasOp->CountDRMAttas();
       
   228         if ( drmAttaCount > 0 )
       
   229             {
       
   230             MailUtils::InformationNoteL( drmAttaCount == 1 ?
       
   231                                          R_QTN_MAIL_SEND_FORBID_1 :
       
   232                                          R_QTN_MAIL_SEND_FORBID );
       
   233             retVal = ETrue;
       
   234             }
       
   235         }
       
   236     return retVal;
       
   237     }    
       
   238     
       
   239 // End Of File