emailuis/nmframeworkadapter/src/nmfwamessagepartfetchingoperation.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     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 NmFwaMessagePartFetchingOperation::NmFwaMessagePartFetchingOperation(
       
    24         const NmId &mailboxId,
       
    25         const NmId &folderId,
       
    26         const NmId &messageId,
       
    27         const NmId &messagePartId,
       
    28         CFSMailClient &mailClient,
       
    29         QObject *parent) : 
       
    30     NmOperation(parent),
       
    31     mMailboxId(mailboxId), 
       
    32     mFolderId(folderId), 
       
    33     mMessageId(messageId), 
       
    34     mMessagePartId(messagePartId),
       
    35     mMailClient(mailClient), 
       
    36     mLastProgressValue(0), 
       
    37     mRequestId(0)
       
    38 
       
    39 {
       
    40     
       
    41 }
       
    42 
       
    43 /*!
       
    44 
       
    45  */
       
    46 NmFwaMessagePartFetchingOperation::~NmFwaMessagePartFetchingOperation()
       
    47 {
       
    48     doCancelOperation();
       
    49 }
       
    50 
       
    51 /*!
       
    52 
       
    53  */
       
    54 void NmFwaMessagePartFetchingOperation::RequestResponseL(TFSProgress aEvent, TInt aRequestId)
       
    55 {
       
    56     if (aRequestId == mRequestId) {
       
    57         if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete ) {
       
    58             completeOperation(aEvent.iError);
       
    59         }
       
    60         else if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled) {
       
    61             // emit cancelled
       
    62             operationCancelled();
       
    63         }
       
    64         else if (aEvent.iProgressStatus == TFSProgress::EFSStatus_Status) {
       
    65             int progress = 0;
       
    66             if (aEvent.iMaxCount > 0) {
       
    67                 // calculate progress per cents
       
    68                 qreal counterValue = aEvent.iCounter;
       
    69                 qreal maxCount = aEvent.iMaxCount;
       
    70                 progress = (counterValue / maxCount)*100;
       
    71             }
       
    72             if (progress > mLastProgressValue) {
       
    73                 // send only increasing values to prevent downward changing percentage
       
    74                 mLastProgressValue = progress;
       
    75                 updateOperationProgress(mLastProgressValue);
       
    76             }
       
    77         }
       
    78     }
       
    79 }
       
    80 
       
    81 /*!
       
    82 
       
    83  */
       
    84 void NmFwaMessagePartFetchingOperation::runAsyncOperation()
       
    85 {
       
    86     TRAPD(err, runAsyncOperationL());
       
    87     if (err != KErrNone) {
       
    88         completeOperation(NmGeneralError);
       
    89     }
       
    90 }
       
    91 
       
    92 /*!
       
    93     Leaving version from runAsyncOperation
       
    94  */
       
    95 void NmFwaMessagePartFetchingOperation::runAsyncOperationL()
       
    96 {
       
    97     const TFSMailMsgId mailboxId(mMailboxId.pluginId32(), mMailboxId.id32());
       
    98     const TFSMailMsgId folderId(mFolderId.pluginId32(), mFolderId.id32());
       
    99     const TFSMailMsgId messageId(mMessageId.pluginId32(), mMessageId.id32());
       
   100     const TFSMailMsgId messagePartId(mMessagePartId.pluginId32(), mMessagePartId.id32());
       
   101 
       
   102     CFSMailMessage *message(NULL);
       
   103     message = mMailClient.GetMessageByUidL(mailboxId, folderId, messageId, EFSMsgDataEnvelope);
       
   104     CleanupStack::PushL(message);
       
   105    
       
   106     if (message) {
       
   107         CFSMailMessagePart* messagePart = message->ChildPartL( messagePartId );
       
   108         CleanupStack::PushL(messagePart);
       
   109         if (messagePart) {            
       
   110             mRequestId = messagePart->FetchMessagePartL(messagePartId, *this, 0);
       
   111         }
       
   112         else {
       
   113             completeOperation(NmNotFoundError);
       
   114         }
       
   115         CleanupStack::PopAndDestroy(messagePart);
       
   116     }
       
   117     else {
       
   118         completeOperation(NmNotFoundError);
       
   119     }
       
   120     CleanupStack::PopAndDestroy(message);
       
   121 }
       
   122 
       
   123 /*!
       
   124 
       
   125  */
       
   126 void NmFwaMessagePartFetchingOperation::doCancelOperation()
       
   127 {
       
   128     TRAP_IGNORE(mMailClient.CancelL(mRequestId));
       
   129 }