|
1 /* |
|
2 * Copyright (c) 2006 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: ImumDeleteMessagesFromServer.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <MTMStore.h> |
|
22 #include <msvstd.hrh> |
|
23 #include <mtmuibas.h> |
|
24 #include <msvuids.h> |
|
25 #include <imum.rsg> |
|
26 #include <coemain.h> |
|
27 #include <StringLoader.h> |
|
28 #include <imapset.h> |
|
29 #include <pop3set.h> |
|
30 #include <miut_err.h> // KErrImapServerBusy |
|
31 #include <eikenv.h> |
|
32 #include <f32file.h> |
|
33 |
|
34 #include "ImumDeleteMessagesFromServer.h" |
|
35 #include "ImumDeleteMessagesLocally.h" |
|
36 #include "EmailUtils.H" |
|
37 #include "ImumMtmLogging.h" |
|
38 |
|
39 |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 const TInt KImumEntriesDoneReplaceIndex = 0; |
|
42 const TInt KImumTotalEntriesReplaceIndex = 1; |
|
43 // minimum disk space needed when deleting messages locally |
|
44 const TInt KImumDiskSpaceForDelete = ( 2*1024 ); |
|
45 const TUid KImumMtmImap4Uid = { 0x1000102A }; |
|
46 const TUid KImumMtmPop3Uid = { 0x10001029 }; |
|
47 _LIT8( KEmptyChar, "" ); |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CImumDeleteMessagesFromServer::CImumDeleteMessagesFromServer() |
|
53 // C++ default constructor can NOT contain any code, that |
|
54 // might leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CImumDeleteMessagesFromServer::CImumDeleteMessagesFromServer( |
|
58 CImumInternalApi& aMailboxApi, |
|
59 TRequestStatus& aObserverRequestStatus ) |
|
60 : |
|
61 CMsvOperation(aMailboxApi.MsvSession(), CActive::EPriorityStandard, aObserverRequestStatus), |
|
62 iMailboxApi( aMailboxApi ), |
|
63 iBlank( KEmptyChar ), |
|
64 iDriveNo( KErrNotFound ) |
|
65 { |
|
66 IMUM_CONTEXT( CImumDeleteMessagesFromServer::CImumDeleteMessagesFromServer, 0, KImumMtmLog ); |
|
67 IMUM_IN(); |
|
68 |
|
69 CActiveScheduler::Add(this); |
|
70 IMUM_OUT(); |
|
71 } |
|
72 |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CImumDeleteMessagesFromServer::ConstructL() |
|
76 // Symbian 2nd phase constructor can leave. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CImumDeleteMessagesFromServer::ConstructL( |
|
80 CMsvEntrySelection& aDeletedEntries ) |
|
81 { |
|
82 IMUM_CONTEXT( CImumDeleteMessagesFromServer::ConstructL, 0, KImumMtmLog ); |
|
83 IMUM_IN(); |
|
84 |
|
85 iEntrySelection = aDeletedEntries.CopyL(); |
|
86 iEntryCount = iEntrySelection->Count(); |
|
87 if ( iEntryCount == 0 ) |
|
88 { |
|
89 User::Leave( KErrNotSupported ); |
|
90 } |
|
91 |
|
92 // Define the environment |
|
93 CEikonEnv* env = CEikonEnv::Static(); |
|
94 |
|
95 // Create the file session and get access to current drive |
|
96 iFileSession = env->FsSession(); |
|
97 iDriveNo = iMsvSession.CurrentDriveL(); |
|
98 |
|
99 // Reserve disk space for deletion |
|
100 User::LeaveIfError( MsvEmailMtmUiUtils::AcquireDiskSpace( |
|
101 iFileSession, iDriveNo, KImumDiskSpaceForDelete ) ); |
|
102 |
|
103 TMsvId serviceId; |
|
104 TMsvEntry entry; |
|
105 User::LeaveIfError( |
|
106 iMsvSession.GetEntry( |
|
107 (*iEntrySelection)[0], serviceId, entry ) ); |
|
108 iEntry = CMsvEntry::NewL( |
|
109 iMsvSession, entry.Parent(), TMsvSelectionOrdering() ); |
|
110 iMtm = iEntry->Entry().iMtm; |
|
111 |
|
112 TInt resourceId = (iEntryCount>1) ? |
|
113 R_IMAP4_PROGRESS_DELETING_MANY : R_IMAP4_PROGRESS_DELETING; |
|
114 |
|
115 iProgressText = StringLoader::LoadL( resourceId, env ); |
|
116 iStatus=KRequestPending; |
|
117 StartNextDeleteLocally(); |
|
118 // StartNextDeleteLocally activates this |
|
119 IMUM_OUT(); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CImumDeleteMessagesFromServer::NewL() |
|
124 // Two-phased constructor. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 CImumDeleteMessagesFromServer* CImumDeleteMessagesFromServer::NewL( |
|
128 CImumInternalApi& aMailboxApi, |
|
129 TRequestStatus& aObserverRequestStatus, |
|
130 CMsvEntrySelection& aDeletedEntries ) |
|
131 { |
|
132 IMUM_STATIC_CONTEXT( CImumDeleteMessagesFromServer::NewL, 0, mtm, KImumMtmLog ); |
|
133 IMUM_IN(); |
|
134 |
|
135 CImumDeleteMessagesFromServer* self=new (ELeave) CImumDeleteMessagesFromServer( |
|
136 aMailboxApi, aObserverRequestStatus ); |
|
137 CleanupStack::PushL(self); |
|
138 self->ConstructL( aDeletedEntries ); |
|
139 CleanupStack::Pop(); // self |
|
140 IMUM_OUT(); |
|
141 return self; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CImumDeleteMessagesFromServer::~CImumDeleteMessagesFromServer() |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 CImumDeleteMessagesFromServer::~CImumDeleteMessagesFromServer() |
|
149 { |
|
150 IMUM_CONTEXT( CImumDeleteMessagesFromServer::~CImumDeleteMessagesFromServer, 0, KImumMtmLog ); |
|
151 IMUM_IN(); |
|
152 |
|
153 Cancel(); |
|
154 |
|
155 // Release the disk space |
|
156 iFileSession.ReleaseReserveAccess( iDriveNo ); |
|
157 |
|
158 delete iOperation; |
|
159 delete iEntry; |
|
160 delete iEntrySelection; |
|
161 delete iProgressText; |
|
162 IMUM_OUT(); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CImumDeleteMessagesFromServer::DoCancel() |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CImumDeleteMessagesFromServer::DoCancel() |
|
170 { |
|
171 IMUM_CONTEXT( CImumDeleteMessagesFromServer::DoCancel, 0, KImumMtmLog ); |
|
172 IMUM_IN(); |
|
173 |
|
174 if (iOperation) |
|
175 { |
|
176 iOperation->Cancel(); |
|
177 } |
|
178 TRequestStatus* status = &iObserverRequestStatus; |
|
179 User::RequestComplete(status, iStatus.Int()); |
|
180 IMUM_OUT(); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CImumDeleteMessagesFromServer::RunL() |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CImumDeleteMessagesFromServer::RunL() |
|
188 { |
|
189 IMUM_CONTEXT( CImumDeleteMessagesFromServer::RunL, 0, KImumMtmLog ); |
|
190 IMUM_IN(); |
|
191 |
|
192 // Make first a check, that nothing has failed |
|
193 if ( iStatus.Int() != KErrNone ) |
|
194 { |
|
195 // something failed, just complete |
|
196 TRequestStatus* status = &iObserverRequestStatus; |
|
197 User::RequestComplete(status, iStatus.Int()); |
|
198 return; |
|
199 } |
|
200 |
|
201 if ( iState == EImumDeletingMessagesStateLocally ) |
|
202 { |
|
203 // local delete completed, start deleting from server |
|
204 StartDeleteFromServer(); |
|
205 } |
|
206 else |
|
207 { |
|
208 // nothing left to process, so complete the observer |
|
209 TRequestStatus* status = &iObserverRequestStatus; |
|
210 User::RequestComplete(status, iStatus.Int()); |
|
211 } |
|
212 IMUM_OUT(); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CImumDeleteMessagesFromServer::ProgressL() |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 const TDesC8& CImumDeleteMessagesFromServer::ProgressL() |
|
220 { |
|
221 IMUM_CONTEXT( CImumDeleteMessagesFromServer::ProgressL, 0, KImumMtmLog ); |
|
222 IMUM_IN(); |
|
223 |
|
224 // Make sure that operation is active |
|
225 if ( IsActive() ) |
|
226 { |
|
227 // Get progress |
|
228 if ( iOperation ) |
|
229 { |
|
230 return iOperation->ProgressL(); |
|
231 } |
|
232 } |
|
233 // Check that we're using IMAP4 protocol |
|
234 else if ( iMtm == KImumMtmImap4Uid ) |
|
235 { |
|
236 // Get the progress bar only with IMAP4 |
|
237 TImap4UiProgress& uiProgress=iUiProgress(); |
|
238 uiProgress.iBytesToDo=0; |
|
239 uiProgress.iBytesDone=0; |
|
240 uiProgress.iError= ( iStatus.Int() == KErrServerBusy ? KErrImapServerBusy : iStatus.Int() ); |
|
241 uiProgress.iUiOperation = TImap4UiProgress::EDeletingMessages; |
|
242 IMUM_OUT(); |
|
243 return iUiProgress; |
|
244 } |
|
245 IMUM_OUT(); |
|
246 |
|
247 return iBlank; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CImumDeleteMessagesFromServer::DecodeProgress() |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 TInt CImumDeleteMessagesFromServer::DecodeProgress( |
|
255 const TDesC8& aProgress, |
|
256 TBuf<CBaseMtmUi::EProgressStringMaxLen>& aReturnString, |
|
257 TInt& aTotalEntryCount, |
|
258 TInt& aEntriesDone, |
|
259 TInt& aCurrentEntrySize, |
|
260 TInt& aCurrentBytesTrans, |
|
261 TBool /*aInternal*/ ) |
|
262 { |
|
263 IMUM_CONTEXT( CImumDeleteMessagesFromServer::DecodeProgress, 0, KImumMtmLog ); |
|
264 IMUM_IN(); |
|
265 |
|
266 aCurrentEntrySize = aTotalEntryCount = iEntryCount; |
|
267 if ( iState == EImumDeletingMessagesStateLocally ) |
|
268 { |
|
269 TPckgBuf<TImCacheManagerProgress> paramPack; |
|
270 paramPack.Copy(aProgress); |
|
271 const TImCacheManagerProgress& progress=paramPack(); |
|
272 |
|
273 aEntriesDone=progress.iMessagesProcessed; |
|
274 aCurrentBytesTrans=progress.iMessagesProcessed; |
|
275 } |
|
276 else if ( iState == EImumDeletingMessagesStateFromServer ) |
|
277 { |
|
278 if ( iMtm == KImumMtmImap4Uid ) |
|
279 { |
|
280 TPckgBuf<TImap4CompoundProgress> paramPack; |
|
281 paramPack.Copy(aProgress); |
|
282 const TImap4GenericProgress& progress=paramPack().iGenericProgress; |
|
283 aCurrentBytesTrans = aEntriesDone = progress.iMsgsDone == 0 ? 1 : |
|
284 progress.iMsgsDone; |
|
285 if ( progress.iState == TImap4GenericProgress::EDeleting ) |
|
286 { |
|
287 iDeleteProgress = ETrue; |
|
288 } |
|
289 else |
|
290 { |
|
291 if ( iDeleteProgress ) |
|
292 { |
|
293 aCurrentBytesTrans = aEntriesDone = aTotalEntryCount; |
|
294 } |
|
295 } |
|
296 } |
|
297 else if ( iMtm == KImumMtmPop3Uid ) |
|
298 { |
|
299 TPckgBuf<TPop3Progress> paramPack; |
|
300 paramPack.Copy( aProgress ); |
|
301 const TPop3Progress& progress = paramPack(); |
|
302 aCurrentBytesTrans = aEntriesDone = |
|
303 ( progress.iMsgsToProcess == progress.iTotalMsgs ) ? |
|
304 1 : progress.iTotalMsgs-progress.iMsgsToProcess; |
|
305 if ( ( progress.iPop3Progress == TPop3Progress::EPopDeleting ) |
|
306 && ( progress.iTotalMsgs != progress.iMsgsToProcess ) ) |
|
307 { |
|
308 iDeleteProgress = ETrue; |
|
309 } |
|
310 else |
|
311 { |
|
312 if ( iDeleteProgress ) |
|
313 { |
|
314 aCurrentBytesTrans = aEntriesDone = aTotalEntryCount; |
|
315 } |
|
316 } |
|
317 } |
|
318 } |
|
319 aReturnString.Copy( *iProgressText ); |
|
320 if ( iEntryCount > 1 ) |
|
321 { |
|
322 TBuf<CBaseMtmUi::EProgressStringMaxLen> tempBuffer; |
|
323 StringLoader::Format( |
|
324 tempBuffer, |
|
325 aReturnString, |
|
326 KImumEntriesDoneReplaceIndex, |
|
327 aEntriesDone ); |
|
328 StringLoader::Format( |
|
329 aReturnString, |
|
330 tempBuffer, |
|
331 KImumTotalEntriesReplaceIndex, |
|
332 aTotalEntryCount ); |
|
333 } |
|
334 IMUM_OUT(); |
|
335 return KErrNone; |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CImumDeleteMessagesFromServer::StartNextDeleteLocally() |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CImumDeleteMessagesFromServer::StartNextDeleteLocally() |
|
343 { |
|
344 IMUM_CONTEXT( CImumDeleteMessagesFromServer::StartNextDeleteLocally, 0, KImumMtmLog ); |
|
345 IMUM_IN(); |
|
346 |
|
347 if(iOperation) |
|
348 { |
|
349 delete iOperation; |
|
350 iOperation = NULL; |
|
351 } |
|
352 TRAPD(err, MakeNextDeleteLocallyL()); |
|
353 |
|
354 // Set active |
|
355 iState = EImumDeletingMessagesStateLocally; |
|
356 iStatus=KRequestPending; |
|
357 SetActive(); |
|
358 // if error then complete this pass with the error code |
|
359 if (err) |
|
360 { |
|
361 TRequestStatus* status = &iStatus; |
|
362 User::RequestComplete(status, err); |
|
363 } |
|
364 IMUM_OUT(); |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CImumDeleteMessagesFromServer::MakeNextDeleteLocallyL() |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CImumDeleteMessagesFromServer::MakeNextDeleteLocallyL() |
|
372 { |
|
373 IMUM_CONTEXT( CImumDeleteMessagesFromServer::MakeNextDeleteLocallyL, 0, KImumMtmLog ); |
|
374 IMUM_IN(); |
|
375 |
|
376 iOperation = CImumDeleteMessagesLocally::NewL( |
|
377 *iEntrySelection, iMailboxApi, iStatus, EFalse ); |
|
378 IMUM_OUT(); |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CImumDeleteMessagesFromServer::StartDeleteFromServer() |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void CImumDeleteMessagesFromServer::StartDeleteFromServer() |
|
386 { |
|
387 IMUM_CONTEXT( CImumDeleteMessagesFromServer::StartDeleteFromServer, 0, KImumMtmLog ); |
|
388 IMUM_IN(); |
|
389 |
|
390 if(iOperation) |
|
391 { |
|
392 delete iOperation; |
|
393 iOperation = NULL; |
|
394 } |
|
395 TRAPD(err, MakeDeleteFromServerL()); |
|
396 |
|
397 // and set active |
|
398 iState = EImumDeletingMessagesStateFromServer; |
|
399 iStatus=KRequestPending; |
|
400 SetActive(); |
|
401 // if error then complete this pass with the error code |
|
402 if (err) |
|
403 { |
|
404 TRequestStatus* status = &iStatus; |
|
405 User::RequestComplete(status, err); |
|
406 } |
|
407 IMUM_OUT(); |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CImumDeleteMessagesFromServer::MakeDeleteFromServerL() |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 void CImumDeleteMessagesFromServer::MakeDeleteFromServerL() |
|
415 { |
|
416 IMUM_CONTEXT( CImumDeleteMessagesFromServer::MakeDeleteFromServerL, 0, KImumMtmLog ); |
|
417 IMUM_IN(); |
|
418 |
|
419 iOperation = iEntry->DeleteL( *iEntrySelection, iStatus ); |
|
420 IMUM_OUT(); |
|
421 } |
|
422 |
|
423 // End of File |
|
424 |
|
425 |