vtuis/videotelui/src/tvtuistaterunning.cpp
changeset 0 ed9695c8bcbe
child 8 07d1685f0cd4
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     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:  running (normal operation) application state
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tvtuistates.h"
       
    20 #include "tvtuiappstates.h"
       
    21 #include "mvtuistatecontext.h"
       
    22 #include "cvtuiappshutter.h"
       
    23 #include "videotelui.hrh"
       
    24 #include <cvtlogger.h>
       
    25 #include <vtengevents.h>
       
    26 #include <stringloader.h>
       
    27 #include <aknquerydialog.h>
       
    28 #include <videotelui.rsg>
       
    29 
       
    30 TVtUiStateRunning* TVtUiStateRunning::iInstance = NULL;
       
    31 
       
    32 // c++ constructor
       
    33 TVtUiStateRunning::TVtUiStateRunning(
       
    34     MVtUiStateContext& aCtx, TVtUiStates& aUiStates )
       
    35     : TVtUiAppStateBase( aCtx, aUiStates ), iCreateVoiceCallDlg( NULL )
       
    36     {
       
    37     }
       
    38 
       
    39 // Destructor
       
    40 TVtUiStateRunning::~TVtUiStateRunning()
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // TVtUiStateRunning::InstanceL
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 TVtUiStateRunning * TVtUiStateRunning::InstanceL(
       
    49     MVtUiStateContext& aCtx,
       
    50     TVtUiStates& aUiStates )
       
    51     {
       
    52     __VTPRINTENTER( "UiStateRunning.InstanceL" )
       
    53     if ( iInstance == NULL )
       
    54         iInstance = new ( ELeave ) TVtUiStateRunning( aCtx, aUiStates );
       
    55     __VTPRINTEXIT( "UiStateRunning.InstanceL" )
       
    56     return iInstance;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // TVtUiStateRunning::HandleVtEventL
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 TVtUiAppStateBase::TEventResponse TVtUiStateRunning::HandleVtEventL(
       
    64     const TInt aEvent )
       
    65     {
       
    66     __VTPRINTENTER( "UiStateRunning.HandleVtEventL" )
       
    67     // let TVtUiAppStateBase base class do common tasks
       
    68     TEventResponse handled = TVtUiAppStateBase::HandleVtEventL( aEvent );
       
    69     switch ( aEvent )
       
    70         {
       
    71     case KVtEngDeviceLockOn:
       
    72     case KVtEngDeviceLockOff:
       
    73         TVtUiAppStateBase::HandleVtEventL( aEvent );
       
    74         if ( aEvent == KVtEngDeviceLockOff )
       
    75             {
       
    76             iCtx.ChangeApplicationFocus( ETrue );
       
    77             }
       
    78         break;
       
    79     case KVtEngSessionStateChanged:
       
    80         if ( CheckEndActiveCallL() )
       
    81             {
       
    82             // At this point shutdown is in progress. Don't allow
       
    83             // appUi to do actions due to this event.
       
    84             handled = EEventHandled;
       
    85             }
       
    86         break;
       
    87     default:
       
    88         break;
       
    89         }
       
    90     __VTPRINTEXIT( "UiStateRunning.HandleVtEventL" )
       
    91     return handled;
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // TVtUiStateRunning::HandleCommandL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TVtUiAppStateBase::TEventResponse TVtUiStateRunning::HandleCommandL(
       
   100     const TInt aCommand )
       
   101     {
       
   102     __VTPRINTENTER( "UiStateRunning.HandleCommandL" )
       
   103     /** By default all commands are enabled by running state.
       
   104       * Other details command validations are done elsewhere
       
   105       */
       
   106     TEventResponse handled = EEventHandled;
       
   107     switch ( aCommand )
       
   108         {
       
   109     case EVtUiCmdEndActiveCall:
       
   110         ShutdownWithEngineCommandL( KVtEngTerminateSession );
       
   111         break;
       
   112     case EVtUiCmdCreateVoice:
       
   113         CreateVoiceCallL();
       
   114         break;
       
   115     case EVtUiCmdDialEmergency:
       
   116         // Attempt emergency call. Note that emergency number check is done
       
   117         // after calling DialEmergencyCallL and if supplied number is not
       
   118         // emergency leave occurs.
       
   119         TRAP_IGNORE( DialEmergencyCallL() );
       
   120         break;
       
   121     default:
       
   122         handled = TVtUiAppStateBase::HandleCommandL( aCommand );
       
   123         break;
       
   124         }
       
   125     __VTPRINTEXITR( "UiStateRunning.HandleCommandL %d", handled )
       
   126     return handled;
       
   127     }
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // TVtUiStateRunning::HandleForegroundChangedL
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TBool TVtUiStateRunning::HandleForegroundChangedL( const TBool aIsForeground )
       
   135     {
       
   136     __VTPRINTENTER( "UiStateRunning.HandleForegroundChangedL" )
       
   137 
       
   138     // Closes create voice call dialog if it is open
       
   139     delete iCreateVoiceCallDlg; iCreateVoiceCallDlg = NULL;
       
   140 
       
   141     SetLightsState( aIsForeground );
       
   142 
       
   143     iCtx.RefreshL( MVtUiStateContext::ENaviPane );
       
   144 
       
   145     TBool handleAsForeground( aIsForeground );
       
   146     TPtrC8 params( reinterpret_cast< TUint8* >( &handleAsForeground ),
       
   147         sizeof( TBool ) );
       
   148     iCtx.DoExecuteCmdL( KVtEngSetUIForeground, &params );
       
   149     __VTPRINTEXIT( "UiStateRunning.HandleForegroundChangedL" )
       
   150     return handleAsForeground;
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // TVtUiStateRunning::PreHandleForegroundChangedL
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool TVtUiStateRunning::PreHandleForegroundChangedL( const TBool aIsForeground )
       
   158     {
       
   159     __VTPRINTENTER( "UiStateRunning.PreHandleForegroundChangedL" )
       
   160     TBool handleAsForeground( aIsForeground );
       
   161     TPtrC8 params( reinterpret_cast< TUint8* >( &handleAsForeground ), sizeof( TBool ) );
       
   162     iCtx.DoExecuteCmdL( KVtEngSetUIForeground, &params );
       
   163     __VTPRINTEXIT( "UiStateRunning.PreHandleForegroundChangedL" )
       
   164     return handleAsForeground;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // TVtUiStateRunning::HandleLayoutChangedL
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void TVtUiStateRunning::HandleLayoutChangedL( )
       
   172     {
       
   173     __VTPRINTENTER( "UiStateRunning.HandleLayoutChangedL" )
       
   174     iUiStates.SetLayoutChangeNeeded( EFalse );
       
   175     iCtx.DoHandleLayoutChangedL();
       
   176     __VTPRINTEXIT( "UiStateRunning.HandleLayoutChangedL" )
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // TVtUiStateRunning::StartDtmfTone
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void TVtUiStateRunning::StartDtmfTone( const TChar& aTone )
       
   184     {
       
   185     iCtx.StartDtmfTone( aTone );
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // TVtUiStateRunning::StopDtmfTone
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void TVtUiStateRunning::StopDtmfTone()
       
   193     {
       
   194     iCtx.StopDtmfTone();
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // TVtUiStateRunning::CreateVoiceCallL
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void TVtUiStateRunning::CreateVoiceCallL()
       
   202     {
       
   203     __VTPRINTENTER( "TVtUiStateRunning.CreateVoiceCallL" )
       
   204     HBufC* prompt =
       
   205     	StringLoader::LoadLC( R_VIDEOTELUI_QTN_QUERY_CREATE_VOICE_CALL );
       
   206 
       
   207     // Create and initialize query dialog
       
   208     CAknQueryDialog* createVoiceCallDlg = CAknQueryDialog::NewL();
       
   209     CleanupStack::PushL( createVoiceCallDlg );
       
   210     createVoiceCallDlg->SetPromptL( *prompt );
       
   211     CleanupStack::Pop(); // createVoiceCallDlg
       
   212 
       
   213     iCreateVoiceCallDlg = createVoiceCallDlg;
       
   214     TInt result( KErrNone );
       
   215     TRAPD( error, result = iCreateVoiceCallDlg->ExecuteLD(
       
   216         R_VIDEOTELUI_CREATE_VOICE_QUERY ) );
       
   217     // Just set to NULL because ExecuteLD() deletes instance
       
   218     iCreateVoiceCallDlg = NULL;
       
   219     // Leave if ExecuteLD() left
       
   220     User::LeaveIfError( error );
       
   221     CleanupStack::PopAndDestroy( ); // prompt
       
   222     if ( result )
       
   223         {
       
   224         //user answered yes
       
   225 		iCtx.DoExecuteCmdL( KVtEngSwitchToVoice, NULL );
       
   226         }
       
   227     __VTPRINTEXITR( "TVtUiAppStateBase.CreateVoiceCallL %d", result )
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // TVtUiStateRunning::ShutdownWithEngineCommandL
       
   232 // Starts shutdown with command to engine.
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void TVtUiStateRunning::ShutdownWithEngineCommandL( const TInt aCommand )
       
   236     {
       
   237     __VTPRINTENTER(
       
   238         "TVtUiStateRunning.ShutdownWithEngineCommandL" )
       
   239     TVtUiAppStateBase* resetState =
       
   240         TVtUiStateResetting::InstanceL( iCtx, iUiStates, aCommand ); 
       
   241     CVtUiAppShutter* shutter = CVtUiAppShutter::InstanceL( *resetState );
       
   242     if ( shutter )
       
   243         {
       
   244         // open resetting state, handles engine command request/reply
       
   245         ChangeStateL( *resetState );
       
   246 #ifdef _DEBUG
       
   247         __VTPRINTEXIT(
       
   248             "TVtUiStateRunning.ShutdownWithEngineCommandL 1" )
       
   249         return;
       
   250 #endif
       
   251         }    
       
   252        
       
   253     __VTPRINTEXIT(
       
   254         "TVtUiStateRunning.ShutdownWithEngineCommandL 0" )
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // TVtUiStateRunning::DialEmergencyCallL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void TVtUiStateRunning::DialEmergencyCallL()
       
   262     {
       
   263     __VTPRINTENTER(
       
   264         "TVtUiStateRunning.DialEmergencyCallL" )
       
   265     TVtUiAppStateBase* resetState =
       
   266         TVtUiStateResetting::InstanceL( iCtx, iUiStates );
       
   267     CVtUiAppShutter* shutter = CVtUiAppShutter::InstanceL( *resetState );
       
   268     if ( shutter )
       
   269         {
       
   270         // Make emergency call and proceed when 1) state has given permission 
       
   271         // and 2) callback from emergency call api is received
       
   272         shutter->ShutdownWithEmergencyCallL( iCtx );
       
   273         ChangeStateL( *resetState );
       
   274         }
       
   275     __VTPRINTEXIT( "TVtUiStateRunning.DialEmergencyCallL" )
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // TVtUiStateRunning::OpenL
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void TVtUiStateRunning::OpenL()
       
   283     {
       
   284     __VTPRINTENTER( "TVtUiStateRunning.OpenL" )
       
   285     SetExecState( TVtUiStates::EExecStateRunning );
       
   286     iCtx.RefreshStatesL();
       
   287     __VTPRINTEXIT( "TVtUiStateRunning.OpenL" )
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // TVtUiStateRunning::Close
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void TVtUiStateRunning::Close()
       
   295     {
       
   296     __VTPRINTENTER( "TVtUiStateRunning.Close" )
       
   297     if ( TVtUiStateRunning::iInstance )
       
   298         {
       
   299         delete TVtUiStateRunning::iInstance;
       
   300         TVtUiStateRunning::iInstance = NULL;
       
   301         }
       
   302     __VTPRINTEXIT( "TVtUiStateRunning.Close" )
       
   303     }