emailuis/nmframeworkadapter/src/nmfwaaddattachmentsoperation.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     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 /*!
       
    20     \class NmFwaAddAttachmentsOperation
       
    21     
       
    22     \brief NmFwaAddAttachmentsOperation is an async operation which adds new
       
    23            attachments into the message.
       
    24            
       
    25     NmFwaAddAttachmentsOperation is an async operation which adds new attachments into the message.
       
    26     \sa NmOperation
       
    27  */
       
    28 
       
    29 /*!
       
    30     Constructor
       
    31     
       
    32     \param message Message where new attachment to be attached.
       
    33     \param fileList File name list of the attached files
       
    34     \param mailClient Reference to mail client object.
       
    35  */
       
    36 NmFwaAddAttachmentsOperation::NmFwaAddAttachmentsOperation(
       
    37     const NmMessage &message,
       
    38     const QList<QString> &fileList,
       
    39     CFSMailClient &mailClient) :
       
    40         mMailClient(mailClient)
       
    41 {
       
    42     NM_FUNCTION;
       
    43     
       
    44     // Take own copy of the file list.
       
    45     mFileList.clear();
       
    46     for (int i=0; i<fileList.count(); ++i) {
       
    47         mFileList.append(fileList.at(i));
       
    48     }
       
    49     mFSMessage = CFSMailMessage::NewL(message);
       
    50     mRequestId = NmNotFoundError;
       
    51 }
       
    52 
       
    53 /*!
       
    54     Destructor
       
    55  */
       
    56 NmFwaAddAttachmentsOperation::~NmFwaAddAttachmentsOperation()
       
    57 {
       
    58     NM_FUNCTION;
       
    59     
       
    60     // Cancel all running operations.
       
    61     doCancelOperation();
       
    62     mFileList.clear(); 
       
    63     delete mFSMessage;
       
    64 }
       
    65 
       
    66 /*!
       
    67     Called after base object construction, runs the
       
    68     async operation.
       
    69     
       
    70     \sa NmOperation
       
    71  */
       
    72 void NmFwaAddAttachmentsOperation::doRunAsyncOperation()
       
    73 {
       
    74     NM_FUNCTION;
       
    75     
       
    76     TRAPD(err, doRunAsyncOperationL());
       
    77     // Trap harness catches an error.
       
    78     if (err != KErrNone) {
       
    79         // File not found, inform UI.
       
    80         if (err == KErrNotFound) {
       
    81             completeOperationPart(mFileList.takeFirst(),
       
    82                                   NULL,
       
    83                                   NmNotFoundError);
       
    84             // Let's continue, if files still left.
       
    85             if (mFileList.count() > 0) {
       
    86                 doRunAsyncOperation();
       
    87             }
       
    88             else {
       
    89                 // We do not want to report whole operation error,
       
    90                 // when the last file is, or files, are missing.
       
    91                 completeOperation(NmNoError);
       
    92             }
       
    93         }
       
    94         else {
       
    95             // Complete operation part, because of unknown error.
       
    96             // File list is never empty in this situation.
       
    97             completeOperationPart(mFileList.takeFirst(),
       
    98                                   NULL,
       
    99                                   NmGeneralError);
       
   100             // Complete whole operation, because of unknown error.
       
   101             mFileList.clear();
       
   102             mRequestId = NmNotFoundError ;
       
   103             completeOperation(NmGeneralError);
       
   104         }
       
   105     }
       
   106 }
       
   107 
       
   108 /*!
       
   109     Leaving version of doRunAsyncOperationL
       
   110  */
       
   111 void NmFwaAddAttachmentsOperation::doRunAsyncOperationL()
       
   112 {
       
   113     NM_FUNCTION;
       
   114     
       
   115     if (mFileList.count() > 0) {
       
   116         // Add new attachment from first file in the list.
       
   117         HBufC *fileName = NmConverter::qstringToHBufCLC(mFileList.first());
       
   118         mRequestId = mFSMessage->AddNewAttachmentL(*fileName, *this);
       
   119         CleanupStack::PopAndDestroy(fileName);   
       
   120     } else {
       
   121         completeOperation(NmNoError);
       
   122     }
       
   123         
       
   124 }
       
   125 
       
   126 /*!
       
   127     Asynchronous request response message.
       
   128     
       
   129     \param aEvent Plugin event description.
       
   130     \param aRequestId Request id of asyncronous operation.
       
   131  */
       
   132 void NmFwaAddAttachmentsOperation::RequestResponseL(TFSProgress aEvent,
       
   133                                                     TInt aRequestId)
       
   134 {
       
   135     NM_FUNCTION;
       
   136     
       
   137     int err = NmNoError;
       
   138 
       
   139     // Request id should always be valid. If not,
       
   140     // then report general error and complete operation.
       
   141     if (aRequestId == mRequestId) {
       
   142 
       
   143         // Request completed so request id used.
       
   144         mRequestId = KErrNotFound;
       
   145        
       
   146         // If request completed we can process the results.
       
   147         //   Otherwise, we report about cancellation or general error
       
   148         // and stop the operation.
       
   149         if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete) {
       
   150             
       
   151             // Request completed. Let's check the result. If no error
       
   152             // and parameter not NULL, report UI about a file added.
       
   153             //   Else complete operation part with general error,
       
   154             // but continue if a file or files still left in the list.
       
   155             if (aEvent.iError == KErrNone && aEvent.iParam) {
       
   156                 
       
   157                 // Cast the parameter to FS message part object, since
       
   158                 // it can't be anything else.
       
   159                 CFSMailMessagePart *fsMessagePart =
       
   160                     static_cast<CFSMailMessagePart *>(aEvent.iParam);
       
   161 
       
   162                 completeOperationPart(
       
   163                     mFileList.takeFirst(),
       
   164                     fsMessagePart->GetPartId().GetNmId(),
       
   165                     NmNoError);
       
   166                     
       
   167                 delete fsMessagePart;
       
   168                 fsMessagePart = NULL;
       
   169             }
       
   170             else {
       
   171                 completeOperationPart(mFileList.takeFirst(),
       
   172                                       NULL,
       
   173                                       NmGeneralError);
       
   174             }
       
   175         }
       
   176         else {
       
   177             completeOperationPart(mFileList.takeFirst(),
       
   178                                   NULL,
       
   179                                   NmGeneralError);
       
   180             mFileList.clear();
       
   181             err = NmGeneralError;
       
   182         }
       
   183     } // if (aRequestId == mRequestId) 
       
   184     else {
       
   185         // Just to be sure.
       
   186         if (mFileList.count() > 0) {
       
   187             completeOperationPart(mFileList.takeFirst(),
       
   188                                   NULL,
       
   189                                   NmGeneralError);   
       
   190         }
       
   191         mFileList.clear();
       
   192         err = NmGeneralError;
       
   193     }
       
   194     
       
   195     // Complete operation if there are no files left.
       
   196     // Otherwise, continue with next file.
       
   197     if (!mFileList.count()) {
       
   198         completeOperation(err);
       
   199     } else {
       
   200         doRunAsyncOperation();
       
   201     }
       
   202 }
       
   203 
       
   204 /*!
       
   205  * Complete the operation
       
   206  */
       
   207 void NmFwaAddAttachmentsOperation::doCompleteOperation()
       
   208 {
       
   209     NM_FUNCTION;
       
   210     
       
   211     mRequestId = NmNotFoundError;
       
   212 }
       
   213 
       
   214 /*!
       
   215     Cancels the async operation. \sa NmOperation
       
   216  */
       
   217 void NmFwaAddAttachmentsOperation::doCancelOperation()
       
   218 {
       
   219     NM_FUNCTION;
       
   220     
       
   221     if (mRequestId >= 0) {
       
   222         TRAP_IGNORE(mMailClient.CancelL(mRequestId));
       
   223         mRequestId = NmNotFoundError;
       
   224     }
       
   225 }