|
1 /* |
|
2 * Copyright (c) 2005 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: Methods for CNSmlDMProgressDialog. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "NSmlDMSyncAppUi.h" |
|
21 #include "NSmlDMProgress.h" |
|
22 #include "NSmlDMSyncUtil.h" |
|
23 #include "NSmlDMSyncDebug.h" |
|
24 #include <NSmlDMSync.rsg> |
|
25 #include <StringLoader.h> |
|
26 #include <eikprogi.h> |
|
27 #include <notecontrol.h> |
|
28 #include <AknsUtils.h> |
|
29 #include <aknappui.h> |
|
30 #include "NSmlDMSyncUi.hrh" |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CNSmlDMProgressDialog::CNSmlDMProgressDialog |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CNSmlDMProgressDialog::CNSmlDMProgressDialog( |
|
40 MNSmlDMProgressDialogObserver* aObserver ) |
|
41 : iObserver( aObserver ) |
|
42 { |
|
43 FLOG( "CNSmlDMProgressDialog: CNSmlDMProgressDialog" ); |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CNSmlDMProgressDialog::NewL |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CNSmlDMProgressDialog* CNSmlDMProgressDialog::NewL( |
|
51 MNSmlDMProgressDialogObserver* aObserver ) |
|
52 { |
|
53 FLOG( "CNSmlDMProgressDialog::NewL" ); |
|
54 |
|
55 CNSmlDMProgressDialog* self = |
|
56 new ( ELeave ) CNSmlDMProgressDialog( aObserver ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop(); |
|
60 |
|
61 FLOG( "CNSmlDMProgressDialog::NewL completed" ); |
|
62 return(self); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CNSmlDMProgressDialog::ConstructL |
|
67 // |
|
68 // Symbian OS default constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CNSmlDMProgressDialog::ConstructL() |
|
72 { |
|
73 FLOG( "CNSmlDMProgressDialog::ConstructL" ); |
|
74 |
|
75 iLastText = KNullDesC; |
|
76 iAnimation = EAnimationNone; |
|
77 iEventCount = 0; |
|
78 |
|
79 FLOG( "CNSmlDMProgressDialog::ConstructL completed" ); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // Destructor |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CNSmlDMProgressDialog::~CNSmlDMProgressDialog() |
|
87 { |
|
88 FLOG( "CNSmlDMProgressDialog::~CNSmlDMProgressDialog" ); |
|
89 |
|
90 delete iProgressDialog; |
|
91 |
|
92 FLOG( "CNSmlDMProgressDialog::~CNSmlDMProgressDialog completed" ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CNSmlDMProgressDialog::LaunchProgressDialogL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CNSmlDMProgressDialog::LaunchProgressDialogL( const TDesC& aLabel) |
|
100 { |
|
101 FLOG( "CNSmlDMProgressDialog::LaunchProgressDialogL" ); |
|
102 |
|
103 iProgressDialog = new( ELeave ) CNSmlDMProgressDialog2( |
|
104 reinterpret_cast<CEikDialog**>(&iProgressDialog)); |
|
105 |
|
106 iProgressDialog->PrepareLC( R_PROGRESS_NOTE ); |
|
107 iProgressDialog->SetTextL(aLabel); |
|
108 |
|
109 // get reference to progress info bar |
|
110 iProgressInfo = iProgressDialog->GetProgressInfoL(); |
|
111 iProgressDialog->SetCallback(this); |
|
112 |
|
113 iProgressDialog->RunLD(); |
|
114 |
|
115 FLOG( "CNSmlDMProgressDialog::LaunchProgressDialogL completed" ); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CNSmlDMProgressDialog::LaunchProgressDialogL |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CNSmlDMProgressDialog::LaunchProgressDialogL( const TDesC& aLabel, |
|
123 TAknsItemID aId, |
|
124 const TDesC& aFileName, |
|
125 TInt aFileBitmapId, |
|
126 TInt aFileMaskId ) |
|
127 { |
|
128 FLOG( "CNSmlDMProgressDialog::LaunchProgressDialogL" ); |
|
129 |
|
130 iProgressDialog = new( ELeave ) CNSmlDMProgressDialog2( |
|
131 reinterpret_cast<CEikDialog**>(&iProgressDialog)); |
|
132 |
|
133 iProgressDialog->PrepareLC( R_PROGRESS_NOTE ); |
|
134 iProgressDialog->SetTextL(aLabel); |
|
135 |
|
136 CEikImage* image = CreateImageLC( aId, |
|
137 aFileName, |
|
138 aFileBitmapId, |
|
139 aFileMaskId ); |
|
140 iProgressDialog->SetImageL(image); |
|
141 CleanupStack::Pop(image); |
|
142 |
|
143 // get reference to progress info bar |
|
144 iProgressInfo = iProgressDialog->GetProgressInfoL(); |
|
145 iProgressDialog->SetCallback(this); |
|
146 |
|
147 iProgressDialog->RunLD(); |
|
148 |
|
149 FLOG( "CNSmlDMProgressDialog::LaunchProgressDialogL completed" ); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CNSmlDMProgressDialog::CancelProgressDialogL |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CNSmlDMProgressDialog::CancelProgressDialogL() |
|
157 { |
|
158 FLOG( "CNSmlDMProgressDialog::CancelProgressDialogL" ); |
|
159 |
|
160 if( iProgressDialog ) |
|
161 { |
|
162 iProgressDialog->ProcessFinishedL(); |
|
163 } |
|
164 |
|
165 FLOG( "CNSmlDMProgressDialog::CancelProgressDialogL completed" ); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CNSmlDMProgressDialog::UpdateTextL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CNSmlDMProgressDialog::UpdateTextL(TInt /*aResId*/) |
|
173 { |
|
174 FLOG( "CNSmlDMProgressDialog::UpdateTextL " ); |
|
175 |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CNSmlDMProgressDialog::UpdateTextL |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CNSmlDMProgressDialog::UpdateTextL(const TDesC& aText) |
|
183 { |
|
184 FLOG( "CNSmlDMProgressDialog::UpdateTextL ( const TDesC& aText )" ); |
|
185 |
|
186 __ASSERT_DEBUG(iProgressDialog, TUtil::Panic(KErrGeneral)); |
|
187 |
|
188 if (iLastText.Compare(aText) == 0) |
|
189 { |
|
190 return; // text has not changed |
|
191 } |
|
192 |
|
193 iProgressDialog->SetTextL( aText ); |
|
194 TUtil::StrCopy(iLastText, aText); |
|
195 |
|
196 FLOG( "CNSmlDMProgressDialog::UpdateTextL ( const TDesC& aText )completed" ); |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CNSmlDMProgressDialog::SetProgress |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CNSmlDMProgressDialog::SetProgress(TInt aValue) |
|
204 { |
|
205 FLOG( "CNSmlDMProgressDialog::SetProgress" ); |
|
206 |
|
207 __ASSERT_DEBUG(iProgressDialog && iProgressInfo, TUtil::Panic(KErrGeneral)); |
|
208 |
|
209 CEikProgressInfo::SInfo info = iProgressInfo->Info(); |
|
210 |
|
211 TInt val = aValue; |
|
212 if (val > info.iFinalValue) |
|
213 { |
|
214 val = info.iFinalValue; |
|
215 } |
|
216 iProgressInfo->SetAndDraw(val); |
|
217 |
|
218 FLOG( "CNSmlDMProgressDialog::SetProgress completed" ); |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CNSmlDMProgressDialog::SetFinalProgress |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CNSmlDMProgressDialog::SetFinalProgress(TInt aFinalValue) |
|
226 { |
|
227 FLOG( "CNSmlDMProgressDialog::SetFinalProgress" ); |
|
228 |
|
229 __ASSERT_DEBUG(iProgressInfo, TUtil::Panic(KErrGeneral)); |
|
230 |
|
231 iProgressInfo->SetFinalValue(aFinalValue); |
|
232 iProgressInfo->SetAndDraw(0); |
|
233 |
|
234 FLOG( "CNSmlDMProgressDialog::SetFinalProgress completed" ); |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CNSmlDMProgressDialog::NoteControl |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 CAknNoteControl* CNSmlDMProgressDialog::NoteControl() |
|
242 { |
|
243 FLOG( "CNSmlDMProgressDialog::NoteControl" ); |
|
244 |
|
245 CAknNoteControl* note = STATIC_CAST( |
|
246 CAknNoteControl*, |
|
247 iProgressDialog->ControlOrNull(ENSmlProgressNote) ); |
|
248 __ASSERT_DEBUG( note, TUtil::Panic( KErrGeneral ) ); |
|
249 |
|
250 return note; |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CNSmlDMProgressDialog::CancelAnimation |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CNSmlDMProgressDialog::CancelAnimation() |
|
258 { |
|
259 NoteControl()->CancelAnimation(); |
|
260 } |
|
261 |
|
262 // ---------------------------------------------------------------------------- |
|
263 // CNSmlDMProgressDialog::StartAnimationL |
|
264 // ---------------------------------------------------------------------------- |
|
265 // |
|
266 void CNSmlDMProgressDialog::StartAnimationL() |
|
267 { |
|
268 NoteControl()->StartAnimationL(); |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CNSmlDMProgressDialog::DialogDismissedL |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CNSmlDMProgressDialog::DialogDismissedL( TInt aButtonId ) |
|
276 { |
|
277 FLOG( "CNSmlDMProgressDialog::DialogDismissedL " ); |
|
278 |
|
279 if ( iObserver ) |
|
280 { |
|
281 // this dialog only sends one cancel event - other events are ignored |
|
282 if ( aButtonId == EEikBidCancel && iEventCount == 0 ) |
|
283 { |
|
284 iEventCount++; |
|
285 TRAP_IGNORE( iObserver->HandleDialogEventL( aButtonId ) ); |
|
286 } |
|
287 } |
|
288 FLOG( "CNSmlDMProgressDialog::DialogDismissedL Completed" ); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CNSmlDMProgressDialog::ReadL |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 void CNSmlDMProgressDialog::ReadL( TDes& aText, TInt aResourceId ) |
|
296 { |
|
297 HBufC* buf = StringLoader::LoadLC( aResourceId ); |
|
298 TUtil::StrCopy( aText, *buf ); |
|
299 CleanupStack::PopAndDestroy( buf ); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CNSmlDMProgressDialog::CreateImageLC |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 CEikImage* CNSmlDMProgressDialog::CreateImageLC( TAknsItemID aId, |
|
307 const TDesC& aFileName, |
|
308 TInt aFileBitmapId, |
|
309 TInt aFileMaskId ) |
|
310 { |
|
311 CFbsBitmap* bitmap1 = NULL; |
|
312 CFbsBitmap* bitmap2 = NULL; |
|
313 |
|
314 CEikImage* image = new (ELeave) CEikImage; |
|
315 CleanupStack::PushL(image); |
|
316 |
|
317 AknsUtils::CreateIconLC( AknsUtils::SkinInstance(), |
|
318 aId, |
|
319 bitmap1, |
|
320 bitmap2, |
|
321 aFileName, |
|
322 aFileBitmapId, |
|
323 aFileMaskId ); |
|
324 image->SetPicture( bitmap1, bitmap2 ); |
|
325 CleanupStack::Pop(2); // bitmap1 bitmap2 |
|
326 |
|
327 return image; |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CNSmlDMProgressDialog::CNSmlDMProgressDialog2 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 void CNSmlDMProgressDialog::SetImageL(CEikImage* aimage) |
|
335 { |
|
336 NoteControl()->SetImageL(aimage); |
|
337 } |
|
338 |
|
339 /****************************************************************************** |
|
340 * class CAknProgressDialog2 |
|
341 ******************************************************************************/ |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CNSmlDMProgressDialog2::CNSmlDMProgressDialog2 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 CNSmlDMProgressDialog2::CNSmlDMProgressDialog2( CEikDialog** aSelfPtr ) |
|
348 : CAknProgressDialog( aSelfPtr ) |
|
349 { |
|
350 iCloseEventReceived = EFalse; |
|
351 iClosed = EFalse; |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CNSmlDMProgressDialog2::OkToExitL |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 TBool CNSmlDMProgressDialog2::OkToExitL(TInt aButtonId) |
|
359 { |
|
360 if ( iCloseEventReceived ) |
|
361 { |
|
362 if (iCallback && !iClosed) |
|
363 { |
|
364 TRAP_IGNORE(iCallback->DialogDismissedL(EKeyPhoneEnd)); |
|
365 STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi() )->ExitCallL(); |
|
366 FLOG("CNSmlDMProgressDialog2::OkToExitL: close handling done"); |
|
367 } |
|
368 |
|
369 if (iAvkonAppUi) |
|
370 { |
|
371 // prevent further close events |
|
372 iAvkonAppUi->RemoveFromStack(this); |
|
373 } |
|
374 |
|
375 FLOG( "CNSmlDMProgressDialog2::OkToExitL END" ); |
|
376 |
|
377 iClosed = ETrue; |
|
378 return ETrue; |
|
379 } |
|
380 |
|
381 if (aButtonId == EEikBidCancel && iCallback) |
|
382 { |
|
383 iCallback->DialogDismissedL(aButtonId); |
|
384 return EFalse; // leave dialog open - let observer close it |
|
385 } |
|
386 |
|
387 return CAknProgressDialog::OkToExitL(aButtonId); |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CNSmlDMProgressDialog2::OfferKeyEventL |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 TKeyResponse CNSmlDMProgressDialog2::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
395 { |
|
396 FLOG("CNSmlDMProgressDialog2::OfferKeyEventL START"); |
|
397 |
|
398 if (aType == EEventKey) |
|
399 { |
|
400 switch (aKeyEvent.iCode) |
|
401 { |
|
402 |
|
403 case EKeyEscape: // iCode 27 (0x1b) |
|
404 { |
|
405 iCloseEventReceived = ETrue; |
|
406 FLOG( "CNSmlDMProgressDialog2::OfferKeyEventL: EKeyEscape received" ); |
|
407 break; |
|
408 } |
|
409 |
|
410 case EKeyPhoneEnd: |
|
411 { |
|
412 iCloseEventReceived = ETrue; |
|
413 FLOG( "CNSmlDMProgressDialog2::OfferKeyEventL: EKeyPhoneEnd received" ); |
|
414 break; |
|
415 } |
|
416 |
|
417 default: |
|
418 FLOG( "event key code is %d" ); |
|
419 break; |
|
420 } |
|
421 } |
|
422 |
|
423 |
|
424 FLOG( "CNSmlDMProgressDialog2::OfferKeyEventL END" ); |
|
425 |
|
426 return CAknProgressDialog::OfferKeyEventL(aKeyEvent, aType); |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // CNSmlDMProgressDialog2::RunLD |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 TInt CNSmlDMProgressDialog2::RunLD() |
|
434 { |
|
435 CNSmlDMSyncAppUi* appUi = STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi()); |
|
436 CNSmlDMSyncDocument* doc = STATIC_CAST( CNSmlDMSyncDocument*, appUi->Document() ); |
|
437 if ( doc->SANSupport() && doc->SilentSession() ) //to suppress backlight |
|
438 { |
|
439 return CEikDialog::RunLD(); |
|
440 } |
|
441 |
|
442 else //for User initated and all alerts except silent |
|
443 { |
|
444 return CAknNoteDialog::RunLD(); |
|
445 } |
|
446 |
|
447 } |
|
448 |
|
449 // ----------------------------------------------------------------------------- |
|
450 // CNSmlDMProgressDialog2::ProcessFinishedL |
|
451 // ----------------------------------------------------------------------------- |
|
452 // |
|
453 void CNSmlDMProgressDialog2::ProcessFinishedL() |
|
454 { |
|
455 CNSmlDMSyncAppUi* appUi = STATIC_CAST( CNSmlDMSyncAppUi*, iEikonEnv->EikAppUi()); |
|
456 CNSmlDMSyncDocument* doc = STATIC_CAST( CNSmlDMSyncDocument*, appUi->Document() ); |
|
457 if ( doc->SANSupport() && doc->SilentSession() ) //to suppress backlight |
|
458 { |
|
459 switch ( iState ) |
|
460 { |
|
461 case EProcessOnDisplayOff: |
|
462 case EProcessOnDisplayOnCanBeDismissed: |
|
463 iState = EProcessOffDisplayOff; |
|
464 delete iProgressDialogTimer; |
|
465 iProgressDialogTimer = NULL; |
|
466 //ReportUserActivity(); |
|
467 //PlayTone(); |
|
468 TryExitL( EAknSoftkeyDone ); |
|
469 break; |
|
470 case EProcessOnDisplayOn: |
|
471 iState = EProcessOffDisplayOn; |
|
472 break; |
|
473 default: |
|
474 break; |
|
475 } |
|
476 } |
|
477 else //for User initated and all alerts except silent |
|
478 { |
|
479 CAknProgressDialog::ProcessFinishedL(); |
|
480 } |
|
481 } |
|
482 // End of File |