|
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: Implementation of CPhoneNoteController class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cphonenotecontroller.h" |
|
21 |
|
22 #include <eikenv.h> |
|
23 #include <eikappui.h> |
|
24 #include <eikprogi.h> |
|
25 #include <StringLoader.h> |
|
26 #include <aknnotedialog.h> // for CAknNoteDialog |
|
27 #include <AknGlobalNote.h> // for CAknGlobalNote |
|
28 |
|
29 #include "phoneui.pan" |
|
30 #include "tphonecommandparam.h" |
|
31 #include "tphonecmdparamnote.h" |
|
32 #include "tphonecmdparamboolean.h" |
|
33 #include "tphonecmdparamprogressnote.h" |
|
34 #include "tphonecmdparamglobalnote.h" |
|
35 #include "tphonecmdparaminteger.h" |
|
36 #include "phoneconstants.h" |
|
37 #include "cphonemainresourceresolver.h" |
|
38 #include "phonerssbase.h" |
|
39 #include "phonelogger.h" |
|
40 #include "cphonetimer.h" |
|
41 #include "cphonenote.h" |
|
42 #include "cphonedtmfsendingnote.h" |
|
43 |
|
44 // CONSTANTS |
|
45 const TInt KPhoneIntervalDivider = 100; |
|
46 // ================= MEMBER FUNCTIONS ======================= |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // |
|
50 CPhoneNoteController::CPhoneNoteController( CEikonEnv& aEikEnv ) : iGlobalNoteId( KErrNotFound ), |
|
51 iEikEnv( aEikEnv ), |
|
52 iNoteText( NULL ) |
|
53 { |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CPhoneNoteController::NewL() |
|
58 // Two-phased constructor |
|
59 // (other items were commented in a header). |
|
60 // --------------------------------------------------------- |
|
61 CPhoneNoteController* CPhoneNoteController::NewL( CEikonEnv& aEikEnv ) |
|
62 { |
|
63 CPhoneNoteController* self = |
|
64 new( ELeave ) CPhoneNoteController( aEikEnv ); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // Destructor |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 CPhoneNoteController::~CPhoneNoteController() |
|
74 { |
|
75 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::~CPhoneNoteController"); |
|
76 DestroyNote(); |
|
77 DestroyProgressNote(); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CPhoneNoteController::CreateNoteL |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 void CPhoneNoteController::CreateNoteL( |
|
85 TPhoneCommandParam* aCommandParam ) |
|
86 { |
|
87 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::CreateNoteL"); |
|
88 TInt resourceId = 0; |
|
89 CAknNoteDialog::TTone tone = CAknNoteDialog::ENoTone; |
|
90 CAknNoteDialog::TTimeout timeout = CAknNoteDialog::ENoTimeout; |
|
91 |
|
92 TPhoneCmdParamNote* noteParam = static_cast<TPhoneCmdParamNote*>( |
|
93 aCommandParam ); |
|
94 |
|
95 if( iNote && noteParam->Type() == EPhoneNoteDtmfSending ) |
|
96 { |
|
97 // Dtmf sending ongoing. |
|
98 UpdateNoteTextL( aCommandParam ); |
|
99 return; |
|
100 } |
|
101 |
|
102 // Delete the existing note |
|
103 DestroyNote(); |
|
104 |
|
105 // Setup parameters according to the type of note |
|
106 switch ( noteParam->Type() ) |
|
107 { |
|
108 case EPhoneNoteError: |
|
109 resourceId = CPhoneMainResourceResolver::Instance()-> |
|
110 ResolveResourceID( EPhoneInformationErrorNote ); |
|
111 timeout = CAknNoteDialog::ELongTimeout; |
|
112 tone = CAknNoteDialog::EErrorTone; |
|
113 break; |
|
114 |
|
115 case EPhoneNoteWarning: |
|
116 resourceId = CPhoneMainResourceResolver::Instance()-> |
|
117 ResolveResourceID( EPhoneInformationWarningNote ); |
|
118 timeout = CAknNoteDialog::ELongTimeout; |
|
119 tone = CAknNoteDialog::EWarningTone; |
|
120 break; |
|
121 |
|
122 case EPhoneNoteConfirmation: |
|
123 resourceId = CPhoneMainResourceResolver::Instance()-> |
|
124 ResolveResourceID( EPhoneInformationConfirmationNote ); |
|
125 timeout = CAknNoteDialog::EShortTimeout; |
|
126 tone = CAknNoteDialog::EConfirmationTone; |
|
127 break; |
|
128 |
|
129 case EPhoneNoteInformation: |
|
130 resourceId = CPhoneMainResourceResolver::Instance()-> |
|
131 ResolveResourceID( EPhoneInformationNote ); |
|
132 timeout = CAknNoteDialog::ELongTimeout; |
|
133 tone = CAknNoteDialog::ENoTone; |
|
134 break; |
|
135 |
|
136 case EPhoneNoteSecurity: |
|
137 case EPhoneNoteCustom: // Fall through |
|
138 case EPhoneNotePermanent: |
|
139 case EPhoneNoteDtmfSending: |
|
140 // Use the specified values |
|
141 resourceId = noteParam->ResourceId(); |
|
142 timeout = noteParam->Timeout(); |
|
143 tone = noteParam->Tone(); |
|
144 break; |
|
145 |
|
146 default: |
|
147 Panic( EPhoneViewCaseNotHandled ); |
|
148 break; |
|
149 } |
|
150 |
|
151 // Create correct note |
|
152 if( noteParam->Type() == EPhoneNoteDtmfSending ) |
|
153 { |
|
154 iNote = new ( ELeave ) CPhoneDtmfSendingNote( reinterpret_cast<CEikDialog**>( &iNote ), *iEikEnv.EikAppUi() ); |
|
155 } |
|
156 else |
|
157 { |
|
158 iNote = new ( ELeave ) CPhoneNote( reinterpret_cast<CEikDialog**>( &iNote ), *iEikEnv.EikAppUi() ); |
|
159 } |
|
160 |
|
161 // Override text if specified |
|
162 if ( noteParam->Text().Length() ) |
|
163 { |
|
164 if( !iNoteText ) |
|
165 { |
|
166 iNoteText = noteParam->Text().AllocL(); |
|
167 } |
|
168 iNote->SetTextL( *iNoteText ); |
|
169 } |
|
170 else if ( noteParam->TextResourceId() ) |
|
171 { |
|
172 // Get the text associated with the resource Id |
|
173 TBuf<KPhoneMaxCharsInNote> noteText; |
|
174 StringLoader::Load( |
|
175 noteText, |
|
176 noteParam->TextResourceId(), |
|
177 &iEikEnv ); |
|
178 |
|
179 iNote->SetTextL( noteText ); |
|
180 } |
|
181 |
|
182 // Override tone if specified |
|
183 if ( tone != CAknNoteDialog::ENoTone ) |
|
184 { |
|
185 iNote->SetTone( tone ); |
|
186 } |
|
187 |
|
188 // Override timeout if specified |
|
189 if ( timeout != CAknNoteDialog::ENoTimeout ) |
|
190 { |
|
191 iNote->SetTimeout( timeout ); |
|
192 } |
|
193 |
|
194 iNote->SetNoteType( noteParam->Type() ); |
|
195 |
|
196 // Display the note |
|
197 iNote->ExecuteLD( resourceId ); |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------- |
|
201 // CPhoneNoteController::DestroyNote |
|
202 // --------------------------------------------------------- |
|
203 // |
|
204 void CPhoneNoteController::DestroyNote() |
|
205 { |
|
206 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::DestroyNote"); |
|
207 |
|
208 // Delete note text if exists |
|
209 if( iNoteText ) |
|
210 { |
|
211 delete iNoteText; |
|
212 iNoteText = NULL; |
|
213 } |
|
214 |
|
215 // Delete the note if it exists |
|
216 if ( iNote ) |
|
217 { |
|
218 delete iNote; |
|
219 iNote = NULL; |
|
220 } |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CPhoneNoteController::DestroyDTMFNote |
|
225 // --------------------------------------------------------- |
|
226 // |
|
227 void CPhoneNoteController::DestroyDTMFNote() |
|
228 { |
|
229 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::DestroyDTMFNote"); |
|
230 |
|
231 // Delete DTFM note if exists |
|
232 if ( iNote && ( iNote->NoteType() == EPhoneNoteDtmfSending ) ) |
|
233 { |
|
234 // Delete note text if exists |
|
235 if( iNoteText ) |
|
236 { |
|
237 delete iNoteText; |
|
238 iNoteText = NULL; |
|
239 } |
|
240 delete iNote; |
|
241 iNote = NULL; |
|
242 } |
|
243 } |
|
244 |
|
245 |
|
246 // --------------------------------------------------------- |
|
247 // CPhoneNoteController::DestroyGlobalNoteL |
|
248 // --------------------------------------------------------- |
|
249 // |
|
250 void CPhoneNoteController::DestroyGlobalNoteL() |
|
251 { |
|
252 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::DestroyGlobalNoteL"); |
|
253 if( iGlobalNoteId != KErrNotFound ) |
|
254 { |
|
255 CAknGlobalNote* glbNote = CAknGlobalNote::NewLC(); |
|
256 glbNote->CancelNoteL( iGlobalNoteId ); |
|
257 CleanupStack::PopAndDestroy( glbNote ); |
|
258 } |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------- |
|
262 // CPhoneNoteController::CreateGlobalNoteL |
|
263 // --------------------------------------------------------- |
|
264 // |
|
265 void CPhoneNoteController::CreateGlobalNoteL( |
|
266 TPhoneCommandParam* aCommandParam ) |
|
267 { |
|
268 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::CreateGlobalNoteL"); |
|
269 TPhoneCmdParamGlobalNote* globalNoteParam = |
|
270 static_cast<TPhoneCmdParamGlobalNote*>( aCommandParam ); |
|
271 TBuf<KPhoneMaxCharsInNote> noteText; |
|
272 |
|
273 // Check if the resource Id is specified |
|
274 if ( globalNoteParam->TextResourceId() ) |
|
275 { |
|
276 if ( globalNoteParam->Text().Length() ) |
|
277 { |
|
278 HBufC* loadedText = StringLoader::LoadL( |
|
279 globalNoteParam->TextResourceId(), |
|
280 globalNoteParam->Text(), |
|
281 CCoeEnv::Static() ); |
|
282 noteText.Copy( *loadedText ); |
|
283 delete loadedText; |
|
284 } |
|
285 else |
|
286 { |
|
287 StringLoader::Load( |
|
288 noteText, |
|
289 globalNoteParam->TextResourceId(), |
|
290 &iEikEnv ); |
|
291 } |
|
292 } |
|
293 else if ( globalNoteParam->Text() != KNullDesC ) |
|
294 { |
|
295 noteText.Copy( globalNoteParam->Text() ); |
|
296 } |
|
297 |
|
298 if ( noteText.Length() > 0 ) |
|
299 { |
|
300 CAknGlobalNote* glbNote = CAknGlobalNote::NewLC(); |
|
301 |
|
302 // Set the tone |
|
303 glbNote->SetTone( globalNoteParam->Tone() ); |
|
304 if ( globalNoteParam->Softkeys()) |
|
305 { |
|
306 glbNote->SetSoftkeys( globalNoteParam->Softkeys() ); |
|
307 } |
|
308 |
|
309 // Show the global note |
|
310 |
|
311 if ( globalNoteParam->WaitForReady() ) |
|
312 { |
|
313 TRequestStatus NoteReady; |
|
314 iGlobalNoteId = glbNote->ShowNoteL( NoteReady, globalNoteParam->Type(), noteText ); |
|
315 User::WaitForRequest( NoteReady ); |
|
316 } |
|
317 else |
|
318 { |
|
319 iGlobalNoteId = glbNote->ShowNoteL( globalNoteParam->Type(), noteText ); |
|
320 } |
|
321 CleanupStack::PopAndDestroy( glbNote ); |
|
322 } |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------- |
|
326 // CPhoneNoteController::CreateProgressNoteL |
|
327 // --------------------------------------------------------- |
|
328 // |
|
329 void CPhoneNoteController::CreateProgressNoteL( |
|
330 TPhoneCommandParam* aCommandParam ) |
|
331 { |
|
332 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::CreateProgressNoteL"); |
|
333 TPhoneCmdParamProgressNote* noteParam = static_cast< |
|
334 TPhoneCmdParamProgressNote*>(aCommandParam ); |
|
335 |
|
336 TInt resourceId = noteParam->ResourceId(); |
|
337 iStartTime.UniversalTime(); |
|
338 |
|
339 TTimeIntervalMicroSeconds32 waitTime = |
|
340 noteParam->WaitTime(); |
|
341 |
|
342 if( !iProgressUpdateTimer ) |
|
343 { |
|
344 iProgressUpdateTimer = CPhoneTimer::NewL(); |
|
345 } |
|
346 |
|
347 iWaitTime = waitTime.Int(); |
|
348 |
|
349 TInt final = waitTime.Int(); |
|
350 iInterval = final / KPhoneIntervalDivider; |
|
351 iProgressBarCount = 0; |
|
352 |
|
353 iProgressUpdateTimer->After( iInterval, this ); |
|
354 |
|
355 CPhoneProgressNote* dlg = |
|
356 new ( ELeave ) CPhoneProgressNote( |
|
357 ( reinterpret_cast< CEikDialog** >( &iProgressNote )), |
|
358 static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() ) ); |
|
359 |
|
360 iProgressNote = dlg; |
|
361 dlg->PrepareLC( resourceId ); |
|
362 |
|
363 CEikProgressInfo* info = dlg->GetProgressInfoL(); |
|
364 |
|
365 if ( info ) |
|
366 { |
|
367 info->SetFinalValue( KPhoneIntervalDivider ); |
|
368 } |
|
369 |
|
370 dlg->RunLD(); |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------- |
|
374 // CPhoneNoteController::DestroyProgressBar |
|
375 // --------------------------------------------------------- |
|
376 // |
|
377 void CPhoneNoteController::DestroyProgressNote() |
|
378 { |
|
379 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::DestroyProgressNote"); |
|
380 |
|
381 // Delete the progress note if it exists |
|
382 if ( iProgressNote ) |
|
383 { |
|
384 delete iProgressNote; |
|
385 iProgressNote = NULL; |
|
386 } |
|
387 if ( iProgressUpdateTimer ) |
|
388 { |
|
389 if( iProgressUpdateTimer->IsActive() ) |
|
390 { |
|
391 iProgressUpdateTimer->CancelTimer(); |
|
392 } |
|
393 |
|
394 delete iProgressUpdateTimer; |
|
395 iProgressUpdateTimer = NULL; |
|
396 } |
|
397 iProgressBarCount = 0; |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------- |
|
401 // CPhoneNoteController::HandleTimeOutL |
|
402 // --------------------------------------------------------- |
|
403 // |
|
404 void CPhoneNoteController::HandleTimeOutL() |
|
405 { |
|
406 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::HandleTimeOutL"); |
|
407 |
|
408 if ( iProgressNote ) |
|
409 { |
|
410 TTime current; |
|
411 current.UniversalTime(); |
|
412 |
|
413 CEikProgressInfo* info = iProgressNote->GetProgressInfoL(); |
|
414 |
|
415 if ( info ) |
|
416 { |
|
417 TTime current; |
|
418 current.UniversalTime(); |
|
419 TInt64 timeDelta = |
|
420 current.MicroSecondsFrom( iStartTime ).Int64(); |
|
421 |
|
422 iProgressBarCount = ( timeDelta / iInterval )+1 ; |
|
423 if ( iProgressBarCount > KPhoneIntervalDivider ) |
|
424 { |
|
425 iProgressBarCount = KPhoneIntervalDivider; |
|
426 } |
|
427 info->SetAndDraw( iProgressBarCount ); |
|
428 } |
|
429 |
|
430 if ( !iProgressUpdateTimer->IsActive() ) |
|
431 { |
|
432 iProgressUpdateTimer->After( iInterval, this ); |
|
433 } |
|
434 } |
|
435 else |
|
436 { |
|
437 if( iProgressUpdateTimer->IsActive() ) |
|
438 { |
|
439 iProgressUpdateTimer->CancelTimer(); |
|
440 } |
|
441 |
|
442 delete iProgressUpdateTimer; |
|
443 iProgressUpdateTimer = NULL; |
|
444 iProgressBarCount = 0; |
|
445 } |
|
446 } |
|
447 |
|
448 // --------------------------------------------------------- |
|
449 // CPhoneNoteController::IsNoteVisible |
|
450 // --------------------------------------------------------- |
|
451 // |
|
452 void CPhoneNoteController::IsNoteVisible( TPhoneCommandParam* aCommandParam ) |
|
453 { |
|
454 __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneNoteController::IsNoteVisible"); |
|
455 |
|
456 TPhoneCmdParamBoolean* booleanParam = |
|
457 static_cast<TPhoneCmdParamBoolean*>( aCommandParam ); |
|
458 |
|
459 if( iNote ) |
|
460 { |
|
461 if( iNote->IsVisible() ) |
|
462 { |
|
463 booleanParam->SetBoolean( ETrue ); |
|
464 } |
|
465 } |
|
466 else |
|
467 { |
|
468 booleanParam->SetBoolean( EFalse ); |
|
469 } |
|
470 } |
|
471 |
|
472 // --------------------------------------------------------- |
|
473 // CPhoneNoteController::IsProgressNoteVisible |
|
474 // --------------------------------------------------------- |
|
475 // |
|
476 void CPhoneNoteController::IsProgressNoteVisible( TPhoneCommandParam* aCommandParam ) |
|
477 { |
|
478 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneNoteController::IsProgressNoteVisible"); |
|
479 |
|
480 TPhoneCmdParamBoolean* booleanParam = |
|
481 static_cast<TPhoneCmdParamBoolean*>( aCommandParam ); |
|
482 |
|
483 if( iProgressNote ) |
|
484 { |
|
485 if( iProgressNote->IsVisible() ) |
|
486 { |
|
487 booleanParam->SetBoolean( ETrue ); |
|
488 } |
|
489 } |
|
490 else |
|
491 { |
|
492 booleanParam->SetBoolean( EFalse ); |
|
493 } |
|
494 } |
|
495 |
|
496 // --------------------------------------------------------- |
|
497 // CPhoneNoteController::IsNoteActive |
|
498 // --------------------------------------------------------- |
|
499 // |
|
500 void CPhoneNoteController::IsNoteActive( TPhoneCommandParam* aCommandParam ) |
|
501 { |
|
502 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneNoteController::IsNote"); |
|
503 |
|
504 TPhoneCmdParamBoolean* booleanParam = |
|
505 static_cast<TPhoneCmdParamBoolean*>( aCommandParam ); |
|
506 |
|
507 if( iProgressNote || iNote ) |
|
508 { |
|
509 booleanParam->SetBoolean( ETrue ); |
|
510 } |
|
511 else |
|
512 { |
|
513 booleanParam->SetBoolean( EFalse ); |
|
514 } |
|
515 } |
|
516 |
|
517 // --------------------------------------------------------- |
|
518 // CPhoneNoteController::IsActiveNoteDissmissableByKeyEvent |
|
519 // --------------------------------------------------------- |
|
520 // |
|
521 void CPhoneNoteController::IsActiveNoteDissmissableByKeyEvent( TPhoneCommandParam* aCommandParam ) |
|
522 { |
|
523 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneNoteController::IsActiveNoteDissmissableByKeyEvent"); |
|
524 |
|
525 TPhoneCmdParamBoolean* booleanParam = |
|
526 static_cast<TPhoneCmdParamBoolean*>( aCommandParam ); |
|
527 // check first that iNote is created. |
|
528 if( ( iNote ) && |
|
529 ( iNote->NoteType() == EPhoneNoteSecurity ) ) |
|
530 { |
|
531 booleanParam->SetBoolean( ETrue ); |
|
532 } |
|
533 else |
|
534 { |
|
535 booleanParam->SetBoolean( EFalse ); |
|
536 } |
|
537 } |
|
538 |
|
539 // --------------------------------------------------------- |
|
540 // CPhoneNoteController::UpdateNoteTextL |
|
541 // --------------------------------------------------------- |
|
542 // |
|
543 void CPhoneNoteController::UpdateNoteTextL( TPhoneCommandParam* aCommandParam ) |
|
544 { |
|
545 TPhoneCmdParamNote* noteParam = static_cast<TPhoneCmdParamNote*>( |
|
546 aCommandParam ); |
|
547 |
|
548 // Delete note text if exists |
|
549 if( iNoteText ) |
|
550 { |
|
551 delete iNoteText; |
|
552 iNoteText = NULL; |
|
553 } |
|
554 |
|
555 if ( iNote ) |
|
556 { |
|
557 // Override text if specified |
|
558 if ( noteParam->Text().Length() ) |
|
559 { |
|
560 if( !iNoteText ) |
|
561 { |
|
562 iNoteText = noteParam->Text().Alloc(); |
|
563 } |
|
564 iNote->SetTextL( *iNoteText ); |
|
565 } |
|
566 else if ( noteParam->TextResourceId() ) |
|
567 { |
|
568 // Get the text associated with the resource Id |
|
569 TBuf<KPhoneMaxCharsInNote> noteText; |
|
570 StringLoader::Load( |
|
571 noteText, |
|
572 noteParam->TextResourceId(), |
|
573 &iEikEnv ); |
|
574 |
|
575 iNote->SetTextL( noteText ); |
|
576 } |
|
577 } |
|
578 } |
|
579 |
|
580 // --------------------------------------------------------- |
|
581 // CPhoneNoteController::UpdateNoteSoftkeysL |
|
582 // --------------------------------------------------------- |
|
583 // |
|
584 void CPhoneNoteController::UpdateNoteSoftkeysL( TPhoneCommandParam* aCommandParam ) |
|
585 { |
|
586 |
|
587 TPhoneCmdParamInteger* integerParam = |
|
588 static_cast<TPhoneCmdParamInteger*>( aCommandParam ); |
|
589 |
|
590 if ( iNote ) |
|
591 { |
|
592 iNote->UpdateSoftkeysL( integerParam->Integer() ); |
|
593 } |
|
594 } |
|
595 |
|
596 // End of File |