emailuis/nmframeworkadapter/src/nmfwaremoveattachmentoperation.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 23 2dc6caa42ec3
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    51 {
    51 {
    52     doCancelOperation();
    52     doCancelOperation();
    53 }
    53 }
    54 
    54 
    55 /*!
    55 /*!
    56     Slot, called after base object construction via timer event, runs the
    56     Called after base object construction via timer event, runs the
    57     async operation.
    57     async operation.
    58     
    58     
    59     \sa NmOperation
    59     \sa NmOperation
    60  */
    60  */
    61 void NmFwaRemoveAttachmentOperation::runAsyncOperation()
    61 void NmFwaRemoveAttachmentOperation::doRunAsyncOperation()
       
    62 {
       
    63     TRAPD(err, doRunAsyncOperationL());
       
    64     if (err != KErrNone) {
       
    65         completeOperation(NmGeneralError);
       
    66     }
       
    67 }
       
    68 
       
    69 /*!
       
    70     Leaving function for async operation
       
    71     \sa NmOperation
       
    72  */
       
    73 void NmFwaRemoveAttachmentOperation::doRunAsyncOperationL()
    62 {
    74 {
    63     CFSMailMessage *msg = NULL;
    75     CFSMailMessage *msg = NULL;
    64 
    76 
    65     TRAPD(err, msg = CFSMailMessage::NewL(mMessage));
    77     msg = CFSMailMessage::NewL(mMessage);
    66     
    78     
    67     if (err == KErrNone) {
    79     // Get attachment list from the message
    68     
    80     RPointerArray<CFSMailMessagePart> attachments;
    69         // Get attachment list from the message
    81     attachments.Reset();
    70         RPointerArray<CFSMailMessagePart> attachments;
    82     msg->AttachmentListL(attachments);
    71         attachments.Reset();
       
    72         TRAP(err, msg->AttachmentListL(attachments));
       
    73         
    83         
    74         if (err == KErrNone) {
    84     // Search through all attachments from message and remove attachment
    75             err = KErrNotFound;
    85     // if message part match.
    76             
    86     for (int i=0; i<attachments.Count(); ++i) {
    77             // Search through all attachments from message and remove attachment
    87         if (mAttachmentPartId.id() == attachments[i]->GetPartId().GetNmId().id()) {
    78             // if message part match.
    88             mRequestId = msg->RemoveChildPartL(attachments[i]->GetPartId(),*this);
    79             for (int i=0; i<attachments.Count(); ++i) {
    89             break;
    80                 if (mAttachmentPartId.id() == attachments[i]->GetPartId().GetNmId().id()) {
       
    81                     TRAP(err, msg->RemoveChildPartL(attachments[i]->GetPartId()));
       
    82                     break;
       
    83                 }
       
    84             }
       
    85         }
    90         }
    86         attachments.ResetAndDestroy();
       
    87     }
    91     }
       
    92     attachments.ResetAndDestroy();
    88     
    93     
    89     delete msg;
    94     delete msg;
    90     msg = NULL;
    95     msg = NULL;
       
    96 }
       
    97 
       
    98 /*!
       
    99     Asynchronous request response message.
    91     
   100     
    92     // Send signal for completion of the operation
   101     \param aEvent Plugin event description.
    93     if (err == KErrNone) {
   102     \param aRequestId Request id of asyncronous operation.
    94         completeOperation(NmNoError);
   103  */
    95     }
   104 void NmFwaRemoveAttachmentOperation::RequestResponseL(TFSProgress aEvent,
    96     else if (err == KErrNotFound) {
   105                                                       TInt aRequestId)
    97         completeOperation(NmNotFoundError);
   106 {
       
   107     if (aRequestId == mRequestId) {
       
   108         TFSProgress::TFSProgressStatus status = aEvent.iProgressStatus;
       
   109         if (status == TFSProgress::EFSStatus_RequestComplete) {
       
   110             // Request completed. Let's check the result
       
   111             switch (aEvent.iError) {
       
   112                 case KErrNone: {
       
   113                     completeOperation(NmNoError);
       
   114                     break;
       
   115                 }
       
   116                 case KErrNotFound:
       
   117                     completeOperation(NmNotFoundError);
       
   118                     break;
       
   119                 default:
       
   120                     completeOperation(NmGeneralError);
       
   121             }
       
   122         }
       
   123         else if (status == TFSProgress::EFSStatus_RequestCancelled) {
       
   124             operationCancelled();
       
   125             completeOperation(NmCancelError);
       
   126         }
       
   127         else {
       
   128             completeOperation(NmGeneralError);
       
   129         }
    98     }
   130     }
    99     else {
   131     else {
   100         completeOperation(NmGeneralError);
   132         completeOperation(NmGeneralError);
   101     }
   133     }
   102 }
   134 }
       
   135 
       
   136 /*!
       
   137     Cancels the async operation. \sa NmOperation
       
   138  */
       
   139 void NmFwaRemoveAttachmentOperation::doCancelOperation()
       
   140 {
       
   141     if (mRequestId >= 0) {
       
   142         TRAP_IGNORE(mMailClient.CancelL(mRequestId));
       
   143         mRequestId = KErrNotFound;
       
   144     }
       
   145 }
       
   146