|
1 /* |
|
2 * Copyright (c) 2005-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: Implementation of CPhoneAudioController class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <aknnavi.h> |
|
21 #include <aknnavide.h> |
|
22 #include <StringLoader.h> |
|
23 #include <avkon.rsg> |
|
24 #include <phoneui.rsg> |
|
25 #include <telephonyvariant.hrh> |
|
26 #include <eikenv.h> |
|
27 #include <eikappui.h> |
|
28 #include <AknUtils.h> |
|
29 #include "cphoneaudiocontroller.h" |
|
30 #include "cphonerecoverysystem.h" |
|
31 #include "cphonecenrepproxy.h" |
|
32 #include "cphonestatuspane.h" |
|
33 #include "cphonetimer.h" |
|
34 #include "tphonecommandparam.h" |
|
35 #include "tphonecmdparamboolean.h" |
|
36 #include "tphonecmdparaminteger.h" |
|
37 #include "phoneconstants.h" |
|
38 #include "phonelogger.h" |
|
39 #include "phoneui.hrh" |
|
40 |
|
41 // CONSTANTS |
|
42 // Defines how long time volume control is shown when volume is changed |
|
43 // while device is muted. Duration in microseconds. |
|
44 const TInt KPhoneDelayVolumeControlToDefaultAfterReleased = 1000000; |
|
45 |
|
46 // ================= MEMBER FUNCTIONS ======================= |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // |
|
50 CPhoneAudioController::CPhoneAudioController() : |
|
51 iIhfVolume( KPhoneDefaultVolume ), |
|
52 iEarVolume( KPhoneDefaultVolume ) |
|
53 { |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CPhoneAudioController::ConstructL() |
|
58 // Construction method for CPhoneAudioController. |
|
59 // (other items were commented in a header). |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 void CPhoneAudioController::ConstructL() |
|
63 { |
|
64 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::ConstructL()"); |
|
65 |
|
66 // Start observing foreground events |
|
67 CCoeEnv::Static()->AddForegroundObserverL( *this ); |
|
68 |
|
69 // Create the status pane singleton |
|
70 iStatusPane = CPhoneStatusPane::Instance(); |
|
71 |
|
72 // Create volume controls |
|
73 iEarVolumeControl = |
|
74 iStatusPane->NaviPane().CreateVolumeIndicatorL( |
|
75 R_AVKON_NAVI_PANE_EARPIECE_VOLUME_INDICATOR ); |
|
76 |
|
77 iIhfVolumeControl = |
|
78 iStatusPane->NaviPane().CreateVolumeIndicatorL( |
|
79 R_AVKON_NAVI_PANE_VOLUME_INDICATOR ); |
|
80 |
|
81 // To get touch input, pen check in HandleControlEventL() |
|
82 iEarVolumeControl->DecoratedControl()->SetObserver( this ); |
|
83 iIhfVolumeControl->DecoratedControl()->SetObserver( this ); |
|
84 |
|
85 // Create "muted" navi decorator |
|
86 HBufC* mutedText = StringLoader::LoadLC( R_PHONE_INCALL_MUTED_PANE ); |
|
87 iMutedControl = iStatusPane->NaviPane().CreateMessageLabelL( *mutedText ); |
|
88 CleanupStack::PopAndDestroy( mutedText ); |
|
89 |
|
90 iNaviPaneUpdateTimer = CPhoneTimer::NewL(); |
|
91 |
|
92 iActivateRecoveryId = CPhoneRecoverySystem::Instance()->AddL( |
|
93 TCallBack( DoRecoverActivateL, this ), |
|
94 CTeleRecoverySystem::EPhonePriorityStandard, |
|
95 CTeleRecoverySystem::EPhoneStateIdle ); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CPhoneAudioController::NewL() |
|
100 // Two-phased constructor |
|
101 // (other items were commented in a header). |
|
102 // --------------------------------------------------------- |
|
103 CPhoneAudioController* CPhoneAudioController::NewL() |
|
104 { |
|
105 CPhoneAudioController* self = |
|
106 new( ELeave ) CPhoneAudioController(); |
|
107 |
|
108 CleanupStack::PushL( self ); |
|
109 self->ConstructL(); |
|
110 CleanupStack::Pop( self ); |
|
111 |
|
112 return self; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------- |
|
116 // Destructor |
|
117 // --------------------------------------------------------- |
|
118 // |
|
119 CPhoneAudioController::~CPhoneAudioController() |
|
120 { |
|
121 CCoeEnv::Static()->RemoveForegroundObserver( *this ); |
|
122 CPhoneRecoverySystem::Remove( iActivateRecoveryId ); |
|
123 |
|
124 delete iNaviPaneUpdateTimer; |
|
125 delete iMutedControl; |
|
126 delete iIhfVolumeControl; |
|
127 delete iEarVolumeControl; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 // CPhoneAudioController::ActivateVolumeControlL |
|
132 // --------------------------------------------------------- |
|
133 // |
|
134 void CPhoneAudioController::ActivateVolumeControlL() |
|
135 { |
|
136 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::ActivateVolumeControlL()"); |
|
137 iVolumeControlCount++; |
|
138 if ( iVolumeControlCount == 1 ) // First time activation |
|
139 { |
|
140 // Decide whether decorator should be Ear or ihf decorator |
|
141 CAknNavigationDecorator& selectedDecorator = SelectDecoratorL(); |
|
142 PushL( selectedDecorator ); |
|
143 } |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CPhoneAudioController::DoRecoverUpdateL |
|
148 // |
|
149 // Callback function. |
|
150 // --------------------------------------------------------- |
|
151 // |
|
152 TInt CPhoneAudioController::DoRecoverActivateL( TAny* aAny ) |
|
153 { |
|
154 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::DoRecoverActivateL()"); |
|
155 static_cast< CPhoneAudioController* >( aAny )->ActivateL(); |
|
156 return KErrNone; |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // CPhoneAudioController::ActivateL |
|
161 // |
|
162 // Updates volume control according to current audio data. |
|
163 // --------------------------------------------------------- |
|
164 // |
|
165 void CPhoneAudioController::ActivateL() |
|
166 { |
|
167 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::ActivateL()"); |
|
168 |
|
169 if( iVolumeControlCount ) |
|
170 { |
|
171 // Decide whether decorator should be Ear, Ihf or Muted decorator |
|
172 CAknNavigationDecorator& selectedDecorator = SelectDecoratorL(); |
|
173 PushL( selectedDecorator ); |
|
174 |
|
175 if( &selectedDecorator != iMutedControl ) |
|
176 { |
|
177 TInt volumeLevel = VolumeLevel(); |
|
178 |
|
179 SetVolumeLevel( VolumeControl(), volumeLevel ); |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CPhoneAudioController::DeactivateVolumeControl |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 void CPhoneAudioController::DeactivateVolumeControl() |
|
189 { |
|
190 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::DeactivateVolumeControl()" ); |
|
191 if ( iOldControl ) |
|
192 { |
|
193 iStatusPane->NaviPane().Pop( iOldControl ); |
|
194 iOldControl = NULL; |
|
195 iVolumeControlCount = 0; |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------- |
|
200 // CPhoneAudioController::HandleVolumeChangeL |
|
201 // |
|
202 // Updates incall indicator according to current call state. |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 void CPhoneAudioController::HandleVolumeChangeL( |
|
206 TPhoneCommandParam* aCommandParam ) |
|
207 { |
|
208 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::HandleVolumeChangeL()"); |
|
209 if( !iPhoneInForeground ) |
|
210 { |
|
211 // Telephony is in the background so it's not our responsibility |
|
212 // to display the volume control. |
|
213 __PHONELOG( EBasic, EPhoneUIView,"CPhoneAudioController::HandleVolumeChangeL - phone in the background" ); |
|
214 return; |
|
215 } |
|
216 |
|
217 TPhoneCmdParamInteger* volumeParam = |
|
218 static_cast<TPhoneCmdParamInteger*>( aCommandParam ); |
|
219 |
|
220 if ( iIhfMode ) |
|
221 { |
|
222 iIhfVolume = volumeParam->Integer(); |
|
223 } |
|
224 else |
|
225 { |
|
226 iEarVolume = volumeParam->Integer(); |
|
227 } |
|
228 |
|
229 if( iMuted ) |
|
230 { |
|
231 // Enable timed control transition in muted state |
|
232 iTimedMuteTransferPending = ETrue; |
|
233 } |
|
234 else |
|
235 { |
|
236 iTimedMuteTransferPending = EFalse; |
|
237 } |
|
238 |
|
239 // Activate the approriate volume control |
|
240 CPhoneRecoverySystem::Instance()->RecoverNow( |
|
241 iActivateRecoveryId, |
|
242 CTeleRecoverySystem::EPhonePriorityStandard ); |
|
243 |
|
244 if( iTimedMuteTransferPending ) |
|
245 { |
|
246 iTimedMuteTransferPending = EFalse; |
|
247 |
|
248 // Cancel any pending request |
|
249 iNaviPaneUpdateTimer->CancelTimer(); |
|
250 |
|
251 // Activate change to Muted decorator after given delay |
|
252 iNaviPaneUpdateTimer->After( |
|
253 KPhoneDelayVolumeControlToDefaultAfterReleased, |
|
254 TCallBack( DoUpdateNaviPaneToDefault, this ) ); |
|
255 } |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------- |
|
259 // CPhoneAudioController::HandleIhfChange |
|
260 // |
|
261 // Updates incall indicator according to current call state. |
|
262 // --------------------------------------------------------- |
|
263 // |
|
264 void CPhoneAudioController::HandleIhfChange( |
|
265 TPhoneCommandParam* aCommandParam ) |
|
266 { |
|
267 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::HandleIhfChange()"); |
|
268 TPhoneCmdParamBoolean* booleanParam = |
|
269 static_cast<TPhoneCmdParamBoolean*>( aCommandParam ); |
|
270 |
|
271 iIhfMode = booleanParam->Boolean(); |
|
272 |
|
273 // Set state transition flag |
|
274 iIhfTransferPending = ETrue; |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------- |
|
278 // CPhoneAudioController::HandleMuteChange |
|
279 // |
|
280 // Updates incall indicator according to current call state. |
|
281 // --------------------------------------------------------- |
|
282 // |
|
283 void CPhoneAudioController::HandleMuteChange( |
|
284 TPhoneCommandParam* aCommandParam ) |
|
285 { |
|
286 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::HandleMuteChange()"); |
|
287 TPhoneCmdParamBoolean* booleanParam = |
|
288 static_cast<TPhoneCmdParamBoolean*>( aCommandParam ); |
|
289 |
|
290 iMuted = booleanParam->Boolean(); |
|
291 |
|
292 // Decide whether decorator should be ear, ihf or muted decorator |
|
293 TRAP_IGNORE( PushL( SelectDecoratorL() ) ); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CPhoneAudioController::PushL |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 void CPhoneAudioController::PushL( CAknNavigationDecorator& aNew ) |
|
301 { |
|
302 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::PushL()"); |
|
303 TInt err = KErrNone; |
|
304 if ( !iOldControl ) |
|
305 { |
|
306 __PHONELOG( EBasic, EPhoneUIView,"CPhoneAudioController::iStatusPane->NaviPane().PushL( aNew );" ); |
|
307 iStatusPane->NaviPane().PushL( aNew ); |
|
308 } |
|
309 else if ( &aNew != iOldControl ) |
|
310 { |
|
311 err = iStatusPane->NaviPane().ReplaceL( *iOldControl, aNew ); |
|
312 } |
|
313 // otherwise iOldControl == &aNew. |
|
314 |
|
315 if ( err == KErrNone ) |
|
316 { |
|
317 iOldControl = &aNew; |
|
318 } |
|
319 } |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CPhoneAudioController::DoUpdateNaviPaneToDefault |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 TInt CPhoneAudioController::DoUpdateNaviPaneToDefault( TAny* aAny ) |
|
326 { |
|
327 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::DoUpdateNaviPaneToDefault()"); |
|
328 CPhoneAudioController* self = static_cast< CPhoneAudioController* >( aAny ); |
|
329 CPhoneRecoverySystem::Instance()->RecoverNow( |
|
330 self->iActivateRecoveryId, |
|
331 CTeleRecoverySystem::EPhonePriorityStandard ); |
|
332 return KErrNone; |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CPhoneAudioController::HandleControlEventL |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 void CPhoneAudioController::HandleControlEventL( |
|
340 CCoeControl* aControl, |
|
341 TCoeEvent aEventType ) |
|
342 { |
|
343 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::HandleControlEventL()" ); |
|
344 if ( aEventType == MCoeControlObserver::EEventStateChanged && |
|
345 AknLayoutUtils::PenEnabled() ) |
|
346 { |
|
347 if ( aControl == iEarVolumeControl->DecoratedControl() ) |
|
348 { |
|
349 TInt volume = static_cast< CAknVolumeControl* > |
|
350 ( iEarVolumeControl->DecoratedControl() ) |
|
351 ->Value(); |
|
352 |
|
353 if ( volume != iEarVolume ) |
|
354 { |
|
355 // Volume level was changed via ui control |
|
356 iEarVolume = volume; |
|
357 CEikonEnv::Static()->EikAppUi()->HandleCommandL( |
|
358 EPhoneInCallCmdSetVolumeLevel ); |
|
359 } |
|
360 } |
|
361 else if ( aControl == iIhfVolumeControl->DecoratedControl() ) |
|
362 { |
|
363 TInt volume = static_cast< CAknVolumeControl* > |
|
364 ( iIhfVolumeControl->DecoratedControl() ) |
|
365 ->Value(); |
|
366 |
|
367 if ( volume != iIhfVolume ) |
|
368 { |
|
369 // Volume level was changed via ui control |
|
370 iIhfVolume = volume; |
|
371 CEikonEnv::Static()->EikAppUi()->HandleCommandL( |
|
372 EPhoneInCallCmdSetVolumeLevel ); |
|
373 } |
|
374 } |
|
375 } |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CPhoneAudioController::VolumeLevelFromControl |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 TInt CPhoneAudioController::VolumeLevelFromControl() |
|
383 { |
|
384 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeLevelFromControl()" ); |
|
385 TInt volume = VolumeControl().Value(); |
|
386 |
|
387 return volume; |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CPhoneAudioController::VolumeDecorator |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 CAknNavigationDecorator& CPhoneAudioController::VolumeDecorator() |
|
395 { |
|
396 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeDecorator()" ); |
|
397 CAknNavigationDecorator* volumeDecorator = NULL; |
|
398 if ( iIhfMode ) |
|
399 { |
|
400 volumeDecorator = iIhfVolumeControl; |
|
401 } |
|
402 else |
|
403 { |
|
404 volumeDecorator = iEarVolumeControl; |
|
405 } |
|
406 |
|
407 return *volumeDecorator; |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CPhoneAudioController::VolumeControl |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 CAknVolumeControl& CPhoneAudioController::VolumeControl() |
|
415 { |
|
416 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeControl()" ); |
|
417 CAknVolumeControl* volumeControl = NULL; |
|
418 volumeControl = static_cast< CAknVolumeControl* >( |
|
419 VolumeDecorator().DecoratedControl() ); |
|
420 |
|
421 return *volumeControl; |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CPhoneAudioController::VolumeLevel |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 TInt CPhoneAudioController::VolumeLevel() |
|
429 { |
|
430 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeLevel()" ); |
|
431 TInt volumeLevel; |
|
432 if ( iIhfMode ) |
|
433 { |
|
434 volumeLevel = iIhfVolume; |
|
435 } |
|
436 else |
|
437 { |
|
438 volumeLevel = iEarVolume; |
|
439 } |
|
440 |
|
441 return volumeLevel; |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // CPhoneAudioController::SelectDecoratorL |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 CAknNavigationDecorator& CPhoneAudioController::SelectDecoratorL() |
|
449 { |
|
450 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::SelectDecoratorL()" ); |
|
451 CAknNavigationDecorator* newDecorator = NULL; |
|
452 if ( !iMuted ) |
|
453 { |
|
454 __PHONELOG( EBasic, EPhoneUIView,"CPhoneAudioController::SelectDecoratorL() - volume decorator " ); |
|
455 newDecorator = &VolumeDecorator(); |
|
456 } |
|
457 else |
|
458 { |
|
459 if ( iIhfTransferPending || !iTimedMuteTransferPending ) |
|
460 { |
|
461 __PHONELOG( EBasic, EPhoneUIView,"CPhoneAudioController::SelectDecoratorL() - muted decorator " ); |
|
462 newDecorator = iMutedControl; |
|
463 } |
|
464 else |
|
465 { |
|
466 __PHONELOG( EBasic, EPhoneUIView,"CPhoneAudioController::SelectDecoratorL() - volume decorator " ); |
|
467 newDecorator = &VolumeDecorator(); |
|
468 |
|
469 // In muted state the volume decorator must be first |
|
470 // pushed to container to enable volume popup showing |
|
471 PushL( *newDecorator ); |
|
472 } |
|
473 } |
|
474 |
|
475 // Clear IHF transfer flag. |
|
476 iIhfTransferPending = EFalse; |
|
477 |
|
478 return *newDecorator; |
|
479 } |
|
480 |
|
481 // ----------------------------------------------------------------------------- |
|
482 // CPhoneAudioController::SetVolumeLevel |
|
483 // ----------------------------------------------------------------------------- |
|
484 // |
|
485 void CPhoneAudioController::SetVolumeLevel( |
|
486 CAknVolumeControl& aVolumeControl, |
|
487 TInt aVolumeLevel) |
|
488 { |
|
489 __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::SetVolumeLevel()" ); |
|
490 aVolumeControl.SetValue( aVolumeLevel ); |
|
491 |
|
492 } |
|
493 |
|
494 // ----------------------------------------------------------------------------- |
|
495 // CPhoneAudioController::HandleGainingForeground |
|
496 // ----------------------------------------------------------------------------- |
|
497 // |
|
498 void CPhoneAudioController::HandleGainingForeground() |
|
499 { |
|
500 iPhoneInForeground = ETrue; |
|
501 } |
|
502 |
|
503 // ----------------------------------------------------------------------------- |
|
504 // CPhoneAudioController::HandleLosingForeground |
|
505 // ----------------------------------------------------------------------------- |
|
506 // |
|
507 void CPhoneAudioController::HandleLosingForeground() |
|
508 { |
|
509 iPhoneInForeground = EFalse; |
|
510 } |
|
511 |
|
512 // End of file |