phoneapp/phoneuivoipextension/src/cphonestatesinglevoip.cpp
changeset 37 ba76fc04e6c2
child 50 377c906a8701
child 51 f39ed5e045e0
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     1 /*
       
     2 * Copyright (c) 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 CPhoneStateSingleVoIP class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <StringLoader.h>
       
    21 #include <avkon.rsg>
       
    22 #include <mpeengineinfo.h>
       
    23 #include "cphonestatesinglevoip.h"
       
    24 #include "phonelogger.h"
       
    25 #include "cphonecustomizationvoip.h"
       
    26 
       
    27 #include "phoneappvoipcommands.hrh"
       
    28 #include "tphonecmdparaminteger.h"
       
    29 #include "tphonecmdparamboolean.h"
       
    30 #include "tphonecmdparamstring.h"
       
    31 #include "cphonemainresourceresolver.h"
       
    32 #include "phonerssvoip.h"
       
    33 
       
    34 #include "tphonecmdparamselector.h"
       
    35 #include "mphonestatemachine.h"
       
    36 #include "tphonecmdparamcustomdialer.h"
       
    37 #include "cphonetransferdialercontroller.h"
       
    38 #include "tphonecmdparamquery.h"
       
    39 #include "tphonecmdparamglobalnote.h"
       
    40 #include "cphonestateutilsvoip.h"
       
    41 #include "cphonestatemachinevoip.h"
       
    42 
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 //
       
    48 CPhoneStateSingleVoIP::CPhoneStateSingleVoIP( 
       
    49     MPhoneStateMachine& aStateMachine, 
       
    50     MPhoneViewCommandHandle& aViewCommandHandle,
       
    51     MPhoneCustomization& aCustomization ) : 
       
    52     CPhoneSingleCall( &aStateMachine, &aViewCommandHandle, &aCustomization )
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------
       
    57 // CPhoneStateSingleVoIP::~CPhoneStateSingleVoIP()
       
    58 // Destructor
       
    59 // (other items were commented in a header).
       
    60 // -----------------------------------------------------------
       
    61 
       
    62 CPhoneStateSingleVoIP::~CPhoneStateSingleVoIP()
       
    63     { 
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------
       
    67 // CPhoneStateSingleVoIP::ConstructL()
       
    68 // Constructor
       
    69 // (other items were commented in a header).
       
    70 // -----------------------------------------------------------
       
    71 //
       
    72 void CPhoneStateSingleVoIP::ConstructL()
       
    73     {
       
    74     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
    75         "CPhoneStateSingleVoIP::ConstructL()" )
       
    76     CPhoneSingleCall::ConstructL(); 
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------
       
    80 // CPhoneStateSingleVoIP::NewL()
       
    81 // Constructor
       
    82 // (other items were commented in a header).
       
    83 // -----------------------------------------------------------
       
    84 //
       
    85 CPhoneStateSingleVoIP* CPhoneStateSingleVoIP::NewL( 
       
    86     MPhoneStateMachine& aStateMachine, 
       
    87     MPhoneViewCommandHandle& aViewCommandHandle,
       
    88     MPhoneCustomization& aCustomization )
       
    89     {
       
    90     CPhoneStateSingleVoIP* self = new (ELeave) 
       
    91         CPhoneStateSingleVoIP( aStateMachine, aViewCommandHandle, aCustomization );
       
    92     
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL();
       
    95     CleanupStack::Pop( self );
       
    96     
       
    97     return self;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------
       
   101 // CPhoneStateSingleVoIP::HandlePhoneEngineMessageL
       
   102 // -----------------------------------------------------------
       
   103 //
       
   104 void CPhoneStateSingleVoIP::HandlePhoneEngineMessageL( 
       
   105     const TInt aMessage, 
       
   106     TInt aCallId )
       
   107     {
       
   108     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   109         "CPhoneStateSingleVoIP::HandlePhoneEngineMessageL() ")
       
   110     switch ( aMessage )
       
   111         {
       
   112         case MEngineMonitor::EPEMessageUnattendedTransferRequest:
       
   113             LaunchUnattendedTransferAcceptanceQueryL();
       
   114             break;
       
   115         default:
       
   116             CPhoneSingleCall::HandlePhoneEngineMessageL( 
       
   117                 aMessage, aCallId );
       
   118             break;
       
   119         }
       
   120     }
       
   121  
       
   122 // -----------------------------------------------------------
       
   123 // CPhoneStateSingleVoIP::HandleCommandL
       
   124 // -----------------------------------------------------------
       
   125 //
       
   126 TBool CPhoneStateSingleVoIP::HandleCommandL( TInt aCommand )
       
   127     {
       
   128     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   129         "CPhoneStateSingleVoIP::HandleCommandL()" )
       
   130 
       
   131     TBool commandStatus( ETrue );
       
   132 
       
   133     switch( aCommand )
       
   134         {
       
   135         case EPhoneNumberAcqCmdInternetCall:
       
   136             StateUtils().SelectServiceAndDialL();
       
   137             break;
       
   138         
       
   139         case EPhoneNumberAcqCmdSendCommand:
       
   140             StartCallingL();
       
   141             break;
       
   142          
       
   143         case EPhoneCmdAcceptUnattendedTransfer:
       
   144             HandleUnattendedTransferRequestResponseL( ETrue );
       
   145             break;
       
   146         
       
   147         case EPhoneCmdRejectUnattendedTransfer:
       
   148             HandleUnattendedTransferRequestResponseL( EFalse );
       
   149             break;
       
   150         default:
       
   151             commandStatus = CPhoneSingleCall::HandleCommandL( aCommand );
       
   152             break;
       
   153         }
       
   154 
       
   155     return commandStatus;
       
   156     } 
       
   157   
       
   158 // -----------------------------------------------------------
       
   159 // CPhoneStateIdleVoIP::HandleKeyMessageL
       
   160 // -----------------------------------------------------------
       
   161 //
       
   162 void CPhoneStateSingleVoIP::HandleKeyMessageL( 
       
   163     TPhoneKeyEventMessages aMessage,
       
   164     TKeyCode aKeyCode  )
       
   165     {
       
   166     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   167         "CPhoneStateSingleVoIP::HandleKeyMessageL()" )
       
   168     switch ( aKeyCode )
       
   169         {
       
   170         // send-key
       
   171         case EKeyYes:
       
   172             {
       
   173             TPhoneCmdParamInteger numberEntryCountParam;
       
   174             iViewCommandHandle->ExecuteCommandL( EPhoneViewGetNumberEntryCount,
       
   175             &numberEntryCountParam );
       
   176             TInt neLength( numberEntryCountParam.Integer() );
       
   177                  
       
   178             if( IsNumberEntryVisibleL() && neLength )
       
   179                 {
       
   180                 if ( IsOnScreenDialerSupported() &&  
       
   181                      ( IsDTMFEditorVisibleL() ||
       
   182                        IsCustomizedDialerVisibleL() ) )
       
   183                     {
       
   184                     return;
       
   185                     }
       
   186                     
       
   187                 StartCallingL();
       
   188                 }
       
   189             else
       
   190                 {
       
   191                 //Calls ToggleHoldL, if number entry isn't used.
       
   192                 CPhoneSingleCall::HandleKeyMessageL( aMessage, aKeyCode );
       
   193                 }
       
   194             }
       
   195             break;
       
   196             
       
   197         default:
       
   198             CPhoneSingleCall::HandleKeyMessageL( aMessage, aKeyCode );
       
   199             break;
       
   200         }
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------
       
   204 // CPhoneStateSingleVoIP::StartCallingL
       
   205 // -----------------------------------------------------------
       
   206 //
       
   207 void CPhoneStateSingleVoIP::StartCallingL()
       
   208     {
       
   209     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   210         "CPhoneStateSingleVoIP::StartCallingL()" )
       
   211     
       
   212     TUint serviceId( 0 );
       
   213     CPhoneStateUtilsVoip& utililty = StateUtils();
       
   214     if ( utililty.IsVoipPreferredCall( serviceId ) )
       
   215         {
       
   216         utililty.SelectServiceAndDialL( KNullDesC, serviceId );         
       
   217         }
       
   218     else
       
   219         {
       
   220         if ( utililty.IsVoipNumber() )
       
   221             {
       
   222             utililty.SelectServiceAndDialL();
       
   223             }
       
   224         else
       
   225             {
       
   226             if ( IsNumberEntryUsedL() )
       
   227                 {
       
   228                 // handle send key short press
       
   229                 HBufC* phoneNumber = PhoneNumberFromEntryLC();
       
   230                 
       
   231                 if ( !IsSimOk() )
       
   232                     {
       
   233                     iStateMachine->PhoneEngineInfo()->SetPhoneNumber( 
       
   234                             *phoneNumber ) ;
       
   235                     iStateMachine->SendPhoneEngineMessage( 
       
   236                             MPEPhoneModel::EPEMessageCheckEmergencyNumber );
       
   237                     CleanupStack::PopAndDestroy( phoneNumber );
       
   238                     return;
       
   239                     }
       
   240                 
       
   241                 // call the number
       
   242                 iStateMachine->PhoneEngineInfo()->SetPhoneNumber( 
       
   243                         *phoneNumber );
       
   244                 DialVoiceCallL();
       
   245 
       
   246                 CleanupStack::PopAndDestroy( phoneNumber );
       
   247                 }
       
   248             }
       
   249         }
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------
       
   253 // CPhoneStateSingleVoIP::LaunchUnattendedTransferAcceptanceQueryL
       
   254 // Dialog is constructed based on S60 In-Call Operations UI Specification, 
       
   255 // Section 2.26.
       
   256 // -----------------------------------------------------------
       
   257 //
       
   258 void CPhoneStateSingleVoIP::LaunchUnattendedTransferAcceptanceQueryL()
       
   259     {
       
   260     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   261         "CPhoneStateSingleVoIP::LaunchUnattendedTransferAcceptanceQueryL() ")
       
   262     
       
   263     TPhoneCmdParamQuery queryParam;
       
   264     queryParam.SetQueryType( EPhoneGlobalMsgQuery );
       
   265     queryParam.SetCommandParamId( 
       
   266         TPhoneCommandParam::EPhoneParamIdUnattendedTransferAcceptanceQuery );
       
   267     
       
   268     HBufC* msgHeader = 
       
   269         StringLoader::LoadLC( CPhoneMainResourceResolver::Instance()->
       
   270             ResolveResourceID( 
       
   271                 EPhoneVoIPUnattendedTransferAcceptanceQueryHeader ) );
       
   272     queryParam.SetQueryPrompt( *msgHeader );
       
   273     
       
   274     RBuf queryText;
       
   275     CleanupClosePushL( queryText );
       
   276     ResolveUnattendedTransferAcceptanceQueryDialogTextL( queryText );
       
   277     queryParam.SetDataText( &queryText );
       
   278     
       
   279     queryParam.SetDefaultCba( R_AVKON_SOFTKEYS_ACCEPT_REJECT );
       
   280     
       
   281     const TInt KAcceptTransferQueryTimeoutInSec = 7;
       
   282     queryParam.SetTimeOut( KAcceptTransferQueryTimeoutInSec );
       
   283     
       
   284     queryParam.SetTone( EAvkonSIDDefaultSound );
       
   285     
       
   286     // configure custom command mappings for user responses
       
   287     queryParam.SetCbaCommandMapping( 
       
   288         EAknSoftkeyYes, EPhoneCmdAcceptUnattendedTransfer );
       
   289     queryParam.SetCbaCommandMapping( 
       
   290         EAknSoftkeyOk, EPhoneCmdAcceptUnattendedTransfer );
       
   291     queryParam.SetCbaCommandMapping( 
       
   292         EAknSoftkeyNo, EPhoneCmdRejectUnattendedTransfer );
       
   293     queryParam.SetCbaCommandMapping( 
       
   294         EAknSoftkeyCancel, EPhoneCmdRejectUnattendedTransfer );
       
   295     queryParam.SetCustomCommandForTimeOut( EPhoneCmdRejectUnattendedTransfer );
       
   296     
       
   297     iViewCommandHandle->ExecuteCommandL( EPhoneViewShowQuery, &queryParam );
       
   298     
       
   299     CleanupStack::PopAndDestroy( &queryText );
       
   300     CleanupStack::PopAndDestroy( msgHeader );
       
   301     }
       
   302 
       
   303 
       
   304 // -----------------------------------------------------------
       
   305 // CPhoneStateSingleVoIP::ResolveUnattendedTransferAcceptanceQueryDialogTextL
       
   306 // -----------------------------------------------------------
       
   307 //
       
   308 void CPhoneStateSingleVoIP::ResolveUnattendedTransferAcceptanceQueryDialogTextL( 
       
   309         RBuf& aQueryText ) const
       
   310     {
       
   311     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   312     "CPhoneStateSingleVoIP::ResolveUnattendedTransferAcceptanceQueryDialogTextL")
       
   313     
       
   314     aQueryText.Close();
       
   315     
       
   316     MPEEngineInfo* info = iStateMachine->PhoneEngineInfo();
       
   317     const TPEPhoneNumber& transferorAddr = info->RemotePhoneNumber( CallId() );
       
   318     const TPEPhoneNumber& transferTarget = 
       
   319         info->UnattendedTransferTarget( CallId() );
       
   320     
       
   321     if ( KNullDesC() == transferorAddr )
       
   322         {
       
   323         // transfer initiator is anonymous
       
   324         aQueryText.Assign( StringLoader::LoadL( 
       
   325             CPhoneMainResourceResolver::Instance()->ResolveResourceID( 
       
   326                 EPhoneVoIPUnattendedTransferAcceptanceQueryAnonymous ), 
       
   327             transferTarget ) );
       
   328         }
       
   329     else
       
   330         {
       
   331         const TInt KGranularity = 2;
       
   332         CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( KGranularity );
       
   333         CleanupStack::PushL( array );
       
   334         array->AppendL( transferorAddr );
       
   335         array->AppendL( transferTarget );
       
   336         aQueryText.Assign( StringLoader::LoadL( 
       
   337             CPhoneMainResourceResolver::Instance()->ResolveResourceID( 
       
   338                 EPhoneVoIPUnattendedTransferAcceptanceQueryIdentified ), 
       
   339             *array ) );
       
   340         CleanupStack::PopAndDestroy( array );
       
   341         }
       
   342     }
       
   343 
       
   344 
       
   345 // -----------------------------------------------------------
       
   346 // CPhoneStateSingleVoIP::HandleUnattendedTransferRequestResponseL
       
   347 // -----------------------------------------------------------
       
   348 //
       
   349 void CPhoneStateSingleVoIP::HandleUnattendedTransferRequestResponseL( 
       
   350         TBool aRequestAccepted )
       
   351     {
       
   352     __LOGMETHODSTARTEND( PhoneUIVoIPExtension, 
       
   353         "CPhoneStateSingleVoIP::HandleUnattendedTransferRequestResponseL" )
       
   354     
       
   355     iStateMachine->SetCallId( CallId() );
       
   356     
       
   357     if ( aRequestAccepted )
       
   358         {        
       
   359         iStateMachine->SendPhoneEngineMessage( 
       
   360             MPEPhoneModel::EPEMessageAcceptUnattendedTransfer );
       
   361         MPEEngineInfo* info = iStateMachine->PhoneEngineInfo();
       
   362         const TPEPhoneNumber& transferTarget = 
       
   363             info->UnattendedTransferTarget( CallId() );
       
   364  
       
   365         TUint32 serviceId = iStateMachine->PhoneEngineInfo()->
       
   366             ServiceId( CallId() );
       
   367         StateUtils().SelectServiceAndDialL( transferTarget, serviceId );
       
   368         }
       
   369     else
       
   370         {
       
   371         iStateMachine->SendPhoneEngineMessage( 
       
   372             MPEPhoneModel::EPEMessageRejectUnattendedTransfer );
       
   373         }
       
   374     }
       
   375 
       
   376 
       
   377 // -----------------------------------------------------------
       
   378 // CPhoneStateSingleVoIP::StateUtils
       
   379 // -----------------------------------------------------------
       
   380 //
       
   381 CPhoneStateUtilsVoip& CPhoneStateSingleVoIP::StateUtils()
       
   382     {
       
   383     return static_cast<CPhoneStateMachineVoIP&>( 
       
   384         *iStateMachine ).StateUtils();
       
   385     }
       
   386 
       
   387 // End of File