emailuis/nmframeworkadapter/src/nmfwamessagecreationoperation.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 #include "nmframeworkadapterheaders.h"
       
    18 
       
    19 #include "nmfwamessagecreationoperation.h"
       
    20 
       
    21 /*!
       
    22     \class NmFwaMessageCreationOperation
       
    23     
       
    24     \brief NmFwaMessageCreationOperation is an async operation which creates a new message.
       
    25     
       
    26     NmFwaMessageCreationOperation is an async operation which creates a new message.
       
    27     \sa NmOperation
       
    28  */
       
    29 
       
    30 /*!
       
    31     Constructor
       
    32     
       
    33     \param mailboxId Id of mailbox the message is to be created with.
       
    34     \param mailClient Reference to mail client object.
       
    35  */
       
    36 NmFwaMessageCreationOperation::NmFwaMessageCreationOperation(
       
    37     const NmId &mailboxId,
       
    38     CFSMailClient &mailClient) :
       
    39         mMailboxId(mailboxId),
       
    40         mMessage(NULL),
       
    41         mMailClient(mailClient),
       
    42         mRequestId(NmNotFoundError)
       
    43 {
       
    44 }
       
    45 
       
    46 /*!
       
    47     Destructor
       
    48  */
       
    49 NmFwaMessageCreationOperation::~NmFwaMessageCreationOperation()
       
    50 {
       
    51     doCancelOperation();
       
    52     delete mMessage;
       
    53 }
       
    54 
       
    55 /*!
       
    56     Slot, called after base object construction via timer event, runs the async operation.
       
    57     
       
    58     \sa NmOperation
       
    59  */
       
    60 void NmFwaMessageCreationOperation::runAsyncOperation()
       
    61 {
       
    62     const TFSMailMsgId mailMsgId(mMailboxId.pluginId32(), mMailboxId.id32());
       
    63 
       
    64     CFSMailBox *mailBox = NULL;
       
    65     TRAP_IGNORE(mailBox = mMailClient.GetMailBoxByUidL(mailMsgId));
       
    66 
       
    67     // Call the asynchronous version first. If it returns KErrNotSupported
       
    68 	// then use the synchronous version. Thus a protocol plugin does not need
       
    69 	// implement the asynchronous version if there is no hit to UI performance
       
    70 	// or overall robustness when using the synchronous version.
       
    71 	if (mailBox) {
       
    72         TRAPD(err, mRequestId = mailBox->CreateMessageToSendL(*this));
       
    73 
       
    74         if (err == KErrFSMailPluginNotSupported) {
       
    75             CFSMailMessage *fsMessage = mailBox->CreateMessageToSend();
       
    76 
       
    77             if (fsMessage)
       
    78                 {
       
    79                 mMessage = fsMessage->GetNmMessage();
       
    80 
       
    81                 delete fsMessage;
       
    82                 fsMessage = NULL;
       
    83                 completeOperation(NmNoError);
       
    84                 }
       
    85             else
       
    86                 {
       
    87                 completeOperation(NmNotFoundError);
       
    88                 }
       
    89             }
       
    90         else if (err != KErrNone)
       
    91             {
       
    92             completeOperation(NmGeneralError);
       
    93         }
       
    94         
       
    95         delete mailBox;
       
    96         mailBox = NULL;
       
    97     }
       
    98     else {
       
    99         completeOperation(NmNotFoundError);
       
   100     }
       
   101 }
       
   102 
       
   103 /*!
       
   104  * Complete the operation
       
   105  */
       
   106 void NmFwaMessageCreationOperation::doCompleteOperation()
       
   107 {
       
   108     mRequestId = NmNotFoundError;
       
   109 }
       
   110 
       
   111 /*!
       
   112     Cancels the async operation. \sa NmOperation
       
   113  */
       
   114 void NmFwaMessageCreationOperation::doCancelOperation()
       
   115 {
       
   116     if (mRequestId >= 0) {
       
   117         TRAP_IGNORE(mMailClient.CancelL(mRequestId));
       
   118         mRequestId = NmNotFoundError;
       
   119     }
       
   120 }
       
   121 
       
   122 /*!
       
   123     Returns the message created by the operation, or null if the operation has not
       
   124     completed, ownership is transferred to caller and following calls will return null.
       
   125     
       
   126     \return NmMessage* The new message.
       
   127  */
       
   128 NmMessage *NmFwaMessageCreationOperation::getMessage()
       
   129 {
       
   130     // Ownership changes
       
   131     NmMessage *ret = mMessage;
       
   132     mMessage = NULL;
       
   133     return ret;
       
   134 }
       
   135 
       
   136 /*!
       
   137     Returns the id of the message created by the operation, or NmId() if operation has not
       
   138 	completed or ownership has already been transferred through getMessage().
       
   139     
       
   140     \return NmId Id of the new message.
       
   141  */
       
   142 NmId NmFwaMessageCreationOperation::getMessageId()
       
   143 {
       
   144     NmId messageId;
       
   145     
       
   146     if (mMessage) {
       
   147         messageId = mMessage->envelope().id();
       
   148     }
       
   149     
       
   150     return messageId;
       
   151 }
       
   152 
       
   153 /*!
       
   154     Asynchronous request response message.
       
   155     
       
   156     \param aEvent Plugin event description.
       
   157     \param aRequestId Request id of asyncronous operation.
       
   158  */
       
   159 void NmFwaMessageCreationOperation::RequestResponseL(TFSProgress aEvent,
       
   160                                                      TInt aRequestId)
       
   161 {
       
   162     TFSProgress::TFSProgressStatus status = aEvent.iProgressStatus;
       
   163 
       
   164     if (aRequestId == mRequestId) {
       
   165         if (status == TFSProgress::EFSStatus_RequestComplete
       
   166             && aEvent.iParam) {
       
   167 
       
   168             CFSMailMessage *fsMessage =
       
   169                 static_cast<CFSMailMessage *>(aEvent.iParam);
       
   170 
       
   171             mMessage = fsMessage->GetNmMessage();
       
   172             
       
   173             delete fsMessage;
       
   174             fsMessage = NULL;
       
   175             
       
   176             completeOperation(NmNoError);
       
   177         }
       
   178         else if (status == TFSProgress::EFSStatus_RequestCancelled) {
       
   179             operationCancelled();
       
   180         }
       
   181         else {
       
   182             completeOperation(NmGeneralError);
       
   183         }
       
   184     }
       
   185 }