emailuis/nmframeworkadapter/src/nmfwamessagefetchingoperation.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2  * Copyright (c) 2009 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 "nmfwamessagefetchingoperation.h"
       
    19 #include "nmframeworkadapterheaders.h"
       
    20 
       
    21 NmFwaMessageFetchingOperation::NmFwaMessageFetchingOperation(
       
    22     const NmId &mailboxId,
       
    23     const NmId &folderId,
       
    24     const NmId &messageId,
       
    25     CFSMailClient &mailClient,
       
    26     QObject *parent) :
       
    27         NmOperation(parent),
       
    28         mMailboxId(mailboxId),
       
    29         mFolderId(folderId),
       
    30         mMessageId(messageId),
       
    31         mMailClient(mailClient),
       
    32         mRequestId(0)
       
    33 
       
    34 {
       
    35 }
       
    36 
       
    37 NmFwaMessageFetchingOperation::~NmFwaMessageFetchingOperation()
       
    38 {
       
    39     doCancelOperation();
       
    40 }
       
    41 
       
    42 void NmFwaMessageFetchingOperation::runAsyncOperation()
       
    43 {
       
    44     const TFSMailMsgId mailboxId(mMailboxId.pluginId32(), mMailboxId.id32());
       
    45     const TFSMailMsgId folderId(mFolderId.pluginId32(), mFolderId.id32());
       
    46     const TFSMailMsgId messageId(mMessageId.pluginId32(), mMessageId.id32());
       
    47 
       
    48     CFSMailFolder *folder( NULL );
       
    49     TRAP_IGNORE(folder = mMailClient.GetFolderByUidL(mailboxId, folderId));
       
    50    
       
    51     if (folder) {
       
    52         RArray<TFSMailMsgId> messageIds; // Cleanupstack not needed
       
    53         messageIds.Append( messageId );
       
    54         TRAPD(err, mRequestId = folder->FetchMessagesL( messageIds, EFSMsgDataStructure, *this ));
       
    55         messageIds.Close();
       
    56         if (err != KErrNone) {
       
    57             completeOperation(NmGeneralError);
       
    58         }
       
    59         delete folder;
       
    60         folder = NULL;
       
    61     }
       
    62     else {
       
    63         completeOperation(NmNotFoundError);
       
    64     }
       
    65 }
       
    66 
       
    67 void NmFwaMessageFetchingOperation::doCancelOperation()
       
    68 {
       
    69     TRAP_IGNORE(mMailClient.CancelL(mRequestId));
       
    70 }
       
    71 
       
    72 /*!
       
    73  asynchronous request response message
       
    74  
       
    75  \param aEvent plugin event description
       
    76  \param mailClient Reference to mail client object
       
    77  */
       
    78 void NmFwaMessageFetchingOperation::RequestResponseL(TFSProgress aEvent, TInt aRequestId)
       
    79 {
       
    80     if (aRequestId == mRequestId) {
       
    81         if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete ) {
       
    82             completeOperation(NmNoError);
       
    83         }
       
    84         else if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled) {
       
    85             operationCancelled();
       
    86         }
       
    87     }
       
    88 }