phoneapp/phoneuicontrol/src/cphonebtaadisconnecthandler.cpp
changeset 0 5f000ab63145
child 4 24062c24fe38
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Bluetooth audio disconnection handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <featmgr.h>
       
    21 #include    <StringLoader.h>
       
    22 #include    <mpeengineinfo.h>
       
    23 
       
    24 #include    "phoneui.hrh"
       
    25 #include    "mphonestatemachine.h"
       
    26 #include    "mphoneviewcommandhandle.h"
       
    27 #include    "phoneconstants.h"
       
    28 #include    "cphonebtaadisconnecthandler.h"
       
    29 #include    "cphonemainresourceresolver.h"
       
    30 #include    "cphonetimer.h"
       
    31 #include    "phonelogger.h"
       
    32 #include    "phonerssbase.h"
       
    33 #include    "tphonecmdparamquery.h"
       
    34 #include    "tphonecmdparamcallstatedata.h"
       
    35 #include    "telinternalsingletonuids.h"
       
    36 #include    "cphonestatehandle.h"
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CPhoneBtaaDisconnectHandler::InstanceL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CPhoneBtaaDisconnectHandler* CPhoneBtaaDisconnectHandler::InstanceL()
       
    47     {
       
    48     CPhoneBtaaDisconnectHandler* self = 
       
    49         static_cast<CPhoneBtaaDisconnectHandler*>( CCoeEnv::Static( KUidBtaaDisconnectHandlerSingleton ) );
       
    50 
       
    51     if ( !self )
       
    52         {
       
    53         self = new ( ELeave ) CPhoneBtaaDisconnectHandler;
       
    54         }
       
    55     
       
    56     return self;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CPhoneBtaaDisconnectHandler::CPhoneBtaaDisconnectHandler
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CPhoneBtaaDisconnectHandler::CPhoneBtaaDisconnectHandler()
       
    64     : CCoeStatic( KUidBtaaDisconnectHandlerSingleton ), iState( EIdle )
       
    65     {
       
    66     CPhoneStateHandle* stateHandle = CPhoneStateHandle::Instance();
       
    67     
       
    68     iViewCommandHandle = stateHandle->ViewCommandHandle();
       
    69     iStateMachine = stateHandle->StateMachine();
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CPhoneBtaaDisconnectHandler::~CPhoneBtaaDisconnectHandler
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CPhoneBtaaDisconnectHandler::~CPhoneBtaaDisconnectHandler()
       
    77     {
       
    78     delete iTimer;
       
    79     }
       
    80  
       
    81 // -----------------------------------------------------------------------------
       
    82 // CPhoneBtaaDisconnectHandler::HandleTimeOutL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CPhoneBtaaDisconnectHandler::HandleTimeOutL()
       
    86     {
       
    87     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneBtaaDisconnectHandler::HandleTimeOutL()");
       
    88     Cancel();
       
    89     TerminateAllCallsL();
       
    90     }
       
    91  
       
    92 // -----------------------------------------------------------------------------
       
    93 // CPhoneBtaaDisconnectHandler::Cancel
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CPhoneBtaaDisconnectHandler::Cancel()
       
    97     {
       
    98     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneBtaaDisconnectHandler::Cancel()");
       
    99     TRAP_IGNORE( iViewCommandHandle->ExecuteCommandL( EPhoneViewRemoveQuery ) );
       
   100     DeleteAll();
       
   101     if ( !iOldMuted && iStateMachine->PhoneEngineInfo()->AudioMute() )
       
   102         {
       
   103         TRAP_IGNORE ( SetMuteL( EFalse ) );
       
   104         }
       
   105     iOldMuted = EFalse;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CPhoneBtaaDisconnectHandler::LaunchQueryL
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CPhoneBtaaDisconnectHandler::LaunchQueryL()
       
   113     {
       
   114     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneBtaaDisconnectHandler::LaunchQueryL()");
       
   115  
       
   116     if ( iState == ELaunchQuery )
       
   117         {
       
   118         // Query already available.
       
   119         __PHONELOG( EBasic,EPhoneControl,"CPhoneBtaaDisconnectHandler::LaunchQueryL.nok");
       
   120         return;
       
   121         }
       
   122    
       
   123     if ( !iTimer )
       
   124         {
       
   125         iTimer = CPhoneTimer::NewL();
       
   126         }
       
   127 
       
   128     // Start timer.
       
   129     iTimer->After( KPhoneBtaaConnectionLostQueryTimeout, this );
       
   130     
       
   131     // Mute the phone if needed.
       
   132     iOldMuted = iStateMachine->PhoneEngineInfo()->AudioMute() ;
       
   133     
       
   134     if ( !iOldMuted )
       
   135         {
       
   136         SetMuteL( ETrue );
       
   137         }
       
   138         
       
   139     iState = ELaunchQuery;
       
   140     
       
   141     if ( iVideoCallStatus )
       
   142         {
       
   143         ShowQueryL( EPhoneContinueInLoudspeakerConfirmationQuery );
       
   144         }
       
   145     else
       
   146         {
       
   147         ShowQueryL( EPhoneContinueInHandsetConfirmationQuery ); 
       
   148         }        
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CPhoneBtaaDisconnectHandler::HandleConnectionLostL
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CPhoneBtaaDisconnectHandler::HandleConnectionLostL()
       
   156     {
       
   157     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneBtaaDisconnectHandler::HandleConnectionLostL()"); 
       
   158     iVideoCallStatus = EFalse;
       
   159            
       
   160     if ( FeatureManager::FeatureSupported( KFeatureIdCsVideoTelephony ) )
       
   161         {
       
   162         // Fetch active call's id from view
       
   163         TPhoneCmdParamCallStateData callStateData;
       
   164         callStateData.SetCallState( EPEStateConnected );
       
   165         iViewCommandHandle->HandleCommandL( 
       
   166             EPhoneViewGetCallIdByState, &callStateData );
       
   167         TInt call = callStateData.CallId();
       
   168         if ( call != KErrNotFound &&
       
   169             iStateMachine->PhoneEngineInfo()->CallType( call ) == EPECallTypeVideo )
       
   170             {
       
   171             iVideoCallStatus = ETrue;
       
   172             }
       
   173         __PHONELOG1( EBasic, EPhoneControl, 
       
   174                 "CPhoneBtaaDisconnectHandler::HandleConnectionLostL callType: %d",
       
   175                 call != KErrNotFound ? 
       
   176                 iStateMachine->PhoneEngineInfo()->CallType( call ) : KErrNotFound );            
       
   177         }
       
   178  
       
   179     if ( iState == EIdle )
       
   180         {
       
   181         LaunchQueryL();
       
   182         }
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CPhoneBtaaDisconnectHandler::HandleQueryDismissL
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CPhoneBtaaDisconnectHandler::HandleQueryDismissL( 
       
   190         TInt aCommand )
       
   191     {
       
   192     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneBtaaDisconnectHandler::HandleQueryDismissL()");
       
   193                                    
       
   194     if ( aCommand == EPhoneCmdYesBtDisconnectQuery )
       
   195         {
       
   196      
       
   197         // If phone was muted only for the duration of the note, unmute.
       
   198         if ( !iOldMuted )
       
   199             {
       
   200             SetMuteL( EFalse );
       
   201             }
       
   202 
       
   203         // Activate loudspeaker when required.
       
   204         if ( iVideoCallStatus )
       
   205             {
       
   206             iStateMachine->PhoneEngineInfo()->SetAudioOutputCommand( 
       
   207                 EPELoudspeaker, ETrue);
       
   208             iStateMachine->SendPhoneEngineMessage( 
       
   209                 MPEPhoneModel::EPEMessageSetAudioOutput );
       
   210             }
       
   211          }
       
   212     else
       
   213         {
       
   214         TerminateAllCallsL();
       
   215         //Unmute, for robustness      
       
   216         SetMuteL( EFalse );        
       
   217         }
       
   218     
       
   219     DeleteAll();
       
   220     iOldMuted = EFalse;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CPhoneBtaaDisconnectHandler::DeleteAll
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CPhoneBtaaDisconnectHandler::DeleteAll()
       
   228     {
       
   229     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneBtaaDisconnectHandler::DeleteAll()");
       
   230     
       
   231     if ( iTimer ) 
       
   232         {
       
   233         if ( iTimer->IsActive() )
       
   234             {
       
   235             iTimer->Cancel();
       
   236             }
       
   237         delete iTimer;
       
   238         iTimer = NULL;
       
   239         }
       
   240  
       
   241     iState = EIdle;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CPhoneBtaaDisconnectHandler::TerminateAllCallsL
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CPhoneBtaaDisconnectHandler::TerminateAllCallsL()
       
   249     {
       
   250     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneBtaaDisconnectHandler::TerminateAllCallsL()");
       
   251     
       
   252     if( iVideoCallStatus )
       
   253         {
       
   254         // Fetch active call's id from view
       
   255         TPhoneCmdParamCallStateData callStateData;
       
   256         callStateData.SetCallState( EPEStateConnected );
       
   257         iViewCommandHandle->HandleCommandL(
       
   258             EPhoneViewGetCallIdByState, &callStateData );
       
   259             
       
   260         if ( callStateData.CallId() != KErrNotFound )
       
   261             {
       
   262             iStateMachine->SetCallId( callStateData.CallId() );
       
   263             iStateMachine->SendPhoneEngineMessage( 
       
   264                 MPEPhoneModel::EPEMessageRelease );        
       
   265             }
       
   266         else
       
   267             {
       
   268             iStateMachine->SendPhoneEngineMessage( 
       
   269                 MPEPhoneModel::EPEMessageReleaseAll );        
       
   270             }        
       
   271         }
       
   272     else
       
   273         {
       
   274         iStateMachine->SendPhoneEngineMessage( 
       
   275             MPEPhoneModel::EPEMessageReleaseAll );        
       
   276         }        
       
   277     }
       
   278  
       
   279 // -----------------------------------------------------------------------------
       
   280 // CPhoneBtaaDisconnectHandler::ShowQueryL
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CPhoneBtaaDisconnectHandler::ShowQueryL( TInt aResourceId )
       
   284     {
       
   285     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneBtaaDisconnectHandler::ShowQueryL( ) ");
       
   286 	//__ASSERT_DEBUG( aResourceId, Panic( EPhoneCtrlParameterNotInitialized ) );
       
   287     TPhoneCmdParamQuery queryParam;
       
   288     queryParam.SetQueryType( EPhoneGlobalQueryDialog );
       
   289   
       
   290     HBufC* queryPrompt = StringLoader::LoadLC( 
       
   291             CPhoneMainResourceResolver::Instance()->ResolveResourceID( 
       
   292                 aResourceId ));
       
   293    
       
   294     queryParam.SetQueryPrompt( *queryPrompt );
       
   295     queryParam.SetDefaultCba(             
       
   296         CPhoneMainResourceResolver::Instance()->
       
   297         ResolveResourceID( EPhoneDisconnectingQueryCBA ) );
       
   298   
       
   299     iViewCommandHandle->ExecuteCommandL( EPhoneViewShowQuery, &queryParam );
       
   300     
       
   301     CleanupStack::PopAndDestroy( queryPrompt );
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CPhoneBtaaDisconnectHandler::SetMuteL
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CPhoneBtaaDisconnectHandler::SetMuteL( TBool aStatus )
       
   309     {
       
   310     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneBtaaDisconnectHandler::SetMuteL( ) ");
       
   311     
       
   312     iStateMachine->PhoneEngineInfo()->SetAudioMuteCommand( aStatus );
       
   313     iStateMachine->SendPhoneEngineMessage( 
       
   314         MPEPhoneModel::EPEMessageSetAudioMute );    
       
   315     }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // CPhoneBtaaDisconnectHandler::IsQuery 
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 TBool CPhoneBtaaDisconnectHandler::IsQuery()
       
   322     {
       
   323     TBool ret = EFalse;
       
   324     if ( iState == ELaunchQuery )
       
   325         {
       
   326         ret = ETrue;
       
   327         __PHONELOG1( EBasic, EPhoneControl, 
       
   328                      "CPhoneBtaaDisconnectHandler::IsQuery: %d", ret );
       
   329         }
       
   330     return ret;
       
   331     }
       
   332 
       
   333 //  End of File