idlehomescreen/xmluirendering/uiengine/src/xneditor.cpp
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 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:  Manages Ai3 personalization
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <StringLoader.h>
       
    20 #include <aknlistquerydialog.h> 
       
    21 #include <aknnotewrappers.h>
       
    22 #include <utf.h>
       
    23 #include <AknsWallpaperUtils.h>
       
    24 #include <centralrepository.h>
       
    25 #include <AknSkinsInternalCRKeys.h>
       
    26 #include "../../../inc/ai3.hrh"
       
    27 
       
    28 #include <xnuiengine.rsg>
       
    29 #include <hscontentcontrolui.h>
       
    30 #include <hscontentcontrol.h>
       
    31 
       
    32 // User includes
       
    33 #include "xnuiengine.h"
       
    34 #include "xnproperty.h"
       
    35 #include "xnnode.h"
       
    36 #include "xntype.h"
       
    37 #include "xntext.h"
       
    38 #include "xnappuiadapter.h"
       
    39 
       
    40 #include "xndomnode.h"
       
    41 #include "xndomproperty.h"
       
    42 #include "xndompropertyvalue.h"
       
    43 #include "xndomlist.h"
       
    44 #include "xndomattribute.h"
       
    45 #include "hspssapi.h"
       
    46 #include "cpssapi.h"
       
    47 #include "xneditmode.h"
       
    48 #include "xndomdocument.h"
       
    49 #include "xnnodeimpl.h"
       
    50 #include "xnodt.h"
       
    51 #include "xnplugindefs.h"
       
    52 
       
    53 #include "xnviewmanager.h"
       
    54 #include "xnplugindata.h"
       
    55 #include "xnrootdata.h"
       
    56 #include "xnviewdata.h"
       
    57 #include "xnwallpaperview.h"
       
    58 
       
    59 #include "xneditor.h"
       
    60 #include "xnpanic.h"
       
    61 
       
    62 using namespace hspswrapper;
       
    63 using namespace cpswrapper;
       
    64 
       
    65 // LOCAL CONSTANTS AND MACROS
       
    66 _LIT8( KEventPluginUnInstalled, "PluginUninstalled" );
       
    67 _LIT8( KEventRootConfActivated, "AppConfActivated" );
       
    68 _LIT8( KEventPluginUpdated, "PluginUpdated" );
       
    69 _LIT8( KEventPluginActivated, "PluginActivated" );
       
    70 _LIT8( KEventPluginInstalled, "PluginInstalled" );
       
    71 _LIT8( KEventPluginAdded, "PluginAdded" );
       
    72 _LIT8( KEventPluginRemoved, "PluginRemoved" );
       
    73 _LIT8( KEventPluginReplaced, "PluginReplaced" );
       
    74 
       
    75 _LIT8( KAi3Uid, "0x102750f0" );
       
    76 
       
    77 _LIT8( KEmptyWidgetUid, "0x2001F47F" );
       
    78 _LIT8( KDownload, "Editor/DownloadCaption" );
       
    79 
       
    80 _LIT8( KSingle, "single" );
       
    81 _LIT8( KMulti, "multi" );
       
    82 
       
    83 _LIT8( KWMUi, "WmContentControlUI" );
       
    84 
       
    85 const TInt32 KMultiInstanceUnlimitedValue = -1;
       
    86 const TInt32 KMultiInstanceHiddenValue = 0;
       
    87 
       
    88 const TUid KDummyUid = { 0x0000000 };
       
    89 enum
       
    90     {
       
    91     ECanBeAdded = 0x01,
       
    92     ECanBeRemoved
       
    93     };
       
    94 
       
    95 // ====================== LOCAL FUNTION PROTOTYPES ============================
       
    96 static void DeletePluginInfos( TAny* aObject );
       
    97 static void DeleteItemMaps( TAny* aObject );
       
    98 static void DeleteWidgetInfo( TAny* aObject );
       
    99 
       
   100 static TPtrC ParseWidgetName( const CHsContentInfo& aContentInfo );
       
   101 static void SetPropertyL( CXnNode& aNode, const TDesC8& aAttribute, 
       
   102                           const TDesC8& aValue );    
       
   103 static void ShowErrorNoteL( const TDesC& aMsg );      
       
   104 static CXnPluginData* DeterminePlugin( CXnViewManager& aViewManager, 
       
   105                                          CXnNode* aPredicate = NULL );
       
   106 static CXnPluginData* DeterminePlugin( 
       
   107                             RPointerArray< CXnPluginData >& aPlugins,                            
       
   108                             const CHsContentInfo& aContentInfo );
       
   109 
       
   110 // ============================ LOCAL FUNCTIONS ===============================
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // DeletePluginInfos
       
   114 // ---------------------------------------------------------------------------
       
   115 // 
       
   116 static void DeletePluginInfos( TAny* aObject )
       
   117     {
       
   118     reinterpret_cast<
       
   119         RPointerArray< hspswrapper::CPluginInfo >* >(
       
   120             aObject )->ResetAndDestroy();
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // DeleteItemMaps
       
   125 // ---------------------------------------------------------------------------
       
   126 // 
       
   127 static void DeleteItemMaps( TAny* aObject )
       
   128     {
       
   129     reinterpret_cast<
       
   130         RPointerArray< hspswrapper::CItemMap >* >(
       
   131             aObject )->ResetAndDestroy();
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // DeleteWidgetInfo
       
   136 // ---------------------------------------------------------------------------
       
   137 // 
       
   138 static void DeleteWidgetInfo( TAny* aObject )    
       
   139     {
       
   140     reinterpret_cast<
       
   141         RPointerArray< CHsContentInfo >* >( aObject )->ResetAndDestroy();
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // ParseWidgetName
       
   146 // ---------------------------------------------------------------------------
       
   147 // 
       
   148 static TPtrC ParseWidgetName( const CHsContentInfo& aContentInfo )
       
   149     {
       
   150     TPtrC retval( aContentInfo.Name() );
       
   151 
       
   152     TInt pos( retval.Locate( ':' ) );
       
   153 
       
   154     if ( pos != KErrNotFound )
       
   155         {
       
   156         retval.Set( retval.Right( retval.Length() - pos - 1 ) );
       
   157         }
       
   158 
       
   159     return retval;
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // SetPropertyL
       
   164 // ---------------------------------------------------------------------------
       
   165 // 
       
   166 static void SetPropertyL( CXnNode& aNode, 
       
   167     const TDesC8& aAttribute, const TDesC8& aValue )
       
   168     {
       
   169     CXnDomNode* node( aNode.DomNode() );
       
   170     
       
   171     if ( node )
       
   172         {
       
   173         CXnDomStringPool& sp( node->StringPool() );
       
   174 
       
   175         // create new property
       
   176         CXnDomPropertyValue* value = CXnDomPropertyValue::NewL( sp );
       
   177         CleanupStack::PushL( value );
       
   178 
       
   179         value->SetStringValueL( CXnDomPropertyValue::EString, aValue );
       
   180 
       
   181         CXnProperty* prop = CXnProperty::NewL( aAttribute, value, sp );
       
   182                     
       
   183         CleanupStack::Pop( value );
       
   184         CleanupStack::PushL( prop );
       
   185 
       
   186         aNode.SetPropertyL( prop );
       
   187 
       
   188         CleanupStack::Pop( prop );
       
   189         }
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // ShowErrorNoteL
       
   194 // ---------------------------------------------------------------------------
       
   195 // 
       
   196 static void ShowErrorNoteL( const TDesC& aMsg )
       
   197     {
       
   198     CAknErrorNote* note = new ( ELeave ) CAknErrorNote;
       
   199     CleanupStack::PushL( note );
       
   200 
       
   201     note->ExecuteLD( aMsg );
       
   202 
       
   203     CleanupStack::Pop( note );    
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // DeterminePlugin
       
   208 // Determinates target plugin where widget should be added
       
   209 // ---------------------------------------------------------------------------
       
   210 // 
       
   211 CXnPluginData* DeterminePlugin( CXnViewManager& aViewManager, 
       
   212     CXnNode* aPredicate )
       
   213     {
       
   214     CXnViewData& viewData( aViewManager.ActiveViewData() );
       
   215 
       
   216     if ( aPredicate )
       
   217         {
       
   218         CXnPluginData& plugin( viewData.Plugin( aPredicate ) );
       
   219 
       
   220         if ( !plugin.Occupied() )
       
   221             {
       
   222             return &plugin;
       
   223             }
       
   224         }
       
   225 
       
   226     RPointerArray< CXnNode >& nodes( aViewManager.PluginNodes() );
       
   227 
       
   228     for ( TInt i = 0; i < nodes.Count(); i++ )
       
   229         {
       
   230         CXnNode* node( nodes[i] );
       
   231 
       
   232         CXnPluginData& plugin( viewData.Plugin( node ) );
       
   233 
       
   234         if ( !plugin.Occupied() )
       
   235             {
       
   236             return &plugin;
       
   237             }
       
   238         }
       
   239 
       
   240     return NULL;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // DeterminePlugin
       
   245 // Determines target plugin based widget info
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 CXnPluginData* DeterminePlugin( RPointerArray< CXnPluginData >& aPlugins, 
       
   249     const CHsContentInfo& aContentInfo ) 
       
   250     {    
       
   251     for ( TInt i = 0; i < aPlugins.Count(); i++ )
       
   252         {
       
   253         CXnPluginData* plugin( aPlugins[i] );
       
   254         
       
   255         if ( plugin->Occupied() && plugin->PluginId() == aContentInfo.PluginId() )
       
   256             {
       
   257             return plugin;
       
   258             }
       
   259         }
       
   260     
       
   261     return NULL;
       
   262     }
       
   263 
       
   264 // ============================ MEMBER FUNCTIONS ===============================
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CXnEditor::NewL
       
   268 // ---------------------------------------------------------------------------
       
   269 // 
       
   270 CXnEditor* CXnEditor::NewL( CXnViewManager& aViewManager, 
       
   271     const TDesC8& aUid )
       
   272     {
       
   273     CXnEditor* self = CXnEditor::NewLC( aViewManager, aUid );
       
   274     CleanupStack::Pop( self );
       
   275     return self;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CXnEditor::NewLC
       
   280 // ---------------------------------------------------------------------------
       
   281 // 
       
   282 CXnEditor* CXnEditor::NewLC( CXnViewManager& aViewManager,
       
   283     const TDesC8& aUid )
       
   284     {
       
   285     CXnEditor* self = new ( ELeave ) CXnEditor( aViewManager );
       
   286     CleanupStack::PushL( self );
       
   287     self->ConstructL( aUid );
       
   288     return self;
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // CXnEditor::CXnEditor
       
   293 // ---------------------------------------------------------------------------
       
   294 // 
       
   295 CXnEditor::CXnEditor( CXnViewManager& aViewManager )
       
   296     : iViewManager( aViewManager ),
       
   297       iWidgetsVisibilityState( ETrue )
       
   298     {
       
   299     iViewManager.AddObserver( *this );
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // CXnEditor::ConstructL
       
   304 // ---------------------------------------------------------------------------
       
   305 // 
       
   306 void CXnEditor::ConstructL( const TDesC8& aUid )
       
   307     {
       
   308     iCpsWrapper = CCpsWrapper::NewL( *this );
       
   309     iHspsWrapper = CHspsWrapper::NewL( aUid, this );
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CXnEditor::~CXnEditor
       
   314 // ---------------------------------------------------------------------------
       
   315 // 
       
   316 CXnEditor::~CXnEditor()
       
   317     {
       
   318     iViewManager.RemoveObserver( *this );
       
   319     
       
   320     delete iCpsWrapper;
       
   321     delete iHspsWrapper;
       
   322     delete iPublisherMap;
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CXnEditor::IsCurrentViewFull
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 TBool CXnEditor::IsCurrentViewFull()
       
   330     {
       
   331     TBool viewFull = ETrue;
       
   332     
       
   333     RPointerArray< CXnPluginData >& plugins( 
       
   334         iViewManager.ActiveViewData().PluginData() );
       
   335                 
       
   336     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   337         {
       
   338         if ( !plugins[i]->Occupied() )
       
   339             {
       
   340             viewFull = EFalse;
       
   341             break;
       
   342             }
       
   343         }
       
   344     
       
   345     return viewFull;
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CXnEditor::FilterWidgetListL
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 void CXnEditor::FilterWidgetListL( CHsContentInfoArray& aContentInfoArray,
       
   353     TBool aIgnoreViewFull )
       
   354     {
       
   355     RPointerArray< CHsContentInfo >& list( aContentInfoArray.Array() );
       
   356     
       
   357     TBool viewFull = ( aIgnoreViewFull ? EFalse : IsCurrentViewFull() );
       
   358     
       
   359     for ( TInt i = 0; i < list.Count(); i++ )
       
   360         {
       
   361         CHsContentInfo* info( list[i] );
       
   362 
       
   363         info->SetCanBeAdded( EFalse );
       
   364         info->SetCanBeRemoved( EFalse );
       
   365         
       
   366         TInt result( 0 );
       
   367 
       
   368         if ( info->Type() != KKeyTemplate() )
       
   369             {   
       
   370             result = NonTemplateWidgetCanBeAddedRemovedL( *info );            
       
   371             }
       
   372         else
       
   373             {
       
   374             result = TemplateWidgetCanBeAddedRemovedL( *info );
       
   375             }
       
   376         
       
   377         if ( ( result & ECanBeAdded ) && !viewFull )
       
   378             {                        
       
   379             info->SetCanBeAdded( ETrue );            
       
   380             }
       
   381         
       
   382         if ( result & ECanBeRemoved )
       
   383             {
       
   384             info->SetCanBeRemoved( ETrue );
       
   385             }
       
   386         }            
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CXnEditor::TemplateWidgetCanBeAddedRemovedL
       
   391 // ---------------------------------------------------------------------------
       
   392 // 
       
   393 TInt CXnEditor::TemplateWidgetCanBeAddedRemovedL( 
       
   394     CHsContentInfo& aInfo )
       
   395 	{
       
   396 	TInt retval( 0 );
       
   397 	
       
   398 	TInt widgetCount( 0 );
       
   399 	
       
   400 	RPointerArray< CXnPluginData > plugins;
       
   401 	CleanupClosePushL( plugins );
       
   402 	
       
   403 	if ( aInfo.IsWrt() )
       
   404 	    {
       
   405 	    // Get plugins globally from all pages
       
   406 	    iViewManager.PluginDataL( plugins, ETrue );
       
   407 	    }
       
   408 	else
       
   409 	    {
       
   410 	    // Get plugins from current page
       
   411 	    iViewManager.PluginDataL( plugins, EFalse );
       
   412 	    }
       
   413 	    	
       
   414 	// Get widgets in current configuration
       
   415 	for ( TInt i = 0; i < plugins.Count(); i++ )
       
   416 		{
       
   417 		CXnPluginData* plugin( plugins[i] );
       
   418 		
       
   419 		if ( !plugin->Occupied() )
       
   420 		    {
       
   421 		    continue;
       
   422 		    }
       
   423 		
       
   424 		if ( plugin->PublisherName() == aInfo.PublisherId() )
       
   425 			{
       
   426 			if ( plugin->Removable() )
       
   427 			    {
       
   428 			    // To enable widget remove
       
   429 			    aInfo.SetPluginIdL( plugin->PluginId() );
       
   430 			    
       
   431 			    retval |= ECanBeRemoved;
       
   432 			    }
       
   433 			
       
   434 			widgetCount++;
       
   435 			}
       
   436 		}
       
   437 
       
   438 	if ( widgetCount < aInfo.MaxWidgets() )
       
   439 	    {
       
   440 	    retval |= ECanBeAdded;
       
   441 	    }
       
   442 	
       
   443 	CleanupStack::PopAndDestroy( &plugins );
       
   444 	
       
   445 	return retval;
       
   446 	}
       
   447 
       
   448 // ---------------------------------------------------------------------------
       
   449 // CXnEditor::NonTemplateWidgetCanBeAddedRemovedL
       
   450 //
       
   451 // ---------------------------------------------------------------------------
       
   452 // 
       
   453 TInt CXnEditor::NonTemplateWidgetCanBeAddedRemovedL( 
       
   454     CHsContentInfo& aInfo )
       
   455     {    
       
   456     TInt retval( 0 );
       
   457     
       
   458     TInt widgetCount( 0 );
       
   459 
       
   460     CXnViewData& activeView( iViewManager.ActiveViewData() );
       
   461 
       
   462     RPointerArray< CXnPluginData >& plugins( activeView.PluginData() );
       
   463 
       
   464     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   465         {
       
   466         CXnPluginData* plugin( plugins[i] );
       
   467 
       
   468         if ( !plugin->Occupied() )
       
   469             {
       
   470             continue;
       
   471             }        
       
   472         
       
   473         if ( plugin->PluginUid().CompareF( aInfo.Uid() ) == 0 )
       
   474             {
       
   475             if ( plugin->Removable() )
       
   476                 {
       
   477                 // To enable widget remove
       
   478                 aInfo.SetPluginIdL( plugin->PluginId() );
       
   479                 
       
   480                 retval |= ECanBeRemoved;
       
   481                 }
       
   482             
       
   483             widgetCount++;
       
   484             }
       
   485         }
       
   486     
       
   487     if ( widgetCount < aInfo.MaxWidgets() ||
       
   488         aInfo.MaxWidgets() == KMultiInstanceUnlimitedValue )
       
   489         {
       
   490         retval |= ECanBeAdded;        
       
   491         }
       
   492     
       
   493     return retval;
       
   494     }
       
   495 
       
   496 
       
   497 // ---------------------------------------------------------------------------
       
   498 // CXnEditor::FilterViewListL
       
   499 // ---------------------------------------------------------------------------
       
   500 //
       
   501 void CXnEditor::FilterViewListL( CHsContentInfoArray& aContentInfoArray )
       
   502     {
       
   503     RPointerArray< CHsContentInfo >& list( aContentInfoArray.Array() );
       
   504     
       
   505     RPointerArray< CXnPluginData >& views( 
       
   506         iViewManager.ActiveAppData().PluginData() );
       
   507 
       
   508     TInt viewAmount( iViewManager.ViewAmount() );
       
   509     
       
   510     const TInt KMaxViewAmount( 6 );
       
   511     
       
   512     for ( TInt i = 0; i < list.Count(); i++ )
       
   513         {
       
   514         CHsContentInfo* info( list[i] );
       
   515         
       
   516         info->SetCanBeAdded( EFalse );
       
   517         info->SetCanBeRemoved( EFalse );
       
   518 
       
   519         for ( TInt j = 0 ; j < views.Count(); j++ )
       
   520             {
       
   521             CXnPluginData* view( views[j] );
       
   522             
       
   523             if ( view->PluginUid().CompareF( info->Uid() ) == 0 )
       
   524                 {
       
   525                 // To enable view remove
       
   526                 info->SetPluginIdL( view->PluginId() );
       
   527                 // Last view cannot be removed
       
   528                 if ( views.Count() > 1 )
       
   529                     {
       
   530                     info->SetCanBeRemoved( ETrue );
       
   531                     }
       
   532                 }
       
   533             }
       
   534         
       
   535         if ( viewAmount < KMaxViewAmount )
       
   536             {
       
   537             info->SetCanBeAdded( ETrue );
       
   538             }
       
   539         }
       
   540     }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // CXnEditor::RemoveUnRegisteredWidgetL
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void CXnEditor::RemoveUnRegisteredWidgetL( const TDesC16& aPublisher )
       
   547     {
       
   548     RPointerArray< CXnPluginData > plugins;
       
   549     CleanupClosePushL( plugins );
       
   550     
       
   551     iViewManager.PluginDataL( plugins, ETrue );
       
   552 
       
   553     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   554         {
       
   555         CXnPluginData* plugin( plugins[i] );
       
   556         
       
   557         if( plugin->Occupied() && plugin->PublisherName() == aPublisher )
       
   558             {
       
   559             iViewManager.UnloadWidgetFromPluginL( *plugin );                                
       
   560             }
       
   561         }
       
   562     
       
   563     CleanupStack::PopAndDestroy( &plugins );
       
   564     }
       
   565 
       
   566 // ---------------------------------------------------------------------------
       
   567 // CXnEditor::RemoveUnInstalledWidgetL
       
   568 // ---------------------------------------------------------------------------
       
   569 // 
       
   570 void CXnEditor::RemoveUnInstalledWidgetL( const CHsContentInfo& aContentInfo )
       
   571     {
       
   572     RPointerArray< CXnPluginData > plugins;
       
   573     CleanupClosePushL( plugins );
       
   574     
       
   575     iViewManager.PluginDataL( plugins, ETrue );
       
   576     
       
   577     CXnPluginData* plugin( DeterminePlugin( plugins, aContentInfo ) ); 
       
   578                             
       
   579     if ( plugin )
       
   580         {
       
   581         iViewManager.UnloadWidgetFromPluginL( *plugin );
       
   582         }  
       
   583     
       
   584     CleanupStack::PopAndDestroy( &plugins );
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------------------------
       
   588 // CXnEditor::ReplaceWidgetL
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 void CXnEditor::ReplaceWidgetL( CHsContentInfo& aContentInfo, TBool aUseHsps ) 
       
   592     {
       
   593     RPointerArray< CXnPluginData > plugins;
       
   594     CleanupClosePushL( plugins );
       
   595     
       
   596     iViewManager.PluginDataL( plugins, ETrue );
       
   597     
       
   598     CXnPluginData* match = NULL;
       
   599     
       
   600     for( TInt i = 0; i < plugins.Count(); i++ )
       
   601         {
       
   602         CXnPluginData* plugin( plugins[i] );
       
   603         
       
   604         if( plugin->PluginId() == aContentInfo.PluginId() )
       
   605             {
       
   606             match = plugin;
       
   607             break;
       
   608             }
       
   609         }
       
   610     
       
   611     if( match )
       
   612         {
       
   613         iViewManager.ReplaceWidgetToPluginL( aContentInfo, *match, aUseHsps );
       
   614         }
       
   615     
       
   616     CleanupStack::PopAndDestroy( &plugins );    
       
   617     }
       
   618 
       
   619 // ---------------------------------------------------------------------------
       
   620 // CXnEditor::AddWidgetL
       
   621 // ---------------------------------------------------------------------------
       
   622 //
       
   623 void CXnEditor::AddWidgetL()
       
   624     {
       
   625     MHsContentControlUi* ui( 
       
   626         iViewManager.AppUiAdapter().HsContentController( KWMUi ) ); 
       
   627                                                 
       
   628     if( ui )
       
   629         {
       
   630         ui->SetContentController( this );
       
   631         ui->Activate();
       
   632         
       
   633         return;
       
   634         }
       
   635     
       
   636     CXnPluginData* plugin( NULL );
       
   637 
       
   638     if ( iTargetPlugin )
       
   639         {
       
   640         plugin = DeterminePlugin( iViewManager, iTargetPlugin );               
       
   641         }
       
   642     else
       
   643         {
       
   644         plugin = DeterminePlugin( iViewManager );
       
   645         }
       
   646 
       
   647     iTargetPlugin = NULL;
       
   648         
       
   649     CHsContentInfoArray* info = CHsContentInfoArray::NewL();
       
   650     CleanupStack::PushL( info );
       
   651            
       
   652     RPointerArray< CHsContentInfo >& widgets( info->Array() );
       
   653 
       
   654     // get installed widgets from HSPS (type: "widget")
       
   655     HSPSPluginsL( widgets, KKeyWidget );
       
   656     // get installed widgets from HSPS
       
   657     TemplatedWidgetsL( widgets );
       
   658     
       
   659     FilterWidgetListL( *info, ETrue );
       
   660                       
       
   661     CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 8 );
       
   662     CleanupStack::PushL( array );
       
   663     
       
   664     for ( TInt i = 0; i < widgets.Count(); i++ )
       
   665         {
       
   666         CHsContentInfo* widget( widgets[i] );
       
   667         
       
   668         if ( widget->CanBeAdded() )
       
   669             {
       
   670             TPtrC name( ParseWidgetName( *widget ) );
       
   671             
       
   672             array->InsertIsqAllowDuplicatesL( name );            
       
   673             }
       
   674         }
       
   675 
       
   676     const TDesC8& ns( iViewManager.ViewNode()->Namespace() );
       
   677 
       
   678     CXnNode* link( iViewManager.UiEngine().FindNodeByIdL( KDownload, ns ) );
       
   679 
       
   680     if ( link )
       
   681         {
       
   682         CXnText* textIf( NULL );
       
   683 
       
   684         XnComponentInterface::MakeInterfaceL( textIf, link->AppIfL() );
       
   685 
       
   686         if ( textIf )
       
   687             {
       
   688             const TDesC* text( textIf->Text() );
       
   689 
       
   690             if ( text )
       
   691                 {
       
   692                 // First item is always Download link
       
   693                 array->InsertL( 0, *text );
       
   694                 }
       
   695             }
       
   696         }
       
   697 
       
   698     // Display dialog
       
   699     TInt selectedIndex( 0 );
       
   700 
       
   701     CAknListQueryDialog* query =
       
   702         new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
   703 
       
   704     query->PrepareLC( R_LISTQUERY_ADD_WIDGET );
       
   705 
       
   706     query->SetItemTextArray( array );
       
   707     query->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   708 
       
   709     // Save dialog pointer for later usage
       
   710     iQuery = query;
       
   711 
       
   712     TBool linkSelected( EFalse );
       
   713 
       
   714     if ( query->RunLD() )
       
   715         {
       
   716         // Download link is always the first one, if it is defined
       
   717         if ( link && selectedIndex == 0 )
       
   718             {
       
   719             // Activate download link shortcut
       
   720             link->SetStateL( XnPropertyNames::style::common::KActive );
       
   721             link->UnsetStateL( XnPropertyNames::style::common::KActive );
       
   722 
       
   723             linkSelected = ETrue;
       
   724             }       
       
   725         else
       
   726             {
       
   727             if ( !plugin )
       
   728                 {
       
   729                 // No room for new widget, so error note.
       
   730                 HBufC* msg = StringLoader::LoadLC( R_QTN_HS_ADD_WIDGET_FULL );                
       
   731                 ShowErrorNoteL( *msg );                    
       
   732                 CleanupStack::PopAndDestroy( msg );
       
   733                 }            
       
   734             }
       
   735                     
       
   736         const TDesC& selectedName( ( *array )[selectedIndex] );
       
   737 
       
   738         for ( TInt i = 0; plugin && !linkSelected && i < widgets.Count(); i++ )
       
   739             {
       
   740             CHsContentInfo* widget( widgets[i] );
       
   741 
       
   742             TPtrC name( ParseWidgetName( *widget ) );
       
   743 
       
   744             if ( selectedName == name )
       
   745                 {             
       
   746                 TInt ret( iViewManager.LoadWidgetToPluginL( *widget, *plugin ) );
       
   747                 
       
   748                 if ( ret == KErrNone )
       
   749                     {
       
   750                     CXnNode *node( plugin->Owner()->LayoutNode() );
       
   751 
       
   752                     // Analyse added widget
       
   753                     TBool widgetOk( iViewManager.UiEngine().AnalyseAddedWidgetL(
       
   754                             *node ) );
       
   755 
       
   756                     if ( !widgetOk )
       
   757                         {
       
   758                         iViewManager.UnloadWidgetFromPluginL( *plugin );
       
   759                         
       
   760                         // Widget doesn't fit to UI 
       
   761                         HBufC* msg = StringLoader::LoadLC(
       
   762                             R_QTN_HS_ADD_WIDGET_FULL );
       
   763                         
       
   764                         ShowErrorNoteL( *msg );
       
   765                         
       
   766                         CleanupStack::PopAndDestroy( msg );
       
   767                         }                    
       
   768                     }
       
   769                 
       
   770                 break;
       
   771                 }
       
   772             }
       
   773         }
       
   774 
       
   775     // Dialog ended and deleted by RunLD
       
   776     iQuery = NULL;
       
   777 
       
   778     CleanupStack::PopAndDestroy( 2, info ); // array
       
   779     }
       
   780 
       
   781 // ---------------------------------------------------------------------------
       
   782 // CXnEditor::RemoveWidgetL
       
   783 // ---------------------------------------------------------------------------
       
   784 //
       
   785 void CXnEditor::RemoveWidgetL( CXnNode* aNode )    
       
   786     {
       
   787     if ( iTargetPlugin )
       
   788         {
       
   789         aNode = iTargetPlugin;               
       
   790         }
       
   791 
       
   792     iTargetPlugin = NULL;
       
   793     
       
   794     if ( !aNode )
       
   795         {
       
   796         return;
       
   797         }
       
   798 
       
   799     CXnPluginData& plugin( iViewManager.ActiveViewData().Plugin( aNode ) );
       
   800 
       
   801     if( plugin.Removable() )
       
   802         {
       
   803         TRAP_IGNORE( iViewManager.UnloadWidgetFromPluginL( plugin ) );
       
   804         }       
       
   805     }
       
   806 
       
   807 // ---------------------------------------------------------------------------
       
   808 // CXnEditor::ReorderWidgetsL
       
   809 // ---------------------------------------------------------------------------
       
   810 //
       
   811 void CXnEditor::ReorderWidgetsL( RPointerArray< CXnNode >* aPluginArray )
       
   812     {    
       
   813     if ( !aPluginArray )
       
   814         {
       
   815         return;
       
   816         }
       
   817     
       
   818     CXnViewData& viewData( iViewManager.ActiveViewData() );
       
   819 
       
   820     const TDesC8& configurationId( viewData.ConfigurationId() );
       
   821   
       
   822     CDesC8ArrayFlat* ids = new ( ELeave ) CDesC8ArrayFlat( 6 );
       
   823     CleanupStack::PushL( ids );
       
   824 
       
   825     for ( TInt i = 0; i < aPluginArray->Count(); i++ )
       
   826         {
       
   827         CXnPluginData& plugin( viewData.Plugin( ( *aPluginArray )[i] ) );
       
   828 
       
   829         const TDesC8& id( plugin.PluginId() );
       
   830         
       
   831         if ( id != KNullDesC8 )
       
   832             {
       
   833             ids->AppendL( id );
       
   834             }              
       
   835         }
       
   836 
       
   837     iHspsWrapper->MovePluginsL( configurationId, *ids );
       
   838 
       
   839     CleanupStack::PopAndDestroy( ids );
       
   840     }
       
   841 
       
   842 // ---------------------------------------------------------------------------
       
   843 // CXnEditor::PublisherInfoL
       
   844 // ---------------------------------------------------------------------------
       
   845 //
       
   846 CPublisherInfo* CXnEditor::PublisherInfoL( const CHsContentInfo& aContentInfo )
       
   847     {
       
   848     if ( !iPublisherMap )
       
   849         {
       
   850         return NULL;
       
   851         }
       
   852 
       
   853     RPointerArray< CPublisherInfo >& publisherInfo(
       
   854         iPublisherMap->PublisherInfo() );
       
   855 
       
   856     const TDesC& widgetName( aContentInfo.Name() );
       
   857     const TDesC& publisherId( aContentInfo.PublisherId() );
       
   858 
       
   859     CPublisherInfo* info = NULL;
       
   860     
       
   861     for ( TInt i = 0; i < publisherInfo.Count(); i++ )
       
   862         {
       
   863         info = publisherInfo[i];
       
   864 
       
   865         if ( info->WidgetName() == widgetName &&
       
   866             info->PublisherId() == publisherId )
       
   867             {
       
   868             break;
       
   869             }
       
   870         }
       
   871 
       
   872     return info;
       
   873     }
       
   874 
       
   875 // ---------------------------------------------------------------------------
       
   876 // CXnEditor::TemplatedWidgetsL
       
   877 // ---------------------------------------------------------------------------
       
   878 //
       
   879 void CXnEditor::TemplatedWidgetsL( RPointerArray< CHsContentInfo >& aWidgets )
       
   880     {
       
   881     RPointerArray< CHsContentInfo > widgetTemplates;
       
   882     CleanupStack::PushL( TCleanupItem( DeleteWidgetInfo, &widgetTemplates ) );
       
   883 
       
   884     // Gets all the installed templates from CPS
       
   885     HSPSPluginsL( widgetTemplates, KKeyTemplate );
       
   886 
       
   887     delete iPublisherMap;
       
   888     iPublisherMap = NULL;
       
   889 
       
   890     iPublisherMap = iCpsWrapper->GetTemplatedPublishersL();
       
   891 
       
   892     RPointerArray< CPublisherInfo >& publisherInfo(
       
   893         iPublisherMap->PublisherInfo() );
       
   894 
       
   895     for ( TInt i = 0; i < publisherInfo.Count(); i++ )
       
   896         {
       
   897         CPublisherInfo* info( publisherInfo[i] );
       
   898 
       
   899         for ( TInt j = 0; j < widgetTemplates.Count(); j++ )
       
   900             {
       
   901             const TDesC& name( widgetTemplates[j]->Name() );
       
   902 
       
   903             if ( name == info->TemplateType() )
       
   904                 {
       
   905                 CHsContentInfo* contentInfo = CHsContentInfo::NewLC();
       
   906 
       
   907                 contentInfo->SetNameL( info->WidgetName() );
       
   908                 contentInfo->SetPublisherIdL( info->PublisherId() );
       
   909                 contentInfo->SetMaxWidgets( info->MaxWidgets() );
       
   910                 contentInfo->SetUidL( widgetTemplates[j]->Uid() );
       
   911                 contentInfo->SetTypeL( widgetTemplates[j]->Type() );
       
   912                 contentInfo->SetDescriptionL( info->Description() );
       
   913                 contentInfo->SetIconPathL( info->LogoIcon() );
       
   914                                 
       
   915                 contentInfo->SetIsWrt(  
       
   916                     ( info->ContentType() == KWRTTemplate() ) );
       
   917                                 
       
   918                 aWidgets.AppendL( contentInfo );
       
   919                 CleanupStack::Pop( contentInfo );
       
   920 
       
   921                 break;
       
   922                 }
       
   923             }
       
   924         }
       
   925 
       
   926     CleanupStack::PopAndDestroy(); // cleanupitem
       
   927     }
       
   928 
       
   929 // ---------------------------------------------------------------------------
       
   930 // CXnEditor::HSPSPluginsL
       
   931 // ---------------------------------------------------------------------------
       
   932 //
       
   933 void CXnEditor::HSPSPluginsL( RPointerArray< CHsContentInfo >& aWidgets,
       
   934     const TDesC8& aType )
       
   935     {
       
   936     RPointerArray< hspswrapper::CPluginInfo > plugins;
       
   937     CleanupStack::PushL( TCleanupItem( DeletePluginInfos, &plugins ) );
       
   938 
       
   939     if ( aType == KApplication )
       
   940         {
       
   941         iHspsWrapper->GetAppConfigurationsL( plugins );
       
   942         }
       
   943     else
       
   944         {
       
   945         iHspsWrapper->GetPluginsL( plugins, KPluginInterface, aType );
       
   946         }
       
   947 
       
   948     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   949         {
       
   950         if ( plugins[i]->Uid().CompareF( KEmptyWidgetUid ) == 0 )
       
   951             {
       
   952             // Skip empty
       
   953             continue;
       
   954             }
       
   955         
       
   956         CHsContentInfo* contentInfo = CHsContentInfo::NewLC();
       
   957 
       
   958         contentInfo->SetNameL( plugins[i]->Name() );
       
   959         contentInfo->SetUidL( plugins[i]->Uid() );
       
   960         contentInfo->SetTypeL( aType );
       
   961         
       
   962         if ( aType == KKeyWidget || aType == KKeyTemplate )
       
   963             {
       
   964             contentInfo->SetMaxWidgets( plugins[i]->MultiInstance() );
       
   965             }
       
   966 
       
   967         contentInfo->SetDescriptionL( plugins[i]->Description() );
       
   968         contentInfo->SetIconPathL( plugins[i]->LogoIcon() );
       
   969 
       
   970         aWidgets.AppendL( contentInfo );
       
   971         CleanupStack::Pop( contentInfo );
       
   972         }
       
   973 
       
   974     CleanupStack::PopAndDestroy( &plugins );
       
   975     }
       
   976 
       
   977 // ---------------------------------------------------------------------------
       
   978 // CXnEditor::ToggleWidgetsVisibiltyL
       
   979 // ---------------------------------------------------------------------------
       
   980 //
       
   981 TBool CXnEditor::ToggleWidgetsVisibiltyL()
       
   982     {
       
   983     RPointerArray< CXnPluginData >& plugins(
       
   984         iViewManager.ActiveViewData().PluginData() );
       
   985 
       
   986     TBool useEmpty( iViewManager.ActiveViewData().UseEmptyWidget() );
       
   987     
       
   988     TBool stateChanged( EFalse );
       
   989 
       
   990     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   991         {
       
   992         CXnPluginData* plugin( plugins[i] );
       
   993         
       
   994         if( !plugin->Removable() )
       
   995             {
       
   996             // Don't touch to non-removable widget
       
   997             continue;
       
   998             }
       
   999 
       
  1000         if ( iWidgetsVisibilityState )
       
  1001             {            
       
  1002             // Currently visible, make invisible
       
  1003             stateChanged = ETrue;
       
  1004 
       
  1005             SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1006                 XnPropertyNames::style::common::KVisibility,
       
  1007                 XnPropertyNames::style::common::visibility::KHidden );
       
  1008             }
       
  1009         else
       
  1010             {
       
  1011             // Currently invisible, make visible
       
  1012             if ( plugin->Occupied() )
       
  1013                 {
       
  1014                 stateChanged = ETrue;
       
  1015                 
       
  1016                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1017                     XnPropertyNames::style::common::KVisibility,
       
  1018                     XnPropertyNames::style::common::visibility::KVisible );                
       
  1019                 }
       
  1020             else if( useEmpty )
       
  1021                 {
       
  1022                 stateChanged = ETrue;
       
  1023                 
       
  1024                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1025                     XnPropertyNames::style::common::KVisibility,
       
  1026                     XnPropertyNames::style::common::visibility::KBlank );                                    
       
  1027                 }
       
  1028             }
       
  1029         }
       
  1030 
       
  1031     if ( stateChanged )
       
  1032         {
       
  1033         // Update
       
  1034         iWidgetsVisibilityState = !iWidgetsVisibilityState;
       
  1035         }
       
  1036 
       
  1037     return iWidgetsVisibilityState;
       
  1038     }
       
  1039 
       
  1040 // ---------------------------------------------------------------------------
       
  1041 // CXnEditor::WidgetsVisible
       
  1042 // ---------------------------------------------------------------------------
       
  1043 //
       
  1044 TBool CXnEditor::WidgetsVisible() const
       
  1045     {
       
  1046     return iWidgetsVisibilityState;
       
  1047     }
       
  1048 
       
  1049 // ---------------------------------------------------------------------------
       
  1050 // CXnEditor::SetTargetPlugin
       
  1051 // ---------------------------------------------------------------------------
       
  1052 //
       
  1053 void CXnEditor::SetTargetPlugin( CXnNode* aNode )
       
  1054     {
       
  1055     iTargetPlugin = aNode;
       
  1056     }
       
  1057 
       
  1058 // ---------------------------------------------------------------------------
       
  1059 // -----------------------------------------------------------------------------
       
  1060 // CXnEditor::NotifyViewActivatedL
       
  1061 // -----------------------------------------------------------------------------
       
  1062 //
       
  1063 void CXnEditor::NotifyViewActivatedL( const CXnViewData& aViewData )
       
  1064     {
       
  1065     RPointerArray< CXnPluginData >& plugins( aViewData.PluginData() );
       
  1066     
       
  1067     TBool emptyInUse( aViewData.UseEmptyWidget() );
       
  1068     TBool editState( iViewManager.UiEngine().EditMode()->EditState() );
       
  1069               
       
  1070     iWidgetsVisibilityState = EFalse;
       
  1071     
       
  1072     for ( TInt i = 0; i < plugins.Count(); i++ )
       
  1073         {
       
  1074         CXnPluginData* plugin( plugins[i] );
       
  1075         
       
  1076         if ( plugin->Occupied() )
       
  1077             {
       
  1078             // At least one widget visible
       
  1079             iWidgetsVisibilityState = ETrue;                       
       
  1080             }
       
  1081         
       
  1082         if ( plugin->Occupied() || editState )
       
  1083             {
       
  1084             // Make widget visible
       
  1085             SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1086                 XnPropertyNames::style::common::KVisibility,
       
  1087                 XnPropertyNames::style::common::visibility::KVisible );            
       
  1088             }              
       
  1089         else
       
  1090             {            
       
  1091             if ( emptyInUse )
       
  1092                 {
       
  1093                 // Make empty space blank
       
  1094                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1095                     XnPropertyNames::style::common::KVisibility,
       
  1096                     XnPropertyNames::style::common::visibility::KBlank );
       
  1097                 }
       
  1098             else
       
  1099                 {
       
  1100                 // Nothing in this plugin hide
       
  1101                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1102                     XnPropertyNames::style::common::KDisplay,
       
  1103                     XnPropertyNames::style::common::display::KNone );                
       
  1104                 }
       
  1105             }
       
  1106         }                           
       
  1107     }
       
  1108 
       
  1109 // ---------------------------------------------------------------------------
       
  1110 // CXnEditor::NotifyConfigureWidgetL
       
  1111 // ---------------------------------------------------------------------------
       
  1112 //
       
  1113 void CXnEditor::NotifyConfigureWidgetL( const CHsContentInfo& aContentInfo,
       
  1114     CXnPluginData& aPluginData )
       
  1115     {
       
  1116     if ( aContentInfo.Type() != KKeyTemplate )    	    
       
  1117         {
       
  1118         // Doesn't need configuration
       
  1119         return;
       
  1120         }
       
  1121 
       
  1122     const TDesC8& pluginId( aPluginData.PluginId() );
       
  1123 
       
  1124     CHspsConfiguration* pluginConf(
       
  1125         iHspsWrapper->GetPluginConfigurationL( pluginId ) );
       
  1126 
       
  1127     CleanupStack::PushL( pluginConf );
       
  1128 
       
  1129     const CPublisherInfo* info = PublisherInfoL( aContentInfo );
       
  1130 
       
  1131     __ASSERT_DEBUG( info != NULL, Panic( EXnInvalidPublisherInfo ) );
       
  1132     if ( !info )
       
  1133         {
       
  1134         User::Leave( KErrBadHandle );
       
  1135         }
       
  1136     RPointerArray< CItemMap > itemMapListIn;
       
  1137     CleanupStack::PushL( TCleanupItem( DeleteItemMaps, &itemMapListIn ) );
       
  1138     RPointerArray< CItemMap >& settings = pluginConf->Settings();
       
  1139 
       
  1140     HBufC8* publisherId = CnvUtfConverter::ConvertFromUnicodeToUtf8L(
       
  1141         info->PublisherId() );
       
  1142     CleanupStack::PushL( publisherId );
       
  1143 
       
  1144     aPluginData.SetPublisherNameL( info->PublisherId() );
       
  1145 
       
  1146     CItemMap* itemMap( 0 );
       
  1147     CPropertyMap* property( 0 );
       
  1148     CPropertyMap* propertyIn( 0 );
       
  1149 
       
  1150     for ( TInt i = 0; i < settings.Count(); ++i )
       
  1151         {
       
  1152         CItemMap* readItem = settings[i];
       
  1153         itemMap = CItemMap::NewLC();
       
  1154         itemMap->SetItemIdL( readItem->ItemId() );
       
  1155         const TDesC8& itemName = readItem->ItemName();
       
  1156         itemMap->SetItemNameL( itemName );
       
  1157 
       
  1158         RPointerArray< CPropertyMap >& properties = readItem->Properties();
       
  1159         for ( int j = 0; j < properties.Count(); ++j )
       
  1160             {
       
  1161             property = properties[j];
       
  1162             propertyIn = CPropertyMap::NewLC();
       
  1163             propertyIn->SetNameL( property->Name() );
       
  1164             // Dispatching is based on item name
       
  1165             if (  itemName == KContentSource() )
       
  1166                 {
       
  1167                 propertyIn->SetValueL( *publisherId );
       
  1168                 }
       
  1169             else if ( itemName ==  KContentData() )
       
  1170                 {
       
  1171                 // If this default template with full configuration
       
  1172                 TInt pos = property->Value().LocateReverse( KSepratorChar );
       
  1173                 if ( KErrNotFound != pos  )
       
  1174                     {
       
  1175                     propertyIn->SetValueL( property->Value() );
       
  1176                     }
       
  1177                 else
       
  1178                     {
       
  1179                     HBufC8* contentData = HBufC8::NewLC( publisherId->Length()
       
  1180                         + KSeperator().Length()
       
  1181                         + property->Value().Length());
       
  1182                     contentData->Des().Copy( *publisherId );
       
  1183                     contentData->Des().Append( KSeperator );
       
  1184                     contentData->Des().Append( property->Value() );
       
  1185                     propertyIn->SetValueL( *contentData );
       
  1186                     CleanupStack::PopAndDestroy( contentData );
       
  1187                     }
       
  1188                 }
       
  1189             else if ( itemName.Find( KPublisher ) != KErrNotFound )
       
  1190                 {
       
  1191                 propertyIn->SetValueL( *publisherId );
       
  1192                 }
       
  1193             else if ( !KPubTrigger().Compare( itemName ) )
       
  1194                 {
       
  1195                 HBufC8* triggerData = HBufC8::NewLC(
       
  1196                     publisherId->Length()
       
  1197                     + KSeperator().Length()
       
  1198                     + KPublisher().Length()
       
  1199                     + KWidgetTriggerName().Length());
       
  1200                 triggerData->Des().Copy( *publisherId );
       
  1201                 triggerData->Des().Append( KSeperator );
       
  1202                 triggerData->Des().Append( KPublisher );
       
  1203                 triggerData->Des().Append( KWidgetTriggerName );
       
  1204 
       
  1205                 propertyIn->SetValueL( *triggerData );
       
  1206                 CleanupStack::PopAndDestroy( triggerData );
       
  1207                 }
       
  1208             else if ( !KTrigger().Compare( itemName ) )
       
  1209                 {
       
  1210                 // If this default template with full configuration
       
  1211                 TInt pos = property->Value().LocateReverse( KSepratorChar );
       
  1212                 if ( KErrNotFound != pos )
       
  1213                     {
       
  1214                     propertyIn->SetValueL( property->Value() );
       
  1215                     }
       
  1216                 else
       
  1217                     {
       
  1218                     HBufC8* triggerData = HBufC8::NewLC(
       
  1219                         publisherId->Length()
       
  1220                         + KSeperator().Length()
       
  1221                         + property->Value().Length()
       
  1222                         + KOpen().Length()
       
  1223                         + property->Value().Length()
       
  1224                         + KClose().Length() );
       
  1225                     triggerData->Des().Copy( *publisherId );
       
  1226                     triggerData->Des().Append( KSeperator );
       
  1227                     triggerData->Des().Append( property->Value() );
       
  1228                     triggerData->Des().Append( KOpen );
       
  1229                     triggerData->Des().Append( property->Value() );
       
  1230                     triggerData->Des().Append( KClose );
       
  1231                     propertyIn->SetValueL( *triggerData );
       
  1232                     CleanupStack::PopAndDestroy( triggerData );
       
  1233                     }
       
  1234                 }
       
  1235             else
       
  1236                 {
       
  1237                 // unrecognized items are not handled
       
  1238                 }
       
  1239             itemMap->AddPropertyMapL( propertyIn );
       
  1240             CleanupStack::Pop( propertyIn );
       
  1241             }
       
  1242         itemMapListIn.AppendL( itemMap );
       
  1243         CleanupStack::Pop( itemMap );
       
  1244         }
       
  1245     iHspsWrapper->SetPluginSettingsL( pluginId, itemMapListIn );
       
  1246 
       
  1247     CleanupStack::PopAndDestroy( publisherId );
       
  1248     CleanupStack::PopAndDestroy( &itemMapListIn );
       
  1249     CleanupStack::PopAndDestroy( pluginConf );
       
  1250     }
       
  1251 
       
  1252 // ---------------------------------------------------------------------------
       
  1253 // CXnEditor::NotifyWidgetAdditionL
       
  1254 // ---------------------------------------------------------------------------
       
  1255 //
       
  1256 void CXnEditor::NotifyWidgetAdditionL( const CXnPluginData& aPluginData )
       
  1257     {
       
  1258     CXnNode* node( aPluginData.Owner()->LayoutNode() );
       
  1259 
       
  1260     // At least one widget is visible
       
  1261     iWidgetsVisibilityState = ETrue;
       
  1262     
       
  1263     // Ensure the new widget is visible
       
  1264     SetPropertyL( *node,
       
  1265         XnPropertyNames::style::common::KVisibility,
       
  1266         XnPropertyNames::style::common::visibility::KVisible );        
       
  1267     
       
  1268     SetPropertyL( *node,
       
  1269         XnPropertyNames::style::common::KDisplay,
       
  1270         XnPropertyNames::style::common::display::KBlock );
       
  1271     
       
  1272     node->SetDirtyL( XnDirtyLevel::ELayoutAndRenderSiblings );
       
  1273     
       
  1274     WidgetListChanged();
       
  1275     }
       
  1276 
       
  1277 // ---------------------------------------------------------------------------
       
  1278 // CXnEditor::NotifyWidgetRemovalL
       
  1279 // ---------------------------------------------------------------------------
       
  1280 //
       
  1281 void CXnEditor::NotifyWidgetRemovalL( const CXnPluginData& aPluginData )
       
  1282     {
       
  1283     CXnNode* node( aPluginData.Owner()->LayoutNode() );
       
  1284 
       
  1285     CXnViewData& viewData( 
       
  1286         static_cast< CXnViewData& >( *aPluginData.Parent() ) );
       
  1287     
       
  1288     TBool emptyInUse( viewData.UseEmptyWidget() );
       
  1289     
       
  1290     if ( emptyInUse )
       
  1291         {        
       
  1292         if ( iViewManager.UiEngine().IsEditMode() )
       
  1293             {
       
  1294             // Ensure the plugin which was holding 
       
  1295             // the removed widget is visible when edit mode is active
       
  1296             SetPropertyL( *node,
       
  1297                 XnPropertyNames::style::common::KVisibility,
       
  1298                 XnPropertyNames::style::common::visibility::KVisible );                   
       
  1299             }
       
  1300         else
       
  1301             {
       
  1302             // Ensure the plugin which was holding 
       
  1303             // the removed widget is blank now
       
  1304             SetPropertyL( *node,
       
  1305                 XnPropertyNames::style::common::KVisibility,
       
  1306                 XnPropertyNames::style::common::visibility::KBlank );            
       
  1307             }                
       
  1308         }
       
  1309     else
       
  1310         {
       
  1311         // Ensure the plugin which was holding the removed widget is invisible
       
  1312         SetPropertyL( *node,
       
  1313             XnPropertyNames::style::common::KDisplay,
       
  1314             XnPropertyNames::style::common::display::KNone );
       
  1315                 
       
  1316         // Reodred layout tree by moving the plugin which was holding the
       
  1317         // removed widget as the last one in layout tree's plugin the list
       
  1318         CXnNode *parent( node->Parent() );
       
  1319 
       
  1320         RPointerArray< CXnNode >& children( parent->Children() );
       
  1321 
       
  1322         TInt nodeIndex( children.Find( node ) );
       
  1323 
       
  1324         children.Remove( nodeIndex );
       
  1325         children.Insert( node, children.Count() - 1 );
       
  1326         }
       
  1327     
       
  1328     node->SetDirtyL( XnDirtyLevel::ERender );
       
  1329     
       
  1330     iTargetPlugin = NULL;
       
  1331     
       
  1332     if ( aPluginData.Active() )
       
  1333         {
       
  1334         CXnViewData& viewData( iViewManager.ActiveViewData() );
       
  1335         
       
  1336         RPointerArray< CXnPluginData >& plugins( viewData.PluginData() );
       
  1337         
       
  1338         TBool occupied( EFalse );
       
  1339         
       
  1340         for ( TInt i = 0; i < plugins.Count(); i++ )
       
  1341             {
       
  1342             if ( plugins[i]->Occupied() && plugins[i]->Removable() )
       
  1343                 {
       
  1344                 occupied = ETrue;
       
  1345                 break;
       
  1346                 }
       
  1347             }
       
  1348         
       
  1349         if ( !occupied )
       
  1350             {
       
  1351             // No more widgets in the active view
       
  1352             iWidgetsVisibilityState = EFalse;
       
  1353             }               
       
  1354         }
       
  1355     
       
  1356     WidgetListChanged();
       
  1357     }
       
  1358 
       
  1359 // ---------------------------------------------------------------------------
       
  1360 // CXnEditor::NotifyViewAdditionL
       
  1361 // ---------------------------------------------------------------------------
       
  1362 //
       
  1363 void CXnEditor::NotifyViewAdditionL( const CXnPluginData& /*aPluginData*/ )
       
  1364     {
       
  1365     ViewListChanged();
       
  1366     }
       
  1367 
       
  1368 // ---------------------------------------------------------------------------
       
  1369 // CXnEditor::NotifyViewRemovalL
       
  1370 // ---------------------------------------------------------------------------
       
  1371 //
       
  1372 void CXnEditor::NotifyViewRemovalL( const CXnPluginData& /*aPluginData*/ )
       
  1373     {
       
  1374     ViewListChanged();
       
  1375     }
       
  1376 
       
  1377 // ---------------------------------------------------------------------------
       
  1378 // CXnEditor::NotifyWidgetUnregisteredL
       
  1379 // ---------------------------------------------------------------------------
       
  1380 //
       
  1381 void CXnEditor::NotifyWidgetUnregisteredL( const TDesC& aPublisher )
       
  1382     {
       
  1383     RemoveUnRegisteredWidgetL( aPublisher );
       
  1384     WidgetListChanged();    
       
  1385     }
       
  1386 
       
  1387 // ---------------------------------------------------------------------------
       
  1388 // CXnEditor::NotifyWidgetRegisteredL
       
  1389 // ---------------------------------------------------------------------------
       
  1390 //
       
  1391 void CXnEditor::NotifyWidgetRegisteredL()
       
  1392     {
       
  1393     WidgetListChanged();
       
  1394     }
       
  1395 
       
  1396 // ---------------------------------------------------------------------------
       
  1397 // CXnEditor::NotifyViewDeactivatedL
       
  1398 // ---------------------------------------------------------------------------
       
  1399 //
       
  1400 void CXnEditor::NotifyViewDeactivatedL( const CXnViewData& /*aViewData*/)
       
  1401     {
       
  1402     }
       
  1403 
       
  1404 // ---------------------------------------------------------------------------
       
  1405 // CXnEditor::SetWallpaperL
       
  1406 // ---------------------------------------------------------------------------
       
  1407 //
       
  1408 void CXnEditor::SetWallpaperL()
       
  1409     {
       
  1410     // Display dialog
       
  1411     TInt selectedIndex( 0 );
       
  1412 
       
  1413     CAknListQueryDialog* query =
       
  1414         new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
  1415     CleanupStack::PushL( query );
       
  1416     query->PrepareLC( R_LISTQUERY_CHANGE_WALLPAPER );
       
  1417 
       
  1418     if ( query->RunLD() )
       
  1419         {
       
  1420         if ( selectedIndex == 0 )
       
  1421             {
       
  1422             // set wallpaper. No need to check return value. If successful,
       
  1423             // avkon calls SkinConfigurationChanged function
       
  1424             AknsWallpaperUtils::SetIdleWallpaper(
       
  1425                     KNullDesC,
       
  1426                     NULL );
       
  1427             }
       
  1428         else if ( selectedIndex == 1 )
       
  1429             {
       
  1430             iViewManager.AppUiAdapter().ActivateLocalViewL( KWallpaperViewUid, KDummyUid, KSingle );                
       
  1431             }
       
  1432         else if ( selectedIndex == 2 )
       
  1433             {
       
  1434             iViewManager.AppUiAdapter().ActivateLocalViewL( KWallpaperViewUid, KDummyUid, KMulti );                
       
  1435             }        
       
  1436         }
       
  1437     CleanupStack::Pop( query );
       
  1438     }
       
  1439 
       
  1440 // -----------------------------------------------------------------------------
       
  1441 // CXnEditor::HandleNotifyL
       
  1442 // Handles notifications from HSPS wrapper
       
  1443 // -----------------------------------------------------------------------------
       
  1444 //
       
  1445 TInt CXnEditor::HandleNotifyL(
       
  1446     const TDesC8& aEvent,
       
  1447     const TDesC8& /*aAppConfUid*/,
       
  1448     const TDesC8& aPluginName,
       
  1449     const TDesC8& aOrigUid,
       
  1450     const TDesC8& aPluginUid,
       
  1451     const TDesC8& aPluginId )
       
  1452     {
       
  1453     // Someone else has modified the configuration. Handle UI side here.
       
  1454     if( aEvent == KEventPluginAdded ||
       
  1455         aEvent == KEventPluginRemoved ||
       
  1456         aEvent == KEventPluginReplaced )
       
  1457         {
       
  1458         if( aOrigUid != KNullDesC8 && 
       
  1459             aOrigUid != KAi3Uid )
       
  1460             {
       
  1461             CHsContentInfo* info = CHsContentInfo::NewLC();
       
  1462             
       
  1463             info->SetNameL( aPluginName );
       
  1464             info->SetUidL( aPluginUid );
       
  1465             info->SetPluginIdL( aPluginId );
       
  1466             
       
  1467             ReplaceWidgetL( *info, EFalse );
       
  1468             
       
  1469             CleanupStack::PopAndDestroy( info );
       
  1470             }
       
  1471         }
       
  1472     else if ( aEvent == KEventPluginUnInstalled )
       
  1473         {
       
  1474         CHsContentInfo* info = CHsContentInfo::NewLC();
       
  1475 
       
  1476         info->SetNameL( aPluginName );
       
  1477         info->SetUidL( aPluginUid );
       
  1478         info->SetPluginIdL( aPluginId );
       
  1479 
       
  1480         RemoveUnInstalledWidgetL( *info );
       
  1481         WidgetListChanged();
       
  1482 
       
  1483         CleanupStack::PopAndDestroy( info );
       
  1484         }
       
  1485     else if ( aEvent == KEventRootConfActivated )
       
  1486         {
       
  1487         iViewManager.AppUiAdapter().ReloadUiL();
       
  1488         }
       
  1489     else if ( aEvent == KEventPluginInstalled )
       
  1490         {        
       
  1491         WidgetListChanged();        
       
  1492         }
       
  1493     else if ( aEvent == KEventPluginUpdated )
       
  1494         {
       
  1495         // If the plugin is in use then reload the widget
       
  1496         if ( aPluginId.Length() > 0 )
       
  1497             {
       
  1498             CHsContentInfo* info = CHsContentInfo::NewLC();    
       
  1499             info->SetNameL( aPluginName );
       
  1500             info->SetUidL( aPluginUid );
       
  1501             info->SetPluginIdL( aPluginId );    
       
  1502             ReplaceWidgetL( *info );                
       
  1503             CleanupStack::PopAndDestroy( info );
       
  1504             }
       
  1505         WidgetListChanged();
       
  1506         }    
       
  1507     else if ( aEvent == KEventPluginActivated )
       
  1508         {
       
  1509         }
       
  1510  
       
  1511     return KErrNone;
       
  1512     }
       
  1513 
       
  1514 // -----------------------------------------------------------------------------
       
  1515 // CXnEditor::WidgetListChanged
       
  1516 // -----------------------------------------------------------------------------
       
  1517 //
       
  1518 void CXnEditor::WidgetListChanged()
       
  1519     {
       
  1520     MHsContentControlUi* ui( 
       
  1521         iViewManager.AppUiAdapter().HsContentController( KWMUi ) );
       
  1522             
       
  1523     if( ui )
       
  1524         {
       
  1525         ui->NotifyWidgetListChanged();
       
  1526         }
       
  1527     MHsContentControl* srv( iViewManager.AppUiAdapter().HsContentControlSrv() );
       
  1528     if ( srv )
       
  1529         {
       
  1530         srv->NotifyWidgetListChanged();
       
  1531         }
       
  1532     }
       
  1533 
       
  1534 // -----------------------------------------------------------------------------
       
  1535 // CXnEditor::ViewListChanged
       
  1536 // -----------------------------------------------------------------------------
       
  1537 //
       
  1538 void CXnEditor::ViewListChanged()
       
  1539     {
       
  1540     MHsContentControlUi* ui( 
       
  1541         iViewManager.AppUiAdapter().HsContentController( KWMUi ) );
       
  1542             
       
  1543     if( ui )
       
  1544         {
       
  1545         ui->NotifyViewListChanged();
       
  1546         }
       
  1547     MHsContentControl* srv( iViewManager.AppUiAdapter().HsContentControlSrv() );
       
  1548     if ( srv )
       
  1549         {
       
  1550         srv->NotifyViewListChanged();
       
  1551         }
       
  1552     }
       
  1553 
       
  1554 // -----------------------------------------------------------------------------
       
  1555 // CXnEditor::HspsWrapper
       
  1556 // -----------------------------------------------------------------------------
       
  1557 //
       
  1558 CHspsWrapper& CXnEditor::HspsWrapper() const
       
  1559     {
       
  1560     return *iHspsWrapper;
       
  1561     }
       
  1562 
       
  1563 // -----------------------------------------------------------------------------
       
  1564 // from MHsContentController
       
  1565 // -----------------------------------------------------------------------------
       
  1566 //
       
  1567 TInt CXnEditor::WidgetListL( CHsContentInfoArray& aArray )
       
  1568     {
       
  1569     RPointerArray< CHsContentInfo >& array( aArray.Array() );
       
  1570 
       
  1571     // get installed widgets from HSPS (type: "widget")
       
  1572     HSPSPluginsL( array, KKeyWidget );
       
  1573     // get installed widgets from HSPS
       
  1574     TemplatedWidgetsL( array );
       
  1575     
       
  1576     FilterWidgetListL( aArray, EFalse );
       
  1577     
       
  1578     return KErrNone;
       
  1579     }
       
  1580 
       
  1581 // -----------------------------------------------------------------------------
       
  1582 // from MHsContentController
       
  1583 // -----------------------------------------------------------------------------
       
  1584 //
       
  1585 TInt CXnEditor::ViewListL( CHsContentInfoArray& aArray )
       
  1586     {
       
  1587     RPointerArray< CHsContentInfo >& array( aArray.Array() );
       
  1588     
       
  1589     // get installed views from HSPS 
       
  1590     HSPSPluginsL( array, KView );
       
  1591     
       
  1592     FilterViewListL( aArray );
       
  1593     
       
  1594     return KErrNone;
       
  1595     }
       
  1596 
       
  1597 // -----------------------------------------------------------------------------
       
  1598 // from MHsContentController
       
  1599 // -----------------------------------------------------------------------------
       
  1600 //
       
  1601 TInt CXnEditor::AppListL( CHsContentInfoArray& aArray )
       
  1602     {
       
  1603     RPointerArray< CHsContentInfo >& array( aArray.Array() );
       
  1604     
       
  1605     HSPSPluginsL( array, KApplication );
       
  1606     
       
  1607     return KErrNone;
       
  1608     }
       
  1609 
       
  1610 // -----------------------------------------------------------------------------
       
  1611 // from MHsContentController
       
  1612 // -----------------------------------------------------------------------------
       
  1613 //
       
  1614 TInt CXnEditor::AddWidgetL( CHsContentInfo& aInfo )
       
  1615     {
       
  1616     TInt ret( KErrNone );    
       
  1617 
       
  1618     const TDesC8& type( aInfo.Type() );
       
  1619     
       
  1620     if ( ( type != KKeyWidget && type != KKeyTemplate ) ||
       
  1621          aInfo.Uid() == KNullDesC8 )
       
  1622         {
       
  1623         // malformed content info
       
  1624         return KErrArgument;
       
  1625         }
       
  1626 
       
  1627     if ( !aInfo.CanBeAdded() )
       
  1628         {
       
  1629         // the widget can not be added. Return proper error code
       
  1630         if ( IsCurrentViewFull() )
       
  1631             {
       
  1632             return KHsErrorViewFull;
       
  1633             }
       
  1634         else
       
  1635             {
       
  1636             return KHsErrorMaxInstanceCountExceeded;
       
  1637             }
       
  1638         }
       
  1639 
       
  1640     CXnPluginData* plugin( NULL );
       
  1641     
       
  1642     if( iTargetPlugin )
       
  1643         {
       
  1644         plugin = DeterminePlugin( iViewManager, iTargetPlugin );
       
  1645         }
       
  1646     else
       
  1647         {
       
  1648         plugin = DeterminePlugin( iViewManager );
       
  1649         }
       
  1650     
       
  1651     iTargetPlugin = NULL;
       
  1652     
       
  1653     if ( !plugin )
       
  1654         {
       
  1655         return KErrGeneral;
       
  1656         }
       
  1657     
       
  1658     ret = iViewManager.LoadWidgetToPluginL( aInfo, *plugin );
       
  1659     
       
  1660     if( ret == KErrNone )
       
  1661         {
       
  1662         CXnNode* node( plugin->Owner()->LayoutNode() );
       
  1663         TBool widgetOk( iViewManager.UiEngine().AnalyseAddedWidgetL( *node ) );
       
  1664     
       
  1665         if( !widgetOk )
       
  1666             {
       
  1667             iViewManager.UnloadWidgetFromPluginL( *plugin );
       
  1668             
       
  1669             ret = KHsErrorDoesNotFit;
       
  1670             }        
       
  1671         }
       
  1672     
       
  1673     return ret;
       
  1674     }
       
  1675 
       
  1676 // -----------------------------------------------------------------------------
       
  1677 // from MHsContentController
       
  1678 // -----------------------------------------------------------------------------
       
  1679 //
       
  1680 TInt CXnEditor::RemoveWidgetL( CHsContentInfo& aInfo )
       
  1681     {
       
  1682     if ( !aInfo.CanBeRemoved() || aInfo.PluginId() == KNullDesC8 || 
       
  1683         ( aInfo.Type() != KKeyWidget && aInfo.Type() != KKeyTemplate ) )
       
  1684         {
       
  1685         return KErrArgument;
       
  1686         }
       
  1687     
       
  1688     TInt retval( KErrNotFound );
       
  1689     
       
  1690     RPointerArray< CXnPluginData > plugins;
       
  1691     CleanupClosePushL( plugins );
       
  1692     
       
  1693     // Search only from active view
       
  1694     iViewManager.PluginDataL( plugins );
       
  1695     
       
  1696     CXnPluginData* plugin( DeterminePlugin( plugins, aInfo ) ); 
       
  1697                             
       
  1698     if ( plugin && plugin->Removable() )
       
  1699         {
       
  1700         retval = iViewManager.UnloadWidgetFromPluginL( *plugin );
       
  1701         }  
       
  1702     
       
  1703     CleanupStack::PopAndDestroy( &plugins );
       
  1704     
       
  1705     return retval;
       
  1706     }
       
  1707 
       
  1708 // -----------------------------------------------------------------------------
       
  1709 // from MHsContentController
       
  1710 // -----------------------------------------------------------------------------
       
  1711 //
       
  1712 TInt CXnEditor::AddViewL( CHsContentInfo& aInfo )
       
  1713     {
       
  1714     if ( !aInfo.CanBeAdded() || aInfo.Uid() == KNullDesC8 || 
       
  1715         aInfo.Type() != KView )
       
  1716         {
       
  1717         return KErrArgument;
       
  1718         }
       
  1719           
       
  1720     return iViewManager.AddViewL( aInfo );
       
  1721     }
       
  1722 
       
  1723 // -----------------------------------------------------------------------------
       
  1724 // from MHsContentController
       
  1725 // -----------------------------------------------------------------------------
       
  1726 //
       
  1727 TInt CXnEditor::RemoveViewL( CHsContentInfo& aInfo )
       
  1728     {
       
  1729     if ( !aInfo.CanBeRemoved() || aInfo.PluginId() == KNullDesC8 || 
       
  1730         aInfo.Type() != KView )
       
  1731         {
       
  1732         return KErrArgument;
       
  1733         }
       
  1734     
       
  1735     return iViewManager.RemoveViewL( aInfo );
       
  1736     }
       
  1737 
       
  1738 // -----------------------------------------------------------------------------
       
  1739 // from MHsContentController
       
  1740 // -----------------------------------------------------------------------------
       
  1741 //
       
  1742 TInt CXnEditor::ActivateViewL( CHsContentInfo& aInfo )
       
  1743     {
       
  1744     if ( aInfo.Type() != KView )
       
  1745         {
       
  1746         return KErrArgument;
       
  1747         }
       
  1748     
       
  1749     return iViewManager.ActivateViewL( aInfo.PluginId() );
       
  1750     }
       
  1751 
       
  1752 // -----------------------------------------------------------------------------
       
  1753 // from MHsContentController
       
  1754 // -----------------------------------------------------------------------------
       
  1755 //
       
  1756 TInt CXnEditor::ActivateAppL( CHsContentInfo& aInfo )
       
  1757     {
       
  1758     if ( aInfo.Type() != KApplication )
       
  1759         {
       
  1760         return KErrArgument;
       
  1761         }
       
  1762     
       
  1763     return iViewManager.ActivateAppL( aInfo.Uid() );     
       
  1764     }
       
  1765 
       
  1766 // End of file