idlehomescreen/xmluirendering/uiengine/src/xncomposer.cpp
branchRCL_3
changeset 83 5456b4e8b3a8
child 88 3321d3e205b6
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2008-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:  Application configuration composer
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <s32file.h>
       
    20 #include <utf.h>
       
    21 
       
    22 // User includes
       
    23 #include "xncomposer.h"
       
    24 #include "xnplugindata.h"
       
    25 #include "xnrootdata.h"
       
    26 #include "xnviewdata.h"
       
    27 #include "xnodt.h"
       
    28 #include "xnproperty.h"
       
    29 #include "xnresource.h"
       
    30 #include "xndomdocument.h"
       
    31 #include "xndomnode.h"
       
    32 #include "xndomlist.h"
       
    33 #include "xndomattribute.h"
       
    34 #include "xnpanic.h"
       
    35 #include "xnplugindefs.h"
       
    36 #include "xnviewmanager.h"
       
    37 #include "xnappuiadapter.h"
       
    38 #include "xnviewadapter.h"
       
    39 #include "xnbackgroundmanager.h"
       
    40 
       
    41 // Constants
       
    42 _LIT8( KStateError, "Error" );
       
    43 
       
    44 _LIT8( KXmluiml, "xmluiml" );
       
    45 _LIT8( KApp, "application" );
       
    46 _LIT8( KViews, "views" );
       
    47 _LIT8( KWidget, "widget" );
       
    48 _LIT8( KUseEmptyWidget, "use_empty_widget" );
       
    49 
       
    50 _LIT8( KEmptyWidgetUid, "0x2001F47F" );
       
    51 
       
    52 _LIT( KCDrive, "C:" );
       
    53 _LIT8( KTagXuikon, "xuikon" );
       
    54 
       
    55 using namespace hspswrapper;
       
    56 
       
    57 // ======== LOCAL FUNCTIONS ========
       
    58 // --------------------------------------------------------------------------
       
    59 // ItemValueL
       
    60 // Get property value from configuration.
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 static HBufC* ItemValueL( CHspsConfiguration& aConfiguration, 
       
    64     const TDesC8& aItemId,
       
    65     const TDesC8& aName,
       
    66     const TBool aUseUtfConversion = EFalse )
       
    67     {
       
    68     HBufC* ret = NULL;
       
    69 
       
    70     RPointerArray<CItemMap>& settingsList = aConfiguration.Settings();    
       
    71     for( TInt i = 0; i < settingsList.Count(); i++ )
       
    72         {
       
    73         CItemMap* setting = settingsList[i];
       
    74         if( !setting )
       
    75             {
       
    76             continue;
       
    77             }
       
    78         
       
    79         if( setting->ItemId() == aItemId )
       
    80             {
       
    81             RPointerArray<CPropertyMap>& properties = setting->Properties();
       
    82             for( TInt j = 0; j < properties.Count(); j++ )
       
    83                 {
       
    84                 CPropertyMap* property = properties[j];
       
    85                 if( !property )
       
    86                     {
       
    87                     continue;
       
    88                     }
       
    89                 
       
    90                 if( property->Name() == aName )
       
    91                     {
       
    92                     if( aUseUtfConversion )
       
    93                         {
       
    94                         ret = CnvUtfConverter::ConvertToUnicodeFromUtf8L( property->Value() );
       
    95                         }
       
    96                     else
       
    97                         {
       
    98                         ret = HBufC::NewL( property->Value().Length() );
       
    99                         ret->Des().Copy( property->Value() );
       
   100                         }
       
   101                     
       
   102                     break;
       
   103                     }
       
   104                 }            
       
   105             break;
       
   106             }    
       
   107         }        
       
   108     return ret;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Finds recursively node by name
       
   113 // @return    returns pointer to desired node, NULL if nothing found 
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 static CXnDomNode* FindNodeByName( CXnDomNode* aNode, const TDesC8& aName )
       
   117     {
       
   118     if ( !aNode )
       
   119         {        
       
   120         return NULL;
       
   121         }
       
   122 
       
   123     if ( aNode->Name() == aName )
       
   124         {
       
   125         return aNode;
       
   126         }
       
   127 
       
   128     CXnDomList& list( aNode->ChildNodes() );
       
   129 
       
   130     for ( TInt i = 0; i < list.Length() ; i++ )
       
   131         {
       
   132         CXnDomNode* retval( FindNodeByName(
       
   133                 static_cast< CXnDomNode* >( list.Item( i ) ), aName ) );
       
   134 
       
   135         if ( retval )
       
   136             {
       
   137             return retval;
       
   138             }
       
   139         }
       
   140 
       
   141     return NULL;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Finds template publisher name
       
   146 //  
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 static const TDesC8& FindTemplatePublisherName( CXnDomNode* aNode )
       
   150     {
       
   151     if ( !aNode )
       
   152         {        
       
   153         return KNullDesC8();
       
   154         }
       
   155 
       
   156     CXnDomList& list( aNode->ChildNodes() );
       
   157     
       
   158     for ( TInt i = 0; i < list.Length(); i++ )
       
   159         {
       
   160         CXnDomNode* node = static_cast< CXnDomNode* >( list.Item( i ) );
       
   161 
       
   162         // Find <configuration> element
       
   163         if ( node->Name() == KConfigurationModel )
       
   164             {
       
   165             CXnDomList& attributes( node->AttributeList() );
       
   166     
       
   167             CXnDomAttribute* name(
       
   168                 static_cast< CXnDomAttribute* >(
       
   169                     attributes.FindByName( XnPropertyNames::action::KName ) ) );
       
   170         
       
   171             // Find attribute name="publisher" 
       
   172             if ( name && name->Value() == KPublisher )
       
   173                 {
       
   174                 CXnDomAttribute* value(
       
   175                     static_cast< CXnDomAttribute* >(
       
   176                         attributes.FindByName( XnPropertyNames::action::KValue ) ) );
       
   177                 
       
   178                 if ( value )
       
   179                     {                    
       
   180                     return value->Value();
       
   181                     }
       
   182                 }            
       
   183             }
       
   184         }
       
   185     
       
   186     return KNullDesC8();
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // FindNodeById
       
   191 // Finds recursively node by id
       
   192 // @return    returns pointer to desired node, NULL if nothing found 
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 static CXnDomNode* FindNodeById( CXnDomNode* aNode, const TDesC8& aId )
       
   196     {
       
   197     if ( !aNode )
       
   198         {        
       
   199         return NULL;
       
   200         }
       
   201 
       
   202     CXnDomList& attributes( aNode->AttributeList() );
       
   203 
       
   204     CXnDomAttribute* id(
       
   205         static_cast< CXnDomAttribute* >(
       
   206                 attributes.FindByName( XnPropertyNames::common::KId ) ) );
       
   207 
       
   208     if ( id && id->Value() == aId )
       
   209         {
       
   210         return aNode;
       
   211         }
       
   212 
       
   213     CXnDomList& list( aNode->ChildNodes() );
       
   214 
       
   215     for ( TInt i = 0; i < list.Length() ; i++ )
       
   216         {
       
   217         CXnDomNode* retval( FindNodeById(
       
   218                 static_cast< CXnDomNode* >( list.Item( i ) ), aId ) );
       
   219 
       
   220         if ( retval )
       
   221             {
       
   222             return retval;
       
   223             }
       
   224         }
       
   225 
       
   226     return NULL;
       
   227     }
       
   228 
       
   229 // ----------------------------------------------------------------------------
       
   230 // UpdateResourcesPathL
       
   231 // ----------------------------------------------------------------------------
       
   232 //
       
   233 static void UpdateResourcesPathL( CArrayPtrSeg< CXnResource >& aList, 
       
   234     TPtrC aNewPath )
       
   235     {
       
   236     TFileName newFilename;
       
   237 
       
   238     for ( TInt i = 0; i < aList.Count(); i++ )
       
   239         {
       
   240         CXnResource& res( *aList[i] );
       
   241         const TDesC& filename( res.FileName() );
       
   242 
       
   243         TParsePtrC fileParser( filename );
       
   244         TPtrC nameAndExt( fileParser.NameAndExt() );
       
   245 
       
   246         newFilename = aNewPath;
       
   247         newFilename.Append( nameAndExt );
       
   248 
       
   249         res.SetFileNameL( newFilename );
       
   250         }
       
   251     }
       
   252 
       
   253 // --------------------------------------------------------------------------
       
   254 // UpdateSettingsL
       
   255 // 
       
   256 // --------------------------------------------------------------------------
       
   257 //
       
   258 static void UpdateSettingsL( const TDesC8& aElementId,
       
   259     RPointerArray< CPropertyMap >& aProperties, CXnDomNode& aRootNode )
       
   260     {    
       
   261     CXnDomNode* node( FindNodeById( &aRootNode, aElementId ) );
       
   262 
       
   263     if( !node )
       
   264         {
       
   265         return;
       
   266         }
       
   267 
       
   268     CXnDomStringPool* sp( node->StringPool() );
       
   269 
       
   270     for ( TInt i = 0; i < aProperties.Count(); i++ )
       
   271         {
       
   272         CPropertyMap* property( aProperties[i] );
       
   273 
       
   274         const TDesC8& name( property->Name() );
       
   275         const TDesC8& value( property->Value() );
       
   276 
       
   277         CXnDomList& attributes( node->AttributeList() );
       
   278 
       
   279         CXnDomAttribute* attribute(
       
   280             static_cast< CXnDomAttribute* >( attributes.FindByName( name ) ) );
       
   281 
       
   282         if ( attribute )
       
   283             {
       
   284             // Update current attribute
       
   285             attribute->SetValueL( value );
       
   286             }
       
   287         else
       
   288             {
       
   289             // Need to create new attribute
       
   290             attribute = CXnDomAttribute::NewL( name, sp );
       
   291             CleanupStack::PushL( attribute );
       
   292 
       
   293             attribute->SetValueL( value );
       
   294 
       
   295             node->AttributeList().AddItemL( attribute );
       
   296             CleanupStack::Pop( attribute );
       
   297             }
       
   298         }
       
   299     }
       
   300 
       
   301 
       
   302 // --------------------------------------------------------------------------
       
   303 // UpdatePluginFromSettingsL()
       
   304 // Updates plugin from settings
       
   305 // --------------------------------------------------------------------------
       
   306 //
       
   307 static void UpdatePluginFromSettingsL( CHspsConfiguration& aConfiguration,
       
   308     CXnDomNode& aRootNode )
       
   309     {
       
   310     RPointerArray< CItemMap >& settings( aConfiguration.Settings() );
       
   311 
       
   312     for ( TInt i = 0; i < settings.Count(); i++ )
       
   313         {
       
   314         CItemMap* setting( settings[i] );
       
   315 
       
   316         const TDesC8& itemId( setting->ItemId() );
       
   317 
       
   318         RPointerArray< CPropertyMap >& properties( setting->Properties() );
       
   319 
       
   320         UpdateSettingsL( itemId, properties, aRootNode );
       
   321         }
       
   322     }
       
   323 
       
   324 // --------------------------------------------------------------------------
       
   325 // MergeLD()
       
   326 // --------------------------------------------------------------------------
       
   327 //
       
   328 static CXnDomNode* MergeLD( CXnDomNode* aRoot,  
       
   329     CXnPluginData& aPluginData, TBool aMergeView = EFalse )
       
   330     {
       
   331     CXnDomNode* parent( aPluginData.Owner() );
       
   332     
       
   333     CXnDomNode* childToFind( NULL );
       
   334 
       
   335     if ( aMergeView )
       
   336         {
       
   337         childToFind = FindNodeByName( aRoot, KView );
       
   338         }
       
   339     else
       
   340         {
       
   341         childToFind = FindNodeByName( aRoot, KWidget );
       
   342         }
       
   343     
       
   344     if( !childToFind || aRoot->Name() != KXmluiml )
       
   345         {
       
   346         delete aRoot;
       
   347         
       
   348         return NULL;
       
   349         }
       
   350 
       
   351     aPluginData.SetNode( childToFind );
       
   352     
       
   353     CXnDomList& list( aRoot->ChildNodes() );
       
   354            
       
   355     TInt index( list.ItemIndex( *childToFind ) );   
       
   356     
       
   357     CXnDomNode* node =
       
   358         static_cast< CXnDomNode* >( list.Item( index ) );
       
   359     
       
   360     list.RemoveItem( index );
       
   361 
       
   362     // sets namespace recursively
       
   363     node->SetOwnershipL( aPluginData.PluginId() );
       
   364     
       
   365     // Takes ownership
       
   366     parent->AddChildL( node );
       
   367 
       
   368     delete aRoot;
       
   369     aRoot = NULL;
       
   370         
       
   371     if ( aMergeView )
       
   372         {
       
   373         // Return the last view
       
   374         TInt index( parent->ChildNodes().Length() - 1 );
       
   375 
       
   376         return ( static_cast< CXnDomNode* >(
       
   377             parent->ChildNodes().Item( index ) ) );
       
   378         }
       
   379     else
       
   380         {
       
   381         // Return <widget>
       
   382         return node;
       
   383         }
       
   384     }
       
   385 
       
   386 // --------------------------------------------------------------------------
       
   387 // UseEmptyWidget
       
   388 // Determines whether to use empty widget in this view configuration
       
   389 // --------------------------------------------------------------------------
       
   390 //
       
   391 static TBool UseEmptyWidget( CXnDomNode& aView )
       
   392     {    
       
   393     CXnDomAttribute* attribute(
       
   394         static_cast< CXnDomAttribute* >( 
       
   395                 aView.AttributeList().FindByName( KUseEmptyWidget ) ) );
       
   396 
       
   397     if ( attribute && attribute->Value() == XnPropertyNames::KTrue )
       
   398         {
       
   399         return ETrue;
       
   400         }
       
   401     
       
   402     return EFalse;
       
   403     }
       
   404 
       
   405 // ======== MEMBER FUNCTIONS ========
       
   406 // --------------------------------------------------------------------------
       
   407 // CXnComposer::NewL
       
   408 // Two-phased constructor.
       
   409 // --------------------------------------------------------------------------
       
   410 //
       
   411 CXnComposer* CXnComposer::NewL( CHspsWrapper& aWrapper )
       
   412     {
       
   413     CXnComposer* self = new ( ELeave ) CXnComposer( aWrapper );
       
   414     CleanupStack::PushL( self );
       
   415     self->ConstructL();
       
   416     CleanupStack::Pop( self );
       
   417 
       
   418     return self;
       
   419     }
       
   420 
       
   421 // --------------------------------------------------------------------------
       
   422 // CXnComposer::~CXnComposer
       
   423 // Destructor
       
   424 // --------------------------------------------------------------------------
       
   425 //
       
   426 CXnComposer::~CXnComposer()
       
   427     {
       
   428     iFs.Close();
       
   429     }
       
   430 
       
   431 // --------------------------------------------------------------------------
       
   432 // CXnComposer::CXnComposer
       
   433 // C++ default constructor can NOT contain any code, that
       
   434 // might leave.
       
   435 // --------------------------------------------------------------------------
       
   436 //
       
   437 CXnComposer::CXnComposer( CHspsWrapper& aWrapper )
       
   438     : iWrapper( aWrapper )
       
   439     {
       
   440     }
       
   441 
       
   442 // --------------------------------------------------------------------------
       
   443 // CXnComposer::ConstructL
       
   444 // Symbian 2nd phase constructor can leave.
       
   445 // --------------------------------------------------------------------------
       
   446 //
       
   447 void CXnComposer::ConstructL()
       
   448     {
       
   449     User::LeaveIfError( iFs.Connect() );
       
   450     }
       
   451 
       
   452 // --------------------------------------------------------------------------
       
   453 // CXnComposer::ComposeRootL()
       
   454 // Composes the application root configuration
       
   455 // --------------------------------------------------------------------------
       
   456 //
       
   457 CXnODT* CXnComposer::ComposeRootL( CXnRootData& aRootData )
       
   458     {
       
   459     // Not owned
       
   460     iODT = NULL;
       
   461     
       
   462     // Get application configuration
       
   463     CHspsConfiguration* configuration( iWrapper.GetAppConfigurationL() );
       
   464     CleanupStack::PushL( configuration );
       
   465 
       
   466     const TDesC8& state( configuration->PluginInfo().ConfigurationState() );
       
   467     
       
   468     aRootData.SetConfigurationIdL( configuration->ConfId() );
       
   469            
       
   470     if ( state.CompareF( KStateError ) == 0 || 
       
   471         configuration->Resources().Count() == 0 )
       
   472         {
       
   473         CleanupStack::PopAndDestroy( configuration );
       
   474         
       
   475         return NULL;       
       
   476         }
       
   477         
       
   478     // Get application configuration odt resource
       
   479     CXnODT* odt = CXnODT::NewL();
       
   480     CleanupStack::PushL( odt );
       
   481     
       
   482     // Save for later usage, not owned
       
   483     iODT = odt;
       
   484     
       
   485     // Find a resource which can be internalized
       
   486     const CObjectMap* resourceObject = FindObject( 
       
   487             configuration->Resources(), KTagXuikon() );
       
   488     if ( !resourceObject )
       
   489         {
       
   490         CleanupStack::PopAndDestroy( 2, configuration );
       
   491         
       
   492         return NULL;
       
   493         }
       
   494     
       
   495     CXnDomNode* root( GetOdtL( *resourceObject, aRootData ) );       
       
   496     if ( !root )
       
   497         {        
       
   498         CleanupStack::PopAndDestroy( 2, configuration );
       
   499         
       
   500         return NULL;
       
   501         }
       
   502     
       
   503     odt->DomDocument().SetRootNode( root );
       
   504       
       
   505     // "views" node is the owner node of view nodes
       
   506     CXnDomNode* views( FindNodeByName( root, KViews ) );
       
   507         
       
   508     if ( !views )
       
   509         {
       
   510         CleanupStack::PopAndDestroy( 2, configuration );
       
   511         
       
   512         return NULL;        
       
   513         }
       
   514 
       
   515     CPluginInfo& info( configuration->PluginInfo() );
       
   516 
       
   517     aRootData.SetOwner( root );
       
   518     aRootData.SetNode( views );
       
   519     
       
   520     aRootData.SetPluginNameL( info.Name() );
       
   521     aRootData.SetPluginUidL( info.Uid() );
       
   522     
       
   523     aRootData.SetPluginTypeL( KApp );
       
   524     
       
   525     aRootData.SetMaxPages( info.MaxChild() );
       
   526 
       
   527     // Get plugins (= views) in this application configuration
       
   528     RPointerArray< CPluginMap >& plugins( configuration->PluginMaps() );
       
   529 
       
   530     if ( ( plugins.Count() == 0 ) || ( aRootData.MaxPages() <= 0 ) )
       
   531         {
       
   532         CleanupStack::PopAndDestroy( 2, configuration );
       
   533         
       
   534         return NULL;
       
   535         }
       
   536 
       
   537     RPointerArray< CXnPluginData >& array( aRootData.PluginData() );
       
   538     
       
   539     TInt index( 0 );
       
   540     
       
   541     for ( TInt i = 0; ( i < plugins.Count() ) && ( i < aRootData.MaxPages() );
       
   542         i++ )
       
   543         {
       
   544         CPluginMap* plugin( plugins[i] );
       
   545         
       
   546         CXnViewData* view = CXnViewData::NewLC( aRootData );
       
   547 
       
   548         // Give view data ownership to CXnRootData
       
   549         array.AppendL( view );                                 
       
   550         CleanupStack::Pop( view );
       
   551        
       
   552         view->SetOwner( views );  
       
   553         
       
   554         view->SetPluginIdL( plugin->PluginId() );
       
   555                 
       
   556         if ( plugin->ActivationState() )
       
   557             {            
       
   558             index = i;            
       
   559             }
       
   560 
       
   561         view->SetLockingStatus( plugin->LockingStatus() );
       
   562         }
       
   563 
       
   564     CXnViewData* initial( static_cast< CXnViewData* >( array[ index ] ) );
       
   565     
       
   566     initial->SetInitial();
       
   567         
       
   568     CleanupStack::Pop( odt );
       
   569     
       
   570     CleanupStack::PopAndDestroy( configuration );
       
   571                     
       
   572     // Ownership is granted to the caller
       
   573     return odt;          
       
   574     }
       
   575 
       
   576 // --------------------------------------------------------------------------
       
   577 // CXnComposer::ComposeViewL()
       
   578 // Composes a view
       
   579 // --------------------------------------------------------------------------
       
   580 //
       
   581 TInt CXnComposer::ComposeViewL( CXnViewData& aViewData )
       
   582     {    
       
   583     TInt retval( KXnErrViewPluginFailure );
       
   584     
       
   585     if ( aViewData.PluginId() == KNullDesC8 )
       
   586         {
       
   587         return retval;
       
   588         }
       
   589     
       
   590     // Get view configuration
       
   591     CHspsConfiguration* configuration(
       
   592         iWrapper.GetPluginConfigurationL( aViewData.PluginId() ) );
       
   593     CleanupStack::PushL( configuration );
       
   594 
       
   595     const TDesC8& state( configuration->PluginInfo().ConfigurationState() );
       
   596                      
       
   597     if ( state.CompareF( KStateError ) == 0 || 
       
   598         configuration->Resources().Count() == 0 )
       
   599         {               
       
   600         CleanupStack::PopAndDestroy( configuration );
       
   601         
       
   602         return retval;
       
   603         }
       
   604                   
       
   605     aViewData.SetConfigurationIdL( configuration->ConfId() );    
       
   606         
       
   607     // Find a resource which can be internalized
       
   608     const CObjectMap* resourceObject = FindObject( 
       
   609                 configuration->Resources(), KTagXuikon );
       
   610     if ( !resourceObject )
       
   611         {
       
   612         CleanupStack::PopAndDestroy( configuration );
       
   613         
       
   614         return retval;
       
   615         }
       
   616     
       
   617     CXnDomNode* root( GetOdtL( *resourceObject, aViewData ) );
       
   618     if ( !root )
       
   619         {               
       
   620         CleanupStack::PopAndDestroy( configuration );
       
   621         
       
   622         return retval;        
       
   623         }
       
   624 
       
   625     root->SetNamespaceL( aViewData.PluginId() );
       
   626     
       
   627     // Merge view to root. Note that root will be obsolete after this call
       
   628     CXnDomNode* viewRoot( MergeLD( root, aViewData, ETrue ) );
       
   629     
       
   630     if ( viewRoot )
       
   631         {                                                     
       
   632         // Finalise view data              
       
   633         CPluginInfo& info( configuration->PluginInfo() );
       
   634         aViewData.SetPluginNameL( info.Name() );
       
   635         aViewData.SetPluginUidL( info.Uid() );
       
   636 
       
   637         aViewData.SetPluginTypeL( KView );
       
   638         
       
   639         // Find first <plugin> element from this view
       
   640         CXnDomNode* pluginNode( FindNodeByName( viewRoot, KPlugin ) );
       
   641 
       
   642         UpdatePluginFromSettingsL( *configuration, *viewRoot );
       
   643                 
       
   644         aViewData.SetUseEmptyWidget( UseEmptyWidget( *viewRoot )  );   
       
   645 
       
   646         // Read wallpaper image path from HSPS
       
   647         CXnAppUiAdapter* appui = static_cast< CXnAppUiAdapter* >( iAvkonAppUi );
       
   648         CXnBackgroundManager& bgManager = appui->ViewAdapter().BgManager();
       
   649         
       
   650         // if page specific wallpaper feature is enabled
       
   651         if( bgManager.WallpaperType() == CXnBackgroundManager::EPageSpecific )
       
   652             {
       
   653             HBufC* bgImage = ItemValueL( *configuration,
       
   654                                          KWallpaper,
       
   655                                          KPath,
       
   656                                          ETrue );
       
   657             if ( bgImage )
       
   658                 {
       
   659                 CleanupStack::PushL( bgImage );
       
   660                 bgImage->Des().Trim();
       
   661                 if( bgImage && bgImage->Length() > 0 )
       
   662                     {                
       
   663                     bgManager.ConstructWallpaper( bgImage->Des(), aViewData );
       
   664                     }
       
   665                 CleanupStack::PopAndDestroy( bgImage );
       
   666                 }
       
   667             }
       
   668         if ( pluginNode )
       
   669             {            
       
   670             // This assumes all <plugin> elements are siblings
       
   671             CXnDomNode* pluginParent( pluginNode->Parent() );   
       
   672             
       
   673             CXnDomList& list( pluginParent->ChildNodes() );
       
   674         
       
   675             // Get plugins configuration
       
   676             RPointerArray< CPluginMap >& plugins( configuration->PluginMaps() );
       
   677                     
       
   678             RPointerArray< CXnPluginData >& array( aViewData.PluginData() );
       
   679 
       
   680             TInt count( 0 );
       
   681             
       
   682             for ( TInt i = 0; i < list.Length(); i++ )
       
   683                 {
       
   684                 CXnDomNode* node =
       
   685                     static_cast< CXnDomNode* >( list.Item( i ) );
       
   686         
       
   687                 // We are interested only about <plugin> elements
       
   688                 if ( node->Name() == KPlugin )
       
   689                     {
       
   690                     // Create plugin data
       
   691                     CXnPluginData* widget = CXnPluginData::NewLC( aViewData );
       
   692             
       
   693                     // Give ownership to view data
       
   694                     array.AppendL( widget );
       
   695                     CleanupStack::Pop( widget );
       
   696                             
       
   697                     // <plugin> element
       
   698                     widget->SetOwner( node );
       
   699                     
       
   700                     if ( count < plugins.Count() )
       
   701                         { 
       
   702                         CPluginMap* plugin( plugins[count] );
       
   703                         
       
   704                         widget->SetPluginIdL( plugin->PluginId() );
       
   705                         
       
   706                         widget->SetLockingStatus( plugin->LockingStatus() );
       
   707                         }
       
   708                     
       
   709                     count++;
       
   710                     }        
       
   711                 }                           
       
   712             }
       
   713         
       
   714         retval = KErrNone;
       
   715         }
       
   716     
       
   717     CleanupStack::PopAndDestroy( configuration );
       
   718     
       
   719     return retval;
       
   720     }
       
   721 
       
   722 // --------------------------------------------------------------------------
       
   723 // ComposeWidgetL()
       
   724 // Composes a widget
       
   725 // --------------------------------------------------------------------------
       
   726 //
       
   727 TInt CXnComposer::ComposeWidgetL( CXnPluginData& aPluginData )     
       
   728     {    
       
   729     TInt retval( KXnErrWidgetPluginFailure );
       
   730     
       
   731     if ( aPluginData.PluginId() == KNullDesC8 )
       
   732         {
       
   733         return retval;
       
   734         }
       
   735     
       
   736     // Get widget configuration
       
   737     CHspsConfiguration* configuration(
       
   738         iWrapper.GetPluginConfigurationL( aPluginData.PluginId() ) );
       
   739     CleanupStack::PushL( configuration );
       
   740 
       
   741     // Empty widget is not composed at all
       
   742     if ( configuration->PluginInfo().Uid().CompareF( KEmptyWidgetUid ) == 0 )
       
   743         {
       
   744         aPluginData.SetEmptyL( aPluginData.PluginId() );
       
   745         
       
   746         CleanupStack::PopAndDestroy( configuration );
       
   747         
       
   748         return KErrNone;
       
   749         }
       
   750     
       
   751     const TDesC8& state( configuration->PluginInfo().ConfigurationState() );
       
   752                      
       
   753     if ( state.CompareF( KStateError ) == 0 || 
       
   754         configuration->Resources().Count() == 0 )
       
   755         {               
       
   756         CleanupStack::PopAndDestroy( configuration );
       
   757         
       
   758         return retval;       
       
   759         }
       
   760     
       
   761     aPluginData.SetConfigurationIdL( configuration->ConfId() );    
       
   762                                 
       
   763     // Find a resource which can be internalized
       
   764     const CObjectMap* resourceObject = FindObject( 
       
   765                 configuration->Resources(), KTagXuikon );
       
   766     if ( !resourceObject )
       
   767         {
       
   768         CleanupStack::PopAndDestroy( configuration );
       
   769         
       
   770         return retval;
       
   771         }
       
   772     
       
   773     CXnDomNode* root( GetOdtL( *resourceObject, aPluginData ) );
       
   774     if ( !root )
       
   775         {
       
   776         CleanupStack::PopAndDestroy( configuration );        
       
   777 
       
   778         return retval;        
       
   779         }
       
   780 
       
   781     // Update plugin namespace
       
   782     root->SetNamespaceL( aPluginData.PluginId() );
       
   783 
       
   784     // Nested plugins are not supported currently. 
       
   785     // Note root will be obsolete after this call.
       
   786     CXnDomNode* widgetRoot( MergeLD( root, aPluginData ) );
       
   787 
       
   788     if ( widgetRoot )
       
   789         {
       
   790         // Finalise plugin data
       
   791         CPluginInfo& info( configuration->PluginInfo() );
       
   792         
       
   793         aPluginData.SetPluginNameL( info.Name() );
       
   794         aPluginData.SetPluginUidL( info.Uid() );
       
   795 
       
   796         aPluginData.SetPluginTypeL( info.Type() );
       
   797 
       
   798         UpdatePluginFromSettingsL( *configuration, *widgetRoot );
       
   799         
       
   800         if ( info.Type() == KKeyTemplate )
       
   801             {
       
   802             const TDesC8& name( FindTemplatePublisherName( widgetRoot ) );
       
   803             
       
   804             aPluginData.SetPublisherNameL( name );
       
   805             }
       
   806                 
       
   807         retval = KErrNone;                       
       
   808         }
       
   809     
       
   810     CleanupStack::PopAndDestroy( configuration );
       
   811     
       
   812     return retval;
       
   813     }
       
   814 
       
   815 // --------------------------------------------------------------------------
       
   816 // CXnComposer::GetOdtL()
       
   817 //
       
   818 // --------------------------------------------------------------------------
       
   819 //
       
   820 CXnDomNode* CXnComposer::GetOdtL( const CObjectMap& aObject,
       
   821     CXnPluginData& aPluginData )
       
   822     {
       
   823     if( !iODT )
       
   824         {
       
   825         return NULL;
       
   826         }
       
   827     
       
   828     CXnDomNode* root( NULL ); 
       
   829     
       
   830     TBuf8< KMaxFileName > resource;
       
   831     TFileName privatePath;
       
   832     TFileName filename;
       
   833 
       
   834     // Get private path
       
   835     User::LeaveIfError( iFs.PrivatePath( privatePath ) );
       
   836 
       
   837     // Get resource path and name
       
   838     resource = aObject.Path();
       
   839     resource.Append( aObject.NameL() );
       
   840 
       
   841     // Copy from TBuf8 to TBuf
       
   842     filename.Copy( resource );
       
   843 
       
   844     // insert private path and
       
   845     filename.Insert( 0, privatePath );
       
   846 
       
   847     // ... c-drive
       
   848     filename.Insert( 0, KCDrive );
       
   849 
       
   850     RFile file;
       
   851 
       
   852     User::LeaveIfError( file.Open( iFs, filename, EFileShareReadersOnly ) );
       
   853     CleanupClosePushL( file );
       
   854 
       
   855     TInt size( 0 );
       
   856     file.Size( size );
       
   857 
       
   858     if ( size )
       
   859         {
       
   860         CFileStore* store( CDirectFileStore::FromLC( file ) );
       
   861 
       
   862         RStoreReadStream instream;
       
   863         CleanupClosePushL( instream );
       
   864 
       
   865         instream.OpenLC( *store, store->Root() );
       
   866 
       
   867         // Consume header
       
   868         CXnODT::InternalizeHeaderL( instream );
       
   869         
       
   870         CArrayPtrSeg< CXnResource >* list( 
       
   871             CXnODT::InternalizeResourceListL( instream ) );
       
   872         
       
   873         aPluginData.SetResources( list );
       
   874 
       
   875         // Set correct resource path
       
   876         UpdateResourcesPathL( 
       
   877             *list, TParsePtrC( filename ).DriveAndPath() );            
       
   878                         
       
   879         root = iODT->InternalizeDomDocumentL( instream );
       
   880 
       
   881         // Destroy the stream object, close the instream, destroy store
       
   882         CleanupStack::PopAndDestroy( 3, store );
       
   883         }
       
   884 
       
   885     CleanupStack::PopAndDestroy( &file );
       
   886 
       
   887     return root;
       
   888     }
       
   889 
       
   890 // --------------------------------------------------------------------------
       
   891 // CXnComposer::FindObject()
       
   892 // Finds an object from the provided array 
       
   893 // --------------------------------------------------------------------------
       
   894 //
       
   895 const CObjectMap* CXnComposer::FindObject( 
       
   896         RPointerArray<CObjectMap>& aResourceObjects,
       
   897         const TDesC8& aTag ) const
       
   898     {
       
   899     CObjectMap* object = NULL;
       
   900     
       
   901     const TInt count = aResourceObjects.Count();
       
   902     if ( count )
       
   903         {   
       
   904         
       
   905         // Find an object with the provided tag
       
   906         for( TInt objectIndex=0; objectIndex < count; objectIndex++ )
       
   907             {
       
   908             CObjectMap* o = aResourceObjects[ objectIndex ];
       
   909             if ( o->Tag() == aTag )
       
   910                 {
       
   911                 object = o;
       
   912                 break;
       
   913                 }
       
   914             }
       
   915         
       
   916         // If the tag was not found, return first object
       
   917         if( !object )
       
   918             {
       
   919             object = aResourceObjects[ 0 ];
       
   920             }
       
   921         }
       
   922     
       
   923     return object;
       
   924     }
       
   925 
       
   926 //  End of File