|
1 /* |
|
2 * Copyright (c) 2007 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: MsvOperation encapsulating deletion of email service |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <StringLoader.h> // StringLoader |
|
20 #include <mtuireg.h> |
|
21 #include <muiumsvuiserviceutilitiesinternal.h> |
|
22 #include <imum.rsg> |
|
23 #include <MtmExtendedCapabilities.hrh> |
|
24 |
|
25 #include "ImumMboxServiceDeletion.h" |
|
26 #include "MsvPrgReporter.h" |
|
27 #include "EmailUtils.H" |
|
28 #include "SenduiMtmUids.h" |
|
29 #include "ImumPanic.h" |
|
30 #include "IMSSettingsNoteUi.h" |
|
31 #include "ImumInternalApiImpl.h" |
|
32 |
|
33 #include "ImumMtmLogging.h" |
|
34 |
|
35 const TInt KSvcDelOpPriority = CActive::EPriorityStandard; |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // CImumMBoxServiceDeletion::NewL() |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CImumMBoxServiceDeletion* CImumMBoxServiceDeletion::NewL( |
|
42 CMsvSession& aMsvSession, |
|
43 TRequestStatus& aObserverRequestStatus, |
|
44 MMsvProgressReporter& aReporter, |
|
45 TMsvId aServiceId ) |
|
46 { |
|
47 CImumMBoxServiceDeletion* op = |
|
48 new ( ELeave ) CImumMBoxServiceDeletion( aMsvSession, |
|
49 aObserverRequestStatus, |
|
50 aReporter, |
|
51 aServiceId ); |
|
52 |
|
53 CleanupStack::PushL( op ); |
|
54 op->ConstructL(); |
|
55 CleanupStack::Pop( op ); |
|
56 return op; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CImumMBoxServiceDeletion::~CImumMBoxServiceDeletion() |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 CImumMBoxServiceDeletion::~CImumMBoxServiceDeletion() |
|
64 { |
|
65 IMUM_CONTEXT( CImumMBoxServiceDeletion::CImumMBoxServiceDeletion, 0, KImumMtmLog ); |
|
66 IMUM_IN(); |
|
67 |
|
68 if ( IsActive() ) |
|
69 { |
|
70 Cancel(); |
|
71 } |
|
72 |
|
73 delete iEmailApi; |
|
74 delete iSubOperation; |
|
75 delete iProgressString; |
|
76 |
|
77 IMUM_OUT(); |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CImumMBoxServiceDeletion::ProgressL() |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 const TDesC8& CImumMBoxServiceDeletion::ProgressL() |
|
85 { |
|
86 if ( iState == EDeleteService ) |
|
87 { |
|
88 iProgressBuf.Copy( iSubOperation->ProgressL() ); |
|
89 } |
|
90 return iProgressBuf; |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // CImumMBoxServiceDeletion::RunL() |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 void CImumMBoxServiceDeletion::RunL() |
|
98 { |
|
99 IMUM_CONTEXT( CImumMBoxServiceDeletion::RunL, 0, KImumMtmLog ); |
|
100 IMUM_IN(); |
|
101 |
|
102 DoRunL(); |
|
103 |
|
104 IMUM_OUT(); |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // CImumMBoxServiceDeletion::DoCancel() |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 void CImumMBoxServiceDeletion::DoCancel() |
|
112 { |
|
113 IMUM_CONTEXT( CImumMBoxServiceDeletion::DoCancel, 0, KImumMtmLog ); |
|
114 IMUM_IN(); |
|
115 |
|
116 if ( iSubOperation ) |
|
117 { |
|
118 iSubOperation->Cancel(); |
|
119 } |
|
120 CompleteObserver(); |
|
121 IMUM_OUT(); |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CImumMBoxServiceDeletion::RunError() |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CImumMBoxServiceDeletion::RunError(TInt __DEBUG_ONLY( aError ) ) |
|
129 { |
|
130 IMUM_CONTEXT( CImumMBoxServiceDeletion::RunError, 0, KImumMtmLog ); |
|
131 IMUM_IN(); |
|
132 |
|
133 IMUM1( 0, "RunL error %d", aError); |
|
134 |
|
135 CompleteObserver(); |
|
136 |
|
137 IMUM_OUT(); |
|
138 return KErrNone; // RunError must return KErrNone to active sheduler. |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------------------------------- |
|
142 // CImumMBoxServiceDeletion::CImumMBoxServiceDeletion() |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 CImumMBoxServiceDeletion::CImumMBoxServiceDeletion( |
|
146 CMsvSession& aMsvSession, |
|
147 TRequestStatus& aObserverRequestStatus, |
|
148 MMsvProgressReporter& aReporter, |
|
149 TMsvId aServiceId ) |
|
150 : |
|
151 CMsvOperation( aMsvSession, KSvcDelOpPriority, aObserverRequestStatus ), |
|
152 iReporter( aReporter ), |
|
153 iServiceId( aServiceId ) |
|
154 { |
|
155 IMUM_CONTEXT( CImumMBoxServiceDeletion::CImumMBoxServiceDeletion, 0, KImumMtmLog ); |
|
156 IMUM_IN(); |
|
157 IMUM_OUT(); |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CImumMBoxServiceDeletion::ConstructL() |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 void CImumMBoxServiceDeletion::ConstructL() |
|
165 { |
|
166 IMUM_CONTEXT( CImumMBoxServiceDeletion::ConstructL, 0, KImumMtmLog ); |
|
167 IMUM_IN(); |
|
168 |
|
169 CActiveScheduler::Add( this ); |
|
170 |
|
171 iEmailApi = CImumInternalApiImpl::NewL( &iMsvSession ); |
|
172 |
|
173 TMsvEntry servEntry; |
|
174 TMsvId serviceId; |
|
175 User::LeaveIfError( |
|
176 iMsvSession.GetEntry( iServiceId, serviceId, servEntry ) ); |
|
177 |
|
178 iSMTPServiceId = servEntry.iRelatedId; |
|
179 iMtm = servEntry.iMtm; |
|
180 |
|
181 TMsvEntry smtpEntry; |
|
182 TMsvId smtpServiceId; |
|
183 |
|
184 User::LeaveIfError( iMsvSession.GetEntry( |
|
185 iSMTPServiceId, smtpServiceId, smtpEntry ) ); |
|
186 |
|
187 // serviceEntry must: be a service entry and have the root as parent. |
|
188 __ASSERT_DEBUG(servEntry.iType.iUid == KUidMsvServiceEntryValue, |
|
189 User::Panic(KImumMtmUiPanic,ESmtpMtmUiSvcDelOpNotAService) ); |
|
190 __ASSERT_DEBUG(servEntry.Parent() == KMsvRootIndexEntryIdValue, |
|
191 User::Panic(KImumMtmUiPanic,ESmtpMtmUiSvcDelOpParentIsNotRoot) ); |
|
192 |
|
193 SetProgressStringL( smtpEntry.Id() ); |
|
194 iReporter.SetProgressDecoder( *this ); |
|
195 |
|
196 // Remove mailbox from ao agent list. |
|
197 // if fails, just ignore, doesn't effect us |
|
198 TRAP_IGNORE( MsvEmailMtmUiUtils::SendAOCommandL( EServerAPIEmailAgentRemove, |
|
199 iServiceId ) ); |
|
200 |
|
201 BeginDeleteOperationL(); |
|
202 iState = EDoPrompts; |
|
203 ProgressL();//Update initial progress. |
|
204 |
|
205 IMUM_OUT(); |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------------------------------- |
|
209 // CImumMBoxServiceDeletion::BeginDeleteOperationL() |
|
210 // ---------------------------------------------------------------------------- |
|
211 // |
|
212 void CImumMBoxServiceDeletion::BeginDeleteOperationL() |
|
213 { |
|
214 IMUM_CONTEXT( CImumMBoxServiceDeletion::BeginDeleteOperationL, 0, KImumMtmLog ); |
|
215 IMUM_IN(); |
|
216 |
|
217 iSubOperation = CMsvCompletedOperation::NewL( |
|
218 iMsvSession, KUidMsvLocalServiceMtm, KNullDesC8, |
|
219 KMsvLocalServiceIndexEntryId, iStatus ); |
|
220 |
|
221 SetActive(); |
|
222 IMUM_OUT(); |
|
223 } |
|
224 |
|
225 // ---------------------------------------------------------------------------- |
|
226 // CImumMBoxServiceDeletion::RemovePreCreatedMessagesL() |
|
227 // ---------------------------------------------------------------------------- |
|
228 // |
|
229 void CImumMBoxServiceDeletion::RemovePreCreatedMessagesL() |
|
230 { |
|
231 IMUM_CONTEXT( CImumMBoxServiceDeletion::RemovePreCreatedMessagesL, 0, KImumMtmLog ); |
|
232 IMUM_IN(); |
|
233 |
|
234 iStatus = KRequestPending; |
|
235 iSubOperation = GetPreCreatedMailDeletionOpL( iStatus ); |
|
236 SetActive(); |
|
237 |
|
238 if( !iSubOperation ) |
|
239 { |
|
240 // If this is the case, complete this stage. |
|
241 TRequestStatus* status = &iStatus; |
|
242 User::RequestComplete(status, KErrNone); |
|
243 } |
|
244 IMUM_OUT(); |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // CImumMBoxServiceDeletion::DoRunL() |
|
249 // ---------------------------------------------------------------------------- |
|
250 // |
|
251 void CImumMBoxServiceDeletion::DoRunL() |
|
252 { |
|
253 IMUM_CONTEXT( CImumMBoxServiceDeletion::DoRunL, 0, KImumMtmLog ); |
|
254 IMUM_IN(); |
|
255 |
|
256 if( iSubOperation ) |
|
257 { |
|
258 if ( iSubOperation->IsActive() ) |
|
259 { |
|
260 iSubOperation->Cancel(); |
|
261 } |
|
262 |
|
263 delete iSubOperation; |
|
264 iSubOperation = NULL; |
|
265 } |
|
266 |
|
267 switch(iState) |
|
268 { |
|
269 case EDoPrompts: |
|
270 DoRemoveMailboxL(); |
|
271 iState = EDeleteService; |
|
272 break; |
|
273 case EDeleteService: |
|
274 RemovePreCreatedMessagesL(); |
|
275 iState = EDeletePreCreatedMsgs; |
|
276 break; |
|
277 case EDeletePreCreatedMsgs: |
|
278 CompleteObserver(); |
|
279 break; |
|
280 case EStateComplete: |
|
281 default: |
|
282 break; |
|
283 } |
|
284 IMUM_OUT(); |
|
285 } |
|
286 |
|
287 // ---------------------------------------------------------------------------- |
|
288 // CImumMBoxServiceDeletion::CompleteObserver() |
|
289 // ---------------------------------------------------------------------------- |
|
290 // |
|
291 void CImumMBoxServiceDeletion::CompleteObserver() |
|
292 { |
|
293 TRequestStatus* status = &iObserverRequestStatus; |
|
294 User::RequestComplete(status, iStatus.Int()); |
|
295 } |
|
296 |
|
297 |
|
298 // ---------------------------------------------------------------------------- |
|
299 // CImumMBoxServiceDeletion::DecodeProgress() |
|
300 // ---------------------------------------------------------------------------- |
|
301 // |
|
302 TInt CImumMBoxServiceDeletion::DecodeProgress( |
|
303 const TDesC8& /* aProgress */, |
|
304 TBuf<CBaseMtmUi::EProgressStringMaxLen>& aReturnString, |
|
305 TInt& aTotalEntryCount, |
|
306 TInt& aEntriesDone, |
|
307 TInt& aCurrentEntrySize, |
|
308 TInt& aCurrentBytesTrans, |
|
309 TBool /* aInternal */) |
|
310 { |
|
311 aTotalEntryCount = 0; |
|
312 aEntriesDone = 0; |
|
313 aCurrentEntrySize = 0; |
|
314 aCurrentBytesTrans = 0; |
|
315 aReturnString.Copy( *iProgressString ); |
|
316 return KErrNone; |
|
317 } |
|
318 |
|
319 // ---------------------------------------------------------------------------- |
|
320 // CImumMBoxServiceDeletion::BeginRemoveAccountDeleteOpL() |
|
321 // ---------------------------------------------------------------------------- |
|
322 // |
|
323 void CImumMBoxServiceDeletion::BeginRemoveAccountDeleteOpL() |
|
324 { |
|
325 IMUM_CONTEXT( CImumMBoxServiceDeletion::BeginRemoveAccountDeleteOpL, 0, KImumMtmLog ); |
|
326 IMUM_IN(); |
|
327 |
|
328 // Complete right after the deletion |
|
329 iSubOperation = CMsvCompletedOperation::NewL( iMsvSession, |
|
330 KUidMsvLocalServiceMtm, |
|
331 KNullDesC8, |
|
332 KMsvLocalServiceIndexEntryId, |
|
333 iStatus ); |
|
334 iStatus = KRequestPending; |
|
335 SetActive(); |
|
336 IMUM_OUT(); |
|
337 } |
|
338 |
|
339 // ---------------------------------------------------------------------------- |
|
340 // CImumMBoxServiceDeletion::GetPreCreatedMailDeletionOpL() |
|
341 // ---------------------------------------------------------------------------- |
|
342 // |
|
343 CMsvOperation* CImumMBoxServiceDeletion::GetPreCreatedMailDeletionOpL( TRequestStatus& aStatus ) |
|
344 { |
|
345 IMUM_CONTEXT( CImumMBoxServiceDeletion::GetPreCreatedMailDeletionOpL, 0, KImumMtmLog ); |
|
346 IMUM_IN(); |
|
347 |
|
348 //Get SMTP UI mtm |
|
349 CClientMtmRegistry* clientRegistry = CClientMtmRegistry::NewL( iMsvSession ); |
|
350 CleanupStack::PushL( clientRegistry ); |
|
351 |
|
352 CBaseMtm* smtpmtm = clientRegistry->NewMtmL( KUidMsgTypeSMTP ); |
|
353 CleanupStack::PushL( smtpmtm ); |
|
354 |
|
355 CMtmUiRegistry* mtmuireg = CMtmUiRegistry::NewL( iMsvSession ); |
|
356 CleanupStack::PushL( mtmuireg ); |
|
357 |
|
358 CBaseMtmUi* smtpUi = mtmuireg->NewMtmUiL( *smtpmtm ); |
|
359 CleanupStack::PushL( smtpUi ); |
|
360 |
|
361 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
362 CleanupStack::PushL(sel); |
|
363 sel->AppendL( iSMTPServiceId ); |
|
364 |
|
365 TBuf8<1> dummyParam; |
|
366 CMsvOperation* op = smtpUi->InvokeAsyncFunctionL( KMtmUiFunctionPreCreateMessage, *sel, aStatus, dummyParam ); |
|
367 |
|
368 CleanupStack::PopAndDestroy( 5, clientRegistry ); // CSI: 47 # sel, smtpUi, mtmuireg, smtpmtm, clientRegistry |
|
369 |
|
370 IMUM_OUT(); |
|
371 return op; |
|
372 } |
|
373 |
|
374 // ---------------------------------------------------------------------------- |
|
375 // CImumMBoxServiceDeletion::DoRemoveMailboxL() |
|
376 // ---------------------------------------------------------------------------- |
|
377 // |
|
378 void CImumMBoxServiceDeletion::DoRemoveMailboxL() |
|
379 { |
|
380 IMUM_CONTEXT( CImumMBoxServiceDeletion::DoRemoveMailboxL, 0, KImumMtmLog ); |
|
381 IMUM_IN(); |
|
382 |
|
383 iStatus = KRequestPending; |
|
384 |
|
385 iEmailApi->SettingsManagerL().RemoveAccount( iServiceId, ETrue ); |
|
386 |
|
387 iSubOperation = CMsvCompletedOperation::NewL( iMsvSession, |
|
388 KUidMsvLocalServiceMtm, |
|
389 KNullDesC8, |
|
390 KMsvLocalServiceIndexEntryId, |
|
391 iStatus ); |
|
392 |
|
393 |
|
394 SetActive(); |
|
395 IMUM_OUT(); |
|
396 } |
|
397 |
|
398 // ---------------------------------------------------------------------------- |
|
399 // CImumMBoxServiceDeletion::SetProgressStringL() |
|
400 // ---------------------------------------------------------------------------- |
|
401 // |
|
402 void CImumMBoxServiceDeletion::SetProgressStringL( TMsvId aServiceId ) |
|
403 { |
|
404 TMsvId serv; |
|
405 TMsvEntry tEntry; |
|
406 |
|
407 TInt err = iMsvSession.GetEntry( aServiceId, serv, tEntry ); |
|
408 |
|
409 if ( iProgressString ) |
|
410 { |
|
411 delete iProgressString; |
|
412 iProgressString = NULL; |
|
413 } |
|
414 |
|
415 iProgressString = StringLoader::LoadL( |
|
416 R_EMAIL_SVCDELOP_DIALOG_TITLE, tEntry.iDetails, CEikonEnv::Static() ); |
|
417 |
|
418 iReporter.SetTitleL(*iProgressString); |
|
419 iReporter.SetProgressDecoder( *this ); |
|
420 } |
|
421 |
|
422 // End of File |