|
1 /* |
|
2 * Copyright (c) 2006-2008 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: This file implements class CCIpsPlgRemoveChildPartOperation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // <qmail> |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "emailtrace.h" |
|
22 #include "ipsplgheaders.h" |
|
23 |
|
24 // LOCAL CONSTANTS AND MACROS |
|
25 |
|
26 // ================= MEMBER FUNCTIONS ======================= |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // CIpsPlgRemoveChildPartOperation::CIpsPlgRemoveChildPartOperation |
|
30 // ---------------------------------------------------------------------------- |
|
31 // |
|
32 CIpsPlgRemoveChildPartOperation::CIpsPlgRemoveChildPartOperation( |
|
33 CMsvSession& aMsvSession, |
|
34 TRequestStatus& aObserverRequestStatus, |
|
35 const TFSMailMsgId& aMessageId, |
|
36 const TFSMailMsgId& aPartId, |
|
37 MFSMailRequestObserver& aOperationObserver, |
|
38 const TInt aRequestId) |
|
39 : |
|
40 CIpsPlgBaseOperation( |
|
41 aMsvSession, |
|
42 aObserverRequestStatus, |
|
43 aRequestId, |
|
44 TFSMailMsgId()), |
|
45 iMessageId(aMessageId), |
|
46 iPartId(aPartId), |
|
47 iOperationObserver(aOperationObserver) |
|
48 { |
|
49 FUNC_LOG; |
|
50 CActiveScheduler::Add( this ); |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // CIpsPlgRemoveChildPartOperation::NewL |
|
55 // ---------------------------------------------------------------------------- |
|
56 // |
|
57 CIpsPlgRemoveChildPartOperation* CIpsPlgRemoveChildPartOperation::NewL( |
|
58 CMsvSession& aMsvSession, |
|
59 TRequestStatus& aObserverRequestStatus, |
|
60 const TFSMailMsgId& aMessageId, |
|
61 const TFSMailMsgId& aPartId, |
|
62 MFSMailRequestObserver& aOperationObserver, |
|
63 const TInt aRequestId) |
|
64 { |
|
65 FUNC_LOG; |
|
66 CIpsPlgRemoveChildPartOperation* self = |
|
67 new (ELeave) CIpsPlgRemoveChildPartOperation( |
|
68 aMsvSession, |
|
69 aObserverRequestStatus, |
|
70 aMessageId, |
|
71 aPartId, |
|
72 aOperationObserver, |
|
73 aRequestId ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop( self ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CIpsPlgRemoveChildPartOperation::ConstructL |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 void CIpsPlgRemoveChildPartOperation::ConstructL() |
|
85 { |
|
86 FUNC_LOG; |
|
87 StartOperationL(); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // CIpsPlgRemoveChildPartOperation::~CIpsPlgRemoveChildPartOperation |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 CIpsPlgRemoveChildPartOperation::~CIpsPlgRemoveChildPartOperation() |
|
95 { |
|
96 FUNC_LOG; |
|
97 Cancel(); // Cancel any request, if outstanding |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // CIpsPlgRemoveChildPartOperation::DoCancel |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void CIpsPlgRemoveChildPartOperation::DoCancel() |
|
105 { |
|
106 FUNC_LOG; |
|
107 |
|
108 if (iMessage) |
|
109 { |
|
110 iMessage->AttachmentManager().CancelRequest(); |
|
111 iMessage->Cancel(); |
|
112 } |
|
113 |
|
114 TRequestStatus* status = &iObserverRequestStatus; |
|
115 if ( status && status->Int() == KRequestPending ) |
|
116 { |
|
117 SignalFSObserver(iStatus.Int(),NULL); |
|
118 User::RequestComplete( status, iStatus.Int() ); |
|
119 } |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CIpsPlgRemoveChildPartOperation::StartOperation |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 void CIpsPlgRemoveChildPartOperation::StartOperationL() |
|
127 { |
|
128 TInt status( KErrNone ); |
|
129 CMsvEntry* cEntry( NULL ); |
|
130 TMsvEntry tEntry; |
|
131 TMsvId serviceId; |
|
132 status = iMsvSession.GetEntry( iPartId.Id(), serviceId, tEntry ); |
|
133 |
|
134 if ( ( status == KErrNone ) && |
|
135 ( tEntry.iType == KUidMsvAttachmentEntry ) ) |
|
136 { |
|
137 iMessage = NULL; |
|
138 // We trust that the message ID really refers to a message |
|
139 GetMessageEntryL( iMessageId.Id(), cEntry, iMessage ); |
|
140 |
|
141 MMsvAttachmentManager& attachmentMgr( iMessage->AttachmentManager() ); |
|
142 |
|
143 // Start async request |
|
144 attachmentMgr.RemoveAttachmentL( |
|
145 (TMsvAttachmentId) iPartId.Id(), iStatus ); |
|
146 SetActive(); |
|
147 } |
|
148 else if ( ( status == KErrNone ) && |
|
149 ( tEntry.iType == KUidMsvFolderEntry ) ) |
|
150 { |
|
151 cEntry = iMsvSession.GetEntryL( tEntry.Parent() ); |
|
152 CleanupStack::PushL( cEntry ); |
|
153 cEntry->DeleteL( tEntry.Id() ); |
|
154 CleanupStack::PopAndDestroy( cEntry ); |
|
155 } |
|
156 } |
|
157 // ---------------------------------------------------------------------------- |
|
158 // CIpsPlgRemoveChildPartOperation::RunL |
|
159 // ---------------------------------------------------------------------------- |
|
160 // |
|
161 void CIpsPlgRemoveChildPartOperation::RunL() |
|
162 { |
|
163 if (iStatus.Int() == KErrNone) |
|
164 { |
|
165 // Inform observer |
|
166 SignalFSObserver(iStatus.Int(),NULL); |
|
167 // Complete observer |
|
168 TRequestStatus* observerStatus = &iObserverRequestStatus; |
|
169 User::RequestComplete( observerStatus, iStatus.Int() ); |
|
170 } |
|
171 else if (iStatus.Int() == KErrCancel) |
|
172 { |
|
173 // Do Nothing |
|
174 } |
|
175 else |
|
176 { |
|
177 User::Leave(iStatus.Int()); |
|
178 } |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // CIpsPlgRemoveChildPartOperation::GetMessageEntryL( ) |
|
183 // Checks whether the requested message is already cached. If not, the cached |
|
184 // objects are deleted and new objects are created. |
|
185 // ---------------------------------------------------------------------------- |
|
186 void CIpsPlgRemoveChildPartOperation::GetMessageEntryL( |
|
187 TMsvId aId, |
|
188 CMsvEntry*& aMessageEntry, |
|
189 CImEmailMessage*& aImEmailMessage ) |
|
190 { |
|
191 FUNC_LOG; |
|
192 if ( !iCachedEntry || ( aId != iCachedEntry->Entry().Id() ) || |
|
193 iCachedEmailMessage->IsActive() ) |
|
194 { |
|
195 CleanCachedMessageEntries(); |
|
196 |
|
197 iCachedEntry = iMsvSession.GetEntryL( aId ); |
|
198 if ( iCachedEntry->Entry().iType == KUidMsvMessageEntry ) |
|
199 { |
|
200 iCachedEmailMessage = CImEmailMessage::NewL( *iCachedEntry ); |
|
201 } |
|
202 } |
|
203 aMessageEntry = iCachedEntry; |
|
204 aImEmailMessage = iCachedEmailMessage; |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------------------------------- |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 void CIpsPlgRemoveChildPartOperation::CleanCachedMessageEntries() |
|
211 { |
|
212 FUNC_LOG; |
|
213 delete iCachedEmailMessage; |
|
214 iCachedEmailMessage = NULL; |
|
215 delete iCachedEntry; |
|
216 iCachedEntry = NULL; |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------------------------------- |
|
220 // CIpsPlgRemoveChildPartOperation::RunError |
|
221 // ---------------------------------------------------------------------------- |
|
222 // |
|
223 TInt CIpsPlgRemoveChildPartOperation::RunError(TInt aError) |
|
224 { |
|
225 FUNC_LOG; |
|
226 SignalFSObserver( aError, NULL ); |
|
227 |
|
228 TRequestStatus* status = &iObserverRequestStatus; |
|
229 User::RequestComplete( status, aError ); |
|
230 return KErrNone; // RunError must return KErrNone to active sheduler. |
|
231 } |
|
232 |
|
233 // ---------------------------------------------------------------------------- |
|
234 // CIpsPlgRemoveChildPartOperation::SignalFSObserver |
|
235 // ---------------------------------------------------------------------------- |
|
236 // |
|
237 void CIpsPlgRemoveChildPartOperation::SignalFSObserver( |
|
238 TInt aStatus, CFSMailMessagePart* /*aMessagePart*/ ) |
|
239 { |
|
240 FUNC_LOG; |
|
241 if ( aStatus == KErrCancel ) |
|
242 { |
|
243 iFSProgress.iProgressStatus = TFSProgress::EFSStatus_RequestCancelled; |
|
244 iFSProgress.iError = KErrCancel; |
|
245 iFSProgress.iParam = NULL; |
|
246 } |
|
247 else |
|
248 { |
|
249 iFSProgress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete; |
|
250 iFSProgress.iError = aStatus; |
|
251 iFSProgress.iParam = NULL; |
|
252 } |
|
253 |
|
254 TRAP_IGNORE( iOperationObserver.RequestResponseL( iFSProgress, iFSRequestId ) ); |
|
255 } |
|
256 |
|
257 // ---------------------------------------------------------------------------- |
|
258 // CIpsPlgRemoveChildPartOperation::ProgressL |
|
259 // ---------------------------------------------------------------------------- |
|
260 // |
|
261 const TDesC8& CIpsPlgRemoveChildPartOperation::ProgressL() |
|
262 { |
|
263 FUNC_LOG; |
|
264 return KNullDesC8; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // CIpsPlgNewChildPartFromFileOperation::GetErrorProgressL |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 const TDesC8& CIpsPlgRemoveChildPartOperation::GetErrorProgressL( TInt /*aError*/ ) |
|
272 { |
|
273 FUNC_LOG; |
|
274 return KNullDesC8; // error progress info not supported |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // CIpsPlgNewChildPartFromFileOperation::GetFSProgressL |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 TFSProgress CIpsPlgRemoveChildPartOperation::GetFSProgressL() const |
|
282 { |
|
283 FUNC_LOG; |
|
284 return iFSProgress; |
|
285 } |
|
286 |
|
287 // ---------------------------------------------------------------------------- |
|
288 // CIpsPlgNewChildPartFromFileOperation::IpsOpType |
|
289 // ---------------------------------------------------------------------------- |
|
290 TIpsOpType CIpsPlgRemoveChildPartOperation::IpsOpType() const |
|
291 { |
|
292 FUNC_LOG; |
|
293 return EIpsOpTypeNewChildPartFromFile; |
|
294 } |
|
295 |
|
296 // End of File |
|
297 |
|
298 // </qmail> |