phoneapp/phoneuiview/src/cphoneaudiocontroller.cpp
branchRCL_3
changeset 62 5266b1f337bd
child 81 c26cc2a7c548
equal deleted inserted replaced
61:41a7f70b3818 62:5266b1f337bd
       
     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 
       
    23 #include <avkon.rsg>
       
    24 
       
    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 
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 //
       
    47 CPhoneAudioController::CPhoneAudioController() :
       
    48     iIhfVolume( KPhoneDefaultVolume ),
       
    49     iEarVolume( KPhoneDefaultVolume )
       
    50     {
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CPhoneAudioController::ConstructL()
       
    55 // Construction method for CPhoneAudioController.
       
    56 // (other items were commented in a header).
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 void CPhoneAudioController::ConstructL()
       
    60     {
       
    61     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::ConstructL()");
       
    62 
       
    63     // Start observing foreground events
       
    64     CCoeEnv::Static()->AddForegroundObserverL( *this );
       
    65 
       
    66     // Create the status pane singleton
       
    67     iStatusPane = CPhoneStatusPane::Instance();
       
    68 
       
    69     // Create volume controls
       
    70     iEarVolumeControl = 
       
    71         iStatusPane->NaviPane().CreateVolumeIndicatorL( 
       
    72         R_AVKON_NAVI_PANE_EARPIECE_VOLUME_INDICATOR );
       
    73     
       
    74     iIhfVolumeControl = 
       
    75         iStatusPane->NaviPane().CreateVolumeIndicatorL( 
       
    76         R_AVKON_NAVI_PANE_VOLUME_INDICATOR );
       
    77         
       
    78     // To get touch input, pen check in HandleControlEventL()
       
    79     iEarVolumeControl->DecoratedControl()->SetObserver( this );
       
    80     iIhfVolumeControl->DecoratedControl()->SetObserver( this );            
       
    81 
       
    82     iActivateRecoveryId = CPhoneRecoverySystem::Instance()->AddL( 
       
    83         TCallBack( DoRecoverActivateL, this ),
       
    84         CTeleRecoverySystem::EPhonePriorityStandard,
       
    85         CTeleRecoverySystem::EPhoneStateIdle );   
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CPhoneAudioController::NewL()
       
    90 // Two-phased constructor
       
    91 // (other items were commented in a header).
       
    92 // ---------------------------------------------------------
       
    93 CPhoneAudioController* CPhoneAudioController::NewL()
       
    94     {   
       
    95     CPhoneAudioController* self = 
       
    96         new( ELeave ) CPhoneAudioController();
       
    97     
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop( self );
       
   101 
       
   102     return self;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // Destructor
       
   107 // ---------------------------------------------------------
       
   108 // 
       
   109 CPhoneAudioController::~CPhoneAudioController()
       
   110     {
       
   111     CCoeEnv::Static()->RemoveForegroundObserver( *this );
       
   112     CPhoneRecoverySystem::Remove( iActivateRecoveryId );
       
   113      
       
   114     delete iIhfVolumeControl;
       
   115     delete iEarVolumeControl;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CPhoneAudioController::ActivateVolumeControlL
       
   120 // ---------------------------------------------------------
       
   121 //
       
   122 void CPhoneAudioController::ActivateVolumeControlL()
       
   123     {
       
   124     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::ActivateVolumeControlL()");
       
   125     iVolumeControlCount++;
       
   126     if ( iVolumeControlCount == 1 ) // First time activation
       
   127         {
       
   128         // Decide whether decorator should be Ear or ihf decorator
       
   129         CAknNavigationDecorator& selectedVolumeDecorator =VolumeDecorator();  
       
   130         PushL( selectedVolumeDecorator ); 
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // CPhoneAudioController::DoRecoverUpdateL
       
   136 //
       
   137 // Callback function.
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 TInt CPhoneAudioController::DoRecoverActivateL( TAny* aAny )
       
   141     {
       
   142     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::DoRecoverActivateL()");
       
   143     static_cast< CPhoneAudioController* >( aAny )->ActivateL();
       
   144     return KErrNone;
       
   145     }
       
   146     
       
   147 // ---------------------------------------------------------
       
   148 // CPhoneAudioController::ActivateL
       
   149 //
       
   150 // Updates volume control according to current audio data.
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 void CPhoneAudioController::ActivateL()
       
   154     {
       
   155     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::ActivateL()");
       
   156     
       
   157     if( iVolumeControlCount )
       
   158         {
       
   159         // Decide whether decorator should be Ear, Ihf decorator
       
   160         CAknNavigationDecorator& selectedVolumeDecorator = VolumeDecorator(); 
       
   161         PushL( selectedVolumeDecorator );                    
       
   162         TInt volumeLevel = VolumeLevel();             
       
   163         SetVolumeLevel( VolumeControl(), volumeLevel );                       
       
   164         }
       
   165     }
       
   166     
       
   167 // ---------------------------------------------------------
       
   168 // CPhoneAudioController::DeactivateVolumeControl
       
   169 // ---------------------------------------------------------
       
   170 //
       
   171 void CPhoneAudioController::DeactivateVolumeControl()
       
   172     {
       
   173     __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::DeactivateVolumeControl()" );
       
   174     if ( iOldControl )
       
   175         {
       
   176         iStatusPane->NaviPane().Pop( iOldControl );
       
   177         iOldControl = NULL;
       
   178         iVolumeControlCount = 0;
       
   179         }
       
   180     }
       
   181     
       
   182 // ---------------------------------------------------------
       
   183 // CPhoneAudioController::HandleVolumeChangeL
       
   184 //
       
   185 // Updates incall indicator according to current call state.
       
   186 // ---------------------------------------------------------
       
   187 //
       
   188 void CPhoneAudioController::HandleVolumeChangeL(
       
   189     TPhoneCommandParam* aCommandParam )
       
   190     {
       
   191     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::HandleVolumeChangeL()");
       
   192     if( !iPhoneInForeground )
       
   193         {
       
   194         // Telephony is in the background so it's not our responsibility
       
   195         // to display the volume control.
       
   196         __PHONELOG( EBasic, EPhoneUIView,"CPhoneAudioController::HandleVolumeChangeL - phone in the background" ); 
       
   197         return;
       
   198         }
       
   199     
       
   200     TPhoneCmdParamInteger* volumeParam =
       
   201         static_cast<TPhoneCmdParamInteger*>( aCommandParam );
       
   202 
       
   203     if ( iIhfMode )
       
   204         {
       
   205         iIhfVolume = volumeParam->Integer();
       
   206         }
       
   207     else
       
   208         {
       
   209         iEarVolume = volumeParam->Integer();
       
   210         }
       
   211      
       
   212     // Activate the approriate volume control
       
   213     CPhoneRecoverySystem::Instance()->RecoverNow( 
       
   214         iActivateRecoveryId, 
       
   215         CTeleRecoverySystem::EPhonePriorityStandard );
       
   216     
       
   217     }
       
   218     
       
   219 // ---------------------------------------------------------
       
   220 // CPhoneAudioController::HandleIhfChange
       
   221 //
       
   222 // Updates incall indicator according to current call state.
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 void CPhoneAudioController::HandleIhfChange(
       
   226     TPhoneCommandParam* aCommandParam )
       
   227     {
       
   228     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::HandleIhfChange()");
       
   229     TPhoneCmdParamBoolean* booleanParam =
       
   230         static_cast<TPhoneCmdParamBoolean*>( aCommandParam );
       
   231     
       
   232     iIhfMode = booleanParam->Boolean();    
       
   233     }
       
   234     
       
   235 // -----------------------------------------------------------------------------
       
   236 // CPhoneAudioController::PushL
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CPhoneAudioController::PushL( CAknNavigationDecorator& aNew )
       
   240     {
       
   241     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneAudioController::PushL()");
       
   242     TInt err = KErrNone;
       
   243     if ( !iOldControl )
       
   244         {
       
   245         __PHONELOG( EBasic, EPhoneUIView,"CPhoneAudioController::iStatusPane->NaviPane().PushL( aNew );" ); 
       
   246         iStatusPane->NaviPane().PushL( aNew );
       
   247         }
       
   248     else if ( &aNew != iOldControl )
       
   249         {
       
   250         err = iStatusPane->NaviPane().ReplaceL( *iOldControl, aNew );
       
   251         }
       
   252     // otherwise iOldControl == &aNew.
       
   253 
       
   254     if ( err == KErrNone )
       
   255         {
       
   256         iOldControl = &aNew;
       
   257         }
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CPhoneAudioController::HandleControlEventL
       
   262 // -----------------------------------------------------------------------------
       
   263 //    
       
   264 void CPhoneAudioController::HandleControlEventL( 
       
   265     CCoeControl* aControl, 
       
   266     TCoeEvent aEventType )
       
   267     {
       
   268     __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::HandleControlEventL()" );
       
   269     if ( aEventType == MCoeControlObserver::EEventStateChanged &&
       
   270          AknLayoutUtils::PenEnabled() )
       
   271         {
       
   272         if ( aControl == iEarVolumeControl->DecoratedControl() )
       
   273             {
       
   274             TInt volume =  static_cast< CAknVolumeControl* > 
       
   275                                ( iEarVolumeControl->DecoratedControl() )
       
   276                                ->Value();
       
   277             
       
   278             if ( volume != iEarVolume )
       
   279                 {
       
   280                 // Volume level was changed via ui control
       
   281                 iEarVolume = volume;
       
   282                 CEikonEnv::Static()->EikAppUi()->HandleCommandL(
       
   283                     EPhoneInCallCmdSetVolumeLevel );                        
       
   284                 }
       
   285             }
       
   286         else if ( aControl == iIhfVolumeControl->DecoratedControl() )
       
   287             {
       
   288             TInt volume =  static_cast< CAknVolumeControl* > 
       
   289                                ( iIhfVolumeControl->DecoratedControl() )
       
   290                                ->Value();
       
   291             
       
   292             if ( volume != iIhfVolume )
       
   293                 {
       
   294                 // Volume level was changed via ui control
       
   295                 iIhfVolume = volume;
       
   296                 CEikonEnv::Static()->EikAppUi()->HandleCommandL(
       
   297                     EPhoneInCallCmdSetVolumeLevel );                        
       
   298                 }        
       
   299             }            
       
   300         }
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CPhoneAudioController::VolumeLevelFromControl
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 TInt CPhoneAudioController::VolumeLevelFromControl()
       
   308     {       
       
   309     __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeLevelFromControl()" );         
       
   310     TInt volume = VolumeControl().Value();     
       
   311     
       
   312     return volume; 
       
   313     }
       
   314         
       
   315 // -----------------------------------------------------------------------------
       
   316 // CPhoneAudioController::VolumeDecorator
       
   317 // -----------------------------------------------------------------------------
       
   318 //    
       
   319 CAknNavigationDecorator& CPhoneAudioController::VolumeDecorator()    
       
   320     {
       
   321     __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeDecorator()" );                 
       
   322     CAknNavigationDecorator* volumeDecorator = NULL;      
       
   323     if ( iIhfMode )
       
   324         {            
       
   325         volumeDecorator = iIhfVolumeControl;
       
   326         }
       
   327     else
       
   328         {
       
   329         volumeDecorator = iEarVolumeControl;        
       
   330         }
       
   331         
       
   332     return *volumeDecorator; 
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CPhoneAudioController::VolumeControl
       
   337 // -----------------------------------------------------------------------------
       
   338 //    
       
   339 CAknVolumeControl& CPhoneAudioController::VolumeControl()      
       
   340     {
       
   341     __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeControl()" );                     
       
   342     CAknVolumeControl* volumeControl = NULL;     
       
   343     volumeControl = static_cast< CAknVolumeControl* >( 
       
   344         VolumeDecorator().DecoratedControl() ); 
       
   345 
       
   346     return *volumeControl; 
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CPhoneAudioController::VolumeLevel
       
   351 // -----------------------------------------------------------------------------
       
   352 //    
       
   353 TInt CPhoneAudioController::VolumeLevel()    
       
   354     {
       
   355     __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::VolumeLevel()" );                             
       
   356     TInt volumeLevel;     
       
   357     if ( iIhfMode )
       
   358         {            
       
   359         volumeLevel = iIhfVolume; 
       
   360         }
       
   361     else
       
   362         {
       
   363         volumeLevel = iEarVolume;         
       
   364         }        
       
   365         
       
   366     return volumeLevel;
       
   367     }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // CPhoneAudioController::SetVolumeLevel
       
   371 // -----------------------------------------------------------------------------
       
   372 //    
       
   373 void CPhoneAudioController::SetVolumeLevel(
       
   374     CAknVolumeControl& aVolumeControl, 
       
   375     TInt aVolumeLevel)
       
   376     {
       
   377     __LOGMETHODSTARTEND( EPhoneUIView,"CPhoneAudioController::SetVolumeLevel()" );   
       
   378     aVolumeControl.SetValue( aVolumeLevel ); 
       
   379 
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CPhoneAudioController::HandleGainingForeground
       
   384 // -----------------------------------------------------------------------------
       
   385 //    
       
   386 void CPhoneAudioController::HandleGainingForeground()
       
   387     {
       
   388     iPhoneInForeground = ETrue;
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CPhoneAudioController::HandleLosingForeground
       
   393 // -----------------------------------------------------------------------------
       
   394 //    
       
   395 void CPhoneAudioController::HandleLosingForeground()
       
   396     {
       
   397     iPhoneInForeground = EFalse;
       
   398     }
       
   399 
       
   400 // End of file