email/imum/Mtms/Src/Imap4SizeAndFetchOp.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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 *       Fetch operation with checking of available disk space
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <eikenv.h>
       
    21 #include <eikrutil.h>
       
    22 
       
    23 #include "Imap4SizeAndFetchOp.h"
       
    24 #include "Imap4FetchOp.h"
       
    25 #include "EmailMsgSizerOperation.h"
       
    26 #include "EmailUtils.H"
       
    27 #include "ImumDisconnectOperation.h"
       
    28 #include "IMAPPRGR.H"
       
    29 #include "ImumMtmLogging.h"
       
    30 #include "ImumPanic.h"
       
    31 
       
    32 // Constants
       
    33 const TInt KSizeAndFetchPriority = CActive::EPriorityStandard;
       
    34 
       
    35 // ----------------------------------------------------------------------------
       
    36 // NewL
       
    37 // ----------------------------------------------------------------------------
       
    38 CImap4SizeAndFetchOp* CImap4SizeAndFetchOp::NewL(
       
    39     CImumInternalApi& aMailboxApi,
       
    40     TRequestStatus& aStatus,
       
    41     MMsvProgressReporter& aReporter,
       
    42     TMsvId aService,
       
    43     TInt aFunctionId,
       
    44     const TImImap4GetMailInfo& aGetMailInfo,
       
    45     const CMsvEntrySelection& aSel)
       
    46     {
       
    47     IMUM_STATIC_CONTEXT( CImap4SizeAndFetchOp::NewL, 0, mtm, KImumMtmLog );
       
    48     IMUM_IN();
       
    49     
       
    50     CImap4SizeAndFetchOp* op = new(ELeave) CImap4SizeAndFetchOp(
       
    51         aMailboxApi, aStatus, aReporter, aService, aFunctionId, aGetMailInfo);
       
    52     CleanupStack::PushL(op);
       
    53     op->ConstructL(aSel);
       
    54     CleanupStack::Pop();
       
    55     IMUM_OUT();
       
    56     return op;
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // ~CImap4SizeAndFetchOp
       
    61 // ----------------------------------------------------------------------------
       
    62 CImap4SizeAndFetchOp::~CImap4SizeAndFetchOp()
       
    63     {
       
    64     IMUM_CONTEXT( CImap4SizeAndFetchOp::~CImap4SizeAndFetchOp, 0, KImumMtmLog );
       
    65     IMUM_IN();
       
    66     IMUM_OUT();
       
    67     
       
    68     delete iSelection;
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // GetErrorProgressL
       
    73 // ----------------------------------------------------------------------------
       
    74 const TDesC8& CImap4SizeAndFetchOp::GetErrorProgressL(TInt aError)
       
    75     {
       
    76     IMUM_CONTEXT( CImap4SizeAndFetchOp::GetErrorProgressL, 0, KImumMtmLog );
       
    77     IMUM_IN();
       
    78     
       
    79     TImap4CompoundProgress& progress = iProgressBuf();
       
    80     progress.iGenericProgress.iOperation = TImap4GenericProgress::EPopulate;
       
    81     progress.iGenericProgress.iState = TImap4GenericProgress::EFetching;
       
    82     progress.iGenericProgress.iErrorCode = aError;
       
    83     IMUM_OUT();
       
    84     return iProgressBuf;
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CImap4SizeAndFetchOp
       
    89 // ----------------------------------------------------------------------------
       
    90 CImap4SizeAndFetchOp::CImap4SizeAndFetchOp(
       
    91     CImumInternalApi& aMailboxApi,
       
    92     TRequestStatus& aStatus,
       
    93     MMsvProgressReporter& aReporter,
       
    94     TMsvId aService,
       
    95     TInt aFunctionId,
       
    96     const TImImap4GetMailInfo& aGetMailInfo )
       
    97     :
       
    98     CImumOnlineOperation(aMailboxApi, KSizeAndFetchPriority, aStatus, aReporter),
       
    99     iState(EStateIdle),
       
   100     iFunctionId(aFunctionId),
       
   101     iGetMailInfo(aGetMailInfo)
       
   102     {
       
   103     IMUM_CONTEXT( CImap4SizeAndFetchOp::CImap4SizeAndFetchOp, 0, KImumMtmLog );
       
   104     IMUM_IN();
       
   105     
       
   106     iService = aService;
       
   107     IMUM_OUT();
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // ConstructL
       
   112 // ----------------------------------------------------------------------------
       
   113 void CImap4SizeAndFetchOp::ConstructL(const CMsvEntrySelection& aSel)
       
   114     {
       
   115     IMUM_CONTEXT( CImap4SizeAndFetchOp::ConstructL, 0, KImumMtmLog );
       
   116     IMUM_IN();
       
   117     
       
   118     __ASSERT_DEBUG(aSel.Count(),
       
   119         User::Panic(KImumMtmUiPanic,EPanicSelectionEmpty));
       
   120     if ( aSel.Count() == 0 )
       
   121         {
       
   122         User::Leave( KErrNotSupported );
       
   123         }
       
   124     iSelection = aSel.CopyL();
       
   125 #ifdef _DEBUG
       
   126     const TInt count = aSel.Count();
       
   127     for ( TInt loop = 0; loop < count; loop++ )
       
   128         {
       
   129         }
       
   130 #endif
       
   131 
       
   132     BaseConstructL(KUidMsgTypeIMAP4);
       
   133     DoSizeMessageL();
       
   134     IMUM_OUT();
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // DoRunL
       
   139 // ----------------------------------------------------------------------------
       
   140 void CImap4SizeAndFetchOp::DoRunL()
       
   141     {
       
   142     IMUM_CONTEXT( CImap4SizeAndFetchOp::DoRunL, 0, KImumMtmLog );
       
   143     IMUM_IN();
       
   144     
       
   145     switch(iState)
       
   146         {
       
   147         case EStateSizeMsg:
       
   148             // Finished determining message size.
       
   149             if(!CheckMessageSizeL())
       
   150                 {
       
   151                 // Not enough storage, user already informed.
       
   152                 CompleteObserver();
       
   153                 iState = EStateIdle;
       
   154                 }
       
   155             else
       
   156                 {
       
   157                 DoSizeNextMessageL();
       
   158                 }
       
   159             break;
       
   160         case EStateFetchMsg:
       
   161             // Finished fetching message.
       
   162             CompleteObserver();
       
   163             iState = EStateIdle;
       
   164             break;
       
   165         case EStateIdle:
       
   166         default:
       
   167             break;
       
   168         }
       
   169     IMUM_OUT();
       
   170     }
       
   171 
       
   172 // ----------------------------------------------------------------------------
       
   173 // DoSizeMessageL
       
   174 // ----------------------------------------------------------------------------
       
   175 void CImap4SizeAndFetchOp::DoSizeMessageL()
       
   176     {
       
   177     IMUM_CONTEXT( CImap4SizeAndFetchOp::DoSizeMessageL, 0, KImumMtmLog );
       
   178     IMUM_IN();
       
   179     
       
   180     iState = EStateSizeMsg;
       
   181     iStatus = KRequestPending;
       
   182     delete iOperation;
       
   183     iOperation = NULL;
       
   184     iOperation = CEmailMsgSizerOperation::NewL(
       
   185         iMailboxApi, iStatus, (*iSelection)[ iCurrentMsgToSize ], iMtm);
       
   186     SetActive();
       
   187     IMUM_OUT();
       
   188     }
       
   189 
       
   190 // ----------------------------------------------------------------------------
       
   191 // DoSizeNextMessageL
       
   192 // ----------------------------------------------------------------------------
       
   193 void CImap4SizeAndFetchOp::DoSizeNextMessageL()
       
   194     {
       
   195     IMUM_CONTEXT( CImap4SizeAndFetchOp::DoSizeNextMessageL, 0, KImumMtmLog );
       
   196     IMUM_IN();
       
   197     
       
   198     iCurrentMsgToSize++;
       
   199     if ( iCurrentMsgToSize < iSelection->Count() )
       
   200         {
       
   201         DoSizeMessageL();
       
   202         }
       
   203     else
       
   204         {
       
   205         DoFetchMessageL();
       
   206         }
       
   207     IMUM_OUT();
       
   208     }
       
   209 
       
   210 // ----------------------------------------------------------------------------
       
   211 // DoFetchMessageL
       
   212 // ----------------------------------------------------------------------------
       
   213 void CImap4SizeAndFetchOp::DoFetchMessageL()
       
   214     {
       
   215     IMUM_CONTEXT( CImap4SizeAndFetchOp::DoFetchMessageL, 0, KImumMtmLog );
       
   216     IMUM_IN();
       
   217     
       
   218     iState = EStateFetchMsg;
       
   219     iStatus = KRequestPending;
       
   220     delete iOperation;
       
   221     iOperation = NULL;
       
   222     iOperation = CImap4FetchOp::NewL(
       
   223         iMailboxApi, iStatus, iReporter, iService,
       
   224         iFunctionId, iGetMailInfo, *iSelection);
       
   225     SetActive();
       
   226     IMUM_OUT();
       
   227     }
       
   228 
       
   229 // ----------------------------------------------------------------------------
       
   230 // CheckMessageSizeL
       
   231 // ----------------------------------------------------------------------------
       
   232 TBool CImap4SizeAndFetchOp::CheckMessageSizeL()
       
   233     {
       
   234     IMUM_CONTEXT( CImap4SizeAndFetchOp::CheckMessageSizeL, 0, KImumMtmLog );
       
   235     IMUM_IN();
       
   236     
       
   237     CEmailMsgSizerOperation& sizer = *STATIC_CAST(CEmailMsgSizerOperation*, iOperation);
       
   238     TInt32 msgSize = 0;
       
   239 
       
   240     switch(iGetMailInfo.iGetMailBodyParts)
       
   241         {
       
   242         case EGetImap4EmailBodyText:
       
   243             msgSize = sizer.BodyTextSizeL();
       
   244             break;
       
   245         case EGetImap4EmailBodyAlternativeText:
       
   246         case EGetImap4EmailBodyTextAndAttachments:
       
   247             msgSize = sizer.TotalMessageSize();
       
   248             break;
       
   249         case EGetImap4EmailAttachments:
       
   250             msgSize = sizer.SizeOfAllAttachmentsL();
       
   251             break;
       
   252         case EGetImap4EmailHeaders:
       
   253         default:
       
   254             break;
       
   255         }
       
   256     iTotalSizeToFetch += msgSize;
       
   257     
       
   258     IMUM_OUT();
       
   259     
       
   260     return ETrue;
       
   261     }
       
   262 
       
   263 // End of File