phoneapp/phoneuicontrol/src/cphonecbamanager.cpp
changeset 0 5f000ab63145
child 1 838b0a10d15b
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2008 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: Class takes care of CBA's.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cphonecbamanager.h"
       
    19 
       
    20 #include "mpeengineinfo.h"
       
    21 #include "mphoneviewcommandhandle.h"
       
    22 #include "mphonestatemachine.h"
       
    23 
       
    24 #include <featmgr.h>
       
    25 #include <callhandlingui.rsg>
       
    26 
       
    27 #include "phonerssbase.h"
       
    28 #include "phoneui.pan"
       
    29 #include "phonelogger.h"
       
    30 
       
    31 #include "cphonestate.h"
       
    32 #include "cphonecenrepproxy.h"
       
    33 #include "cphonemainresourceresolver.h"
       
    34 
       
    35 #include "telephonyvariant.hrh"
       
    36 #include "phoneui.hrh"
       
    37 
       
    38 #include "tphonecmdparamboolean.h"
       
    39 #include "tphonecmdparaminteger.h"
       
    40 #include "tphonecmdparamcallstatedata.h"
       
    41 
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CPhoneCbaManager::CPhoneCbaManager
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CPhoneCbaManager::CPhoneCbaManager(
       
    50          CPhoneState* aState,
       
    51          MPhoneViewCommandHandle& aViewCommandHandle,
       
    52          MPhoneStateMachine& aStateMachine )
       
    53    : iState ( aState ), 
       
    54      iViewCommandHandle ( aViewCommandHandle ),
       
    55      iStateMachine ( aStateMachine )
       
    56     {
       
    57     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneCbaManager::CPhoneCbaManager() ");
       
    58     }
       
    59 
       
    60  // ---------------------------------------------------------------------------
       
    61  // CPhoneCbaManager::NewL
       
    62  // ---------------------------------------------------------------------------
       
    63  //
       
    64 CPhoneCbaManager* CPhoneCbaManager::NewL( 
       
    65         CPhoneState* aState,
       
    66         MPhoneViewCommandHandle& aViewCommandHandle,
       
    67         MPhoneStateMachine& aStateMachine )
       
    68      {
       
    69      __LOGMETHODSTARTEND( EPhoneControl, "CPhoneCbaManager::NewL() ");
       
    70      return new (ELeave) CPhoneCbaManager( aState, aViewCommandHandle, aStateMachine );
       
    71      }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 //  CPhoneCbaManager::~CPhoneCbaManager
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CPhoneCbaManager::~CPhoneCbaManager()
       
    78      {
       
    79      __LOGMETHODSTARTEND( EPhoneControl, "CPhoneCbaManager::~CPhoneCbaManager() ");
       
    80      }
       
    81  
       
    82 // ======== LOCAL FUNCTIONS ========
       
    83 
       
    84 // -----------------------------------------------------------
       
    85 // CPhoneCbaManager::UpdateInCallCbaL
       
    86 // -----------------------------------------------------------
       
    87 //
       
    88 void CPhoneCbaManager::UpdateInCallCbaL()
       
    89     {
       
    90     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::UpdateInCallCbaL() ");
       
    91     UpdateCbaL( EPhoneCallHandlingInCallCBA );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------
       
    95 // CPhoneCbaManager::UpdateCbaL
       
    96 // -----------------------------------------------------------
       
    97 //
       
    98 EXPORT_C void CPhoneCbaManager::UpdateCbaL( TInt aResource )
       
    99     {
       
   100     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::UpdateCbaL() ");
       
   101     __ASSERT_DEBUG( iStateMachine.PhoneEngineInfo(),
       
   102         Panic( EPhoneCtrlInvariant ) );
       
   103     TInt resourceId = aResource;
       
   104     TPhoneCmdParamBoolean hold;
       
   105     iViewCommandHandle.ExecuteCommandL( EPhoneViewGetHoldFlag, &hold );
       
   106 
       
   107     const TBool coverHideSendEndKey =
       
   108         CPhoneCenRepProxy::Instance()->IsTelephonyFeatureSupported(
       
   109             KTelephonyLVFlagCoverHideSendEndKey );
       
   110 
       
   111     const TPEAudioOutput audioOutput =
       
   112         iStateMachine.PhoneEngineInfo()->AudioOutput();
       
   113 
       
   114     TBool btAvailable = iStateMachine.PhoneEngineInfo()->AudioOutputAvailable(
       
   115         EPEBTAudioAccessory );
       
   116 
       
   117     // Call setup cases
       
   118     if ( EPhoneCallHandlingCallSetupCBA == aResource )
       
   119         {
       
   120         if ( !FeatureManager::FeatureSupported( KFeatureIdTouchCallHandling) )
       
   121             {
       
   122             if ( audioOutput == EPELoudspeaker )
       
   123                 {
       
   124                 resourceId = EPhoneCallHandlingCallSetupToHandsetCBA;
       
   125                 }
       
   126             else if ( audioOutput == EPEHandset )
       
   127                 {
       
   128                 resourceId = EPhoneCallHandlingCallSetupToIhfCBA;
       
   129                 }
       
   130             }
       
   131         }
       
   132 
       
   133     // Is numberentry visible
       
   134     else if ( iState->IsNumberEntryUsedL() )
       
   135         {
       
   136         if ( iState->IsAutoLockOn() || !(iState->IsSimOk()) )
       
   137             {
       
   138             resourceId = EPhoneEmptyBackCBA;
       
   139             }
       
   140         else
       
   141             {
       
   142             TBool dtmfEditorVisible = iViewCommandHandle.HandleCommandL(
       
   143                     EPhoneViewIsDTMFEditorVisible ) ==
       
   144                     EPhoneViewResponseSuccess;
       
   145             TPhoneCmdParamInteger activeCallCount;
       
   146             iViewCommandHandle.ExecuteCommandL(
       
   147                     EPhoneViewGetCountOfActiveCalls, &activeCallCount );
       
   148             
       
   149             TPhoneCmdParamCallStateData callStateData;
       
   150 		    callStateData.SetCallState( EPEStateRinging );
       
   151             iViewCommandHandle.HandleCommandL(
       
   152                     EPhoneViewGetCallIdByState, &callStateData );
       
   153 		    
       
   154             TInt incomingCall = callStateData.CallId();
       
   155 
       
   156             if( dtmfEditorVisible )
       
   157             	{
       
   158                 resourceId = EPhoneDtmfDialerCBA;
       
   159                 }                    
       
   160             else if( activeCallCount.Integer() == ENoActiveCalls )
       
   161                 {
       
   162                 resourceId = EPhoneNumberAcqCBA;
       
   163                 }
       
   164             else if ( activeCallCount.Integer() > ENoActiveCalls &&  
       
   165             		  incomingCall > KErrNotFound )
       
   166 				{
       
   167 				resourceId = EPhoneCallHandlingCallWaitingCBA;
       
   168 				}
       
   169             else
       
   170                 {
       
   171                 resourceId = EPhoneInCallNumberAcqCBA;
       
   172                 }
       
   173             }
       
   174         }
       
   175 
       
   176     // Check is Audio muted
       
   177     else if ( iStateMachine.PhoneEngineInfo()->AudioMute() )
       
   178         {
       
   179         resourceId = EPhoneCallHandlingInCallUnmuteCBA;
       
   180         }
       
   181 
       
   182     // Multicall swap
       
   183     else if ( EPhoneCallHandlingNewCallSwapCBA == aResource )
       
   184         {
       
   185         resourceId = EPhoneCallHandlingNewCallSwapCBA;
       
   186         }
       
   187 
       
   188     // Call waiting cases
       
   189     else if ( EPhoneCallHandlingCallWaitingCBA == aResource )
       
   190         {
       
   191         resourceId = EPhoneCallHandlingCallWaitingCBA;
       
   192         if ( iState->IsSwivelClosed() )
       
   193             {
       
   194             TPhoneCmdParamInteger activeCallCount;
       
   195             iViewCommandHandle.ExecuteCommandL(
       
   196                     EPhoneViewGetCountOfActiveCalls, &activeCallCount );
       
   197             if( activeCallCount.Integer() == EOneActiveCall )
       
   198                 {
       
   199                 resourceId = EPhoneCallHandlingWaitingAnswerSwivelClosedCBA;
       
   200                 }
       
   201             else if( activeCallCount.Integer() == ETwoActiveCalls )
       
   202                 {
       
   203                 resourceId = EPhoneCallHandlingWaitingReplaceSwivelClosedCBA;
       
   204                 }
       
   205             }
       
   206         }
       
   207 
       
   208     // Check is call in hold
       
   209     else if ( hold.Boolean() )
       
   210         {
       
   211         resourceId = EPhoneCallHandlingInCallUnholdCBA;
       
   212         }
       
   213 
       
   214     // Is BT accessory connected
       
   215     else if ( audioOutput == EPEBTAudioAccessory &&
       
   216               IsVoiceCallAlertingOrActiveL() &&
       
   217               !coverHideSendEndKey )
       
   218         {
       
   219         resourceId = EPhoneCallHandlingInCallHandsetCBA;
       
   220         }
       
   221 
       
   222     else if ( audioOutput == EPEWiredAudioAccessory ||
       
   223               coverHideSendEndKey || iState->IsSwivelClosed() )
       
   224         {
       
   225         resourceId = EPhoneCallHandlingInCallNoIhfCBA;
       
   226         }
       
   227 
       
   228     // Check BT availability
       
   229     else if ( audioOutput == EPELoudspeaker )
       
   230         {
       
   231         if ( btAvailable )
       
   232             {
       
   233             resourceId = EPhoneCallHandlingInCallBtaaCBA;
       
   234             }
       
   235         else
       
   236             {
       
   237             resourceId = EPhoneCallHandlingInCallHandsetCBA;
       
   238             }
       
   239         }
       
   240     else if ( audioOutput == EPEHandset &&  btAvailable )
       
   241         {
       
   242         resourceId = EPhoneCallHandlingInCallBtaaCBA;
       
   243         }
       
   244 
       
   245     SetCbaL( resourceId );
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------
       
   249 // CPhoneCbaManager::UpdateIncomingCbaL
       
   250 // -----------------------------------------------------------
       
   251 //
       
   252 EXPORT_C void CPhoneCbaManager::UpdateIncomingCbaL( TInt aCallId )
       
   253     {
       
   254     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneCbaManager::UpdateIncomingCbaL()" );
       
   255 
       
   256     const TBool coverHideSendEndKey =
       
   257         CPhoneCenRepProxy::Instance()->IsTelephonyFeatureSupported(
       
   258             KTelephonyLVFlagCoverHideSendEndKey );
       
   259 
       
   260     const TProfileRingingType ringingType =
       
   261         iStateMachine.PhoneEngineInfo()->RingingType();
       
   262 
       
   263     const TBool callIsAlerting =
       
   264             !(( ringingType == EProfileRingingTypeSilent ) ||
       
   265               ( ringingType == EProfileRingingTypeBeepOnce ));
       
   266 
       
   267     // Update soft reject flag
       
   268     TBool softRejectActivated( ETrue );
       
   269     // VoIP calls do not support sms sending
       
   270     if ( iStateMachine.PhoneEngineInfo()->CallType( aCallId ) == EPECallTypeVoIP 
       
   271     	|| iStateMachine.PhoneEngineInfo()->RemotePhoneNumber( aCallId ).Length() == 0 )
       
   272     	{
       
   273     	softRejectActivated = EFalse;
       
   274     	}
       
   275     TPhoneCmdParamBoolean softRejectParam;
       
   276     softRejectParam.SetBoolean( softRejectActivated );
       
   277     iViewCommandHandle.ExecuteCommandL( EPhoneViewSetSoftRejectFlag,
       
   278         &softRejectParam );
       
   279 
       
   280     TInt incomingCbaResourceId;
       
   281 
       
   282     if ( iState->IsSwivelClosed() )
       
   283         {
       
   284         if ( !callIsAlerting || iRingtoneSilenced )
       
   285             {
       
   286             incomingCbaResourceId = EPhoneCallHandlingIncomingSilentSwivelClosedCBA;
       
   287             }
       
   288         else
       
   289             {
       
   290             incomingCbaResourceId = EPhoneCallHandlingIncomingSwivelClosedCBA;
       
   291             }
       
   292         }
       
   293 
       
   294     else if ( coverHideSendEndKey )
       
   295         {
       
   296         if ( callIsAlerting )
       
   297             {
       
   298             // Set CBA to Options..Silence
       
   299             incomingCbaResourceId = EPhoneCallHandlingIncomingSliderCBA;
       
   300             }
       
   301         else if ( softRejectActivated )
       
   302             {
       
   303             // Set CBA for soft reject
       
   304             incomingCbaResourceId = EPhoneCallHandlingIncomingSoftRejectSliderCBA;
       
   305             }
       
   306         else
       
   307             {
       
   308             // Set CBA to Options..Reject
       
   309             incomingCbaResourceId = EPhoneCallHandlingIncomingSilentSliderCBA;
       
   310             }
       
   311         }
       
   312 
       
   313     else
       
   314         {
       
   315         if ( callIsAlerting )
       
   316             {
       
   317             incomingCbaResourceId = GetIncomingCallSilenceCBA( softRejectActivated );
       
   318             }
       
   319         else if ( softRejectActivated )
       
   320             {
       
   321             // Set CBA for soft reject
       
   322             incomingCbaResourceId = EPhoneCallHandlingIncomingSoftRejectCBA;
       
   323             }
       
   324         else
       
   325             {
       
   326             incomingCbaResourceId = EPhoneCallHandlingIncomingRejectCBA;
       
   327             }
       
   328         }
       
   329 
       
   330     SetCbaL( incomingCbaResourceId );
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------
       
   334 // CPhoneCbaManager::SetCbaL
       
   335 // -----------------------------------------------------------
       
   336 //
       
   337 EXPORT_C void CPhoneCbaManager::SetCbaL( TInt aResource )
       
   338     {
       
   339     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneCbaManager::SetCbaL()" );
       
   340 
       
   341     __PHONELOG1( EBasic, EPhoneControl,
       
   342             "CPhoneCbaManager::SetCbaL : %d",aResource );
       
   343 
       
   344     TPhoneCmdParamInteger integerParam;
       
   345     integerParam.SetInteger(
       
   346         CPhoneMainResourceResolver::Instance()->ResolveResourceID(
       
   347         aResource ) );
       
   348     iViewCommandHandle.ExecuteCommandL( EPhoneViewUpdateCba,
       
   349         &integerParam );
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------
       
   353 // CPhoneCbaManager::UpdateCbaSwivelStateChangedL
       
   354 // -----------------------------------------------------------
       
   355 //
       
   356 void CPhoneCbaManager::UpdateCbaSwivelStateChangedL()
       
   357     {
       
   358     __LOGMETHODSTARTEND(EPhoneControl,"CPhoneCbaManager::UpdateCbaSwivelStateChangedL()" );
       
   359 
       
   360     TPhoneCmdParamCallStateData callStateData;
       
   361     callStateData.SetCallState( EPEStateRinging );
       
   362     iViewCommandHandle.HandleCommandL(
       
   363         EPhoneViewGetCallIdByState, &callStateData );
       
   364     TInt incomingCall = callStateData.CallId();
       
   365 
       
   366     TPhoneCmdParamInteger activeCallCount;
       
   367     iViewCommandHandle.ExecuteCommandL(
       
   368             EPhoneViewGetCountOfActiveCalls, &activeCallCount );
       
   369 
       
   370     if ( incomingCall > KErrNotFound )
       
   371         {
       
   372        if( activeCallCount.Integer() == ENoActiveCalls )
       
   373             {
       
   374             UpdateIncomingCbaL( incomingCall );
       
   375             }
       
   376         else
       
   377             {
       
   378             UpdateCbaL( EPhoneCallHandlingCallWaitingCBA );
       
   379             }
       
   380         }
       
   381     else if ( activeCallCount.Integer() != ENoActiveCalls )
       
   382         {
       
   383         UpdateInCallCbaL();
       
   384         }
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------
       
   388 // CPhoneCbaManager::IsVoiceCallAlertingOrActiveL
       
   389 // -----------------------------------------------------------
       
   390 //
       
   391 TBool CPhoneCbaManager::IsVoiceCallAlertingOrActiveL()
       
   392     {
       
   393     __LOGMETHODSTARTEND( EPhoneControl,
       
   394         "CPhoneCbaManager::IsVoiceCallAlertingOrActiveL()" );
       
   395     TBool retVal = EFalse;
       
   396 
       
   397     // Fetch alerting call's id from view
       
   398     TPhoneCmdParamCallStateData callStateData;
       
   399     callStateData.SetCallState( EPEStateConnecting );
       
   400     iViewCommandHandle.HandleCommandL(
       
   401         EPhoneViewGetCallIdByState, &callStateData );
       
   402 
       
   403     if ( callStateData.CallId() > KErrNotFound )
       
   404         {
       
   405         TPECallType type = iStateMachine.PhoneEngineInfo()->CallType(
       
   406             callStateData.CallId() );
       
   407 
       
   408         if ( EPECallTypeCSVoice == type || EPECallTypeVoIP == type )
       
   409             {
       
   410             retVal = ETrue;
       
   411             }
       
   412         }
       
   413     else
       
   414         {
       
   415         // Fetch active call's id from view
       
   416         TPhoneCmdParamCallStateData callStateData;
       
   417         callStateData.SetCallState( EPEStateConnected );
       
   418         iViewCommandHandle.HandleCommandL(
       
   419             EPhoneViewGetCallIdByState, &callStateData );
       
   420 
       
   421         if ( callStateData.CallId() > KErrNotFound )
       
   422             {
       
   423             TPECallType type = iStateMachine.PhoneEngineInfo()->CallType(
       
   424                  callStateData.CallId() );
       
   425 
       
   426             if ( EPECallTypeCSVoice == type || EPECallTypeVoIP == type )
       
   427                 {
       
   428                 retVal = ETrue;
       
   429                 }
       
   430             }
       
   431         }
       
   432     return retVal;
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------
       
   436 // CPhoneCbaManager::SetRingtoneSilencedStatus
       
   437 // -----------------------------------------------------------
       
   438 //
       
   439 void CPhoneCbaManager::SetRingtoneSilencedStatus( const TBool aSilencedStatus )
       
   440     {
       
   441     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::SetRingtoneSilencedStatus ()" );
       
   442     // Set the internal TBool variable
       
   443     iRingtoneSilenced = aSilencedStatus;
       
   444     __PHONELOG1( 
       
   445             EBasic, 
       
   446             EPhoneControl, 
       
   447             "CPhoneCbaManager::SetRingtoneSilencedStatus - iRingtoneSilenced =%d", 
       
   448             iRingtoneSilenced  );
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------
       
   452 // CPhoneCbaManager::GetIncomingCallSilenceCBA
       
   453 // -----------------------------------------------------------
       
   454 //
       
   455 TInt CPhoneCbaManager::GetIncomingCallSilenceCBA( 
       
   456         const TBool aSoftRejectActivated )
       
   457     {
       
   458     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneCbaManager::GetIncomingCallSilenceCBA ()" );
       
   459     TInt ret = EPhoneCallHandlingIncomingSoftRejectCBA;
       
   460     
       
   461     //Get incoming call touchpane button set
       
   462     TPhoneCmdParamInteger touchpaneButtonsParam;
       
   463     touchpaneButtonsParam.SetInteger( CPhoneMainResourceResolver::Instance()->
       
   464                              ResolveResourceID( EPhoneIncomingCallButtons ) );
       
   465 
       
   466     if ( touchpaneButtonsParam.Integer() 
       
   467          == R_PHONEUI_INCOMING_CALL_SILENCE_BUTTONS )
       
   468         {
       
   469         aSoftRejectActivated ? 
       
   470         ret = EPhoneCallHandlingIncomingSoftRejectCBA:
       
   471         ret = EPhoneCallHandlingIncomingRejectCBA;
       
   472         }
       
   473     else
       
   474         {
       
   475         // Check if the ringtone has been silenced. If it is, then show
       
   476         // "Send Message" in RSK, else show "Silence".
       
   477         iRingtoneSilenced ?
       
   478             ret = EPhoneCallHandlingIncomingSoftRejectCBA :
       
   479             ret = EPhoneCallHandlingIncomingCBA;
       
   480         }
       
   481 
       
   482     // reset the iRingtoneSilence so it won't cause any problems with
       
   483     // next calls.
       
   484     SetRingtoneSilencedStatus( EFalse );
       
   485 
       
   486     return ret;
       
   487     }
       
   488 
       
   489 // ======== LOCAL FUNCTIONS ========
       
   490 
       
   491