|
1 /* |
|
2 * Copyright (c) 2002 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: E-mail attachment remove operation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <miutset.h> // KUidMsgTypeIMAP4 |
|
21 #include <cacheman.h> // CImPruneMessage |
|
22 #include <eikenv.h> // CEikonEnv |
|
23 #include <mmsvattachmentmanager.h> |
|
24 |
|
25 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
26 #include <cimprunemessage.h> |
|
27 #endif |
|
28 |
|
29 |
|
30 |
|
31 #include "MailLog.h" |
|
32 #include "MsgMailViewerRemoveAttachment.h" |
|
33 #include "CMailMessage.h" |
|
34 |
|
35 enum TLoadState |
|
36 { |
|
37 EChangeStatus = 1, |
|
38 EDeleteAttachment, |
|
39 EChangeAttachmentEntryStatus, |
|
40 EAllDone |
|
41 }; |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 |
|
44 // Constructor |
|
45 CMsgMailViewerRemoveAttachmentOp::CMsgMailViewerRemoveAttachmentOp( |
|
46 CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus, |
|
47 TMsvId aMsgID) |
|
48 : CMsvOperation(aMsvSession, EPriorityStandard, aObserverRequestStatus) |
|
49 { |
|
50 CActiveScheduler::Add(this); |
|
51 iMtm = KUidMsgTypeIMAP4; // operation possible only for IMAP messages |
|
52 iMsgID = aMsgID; |
|
53 iState = EDeleteAttachment; |
|
54 } |
|
55 |
|
56 |
|
57 // 2nd phase constructor |
|
58 inline void CMsgMailViewerRemoveAttachmentOp::ConstructL( |
|
59 const TMsvId aAttachmentId) |
|
60 { |
|
61 LOG("CMsgMailViewerRemoveAttachmentOp::ConstructL"); |
|
62 iCentry = iMsvSession.GetEntryL(iMsgID); |
|
63 |
|
64 iMsgEntry = iMsvSession.GetEntryL(aAttachmentId); |
|
65 |
|
66 iPruneMsg = CImPruneMessage::NewL(*iMsgEntry, |
|
67 iMsvSession.FileSession()); |
|
68 |
|
69 iPruneMsg->StartL(aAttachmentId, iStatus); |
|
70 iObserverRequestStatus = KRequestPending; |
|
71 |
|
72 SetActive(); |
|
73 } |
|
74 |
|
75 inline void CMsgMailViewerRemoveAttachmentOp::ConstructL( |
|
76 CMailMessage& aMailMessage, TMsvAttachmentId aAttachmentId ) |
|
77 { |
|
78 LOG("CMsgMailViewerRemoveAttachmentOp::ConstructL 2"); |
|
79 aMailMessage.AttachmentManager().RemoveAttachmentL( |
|
80 aAttachmentId, iStatus ); |
|
81 iState = EAllDone; |
|
82 iObserverRequestStatus = KRequestPending; |
|
83 |
|
84 SetActive(); |
|
85 } |
|
86 |
|
87 |
|
88 // Symbian OS constructor |
|
89 CMsgMailViewerRemoveAttachmentOp* |
|
90 CMsgMailViewerRemoveAttachmentOp::NewLC(CMsvSession& aMsvSession, |
|
91 TRequestStatus& aObserverRequestStatus, const TMsvId aAttachmentId, |
|
92 TMsvId aMsgID) |
|
93 { |
|
94 CMsgMailViewerRemoveAttachmentOp *op = new(ELeave) |
|
95 CMsgMailViewerRemoveAttachmentOp( |
|
96 aMsvSession, aObserverRequestStatus, aMsgID); |
|
97 CleanupStack::PushL(op); |
|
98 |
|
99 op->ConstructL(aAttachmentId); |
|
100 return op; |
|
101 } |
|
102 |
|
103 |
|
104 CMsgMailViewerRemoveAttachmentOp* CMsgMailViewerRemoveAttachmentOp::NewL( |
|
105 CMailMessage& aMailMessage, |
|
106 TRequestStatus& aObserverRequestStatus, |
|
107 TMsvAttachmentId aAttachmentId ) |
|
108 { |
|
109 CMsgMailViewerRemoveAttachmentOp *op = |
|
110 new( ELeave ) CMsgMailViewerRemoveAttachmentOp( |
|
111 *aMailMessage.Session(), aObserverRequestStatus, 0 ); |
|
112 CleanupStack::PushL(op); |
|
113 |
|
114 op->ConstructL( aMailMessage, aAttachmentId ); |
|
115 CleanupStack::Pop( op ); |
|
116 |
|
117 return op; |
|
118 } |
|
119 |
|
120 |
|
121 // Destructor |
|
122 CMsgMailViewerRemoveAttachmentOp::~CMsgMailViewerRemoveAttachmentOp() |
|
123 { |
|
124 LOG("CMsgMailViewerRemoveAttachmentOp destructor"); |
|
125 |
|
126 Cancel(); |
|
127 delete iMsvOp; |
|
128 delete iMsgEntry; |
|
129 delete iPruneMsg; |
|
130 delete iCentry; |
|
131 } |
|
132 |
|
133 // Returns progress of the operation using TMsvLocalOperationProgress |
|
134 const TDesC8& CMsgMailViewerRemoveAttachmentOp::ProgressL() |
|
135 { |
|
136 return iProgress; |
|
137 } |
|
138 |
|
139 // Cancels outstanding operation |
|
140 void CMsgMailViewerRemoveAttachmentOp::DoCancel() |
|
141 { |
|
142 LOG("CMsgMailViewerRemoveAttachmentOp::DoCancel"); |
|
143 if(iPruneMsg) |
|
144 { |
|
145 iPruneMsg->Cancel(); |
|
146 iProgress().iError = KErrCancel; |
|
147 } |
|
148 |
|
149 if(iMsvOp) |
|
150 { |
|
151 iMsvOp->Cancel(); |
|
152 iProgress().iError = KErrCancel; |
|
153 } |
|
154 |
|
155 } |
|
156 |
|
157 // Handles an active object’s request completion event |
|
158 void CMsgMailViewerRemoveAttachmentOp::RunL() |
|
159 { |
|
160 LOG("CMsgMailViewerRemoveAttachmentOp::RunL"); |
|
161 delete iMsvOp; |
|
162 iMsvOp = NULL; |
|
163 |
|
164 switch(iState) |
|
165 { |
|
166 case EDeleteAttachment: |
|
167 LOG("RunL: EDeleteAttachment"); |
|
168 iState = EChangeStatus; |
|
169 break; |
|
170 |
|
171 case EChangeStatus: |
|
172 LOG("RunL: EChangeStatus"); |
|
173 iState = EChangeAttachmentEntryStatus; |
|
174 break; |
|
175 |
|
176 case EChangeAttachmentEntryStatus: |
|
177 LOG("RunL: EChangeAttachmentEntryStatus"); |
|
178 iState = EAllDone; |
|
179 break; |
|
180 |
|
181 default: |
|
182 LOG("RunL: default"); |
|
183 break; |
|
184 } |
|
185 |
|
186 DoNextStateL(); |
|
187 } |
|
188 |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // CMsgMailViewerRemoveAttachmentOp::DoNextStateL() |
|
192 // ---------------------------------------------------------------------------- |
|
193 // |
|
194 void CMsgMailViewerRemoveAttachmentOp::DoNextStateL() |
|
195 { |
|
196 LOG("CMsgMailViewerRemoveAttachmentOp::DoNextState"); |
|
197 TRequestStatus* status; |
|
198 |
|
199 switch(iState) |
|
200 { |
|
201 case EChangeStatus: |
|
202 LOG("EChangeStatus"); |
|
203 UpdateStatusL(); |
|
204 SetActive(); |
|
205 break; |
|
206 case EChangeAttachmentEntryStatus: |
|
207 LOG("EChangeAttachmentEntryStatus"); |
|
208 UpdateAttachmentStatusL(); |
|
209 SetActive(); |
|
210 break; |
|
211 case EAllDone: |
|
212 LOG("EAllDone"); |
|
213 iProgress().iError = iStatus.Int(); |
|
214 status = &iObserverRequestStatus; |
|
215 User::RequestComplete(status, KErrNone); |
|
216 break; |
|
217 default: |
|
218 LOG1("CMsgMailViewerRemoveAttachmentOp::DoNextState:False State%d", |
|
219 iState); |
|
220 break; |
|
221 |
|
222 } |
|
223 |
|
224 } |
|
225 // ---------------------------------------------------------------------------- |
|
226 // CMsgMailViewerRemoveAttachmentOp::UpdateAttachmentStatusL() |
|
227 // ---------------------------------------------------------------------------- |
|
228 // |
|
229 void CMsgMailViewerRemoveAttachmentOp::UpdateAttachmentStatusL() |
|
230 { |
|
231 TMsvEntry attachment = iMsgEntry->Entry(); |
|
232 |
|
233 //Set attachment entry as not comleted |
|
234 attachment.SetComplete( EFalse ); |
|
235 |
|
236 ASSERT( iMsvOp == NULL ); |
|
237 iMsvOp = iMsgEntry->ChangeL(attachment, iStatus); |
|
238 } |
|
239 |
|
240 |
|
241 // ---------------------------------------------------------------------------- |
|
242 // CMsgMailViewerRemoveAttachmentOp::UpdateStatusL() |
|
243 // ---------------------------------------------------------------------------- |
|
244 // |
|
245 void CMsgMailViewerRemoveAttachmentOp::UpdateStatusL() |
|
246 { |
|
247 TMsvEntry tentry = iCentry->Entry(); |
|
248 ASSERT( tentry.iType == KUidMsvMessageEntry ); |
|
249 //Set entry as not comleted |
|
250 tentry.SetComplete(EFalse); |
|
251 ASSERT( iMsvOp == NULL ); |
|
252 iMsvOp = iCentry->ChangeL(tentry, iStatus); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CMsgMailViewerRemoveAttachmentOp::RunError |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 TInt CMsgMailViewerRemoveAttachmentOp::RunError(TInt aError) |
|
260 { |
|
261 Cancel(); |
|
262 |
|
263 iProgress().iError = aError; |
|
264 |
|
265 // ActiveSheduler Panics if this returns != KErrNone |
|
266 return KErrNone; |
|
267 } |
|
268 |
|
269 // End of File |