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