emailuis/nmframeworkadapter/src/nmfwaremoveattachmentoperation.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 /*!
       
    20     \class NmFwaRemoveAttachmentOperation
       
    21     
       
    22     \brief NmFwaRemoveAttachmentOperation is an async operation which removes
       
    23            attachment from the message.
       
    24            
       
    25     NmFwaRemoveAttachmentOperation is an async operation which removes attachment from the message.
       
    26     \sa NmOperation
       
    27  */
       
    28 
       
    29 /*!
       
    30     Constructor
       
    31     
       
    32     \param message Message where attachment to be removed.
       
    33     \param fileName File name of the removed file.
       
    34     \param mailClient Reference to mail client object.
       
    35  */
       
    36 NmFwaRemoveAttachmentOperation::NmFwaRemoveAttachmentOperation(
       
    37     const NmMessage &message,
       
    38     const NmId &attachmentPartId,
       
    39     CFSMailClient &mailClient) :
       
    40         mMessage(message),
       
    41         mMailClient(mailClient)
       
    42 {
       
    43     // Take a copy because original will be deleted during the operation
       
    44     mAttachmentPartId.setId(attachmentPartId.id());
       
    45 }
       
    46 
       
    47 /*!
       
    48     Destructor
       
    49  */
       
    50 NmFwaRemoveAttachmentOperation::~NmFwaRemoveAttachmentOperation()
       
    51 {
       
    52     doCancelOperation();
       
    53 }
       
    54 
       
    55 /*!
       
    56     Slot, called after base object construction via timer event, runs the
       
    57     async operation.
       
    58     
       
    59     \sa NmOperation
       
    60  */
       
    61 void NmFwaRemoveAttachmentOperation::runAsyncOperation()
       
    62 {
       
    63     CFSMailMessage *msg = NULL;
       
    64 
       
    65     TRAPD(err, msg = CFSMailMessage::NewL(mMessage));
       
    66     
       
    67     if (err == KErrNone) {
       
    68     
       
    69         // Get attachment list from the message
       
    70         RPointerArray<CFSMailMessagePart> attachments;
       
    71         attachments.Reset();
       
    72         TRAP(err, msg->AttachmentListL(attachments));
       
    73         
       
    74         if (err == KErrNone) {
       
    75             err = KErrNotFound;
       
    76             
       
    77             // Search through all attachments from message and remove attachment
       
    78             // if message part match.
       
    79             for (int i=0; i<attachments.Count(); ++i) {
       
    80                 if (mAttachmentPartId.id() == attachments[i]->GetPartId().GetNmId().id()) {
       
    81                     TRAP(err, msg->RemoveChildPartL(attachments[i]->GetPartId()));
       
    82                     break;
       
    83                 }
       
    84             }
       
    85         }
       
    86         attachments.ResetAndDestroy();
       
    87     }
       
    88     
       
    89     delete msg;
       
    90     msg = NULL;
       
    91     
       
    92     // Send signal for completion of the operation
       
    93     if (err == KErrNone) {
       
    94         completeOperation(NmNoError);
       
    95     }
       
    96     else if (err == KErrNotFound) {
       
    97         completeOperation(NmNotFoundError);
       
    98     }
       
    99     else {
       
   100         completeOperation(NmGeneralError);
       
   101     }
       
   102 }