idlehomescreen/xmluicontroller/src/xmluicontroller.cpp
changeset 0 f72a12da539e
child 4 4d54b72983ae
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2005-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:  XML UI Controller main class
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <ecom/implementationproxy.h>
       
    20 #include <AknQueryDialog.h>
       
    21 #include <eikstart.h>
       
    22 #include <apgtask.h>
       
    23 #include <centralrepository.h>
       
    24 #include <e32property.h>
       
    25 
       
    26 // User includes
       
    27 #include <activeidle2domainpskeys.h>
       
    28 #include <activeidle2domaincrkeys.h>
       
    29 #include <aiscutplugindomaincrkeys.h>
       
    30 #include <aisystemuids.hrh>
       
    31 #include <ai3xmlui.rsg>
       
    32 
       
    33 #include "xmluicontroller.h"
       
    34 
       
    35 #include "xnuiengineappif.h"
       
    36 #include "xnnodeappif.h"
       
    37 #include "xnproperty.h"
       
    38 #include "xntype.h"
       
    39 #include "aistrcnv.h"
       
    40 
       
    41 #include "application.h"
       
    42 #include "appui.h"
       
    43 #include "xmlnodeidgenerator.h"
       
    44 #include "aixuikoneventhandler.h"
       
    45 #include "aixmluiutils.h"
       
    46 #include "aiutility.h"
       
    47 #include "aipluginsettings.h"
       
    48 #include "aixmluiconstants.h"
       
    49 #include "aifweventhandler.h"
       
    50 #include "debug.h"
       
    51 #include "aiconsts.h"
       
    52 #include "contentrenderer.h"
       
    53 #include "xmluicontrollerpanic.h"
       
    54 #include "pmodtiterator.h"
       
    55 #include "contentpublisher.h"
       
    56 #include "xnplugindefs.h"
       
    57 #include "ainativeuiplugins.h"
       
    58 
       
    59 
       
    60 using namespace AiXmlUiController;
       
    61 
       
    62 const TInt KOneSecondInMicroS = 1000*1000;
       
    63 const TInt KAI2CrKeyIncrementBy2 = 2;
       
    64 
       
    65 typedef TBuf<32> TNamespace;
       
    66 
       
    67 _LIT( KSettingsDummyData, "" );
       
    68 
       
    69 // ======== LOCAL FUNCTIONS ========
       
    70 // ----------------------------------------------------------------------------
       
    71 // ResolveEventParameters()
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 static void ResolveEventParameters( const TDesC8& aEventString, 
       
    75     TPtrC8& aParam1, TPtrC8& aParam2 )
       
    76     {
       
    77     TInt  paramPos( aEventString.Locate( KEventParameterSeparator ) );
       
    78     
       
    79     TLex8 lex( aEventString.Mid( ++paramPos ) );
       
    80     
       
    81     aParam1.Set( lex.NextToken() );   // first ui element id
       
    82     
       
    83     TInt commaPos( aParam1.LocateReverse( KComma ) );
       
    84     
       
    85     if( commaPos != KErrNotFound )
       
    86         {
       
    87         // Strip comma
       
    88         aParam1.Set( aParam1.Left( commaPos ) );
       
    89         
       
    90         aParam2.Set( lex.NextToken() );   // second ui element id
       
    91         
       
    92         TInt rightParenthesis( aParam2.LocateReverse( KRightParenthesis ) );
       
    93         
       
    94         if( rightParenthesis != KErrNotFound )
       
    95             {
       
    96             aParam2.Set( aParam2.Left( rightParenthesis ) );
       
    97             }        
       
    98         }
       
    99     else
       
   100         {
       
   101         // Strip right parenthesis
       
   102         aParam1.Set( aParam1.Left( aParam1.Length() -1 ) );
       
   103         }
       
   104     }
       
   105 
       
   106 // ======== MEMBER FUNCTIONS ========
       
   107 // ----------------------------------------------------------------------------
       
   108 // CXmlUiController::CXmlUiController()
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 CXmlUiController::CXmlUiController()
       
   112     {
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // CXmlUiController::ConstructL()
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 void CXmlUiController::ConstructL()
       
   120     {       
       
   121     iNodeIdGenerator = CXmlNodeIdGenerator::NewL();  
       
   122     
       
   123     iAISettingsRepository = 
       
   124         CRepository::NewL( TUid::Uid( KCRUidActiveIdleLV ) ); 
       
   125         
       
   126     // Indicate to wserv plugin if it launches logs on send key or not              
       
   127     RProperty::Set( KPSUidAiInformation, KActiveIdleActOnSendKey, ETrue );                     
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------------------------------
       
   131 // CXmlUiController::NewL()
       
   132 // ----------------------------------------------------------------------------
       
   133 //
       
   134 CXmlUiController* CXmlUiController::NewL()
       
   135     {
       
   136     CXmlUiController* self = new ( ELeave ) CXmlUiController;
       
   137 
       
   138     CleanupStack::PushL( self );
       
   139     self->ConstructL();
       
   140     
       
   141     // Set XML UI Controller object to TLS for access in static
       
   142     // CXmlUiController::NewApplication
       
   143     User::LeaveIfError( Dll::SetTls( self ) );
       
   144     
       
   145     CleanupStack::Pop( self ); 
       
   146 
       
   147     return self;
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CXmlUiController::~CXmlUiController()
       
   152 // ----------------------------------------------------------------------------
       
   153 //
       
   154 CXmlUiController::~CXmlUiController()
       
   155     {
       
   156     delete iNodeIdGenerator;
       
   157     delete iExitTimer;
       
   158     delete iAISettingsRepository;
       
   159     delete iCPSpublisher;
       
   160     
       
   161     // Reset TLS pointer to this set in NewL
       
   162     Dll::SetTls( NULL );
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CXmlUiController::Exit()
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 void CXmlUiController::Exit()
       
   170     {
       
   171     if( iExitTimer )
       
   172         {
       
   173         iExitTimer->Cancel();
       
   174         
       
   175         iExitTimer->Start( 0, KOneSecondInMicroS,           
       
   176            TCallBack( ExitTimerCallBack, this ) );
       
   177         }
       
   178     }
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // CXmlUiController::ExitTimerCallBack()
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 TInt CXmlUiController::ExitTimerCallBack(TAny *aSelf)
       
   185     {
       
   186      CXmlUiController* self =
       
   187          static_cast< CXmlUiController* >( aSelf );
       
   188     
       
   189     if( self )
       
   190         {
       
   191         self->iExitTimer->Cancel();
       
   192         
       
   193         self->iAppUi->Exit();        
       
   194         }
       
   195     
       
   196     return KErrNone;
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------------------------
       
   200 // CXmlUiController::SetObserver()
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 void CXmlUiController::SetObserver( MAiContentObserver& aObserver )
       
   204     {
       
   205     iObserver = &aObserver;
       
   206     }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CXmlUiController::SetAppUi()
       
   210 // ----------------------------------------------------------------------------
       
   211 //
       
   212 void CXmlUiController::SetAppUi( CAppUi& aAppUi )
       
   213     {
       
   214     iAppUi = &aAppUi;
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------------------------------
       
   218 // CXmlUiController::AppUi()
       
   219 // ----------------------------------------------------------------------------
       
   220 //
       
   221 CAppUi* CXmlUiController::AppUi() const
       
   222     {
       
   223     return iAppUi;
       
   224     }
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // CXmlUiController::UiEngineL()
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 TXnUiEngineAppIf* CXmlUiController::UiEngineL() const
       
   231     {
       
   232     return iAppUi ? iAppUi->UiEngineL() : NULL;
       
   233     }
       
   234 
       
   235 // ----------------------------------------------------------------------------
       
   236 // CXmlUiController::SettingsRepository()
       
   237 // ----------------------------------------------------------------------------
       
   238 //
       
   239 CRepository& CXmlUiController::SettingsRepository() const
       
   240     {
       
   241     return *iAISettingsRepository;
       
   242     }
       
   243 
       
   244 // ----------------------------------------------------------------------------
       
   245 // CXmlUiController::CreateXuikonEventHandlerL()
       
   246 // ----------------------------------------------------------------------------
       
   247 //
       
   248 CAIXuikonEventHandler* CXmlUiController::CreateXuikonEventHandlerL(
       
   249     CContentRenderer& aRenderer )
       
   250     {
       
   251     CAIXuikonEventHandler* eventHandler = 
       
   252         CAIXuikonEventHandler::NewL( *this, aRenderer );
       
   253     
       
   254     eventHandler->SetFwEventHandler( iFwEventHandler );
       
   255     eventHandler->SetUiEventHandler( this );
       
   256     
       
   257     return eventHandler;
       
   258     }
       
   259 
       
   260 // ----------------------------------------------------------------------------
       
   261 // CXmlUiController::NotifyAppEnvReadyL()
       
   262 // ----------------------------------------------------------------------------
       
   263 //
       
   264 void CXmlUiController::NotifyAppEnvReadyL()
       
   265     {
       
   266     if( iFwEventHandler )
       
   267         {
       
   268         iFwEventHandler->AppEnvReadyL();
       
   269         iFwEventHandler->HandleUiReadyEventL( *this );
       
   270         }
       
   271     
       
   272     if( !iCPSpublisher )
       
   273         {
       
   274         iCPSpublisher = CContentPublisher::NewL( *this );
       
   275         }
       
   276     
       
   277     if( !iExitTimer )
       
   278         {
       
   279         iExitTimer = CPeriodic::NewL( CActive::EPriorityStandard );        
       
   280         }
       
   281     }
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // CXmlUiController::LoadUIDefinition()
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 void CXmlUiController::LoadUIDefinitionL()
       
   288     {
       
   289     // No implementation required
       
   290     }
       
   291 
       
   292 // ----------------------------------------------------------------------------
       
   293 // CXmlUiController::GetPluginsL()
       
   294 // ----------------------------------------------------------------------------
       
   295 //
       
   296 void CXmlUiController::GetPluginsL( RAiPublisherInfoArray& /*aPlugins*/ )
       
   297     {   
       
   298     // No implementation required
       
   299     }
       
   300 
       
   301 // ----------------------------------------------------------------------------
       
   302 // CXmlUiController::PublisherInfo()
       
   303 // ----------------------------------------------------------------------------
       
   304 //
       
   305 void CXmlUiController::PublisherInfoL( RAiPublisherInfoArray& aPlugins )
       
   306     {
       
   307     // This method returns plugins with namespace KNativeUiNamespace
       
   308     if ( iRunningAsMain )
       
   309         {
       
   310         // This plugin is used to publish data on secondary ui controller side       
       
   311         TAiPublisherInfo deviceStatus;
       
   312         deviceStatus.iUid = KDeviceStatusPluginUid;
       
   313         deviceStatus.iName.Copy( KDeviceStatusPluginName );
       
   314         deviceStatus.iNamespace.Copy( KNativeUiNamespace );
       
   315                 
       
   316         aPlugins.AppendL( deviceStatus );               
       
   317         }        
       
   318     }
       
   319 
       
   320 // ----------------------------------------------------------------------------
       
   321 // CXmlUiController::PublisherInfoL()
       
   322 // ----------------------------------------------------------------------------
       
   323 //
       
   324 void CXmlUiController::PublisherInfoL( CXnNodeAppIf& aSource,
       
   325     TAiPublisherInfo& aInfo )
       
   326     {
       
   327     // Fetch uid from XML and convert it to TUid
       
   328     const TDesC8* uid( PropertyValue( aSource, 
       
   329         AiUiDef::xml::property::KValue ) ); 
       
   330 
       
   331     if ( !uid )
       
   332         {
       
   333         return;
       
   334         }
       
   335         
       
   336     _LIT8( KPrefix, "0x" );
       
   337     
       
   338     const TInt pos( uid->FindF( KPrefix ) );
       
   339 
       
   340     if( pos != KErrNotFound )
       
   341          {
       
   342          TLex8 lex( uid->Mid( pos + KPrefix().Length() ) );
       
   343           
       
   344          // Hex parsing needs unsigned int
       
   345          TUint32 value = 0;
       
   346          const TInt parseResult = lex.Val( value, EHex );
       
   347          
       
   348          if ( parseResult == KErrNone )
       
   349              {
       
   350              TInt32 value32( value );
       
   351              
       
   352              aInfo.iUid = TUid::Uid( value32 );            
       
   353              }
       
   354          }
       
   355      
       
   356     // Fetch plug-in name from XML
       
   357     HBufC* pluginName( PropertyValueL( aSource, 
       
   358                 AiUiDef::xml::property::KName ) ); 
       
   359             
       
   360     CleanupStack::PushL( pluginName );
       
   361 
       
   362     if ( pluginName )
       
   363         {
       
   364         aInfo.iName.Copy( *pluginName );
       
   365         }
       
   366     
       
   367     CleanupStack::PopAndDestroy( pluginName );
       
   368         
       
   369     aInfo.iNamespace.Copy( aSource.Namespace() );    
       
   370     }
       
   371 
       
   372 // ----------------------------------------------------------------------------
       
   373 // CXmlUiController::GetSettingsL()
       
   374 // ----------------------------------------------------------------------------
       
   375 //
       
   376 void CXmlUiController::GetSettingsL( const TAiPublisherInfo& aPubInfo,     
       
   377     RAiSettingsItemArray& aSettings )
       
   378     {
       
   379     if ( aPubInfo.iNamespace == KNativeUiNamespace )
       
   380         {
       
   381         // This controller doesn't provide settings for native ui namespace
       
   382         return;
       
   383         }
       
   384     
       
   385     const TDesC& classId( iNodeIdGenerator->SettingsNodeIdL( aPubInfo ) );
       
   386     
       
   387     TNamespace ns;
       
   388     
       
   389     ns.Copy( aPubInfo.iNamespace );
       
   390        
       
   391     // Find settings nodes
       
   392     RPointerArray< CXnNodeAppIf > nodes( 
       
   393         UiEngineL()->FindNodeByClassL( classId, ns ) );
       
   394     
       
   395     CleanupClosePushL( nodes );
       
   396     
       
   397     // Reserve space for settings
       
   398     aSettings.ReserveL( aSettings.Count() + nodes.Count() );
       
   399     
       
   400     // Collect settings
       
   401     TInt count( nodes.Count() );
       
   402     
       
   403     for( TInt i = 0; i < count; ++i )
       
   404         {
       
   405         CXnNodeAppIf* node( nodes[i] );
       
   406         
       
   407         const TDesC8* name( 
       
   408                 PropertyValue( *node, AiUiDef::xml::property::KName ) );
       
   409         
       
   410         HBufC* value( 
       
   411                 PropertyValueL( *node, AiUiDef::xml::property::KValue ) );        
       
   412         
       
   413         CleanupStack::PushL( value );
       
   414         
       
   415         if( name && value )
       
   416             {
       
   417             MAiPluginSettings* settings( AiUtility::CreatePluginSettingsL() );
       
   418             CleanupDeletePushL( settings );
       
   419             
       
   420             MAiPluginSettingsItem& item( settings->AiPluginSettingsItem() ); 
       
   421             item.SetPublisherId( aPubInfo.iUid );
       
   422             
       
   423             TInt32 key( 0 );
       
   424             
       
   425             User::LeaveIfError( AiUtility::ParseInt( key, *name ) );
       
   426             
       
   427             item.SetKey( key );            
       
   428             item.SetValueL( *value, EFalse );
       
   429             
       
   430             // Append settings into array.
       
   431             // This can not fail because space has been reserved.
       
   432             aSettings.Append( settings );            
       
   433             CleanupStack::Pop( settings );
       
   434             }
       
   435             
       
   436         CleanupStack::PopAndDestroy( value );
       
   437         }
       
   438     
       
   439     CleanupStack::PopAndDestroy( &nodes );
       
   440     
       
   441     GetSettingsFromCRL( aPubInfo, aSettings );
       
   442     GetContentModelL( aPubInfo, aSettings );
       
   443     }
       
   444 
       
   445 // ----------------------------------------------------------------------------
       
   446 // CXmlUiController::GetSettingsFromCRL()
       
   447 // ----------------------------------------------------------------------------
       
   448 //
       
   449 void CXmlUiController::GetSettingsFromCRL( const TAiPublisherInfo& aPubInfo, 
       
   450     RAiSettingsItemArray &aPluginSettings )                            
       
   451     {
       
   452     if ( aPubInfo.iNamespace == KNativeUiNamespace )
       
   453         {
       
   454         // This controller doesn't provide settings for native ui namespace
       
   455         return;
       
   456         }
       
   457     
       
   458     /*
       
   459     * The settings are stored in the cenrep starting from 0x1000. 
       
   460     * 0x1000 is the name of the plugin which this setting belongs to (for example Settings/Shortcut)
       
   461     * 0x1001 is the id of the setting (for example 1)
       
   462     * 0x1002 is the value of the setting (for example localapp:0x012345678)
       
   463     * 
       
   464     * So three keys per setting.
       
   465     * 
       
   466     * Settings from cenrep override those from XML
       
   467     */
       
   468     
       
   469     TUint32 crKey( KAIPluginSettingsKeyRangeStart );
       
   470 
       
   471     TBool moreSettings( ETrue );
       
   472     
       
   473     HBufC* pluginId = HBufC::NewLC(
       
   474             NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   475     
       
   476     HBufC* settingValue = HBufC::NewLC(
       
   477             NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   478     
       
   479     HBufC* settingKey = HBufC::NewLC(
       
   480             NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   481     
       
   482     TPtr pluginIdPtr( pluginId->Des() );
       
   483     TPtr settingValuePtr( settingValue->Des() );
       
   484     TPtr settingKeyPtr( settingKey->Des() );
       
   485     
       
   486     TInt32 settingId( 0 );
       
   487 
       
   488     TInt err( KErrNone );
       
   489     TBool settingFound( EFalse );
       
   490     
       
   491     while( moreSettings )
       
   492         {
       
   493         settingFound = EFalse;
       
   494         
       
   495         pluginIdPtr.Zero();
       
   496         settingValuePtr.Zero();
       
   497         settingKeyPtr.Zero();
       
   498         
       
   499         //Get the name of plugin with the Settings/ prefix
       
   500         err = iAISettingsRepository->Get( crKey++, pluginIdPtr );       
       
   501    
       
   502         // remove the Settings/ prefix if it is located at the start of the string
       
   503         if( pluginIdPtr.FindC( AiUiDef::xml::propertyClass::KSettings ) == 0 )
       
   504             {   
       
   505             pluginIdPtr.Delete( 0, 
       
   506                     AiUiDef::xml::id::KSettingsIdSeparator().Length() +
       
   507                     AiUiDef::xml::propertyClass::KSettings().Length() );               
       
   508             }
       
   509             
       
   510         // does the setting belong to this plugin
       
   511         if( err == KErrNone && pluginIdPtr == aPubInfo.iName )
       
   512             {
       
   513             // Get the settings id 
       
   514             err = iAISettingsRepository->Get( crKey++, settingKeyPtr );
       
   515             
       
   516             if( err == KErrNone )
       
   517                 {
       
   518                 err = AiUtility::ParseInt( settingId,settingKeyPtr );
       
   519                 }
       
   520             
       
   521             if( err == KErrNone )
       
   522                 {                
       
   523                 // Get the actual value of the setting
       
   524                 err = iAISettingsRepository->Get( crKey++, settingValuePtr );    
       
   525                 
       
   526                 // Ignore possible placeholder data in cenrep                                
       
   527                 if( err == KErrNone && settingValuePtr.Compare( KSettingsDummyData ) != 0 )
       
   528                     {
       
   529                     // Try to find an existing setting for this
       
   530                     for( TInt j = 0; j < aPluginSettings.Count(); j++  )
       
   531                         {
       
   532                         MAiPluginSettings* setting( aPluginSettings[j] );                         
       
   533                         MAiPluginSettingsItem& item( setting->AiPluginSettingsItem() );                       
       
   534                         
       
   535                         // Existing setting found => replace it
       
   536                         if( item.Key() == settingId && item.PublisherId() == aPubInfo.iUid )
       
   537                             {
       
   538                             item.SetValueL( settingValuePtr, EFalse );
       
   539                             settingFound = ETrue;
       
   540                             break;
       
   541                             }
       
   542                         }
       
   543                     
       
   544                     // Existing setting not found => append new one ONLY if we
       
   545                     // are dealing with the icon overrides or toolbar shortcuts
       
   546                     if( !settingFound && 
       
   547                        ( ( settingId & KScutFlagBitToolbarShortcut ) || 
       
   548                          ( settingId & KScutFlagBitIconOverride ) ) )
       
   549                         {
       
   550                         MAiPluginSettings* settings( AiUtility::CreatePluginSettingsL() );
       
   551                         CleanupDeletePushL( settings );
       
   552                         
       
   553                         MAiPluginSettingsItem& item( settings->AiPluginSettingsItem() );
       
   554                         
       
   555                         item.SetPublisherId( aPubInfo.iUid );
       
   556                         item.SetKey( settingId );                
       
   557                         item.SetValueL( settingValuePtr, EFalse );                                            
       
   558                         
       
   559                         aPluginSettings.Append( settings );                        
       
   560                         CleanupStack::Pop( settings );
       
   561                         }
       
   562                     }
       
   563                 }                                 
       
   564             else
       
   565                 {
       
   566                 // no settings id found => invalid settings in cenrep
       
   567                 __PRINT8( __DBG_FORMAT8("CXmlUiController::GetSettingsFromCRL: ERROR: invalid settings. key: %d pluginname: %S id: %d value: %S"), crKey, pluginId, settingId, settingValue );                    
       
   568                 }            
       
   569             }               
       
   570         else if( err != KErrNone )
       
   571             {
       
   572             // name of the plugin not found => no more settings
       
   573             moreSettings = EFalse;            
       
   574             }                          
       
   575         else
       
   576             {
       
   577             // not the correct setting for this plugin
       
   578             crKey += KAI2CrKeyIncrementBy2;
       
   579             }
       
   580         }
       
   581 
       
   582     CleanupStack::PopAndDestroy( 3, pluginId ); // settingValue, settingKey
       
   583     }
       
   584 
       
   585 // ----------------------------------------------------------------------------
       
   586 // CXmlUiController::GetContentModelL()
       
   587 // ----------------------------------------------------------------------------
       
   588 //
       
   589 // ContentModelL()
       
   590 void CXmlUiController::GetContentModelL( const TAiPublisherInfo& aPubInfo,         
       
   591     RAiSettingsItemArray& aSettings )
       
   592     {
       
   593     if ( aPubInfo.iNamespace == KNativeUiNamespace )
       
   594         {
       
   595         // This controller doesn't provide content model for native ui namespace
       
   596         return;
       
   597         }
       
   598     
       
   599     // Find the node for the publisher
       
   600 	// TODO Does not work if widget is in view  
       
   601     RPointerArray<CXnNodeAppIf> list( 
       
   602         UiEngineL()->FindContentSourceNodesL( aPubInfo.iNamespace ) );
       
   603     CleanupClosePushL( list );
       
   604     
       
   605     CXnNodeAppIf* publisherNode( NULL );
       
   606     
       
   607     if ( list.Count() > 0 )
       
   608         {
       
   609         publisherNode = list[0];
       
   610         }
       
   611          
       
   612     CleanupStack::PopAndDestroy( &list );
       
   613     
       
   614     if( !publisherNode )
       
   615         {
       
   616         return;
       
   617         }
       
   618     
       
   619     // Find ui plugin node for the data plugin
       
   620     CXnNodeAppIf* parentNode( publisherNode->ParentL() );
       
   621     
       
   622     // parent must be correct type
       
   623     if( parentNode->InternalDomNodeType() == _L8("widget") )
       
   624         {
       
   625         // Get plugin configurations
       
   626         GetConfigurationsL( *parentNode, aSettings, AiUiDef::xml::element::K16Plugin());
       
   627         CPmODTIterator* iter = CPmODTIterator::NewL( *parentNode );
       
   628         CleanupStack::PushL( iter );
       
   629         CXnNodeAppIf* node = iter->First();
       
   630         while( node )
       
   631             {
       
   632             const TDesC8& nodeType = node->Type()->Type();
       
   633             if( nodeType == XnPropertyNames::action::KActions)
       
   634                 {
       
   635                 node = iter->SkipBranchL();
       
   636                 }
       
   637             // Get the content model and configuration for the supported elements
       
   638             else if( nodeType == AiUiDef::xml::element::KImage ||
       
   639                      nodeType == AiUiDef::xml::element::KText ||
       
   640                      nodeType == AiUiDef::xml::element::KNewsTicker )
       
   641                 {
       
   642                 // Is created in GetContenItem and used in GetConfigurationsL
       
   643                 HBufC* confOwner( NULL );
       
   644                 // get content item for the element, confOwner is filled
       
   645                 GetContentItemL( *node, aSettings, confOwner );
       
   646                 if( confOwner )
       
   647                     {
       
   648                     CleanupStack::PushL( confOwner );
       
   649                     // get configurations for the element
       
   650                     GetConfigurationsL( *node, aSettings, *confOwner );
       
   651                     CleanupStack::PopAndDestroy( confOwner );
       
   652                     }
       
   653                 node = iter->SkipBranchL();
       
   654                 }
       
   655             else
       
   656                 {
       
   657                 node = iter->NextL();
       
   658                 }
       
   659             }
       
   660         CleanupStack::PopAndDestroy( iter );
       
   661         }
       
   662     }
       
   663 
       
   664 // ----------------------------------------------------------------------------
       
   665 // CXmlUiController::GetContentItemL()
       
   666 // ----------------------------------------------------------------------------
       
   667 //
       
   668 // ContentItemL()
       
   669 void CXmlUiController::GetContentItemL( CXnNodeAppIf& aNode, 
       
   670     RAiSettingsItemArray& aSettings, HBufC*& aItemName )
       
   671     {
       
   672     // Find property node
       
   673     RPointerArray<CXnNodeAppIf> childNodes( aNode.ChildrenL() );
       
   674     CleanupClosePushL( childNodes );
       
   675     
       
   676     TInt count( childNodes.Count() );
       
   677     
       
   678     for ( TInt i = 0; i < count; i++ )
       
   679         {
       
   680         CXnNodeAppIf* node( childNodes[i] );
       
   681         
       
   682         if( node->Type()->Type() == XnPropertyNames::action::KProperty )
       
   683             {
       
   684             HBufC* name = PropertyValueL( *node, AiUiDef::xml::property::KClass );
       
   685             CleanupStack::PushL( name );
       
   686         
       
   687             if( name )
       
   688                 {
       
   689                 // Content model found for the element, create content item
       
   690                 MAiPluginSettings* settings = AiUtility::CreatePluginSettingsL();
       
   691                 CleanupDeletePushL( settings );
       
   692                 
       
   693                 MAiPluginContentItem& item = settings->AiPluginContentItem();
       
   694                 
       
   695                 // Type of the element is needed in content model 
       
   696                 HBufC* type( NULL ); 
       
   697                 type = AiUtility::CopyToBufferL( type, aNode.Type()->Type());
       
   698                 CleanupStack::PushL( type );
       
   699                 item.SetTypeL( *type );
       
   700                 CleanupStack::PopAndDestroy( type );
       
   701                 
       
   702                 item.SetNameL( *name );
       
   703                 
       
   704                 aItemName = name;
       
   705                 aSettings.AppendL( settings );
       
   706                 CleanupStack::Pop( settings );
       
   707                 }
       
   708             
       
   709             // Ownership is given to aItemName
       
   710             CleanupStack::Pop( name );
       
   711             
       
   712             // First property element, which has class attribute is selected
       
   713             break;
       
   714             }
       
   715         }
       
   716     
       
   717     CleanupStack::PopAndDestroy( &childNodes );
       
   718     }
       
   719 
       
   720 // ----------------------------------------------------------------------------
       
   721 // CXmlUiController::GetConfigurationsL()
       
   722 // ----------------------------------------------------------------------------
       
   723 //
       
   724 // ConfigurationItemsL()
       
   725 void CXmlUiController::GetConfigurationsL( CXnNodeAppIf& aNode, 
       
   726     RAiSettingsItemArray& aSettings, const TDesC& aConfOwner  )
       
   727     {    
       
   728     // Find configuration nodes
       
   729     RPointerArray< CXnNodeAppIf > nodes( aNode.ChildrenL() );
       
   730     CleanupClosePushL( nodes );
       
   731 
       
   732     // Collect settings
       
   733     TInt count( nodes.Count() );
       
   734     
       
   735     for( TInt j = 0; j < count; j++ )
       
   736         {
       
   737         CXnNodeAppIf* node( nodes[j] );
       
   738         
       
   739         if( node->Type()->Type() == AiUiDef::xml::element::KConfiguration )
       
   740             {
       
   741             HBufC* name( PropertyValueL( *node, AiUiDef::xml::property::KName ) );
       
   742             CleanupStack::PushL( name );
       
   743 
       
   744             HBufC* value( PropertyValueL( *node, AiUiDef::xml::property::KValue ) );
       
   745             CleanupStack::PushL( value );
       
   746 
       
   747             MAiPluginSettings* settings = AiUtility::CreatePluginSettingsL();
       
   748             CleanupDeletePushL( settings );
       
   749                
       
   750             MAiPluginConfigurationItem& item( settings->AiPluginConfigurationItem() );
       
   751      
       
   752             item.SetOwnerL( aConfOwner );
       
   753             item.SetNameL( *name );
       
   754             item.SetValueL( *value );
       
   755             
       
   756             // Append settings into array.
       
   757             aSettings.AppendL( settings );
       
   758         
       
   759             CleanupStack::Pop( settings );
       
   760             CleanupStack::PopAndDestroy( value );    
       
   761             CleanupStack::PopAndDestroy( name );        
       
   762             }
       
   763         }
       
   764     
       
   765     CleanupStack::PopAndDestroy( &nodes );
       
   766     }
       
   767 
       
   768 // ----------------------------------------------------------------------------
       
   769 // CXmlUiController::ActivateUI()
       
   770 // ----------------------------------------------------------------------------
       
   771 //
       
   772 void CXmlUiController::ActivateUI()
       
   773     {
       
   774     }
       
   775 
       
   776 // ----------------------------------------------------------------------------
       
   777 // CXmlUiController::GetContentObserver()
       
   778 // ----------------------------------------------------------------------------
       
   779 //
       
   780 MAiContentObserver& CXmlUiController::GetContentObserver()
       
   781     {
       
   782     return *iObserver;
       
   783     }
       
   784 
       
   785 // ----------------------------------------------------------------------------
       
   786 // CXmlUiController::SetEventHandler()
       
   787 // ----------------------------------------------------------------------------
       
   788 //
       
   789 void CXmlUiController::SetEventHandler( MAiFwEventHandler& aFwEventHandler )
       
   790     {
       
   791     iFwEventHandler = &aFwEventHandler;
       
   792     }
       
   793 
       
   794 // ----------------------------------------------------------------------------
       
   795 // CXmlUiController::RemovePluginFromUI()
       
   796 // ----------------------------------------------------------------------------
       
   797 //
       
   798 void CXmlUiController::RemovePluginFromUI( MAiPropertyExtension& aPlugin )
       
   799     {
       
   800     CContentRenderer* contentRenderer = 
       
   801         static_cast< CContentRenderer* >( iObserver );
       
   802     
       
   803     if ( contentRenderer )
       
   804         {
       
   805         contentRenderer->CleanPluginFromUi( aPlugin );
       
   806         }
       
   807     }
       
   808 
       
   809 // ----------------------------------------------------------------------------
       
   810 // CXmlUiController::FwEventHandler()
       
   811 // ----------------------------------------------------------------------------
       
   812 //
       
   813 MAiFwEventHandler* CXmlUiController::FwEventHandler() const
       
   814     {
       
   815     return iFwEventHandler;
       
   816     }
       
   817 
       
   818 // ----------------------------------------------------------------------------
       
   819 // CXmlUiController::MainInterface()
       
   820 // ----------------------------------------------------------------------------
       
   821 //
       
   822 MAiMainUiController* CXmlUiController::MainInterface()
       
   823     {
       
   824     return this;
       
   825     }
       
   826 
       
   827 // ----------------------------------------------------------------------------
       
   828 // CXmlUiController::SecondaryInterface()
       
   829 // ----------------------------------------------------------------------------
       
   830 //
       
   831 MAiSecondaryUiController* CXmlUiController::SecondaryInterface()
       
   832     {
       
   833     return NULL;
       
   834     }
       
   835 
       
   836 // ----------------------------------------------------------------------------
       
   837 // CXmlUiController::RunApplicationL()
       
   838 // ----------------------------------------------------------------------------
       
   839 //
       
   840 void CXmlUiController::RunApplicationL()
       
   841     {
       
   842     iRunningAsMain = ETrue;
       
   843     
       
   844     User::LeaveIfError( 
       
   845         EikStart::RunApplication( &CXmlUiController::NewApplication ) );
       
   846     }
       
   847 
       
   848 // ----------------------------------------------------------------------------
       
   849 // CXmlUiController::CoeEnv()
       
   850 // ----------------------------------------------------------------------------
       
   851 //
       
   852 CCoeEnv& CXmlUiController::CoeEnv()
       
   853     {
       
   854     __ASSERT_ALWAYS( iAppUi, Panic(ECriticalPointerNull) );
       
   855     return *iAppUi->CoeEnv();
       
   856     }
       
   857 
       
   858 // ----------------------------------------------------------------------------
       
   859 // CXmlUiController::SetUiFrameworkObserver()
       
   860 // ----------------------------------------------------------------------------
       
   861 //
       
   862 void CXmlUiController::SetUiFrameworkObserver( 
       
   863     MAiUiFrameworkObserver& aObserver )
       
   864     {
       
   865     iUiFrameworkObserver = &aObserver;
       
   866     }
       
   867 
       
   868 // ----------------------------------------------------------------------------
       
   869 // CXmlUiController::IsMenuOpen()
       
   870 // ----------------------------------------------------------------------------
       
   871 //
       
   872 TBool CXmlUiController::IsMenuOpen()
       
   873     {
       
   874     TBool menuOpen( EFalse );
       
   875     TRAP_IGNORE( menuOpen = UiEngineL()->IsMenuDisplaying() );
       
   876     return menuOpen;
       
   877     }
       
   878 
       
   879 // ----------------------------------------------------------------------------
       
   880 // CXmlUiController::UiFrameworkObserver()
       
   881 // ----------------------------------------------------------------------------
       
   882 //
       
   883 MAiUiFrameworkObserver* CXmlUiController::UiFrameworkObserver() const
       
   884     {
       
   885     return iUiFrameworkObserver;
       
   886     }
       
   887 
       
   888 // ----------------------------------------------------------------------------
       
   889 // CXmlUiController::HandleUiEvent()
       
   890 // ----------------------------------------------------------------------------
       
   891 //
       
   892 TBool CXmlUiController::HandleUiEvent( TAny* aEvent, const TDesC8& aParam )
       
   893     {
       
   894     CXnNodeAppIf* event( static_cast<CXnNodeAppIf*>( aEvent ) );
       
   895     
       
   896     TBool retval( EFalse );
       
   897     
       
   898     if( event )
       
   899         {
       
   900         TPtrC8 param1;
       
   901         TPtrC8 param2;
       
   902         const TDesC8& eventString(
       
   903                 aParam.Mid( AiUiDef::xml::event::KUiEventPrefix().Length() ) );
       
   904         
       
   905         // Extract event name
       
   906         TInt  paramPos( eventString.Locate( KEventParameterSeparator ) );
       
   907         
       
   908         const TDesC8& eventName( eventString.Left( Max( 0, paramPos ) ) );
       
   909     
       
   910         if( eventName == AiUiDef::xml::event::KFocusGained )
       
   911             {
       
   912             // Resolve event parameters
       
   913             ResolveEventParameters( eventString, param1, param2 );
       
   914             
       
   915             TRAP_IGNORE( HandleFocusGainedL( param1, param2, *event ) );    
       
   916             
       
   917             retval = ETrue;
       
   918             }
       
   919         else if( eventName == AiUiDef::xml::event::KSetElementSizeToCPS )
       
   920             {
       
   921             // Resolve event parameters
       
   922             ResolveEventParameters( eventString, param1, param2 );
       
   923             
       
   924             TRAP_IGNORE( HandleSetElementSizeL( param1, *event ));
       
   925             
       
   926             retval = ETrue;
       
   927             }
       
   928         }
       
   929     
       
   930     return retval;
       
   931     }
       
   932 
       
   933 // ----------------------------------------------------------------------------
       
   934 // CXmlUiController::HandleSetElementSizeL()
       
   935 // ----------------------------------------------------------------------------
       
   936 //
       
   937 void CXmlUiController::HandleSetElementSizeL( const TDesC8& aElementName, 
       
   938     CXnNodeAppIf& aOrigin )
       
   939     {
       
   940     __UHEAP_MARK;
       
   941     // Resolve ui elements
       
   942     CXnNodeAppIf* element( 
       
   943             UiEngineL()->FindNodeByIdL( aElementName, aOrigin.Namespace() ) );
       
   944     
       
   945     LeaveIfNull( element, KErrNotFound );
       
   946 
       
   947     TRect rect( element->Rect() );
       
   948     
       
   949     HBufC* elementName( NULL );
       
   950     elementName = AiUtility::CopyToBufferL( elementName, aElementName );
       
   951     CleanupStack::PushL( elementName );
       
   952     
       
   953     iCPSpublisher->PublishSizeL( *elementName, rect.Width(), rect.Height() );
       
   954     
       
   955     CleanupStack::PopAndDestroy( elementName );
       
   956     
       
   957     __UHEAP_MARKEND;    
       
   958     }
       
   959 
       
   960 // ----------------------------------------------------------------------------
       
   961 // CXmlUiController::HandleFocusGainedL()
       
   962 // ----------------------------------------------------------------------------
       
   963 //
       
   964 void CXmlUiController::HandleFocusGainedL( const TDesC8& aUiElement1,
       
   965     const TDesC8& aUiElement2, CXnNodeAppIf& aOrigin )
       
   966     {
       
   967     // Resolve ui elements
       
   968     CXnNodeAppIf* element1( 
       
   969         UiEngineL()->FindNodeByIdL( aUiElement1, aOrigin.Namespace() ) );
       
   970     
       
   971     LeaveIfNull( element1, KErrNotFound );
       
   972     
       
   973     CXnNodeAppIf* element2( 
       
   974         UiEngineL()->FindNodeByIdL( aUiElement2, aOrigin.Namespace() ) );
       
   975     
       
   976     LeaveIfNull( element2, KErrNotFound );
       
   977     
       
   978     // swap display properties between ui elements
       
   979     CXnProperty* display1( 
       
   980         element1->GetPropertyL( XnPropertyNames::style::common::KDisplay ) );
       
   981     
       
   982     LeaveIfNull( display1, KErrNotFound );
       
   983     
       
   984     CXnProperty* display2(
       
   985         element2->GetPropertyL( XnPropertyNames::style::common::KDisplay ) );
       
   986     
       
   987     LeaveIfNull( display2, KErrNotFound );
       
   988     
       
   989     display1 = display1->CloneL();
       
   990     CleanupStack::PushL( display1 );
       
   991     
       
   992     display2 = display2->CloneL();
       
   993     CleanupStack::PushL( display2 );
       
   994     
       
   995     element1->SetPropertyL( display2 );
       
   996     CleanupStack::Pop( display2 );
       
   997     
       
   998     element2->SetPropertyL( display1 );
       
   999     CleanupStack::Pop( display1 );
       
  1000     }
       
  1001 
       
  1002 // ----------------------------------------------------------------------------
       
  1003 // CXmlUiController::NewApplication()
       
  1004 // ----------------------------------------------------------------------------
       
  1005 //
       
  1006 CApaApplication* CXmlUiController::NewApplication()
       
  1007     {
       
  1008     CXmlUiController* self = static_cast<CXmlUiController*>(Dll::Tls());
       
  1009     __ASSERT_ALWAYS( self, Panic(ECriticalPointerNull) );
       
  1010     return CApplication::New(*self);
       
  1011     }
       
  1012 
       
  1013 const TImplementationProxy KImplementationTable[] =
       
  1014     {
       
  1015     IMPLEMENTATION_PROXY_ENTRY(KImplementationUidXmlUiController, CXmlUiController::NewL)
       
  1016     };
       
  1017 
       
  1018 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
  1019     {
       
  1020     aTableCount = sizeof(KImplementationTable) / sizeof(TImplementationProxy);
       
  1021     return KImplementationTable;
       
  1022     }
       
  1023