vtuis/videotelui/src/tvtuiappstatebase.cpp
branchRCL_3
changeset 35 779871d1e4f4
equal deleted inserted replaced
34:f15ac8e65a02 35:779871d1e4f4
       
     1 /*
       
     2 * Copyright (c) 2007 - 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:  base class for application states
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tvtuiappstates.h"
       
    20 #include "videotelui.hrh"
       
    21 #include "tvtuistates.h"
       
    22 #include "cvtuiappshutter.h"
       
    23 #include "mvtuistatecontext.h"
       
    24 #include <videotelui.rsg>
       
    25 #include <AknQueryDialog.h>
       
    26 #include <StringLoader.h>
       
    27 #include <cvtlogger.h>
       
    28 #include <cvtengmodel.h>
       
    29 #include <vtengevents.h>
       
    30 #include <mvtengcommandhandler.h>
       
    31 #include <coreapplicationuisdomainpskeys.h>
       
    32 
       
    33 // By default call ending command is allowed to send to call handling.
       
    34 
       
    35 // Initially no shutdown request
       
    36 TBool TVtUiAppStateBase::iShutdownRequested = EFalse;
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // c++ constructor
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 TVtUiAppStateBase::TVtUiAppStateBase(
       
    43     MVtUiStateContext& aCtx,
       
    44     TVtUiStates& aUiStates ) : iCtx(aCtx), iUiStates( aUiStates )
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // Destructor
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 TVtUiAppStateBase::~TVtUiAppStateBase()
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // TVtUiAppStateBase::AppUiStartupPhase1DoneL
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void TVtUiAppStateBase::AppUiStartupPhase1DoneL()
       
    61     {
       
    62     // no default behavior
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // TVtUiAppStateBase::AppUiStartupPhase2DoneL
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void TVtUiAppStateBase::AppUiStartupPhase2DoneL()
       
    70     {
       
    71     // no default behavior
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // TVtUiAppStateBase::ShutdownDoneL
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void TVtUiAppStateBase::ShutdownDoneL()
       
    79     {
       
    80     // no default behavior
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // TVtUiAppStateBase::HandleForegroundChangedL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 TBool TVtUiAppStateBase::HandleForegroundChangedL(
       
    88     const TBool /*aIsForegroung*/ )
       
    89     {
       
    90     // no default behavior
       
    91     return EFalse;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // TVtUiAppStateBase::PreHandleForegroundChangedL
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TBool TVtUiAppStateBase::PreHandleForegroundChangedL(
       
    99     const TBool /*aIsForegroung*/ )
       
   100     {
       
   101     // no default behavior
       
   102     return EFalse;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // TVtUiAppStateBase::StartDtmfTone
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void TVtUiAppStateBase::StartDtmfTone( const TChar& /*aTone*/ )
       
   110     {
       
   111     // no default behavior
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // TVtUiAppStateBase::StopDtmfTone
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void TVtUiAppStateBase::StopDtmfTone()
       
   119     {
       
   120     // no default behavior
       
   121     }
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // TVtUiAppStateBase::SetInitialStateL
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void TVtUiAppStateBase::SetInitialStateL(
       
   129     MVtUiStateContext& aCtx,
       
   130     TVtUiStates& aUiStates )
       
   131     {
       
   132     __VTPRINTENTER( "TVtUiAppStateBase.SetInitialState" )
       
   133     TVtUiAppStateBase* initialState =
       
   134         TVtUiStateStarting::InstanceL( aCtx, aUiStates );
       
   135     aCtx.ChangeState( initialState );
       
   136     initialState->OpenL();
       
   137     __VTPRINTEXIT( "TVtUiAppStateBase.SetInitialState" )
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // TVtUiAppStateBase::ShutdownRequested
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 TBool TVtUiAppStateBase::ShutdownRequested()
       
   145     {
       
   146     return iShutdownRequested;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // TVtUiAppStateBase::AppUiStartupFailedL
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void TVtUiAppStateBase::AppUiStartupFailedL()
       
   154     {
       
   155     __VTPRINTENTER( "TVtUiAppStateBase.AppUiStartupFailedL" )
       
   156     // Shutdown
       
   157     ChangeStateL( *TVtUiStateResetting::InstanceL( iCtx, iUiStates ) );
       
   158     __VTPRINTEXIT( "TVtUiAppStateBase.AppUiStartupFailedL" )
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // TVtUiAppStateBase::OpenL
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void TVtUiAppStateBase::OpenL()
       
   166     {
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // TVtUiAppStateBase::Close
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void TVtUiAppStateBase::Close()
       
   174     {
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // TVtUiAppStateBase::ChangeStateL
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void TVtUiAppStateBase::ChangeStateL( TVtUiAppStateBase& aNewState )
       
   182     {
       
   183     __VTPRINTENTER( "TVtUiAppStateBase.ChangeStateL" )
       
   184 
       
   185     // Check for transition to already active state.
       
   186     TVtUiAppStateBase* state = &aNewState;
       
   187     if ( state == this )
       
   188         {
       
   189         __VTPRINTEXITR( "TVtUiAppStateBase.ChangeStateL %d", 0 )
       
   190         return;
       
   191         }
       
   192     const TVtEngCommandId pending =
       
   193         iCtx.Model().CommandHandler().PendingCommand();
       
   194     if ( pending !=  KVtEngCommandNone &&
       
   195          state == TVtUiStateResetting::InstanceL( iCtx, iUiStates ) )
       
   196         {
       
   197         // delay shutdown until engine command completes
       
   198         __VTPRINT2( DEBUG_GEN, "TVtUiAppStateBase.ChangeStateL, pengind command is: %d", pending );
       
   199         TVtUiAppStateBase::iShutdownRequested = ETrue;
       
   200 
       
   201         if ( pending == KVtEngInitializeShareImage )
       
   202             {
       
   203             iCtx.Model().CommandHandler().CancelCommand( pending );
       
   204             }
       
   205 
       
   206         __VTPRINTEXITR( "TVtUiAppStateBase.ChangeStateL %d", KErrNotReady )
       
   207         return;
       
   208         }
       
   209     __VTPRINT( DEBUG_GEN,
       
   210         " TVtUiAppStateBase.ChangeStateL !! STATE TRANSITION !!" )
       
   211     iCtx.ChangeState( &aNewState );
       
   212     Close();
       
   213     // perform entry action for new state
       
   214     aNewState.OpenL();
       
   215     __VTPRINTEXITR( "TVtUiAppStateBase.ChangeStateL %d", 1 )
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // TVtUiAppStateBase::CleanupResetPushL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void TVtUiAppStateBase::CleanupResetPushL()
       
   223     {
       
   224     // Shutdown if leave occurs in critical ops.
       
   225     CleanupStack::PushL(
       
   226         TCleanupItem( TransitionToReset, this ) );
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // TVtUiAppStateBase::TransitionToReset
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void TVtUiAppStateBase::TransitionToReset( TAny* aAny )
       
   234     {
       
   235     TVtUiAppStateBase* state = reinterpret_cast< TVtUiAppStateBase* >( aAny );
       
   236     TRAP_IGNORE( state->ChangeStateL( *TVtUiStateResetting::InstanceL(
       
   237         state->iCtx, state->iUiStates ) ) );
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // TVtUiAppStateBase::HandleVTCommandPerformedL
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 TVtUiAppStateBase::TEventResponse TVtUiAppStateBase::HandleVTCommandPerformedL(
       
   245             TVtEngCommandId /*aCommand*/,
       
   246             const TInt /*aError*/ )
       
   247     {
       
   248     __VTPRINTENTER( "TVtUiAppStateBase.HandleVTCommandPerformedL" )
       
   249     // By default all UI is allowed to handle all command completions.
       
   250     TEventResponse handled = EEventNotHandled;
       
   251 
       
   252     // check if shutdown requested while command was pending
       
   253     const TVtEngCommandId pending = iCtx.Model().CommandHandler().PendingCommand();
       
   254     if ( pending == KVtEngCommandNone &&
       
   255           TVtUiAppStateBase::iShutdownRequested )
       
   256         {
       
   257         __VTPRINT( DEBUG_GEN, "Handling delayed shutdown" );
       
   258         ChangeStateL( *TVtUiStateResetting::InstanceL(
       
   259             iCtx, iUiStates ) );
       
   260         }
       
   261     __VTPRINTEXIT( "TVtUiAppStateBase.HandleVTCommandPerformedL" )
       
   262     return handled;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // TVtUiAppStateBase::HandleVtEventL
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 TVtUiAppStateBase::TEventResponse TVtUiAppStateBase::HandleVtEventL(
       
   270     const TInt aEvent )
       
   271     {
       
   272     __VTPRINTENTER( "TVtUiAppStateBase.HandleVtEventL" )
       
   273     TEventResponse handled = EEventHandled;
       
   274     switch ( aEvent )
       
   275         {
       
   276     case KVtEngDeviceLockOn:
       
   277     case KVtEngDeviceLockOff:
       
   278         HandleDeviceLockEventL( aEvent == KVtEngDeviceLockOn );
       
   279         break;
       
   280     case KVtEngRemoteDisconnect:
       
   281         /** Don't allow sending of end active call command to call handling
       
   282          *  because requesting disconnect from the network after NW originated
       
   283          *  termination violates standards.
       
   284          */
       
   285         break;
       
   286     default:
       
   287         handled = EEventNotHandled;
       
   288         break;
       
   289         }
       
   290     __VTPRINTEXIT( "TVtUiAppStateBase.HandleVtEventL" )
       
   291     return handled;
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // TVtUiAppStateBase::HandleCommandL
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 TVtUiAppStateBase::TEventResponse TVtUiAppStateBase::HandleCommandL(
       
   299     const TInt /*aCommand*/ )
       
   300     {
       
   301     __VTPRINTENTER( "TVtUiAppStateBase.HandleCommandL" )
       
   302     TEventResponse handled = EEventNotHandled;
       
   303     __VTPRINTEXITR( "TVtUiAppStateBase.HandleCommandL %d", handled )
       
   304     return handled;
       
   305     }
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // TVtUiAppStateBase::HandleLayoutChangedL
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 void TVtUiAppStateBase::HandleLayoutChangedL( )
       
   312     {
       
   313     __VTPRINTENTER( "TVtUiAppStateBase.HandleLayoutChangedL" )
       
   314     // By default only indicate that layout change needs to be handled.
       
   315     iUiStates.SetLayoutChangeNeeded( ETrue );
       
   316     __VTPRINTEXIT( "TVtUiAppStateBase.HandleLayoutChangedL" )
       
   317     }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // TVtUiAppStateBase::HandleShutdownReady
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 void TVtUiAppStateBase::HandleShutdownReady()
       
   324     {
       
   325      __VTPRINTENTER( "TVtUiAppStateBase.HandleShutdownReady" )
       
   326     // forwarded to AppUi which handles UI framework exit
       
   327     iCtx.HandleShutdownReady();
       
   328     iCtx.ChangeState( NULL );
       
   329     // deletes current state
       
   330     Close();
       
   331      __VTPRINTEXIT( "TVtUiAppStateBase.HandleShutdownReady" )
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // TVtUiAppStateBase::HandleDeviceLockEventL
       
   336 //
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 void TVtUiAppStateBase::HandleDeviceLockEventL( const TBool aDeviceIsLocked )
       
   340     {
       
   341     __VTPRINTENTER( "TVtUiAppStateBase.HandleDeviceLockEventL" )
       
   342     iUiStates.SetDeviceLockOn( aDeviceIsLocked );
       
   343     if ( aDeviceIsLocked )
       
   344         {
       
   345         iCtx.ChangeApplicationFocus( EFalse );
       
   346         }
       
   347     __VTPRINTEXITR( "TVtUiAppStateBase.HandleDeviceLockEventL lock state=%d",
       
   348         aDeviceIsLocked )
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // TVtUiAppStateBase::CheckEndActiveCallL
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 TBool TVtUiAppStateBase::CheckEndActiveCallL()
       
   356     {
       
   357     __VTPRINTENTER( "TVtUiAppStateBase.CheckEndActiveCallL" )
       
   358     const MVtEngSessionInfo::TSessionState state = SessionState( EFalse );
       
   359     TBool shutdownStarted( EFalse );
       
   360     if ( state == MVtEngSessionInfo::EIdle )
       
   361         {
       
   362         __VTPRINT( DEBUG_GEN, "VtUi.Release bearer" )
       
   363         // h.245 session is ended
       
   364         ChangeStateL( *TVtUiStateResetting::InstanceL( iCtx, iUiStates ) );        
       
   365         shutdownStarted = ETrue;
       
   366         }
       
   367     __VTPRINTEXITR( "TVtUiAppStateBase.CheckEndActiveCallL %d",
       
   368         shutdownStarted )
       
   369     return shutdownStarted;
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // TVtUiAppStateBase::SessionState
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 MVtEngSessionInfo::TSessionState TVtUiAppStateBase::SessionState(
       
   377     const TBool aUpdate ) const
       
   378     {
       
   379     const CVtEngModel& model = iCtx.Model();
       
   380     const MVtEngSessionInfo& session = model.Session();
       
   381     return session.State( aUpdate );
       
   382     }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // TVtUiAppStateBase::SetLightsState
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 void TVtUiAppStateBase::SetLightsState( const TBool aOn )
       
   389     {
       
   390     __VTPRINTENTER( "TVtUiAppStateBase.SetLightsState" )
       
   391     const TInt value = aOn ? EForcedLightsOn : EForcedLightsOff;
       
   392     RProperty::Set(
       
   393             KPSUidCoreApplicationUIs,
       
   394             KLightsVTForcedLightsOn,
       
   395             value );
       
   396     __VTPRINTEXIT( "TVtUiAppStateBase.SetLightsState" )
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // TVtUiAppStateBase::SetExecState
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void TVtUiAppStateBase::SetExecState( const TVtUiStates::TVtUiExecState aState )
       
   404     {
       
   405     __VTPRINTENTER( "TVtUiAppStateBase.SetExecState" )
       
   406     iUiStates.SetExecState( aState );
       
   407     __VTPRINTEXITR( "TVtUiAppStateBase.SetExecState %d", aState )
       
   408     }