phoneapp/phoneui/src/cphoneappui.cpp
branchRCL_3
changeset 25 5266b1f337bd
equal deleted inserted replaced
24:41a7f70b3818 25:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Application UI class implementation. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <eikenv.h>
       
    21 #include <coemain.h>
       
    22 #include <coehelp.h>
       
    23 #include <bacntf.h>
       
    24 #include <starterclient.h>
       
    25 #include <telinternalpskeys.h>
       
    26 #include <activeidle2domainpskeys.h>
       
    27 #include <telremotepartyinformationpskeys.h>
       
    28 #include <telinformationpskeys.h>
       
    29 #include <UikonInternalPSKeys.h>
       
    30 #include <startupdomainpskeys.h>
       
    31 #include <apgtask.h>
       
    32 #include <apgwgnam.h>
       
    33 #include <barsread.h>
       
    34 #include <coemain.h>
       
    35 #include <AknsConstants.h>   // KAknsMessageSkinChange
       
    36 #include <bautils.h>
       
    37 #include <StringLoader.h>
       
    38 #include <aknnotewrappers.h> // for Notification for startup...
       
    39 #include <eikbtgpc.h>
       
    40 #include <eiksoftkeyimage.h> // EikSoftkeyImage
       
    41 #include <featmgr.h>         // Feature Manager
       
    42 #include <bldvariant.hrh>    // System variant definition
       
    43 #include <phoneui.rsg>
       
    44 #include "phoneui.pan"
       
    45 #include "cphoneappui.h"
       
    46 #include "cphoneapplication.h"
       
    47 #include "cphonedocument.h"
       
    48 #include "cphonekeys.h"
       
    49 #include "cphoneview.h" // from PhoneUIView
       
    50 #include "cphoneviewcontroller.h"
       
    51 #include "cphoneuicontroller.h"
       
    52 #include "cphonepubsubproxy.h"
       
    53 #include "phonelogger.h"
       
    54 #include "phoneconstants.h"
       
    55 #include "cphoneclearblacklist.h"
       
    56 #include "cphonestatuspane.h"
       
    57 #include "tphonecmdparaminteger.h"
       
    58 #ifndef __WINS__
       
    59 #include <f32file.h>
       
    60 #endif
       
    61 
       
    62 
       
    63 // ================= MEMBER FUNCTIONS =======================
       
    64 
       
    65 // ---------------------------------------------------------
       
    66 // CPhoneAppUI::CPhoneAppUI()
       
    67 // Default constructor
       
    68 // (other items were commented in a header).
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 CPhoneAppUI::CPhoneAppUI() : 
       
    72     iAppsReady( EPhoneStartupInitial )
       
    73     {            
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CPhoneAppUI::~CPhoneAppUI()
       
    78 // Destructor
       
    79 // (other items were commented in a header).
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 CPhoneAppUI::~CPhoneAppUI()
       
    83     {
       
    84     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneAppUI::~CPhoneAppUI() ");
       
    85     if ( iPhoneViewController )
       
    86         {
       
    87         RemoveFromStack( iPhoneViewController->PhoneView() );
       
    88         delete iPhoneViewController;
       
    89         }
       
    90     delete iPhoneUIController;
       
    91     
       
    92     CPhoneRecoverySystem::Remove( iStartupSignalRecoveryId );
       
    93 
       
    94     delete iEnvChangeNotifier;
       
    95     iEnvChangeNotifier = NULL;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CPhoneAppUI::ConstructL
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CPhoneAppUI::ConstructL()
       
   103     {
       
   104     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneAppUI::ConstructL() ");
       
   105     // Requires the availability of CBA and Menubar resources
       
   106     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
   107     SetKeyEventFlags( CAknAppUiBase::EDisableSendKeyShort | CAknAppUiBase::EDisableSendKeyLong );
       
   108     
       
   109     // Item specific soft key IS DISABLED in order to make SK1 visible with easy dialing.
       
   110     CEikCba* cba = static_cast<CEikCba*>( CEikButtonGroupContainer::Current()->ButtonGroup() );
       
   111     cba->EnableItemSpecificSoftkey( EFalse );
       
   112     
       
   113     SetAliasKeyCodeResolverL( this );
       
   114     
       
   115     // Set phone application to be system application so it can't be closed
       
   116     iEikonEnv->SetSystem( ETrue );
       
   117 
       
   118     // Disable priority changes of window server and set
       
   119     // process priority (phone app might be on the background
       
   120     // and so it's priority might be low).
       
   121     iEikonEnv->WsSession().ComputeMode( 
       
   122         RWsSession::EPriorityControlDisabled ); 
       
   123     RThread().SetProcessPriority( EPriorityHigh  );
       
   124 
       
   125     // System enviroment change notifier.
       
   126     iEnvChangeNotifier = CEnvironmentChangeNotifier::NewL( 
       
   127         CActive::EPriorityStandard, TCallBack( HandleCallBackL, this ) );
       
   128         
       
   129     iEnvChangeNotifier->Start();
       
   130 
       
   131     iPhoneViewController = CPhoneViewController::NewL( ClientRect() );
       
   132     iPhoneUIController = CPhoneUIController::NewL( *iPhoneViewController );
       
   133 
       
   134     // Blacklist singleton is initialized here
       
   135     // return value is ignored since we do not require its services in this class
       
   136     CPhoneClearBlacklist::CreateL( 
       
   137         iEikonEnv->WsSession(), 
       
   138         *iPhoneViewController->PhoneView()->DrawableWindow() );
       
   139 
       
   140     RegisterViewL( *iPhoneViewController->PhoneView() );
       
   141     AddToStackL( iPhoneViewController->PhoneView(), ECoeStackPriorityDefault );
       
   142 
       
   143     const_cast<CEikAppUi*>( 
       
   144         iEikonEnv->EikAppUi() )->AddViewActivationObserverL( this );
       
   145 
       
   146     // Eikon server window group
       
   147     iEikonServerWgId = 
       
   148         iEikonEnv->WsSession().FindWindowGroupIdentifier( 0, KPhoneEikonServer );
       
   149     __ASSERT_ALWAYS( iEikonServerWgId != KErrNotFound, Panic( EPhoneUiNoWindowGroup ) );
       
   150     iEikonEnv->RootWin().EnableFocusChangeEvents(); 
       
   151     iEikonEnv->RootWin().EnableGroupChangeEvents();
       
   152 
       
   153     // CLI Name.
       
   154     TInt err = RProperty::Define( 
       
   155         KPSUidTelRemotePartyInformation,
       
   156         KTelCLIName,
       
   157         RProperty::EText,
       
   158         KPhoneReadPolicy,
       
   159         KPhoneWritePolicy );
       
   160 
       
   161     __PHONELOG1( 
       
   162         EBasic, 
       
   163         EPhonePhoneapp, 
       
   164         "CPhoneAppUI::ConstructL() - Define CLIName property (status=%d)", 
       
   165         err );
       
   166       
       
   167     // CLI Number.
       
   168     err = RProperty::Define( 
       
   169         KPSUidTelRemotePartyInformation,
       
   170         KTelCLINumber,
       
   171         RProperty::EText,
       
   172         KPhoneReadPolicy,
       
   173         KPhoneWritePolicy );
       
   174 
       
   175     __PHONELOG1( 
       
   176         EBasic, 
       
   177         EPhonePhoneapp, 
       
   178         "CPhoneAppUI::ConstructL() - Define CLINumber property (status=%d)", 
       
   179         err );
       
   180 
       
   181     // Define the top application system property
       
   182     err = RProperty::Define( 
       
   183         KPSUidUikon,
       
   184         KUikVideoCallTopApp,
       
   185         RProperty::EInt,
       
   186         KPhoneReadPolicy,
       
   187         KPhoneWritePolicy );
       
   188 
       
   189     __PHONELOG1( 
       
   190         EBasic, 
       
   191         EPhonePhoneapp, 
       
   192         "CPhoneAppUI::ConstructL() Define top application property (status=%d)", 
       
   193         err );
       
   194 
       
   195     // Startup event signalling
       
   196     // Define the telephony application system property 
       
   197  
       
   198      err = RProperty::Define( 
       
   199         KPSUidTelInformation,
       
   200         KTelPhoneUid,
       
   201         RProperty::EInt,
       
   202         KPhoneReadPolicy,
       
   203         KPhoneWritePolicy );  
       
   204 
       
   205 // DefineNewPSKeys:
       
   206 
       
   207     // UID: KPSUidTelInternalInformation:
       
   208     err = RProperty::Define( 
       
   209         KPSUidTelInternalInformation,
       
   210         KTelRemotePartyContactInfo,
       
   211         RProperty::EByteArray,
       
   212         KPhoneReadPolicy,
       
   213         KPhoneWritePolicy );    
       
   214                
       
   215     // VT UID.
       
   216     err = RProperty::Define( 
       
   217         KPSUidTelInternalInformation,
       
   218         KTelVideoCallUid,
       
   219         RProperty::EInt,
       
   220         KPhoneReadPolicy,
       
   221         KPhoneWritePolicy );
       
   222 
       
   223     // TELINTERNALPSKEY CHANGE 
       
   224     // Move to AudioHandling
       
   225     // UID: KPSUidTelAudioPreference
       
   226     // Call Audio Routing
       
   227     err = RProperty::Define( 
       
   228         KPSUidTelAudioPreference, 
       
   229         KTelAudioOutput, 
       
   230         RProperty::EInt,
       
   231         KPhoneReadPolicyAlwaysPass,
       
   232         KPhoneWritePolicy );
       
   233 
       
   234     // UID: KPSUidNEInformation
       
   235     err = RProperty::Define( 
       
   236         KPSUidNEInformation, 
       
   237         KTelNumberEntryInfo, 
       
   238         RProperty::EInt,
       
   239         KPhoneReadPolicyAlwaysPass,
       
   240         KPhoneWritePolicy );
       
   241 
       
   242     __PHONELOG1( 
       
   243         EBasic, 
       
   244         EPhonePhoneapp, 
       
   245         "CPhoneAppUI::ConstructL() Define phone property (status=%d)", 
       
   246         err );
       
   247            
       
   248     // Add DoStartupSignalL to the recovery system 
       
   249     iStartupSignalRecoveryId = 
       
   250         CPhoneRecoverySystem::Instance()->AddL( 
       
   251             TCallBack( DoStartupSignalL, this ),
       
   252             CTeleRecoverySystem::EPhonePriorityHigh,
       
   253             CTeleRecoverySystem::EPhoneStateIdle );
       
   254 
       
   255     // Call DoStartupSignalL within recovery system
       
   256     const TInt startupState = CPhonePubSubProxy::Instance()->Value(
       
   257         KPSUidStartup,
       
   258         KPSGlobalSystemState );
       
   259 
       
   260     __PHONELOG1( 
       
   261         EBasic, 
       
   262         EPhonePhoneapp, 
       
   263         "CPhoneAppUI::ConstructL() StartupState value", 
       
   264         startupState );
       
   265         
       
   266     if ( startupState == ESwStateCriticalPhaseOK ||
       
   267         startupState == ESwStateEmergencyCallsOnly ||
       
   268         startupState == ESwStateNormalRfOn ||
       
   269         startupState == ESwStateNormalRfOff ||
       
   270         startupState == ESwStateNormalBTSap )
       
   271         {
       
   272         __PHONELOG( 
       
   273             EBasic, 
       
   274             EPhonePhoneapp, 
       
   275             "CPhoneAppUI::ConstructL() Notify Starter that phone is ready..." );
       
   276             
       
   277         CPhoneRecoverySystem::Instance()->RecoverNow(
       
   278             iStartupSignalRecoveryId, 
       
   279             CTeleRecoverySystem::EPhonePriorityHigh );
       
   280         }
       
   281     else
       
   282         {        
       
   283         __PHONELOG( 
       
   284             EBasic, 
       
   285             EPhonePhoneapp, 
       
   286             "CPhoneAppUI::ConstructL() Startup not ready yet. Start listening..." );            
       
   287         CPhonePubSubProxy::Instance()->NotifyChangeL(
       
   288             KPSUidStartup,
       
   289             KPSGlobalSystemState,
       
   290             this );
       
   291         }
       
   292 
       
   293 
       
   294     // THE VERY LAST STEP: DROP PRIORITY.
       
   295     RThread().SetPriority( EPriorityNormal );
       
   296 
       
   297     if ( err == KErrNone || err == KErrAlreadyExists )
       
   298         {
       
   299         // Indicate to the system that the Phone has been started
       
   300         CPhonePubSubProxy::Instance()->ChangePropertyValue(
       
   301             KPSUidTelInformation,
       
   302             KTelPhoneUid,
       
   303             KUidPhoneApplication.iUid );
       
   304         }
       
   305 
       
   306     // Update the Apps ready flag
       
   307     iAppsReady += EPhoneStartedUp;
       
   308     
       
   309     if ( FeatureManager::FeatureSupported( KFeatureIdOnScreenDialer ) )     
       
   310         {
       
   311         iOnScreenDialer = ETrue;   
       
   312         }
       
   313     __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::ConstructL() Phone started..." );
       
   314     __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::ConstructL() done..." );
       
   315     }
       
   316    
       
   317 // -----------------------------------------------------------------------------
       
   318 // CPhoneAppUI::DoStartupSignalL
       
   319 //
       
   320 // Callback function.
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 TInt CPhoneAppUI::DoStartupSignalL( TAny* aAny )
       
   324     {
       
   325     CPhoneAppUI* appUi =
       
   326         static_cast< CPhoneAppUI* >( aAny );
       
   327     
       
   328     return
       
   329         !appUi->iLightIdleReached ?
       
   330             appUi->DoStartupSignalIdleL() :
       
   331             appUi->DoStartupSignalSecurityL();
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CPhoneAppUI::DoStartupSignalIdleL
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 TInt CPhoneAppUI::DoStartupSignalIdleL()
       
   339     {
       
   340     TBool idleReached = EFalse;
       
   341     
       
   342     // Check if Idle application has been started.
       
   343     const TInt idleUid = CPhonePubSubProxy::Instance()->Value(
       
   344             KPSUidAiInformation,
       
   345             KActiveIdleUid );
       
   346 
       
   347     if ( idleUid != 0 && idleUid != KErrNotFound )
       
   348         {
       
   349         // Idle application has already started
       
   350         if ( !( iAppsReady & EPhoneIdleStartedUp ) )
       
   351             {
       
   352             __PHONELOG1( EBasic, EPhonePhoneapp, "CPhoneAppUI::ConstructL() Idle App started (uid=%d)!", idleUid );
       
   353             iAppsReady += EPhoneIdleStartedUp;
       
   354             
       
   355             // Remove Phone application from Fast Swap Window.
       
   356             iPhoneViewController->SetHiddenL( ETrue );
       
   357             
       
   358             // Set Idle's UID to PubSub.
       
   359             CPhonePubSubProxy::Instance()->ChangePropertyValue(
       
   360                 KPSUidUikon,
       
   361                 KUikVideoCallTopApp,
       
   362                 idleUid );
       
   363             }
       
   364         }
       
   365     else
       
   366         {
       
   367         CPhonePubSubProxy::Instance()->NotifyChangeL(
       
   368             KPSUidAiInformation,
       
   369             KActiveIdleUid,
       
   370             this );   
       
   371         }
       
   372 
       
   373     const TInt current = CPhonePubSubProxy::Instance()->Value(
       
   374         KPSUidStartup,
       
   375         KPSGlobalSystemState );
       
   376 
       
   377     __PHONELOG1( EBasic, EPhonePhoneapp, "CPhoneAppUI::DoStartupSignalIdleL() System state=%d", current );
       
   378     if ( current == ESwStateSelfTestOK ||
       
   379         current == ESwStateCriticalPhaseOK )
       
   380         {                       
       
   381         // Check that both the Phone and Idle applications are ready
       
   382         idleReached = ( iAppsReady & EPhoneStartedUp ) &&
       
   383              ( iAppsReady & EPhoneIdleStartedUp );
       
   384 
       
   385         if ( idleReached )
       
   386             {
       
   387             __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::DoStartupSignalIdleL() Phone and Idle apps have both been started" );
       
   388 
       
   389             CPhonePubSubProxy::Instance()->ChangePropertyValue(
       
   390                 KPSUidStartup,
       
   391                 KPSPhonePhase1Ok,
       
   392                 EPhonePhase1Ok );
       
   393             }
       
   394         }
       
   395     else 
       
   396         {
       
   397         idleReached = ( iAppsReady & EPhoneIdleStartedUp ) && 
       
   398             ( current == ESwStateEmergencyCallsOnly ||
       
   399             current == ESwStateNormalRfOn ||
       
   400             current == ESwStateNormalRfOff ||
       
   401             current == ESwStateNormalBTSap );
       
   402 
       
   403         __PHONELOG1( EBasic, EPhonePhoneapp, "CPhoneAppUI::DoStartupSignalIdleL() System state is not at SelfTestOk. Idle reached anyway?=%d", idleReached );
       
   404         }
       
   405 
       
   406     if ( idleReached )
       
   407         {
       
   408         __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::DoStartupSignalIdleL() Idle reached!" );
       
   409         // Now err == KErrNone and it means that
       
   410         // we have succeeded in signalling.
       
   411         CPhoneRecoverySystem::Instance()->EnablePreconditionL();
       
   412 
       
   413         // Update the Phone light idle flag
       
   414         iLightIdleReached = ETrue;
       
   415 
       
   416         // Notify the UI controller that the phone is ready
       
   417         iPhoneUIController->HandlePhoneStartupL();
       
   418         }
       
   419     else 
       
   420         {
       
   421         __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::DoStartupSignalIdleL() Idle is not reached yet!" );
       
   422         // Idle has not been reached yet. Indicate to the recovery
       
   423         // system that this iteration has failed so that it will
       
   424         // try again at a later time.
       
   425         User::Leave( KErrNotReady );
       
   426         }
       
   427 
       
   428     return KErrNone;
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CPhoneAppUI::DoStartupSignalSecurityL
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 TInt CPhoneAppUI::DoStartupSignalSecurityL()
       
   436     {
       
   437     TInt err = KErrNone;    
       
   438     return err;
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------
       
   442 // CPhoneAppUI::HandlePropertyChangedL
       
   443 // -----------------------------------------------------------
       
   444 //
       
   445 void CPhoneAppUI::HandlePropertyChangedL( 
       
   446     const TUid& aCategory,
       
   447     const TUint aKey,
       
   448     const TInt aValue )
       
   449     {
       
   450     __LOGMETHODSTARTEND(EPhoneControl, "CPhoneAppUI::HandlePropertyChangedL( ) ");
       
   451 
       
   452     if ( aCategory == KPSUidAiInformation )
       
   453         {
       
   454         // Call state event
       
   455         if ( aKey == KActiveIdleUid )
       
   456             {
       
   457             __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUi::HandleChangeL() Idle event" );
       
   458             TInt idleUid = aValue;
       
   459             
       
   460             // If idle startup is ok.
       
   461             if ( idleUid != 0 )
       
   462                 {
       
   463                 // If idle startup is ok for the first time, then recover
       
   464                 // the Start signal processing
       
   465                 if ( !( iAppsReady & EPhoneIdleStartedUp ) )
       
   466                     {            
       
   467                     __PHONELOG( EBasic, EPhonePhoneapp, 
       
   468                         "CPhoneAppUI::HandlePropertyChangedL() Idle App started!" );
       
   469                     iAppsReady += EPhoneIdleStartedUp;
       
   470                     // Try to update the startup signal again
       
   471                     CPhoneRecoverySystem::Instance()->RecoverNow(
       
   472                         iStartupSignalRecoveryId, 
       
   473                         CTeleRecoverySystem::EPhonePriorityHigh );    
       
   474                     // Remove Phone application from Fast Swap Window.
       
   475                     iPhoneViewController->SetHiddenL( ETrue );
       
   476                     // Set Idle's UID to PubSub.
       
   477                     CPhonePubSubProxy::Instance()->ChangePropertyValue(
       
   478                         KPSUidUikon,
       
   479                         KUikVideoCallTopApp,
       
   480                         idleUid );
       
   481                     }
       
   482                 }
       
   483             }
       
   484         }
       
   485 
       
   486     if ( aCategory == KPSUidStartup )
       
   487         {
       
   488         __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUi::HandleChangeL() Starter event" );
       
   489         const TInt startupState = CPhonePubSubProxy::Instance()->Value(
       
   490             KPSUidStartup,
       
   491             KPSGlobalSystemState );
       
   492 
       
   493         __PHONELOG1( EBasic, EPhonePhoneapp, "CPhoneAppUI::HandleChangeL() StartupState value", startupState );
       
   494         if ( startupState == ESwStateCriticalPhaseOK ||
       
   495             startupState == ESwStateEmergencyCallsOnly ||
       
   496             startupState == ESwStateNormalRfOn ||
       
   497             startupState == ESwStateNormalRfOff ||
       
   498             startupState == ESwStateNormalBTSap )
       
   499             {
       
   500             // Try to update the startup signal again
       
   501             CPhoneRecoverySystem::Instance()->RecoverNow(
       
   502                 iStartupSignalRecoveryId, 
       
   503                 CTeleRecoverySystem::EPhonePriorityHigh );    
       
   504             }
       
   505         }
       
   506     }
       
   507 
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // CPhoneAppUI::HandleEnvironmentChangeL
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 void CPhoneAppUI::HandleEnvironmentChangeL( const TInt aChanges )
       
   514     {
       
   515     // Pass environment changes to the UI controller
       
   516     iPhoneUIController->HandleEnvironmentChangeL( aChanges );
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CPhoneAppUI::HandleWsEventL
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void CPhoneAppUI::HandleWsEventL( 
       
   524     const TWsEvent& aEvent,
       
   525     CCoeControl* aDestination )
       
   526     {
       
   527     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAppUI::HandleWsEventL" );
       
   528     
       
   529     // Only handle window server events if startup is finished
       
   530     if ( iLightIdleReached )
       
   531         {
       
   532         __PHONELOG3( EBasic, EPhonePhoneapp, "CPhoneAppUI::HandleWsEvent( key(%d), iCode(%d), type(%d) )",
       
   533             aEvent.Key()->iScanCode, aEvent.Key()->iCode, aEvent.Type() );
       
   534 
       
   535         CEikonEnv& eikEnv = *iEikonEnv;
       
   536         CCoeEnv& coeEnv = eikEnv; 
       
   537 
       
   538         const TInt type = aEvent.Type();
       
   539         switch ( type )
       
   540             {
       
   541             case EEventFocusGained:
       
   542                 {
       
   543                 const TInt foregroundApp = 
       
   544                     iPhoneViewController->ForegroundApplicationWindowGroupId();
       
   545                 const TInt thisApplicationWgId = 
       
   546                     iPhoneViewController->ApplicationWindowGroupId();
       
   547                 
       
   548                 if ( thisApplicationWgId != foregroundApp )
       
   549                     {
       
   550                     // Focus gained but phone is not in fore then phone need
       
   551                     // to bring idle to fore if needed.
       
   552                     iPhoneUIController->HandleIdleForegroundEventL();
       
   553                     }
       
   554                 else
       
   555                     {
       
   556                     iPhoneUIController->HandlePhoneForegroundEventL();
       
   557                     }
       
   558                 }
       
   559                 break;
       
   560             
       
   561             case EEventFocusLost:
       
   562                 {
       
   563                 const TInt windowGroupId = 
       
   564                     coeEnv.WsSession().GetFocusWindowGroup();
       
   565                 const TInt foregroundAppWgId = 
       
   566                     iPhoneViewController->ForegroundApplicationWindowGroupId();
       
   567                 const TInt phoneApplicationWgId = 
       
   568                     iPhoneViewController->ApplicationWindowGroupId();
       
   569                 // If phone app is not in fore and we receive focuslost then we
       
   570                 // need to send focus lost event to state which then updates
       
   571                 // FSW to correct state. 
       
   572                 if ( ( foregroundAppWgId != phoneApplicationWgId ) && 
       
   573                         ( windowGroupId != phoneApplicationWgId ) && 
       
   574                         ( windowGroupId != iEikonServerWgId ) )
       
   575                     {
       
   576                     iPhoneUIController->HandlePhoneFocusLostEventL();
       
   577                     }
       
   578                 }
       
   579                 break;
       
   580 
       
   581             case EEventKey:
       
   582                 {
       
   583                 TKeyEvent* keyEvent = aEvent.Key();
       
   584                 
       
   585                 if ( keyEvent->iScanCode == EStdKeyNo )
       
   586                     {
       
   587                     NoKeySpecialHandlingL( *keyEvent, EEventKey );
       
   588                     }
       
   589                     
       
   590                  //will be called if exit number is typed (*#1234#)
       
   591                 if ( keyEvent->iCode == EEikCmdExit )
       
   592                     {
       
   593                     Exit();
       
   594                     return;
       
   595                     }
       
   596                 }
       
   597                 break;
       
   598                 
       
   599             case EEventKeyUp:
       
   600                 {
       
   601                 TKeyEvent* keyEvent = aEvent.Key();
       
   602                 
       
   603                 if ( keyEvent->iScanCode == EStdKeyNo )
       
   604                     {
       
   605                     NoKeySpecialHandlingL( *keyEvent, EEventKeyUp );
       
   606                     }
       
   607                 }
       
   608                 break;
       
   609                 
       
   610             case EEventKeyDown:
       
   611                 {
       
   612                 TKeyEvent* keyEvent = aEvent.Key();
       
   613                 
       
   614                 if ( keyEvent->iScanCode == EStdKeyNo )
       
   615                     {
       
   616                     NoKeySpecialHandlingL( *keyEvent, EEventKeyDown );
       
   617                     }
       
   618                 }
       
   619                 break;
       
   620 
       
   621 
       
   622             default:
       
   623                 break;
       
   624             }            
       
   625         }
       
   626     // All events are sent to base class.
       
   627     CAknAppUi::HandleWsEventL( aEvent, aDestination );
       
   628     }
       
   629 
       
   630 
       
   631 // ---------------------------------------------------------
       
   632 // CPhoneAppUI::NoKeySpecialHandlingL
       
   633 // Handle no key specific cases.
       
   634 // (other items were commented in a header).
       
   635 // ---------------------------------------------------------
       
   636 //
       
   637 void CPhoneAppUI::NoKeySpecialHandlingL( const TKeyEvent& aEvent,
       
   638                                          TEventCode aType  )
       
   639     {
       
   640     CEikonEnv& eikEnv = *iEikonEnv;
       
   641     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAppUI::NoKeySpecialHandling" );
       
   642     
       
   643     // Handle case where menu bar is opened or a blocking dialog is 
       
   644     // displayed and the end key is pressed. HandleKeyEventL will not be 
       
   645     // called in this case so it has to be handled here.
       
   646     if ( eikEnv.AppUiFactory()->MenuBar()->IsDisplayed() ||
       
   647         iPhoneViewController->BlockingDialogIsDisplayed() )
       
   648         {
       
   649         // Send key event to the UI controller
       
   650         iPhoneUIController->HandleKeyEventL( aEvent,  aType );
       
   651         }    
       
   652     }
       
   653 
       
   654 // ---------------------------------------------------------
       
   655 // CPhoneAppUI::HandleKeyEventL
       
   656 // Handle key events.
       
   657 // (other items were commented in a header).
       
   658 // ---------------------------------------------------------
       
   659 //
       
   660 TKeyResponse CPhoneAppUI::HandleKeyEventL(
       
   661     const TKeyEvent& aKeyEvent,
       
   662     TEventCode aType )
       
   663     {
       
   664     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAppUI::HandleKeyEventL" );
       
   665     // Let key event handler handle event. 
       
   666     return iPhoneUIController->HandleKeyEventL( aKeyEvent, aType );
       
   667     }
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // CPhoneAppUI::ProcessCommandL
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 void CPhoneAppUI::ProcessCommandL( TInt aCommand )
       
   674     {
       
   675     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAppUI::ProcessCommandL()" );
       
   676 
       
   677     if( !iPhoneUIController->ProcessCommandL( aCommand ) )
       
   678         {
       
   679         // State didn't handle the command so pass it up
       
   680         CAknAppUi::ProcessCommandL( aCommand );
       
   681         }
       
   682     
       
   683     }
       
   684 
       
   685 // -----------------------------------------------------------------------------
       
   686 // CPhoneAppUI::HandleCommandL
       
   687 // 
       
   688 // Forwards the request to the main view.
       
   689 // -----------------------------------------------------------------------------
       
   690 //
       
   691 void CPhoneAppUI::HandleCommandL( TInt aCommand )
       
   692     {
       
   693     __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAppUI::HandleCommandL()" );
       
   694  
       
   695     switch (aCommand)
       
   696         {
       
   697         case EEikCmdExit:
       
   698             {
       
   699             __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::HandleCommandL -- EEikCmdExit" );
       
   700             Exit();
       
   701             }
       
   702             break;
       
   703         default:
       
   704             {
       
   705             if( !iPhoneUIController->HandleCommandL( aCommand ) )
       
   706                 {
       
   707                 // State didn't handle the command so pass it up
       
   708                 CAknAppUi::HandleCommandL( aCommand );
       
   709                 }
       
   710             }
       
   711             break;
       
   712        }
       
   713     }
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // CPhoneAppUI::DynInitMenuPaneL
       
   717 // 
       
   718 // Forwards the request to the main view.
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 void CPhoneAppUI::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   722     {
       
   723     iPhoneUIController->DynInitMenuPaneL( aResourceId, aMenuPane );
       
   724     }
       
   725 
       
   726 // ---------------------------------------------------------
       
   727 // CPAAppUIS60Base::DynInitMenuBarL
       
   728 // ---------------------------------------------------------
       
   729 //
       
   730 void CPhoneAppUI::DynInitMenuBarL(
       
   731     TInt aResourceId, CEikMenuBar* aMenuBar)
       
   732     {
       
   733     iPhoneUIController->DynInitMenuBarL( aResourceId, aMenuBar );
       
   734     }   
       
   735 
       
   736 // -----------------------------------------------------------------------------
       
   737 // CPhoneAppUI::HandleForegroundEventL
       
   738 // -----------------------------------------------------------------------------
       
   739 //
       
   740 void CPhoneAppUI::HandleForegroundEventL( TBool aForeground )
       
   741     {
       
   742     __PHONELOG1(
       
   743         EBasic,
       
   744         EPhonePhoneapp,
       
   745         "CPhoneAppUI::HandleForegroundEventL( InForeground=%d )",
       
   746         aForeground );
       
   747         
       
   748     iPhoneUIController->HandleForegroundEventL( aForeground );
       
   749 
       
   750     CAknAppUi::HandleForegroundEventL( aForeground );
       
   751     }
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 // CPhoneAppUI::HandleStatusPaneSizeChange
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 void CPhoneAppUI::HandleStatusPaneSizeChange()
       
   758     {
       
   759     __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::HandleStatusPaneSizeChange" );
       
   760     CAknAppUi::HandleStatusPaneSizeChange();
       
   761 
       
   762     LayoutMainView();
       
   763     }
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 // CPhoneAppUI::HandleViewDeactivation
       
   767 // -----------------------------------------------------------------------------
       
   768 //
       
   769 void CPhoneAppUI::HandleViewDeactivation(
       
   770     const TVwsViewId& aViewIdToBeDeactivated, 
       
   771     const TVwsViewId& aNewlyActivatedViewId )
       
   772     {
       
   773     __PHONELOG2(
       
   774         EBasic,
       
   775         EPhonePhoneapp,
       
   776         "CPhoneAppUI::HandleViewDeactivation( aViewIdToBeDeactivated(%d), aNewlyActivatedViewId(%d) )",
       
   777         aViewIdToBeDeactivated.iViewUid, 
       
   778         aNewlyActivatedViewId.iViewUid );
       
   779         
       
   780     CAknAppUi::HandleViewDeactivation( 
       
   781         aViewIdToBeDeactivated, 
       
   782         aNewlyActivatedViewId );
       
   783     }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CPhoneAppUI::HandleApplicationSpecificEventL
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 void CPhoneAppUI::HandleApplicationSpecificEventL(
       
   790     TInt aType,
       
   791     const TWsEvent& aEvent )
       
   792     {
       
   793     __LOGMETHODSTARTEND( EPhonePhoneapp, "CPhoneAppUI::HandleApplicationSpecificEventL" );
       
   794     
       
   795     CAknAppUi::HandleApplicationSpecificEventL( aType, aEvent );
       
   796     }
       
   797 
       
   798 // -----------------------------------------------------------------------------
       
   799 // CPhoneAppUI::HandleResourceChangeL
       
   800 // -----------------------------------------------------------------------------
       
   801 //
       
   802 void CPhoneAppUI::HandleResourceChangeL( TInt aType )
       
   803     {
       
   804     __LOGMETHODSTARTEND( EPhonePhoneapp, "CPhoneAppUI::HandleResourceChangeL" );
       
   805     
       
   806     CAknAppUi::HandleResourceChangeL( aType );
       
   807             
       
   808     if ( aType == KAknsMessageSkinChange || 
       
   809          aType == KEikDynamicLayoutVariantSwitch )
       
   810         {
       
   811         LayoutMainView();
       
   812         iPhoneViewController->HandleResourceChangeL( aType );
       
   813         }
       
   814     }
       
   815 
       
   816 // ---------------------------------------------------------
       
   817 // CPhoneAppUI::HandleViewActivation
       
   818 //  Handles the activation of the view aNewlyActivatedViewId 
       
   819 //  before the old view 
       
   820 //  aViewIdToBeDeactivated is to be deactivated.
       
   821 // (other items were commented in a header).
       
   822 // ---------------------------------------------------------
       
   823 //
       
   824 void CPhoneAppUI::HandleViewActivation( 
       
   825     const TVwsViewId& /*aNewlyActivatedViewId*/, 
       
   826     const TVwsViewId& /*aViewIdToBeDeactivated*/ )
       
   827     {
       
   828      __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::HandleViewActivation" );        
       
   829     }
       
   830 
       
   831 // ---------------------------------------------------------
       
   832 // CPhoneAppUI::HelpContextL
       
   833 // This routine will be called for returning help context
       
   834 // when AppHelpContextL() is called in 
       
   835 // CPhoneViewController::LaunchHelpApplicationL()
       
   836 // ---------------------------------------------------------
       
   837 //
       
   838 CArrayFix<TCoeHelpContext>* CPhoneAppUI::HelpContextL() const
       
   839     {
       
   840     CArrayFix<TCoeHelpContext>* result = 
       
   841         new(ELeave) CArrayFixFlat<TCoeHelpContext>( 1 );
       
   842     
       
   843     CleanupStack::PushL( result );
       
   844     // Get the help context name from the View controller
       
   845     TCoeHelpContext helpContext( KUidPhoneApplication, 
       
   846         iPhoneViewController->HelpContext() ); 
       
   847     result->AppendL( helpContext );
       
   848     CleanupStack::Pop( result );
       
   849 
       
   850     return result; 
       
   851     }
       
   852 
       
   853 // -----------------------------------------------------------------------------
       
   854 // CPhoneAppUi::LayoutMainView
       
   855 // -----------------------------------------------------------------------------
       
   856 //
       
   857 void CPhoneAppUI::LayoutMainView()
       
   858     {
       
   859     __LOGMETHODSTARTEND( EPhonePhoneapp, "CPhoneAppUI::LayoutMainView" );
       
   860     iPhoneViewController->HandleLayoutChange( ClientRect() );
       
   861     }
       
   862 
       
   863 // -----------------------------------------------------------------------------
       
   864 // CPhoneAppUi::GetAliasKeyCode
       
   865 // -----------------------------------------------------------------------------
       
   866 //        
       
   867 TInt CPhoneAppUI::GetAliasKeyCode( TUint& aCode, 
       
   868                                    const TKeyEvent& aKeyEvent,
       
   869                                    TEventCode /*aType*/)
       
   870     {    
       
   871     aCode = aKeyEvent.iCode;
       
   872     return KErrNone;
       
   873     } 
       
   874 
       
   875 
       
   876 // -----------------------------------------------------------------------------
       
   877 // CPhoneAppUI::HandleCallBackL
       
   878 // Called when the observed value changes
       
   879 //
       
   880 // Callback function.
       
   881 // -----------------------------------------------------------------------------
       
   882 //
       
   883 TInt CPhoneAppUI::HandleCallBackL( TAny* aAny )
       
   884     {
       
   885     __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::HandleCallBackL" );
       
   886     CPhoneAppUI* appUi =
       
   887         static_cast< CPhoneAppUI* >( aAny );
       
   888     appUi->DoHandleCallBackL();
       
   889     return KErrNone;
       
   890     }
       
   891     
       
   892 // -----------------------------------------------------------------------------
       
   893 // CPhoneAppUI::DoHandleCallBackL
       
   894 // Call back to a specific instance.
       
   895 // -----------------------------------------------------------------------------
       
   896 //
       
   897 void CPhoneAppUI::DoHandleCallBackL()
       
   898     {
       
   899     __PHONELOG( EBasic, EPhonePhoneapp, "CPhoneAppUI::DoHandleCallBackL" );
       
   900     const TInt change = iEnvChangeNotifier->Change();
       
   901     HandleEnvironmentChangeL( change );
       
   902     }
       
   903         
       
   904 //  End of File