emailuis/nmframeworkadapter/src/nmfwaaddattachmentsoperation.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 23 2dc6caa42ec3
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    50 /*!
    50 /*!
    51     Destructor
    51     Destructor
    52  */
    52  */
    53 NmFwaAddAttachmentsOperation::~NmFwaAddAttachmentsOperation()
    53 NmFwaAddAttachmentsOperation::~NmFwaAddAttachmentsOperation()
    54 {
    54 {
       
    55     doCancelOperation();
    55     mFileList.clear();
    56     mFileList.clear();
    56     mRequestIds.clear();
    57     mRequestIds.clear();
    57     doCancelOperation();
       
    58 }
    58 }
    59 
    59 
    60 /*!
    60 /*!
    61     Slot, called after base object construction via timer event, runs the
    61     Called after base object construction via timer event, runs the
    62     async operation.
    62     async operation.
    63     
    63     
    64     \sa NmOperation
    64     \sa NmOperation
    65  */
    65  */
    66 void NmFwaAddAttachmentsOperation::runAsyncOperation()
    66 void NmFwaAddAttachmentsOperation::doRunAsyncOperation()
       
    67 {
       
    68     TRAPD(err, doRunAsyncOperationL());
       
    69     if (err != KErrNone) {
       
    70         completeOperation(NmGeneralError);
       
    71     }
       
    72 }
       
    73 
       
    74 /*!
       
    75     Leaving version of doRunAsyncOperationL
       
    76  */
       
    77 void NmFwaAddAttachmentsOperation::doRunAsyncOperationL()
    67 {
    78 {
    68     CFSMailMessage *msg = NULL;
    79     CFSMailMessage *msg = NULL;
       
    80     msg = CFSMailMessage::NewL(mMessage);
    69 
    81 
    70     TRAPD(err, msg = CFSMailMessage::NewL(mMessage));
    82     // Go through the attachment list and add those into mail message one by one.
    71 
    83     for (int i=0; i<mFileList.count(); ++i) {
    72     if (err == KErrNone) {
    84         HBufC *fileName = NmConverter::qstringToHBufCLC(mFileList.at(i));
    73         // Go through the attachment list and add those into mail message one by one.
    85         mRequestIds.append(msg->AddNewAttachmentL(*fileName, *this));
    74         for (int i=0; i<mFileList.count(); ++i) {
    86         CleanupStack::PopAndDestroy(fileName);
    75             HBufC *fileName = NmConverter::qstringToHBufCLC(mFileList.at(i));
       
    76             TRAP(err, mRequestIds.append(msg->AddNewAttachmentL(*fileName, *this)));
       
    77             CleanupStack::PopAndDestroy(fileName);
       
    78         }
       
    79     }
    87     }
    80     delete msg;
    88     delete msg;
    81     msg = NULL;
    89     msg = NULL;
    82 }
    90 }
    83 
    91 
   127                 // remove request id and file name
   135                 // remove request id and file name
   128                 mRequestIds.removeAt(i);
   136                 mRequestIds.removeAt(i);
   129                 mFileList.removeAt(i);
   137                 mFileList.removeAt(i);
   130             }
   138             }
   131             else if (status == TFSProgress::EFSStatus_RequestCancelled) {
   139             else if (status == TFSProgress::EFSStatus_RequestCancelled) {
       
   140                 completeOperationPart(mFileList.at(i),
       
   141                                       NULL,
       
   142                                       NmCancelError);
   132                 mFileList.clear();
   143                 mFileList.clear();
   133                 mRequestIds.clear();
   144                 mRequestIds.clear();
   134                 operationCancelled();
   145                 operationCancelled();
   135                 err = NmCancelError;
   146                 err = NmCancelError;
   136             }
   147             }
   137             else {
   148             else {
       
   149                 completeOperationPart(mFileList.at(i),
       
   150                                       NULL,
       
   151                                       NmGeneralError);
   138                 mFileList.clear();
   152                 mFileList.clear();
   139                 mRequestIds.clear();
   153                 mRequestIds.clear();
   140                 err = NmGeneralError;
   154                 err = NmGeneralError;
   141             }
   155             }
   142         } // end if
   156         } // end if
   145     // complete operation
   159     // complete operation
   146     if (!mRequestIds.count()) {
   160     if (!mRequestIds.count()) {
   147         completeOperation(err);
   161         completeOperation(err);
   148     }
   162     }
   149 }
   163 }
       
   164 
       
   165 /*!
       
   166     Cancels the async operation. \sa NmOperation
       
   167  */
       
   168 void NmFwaAddAttachmentsOperation::doCancelOperation()
       
   169 {
       
   170     for (int i=0;i<mRequestIds.count();++i) {
       
   171         if (mRequestIds[i] >= 0) {
       
   172             TInt reqId = static_cast<TInt>(mRequestIds[i]);
       
   173             TRAP_IGNORE(mMailClient.CancelL(reqId));
       
   174         }
       
   175     }
       
   176 }