idlefw/src/idleint/aiuiidleintegration.cpp
changeset 0 79c6a41cd166
child 8 d0529222e3f0
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Window server plug-in manager.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "aiuiidleintegrationimpl.h"
       
    20 #include "aifweventhandler.h"
       
    21 
       
    22 #include <coemain.h>
       
    23 #include <coeaui.h>
       
    24 #include <eikenv.h>
       
    25 #include <apgtask.h>
       
    26 #include <AknIncallBubbleNotify.h>
       
    27 #include <aknsoundsystem.h>
       
    28 #include <apgwgnam.h> 
       
    29 #include <AknDef.h>
       
    30 #include <AknCapServerDefs.h> 
       
    31 #include <startupdomainpskeys.h>
       
    32 #include <aiutility.h>
       
    33 #include <aipspropertyobserver.h>
       
    34 #include <aisystemuids.hrh>
       
    35 
       
    36 #include "aistate.h"
       
    37 #include "aifwpanic.h"
       
    38 #include "activeidle2domainpskeys.h"
       
    39 
       
    40 #include <ctsydomainpskeys.h>
       
    41 
       
    42 #include <AknSgcc.h>
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // CAiUiIdleIntegrationImpl::NewL()
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 CAiUiIdleIntegrationImpl* CAiUiIdleIntegrationImpl::NewL( CEikonEnv& aEikEnv,         
       
    51     const TAiIdleKeySoundConfig& aKeySoundConfig,
       
    52     MAiFwEventHandler* aAiFwEventHandler )
       
    53     {
       
    54     CAiUiIdleIntegrationImpl* self = 
       
    55         new ( ELeave ) CAiUiIdleIntegrationImpl( aEikEnv, aAiFwEventHandler );
       
    56                                               
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aKeySoundConfig );
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // CAiUiIdleIntegrationImpl::~CAiUiIdleIntegrationImpl()
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 CAiUiIdleIntegrationImpl::~CAiUiIdleIntegrationImpl()
       
    68     {
       
    69     delete iActiveIdleState;
       
    70     
       
    71     delete iIncallBubble;
       
    72     
       
    73     Release( iSystemStateObserver );
       
    74     
       
    75     Release( iUiStartupStateObserver );
       
    76     
       
    77     Release( iCallStatusObserver );
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // CAiUiIdleIntegrationImpl::CAiUiIdleIntegrationImpl()
       
    82 // ----------------------------------------------------------------------------
       
    83 //
       
    84 CAiUiIdleIntegrationImpl::CAiUiIdleIntegrationImpl( CEikonEnv& aEikEnv,
       
    85     MAiFwEventHandler* aAiFwEventHandler )
       
    86     : iEikEnv( aEikEnv ),
       
    87       iAiFwEventHandler( aAiFwEventHandler )
       
    88     {
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // CAiUiIdleIntegrationImpl::ConstructL()
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 void CAiUiIdleIntegrationImpl::ConstructL(
       
    96     const TAiIdleKeySoundConfig& aKeySoundConfig )       
       
    97     {   
       
    98 	iIncallBubble = CAknIncallBubble::NewL();
       
    99 	
       
   100     iActiveIdleState = CActiveIdleState::NewL();
       
   101            
       
   102     // Set up keysounds
       
   103     if( aKeySoundConfig.iKeySounds )
       
   104         {
       
   105         aKeySoundConfig.iKeySounds
       
   106             ->PushContextL( aKeySoundConfig.iContextResId );            
       
   107         }
       
   108     
       
   109     // Set Active Idle application to be system application and disable
       
   110     // priority switching performed by window server.
       
   111     iEikEnv.SetSystem( ETrue );
       
   112     iEikEnv.WsSession().ComputeMode( RWsSession::EPriorityControlDisabled ); 
       
   113              
       
   114     // Eikon server window group
       
   115     iThisApplicationWgId = iEikEnv.RootWin().Identifier();
       
   116 
       
   117     iEikEnv.RootWin().EnableFocusChangeEvents(); 
       
   118     iEikEnv.RootWin().EnableGroupChangeEvents();
       
   119     
       
   120     CApaWindowGroupName::FindByAppUid( KAknCapServerUid, 
       
   121                                        iEikEnv.WsSession(), 
       
   122                                        iEikonServerWgId );
       
   123 	           
       
   124     iActiveIdleState->SetIsIdleForeground( iThisApplicationForeground );
       
   125       
       
   126     iSystemStateObserver = AiUtility::CreatePSPropertyObserverL(                      
       
   127                             TCallBack( HandleSystemStateChange, this ),            
       
   128                                        KPSUidStartup, 
       
   129                                        KPSGlobalSystemState );
       
   130               
       
   131     iUiStartupStateObserver = AiUtility::CreatePSPropertyObserverL(                           
       
   132                                 TCallBack( HandleUiStartupStateChange, this ),            
       
   133                                            KPSUidStartup, 
       
   134                                            KPSStartupUiPhase );        
       
   135                  
       
   136     iCallStatusObserver = AiUtility::CreatePSPropertyObserverL(          
       
   137                             TCallBack( HandleCallEvent, this ),  
       
   138                                        KPSUidCtsyCallInformation, 
       
   139                                        KCTsyCallState );  
       
   140     
       
   141     // Update state flags.    
       
   142     CAiUiIdleIntegrationImpl::HandleSystemStateChange( this );
       
   143     CAiUiIdleIntegrationImpl::HandleUiStartupStateChange( this );
       
   144     }
       
   145 
       
   146 // ----------------------------------------------------------------------------
       
   147 // CAiUiIdleIntegrationImpl::ActivateUI()
       
   148 // ----------------------------------------------------------------------------
       
   149 //
       
   150 void CAiUiIdleIntegrationImpl::ActivateUI()
       
   151     {       
       
   152     if( iUiStartupPhaseOk && iSystemStateOk )
       
   153         {      
       
   154         RWsSession& wsSession( iEikEnv.WsSession() );
       
   155         
       
   156         TInt focusWgId( wsSession.GetFocusWindowGroup() );
       
   157         
       
   158         if( iThisApplicationWgId != focusWgId )
       
   159             {                       
       
   160             TApaTaskList taskList( wsSession );
       
   161             
       
   162             TApaTask task( taskList.FindApp( TUid::Uid( AI_UID3_AIFW_EXE ) ) );
       
   163             
       
   164             task.SendSystemEvent( EApaSystemEventBroughtToForeground );            
       
   165             }
       
   166 
       
   167         iAiFwEventHandler->HandleActivateUI();
       
   168         }    
       
   169     }
       
   170 
       
   171 // ----------------------------------------------------------------------------
       
   172 // CAiUiIdleIntegrationImpl::HandleWsEventL()
       
   173 // ----------------------------------------------------------------------------
       
   174 //
       
   175 void CAiUiIdleIntegrationImpl::HandleWsEventL( const TWsEvent& aEvent, 
       
   176     CCoeControl* /*aDestination*/ )
       
   177     {
       
   178     if( !iSystemStateOk || !iUiStartupPhaseOk )
       
   179         {                
       
   180         return;
       
   181         }
       
   182       
       
   183     switch ( aEvent.Type() )
       
   184     	{
       
   185     	case KAknFullOrPartialForegroundGained:	
       
   186         	{
       
   187             if ( !iThisApplicationForeground )
       
   188             	{
       
   189                 iThisApplicationForeground = ETrue;
       
   190                 iActiveIdleState->SetIsIdleForeground( ETrue );
       
   191                	SetCallBubbleIfNeededL();
       
   192                 }
       
   193           	break;
       
   194         	}
       
   195                 
       
   196         case KAknFullOrPartialForegroundLost:
       
   197         	{
       
   198         	if ( iThisApplicationForeground )
       
   199             	{
       
   200             	iThisApplicationForeground = EFalse;
       
   201                 iActiveIdleState->SetIsIdleForeground( EFalse );
       
   202                 ClearCallBubbleL();
       
   203                 }
       
   204         	break;
       
   205         	}
       
   206         
       
   207     	case EEventKeyDown:
       
   208     	    {
       
   209             if( aEvent.Key()->iScanCode == EStdKeyDevice0 )
       
   210             	{
       
   211             	TBool isDialog( iEikEnv.AppUi()->IsDisplayingMenuOrDialog() );
       
   212             	
       
   213             	if( isDialog || iAiFwEventHandler->QueryIsMenuOpen() )
       
   214             	    {
       
   215                     RProperty::Set(
       
   216                         KPSUidAiInformation, 
       
   217                         KActiveIdlePopupState, 
       
   218                         EPSAiDisplayingMenuOrDialog );
       
   219             	    }
       
   220             	else
       
   221             	    {
       
   222                     RProperty::Set(
       
   223                         KPSUidAiInformation, 
       
   224                         KActiveIdlePopupState, 
       
   225                         EPSAiNotDisplayingMenuOrDialog );
       
   226             	    }
       
   227             	} 
       
   228     	    break;
       
   229     	    }
       
   230                 
       
   231     	default:
       
   232     	    {
       
   233     		break;
       
   234     	    }
       
   235     	}
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------------------------------
       
   239 // CAiUiIdleIntegrationImpl::SetCallBubbleIfNeededL()
       
   240 // ----------------------------------------------------------------------------
       
   241 //
       
   242 void CAiUiIdleIntegrationImpl::SetCallBubbleIfNeededL()
       
   243 	{
       
   244     if( !iIncallBubbleAllowed )
       
   245     	{
       
   246         TInt callStatus( 0 );
       
   247             	
       
   248         TInt err( RProperty::Get( KPSUidCtsyCallInformation,
       
   249                                   KCTsyCallState,
       
   250                                   callStatus ) );
       
   251         
       
   252         // Call ongoing => show bubble
       
   253 	  	if( err == KErrNone && callStatus > EPSCTsyCallStateNone )
       
   254 	      	{
       
   255 	       	iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );                	
       
   256 	       	iIncallBubbleAllowed = ETrue;
       
   257 	       	}    
       
   258     	}
       
   259 	}
       
   260 
       
   261 // ----------------------------------------------------------------------------
       
   262 // CAiUiIdleIntegrationImpl::ClearCallBubbleL()
       
   263 // ----------------------------------------------------------------------------
       
   264 //
       
   265 void CAiUiIdleIntegrationImpl::ClearCallBubbleL()
       
   266 	{
       
   267 	 if( iIncallBubbleAllowed )
       
   268     	{
       
   269     	iIncallBubble->SetIncallBubbleAllowedInIdleL( EFalse );
       
   270     	iIncallBubbleAllowed = EFalse;
       
   271     	}        
       
   272 	}
       
   273     
       
   274 // ----------------------------------------------------------------------------
       
   275 // CAiUiIdleIntegration::NewL()
       
   276 // ----------------------------------------------------------------------------
       
   277 //
       
   278 EXPORT_C CAiUiIdleIntegration* CAiUiIdleIntegration::NewL( CEikonEnv& aEikEnv, 
       
   279     const TAiIdleKeySoundConfig& aKeySoundConfig,
       
   280     MAiFwEventHandler* aAiFwEventHandler )
       
   281     {
       
   282     return CAiUiIdleIntegrationImpl::NewL( aEikEnv, aKeySoundConfig,                                             
       
   283                                            aAiFwEventHandler );
       
   284     }
       
   285 
       
   286 // ----------------------------------------------------------------------------
       
   287 // CAiUiIdleIntegrationImpl::HandleSystemStateChange()
       
   288 // ----------------------------------------------------------------------------
       
   289 //
       
   290 TInt CAiUiIdleIntegrationImpl::HandleSystemStateChange( TAny* aPtr )
       
   291     {
       
   292     __ASSERT_DEBUG( aPtr, 
       
   293             AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) );
       
   294     
       
   295     CAiUiIdleIntegrationImpl* self = 
       
   296         static_cast<CAiUiIdleIntegrationImpl*>( aPtr );
       
   297            
       
   298     if( !self->iSystemStateOk )
       
   299         {
       
   300         TInt state( 0 );
       
   301         
       
   302         self->iSystemStateObserver->Get( state );               
       
   303 
       
   304         if ( state == ESwStateCriticalPhaseOK ||
       
   305              state == ESwStateNormalRfOn || 
       
   306              state == ESwStateNormalRfOff ||
       
   307              state == ESwStateNormalBTSap )        
       
   308             {
       
   309             self->iSystemStateOk = ETrue;            
       
   310             self->ActivateUI();
       
   311             }        
       
   312         }
       
   313               
       
   314     return KErrNone;
       
   315     }
       
   316 
       
   317 // ----------------------------------------------------------------------------
       
   318 // CAiUiIdleIntegrationImpl::HandleUiStartupStateChange()
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 TInt CAiUiIdleIntegrationImpl::HandleUiStartupStateChange( TAny *aPtr )
       
   322     {
       
   323     __ASSERT_DEBUG( aPtr, 
       
   324             AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) );
       
   325     
       
   326     CAiUiIdleIntegrationImpl* self = 
       
   327         static_cast<CAiUiIdleIntegrationImpl*>( aPtr );
       
   328 
       
   329     if( !self->iUiStartupPhaseOk )
       
   330         {
       
   331         TInt state( 0 );
       
   332         
       
   333         self->iUiStartupStateObserver->Get( state );
       
   334         
       
   335         if( state == EStartupUiPhaseAllDone )
       
   336             {
       
   337             self->iUiStartupPhaseOk = ETrue;
       
   338             
       
   339             self->ActivateUI();
       
   340             }
       
   341         }
       
   342     
       
   343     return KErrNone;
       
   344     }
       
   345 
       
   346 // ----------------------------------------------------------------------------
       
   347 // CAiUiIdleIntegrationImpl::HandleCallEvent()
       
   348 // ----------------------------------------------------------------------------
       
   349 //
       
   350 TInt CAiUiIdleIntegrationImpl::HandleCallEvent( TAny* aPtr )
       
   351 	{
       
   352 	__ASSERT_DEBUG( aPtr, 
       
   353 	        AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) );
       
   354     
       
   355 	CAiUiIdleIntegrationImpl* self = 
       
   356         static_cast<CAiUiIdleIntegrationImpl*>( aPtr );
       
   357         
       
   358 	TInt callStatus( EPSCTsyCallStateNone );
       
   359 	
       
   360 	TInt err( self->iCallStatusObserver->Get( callStatus ) );
       
   361 	
       
   362 	if( err == KErrNone )
       
   363 		{
       
   364 		// Call ongoing => show bubble if not showing already
       
   365 		TBool allowed = EFalse;
       
   366 		
       
   367 		if( !self->iIncallBubbleAllowed &&
       
   368 		     self->iThisApplicationForeground &&
       
   369 		    ( callStatus > EPSCTsyCallStateNone ) )
       
   370 			{
       
   371 			allowed = ETrue;
       
   372     		
       
   373 			TRAP( err, 
       
   374                 self->iIncallBubble->SetIncallBubbleAllowedInIdleL( allowed ) );
       
   375 			        
       
   376     		
       
   377 			if( err == KErrNone )
       
   378     		    {
       
   379     			self->iIncallBubbleAllowed = allowed;
       
   380     		    }
       
   381 			}
       
   382 		// No call ongoing => hide if bubble is visible			
       
   383 		else if( self->iIncallBubbleAllowed && callStatus <= EPSCTsyCallStateNone )
       
   384 			{
       
   385 			allowed = EFalse;
       
   386 			
       
   387     		TRAP( err, 
       
   388                 self->iIncallBubble->SetIncallBubbleAllowedInIdleL( allowed ) );
       
   389     		
       
   390     		if( err == KErrNone )
       
   391     		    {
       
   392     			self->iIncallBubbleAllowed = allowed;
       
   393     		    }
       
   394 			}
       
   395 		}
       
   396 	
       
   397 	return err;
       
   398 	}
       
   399 
       
   400 // End of file.
       
   401