|
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 NM_FUNCTION; |
|
44 |
|
45 // Take a copy because original will be deleted during the operation |
|
46 mAttachmentPartId.setId(attachmentPartId.id()); |
|
47 } |
|
48 |
|
49 /*! |
|
50 Destructor |
|
51 */ |
|
52 NmFwaRemoveAttachmentOperation::~NmFwaRemoveAttachmentOperation() |
|
53 { |
|
54 NM_FUNCTION; |
|
55 |
|
56 doCancelOperation(); |
|
57 } |
|
58 |
|
59 /*! |
|
60 Called after base object construction, runs the |
|
61 async operation. |
|
62 |
|
63 \sa NmOperation |
|
64 */ |
|
65 void NmFwaRemoveAttachmentOperation::doRunAsyncOperation() |
|
66 { |
|
67 NM_FUNCTION; |
|
68 |
|
69 TRAPD(err, doRunAsyncOperationL()); |
|
70 if (err != KErrNone) { |
|
71 completeOperation(NmGeneralError); |
|
72 } |
|
73 } |
|
74 |
|
75 /*! |
|
76 Leaving function for async operation |
|
77 \sa NmOperation |
|
78 */ |
|
79 void NmFwaRemoveAttachmentOperation::doRunAsyncOperationL() |
|
80 { |
|
81 NM_FUNCTION; |
|
82 |
|
83 CFSMailMessage *msg = NULL; |
|
84 |
|
85 msg = CFSMailMessage::NewL(mMessage); |
|
86 |
|
87 // Get attachment list from the message |
|
88 RPointerArray<CFSMailMessagePart> attachments; |
|
89 attachments.Reset(); |
|
90 msg->AttachmentListL(attachments); |
|
91 |
|
92 // Search through all attachments from message and remove attachment |
|
93 // if message part match. |
|
94 bool found(false); |
|
95 for (int i=0; i<attachments.Count(); ++i) { |
|
96 if (mAttachmentPartId.id() == attachments[i]->GetPartId().GetNmId().id()) { |
|
97 mRequestId = msg->RemoveChildPartL(attachments[i]->GetPartId(),*this); |
|
98 found = true; |
|
99 break; |
|
100 } |
|
101 } |
|
102 attachments.ResetAndDestroy(); |
|
103 delete msg; |
|
104 msg = NULL; |
|
105 // if attachment is not found, request to plugin is not made |
|
106 // and the operation should be completed here |
|
107 if (!found) { |
|
108 completeOperation(NmNotFoundError); |
|
109 } |
|
110 } |
|
111 |
|
112 /*! |
|
113 Asynchronous request response message. |
|
114 |
|
115 \param aEvent Plugin event description. |
|
116 \param aRequestId Request id of asyncronous operation. |
|
117 */ |
|
118 void NmFwaRemoveAttachmentOperation::RequestResponseL(TFSProgress aEvent, |
|
119 TInt aRequestId) |
|
120 { |
|
121 NM_FUNCTION; |
|
122 |
|
123 if (aRequestId == mRequestId) { |
|
124 TFSProgress::TFSProgressStatus status = aEvent.iProgressStatus; |
|
125 if (status == TFSProgress::EFSStatus_RequestComplete) { |
|
126 // Request completed. Let's check the result |
|
127 switch (aEvent.iError) { |
|
128 case KErrNone: { |
|
129 completeOperation(NmNoError); |
|
130 break; |
|
131 } |
|
132 case KErrNotFound: |
|
133 completeOperation(NmNotFoundError); |
|
134 break; |
|
135 default: |
|
136 completeOperation(NmGeneralError); |
|
137 } |
|
138 } |
|
139 else if (status == TFSProgress::EFSStatus_RequestCancelled) { |
|
140 completeOperation(NmCancelError); |
|
141 } |
|
142 else { |
|
143 completeOperation(NmGeneralError); |
|
144 } |
|
145 } |
|
146 else { |
|
147 completeOperation(NmGeneralError); |
|
148 } |
|
149 } |
|
150 |
|
151 /*! |
|
152 Cancels the async operation. \sa NmOperation |
|
153 */ |
|
154 void NmFwaRemoveAttachmentOperation::doCancelOperation() |
|
155 { |
|
156 NM_FUNCTION; |
|
157 |
|
158 if (mRequestId >= 0) { |
|
159 TRAP_IGNORE(mMailClient.CancelL(mRequestId)); |
|
160 mRequestId = KErrNotFound; |
|
161 } |
|
162 } |
|
163 |