idlefw/src/idleint/aiwspluginmanager.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2006 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 "aiwspluginmanagerimpl.h"
       
    20 #include <coemain.h>
       
    21 #include <apgtask.h>
       
    22 #include <aiutility.h>
       
    23 #include <telinformationpskeys.h>
       
    24 #include <aipspropertyobserver.h>
       
    25 
       
    26 CAiWsPluginManagerImpl::CAiWsPluginManagerImpl(RWsSession& aWsSession) :
       
    27     iAnimDll( aWsSession ),
       
    28     iWnd( aWsSession ),
       
    29     iAnim( iAnimDll )
       
    30     {
       
    31     }
       
    32 
       
    33 void CAiWsPluginManagerImpl::ConstructL(CCoeEnv& aCoeEnv)
       
    34     {
       
    35     User::LeaveIfError( iAnimDll.Load( KAiWsPluginAnimDllName ) );
       
    36     iCoeEnv = &aCoeEnv;
       
    37     iPhoneStatusObserver = AiUtility::CreatePSPropertyObserverL
       
    38         ( TCallBack( HandlePhoneEvent, this ),
       
    39             KPSUidTelInformation, KTelPhoneUid );
       
    40     TryLoadWsPluginL();
       
    41     }
       
    42 
       
    43 CAiWsPluginManagerImpl* CAiWsPluginManagerImpl::NewL( CCoeEnv& aCoeEnv )
       
    44     {
       
    45     CAiWsPluginManagerImpl* self = 
       
    46         new(ELeave) CAiWsPluginManagerImpl( aCoeEnv.WsSession() );
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( aCoeEnv );
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 CAiWsPluginManagerImpl::~CAiWsPluginManagerImpl()
       
    54     {
       
    55     iAnim.Close();
       
    56     iWnd.Close();
       
    57     Release( iPhoneStatusObserver );
       
    58     iAnimDll.Close();
       
    59     }
       
    60 
       
    61 EXPORT_C CAiWsPluginManager* CAiWsPluginManager::NewL
       
    62         (CCoeEnv& aCoeEnv)
       
    63     {
       
    64     return CAiWsPluginManagerImpl::NewL(aCoeEnv);
       
    65     }
       
    66 
       
    67 TInt CAiWsPluginManagerImpl::HandlePhoneEvent( TAny* aPtr )
       
    68 	{
       
    69     CAiWsPluginManagerImpl* self = 
       
    70         static_cast<CAiWsPluginManagerImpl*>( aPtr );
       
    71     TInt err = KErrNone;
       
    72     if( self )
       
    73         {
       
    74         TRAP( err, self->TryLoadWsPluginL() );
       
    75         }
       
    76     return err;
       
    77 	}
       
    78 	
       
    79 void CAiWsPluginManagerImpl::TryLoadWsPluginL()
       
    80     {
       
    81     TInt phoneUidVal;
       
    82     iPhoneStatusObserver->Get( phoneUidVal );
       
    83     const TUid phoneUid = TUid::Uid( phoneUidVal );
       
    84     
       
    85     if ( phoneUid != KNullUid )
       
    86         {
       
    87 	    RWsSession& wsSession = iCoeEnv->WsSession();
       
    88 		TApaTaskList taskList( wsSession );
       
    89 		TApaTask phoneTask( taskList.FindApp( phoneUid ) );
       
    90 		if ( phoneTask.Exists() )
       
    91 			{
       
    92             iAnim.Close();
       
    93             iWnd.Close();
       
    94         
       
    95          	RWindowGroup& aiRootWg = iCoeEnv->RootWin();
       
    96     	    // RWindow::Construct requires a unique non-null handle. Active Idle
       
    97     	    // does not care about the handle value and just uses this pointer to have
       
    98     	    // something non-null.
       
    99     	    const TUint32 dummyHandle = reinterpret_cast<TUint32>(this);
       
   100   	        User::LeaveIfError( iWnd.Construct(aiRootWg, dummyHandle ) );
       
   101 
       
   102     	    const TInt aiWgId = aiRootWg.Identifier();
       
   103     	    const TInt phoneWgId = phoneTask.WgId();
       
   104     	    User::LeaveIfError( iAnim.Construct( iWnd, aiWgId, phoneWgId ) );
       
   105     	    
       
   106     	    // No need to monitor Phone app status anymore
       
   107     	    Release( iPhoneStatusObserver );
       
   108     	    iPhoneStatusObserver = NULL;
       
   109 			}
       
   110 	    }
       
   111     }
       
   112