emailuis/nmframeworkadapter/src/nmfwamessagepartsfetchingoperation.cpp
branchGCC_SURGE
changeset 55 cdd802add233
parent 30 759dc5235cdb
child 51 d845db10c0d4
equal deleted inserted replaced
28:011f79704660 55:cdd802add233
       
     1 /*
       
     2  * Copyright (c) 2010 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  *
       
    16  */
       
    17 
       
    18 #include "nmframeworkadapterheaders.h"
       
    19 
       
    20 /*!
       
    21 
       
    22  */
       
    23 NmFwaMessagePartsFetchingOperation::NmFwaMessagePartsFetchingOperation(
       
    24         const NmId &mailboxId,
       
    25         const NmId &folderId,
       
    26         const NmId &messageId,
       
    27         const QList<NmId> &messagePartIds,
       
    28         CFSMailClient &mailClient)
       
    29   : mMailboxId(mailboxId), 
       
    30     mFolderId(folderId), 
       
    31     mMessageId(messageId), 
       
    32     mMailClient(mailClient), 
       
    33     mLastProgressValue(0), 
       
    34     mRequestId(0)
       
    35 
       
    36 {
       
    37     NM_FUNCTION;
       
    38     
       
    39     // Take own copy of the message part id list.
       
    40     mMessagePartIds.Reset();
       
    41     for (int i=0; i<messagePartIds.count(); ++i) {
       
    42         mMessagePartIds.Append(
       
    43             NmConverter::nmIdToMailMsgId(
       
    44                 messagePartIds.at(i)));
       
    45     }
       
    46     
       
    47 }
       
    48 
       
    49 /*!
       
    50 
       
    51  */
       
    52 NmFwaMessagePartsFetchingOperation::~NmFwaMessagePartsFetchingOperation()
       
    53 {
       
    54     NM_FUNCTION;
       
    55     
       
    56     doCancelOperation();
       
    57 }
       
    58 
       
    59 /*!
       
    60 
       
    61  */
       
    62 void NmFwaMessagePartsFetchingOperation::RequestResponseL(TFSProgress aEvent, TInt aRequestId)
       
    63 {
       
    64     NM_FUNCTION;
       
    65     
       
    66     if (aRequestId == mRequestId) {
       
    67         if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete ) {
       
    68             completeOperation(aEvent.iError);
       
    69         }
       
    70         else if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled) {
       
    71             completeOperation(NmCancelError);
       
    72         }
       
    73         else if (aEvent.iProgressStatus == TFSProgress::EFSStatus_Status) {
       
    74             int progress = 0;
       
    75             if (aEvent.iMaxCount > 0) {
       
    76                 // calculate progress per cents
       
    77                 qreal counterValue = aEvent.iCounter;
       
    78                 qreal maxCount = aEvent.iMaxCount;
       
    79                 progress = (counterValue / maxCount)*100;
       
    80             }
       
    81             if (progress > mLastProgressValue) {
       
    82                 // send only increasing values to prevent downward changing percentage
       
    83                 mLastProgressValue = progress;
       
    84                 updateOperationProgress(mLastProgressValue);
       
    85             }
       
    86         }
       
    87     }
       
    88 }
       
    89 
       
    90 /*!
       
    91 
       
    92  */
       
    93 void NmFwaMessagePartsFetchingOperation::doRunAsyncOperation()
       
    94 {
       
    95     NM_FUNCTION;
       
    96     
       
    97     TRAPD(err, doRunAsyncOperationL());
       
    98     if (err != KErrNone) {
       
    99         completeOperation(NmGeneralError);
       
   100     }
       
   101 }
       
   102 
       
   103 /*!
       
   104     Leaving version from doRunAsyncOperation
       
   105  */
       
   106 void NmFwaMessagePartsFetchingOperation::doRunAsyncOperationL()
       
   107 {
       
   108     NM_FUNCTION;
       
   109     
       
   110     if (mMessagePartIds.Count() > 0) {
       
   111         
       
   112         const TFSMailMsgId mailboxId(mMailboxId.pluginId32(), mMailboxId.id32());
       
   113         const TFSMailMsgId folderId(mFolderId.pluginId32(), mFolderId.id32());
       
   114         const TFSMailMsgId messageId(mMessageId.pluginId32(), mMessageId.id32());
       
   115         
       
   116         CFSMailMessage *message(NULL);
       
   117         message = mMailClient.GetMessageByUidL(mailboxId, folderId, messageId, EFSMsgDataEnvelope);
       
   118         CleanupStack::PushL(message);
       
   119        
       
   120         if (message) {
       
   121             CFSMailMessagePart* messagePart = message->ChildPartL( mMessagePartIds[0] );
       
   122             CleanupStack::PushL(messagePart);
       
   123             if (messagePart) {            
       
   124                 mRequestId = messagePart->FetchMessagesPartsL(mMessagePartIds,*this,0);
       
   125             }
       
   126             else {
       
   127                 completeOperation(NmNotFoundError);
       
   128             }
       
   129             CleanupStack::PopAndDestroy(messagePart);
       
   130         }
       
   131         else {
       
   132             completeOperation(NmNotFoundError);
       
   133         }
       
   134         CleanupStack::PopAndDestroy(message);
       
   135     }
       
   136     else {
       
   137         completeOperation(NmNotFoundError);
       
   138     }
       
   139 }
       
   140 
       
   141 /*!
       
   142  * Complete the operation
       
   143  */
       
   144 void NmFwaMessagePartsFetchingOperation::doCompleteOperation()
       
   145 {
       
   146     NM_FUNCTION;
       
   147     
       
   148     mRequestId = NmNotFoundError;
       
   149 }
       
   150 
       
   151 /*!
       
   152     Cancels the async operation. \sa NmOperation
       
   153  */
       
   154 void NmFwaMessagePartsFetchingOperation::doCancelOperation()
       
   155 {
       
   156     NM_FUNCTION;
       
   157     
       
   158     if (mRequestId >= 0) {
       
   159         TRAP_IGNORE(mMailClient.CancelL(mRequestId));
       
   160         mRequestId = NmNotFoundError;
       
   161     }
       
   162 }