|
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: |
|
15 * Common base class for email online operations |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <eikenv.h> |
|
21 #include <eikrutil.h> |
|
22 #include <MsvPrgReporter.h> |
|
23 #include <MTMStore.h> |
|
24 #include <mtmuibas.h> |
|
25 #include <ImumInternalApi.h> // CImumInternalApi |
|
26 |
|
27 #include "ImumOnlineOperation.h" |
|
28 #include "ImumPanic.h" |
|
29 #include "ImumMtmLogging.h" |
|
30 |
|
31 |
|
32 // ---------------------------------------------------------------------------- |
|
33 // CImumOnlineOperation::~CImumOnlineOperation() |
|
34 // ---------------------------------------------------------------------------- |
|
35 // |
|
36 CImumOnlineOperation::~CImumOnlineOperation() |
|
37 { |
|
38 IMUM_CONTEXT( CImumOnlineOperation::~CImumOnlineOperation, 0, KImumMtmLog ); |
|
39 IMUM_IN(); |
|
40 |
|
41 Cancel(); |
|
42 delete iOperation; |
|
43 if(iMtmUi) |
|
44 { |
|
45 iReporter.MtmStore().ReleaseMtmUi(iMtmUi->Type()); |
|
46 } |
|
47 IMUM_OUT(); |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // CImumOnlineOperation::ProgressL() |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 const TDesC8& CImumOnlineOperation::ProgressL() |
|
55 { |
|
56 IMUM_CONTEXT( CImumOnlineOperation::ProgressL, 0, KImumMtmLog ); |
|
57 IMUM_IN(); |
|
58 |
|
59 IMUM_OUT(); |
|
60 if(iError != KErrNone) |
|
61 { |
|
62 return GetErrorProgressL(iError); |
|
63 } |
|
64 else if(iOperation) |
|
65 { |
|
66 return iOperation->ProgressL(); |
|
67 } |
|
68 return iDummyProg; |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // CImumOnlineOperation::CImumOnlineOperation() |
|
73 // ---------------------------------------------------------------------------- |
|
74 // |
|
75 CImumOnlineOperation::CImumOnlineOperation( |
|
76 CImumInternalApi& aMailboxApi, |
|
77 TInt aPriority, |
|
78 TRequestStatus& aObserverRequestStatus, |
|
79 MMsvProgressReporter& aReporter) |
|
80 : |
|
81 CMsvOperation( |
|
82 aMailboxApi.MsvSession(), |
|
83 aPriority, |
|
84 aObserverRequestStatus), |
|
85 iReporter(aReporter), |
|
86 iMailboxApi( aMailboxApi ), |
|
87 iEikEnv(CEikonEnv::Static()) |
|
88 { |
|
89 IMUM_CONTEXT( CImumOnlineOperation::CImumOnlineOperation, 0, KImumMtmLog ); |
|
90 IMUM_IN(); |
|
91 IMUM_OUT(); |
|
92 |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CImumOnlineOperation::BaseConstructL() |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 void CImumOnlineOperation::BaseConstructL(TUid aMtmType) |
|
100 { |
|
101 IMUM_CONTEXT( CImumOnlineOperation::BaseConstructL, 0, KImumMtmLog ); |
|
102 IMUM_IN(); |
|
103 |
|
104 iObserverRequestStatus = KRequestPending; |
|
105 CActiveScheduler::Add(this); |
|
106 iMtmUi = &(iReporter.MtmStore().ClaimMtmUiL(aMtmType)); |
|
107 iMtm = aMtmType; |
|
108 IMUM_OUT(); |
|
109 } |
|
110 |
|
111 // ---------------------------------------------------------------------------- |
|
112 // CImumOnlineOperation::DoCancel() |
|
113 // ---------------------------------------------------------------------------- |
|
114 // |
|
115 void CImumOnlineOperation::DoCancel() |
|
116 { |
|
117 IMUM_CONTEXT( CImumOnlineOperation::DoCancel, 0, KImumMtmLog ); |
|
118 IMUM_IN(); |
|
119 |
|
120 if(iOperation) |
|
121 { |
|
122 iOperation->Cancel(); |
|
123 } |
|
124 CompleteObserver(); |
|
125 IMUM_OUT(); |
|
126 } |
|
127 |
|
128 // ---------------------------------------------------------------------------- |
|
129 // CImumOnlineOperation::RunL() |
|
130 // ---------------------------------------------------------------------------- |
|
131 // |
|
132 void CImumOnlineOperation::RunL() |
|
133 { |
|
134 IMUM_CONTEXT( CImumOnlineOperation::RunL, 0, KImumMtmLog ); |
|
135 IMUM_IN(); |
|
136 |
|
137 // First do a disk space check, so the operation can continue |
|
138 iError = DoDiskSpaceCheckL(); |
|
139 |
|
140 // If still free disk space, the actual operation can be continued |
|
141 if ( iError == KErrNone ) |
|
142 { |
|
143 DoRunL(); |
|
144 } |
|
145 else |
|
146 { |
|
147 User::Leave( iError ); |
|
148 } |
|
149 IMUM_OUT(); |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------------------------------- |
|
153 // CImumOnlineOperation::RunError() |
|
154 // ---------------------------------------------------------------------------- |
|
155 // |
|
156 TInt CImumOnlineOperation::RunError( TInt aError ) |
|
157 { |
|
158 IMUM_CONTEXT( CImumOnlineOperation::RunError, 0, KImumMtmLog ); |
|
159 IMUM_IN(); |
|
160 |
|
161 IMUM1( 0, "RunL error %d", aError ); |
|
162 CompleteObserver( aError ); |
|
163 |
|
164 IMUM_OUT(); |
|
165 // RunError must return KErrNone to active sheduler. |
|
166 // We return the error, since we do not fully handle the error |
|
167 // We may want the framework to show some notes etc... |
|
168 return aError; |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CImumOnlineOperation::CompleteObserver() |
|
173 // ---------------------------------------------------------------------------- |
|
174 // |
|
175 void CImumOnlineOperation::CompleteObserver( TInt aStatus /*= KErrNone*/ ) |
|
176 { |
|
177 IMUM_CONTEXT( CImumOnlineOperation::CompleteObserver, 0, KImumMtmLog ); |
|
178 IMUM_IN(); |
|
179 |
|
180 TRequestStatus* status = &iObserverRequestStatus; |
|
181 User::RequestComplete(status, aStatus); |
|
182 IMUM_OUT(); |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // CImumOnlineOperation::CompleteThis() |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 void CImumOnlineOperation::CompleteThis() |
|
190 { |
|
191 IMUM_CONTEXT( CImumOnlineOperation::CompleteThis, 0, KImumMtmLog ); |
|
192 IMUM_IN(); |
|
193 |
|
194 TRequestStatus* status = &iStatus; |
|
195 User::RequestComplete(status, KErrNone); |
|
196 IMUM_OUT(); |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // CImumOnlineOperation::GetOperationCompletionCodeL() |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CImumOnlineOperation::GetOperationCompletionCodeL() |
|
204 { |
|
205 IMUM_CONTEXT( CImumOnlineOperation::GetOperationCompletionCodeL, 0, KImumMtmLog ); |
|
206 IMUM_IN(); |
|
207 |
|
208 if(iStatus.Int() != KErrNone) |
|
209 { |
|
210 IMUM_OUT(); |
|
211 return iStatus.Int(); |
|
212 } |
|
213 __ASSERT_DEBUG( iMtmUi, User::Panic( KImumMtmUiPanic,EPanicOpNoMtmUi ) ); |
|
214 TBuf<CBaseMtmUi::EProgressStringMaxLen> retString; |
|
215 TInt totalEntryCount = 0; |
|
216 TInt entriesDone = 0; |
|
217 TInt currentEntrySize = 0; |
|
218 TInt currentBytesTrans = 0; |
|
219 IMUM_OUT(); |
|
220 |
|
221 return iMtmUi->GetProgress( |
|
222 ProgressL(), |
|
223 retString, |
|
224 totalEntryCount, |
|
225 entriesDone, |
|
226 currentEntrySize, |
|
227 currentBytesTrans); |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // CImumOnlineOperation::InvokeClientMtmAsyncFunctionL() |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 void CImumOnlineOperation::InvokeClientMtmAsyncFunctionL( |
|
235 TInt aFunctionId, |
|
236 TMsvId aEntryId, |
|
237 TMsvId aContextId, |
|
238 const TDesC8& aParams) |
|
239 { |
|
240 IMUM_CONTEXT( CImumOnlineOperation::InvokeClientMtmAsyncFunctionL, 0, KImumMtmLog ); |
|
241 IMUM_IN(); |
|
242 |
|
243 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
244 CleanupStack::PushL(sel); |
|
245 sel->AppendL(aEntryId); |
|
246 InvokeClientMtmAsyncFunctionL(aFunctionId, *sel, aContextId, aParams); |
|
247 CleanupStack::PopAndDestroy(); // sel |
|
248 IMUM_OUT(); |
|
249 } |
|
250 |
|
251 // ---------------------------------------------------------------------------- |
|
252 // CImumOnlineOperation::InvokeClientMtmAsyncFunctionL() |
|
253 // ---------------------------------------------------------------------------- |
|
254 // |
|
255 void CImumOnlineOperation::InvokeClientMtmAsyncFunctionL( |
|
256 TInt aFunctionId, |
|
257 const CMsvEntrySelection& aSel, |
|
258 TMsvId aContextId, |
|
259 const TDesC8& aParams) |
|
260 { |
|
261 IMUM_CONTEXT( CImumOnlineOperation::InvokeClientMtmAsyncFunctionL, 0, KImumMtmLog ); |
|
262 IMUM_IN(); |
|
263 |
|
264 __ASSERT_DEBUG(iMtmUi, User::Panic( KImumMtmUiPanic,EPanicOpNoMtmUi)); |
|
265 CBaseMtm& mtm = iMtmUi->BaseMtm(); |
|
266 mtm.SwitchCurrentEntryL(aContextId); |
|
267 HBufC8* params = aParams.AllocLC(); |
|
268 TPtr8 ptr(params->Des()); |
|
269 // Delete previous operation if it exist |
|
270 if ( iOperation ) |
|
271 { |
|
272 delete iOperation; |
|
273 iOperation = NULL; |
|
274 } |
|
275 iOperation = mtm.InvokeAsyncFunctionL(aFunctionId, aSel, ptr, iStatus); |
|
276 CleanupStack::PopAndDestroy(); // params |
|
277 IMUM_OUT(); |
|
278 } |
|
279 |
|
280 // ---------------------------------------------------------------------------- |
|
281 // CImumOnlineOperation::ReDisplayProgressL() |
|
282 // ---------------------------------------------------------------------------- |
|
283 // |
|
284 void CImumOnlineOperation::ReDisplayProgressL( |
|
285 TInt /*aTitleResourceId*/, TMsvId /*aServiceId*/) |
|
286 { |
|
287 IMUM_CONTEXT( CImumOnlineOperation::ReDisplayProgressL, 0, KImumMtmLog ); |
|
288 IMUM_IN(); |
|
289 |
|
290 iReporter.MakeProgressVisibleL(ETrue); |
|
291 IMUM_OUT(); |
|
292 } |
|
293 |
|
294 // ---------------------------------------------------------------------------- |
|
295 // CImumOnlineOperation::DoDiskSpaceCheckL() |
|
296 // ---------------------------------------------------------------------------- |
|
297 // |
|
298 TInt CImumOnlineOperation::DoDiskSpaceCheckL() |
|
299 { |
|
300 IMUM_CONTEXT( CImumOnlineOperation::DoDiskSpaceCheckL, 0, KImumMtmLog ); |
|
301 IMUM_IN(); |
|
302 IMUM_OUT(); |
|
303 |
|
304 // As default, return KErrNone |
|
305 return KErrNone; |
|
306 } |
|
307 |
|
308 |