idlefw/src/idleint/aiuiidleintegration.cpp
branchRCL_3
changeset 114 a5a39a295112
equal deleted inserted replaced
113:0efa10d348c0 114:a5a39a295112
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Idle integration
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System includes
       
    20 #include <startupdomainpskeys.h>
       
    21 #include <coeaui.h>
       
    22 #include <eikenv.h>
       
    23 #include <AknIncallBubbleNotify.h>
       
    24 #include <aknsoundsystem.h>
       
    25 #include <AknDef.h>
       
    26 #include <ctsydomainpskeys.h>
       
    27 #include <apgtask.h>
       
    28 
       
    29 
       
    30 // User includes
       
    31 #include <aisystemuids.hrh>
       
    32 #include <aiutility.h>
       
    33 #include <aipspropertyobserver.h>
       
    34 #include "activeidle2domainpskeys.h"
       
    35 #include "aiuiidleintegrationimpl.h"
       
    36 #include "aifweventhandler.h"
       
    37 #include "aistate.h"
       
    38 #include "aifwpanic.h"
       
    39 #include "debug.h"
       
    40 
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 // ----------------------------------------------------------------------------
       
    45 // CAiUiIdleIntegrationImpl::NewL()
       
    46 // ----------------------------------------------------------------------------
       
    47 //
       
    48 CAiUiIdleIntegrationImpl* CAiUiIdleIntegrationImpl::NewL( CEikonEnv& aEikEnv,         
       
    49     const TAiIdleKeySoundConfig& aKeySoundConfig,
       
    50     MAiFwEventHandler* aAiFwEventHandler )
       
    51     {
       
    52     CAiUiIdleIntegrationImpl* self = 
       
    53         new ( ELeave ) CAiUiIdleIntegrationImpl( aEikEnv, aAiFwEventHandler );
       
    54                                               
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL( aKeySoundConfig );
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CAiUiIdleIntegrationImpl::~CAiUiIdleIntegrationImpl()
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CAiUiIdleIntegrationImpl::~CAiUiIdleIntegrationImpl()
       
    66     {
       
    67     delete iActiveIdleState;
       
    68     
       
    69     delete iIncallBubble;
       
    70     
       
    71     Release( iCallStatusObserver );       
       
    72     
       
    73     Release( iUiStartupStateObserver );
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CAiUiIdleIntegrationImpl::CAiUiIdleIntegrationImpl()
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 CAiUiIdleIntegrationImpl::CAiUiIdleIntegrationImpl( CEikonEnv& aEikEnv,
       
    81     MAiFwEventHandler* aAiFwEventHandler )
       
    82     : iEikEnv( aEikEnv ),
       
    83       iAiFwEventHandler( aAiFwEventHandler )
       
    84     {
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CAiUiIdleIntegrationImpl::ConstructL()
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 void CAiUiIdleIntegrationImpl::ConstructL(
       
    92     const TAiIdleKeySoundConfig& aKeySoundConfig )       
       
    93     {   
       
    94     __PRINTS( "*** CAiUiIdleIntegrationImpl::ConstructL" );
       
    95     __TIME_MARK( time );
       
    96     
       
    97 	iIncallBubble = CAknIncallBubble::NewL();
       
    98 	
       
    99     iActiveIdleState = CActiveIdleState::NewL();
       
   100            
       
   101     // Set up keysounds
       
   102     if( aKeySoundConfig.iKeySounds )
       
   103         {
       
   104         aKeySoundConfig.iKeySounds->PushContextL( 
       
   105             aKeySoundConfig.iContextResId );                       
       
   106         }
       
   107     
       
   108     iEikEnv.SetSystem( ETrue );
       
   109              
       
   110     RWindowGroup& windowGroup = iEikEnv.RootWin();
       
   111     windowGroup.AutoForeground(EFalse);
       
   112     TInt wgId( windowGroup.Identifier() );
       
   113     TInt focusWgId( iEikEnv.WsSession().GetFocusWindowGroup() );
       
   114     
       
   115     if ( focusWgId == wgId )
       
   116         {
       
   117         __PRINTS( "*** CAiUiIdleIntegrationImpl::ConstructL - iForeground: 1" );
       
   118     
       
   119         iForeground = ETrue;
       
   120         }
       
   121     
       
   122     iActiveIdleState->SetIsIdleForeground( iForeground );
       
   123       
       
   124     iCallStatusObserver = AiUtility::CreatePSPropertyObserverL(          
       
   125                             TCallBack( HandleCallEvent, this ),  
       
   126                                        KPSUidCtsyCallInformation, 
       
   127                                        KCTsyCallState );  
       
   128     
       
   129     iUiStartupStateObserver = AiUtility::CreatePSPropertyObserverL(                           
       
   130                                 TCallBack( HandleUiStartupStateChange, this ),            
       
   131                                            KPSUidStartup, 
       
   132                                            KPSStartupUiPhase );        
       
   133     
       
   134     HandleUiStartupStateChange( this );
       
   135                  
       
   136     __TIME_ENDMARK( "CAiUiIdleIntegrationImpl::ConstructL, done", time );
       
   137     }
       
   138 
       
   139 // ----------------------------------------------------------------------------
       
   140 // CAiUiIdleIntegrationImpl::ActivateUI()
       
   141 // ----------------------------------------------------------------------------
       
   142 //
       
   143 void CAiUiIdleIntegrationImpl::ActivateUI()
       
   144     {   
       
   145     __TICK( "CAiUiIdleIntegrationImpl::ActivateUI" );
       
   146     
       
   147     Release( iUiStartupStateObserver );
       
   148     iUiStartupStateObserver = NULL;
       
   149     
       
   150     iAiFwEventHandler->HandleActivateUI();
       
   151     
       
   152     RWsSession& wsSession( iEikEnv.WsSession() );
       
   153     
       
   154     TApaTaskList taskList( wsSession );
       
   155     
       
   156     TApaTask task( taskList.FindApp( TUid::Uid( AI_UID3_AIFW_EXE ) ) );
       
   157     
       
   158     task.BringToForeground(); 
       
   159         
       
   160     __PRINTS( "*** CAiUiIdleIntegrationImpl::ActivateUI - done" );    
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // CAiUiIdleIntegrationImpl::HandleWsEventL()
       
   165 // ----------------------------------------------------------------------------
       
   166 //
       
   167 void CAiUiIdleIntegrationImpl::HandleWsEventL( const TWsEvent& aEvent, 
       
   168     CCoeControl* /*aDestination*/ )
       
   169     {
       
   170     TInt type( aEvent.Type() );
       
   171     
       
   172     if ( type == KAknFullOrPartialForegroundGained )
       
   173         {
       
   174         __PRINTS( "*** CAiUiIdleIntegrationImpl::HandleWsEventL - Foreground" );
       
   175         
       
   176         if ( !iForeground )
       
   177             {
       
   178             iForeground = ETrue;
       
   179             iActiveIdleState->SetIsIdleForeground( ETrue );
       
   180             SetCallBubbleIfNeededL();
       
   181             }    
       
   182         }
       
   183     else if ( type == KAknFullOrPartialForegroundLost )
       
   184         {
       
   185         __PRINTS( "*** CAiUiIdleIntegrationImpl::HandleWsEventL - Background" );
       
   186     
       
   187         if ( iForeground )
       
   188             {
       
   189             iForeground = EFalse;
       
   190             iActiveIdleState->SetIsIdleForeground( EFalse );
       
   191             ClearCallBubbleL();
       
   192             }    
       
   193         }
       
   194     else if ( type == EEventKeyDown )
       
   195         {
       
   196         if( aEvent.Key()->iScanCode == EStdKeyDevice0 )
       
   197             {
       
   198             TBool isDialog( iEikEnv.AppUi()->IsDisplayingMenuOrDialog() );
       
   199             
       
   200             if( isDialog || iAiFwEventHandler->QueryIsMenuOpen() )
       
   201                 {
       
   202                 RProperty::Set(
       
   203                     KPSUidAiInformation, 
       
   204                     KActiveIdlePopupState, 
       
   205                     EPSAiDisplayingMenuOrDialog );
       
   206                 }
       
   207             else
       
   208                 {
       
   209                 RProperty::Set(
       
   210                     KPSUidAiInformation, 
       
   211                     KActiveIdlePopupState, 
       
   212                     EPSAiNotDisplayingMenuOrDialog );
       
   213                 }    
       
   214             }
       
   215         }        
       
   216     }
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 // CAiUiIdleIntegrationImpl::SetCallBubbleIfNeededL()
       
   220 // ----------------------------------------------------------------------------
       
   221 //
       
   222 void CAiUiIdleIntegrationImpl::SetCallBubbleIfNeededL()
       
   223 	{
       
   224     if( !iIncallBubbleAllowed )
       
   225     	{
       
   226         TInt callStatus( 0 );
       
   227             	
       
   228         TInt err( RProperty::Get( KPSUidCtsyCallInformation,
       
   229                                   KCTsyCallState,
       
   230                                   callStatus ) );
       
   231         
       
   232         // Call ongoing => show bubble
       
   233 	  	if( err == KErrNone && callStatus > EPSCTsyCallStateNone )
       
   234 	      	{
       
   235 	       	iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );                	
       
   236 	       	iIncallBubbleAllowed = ETrue;
       
   237 	       	}    
       
   238     	}
       
   239 	}
       
   240 
       
   241 // ----------------------------------------------------------------------------
       
   242 // CAiUiIdleIntegrationImpl::ClearCallBubbleL()
       
   243 // ----------------------------------------------------------------------------
       
   244 //
       
   245 void CAiUiIdleIntegrationImpl::ClearCallBubbleL()
       
   246 	{
       
   247 	 if( iIncallBubbleAllowed )
       
   248     	{
       
   249     	iIncallBubble->SetIncallBubbleAllowedInIdleL( EFalse );
       
   250     	iIncallBubbleAllowed = EFalse;
       
   251     	}        
       
   252 	}
       
   253     
       
   254 // ----------------------------------------------------------------------------
       
   255 // CAiUiIdleIntegration::NewL()
       
   256 // ----------------------------------------------------------------------------
       
   257 //
       
   258 EXPORT_C CAiUiIdleIntegration* CAiUiIdleIntegration::NewL( CEikonEnv& aEikEnv, 
       
   259     const TAiIdleKeySoundConfig& aKeySoundConfig,
       
   260     MAiFwEventHandler* aAiFwEventHandler )
       
   261     {
       
   262     return CAiUiIdleIntegrationImpl::NewL( aEikEnv, aKeySoundConfig,                                             
       
   263                                            aAiFwEventHandler );
       
   264     }
       
   265 
       
   266 // ----------------------------------------------------------------------------
       
   267 // CAiUiIdleIntegrationImpl::HandleCallEvent()
       
   268 // ----------------------------------------------------------------------------
       
   269 //
       
   270 TInt CAiUiIdleIntegrationImpl::HandleCallEvent( TAny* aPtr )
       
   271 	{
       
   272 	__ASSERT_DEBUG( aPtr, 
       
   273         AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) );
       
   274     
       
   275 	CAiUiIdleIntegrationImpl* self = 
       
   276         static_cast< CAiUiIdleIntegrationImpl* >( aPtr );
       
   277         
       
   278 	TInt callStatus( EPSCTsyCallStateNone );
       
   279 	
       
   280 	TInt err( self->iCallStatusObserver->Get( callStatus ) );
       
   281 	
       
   282 	if ( err == KErrNone )
       
   283 		{
       
   284 		// Call ongoing => show bubble if not showing already
       
   285 		TBool allowed = EFalse;
       
   286 		
       
   287 		if ( !self->iIncallBubbleAllowed &&
       
   288 		     self->iForeground &&
       
   289 		    ( callStatus > EPSCTsyCallStateNone ) )
       
   290 			{
       
   291 			allowed = ETrue;
       
   292     		
       
   293 			TRAP( err, 
       
   294                 self->iIncallBubble->SetIncallBubbleAllowedInIdleL( allowed ) );
       
   295 			            		
       
   296 			if ( err == KErrNone )
       
   297     		    {
       
   298     			self->iIncallBubbleAllowed = allowed;
       
   299     		    }
       
   300 			}
       
   301 		// No call ongoing => hide if bubble is visible			
       
   302 		else if ( self->iIncallBubbleAllowed && callStatus <= EPSCTsyCallStateNone )
       
   303 			{
       
   304 			allowed = EFalse;
       
   305 			
       
   306     		TRAP( err, 
       
   307                 self->iIncallBubble->SetIncallBubbleAllowedInIdleL( allowed ) );
       
   308     		
       
   309     		if ( err == KErrNone )
       
   310     		    {
       
   311     			self->iIncallBubbleAllowed = allowed;
       
   312     		    }
       
   313 			}
       
   314 		}
       
   315 	
       
   316 	return err;
       
   317 	}
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 // CAiUiIdleIntegrationImpl::HandleUiStartupStateChange()
       
   321 // ----------------------------------------------------------------------------
       
   322 //
       
   323 TInt CAiUiIdleIntegrationImpl::HandleUiStartupStateChange( TAny *aPtr )
       
   324     {
       
   325     __ASSERT_DEBUG( aPtr, 
       
   326         AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) );
       
   327     
       
   328     CAiUiIdleIntegrationImpl* self = 
       
   329         static_cast< CAiUiIdleIntegrationImpl* >( aPtr );
       
   330 
       
   331     if ( !self->iUiStartupPhaseOk )
       
   332         {
       
   333         TInt state( 0 );
       
   334         
       
   335         self->iUiStartupStateObserver->Get( state );
       
   336         
       
   337         if ( state == EStartupUiPhaseAllDone )
       
   338             {
       
   339             self->iUiStartupPhaseOk = ETrue;
       
   340             
       
   341             self->ActivateUI();                        
       
   342             }
       
   343         }
       
   344     
       
   345     return KErrNone;
       
   346     }
       
   347 
       
   348 // End of file