|
1 /* |
|
2 * Copyright (c) 2009 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: CSimDeleteCopyOperation header |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <AknProgressDialog.h> // CAknProgressDialog |
|
20 #include <eikprogi.h> // CEikProgressInfo |
|
21 #include <StringLoader.h> // StringLoader |
|
22 #include <msvids.h> // for msv entry ids |
|
23 #include <msvapi.h> // for CMsvSession |
|
24 #include <smscmds.h> // for async sms commands |
|
25 #include <smut.h> // TSmsUtilities::ServiceIdL |
|
26 |
|
27 #include "simdeletecopyoperation.h" // for CSimDeleteCopyOperation |
|
28 #include "SMSU.H" // for CSmsMtmUi |
|
29 #include "SMSU.HRH" // for command ids |
|
30 #include <defaultsimdialog.rsg> // for resource ids |
|
31 |
|
32 //For logging |
|
33 #include "SmumLogging.h" |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KSmumNoteStringLength = 128; |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // |
|
43 CSimDeleteCopyOperation::CSimDeleteCopyOperation( |
|
44 CMsvSession& aMsvSession, |
|
45 CSmsMtmUi& aSmsMtmUi, |
|
46 TRequestStatus& aObserverRequestStatus, |
|
47 TMsvId aDestinationId, |
|
48 CAknProgressDialog& aProgressDialog, |
|
49 TBool aCopying, |
|
50 CCoeEnv* aCoeEnv ) |
|
51 : |
|
52 CMsvOperation( |
|
53 aMsvSession, |
|
54 CActive::EPriorityStandard, |
|
55 aObserverRequestStatus), |
|
56 iDestinationId( aDestinationId ), |
|
57 iCopying( aCopying ), |
|
58 iSmsMtmUi( aSmsMtmUi ), |
|
59 iProgressDialog( aProgressDialog ), |
|
60 iCoeEnv( aCoeEnv ), |
|
61 iBlank( KNullDesC8 ) |
|
62 { |
|
63 CActiveScheduler::Add(this); |
|
64 } |
|
65 |
|
66 |
|
67 // Symbian OS default constructor can leave. |
|
68 void CSimDeleteCopyOperation::ConstructL( CMsvEntrySelection* aSelection ) |
|
69 { |
|
70 SMUMLOGGER_ENTERFN("CSimDeleteCopyOperation::ConstructL"); |
|
71 iEntrySelection = aSelection->CopyL(); |
|
72 iEntryCount = iEntrySelection->Count(); |
|
73 if ( iEntryCount == 0 ) |
|
74 { // no entries in selection -> complete |
|
75 iStatus = KRequestPending; |
|
76 SetActive(); |
|
77 TRequestStatus* status = &iStatus; |
|
78 User::RequestComplete( status, KErrNone ); |
|
79 } |
|
80 else |
|
81 { // entries in selection -> proceed |
|
82 // Save SMS Service id to member |
|
83 CMsvEntry* root = iMsvSession.GetEntryL( KMsvRootIndexEntryId ); |
|
84 CleanupStack::PushL( root ); |
|
85 TSmsUtilities::ServiceIdL( *root, iSmsServiceId ); |
|
86 CleanupStack::PopAndDestroy( root); |
|
87 |
|
88 // Load correct string to member |
|
89 if ( iEntryCount == 1 ) |
|
90 {// simple string is enough |
|
91 iNoteString = StringLoader::LoadL( iCopying |
|
92 ? R_QTN_MCE_WAIT_COPY_SIM_DLG : R_QTN_MCE_WAIT_DELETE_SIM_DLG, iCoeEnv ); |
|
93 } |
|
94 else |
|
95 {// prepare string with formatting second number already |
|
96 // to string |
|
97 TBuf<KSmumNoteStringLength> tbuf; |
|
98 HBufC* buf = StringLoader::LoadL( iCopying |
|
99 ? R_QTN_MCE_WAIT_COPY_MANY_SIM_DLG : R_QTN_MCE_WAIT_DELETE_MANY_SIM_DLG, |
|
100 iCoeEnv ); |
|
101 StringLoader::Format( tbuf, buf->Des(), 1, iEntryCount ); |
|
102 delete buf; |
|
103 iNoteString = tbuf.AllocL(); |
|
104 } |
|
105 |
|
106 // Actual operation |
|
107 CEikProgressInfo* bar = iProgressDialog.GetProgressInfoL(); |
|
108 bar->SetFinalValue( iEntryCount ); |
|
109 |
|
110 DeleteCopyNext(); |
|
111 bar->SetAndDraw( iCurrentEntryIndex + 1 ); |
|
112 } |
|
113 SMUMLOGGER_LEAVEFN("CSimDeleteCopyOperation::ConstructL"); |
|
114 } |
|
115 |
|
116 |
|
117 // Two-phased constructor. |
|
118 CSimDeleteCopyOperation* CSimDeleteCopyOperation::NewL( |
|
119 CMsvSession& aMsvSession, |
|
120 CSmsMtmUi& aSmsMtmUi, |
|
121 TRequestStatus& aObserverRequestStatus, |
|
122 CMsvEntrySelection* aSelection, |
|
123 TMsvId aDestinationId, |
|
124 CAknProgressDialog& aProgressDialog, |
|
125 CCoeEnv* aCoeEnv ) |
|
126 { |
|
127 SMUMLOGGER_ENTERFN("CSimDeleteCopyOperation::NewL"); |
|
128 CSimDeleteCopyOperation* self=new (ELeave) CSimDeleteCopyOperation( |
|
129 aMsvSession, |
|
130 aSmsMtmUi, |
|
131 aObserverRequestStatus, |
|
132 aDestinationId, |
|
133 aProgressDialog, |
|
134 ETrue, |
|
135 aCoeEnv ); |
|
136 CleanupStack::PushL(self); |
|
137 self->ConstructL( aSelection ); |
|
138 CleanupStack::Pop(); // self |
|
139 SMUMLOGGER_LEAVEFN("CSimDeleteCopyOperation::NewL"); |
|
140 return self; |
|
141 } |
|
142 |
|
143 // Two-phased constructor. |
|
144 CSimDeleteCopyOperation* CSimDeleteCopyOperation::NewL( |
|
145 CMsvSession& aMsvSession, |
|
146 CSmsMtmUi& aSmsMtmUi, |
|
147 TRequestStatus& aObserverRequestStatus, |
|
148 CMsvEntrySelection* aSelection, |
|
149 CAknProgressDialog& aProgressDialog, |
|
150 CCoeEnv* aCoeEnv ) |
|
151 { |
|
152 SMUMLOGGER_ENTERFN("CSimDeleteCopyOperation::NewL 2"); |
|
153 CSimDeleteCopyOperation* self=new (ELeave) CSimDeleteCopyOperation( |
|
154 aMsvSession, |
|
155 aSmsMtmUi, |
|
156 aObserverRequestStatus, |
|
157 KMsvNullIndexEntryId, |
|
158 aProgressDialog, |
|
159 EFalse, |
|
160 aCoeEnv ); |
|
161 CleanupStack::PushL(self); |
|
162 self->ConstructL( aSelection ); |
|
163 CleanupStack::Pop(); // self |
|
164 SMUMLOGGER_LEAVEFN("CSimDeleteCopyOperation::NewL 2"); |
|
165 return self; |
|
166 } |
|
167 |
|
168 |
|
169 |
|
170 //destructor |
|
171 CSimDeleteCopyOperation::~CSimDeleteCopyOperation() |
|
172 { |
|
173 SMUMLOGGER_ENTERFN("CSimDeleteCopyOperation::~CSimDeleteCopyOperation"); |
|
174 Cancel(); |
|
175 delete iOperation; |
|
176 delete iEntrySelection; |
|
177 delete iNoteString; |
|
178 SMUMLOGGER_LEAVEFN("CSimDeleteCopyOperation::~CSimDeleteCopyOperation"); |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CSimDeleteCopyOperation::DeleteCopyNext() |
|
183 // |
|
184 // --------------------------------------------------------------------------- |
|
185 void CSimDeleteCopyOperation::DeleteCopyNext() |
|
186 { |
|
187 SMUMLOGGER_ENTERFN("CSimDeleteCopyOperation::DeleteCopyNext"); |
|
188 delete iOperation; |
|
189 iOperation = NULL; |
|
190 |
|
191 TInt err = KErrNone; |
|
192 if ( iCanceling ) |
|
193 { |
|
194 #ifdef _DEBUG |
|
195 RDebug::Print(_L("CSimDeleteCopyOperation::DeleteCopyNext, canceling...") ); |
|
196 #endif |
|
197 err = KErrCancel; |
|
198 } |
|
199 else |
|
200 { |
|
201 #ifdef _DEBUG |
|
202 RDebug::Print(_L("CSimDeleteCopyOperation::DeleteCopyNext, do next...") ); |
|
203 #endif |
|
204 TRAP(err, MakeNextDeleteCopyL()); |
|
205 } |
|
206 |
|
207 // and set active |
|
208 iStatus=KRequestPending; |
|
209 SetActive(); |
|
210 // if error then complete this pass with the error code |
|
211 if (err) |
|
212 { |
|
213 TRequestStatus* status = &iStatus; |
|
214 User::RequestComplete(status, err); |
|
215 } |
|
216 SMUMLOGGER_LEAVEFN("CSimDeleteCopyOperation::DeleteCopyNext"); |
|
217 } |
|
218 |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // CSimDeleteCopyOperation::MakeNextDeleteCopyL() |
|
222 // |
|
223 // --------------------------------------------------------------------------- |
|
224 void CSimDeleteCopyOperation::MakeNextDeleteCopyL() |
|
225 { |
|
226 SMUMLOGGER_ENTERFN("CSimDeleteCopyOperation::MakeNextDeleteCopyL"); |
|
227 CEikProgressInfo* bar = iProgressDialog.GetProgressInfoL(); |
|
228 bar->SetAndDraw( iCurrentEntryIndex + 1 ); |
|
229 |
|
230 // Update (if necessary) the note |
|
231 if ( iEntryCount == 1 ) |
|
232 { |
|
233 iProgressDialog.SetTextL( *iNoteString ); |
|
234 } |
|
235 else |
|
236 { // update the first number in string |
|
237 TBuf<KSmumNoteStringLength> tbuf; |
|
238 StringLoader::Format( tbuf, iNoteString->Des(), 0, iCurrentEntryIndex + 1 ); |
|
239 iProgressDialog.SetTextL( tbuf ); |
|
240 } |
|
241 |
|
242 // Create selection to be given to MTM |
|
243 CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection(); |
|
244 CleanupStack::PushL( selection ); |
|
245 // Put SMS Service id as first id in array |
|
246 selection->AppendL( iSmsServiceId ); |
|
247 // ...and then current id |
|
248 selection->AppendL( iEntrySelection->At( iCurrentEntryIndex ) ); |
|
249 |
|
250 if ( iCopying ) |
|
251 { |
|
252 TPckgBuf<TMsvId> pkg( iDestinationId ); |
|
253 iOperation = iSmsMtmUi.BaseMtm().InvokeAsyncFunctionL( |
|
254 ESmsMtmCommandCopyFromPhoneStore, |
|
255 *selection, pkg, iStatus ); |
|
256 } |
|
257 else |
|
258 { |
|
259 TBuf8<1> foo (KNullDesC8); |
|
260 iOperation = iSmsMtmUi.BaseMtm().InvokeAsyncFunctionL( |
|
261 ESmsMtmCommandDeleteFromPhoneStore, |
|
262 *selection, foo, iStatus); |
|
263 } |
|
264 |
|
265 CleanupStack::PopAndDestroy( selection ); |
|
266 SMUMLOGGER_LEAVEFN("CSimDeleteCopyOperation::MakeNextDeleteCopyL"); |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // CSimDeleteCopyOperation::DoCancel() |
|
271 // |
|
272 // --------------------------------------------------------------------------- |
|
273 void CSimDeleteCopyOperation::DoCancel() |
|
274 { |
|
275 #ifdef _DEBUG |
|
276 RDebug::Print(_L("CSimDeleteCopyOperation::DoCancel") ); |
|
277 #endif |
|
278 if (iOperation) |
|
279 { |
|
280 iOperation->Cancel(); |
|
281 } |
|
282 TRequestStatus* status = &iObserverRequestStatus; |
|
283 User::RequestComplete(status, iStatus.Int()); |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // CSimDeleteCopyOperation::CancelAfterCurrentCompleted() |
|
288 // |
|
289 // --------------------------------------------------------------------------- |
|
290 void CSimDeleteCopyOperation::CancelAfterCurrentCompleted() |
|
291 { |
|
292 iCanceling = ETrue; |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // CSimDeleteCopyOperation::RunL() |
|
297 // |
|
298 // --------------------------------------------------------------------------- |
|
299 void CSimDeleteCopyOperation::RunL() |
|
300 { |
|
301 SMUMLOGGER_ENTERFN("CSimDeleteCopyOperation::RunL"); |
|
302 // no error handling since we immediately try with |
|
303 // the next one |
|
304 |
|
305 iCurrentEntryIndex++; |
|
306 if ( iCurrentEntryIndex >= iEntrySelection->Count() ) |
|
307 { |
|
308 // nothing left to process, so complete the observer |
|
309 TRequestStatus* status = &iObserverRequestStatus; |
|
310 User::RequestComplete(status, iStatus.Int()); |
|
311 } |
|
312 else |
|
313 { |
|
314 // start the next pass |
|
315 DeleteCopyNext(); |
|
316 } |
|
317 SMUMLOGGER_LEAVEFN("CSimDeleteCopyOperation::RunL"); |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CSimDeleteCopyOperation::ProgressL() |
|
322 // |
|
323 // --------------------------------------------------------------------------- |
|
324 const TDesC8& CSimDeleteCopyOperation::ProgressL() |
|
325 { |
|
326 if (iOperation) |
|
327 return iOperation->ProgressL(); |
|
328 return iBlank; |
|
329 } |
|
330 |
|
331 |
|
332 // End of File |
|
333 |