idlehomescreen/xmluirendering/uiengine/src/xneditor.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     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 #include <activeidle2domaincrkeys.h>
       
    32 
       
    33 // User includes
       
    34 #include "xnuiengine.h"
       
    35 #include "xnproperty.h"
       
    36 #include "xnnode.h"
       
    37 #include "xntype.h"
       
    38 #include "xntext.h"
       
    39 #include "xnappuiadapter.h"
       
    40 
       
    41 #include "xndomnode.h"
       
    42 #include "xndomproperty.h"
       
    43 #include "xndompropertyvalue.h"
       
    44 #include "xndomlist.h"
       
    45 #include "xndomattribute.h"
       
    46 #include "hspssapi.h"
       
    47 #include "cpssapi.h"
       
    48 #include "xneditmode.h"
       
    49 #include "xndomdocument.h"
       
    50 #include "xnnodeimpl.h"
       
    51 #include "xnodt.h"
       
    52 #include "xnplugindefs.h"
       
    53 
       
    54 #include "xnviewmanager.h"
       
    55 #include "xnplugindata.h"
       
    56 #include "xnrootdata.h"
       
    57 #include "xnviewdata.h"
       
    58 #include "xnwallpaperview.h"
       
    59 #include "xnbackgroundmanager.h"
       
    60 #include "xnpopupcontroladapter.h"
       
    61 
       
    62 #include "xneditor.h"
       
    63 #include "xnpanic.h"
       
    64 
       
    65 #include "xnoomsyshandler.h"
       
    66 
       
    67 using namespace hspswrapper;
       
    68 using namespace cpswrapper;
       
    69 
       
    70 // LOCAL CONSTANTS AND MACROS
       
    71 _LIT8( KEventPluginUnInstalled, "PluginUninstalled" );
       
    72 _LIT8( KEventRootConfActivated, "AppConfActivated" );
       
    73 _LIT8( KEventPluginUpdated, "PluginUpdated" );
       
    74 _LIT8( KEventPluginInstalled, "PluginInstalled" );
       
    75 
       
    76 _LIT8( KEmptyWidgetUid, "0x2001F47F" );
       
    77 _LIT8( KDownload, "Editor/DownloadCaption" );
       
    78 
       
    79 _LIT8( KSingle, "single" );
       
    80 _LIT8( KMulti, "multi" );
       
    81 
       
    82 
       
    83 const TInt32 KMultiInstanceUnlimitedValue = -1;
       
    84 
       
    85 const TUid KDummyUid = { 0x0000000 };
       
    86 
       
    87 const TUint32 KAICCPluginUIDKey = 0x00003010;
       
    88 const TInt32 KOpaQDataLen = 10;
       
    89 
       
    90 enum
       
    91     {
       
    92     ECanBeAdded = 0x01,
       
    93     ECanBeRemoved
       
    94     };
       
    95 
       
    96 const TInt KNotifyWidgetListChangedDelay( 1000000 ); //1sec
       
    97 const TInt KNotifyViewListChangedDelay( 1000000 );   //1sec
       
    98 
       
    99 // ====================== LOCAL FUNTION PROTOTYPES ============================
       
   100 static void DeletePluginInfos( TAny* aObject );
       
   101 static void DeleteItemMaps( TAny* aObject );
       
   102 static void DeleteContentInfo( TAny* aObject );
       
   103 
       
   104 static TPtrC ParseWidgetName( const CHsContentInfo& aContentInfo );
       
   105 static void SetPropertyL( CXnNode& aNode, const TDesC8& aAttribute, 
       
   106                           const TDesC8& aValue );    
       
   107 static void ShowErrorNoteL( const TDesC& aMsg );      
       
   108 static CXnPluginData* DeterminePlugin( CXnViewManager& aViewManager, 
       
   109                                          CXnNode* aPredicate = NULL );
       
   110 static CXnPluginData* DeterminePlugin( 
       
   111                             RPointerArray< CXnPluginData >& aPlugins,                            
       
   112                             const CHsContentInfo& aContentInfo );
       
   113 
       
   114 // ============================ LOCAL FUNCTIONS ===============================
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // DeletePluginInfos
       
   118 // ---------------------------------------------------------------------------
       
   119 // 
       
   120 static void DeletePluginInfos( TAny* aObject )
       
   121     {
       
   122     reinterpret_cast<
       
   123         RPointerArray< hspswrapper::CPluginInfo >* >(
       
   124             aObject )->ResetAndDestroy();
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // DeleteItemMaps
       
   129 // ---------------------------------------------------------------------------
       
   130 // 
       
   131 static void DeleteItemMaps( TAny* aObject )
       
   132     {
       
   133     reinterpret_cast<
       
   134         RPointerArray< hspswrapper::CItemMap >* >(
       
   135             aObject )->ResetAndDestroy();
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // DeleteContentInfo
       
   140 // ---------------------------------------------------------------------------
       
   141 // 
       
   142 static void DeleteContentInfo( TAny* aObject )    
       
   143     {
       
   144     reinterpret_cast<RPointerArray< CHsContentInfo >* >( 
       
   145         aObject )->ResetAndDestroy();
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // ParseWidgetName
       
   150 // ---------------------------------------------------------------------------
       
   151 // 
       
   152 static TPtrC ParseWidgetName( const CHsContentInfo& aContentInfo )
       
   153     {
       
   154     TPtrC retval( aContentInfo.Name() );
       
   155 
       
   156     TInt pos( retval.Locate( ':' ) );
       
   157 
       
   158     if ( pos != KErrNotFound )
       
   159         {
       
   160         retval.Set( retval.Right( retval.Length() - pos - 1 ) );
       
   161         }
       
   162 
       
   163     return retval;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // SetPropertyL
       
   168 // ---------------------------------------------------------------------------
       
   169 // 
       
   170 static void SetPropertyL( CXnNode& aNode, 
       
   171     const TDesC8& aAttribute, const TDesC8& aValue )
       
   172     {
       
   173     CXnDomNode* node( aNode.DomNode() );
       
   174     
       
   175     if ( node )
       
   176         {
       
   177         CXnDomStringPool* sp( node->StringPool() );
       
   178 
       
   179         // create new property
       
   180         CXnDomPropertyValue* value = CXnDomPropertyValue::NewL( sp );
       
   181         CleanupStack::PushL( value );
       
   182 
       
   183         value->SetStringValueL( CXnDomPropertyValue::EString, aValue );
       
   184 
       
   185         CXnProperty* prop = CXnProperty::NewL( aAttribute, value, *sp );
       
   186                     
       
   187         CleanupStack::Pop( value );
       
   188         CleanupStack::PushL( prop );
       
   189 
       
   190         aNode.SetPropertyL( prop );
       
   191 
       
   192         CleanupStack::Pop( prop );
       
   193         }
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // ShowErrorNoteL
       
   198 // ---------------------------------------------------------------------------
       
   199 // 
       
   200 static void ShowErrorNoteL( const TDesC& aMsg )
       
   201     {
       
   202     CAknErrorNote* note = new ( ELeave ) CAknErrorNote;
       
   203     CleanupStack::PushL( note );
       
   204 
       
   205     note->ExecuteLD( aMsg );
       
   206 
       
   207     CleanupStack::Pop( note );    
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // DeterminePlugin
       
   212 // Determinates target plugin where widget should be added
       
   213 // ---------------------------------------------------------------------------
       
   214 // 
       
   215 CXnPluginData* DeterminePlugin( CXnViewManager& aViewManager, 
       
   216     CXnNode* aPredicate )
       
   217     {
       
   218     CXnViewData& viewData( aViewManager.ActiveViewData() );
       
   219 
       
   220     if ( aPredicate )
       
   221         {
       
   222         CXnPluginData* plugin( viewData.Plugin( aPredicate ) );
       
   223 
       
   224         if ( plugin && !plugin->Occupied() )
       
   225             {
       
   226             return plugin;
       
   227             }
       
   228         }
       
   229 
       
   230     RPointerArray< CXnNode >& nodes( aViewManager.PluginNodes() );
       
   231 
       
   232     for ( TInt i = 0; i < nodes.Count(); i++ )
       
   233         {
       
   234         CXnNode* node( nodes[i] );
       
   235 
       
   236         CXnPluginData* plugin( viewData.Plugin( node ) );
       
   237 
       
   238         if ( plugin && !plugin->Occupied() )
       
   239             {
       
   240             return plugin;
       
   241             }
       
   242         }
       
   243 
       
   244     return NULL;
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // DeterminePlugin
       
   249 // Determines target plugin based widget info
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 CXnPluginData* DeterminePlugin( RPointerArray< CXnPluginData >& aPlugins, 
       
   253     const CHsContentInfo& aContentInfo ) 
       
   254     {    
       
   255     for ( TInt i = 0; i < aPlugins.Count(); i++ )
       
   256         {
       
   257         CXnPluginData* plugin( aPlugins[i] );
       
   258         
       
   259         if ( plugin->Occupied() && plugin->PluginId() == aContentInfo.PluginId() )
       
   260             {
       
   261             return plugin;
       
   262             }
       
   263         }
       
   264     
       
   265     return NULL;
       
   266     }
       
   267 
       
   268 // ============================ MEMBER FUNCTIONS ===============================
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CXnEditor::NewL
       
   272 // ---------------------------------------------------------------------------
       
   273 // 
       
   274 CXnEditor* CXnEditor::NewL( CXnViewManager& aViewManager, 
       
   275     const TDesC8& aUid )
       
   276     {
       
   277     CXnEditor* self = CXnEditor::NewLC( aViewManager, aUid );
       
   278     CleanupStack::Pop( self );
       
   279     return self;
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CXnEditor::NewLC
       
   284 // ---------------------------------------------------------------------------
       
   285 // 
       
   286 CXnEditor* CXnEditor::NewLC( CXnViewManager& aViewManager,
       
   287     const TDesC8& aUid )
       
   288     {
       
   289     CXnEditor* self = new ( ELeave ) CXnEditor( aViewManager );
       
   290     CleanupStack::PushL( self );
       
   291     self->ConstructL( aUid );
       
   292     return self;
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CXnEditor::CXnEditor
       
   297 // ---------------------------------------------------------------------------
       
   298 // 
       
   299 CXnEditor::CXnEditor( CXnViewManager& aViewManager )
       
   300     : iViewManager( aViewManager ),
       
   301       iWidgetsVisibilityState( ETrue )
       
   302     {
       
   303     iViewManager.AddObserver( *this );
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // CXnEditor::ConstructL
       
   308 // ---------------------------------------------------------------------------
       
   309 // 
       
   310 void CXnEditor::ConstructL( const TDesC8& aUid )
       
   311     {
       
   312     iCpsWrapper = CCpsWrapper::NewL( *this );
       
   313     iHspsWrapper = CHspsWrapper::NewL( aUid, this );
       
   314     iRepository= CRepository::NewL( TUid::Uid( KCRUidActiveIdleLV ) );
       
   315     iOomSysHandler = CXnOomSysHandler::NewL();
       
   316     iNotifyWidgetListChanged = CPeriodic::NewL( CActive::EPriorityIdle );
       
   317     iNotifyViewListChanged = CPeriodic::NewL( CActive::EPriorityIdle );
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CXnEditor::~CXnEditor
       
   322 // ---------------------------------------------------------------------------
       
   323 // 
       
   324 CXnEditor::~CXnEditor()
       
   325     {
       
   326     if ( iNotifyWidgetListChanged && 
       
   327        iNotifyWidgetListChanged->IsActive() )
       
   328         {
       
   329         iNotifyWidgetListChanged->Cancel();
       
   330         }
       
   331     delete iNotifyWidgetListChanged;
       
   332 
       
   333     if ( iNotifyViewListChanged && 
       
   334        iNotifyViewListChanged->IsActive() )
       
   335         {
       
   336         iNotifyViewListChanged->Cancel();
       
   337         }
       
   338     delete iNotifyViewListChanged;
       
   339 
       
   340     iViewManager.RemoveObserver( *this );
       
   341     if( iPluginConfigurations.Count() )
       
   342         {
       
   343         iPluginConfigurations.ResetAndDestroy();
       
   344         }    
       
   345     delete iCpsWrapper;
       
   346     delete iHspsWrapper;
       
   347     delete iPublisherMap;
       
   348     delete iRepository;
       
   349     delete iOomSysHandler;
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CXnEditor::IsCurrentViewFull
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 TBool CXnEditor::IsCurrentViewFull()
       
   357     {
       
   358     return IsViewFull( iViewManager.ActiveViewData() );
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CXnEditor::FilterPluginsL
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CXnEditor::FilterPluginsL( CHsContentInfoArray& aContentInfoArray,
       
   366     TBool aIgnoreViewFull )
       
   367     {
       
   368     RPointerArray< CHsContentInfo >& list( aContentInfoArray.Array() );
       
   369     
       
   370     TBool viewFull = ( aIgnoreViewFull ? EFalse : IsCurrentViewFull() );
       
   371     
       
   372     for ( TInt i = 0; i < list.Count(); i++ )
       
   373         {
       
   374         CHsContentInfo* info( list[i] );
       
   375 
       
   376         info->SetCanBeAdded( EFalse );
       
   377         info->SetCanBeRemoved( EFalse );
       
   378         
       
   379         TInt result( 0 );
       
   380 
       
   381         if ( info->Type() != KKeyTemplate() )
       
   382             {   
       
   383             result = NonTemplateWidgetCanBeAddedRemovedL( *info );            
       
   384             }
       
   385         else
       
   386             {
       
   387             result = TemplateWidgetCanBeAddedRemovedL( *info );
       
   388             }
       
   389         
       
   390         if ( ( result & ECanBeAdded ) && !viewFull )
       
   391             {                        
       
   392             info->SetCanBeAdded( ETrue );            
       
   393             }
       
   394         
       
   395         if ( result & ECanBeRemoved )
       
   396             {
       
   397             info->SetCanBeRemoved( ETrue );
       
   398             }
       
   399         }            
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // CXnEditor::TemplateWidgetCanBeAddedRemovedL
       
   404 // ---------------------------------------------------------------------------
       
   405 // 
       
   406 TInt CXnEditor::TemplateWidgetCanBeAddedRemovedL( 
       
   407     CHsContentInfo& aInfo )
       
   408 	{
       
   409 	TInt retval( 0 );
       
   410 	
       
   411 	TInt widgetCount( 0 );
       
   412 	
       
   413 	RPointerArray< CXnPluginData > plugins;
       
   414 	CleanupClosePushL( plugins );
       
   415 	
       
   416 	if ( aInfo.IsWrt() )
       
   417 	    {
       
   418 	    // Get plugins globally from all pages
       
   419 	    iViewManager.PluginDataL( plugins, ETrue );
       
   420 	    }
       
   421 	else
       
   422 	    {
       
   423 	    // Get plugins from current page
       
   424 	    iViewManager.PluginDataL( plugins, EFalse );
       
   425 	    }
       
   426 	    	
       
   427 	// Get widgets in current configuration
       
   428 	for ( TInt i = 0; i < plugins.Count(); i++ )
       
   429 		{
       
   430 		CXnPluginData* plugin( plugins[i] );
       
   431 		
       
   432 		if ( !plugin->Occupied() )
       
   433 		    {
       
   434 		    continue;
       
   435 		    }
       
   436 		
       
   437 		if ( plugin->PublisherName() == aInfo.PublisherId() )
       
   438 			{
       
   439 			widgetCount++;
       
   440 			}
       
   441 		}
       
   442 
       
   443 	if ( widgetCount < aInfo.MaxWidgets() )
       
   444 	    {
       
   445 	    retval |= ECanBeAdded;
       
   446 	    }
       
   447 	
       
   448 	CleanupStack::PopAndDestroy( &plugins );
       
   449 	
       
   450 	return retval;
       
   451 	}
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CXnEditor::NonTemplateWidgetCanBeAddedRemovedL
       
   455 //
       
   456 // ---------------------------------------------------------------------------
       
   457 // 
       
   458 TInt CXnEditor::NonTemplateWidgetCanBeAddedRemovedL( 
       
   459     CHsContentInfo& aInfo )
       
   460     {    
       
   461     TInt retval( 0 );
       
   462     
       
   463     TInt widgetCount( 0 );
       
   464 
       
   465     CXnViewData& activeView( iViewManager.ActiveViewData() );
       
   466 
       
   467     RPointerArray< CXnPluginData >& plugins( activeView.PluginData() );
       
   468 
       
   469     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   470         {
       
   471         CXnPluginData* plugin( plugins[i] );
       
   472 
       
   473         if ( !plugin->Occupied() )
       
   474             {
       
   475             continue;
       
   476             }        
       
   477         
       
   478         if ( plugin->PluginUid().CompareF( aInfo.Uid() ) == 0 )
       
   479             {
       
   480             widgetCount++;
       
   481             }
       
   482         }
       
   483     
       
   484     if ( widgetCount < aInfo.MaxWidgets() ||
       
   485         aInfo.MaxWidgets() == KMultiInstanceUnlimitedValue )
       
   486         {
       
   487         retval |= ECanBeAdded;        
       
   488         }
       
   489     
       
   490     return retval;
       
   491     }
       
   492 
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // CXnEditor::FilterViewListL
       
   496 // ---------------------------------------------------------------------------
       
   497 //
       
   498 void CXnEditor::FilterViewListL( CHsContentInfoArray& aContentInfoArray )
       
   499     {
       
   500     RPointerArray< CHsContentInfo >& list( aContentInfoArray.Array() );
       
   501     
       
   502     TBool canBeAdded( EFalse );
       
   503     CXnRootData& appData( iViewManager.ActiveAppData() );
       
   504     if ( appData.PluginData().Count() < appData.MaxPages() )
       
   505         {
       
   506         canBeAdded = ETrue;
       
   507         }    
       
   508     
       
   509     for ( TInt i = 0; i < list.Count(); i++ )
       
   510         {
       
   511         CHsContentInfo* info( list[i] );        
       
   512         info->SetCanBeAdded( canBeAdded );
       
   513         }
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // CXnEditor::RemoveUnRegisteredWidgetL
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void CXnEditor::RemoveUnRegisteredWidgetL( const TDesC16& aPublisher )
       
   521     {
       
   522     RPointerArray< CXnPluginData > plugins;
       
   523     CleanupClosePushL( plugins );
       
   524     
       
   525     iViewManager.PluginDataL( plugins, ETrue );
       
   526 
       
   527     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   528         {
       
   529         CXnPluginData* plugin( plugins[i] );
       
   530         
       
   531         if( plugin->Occupied() && plugin->PublisherName() == aPublisher )
       
   532             {
       
   533             iViewManager.UnloadWidgetFromPluginL( *plugin );                                
       
   534             }
       
   535         }
       
   536     
       
   537     CleanupStack::PopAndDestroy( &plugins );
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------------------------
       
   541 // CXnEditor::RemoveUnInstalledWidgetL
       
   542 // ---------------------------------------------------------------------------
       
   543 // 
       
   544 void CXnEditor::RemoveUnInstalledWidgetL( const CHsContentInfo& aContentInfo )
       
   545     {
       
   546     RPointerArray< CXnPluginData > plugins;
       
   547     CleanupClosePushL( plugins );
       
   548     
       
   549     iViewManager.PluginDataL( plugins, ETrue );
       
   550     
       
   551     CXnPluginData* plugin( DeterminePlugin( plugins, aContentInfo ) ); 
       
   552                             
       
   553     if ( plugin )
       
   554         {
       
   555         iViewManager.UnloadWidgetFromPluginL( *plugin );
       
   556         }  
       
   557     
       
   558     CleanupStack::PopAndDestroy( &plugins );
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // CXnEditor::ReplaceWidgetL
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 void CXnEditor::ReplaceWidgetL( CHsContentInfo& aContentInfo ) 
       
   566     {
       
   567     RPointerArray< CXnPluginData > plugins;
       
   568     CleanupClosePushL( plugins );
       
   569     
       
   570     iViewManager.PluginDataL( plugins, ETrue );
       
   571     
       
   572     CXnPluginData* match = NULL;
       
   573     
       
   574     for( TInt i = 0; i < plugins.Count(); i++ )
       
   575         {
       
   576         CXnPluginData* plugin( plugins[i] );
       
   577         
       
   578         if( plugin->PluginId() == aContentInfo.PluginId() )
       
   579             {
       
   580             if ( aContentInfo.Type() == KNullDesC8 )
       
   581                 {
       
   582                 aContentInfo.SetTypeL( plugin->Type() );
       
   583                 }
       
   584             
       
   585             if ( aContentInfo.PublisherId() == KNullDesC )
       
   586                 {
       
   587                 aContentInfo.SetPublisherIdL( plugin->PublisherName() );
       
   588                 }
       
   589             match = plugin;
       
   590             break;
       
   591             }
       
   592         }
       
   593     
       
   594     if( match )
       
   595         {
       
   596         iViewManager.ReplaceWidgetToPluginL( aContentInfo, *match );
       
   597         }
       
   598     
       
   599     CleanupStack::PopAndDestroy( &plugins );    
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // CXnEditor::IdFromCrep
       
   604 // ---------------------------------------------------------------------------
       
   605 //
       
   606 TInt CXnEditor::IdFromCrep (TDes8& aUid) const
       
   607     {
       
   608     return iRepository->Get( KAICCPluginUIDKey, aUid );
       
   609     }
       
   610 
       
   611 // ---------------------------------------------------------------------------
       
   612 // CXnEditor::AddWidgetL
       
   613 // ---------------------------------------------------------------------------
       
   614 //
       
   615 void CXnEditor::AddWidgetL()
       
   616     {
       
   617     if ( !CXnOomSysHandler::HeapAvailable( VIEW_MIN_MEM ) )
       
   618         {
       
   619     	OomSysHandler().HandlePotentialOomL();
       
   620     	return;
       
   621         }
       
   622     
       
   623     TBuf8<KOpaQDataLen> oPaqDataStr = KNullDesC8();
       
   624            
       
   625     MHsContentControlUi* ui( NULL );
       
   626     if ( IdFromCrep ( oPaqDataStr ) == KErrNone )
       
   627         {
       
   628         ui = iViewManager.AppUiAdapter().HsContentController( oPaqDataStr ); 
       
   629         }
       
   630     if( ui )
       
   631         {
       
   632         CXnNode* popup( iViewManager.UiEngine().StylusPopupNode() );
       
   633         if ( popup )
       
   634             {
       
   635             CXnPopupControlAdapter* control =
       
   636                 static_cast< CXnPopupControlAdapter* >(
       
   637                         popup->Control() );
       
   638            
       
   639             if ( control )
       
   640                 {
       
   641                 control->HideMenuL();
       
   642                 }
       
   643             }
       
   644         ui->SetContentController( this );
       
   645         ui->Activate();
       
   646         
       
   647         return;
       
   648         }
       
   649     
       
   650     CXnPluginData* plugin( NULL );
       
   651 
       
   652     if ( iTargetPlugin )
       
   653         {
       
   654         plugin = DeterminePlugin( iViewManager, iTargetPlugin );               
       
   655         }
       
   656     else
       
   657         {
       
   658         plugin = DeterminePlugin( iViewManager );
       
   659         }
       
   660 
       
   661     iTargetPlugin = NULL;
       
   662         
       
   663     CHsContentInfoArray* info = CHsContentInfoArray::NewL();
       
   664     CleanupStack::PushL( info );
       
   665            
       
   666     RPointerArray< CHsContentInfo >& widgets( info->Array() );
       
   667     
       
   668     // get installed widgets and template configurations from HSPS
       
   669     HspsWidgetPluginsL( widgets );
       
   670         
       
   671     // get installed widgets from HSPS (type: "template")    
       
   672     CpsWidgetPluginsL( widgets );
       
   673                 
       
   674     // check whether the plugins can be added or removed
       
   675     FilterPluginsL( *info, ETrue );
       
   676                       
       
   677     CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 8 );
       
   678     CleanupStack::PushL( array );
       
   679     
       
   680     for ( TInt i = 0; i < widgets.Count(); i++ )
       
   681         {
       
   682         CHsContentInfo* widget( widgets[i] );
       
   683         
       
   684         if ( widget->CanBeAdded() )
       
   685             {
       
   686             TPtrC name( ParseWidgetName( *widget ) );
       
   687             
       
   688             array->InsertIsqAllowDuplicatesL( name );            
       
   689             }
       
   690         }
       
   691 
       
   692     const TDesC8& ns( iViewManager.ViewNode()->Namespace() );
       
   693 
       
   694     CXnNode* link( iViewManager.UiEngine().FindNodeByIdL( KDownload, ns ) );
       
   695 
       
   696     if ( link )
       
   697         {
       
   698         CXnText* textIf( NULL );
       
   699 
       
   700         XnComponentInterface::MakeInterfaceL( textIf, link->AppIfL() );
       
   701 
       
   702         if ( textIf )
       
   703             {
       
   704             const TDesC* text( textIf->Text() );
       
   705 
       
   706             if ( text )
       
   707                 {
       
   708                 // First item is always Download link
       
   709                 array->InsertL( 0, *text );
       
   710                 }
       
   711             }
       
   712         }
       
   713 
       
   714     // Display dialog
       
   715     TInt selectedIndex( 0 );
       
   716 
       
   717     CAknListQueryDialog* query =
       
   718         new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
   719 
       
   720     query->PrepareLC( R_LISTQUERY_ADD_WIDGET );
       
   721 
       
   722     query->SetItemTextArray( array );
       
   723     query->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   724 
       
   725     // Save dialog pointer for later usage
       
   726     iQuery = query;
       
   727 
       
   728     TBool linkSelected( EFalse );
       
   729 
       
   730     if ( query->RunLD() )
       
   731         {
       
   732         // Download link is always the first one, if it is defined
       
   733         if ( link && selectedIndex == 0 )
       
   734             {
       
   735             // Activate download link shortcut
       
   736             link->SetStateL( XnPropertyNames::style::common::KActive );
       
   737             link->UnsetStateL( XnPropertyNames::style::common::KActive );
       
   738 
       
   739             linkSelected = ETrue;
       
   740             }       
       
   741         else
       
   742             {
       
   743             if ( !plugin )
       
   744                 {
       
   745                 // No room for new widget, so error note.
       
   746                 HBufC* msg = StringLoader::LoadLC( R_QTN_HS_ADD_WIDGET_FULL );                
       
   747                 ShowErrorNoteL( *msg );                    
       
   748                 CleanupStack::PopAndDestroy( msg );
       
   749                 }            
       
   750             }
       
   751                     
       
   752         const TDesC& selectedName( ( *array )[selectedIndex] );
       
   753 
       
   754         for ( TInt i = 0; plugin && !linkSelected && i < widgets.Count(); i++ )
       
   755             {
       
   756             CHsContentInfo* widget( widgets[i] );
       
   757 
       
   758             TPtrC name( ParseWidgetName( *widget ) );
       
   759 
       
   760             if ( selectedName == name )
       
   761                 {             
       
   762                 TInt ret( iViewManager.LoadWidgetToPluginL( *widget, *plugin ) );
       
   763                 
       
   764                 if ( ret == KErrNone )
       
   765                     {
       
   766                     CXnNode *node( plugin->Owner()->LayoutNode() );
       
   767 
       
   768                     // Analyse added widget
       
   769                     TBool widgetOk( iViewManager.UiEngine().AnalyseAddedWidgetL(
       
   770                             *node ) );
       
   771 
       
   772                     if ( !widgetOk )
       
   773                         {
       
   774                         iViewManager.UnloadWidgetFromPluginL( *plugin );
       
   775                         
       
   776                         // Widget doesn't fit to UI 
       
   777                         HBufC* msg = StringLoader::LoadLC(
       
   778                             R_QTN_HS_ADD_WIDGET_FULL );
       
   779                         
       
   780                         ShowErrorNoteL( *msg );
       
   781                         
       
   782                         CleanupStack::PopAndDestroy( msg );
       
   783                         }                    
       
   784                     }
       
   785                 
       
   786                 break;
       
   787                 }
       
   788             }
       
   789         }
       
   790 
       
   791     // Dialog ended and deleted by RunLD
       
   792     iQuery = NULL;
       
   793 
       
   794     CleanupStack::PopAndDestroy( 2, info ); // array
       
   795     }
       
   796 
       
   797 // ---------------------------------------------------------------------------
       
   798 // CXnEditor::RemoveWidgetL
       
   799 // ---------------------------------------------------------------------------
       
   800 //
       
   801 void CXnEditor::RemoveWidgetL( CXnNode* aNode )    
       
   802     {
       
   803     if ( iTargetPlugin )
       
   804         {
       
   805         aNode = iTargetPlugin;               
       
   806         }
       
   807 
       
   808     iTargetPlugin = NULL;
       
   809     
       
   810     if ( !aNode )
       
   811         {
       
   812         return;
       
   813         }
       
   814 
       
   815     CXnPluginData* plugin( iViewManager.ActiveViewData().Plugin( aNode ) );
       
   816 
       
   817     if( plugin && plugin->Removable() )
       
   818         {
       
   819         TRAPD( err, err = iViewManager.UnloadWidgetFromPluginL( *plugin ) );
       
   820         
       
   821         if ( err != KErrNone )
       
   822             {
       
   823             HBufC* msg = StringLoader::LoadLC( 
       
   824                     R_QTN_HS_OPERATION_FAILED_NO_DISK );    
       
   825             ShowErrorNoteL( *msg );
       
   826             CleanupStack::PopAndDestroy( msg );
       
   827             }
       
   828         }
       
   829     }
       
   830 
       
   831 // ---------------------------------------------------------------------------
       
   832 // CXnEditor::ReorderWidgetsL
       
   833 // ---------------------------------------------------------------------------
       
   834 //
       
   835 void CXnEditor::ReorderWidgetsL( RPointerArray< CXnNode >* aPluginArray )
       
   836     {    
       
   837     if ( !aPluginArray )
       
   838         {
       
   839         return;
       
   840         }
       
   841     
       
   842     CXnViewData& viewData( iViewManager.ActiveViewData() );
       
   843 
       
   844     const TDesC8& configurationId( viewData.ConfigurationId() );
       
   845   
       
   846     CDesC8ArrayFlat* ids = new ( ELeave ) CDesC8ArrayFlat( 6 );
       
   847     CleanupStack::PushL( ids );
       
   848 
       
   849     for ( TInt i = 0; i < aPluginArray->Count(); i++ )
       
   850         {
       
   851         CXnPluginData* plugin( viewData.Plugin( ( *aPluginArray )[i] ) );
       
   852         if ( plugin )
       
   853             {
       
   854             const TDesC8& id( plugin->PluginId() );
       
   855             
       
   856             if ( id != KNullDesC8 )
       
   857                 {
       
   858                 ids->AppendL( id );
       
   859                 }
       
   860             }
       
   861         }        
       
   862 
       
   863     iHspsWrapper->MovePluginsL( configurationId, *ids );
       
   864 
       
   865     CleanupStack::PopAndDestroy( ids );
       
   866     }
       
   867 
       
   868 // ---------------------------------------------------------------------------
       
   869 // CXnEditor::PublisherInfoL
       
   870 // ---------------------------------------------------------------------------
       
   871 //
       
   872 CPublisherInfo* CXnEditor::PublisherInfoL( const CHsContentInfo& aContentInfo )
       
   873     {
       
   874     if ( !iPublisherMap )
       
   875         {
       
   876         return NULL;
       
   877         }
       
   878 
       
   879     RPointerArray< CPublisherInfo >& publisherInfo(
       
   880         iPublisherMap->PublisherInfo() );
       
   881     
       
   882     const TDesC& publisherId( aContentInfo.PublisherId() );
       
   883 
       
   884     CPublisherInfo* info = NULL;
       
   885     
       
   886     for ( TInt i = 0; i < publisherInfo.Count(); i++ )
       
   887         {
       
   888         CPublisherInfo* temp = publisherInfo[i];
       
   889 
       
   890         if ( temp->PublisherId() == publisherId )
       
   891             {
       
   892             info = temp;
       
   893             break;
       
   894             }
       
   895         }
       
   896 
       
   897     return info;
       
   898     }
       
   899 
       
   900 // ---------------------------------------------------------------------------
       
   901 // CXnEditor::CpsWidgetPluginsL
       
   902 // ---------------------------------------------------------------------------
       
   903 //
       
   904 void CXnEditor::CpsWidgetPluginsL( RPointerArray< CHsContentInfo >& aWidgets )
       
   905     {
       
   906     // Get publishers from CPS
       
   907     delete iPublisherMap;
       
   908     iPublisherMap = NULL;
       
   909     
       
   910     iPublisherMap = iCpsWrapper->GetTemplatedPublishersL();
       
   911     
       
   912     RPointerArray< CPublisherInfo >& publisherInfo( iPublisherMap->PublisherInfo() );
       
   913     
       
   914     // Find templates for the published data
       
   915     for ( TInt i = 0; i < publisherInfo.Count(); i++ )
       
   916         {
       
   917         CPublisherInfo* info( publisherInfo[i] );
       
   918 
       
   919         for ( TInt j = 0; j < iPluginConfigurations.Count(); j++ )
       
   920             {        
       
   921             if( iPluginConfigurations[j]->Name().Length() > 0 )
       
   922                 {               
       
   923                 // 8 to 16bit conv
       
   924                 HBufC* nameBuf = HBufC::NewLC( iPluginConfigurations[j]->Name().Length() );
       
   925                 nameBuf->Des().Copy( iPluginConfigurations[j]->Name() );
       
   926                 TBool matchingNames = ( nameBuf->Des() == info->TemplateType() );
       
   927                 CleanupStack::PopAndDestroy();
       
   928                 if ( matchingNames )
       
   929                     {
       
   930                 
       
   931                     // Add published widget
       
   932                     CHsContentInfo* contentInfo = CHsContentInfo::NewLC();
       
   933     
       
   934                     contentInfo->SetNameL( info->WidgetName() );
       
   935                     contentInfo->SetPublisherIdL( info->PublisherId() );
       
   936                     contentInfo->SetMaxWidgets( info->MaxWidgets() );
       
   937                     contentInfo->SetUidL( iPluginConfigurations[j]->Uid() );
       
   938                     contentInfo->SetTypeL( iPluginConfigurations[j]->Type() );
       
   939                     contentInfo->SetDescriptionL( info->Description() );
       
   940                     contentInfo->SetIconPathL( info->LogoIcon() );                                
       
   941                     contentInfo->SetIsWrt( info->ContentType() == KWRTTemplate() );
       
   942                                     
       
   943                     aWidgets.AppendL( contentInfo );
       
   944                     
       
   945                     CleanupStack::Pop( contentInfo );
       
   946                     break;
       
   947                     }
       
   948                 }
       
   949             }
       
   950         }        
       
   951     }
       
   952 
       
   953 
       
   954 // ---------------------------------------------------------------------------
       
   955 // CXnEditor::ToggleWidgetsVisibiltyL
       
   956 // ---------------------------------------------------------------------------
       
   957 //
       
   958 TBool CXnEditor::ToggleWidgetsVisibiltyL()
       
   959     {
       
   960     RPointerArray< CXnPluginData >& plugins(
       
   961         iViewManager.ActiveViewData().PluginData() );
       
   962 
       
   963     TBool useEmpty( iViewManager.ActiveViewData().UseEmptyWidget() );
       
   964     
       
   965     TBool stateChanged( EFalse );
       
   966 
       
   967     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   968         {
       
   969         CXnPluginData* plugin( plugins[i] );
       
   970         
       
   971         if( !plugin->Removable() )
       
   972             {
       
   973             // Don't touch to non-removable widget
       
   974             continue;
       
   975             }
       
   976 
       
   977         if ( iWidgetsVisibilityState )
       
   978             {            
       
   979             // Currently visible, make invisible
       
   980             stateChanged = ETrue;
       
   981 
       
   982             SetPropertyL( *plugin->Owner()->LayoutNode(),
       
   983                 XnPropertyNames::style::common::KVisibility,
       
   984                 XnPropertyNames::style::common::visibility::KHidden );
       
   985             }
       
   986         else
       
   987             {
       
   988             // Currently invisible, make visible
       
   989             if ( plugin->Occupied() )
       
   990                 {
       
   991                 stateChanged = ETrue;
       
   992                 
       
   993                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
   994                     XnPropertyNames::style::common::KVisibility,
       
   995                     XnPropertyNames::style::common::visibility::KVisible );                
       
   996                 }
       
   997             else if( useEmpty )
       
   998                 {
       
   999                 stateChanged = ETrue;
       
  1000                 
       
  1001                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1002                     XnPropertyNames::style::common::KVisibility,
       
  1003                     XnPropertyNames::style::common::visibility::KBlank );                                    
       
  1004                 }
       
  1005             }
       
  1006         }
       
  1007 
       
  1008     if ( stateChanged )
       
  1009         {
       
  1010         // Update
       
  1011         iWidgetsVisibilityState = !iWidgetsVisibilityState;
       
  1012         }
       
  1013 
       
  1014     return iWidgetsVisibilityState;
       
  1015     }
       
  1016 
       
  1017 // ---------------------------------------------------------------------------
       
  1018 // CXnEditor::WidgetsVisible
       
  1019 // ---------------------------------------------------------------------------
       
  1020 //
       
  1021 TBool CXnEditor::WidgetsVisible() const
       
  1022     {
       
  1023     return iWidgetsVisibilityState;
       
  1024     }
       
  1025 
       
  1026 // ---------------------------------------------------------------------------
       
  1027 // CXnEditor::SetTargetPlugin
       
  1028 // ---------------------------------------------------------------------------
       
  1029 //
       
  1030 void CXnEditor::SetTargetPlugin( CXnNode* aNode )
       
  1031     {
       
  1032     TBool editState( iViewManager.UiEngine().EditMode()->EditState() );
       
  1033     
       
  1034     if ( editState )
       
  1035         {
       
  1036         iTargetPlugin = aNode;
       
  1037         }    
       
  1038     }
       
  1039 
       
  1040 // -----------------------------------------------------------------------------
       
  1041 // CXnEditor::NotifyViewActivatedL
       
  1042 // -----------------------------------------------------------------------------
       
  1043 //
       
  1044 void CXnEditor::NotifyViewActivatedL( const CXnViewData& aViewData )
       
  1045     {
       
  1046     RPointerArray< CXnPluginData >& plugins( aViewData.PluginData() );
       
  1047     
       
  1048     TBool emptyInUse( aViewData.UseEmptyWidget() );
       
  1049     TBool editState( iViewManager.UiEngine().EditMode()->EditState() );
       
  1050               
       
  1051     iWidgetsVisibilityState = EFalse;
       
  1052     
       
  1053     for ( TInt i = 0; i < plugins.Count(); i++ )
       
  1054         {
       
  1055         CXnPluginData* plugin( plugins[i] );
       
  1056         
       
  1057         if ( plugin->Occupied() )
       
  1058             {
       
  1059             // At least one widget visible
       
  1060             iWidgetsVisibilityState = ETrue;                       
       
  1061             }
       
  1062         
       
  1063         if ( plugin->Occupied() || editState )
       
  1064             {
       
  1065             // Make widget visible
       
  1066             SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1067                 XnPropertyNames::style::common::KVisibility,
       
  1068                 XnPropertyNames::style::common::visibility::KVisible );            
       
  1069             }              
       
  1070         else
       
  1071             {            
       
  1072             if ( emptyInUse )
       
  1073                 {
       
  1074                 // Make empty space blank
       
  1075                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1076                     XnPropertyNames::style::common::KVisibility,
       
  1077                     XnPropertyNames::style::common::visibility::KBlank );
       
  1078                 }
       
  1079             else
       
  1080                 {
       
  1081                 // Nothing in this plugin hide
       
  1082                 SetPropertyL( *plugin->Owner()->LayoutNode(),
       
  1083                     XnPropertyNames::style::common::KDisplay,
       
  1084                     XnPropertyNames::style::common::display::KNone );                
       
  1085                 }
       
  1086             }
       
  1087         }                           
       
  1088     }
       
  1089 
       
  1090 // ---------------------------------------------------------------------------
       
  1091 // CXnEditor::NotifyConfigureWidgetL
       
  1092 // ---------------------------------------------------------------------------
       
  1093 //
       
  1094 void CXnEditor::NotifyConfigureWidgetL( const CHsContentInfo& aContentInfo,
       
  1095     CXnPluginData& aPluginData )
       
  1096     {
       
  1097     if ( aContentInfo.Type() != KKeyTemplate )    	    
       
  1098         {
       
  1099         // Doesn't need configuration
       
  1100         return;
       
  1101         }
       
  1102 
       
  1103     const TDesC8& pluginId( aPluginData.PluginId() );
       
  1104 
       
  1105     CHspsConfiguration* pluginConf(
       
  1106         iHspsWrapper->GetPluginConfigurationL( pluginId ) );
       
  1107 
       
  1108     CleanupStack::PushL( pluginConf );
       
  1109 
       
  1110     const CPublisherInfo* info = PublisherInfoL( aContentInfo );
       
  1111 
       
  1112     __ASSERT_DEBUG( info != NULL, Panic( EXnInvalidPublisherInfo ) );
       
  1113     if ( !info )
       
  1114         {
       
  1115         User::Leave( KErrBadHandle );
       
  1116         }
       
  1117     RPointerArray< CItemMap > itemMapListIn;
       
  1118     CleanupStack::PushL( TCleanupItem( DeleteItemMaps, &itemMapListIn ) );
       
  1119     RPointerArray< CItemMap >& settings = pluginConf->Settings();
       
  1120 
       
  1121     HBufC8* publisherId = CnvUtfConverter::ConvertFromUnicodeToUtf8L(
       
  1122         info->PublisherId() );
       
  1123     CleanupStack::PushL( publisherId );
       
  1124     
       
  1125     CItemMap* itemMap( 0 );
       
  1126     CPropertyMap* property( 0 );
       
  1127     CPropertyMap* propertyIn( 0 );
       
  1128 
       
  1129     for ( TInt i = 0; i < settings.Count(); ++i )
       
  1130         {
       
  1131         CItemMap* readItem = settings[i];
       
  1132         itemMap = CItemMap::NewLC();
       
  1133         itemMap->SetItemIdL( readItem->ItemId() );
       
  1134         const TDesC8& itemName = readItem->ItemName();
       
  1135         itemMap->SetItemNameL( itemName );
       
  1136 
       
  1137         RPointerArray< CPropertyMap >& properties = readItem->Properties();
       
  1138         for ( int j = 0; j < properties.Count(); ++j )
       
  1139             {
       
  1140             property = properties[j];
       
  1141             propertyIn = CPropertyMap::NewLC();
       
  1142             propertyIn->SetNameL( property->Name() );
       
  1143             // Dispatching is based on item name
       
  1144             if (  itemName == KContentSource() )
       
  1145                 {
       
  1146                 propertyIn->SetValueL( *publisherId );
       
  1147                 }
       
  1148             else if ( itemName ==  KContentData() )
       
  1149                 {
       
  1150                 // If this default template with full configuration
       
  1151                 TInt pos = property->Value().LocateReverse( KSepratorChar );
       
  1152                 if ( KErrNotFound != pos  )
       
  1153                     {
       
  1154                     propertyIn->SetValueL( property->Value() );
       
  1155                     }
       
  1156                 else
       
  1157                     {
       
  1158                     HBufC8* contentData = HBufC8::NewLC( publisherId->Length()
       
  1159                         + KSeperator().Length()
       
  1160                         + property->Value().Length());
       
  1161                     contentData->Des().Copy( *publisherId );
       
  1162                     contentData->Des().Append( KSeperator );
       
  1163                     contentData->Des().Append( property->Value() );
       
  1164                     propertyIn->SetValueL( *contentData );
       
  1165                     CleanupStack::PopAndDestroy( contentData );
       
  1166                     }
       
  1167                 }
       
  1168             else if ( itemName.Find( KPublisher ) != KErrNotFound )
       
  1169                 {
       
  1170                 propertyIn->SetValueL( *publisherId );
       
  1171                 }
       
  1172             else if ( !KPubTrigger().Compare( itemName ) )
       
  1173                 {
       
  1174                 HBufC8* triggerData = HBufC8::NewLC(
       
  1175                     publisherId->Length()
       
  1176                     + KSeperator().Length()
       
  1177                     + KPublisher().Length()
       
  1178                     + KWidgetTriggerName().Length());
       
  1179                 triggerData->Des().Copy( *publisherId );
       
  1180                 triggerData->Des().Append( KSeperator );
       
  1181                 triggerData->Des().Append( KPublisher );
       
  1182                 triggerData->Des().Append( KWidgetTriggerName );
       
  1183 
       
  1184                 propertyIn->SetValueL( *triggerData );
       
  1185                 CleanupStack::PopAndDestroy( triggerData );
       
  1186                 }
       
  1187             else if ( !KTrigger().Compare( itemName ) )
       
  1188                 {
       
  1189                 // If this default template with full configuration
       
  1190                 TInt pos = property->Value().LocateReverse( KSepratorChar );
       
  1191                 if ( KErrNotFound != pos )
       
  1192                     {
       
  1193                     propertyIn->SetValueL( property->Value() );
       
  1194                     }
       
  1195                 else
       
  1196                     {
       
  1197                     HBufC8* triggerData = HBufC8::NewLC(
       
  1198                         publisherId->Length()
       
  1199                         + KSeperator().Length()
       
  1200                         + property->Value().Length()
       
  1201                         + KOpen().Length()
       
  1202                         + property->Value().Length()
       
  1203                         + KClose().Length() );
       
  1204                     triggerData->Des().Copy( *publisherId );
       
  1205                     triggerData->Des().Append( KSeperator );
       
  1206                     triggerData->Des().Append( property->Value() );
       
  1207                     triggerData->Des().Append( KOpen );
       
  1208                     triggerData->Des().Append( property->Value() );
       
  1209                     triggerData->Des().Append( KClose );
       
  1210                     propertyIn->SetValueL( *triggerData );
       
  1211                     CleanupStack::PopAndDestroy( triggerData );
       
  1212                     }
       
  1213                 }
       
  1214             else
       
  1215                 {
       
  1216                 // unrecognized items are not handled
       
  1217                 }
       
  1218             itemMap->AddPropertyMapL( propertyIn );
       
  1219             CleanupStack::Pop( propertyIn );
       
  1220             }
       
  1221         itemMapListIn.AppendL( itemMap );
       
  1222         CleanupStack::Pop( itemMap );
       
  1223         }
       
  1224     iHspsWrapper->SetPluginSettingsL( pluginId, itemMapListIn );
       
  1225 
       
  1226     CleanupStack::PopAndDestroy( publisherId );
       
  1227     CleanupStack::PopAndDestroy( &itemMapListIn );
       
  1228     CleanupStack::PopAndDestroy( pluginConf );
       
  1229     }
       
  1230 
       
  1231 // ---------------------------------------------------------------------------
       
  1232 // CXnEditor::NotifyWidgetAdditionL
       
  1233 // ---------------------------------------------------------------------------
       
  1234 //
       
  1235 void CXnEditor::NotifyWidgetAdditionL( const CXnPluginData& aPluginData )
       
  1236     {
       
  1237     CXnNode* node( aPluginData.Owner()->LayoutNode() );
       
  1238 
       
  1239     // At least one widget is visible
       
  1240     iWidgetsVisibilityState = ETrue;
       
  1241     
       
  1242     // Ensure the new widget is visible
       
  1243     SetPropertyL( *node,
       
  1244         XnPropertyNames::style::common::KVisibility,
       
  1245         XnPropertyNames::style::common::visibility::KVisible );        
       
  1246     
       
  1247     SetPropertyL( *node,
       
  1248         XnPropertyNames::style::common::KDisplay,
       
  1249         XnPropertyNames::style::common::display::KBlock );
       
  1250     
       
  1251     node->SetDirtyL( XnDirtyLevel::ELayoutAndRenderSiblings );
       
  1252     
       
  1253     NotifyWidgetListChanged();
       
  1254     }
       
  1255 
       
  1256 // ---------------------------------------------------------------------------
       
  1257 // CXnEditor::NotifyWidgetRemovalL
       
  1258 // ---------------------------------------------------------------------------
       
  1259 //
       
  1260 void CXnEditor::NotifyWidgetRemovalL( const CXnPluginData& aPluginData )
       
  1261     {
       
  1262     CXnNode* node( aPluginData.Owner()->LayoutNode() );
       
  1263 
       
  1264     CXnViewData& viewData( 
       
  1265         static_cast< CXnViewData& >( *aPluginData.Parent() ) );
       
  1266     
       
  1267     TBool emptyInUse( viewData.UseEmptyWidget() );
       
  1268     
       
  1269     if ( emptyInUse )
       
  1270         {        
       
  1271         if ( iViewManager.UiEngine().IsEditMode() )
       
  1272             {
       
  1273             // Ensure the plugin which was holding 
       
  1274             // the removed widget is visible when edit mode is active
       
  1275             SetPropertyL( *node,
       
  1276                 XnPropertyNames::style::common::KVisibility,
       
  1277                 XnPropertyNames::style::common::visibility::KVisible );                   
       
  1278             }
       
  1279         else
       
  1280             {
       
  1281             // Ensure the plugin which was holding 
       
  1282             // the removed widget is blank now
       
  1283             SetPropertyL( *node,
       
  1284                 XnPropertyNames::style::common::KVisibility,
       
  1285                 XnPropertyNames::style::common::visibility::KBlank );            
       
  1286             }                
       
  1287         }
       
  1288     else
       
  1289         {
       
  1290         // Ensure the plugin which was holding the removed widget is invisible
       
  1291         SetPropertyL( *node,
       
  1292             XnPropertyNames::style::common::KDisplay,
       
  1293             XnPropertyNames::style::common::display::KNone );
       
  1294                 
       
  1295         // Reodred layout tree by moving the plugin which was holding the
       
  1296         // removed widget as the last one in layout tree's plugin the list
       
  1297         CXnNode *parent( node->Parent() );
       
  1298 
       
  1299         RPointerArray< CXnNode >& children( parent->Children() );
       
  1300 
       
  1301         TInt nodeIndex( children.Find( node ) );
       
  1302 
       
  1303         children.Remove( nodeIndex );
       
  1304         children.Insert( node, children.Count() - 1 );
       
  1305         }
       
  1306     
       
  1307     node->SetDirtyL( XnDirtyLevel::ERender );
       
  1308     
       
  1309     iTargetPlugin = NULL;
       
  1310     
       
  1311     if ( aPluginData.Active() )
       
  1312         {
       
  1313         CXnViewData& viewData( iViewManager.ActiveViewData() );
       
  1314         
       
  1315         RPointerArray< CXnPluginData >& plugins( viewData.PluginData() );
       
  1316         
       
  1317         TBool occupied( EFalse );
       
  1318         
       
  1319         for ( TInt i = 0; i < plugins.Count(); i++ )
       
  1320             {
       
  1321             if ( plugins[i]->Occupied() && plugins[i]->Removable() )
       
  1322                 {
       
  1323                 occupied = ETrue;
       
  1324                 break;
       
  1325                 }
       
  1326             }
       
  1327         
       
  1328         if ( !occupied )
       
  1329             {
       
  1330             // No more widgets in the active view
       
  1331             iWidgetsVisibilityState = EFalse;
       
  1332             }               
       
  1333         }
       
  1334     
       
  1335     NotifyWidgetListChanged();
       
  1336     }
       
  1337 
       
  1338 // ---------------------------------------------------------------------------
       
  1339 // CXnEditor::NotifyViewAdditionL
       
  1340 // ---------------------------------------------------------------------------
       
  1341 //
       
  1342 void CXnEditor::NotifyViewAdditionL( const CXnPluginData& /*aPluginData*/ )
       
  1343     {
       
  1344     NotifyViewListChanged();
       
  1345     }
       
  1346 
       
  1347 // ---------------------------------------------------------------------------
       
  1348 // CXnEditor::NotifyViewRemovalL
       
  1349 // ---------------------------------------------------------------------------
       
  1350 //
       
  1351 void CXnEditor::NotifyViewRemovalL( const CXnPluginData& /*aPluginData*/ )
       
  1352     {
       
  1353     NotifyViewListChanged();
       
  1354     }
       
  1355 
       
  1356 // ---------------------------------------------------------------------------
       
  1357 // CXnEditor::NotifyWidgetUnregisteredL
       
  1358 // ---------------------------------------------------------------------------
       
  1359 //
       
  1360 void CXnEditor::NotifyWidgetUnregisteredL( const TDesC& aPublisher )
       
  1361     {
       
  1362     ResetPluginsAndPublishers();
       
  1363     RemoveUnRegisteredWidgetL( aPublisher );
       
  1364     NotifyWidgetListChanged();    
       
  1365     }
       
  1366 
       
  1367 // ---------------------------------------------------------------------------
       
  1368 // CXnEditor::NotifyWidgetRegisteredL
       
  1369 // ---------------------------------------------------------------------------
       
  1370 //
       
  1371 void CXnEditor::NotifyWidgetRegisteredL()
       
  1372     {
       
  1373     ResetPluginsAndPublishers();        
       
  1374     NotifyWidgetListChanged();
       
  1375     }
       
  1376 
       
  1377 // ---------------------------------------------------------------------------
       
  1378 // CXnEditor::NotifyWidgetUpdatedL
       
  1379 // ---------------------------------------------------------------------------
       
  1380 //
       
  1381 void CXnEditor::NotifyWidgetUpdatedL()
       
  1382     {
       
  1383     NotifyWidgetListChanged();
       
  1384     }
       
  1385 
       
  1386 // ---------------------------------------------------------------------------
       
  1387 // CXnEditor::NotifyAllViewsLoadedL
       
  1388 // ---------------------------------------------------------------------------
       
  1389 //
       
  1390 void CXnEditor::NotifyAllViewsLoadedL()
       
  1391     {
       
  1392     NotifyViewListChanged();
       
  1393     NotifyWidgetListChanged();
       
  1394     }
       
  1395 
       
  1396 // -----------------------------------------------------------------------------
       
  1397 // CXnEditor::NotifyContainerActivatedL
       
  1398 // -----------------------------------------------------------------------------
       
  1399 //
       
  1400 void CXnEditor::NotifyContainerActivatedL( const CXnViewData& /* aViewData */ )
       
  1401     {
       
  1402     if ( iViewManager.ActiveAppData().AllViewsLoaded() )
       
  1403         {
       
  1404         NotifyWidgetListChanged();
       
  1405         }
       
  1406     }
       
  1407 
       
  1408 // ---------------------------------------------------------------------------
       
  1409 // CXnEditor::NotifyWidgetListChanged
       
  1410 // ---------------------------------------------------------------------------
       
  1411 //
       
  1412 void CXnEditor::NotifyWidgetListChanged()
       
  1413     {
       
  1414     if ( iNotifyWidgetListChanged->IsActive() )
       
  1415         {
       
  1416         iNotifyWidgetListChanged->Cancel();
       
  1417         }
       
  1418     // start waiting for widget list changes (wait time is 1sec).
       
  1419     // if no new changes, notify observers about changes. otherwise
       
  1420     // start waiting for new updates again. 
       
  1421     iNotifyWidgetListChanged->Start(
       
  1422         KNotifyWidgetListChangedDelay,
       
  1423         KNotifyWidgetListChangedDelay,
       
  1424         TCallBack( WidgetListChangedCallBack, this ) );
       
  1425 
       
  1426     }
       
  1427 
       
  1428 // ---------------------------------------------------------------------------
       
  1429 // CXnEditor::WidgetListChangedCallBack
       
  1430 // ---------------------------------------------------------------------------
       
  1431 //
       
  1432 TInt CXnEditor::WidgetListChangedCallBack( TAny* aSelf )
       
  1433     {
       
  1434     CXnEditor* editor = static_cast<CXnEditor*>( aSelf );
       
  1435     if ( editor && editor->iNotifyWidgetListChanged->IsActive() )
       
  1436         {
       
  1437         // prevent multiple events
       
  1438         editor->iNotifyWidgetListChanged->Cancel();
       
  1439         editor->WidgetListChanged();
       
  1440         }
       
  1441     return KErrNone;
       
  1442     }
       
  1443 
       
  1444 // ---------------------------------------------------------------------------
       
  1445 // CXnEditor::NotifyViewListChanged
       
  1446 // ---------------------------------------------------------------------------
       
  1447 //
       
  1448 void CXnEditor::NotifyViewListChanged()
       
  1449     {
       
  1450     if ( iNotifyViewListChanged->IsActive() )
       
  1451         {
       
  1452         iNotifyViewListChanged->Cancel();
       
  1453         }
       
  1454     // start waiting for widget list changes (wait time is 1sec).
       
  1455     // if no new changes, notify observer about changes. otherwise
       
  1456     // start waiting for new changes again. 
       
  1457     iNotifyViewListChanged->Start(
       
  1458         KNotifyViewListChangedDelay,
       
  1459         KNotifyViewListChangedDelay,
       
  1460         TCallBack( ViewListChangedCallBack, this ) );
       
  1461 
       
  1462     }
       
  1463 
       
  1464 // ---------------------------------------------------------------------------
       
  1465 // CXnEditor::ViewListChangedCallBack
       
  1466 // ---------------------------------------------------------------------------
       
  1467 //
       
  1468 TInt CXnEditor::ViewListChangedCallBack( TAny* aSelf )
       
  1469     {
       
  1470     CXnEditor* editor = static_cast<CXnEditor*>( aSelf );
       
  1471     if ( editor && editor->iNotifyViewListChanged->IsActive() )
       
  1472         {
       
  1473         // prevent multiple events
       
  1474         editor->iNotifyViewListChanged->Cancel();
       
  1475         editor->ViewListChanged();
       
  1476         }
       
  1477     return KErrNone;
       
  1478     }
       
  1479 
       
  1480 // ---------------------------------------------------------------------------
       
  1481 // CXnEditor::NotifyViewDeactivatedL
       
  1482 // ---------------------------------------------------------------------------
       
  1483 //
       
  1484 void CXnEditor::NotifyViewDeactivatedL( const CXnViewData& /*aViewData*/)
       
  1485     {
       
  1486     iTargetPlugin = NULL;
       
  1487     }
       
  1488 
       
  1489 // ---------------------------------------------------------------------------
       
  1490 // CXnEditor::SetWallpaperL
       
  1491 // ---------------------------------------------------------------------------
       
  1492 //
       
  1493 void CXnEditor::SetWallpaperL()
       
  1494     {
       
  1495     // Display dialog
       
  1496     TInt selectedIndex( 0 );
       
  1497 
       
  1498     CAknListQueryDialog* query =
       
  1499         new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
  1500     CleanupStack::PushL( query );
       
  1501     query->PrepareLC( R_LISTQUERY_CHANGE_WALLPAPER );
       
  1502 
       
  1503     if ( query->RunLD() )
       
  1504         {
       
  1505         if ( selectedIndex == 0 )
       
  1506             {
       
  1507             // set wallpaper. No need to check return value. If successful,
       
  1508             // avkon calls SkinConfigurationChanged function
       
  1509             AknsWallpaperUtils::SetIdleWallpaper(
       
  1510                     KNullDesC,
       
  1511                     NULL );
       
  1512             }
       
  1513         else if ( selectedIndex == 1 )
       
  1514             {
       
  1515             iViewManager.AppUiAdapter().ActivateLocalViewL( KWallpaperViewUid, KDummyUid, KSingle );                
       
  1516             }
       
  1517         else if ( selectedIndex == 2 )
       
  1518             {
       
  1519             iViewManager.AppUiAdapter().ActivateLocalViewL( KWallpaperViewUid, KDummyUid, KMulti );                
       
  1520             }        
       
  1521         }
       
  1522     CleanupStack::Pop( query );
       
  1523     }
       
  1524 
       
  1525 // -----------------------------------------------------------------------------
       
  1526 // CXnEditor::HandleNotifyL
       
  1527 // Handles notifications from HSPS wrapper
       
  1528 // -----------------------------------------------------------------------------
       
  1529 //
       
  1530 TInt CXnEditor::HandleNotifyL(
       
  1531     const TDesC8& aEvent,
       
  1532     const TDesC8& /*aAppConfUid*/,
       
  1533     const TDesC8& aPluginName,
       
  1534     const TDesC8& /*aOrigUid*/,
       
  1535     const TDesC8& aPluginUid,
       
  1536     const TDesC8& aPluginId )
       
  1537     {
       
  1538     if ( aEvent == KEventPluginUnInstalled )
       
  1539         {
       
  1540         ResetPluginsAndPublishers();
       
  1541                 
       
  1542         CHsContentInfo* info = CHsContentInfo::NewLC();
       
  1543 
       
  1544         info->SetNameL( aPluginName );
       
  1545         info->SetUidL( aPluginUid );
       
  1546         info->SetPluginIdL( aPluginId );
       
  1547 
       
  1548         RemoveUnInstalledWidgetL( *info );
       
  1549         NotifyWidgetListChanged();
       
  1550 
       
  1551         CleanupStack::PopAndDestroy( info );
       
  1552         }
       
  1553     else if ( aEvent == KEventRootConfActivated )
       
  1554         {
       
  1555         iViewManager.AppUiAdapter().ReloadUiL();
       
  1556         }
       
  1557     else if ( aEvent == KEventPluginInstalled )
       
  1558         {        
       
  1559         ResetPluginsAndPublishers();
       
  1560         
       
  1561         NotifyWidgetListChanged();        
       
  1562         }
       
  1563     else if ( aEvent == KEventPluginUpdated )
       
  1564         {
       
  1565         ResetPluginsAndPublishers();
       
  1566         
       
  1567         // If the plugin is in use then reload the widget
       
  1568         if ( aPluginId.Length() > 0 )
       
  1569             {
       
  1570             CHsContentInfo* info = CHsContentInfo::NewLC();    
       
  1571             info->SetNameL( aPluginName );
       
  1572             info->SetUidL( aPluginUid );
       
  1573             info->SetPluginIdL( aPluginId );    
       
  1574             ReplaceWidgetL( *info );                
       
  1575             CleanupStack::PopAndDestroy( info );
       
  1576             }
       
  1577         NotifyWidgetListChanged();
       
  1578         }
       
  1579  
       
  1580     return KErrNone;
       
  1581     }
       
  1582 
       
  1583 // -----------------------------------------------------------------------------
       
  1584 // CXnEditor::WidgetListChanged
       
  1585 // -----------------------------------------------------------------------------
       
  1586 //
       
  1587 void CXnEditor::WidgetListChanged()
       
  1588     {
       
  1589     TBuf8<KOpaQDataLen> oPaqDataStr = KNullDesC8();
       
  1590               
       
  1591    MHsContentControlUi* ui( NULL );
       
  1592    if ( IdFromCrep ( oPaqDataStr ) == KErrNone )
       
  1593        {
       
  1594        ui = iViewManager.AppUiAdapter().HsContentController( oPaqDataStr ); 
       
  1595        }
       
  1596     if( ui )
       
  1597         {
       
  1598         ui->NotifyWidgetListChanged();
       
  1599         }
       
  1600     MHsContentControl* srv( iViewManager.AppUiAdapter().HsContentControlSrv() );
       
  1601     if ( srv )
       
  1602         {
       
  1603         srv->NotifyWidgetListChanged();
       
  1604         }
       
  1605     }
       
  1606 
       
  1607 // -----------------------------------------------------------------------------
       
  1608 // CXnEditor::ViewListChanged
       
  1609 // -----------------------------------------------------------------------------
       
  1610 //
       
  1611 void CXnEditor::ViewListChanged()
       
  1612     {
       
  1613     TBuf8<KOpaQDataLen> oPaqDataStr = KNullDesC8();
       
  1614               
       
  1615    MHsContentControlUi* ui( NULL );
       
  1616    if ( IdFromCrep ( oPaqDataStr ) == KErrNone )
       
  1617        {
       
  1618        ui = iViewManager.AppUiAdapter().HsContentController( oPaqDataStr ); 
       
  1619        }
       
  1620     if( ui )
       
  1621         {
       
  1622         ui->NotifyViewListChanged();
       
  1623         }
       
  1624     MHsContentControl* srv( iViewManager.AppUiAdapter().HsContentControlSrv() );
       
  1625     if ( srv )
       
  1626         {
       
  1627         srv->NotifyViewListChanged();
       
  1628         }
       
  1629     }
       
  1630 
       
  1631 // -----------------------------------------------------------------------------
       
  1632 // CXnEditor::HspsWrapper
       
  1633 // -----------------------------------------------------------------------------
       
  1634 //
       
  1635 CHspsWrapper& CXnEditor::HspsWrapper() const
       
  1636     {
       
  1637     return *iHspsWrapper;
       
  1638     }
       
  1639 
       
  1640 // -----------------------------------------------------------------------------
       
  1641 // CXnEditor::AppendPluginsL
       
  1642 // -----------------------------------------------------------------------------
       
  1643 //
       
  1644 void CXnEditor::AppendPluginsL(
       
  1645         RPointerArray< hspswrapper::CPluginInfo > aPlugins,
       
  1646         RPointerArray< CHsContentInfo >& aWidgets )    
       
  1647     {    
       
  1648     // Append plugins to the content info array
       
  1649     for ( TInt i = 0; i < aPlugins.Count(); i++ )
       
  1650        {
       
  1651     
       
  1652        // Block the empty and template plugins from the list
       
  1653        if ( aPlugins[i]->Uid().CompareF( KEmptyWidgetUid ) == 0 
       
  1654                || aPlugins[i]->Type() == KKeyTemplate )
       
  1655            {           
       
  1656            continue;
       
  1657            }
       
  1658        
       
  1659        CHsContentInfo* contentInfo = CHsContentInfo::NewLC();
       
  1660        contentInfo->SetNameL( aPlugins[i]->Name() );
       
  1661        contentInfo->SetUidL( aPlugins[i]->Uid() );
       
  1662        contentInfo->SetTypeL( aPlugins[i]->Type() );      
       
  1663        if ( aPlugins[i]->Type() == KKeyWidget 
       
  1664                || aPlugins[i]->Type() == KKeyTemplate )
       
  1665            {
       
  1666            contentInfo->SetMaxWidgets( aPlugins[i]->MultiInstance() );
       
  1667            }
       
  1668        contentInfo->SetDescriptionL( aPlugins[i]->Description() );
       
  1669        contentInfo->SetIconPathL( aPlugins[i]->LogoIcon() );
       
  1670 
       
  1671        aWidgets.AppendL( contentInfo );
       
  1672        CleanupStack::Pop( contentInfo );
       
  1673        }    
       
  1674     }
       
  1675 
       
  1676 // -----------------------------------------------------------------------------
       
  1677 // CXnEditor::ResetPluginsAndPublishers
       
  1678 // -----------------------------------------------------------------------------
       
  1679 //
       
  1680 void CXnEditor::ResetPluginsAndPublishers()
       
  1681     {
       
  1682     // Force loading of widget/template plugin configurations
       
  1683     iPluginConfigurations.ResetAndDestroy();
       
  1684     
       
  1685     // Forece reloading of CPS publishers 
       
  1686     delete iPublisherMap;
       
  1687     iPublisherMap = NULL;
       
  1688     }
       
  1689 
       
  1690 // -----------------------------------------------------------------------------
       
  1691 // CXnEditor::HspsApplicationPluginsL
       
  1692 // -----------------------------------------------------------------------------
       
  1693 //
       
  1694 void  CXnEditor::HspsApplicationPluginsL( RPointerArray< CHsContentInfo >& aWidgets )
       
  1695     {
       
  1696     RPointerArray< hspswrapper::CPluginInfo > plugins;
       
  1697     CleanupStack::PushL( TCleanupItem( DeletePluginInfos, &plugins ) );
       
  1698         
       
  1699     iHspsWrapper->GetAppConfigurationsL( plugins );
       
  1700     
       
  1701     // Append plugins to the content info array
       
  1702     AppendPluginsL( plugins, aWidgets ); 
       
  1703     
       
  1704     CleanupStack::PopAndDestroy( &plugins );
       
  1705     }
       
  1706 
       
  1707 // -----------------------------------------------------------------------------
       
  1708 // CXnEditor::HspsViewPluginsL
       
  1709 // -----------------------------------------------------------------------------
       
  1710 //
       
  1711 void CXnEditor::HspsViewPluginsL( RPointerArray< CHsContentInfo >& aWidgets )
       
  1712     {
       
  1713     RPointerArray< hspswrapper::CPluginInfo > plugins;
       
  1714     CleanupStack::PushL( TCleanupItem( DeletePluginInfos, &plugins ) );
       
  1715         
       
  1716     iHspsWrapper->GetPluginsL( plugins, KPluginInterface, KView );
       
  1717     
       
  1718     // Append plugins to the content info array
       
  1719     AppendPluginsL( plugins, aWidgets ); 
       
  1720     
       
  1721     CleanupStack::PopAndDestroy( &plugins );
       
  1722     }
       
  1723 
       
  1724 // -----------------------------------------------------------------------------
       
  1725 // CXnEditor::HspsWidgetPluginsL
       
  1726 // -----------------------------------------------------------------------------
       
  1727 //
       
  1728 void CXnEditor::HspsWidgetPluginsL( RPointerArray< CHsContentInfo >& aWidgets )
       
  1729     {          
       
  1730     __ASSERT_DEBUG( aWidgets.Count() == 0, User::Leave( KErrGeneral ) );
       
  1731     
       
  1732     // If widget/template plugins haven't been fetched yet
       
  1733     if( iPluginConfigurations.Count() == 0 )
       
  1734         {
       
  1735         // Fetch the plugins into the runtime cache
       
  1736         TRAPD( err, DoHspsWidgetPluginsL() );
       
  1737         if( err )
       
  1738             {            
       
  1739             ResetPluginsAndPublishers();
       
  1740             User::LeaveIfError( err );
       
  1741             }  
       
  1742         }    
       
  1743         
       
  1744     // Append plugins to the content info array
       
  1745     AppendPluginsL( iPluginConfigurations, aWidgets );            
       
  1746     }
       
  1747 
       
  1748 // -----------------------------------------------------------------------------
       
  1749 // CXnEditor::DoHspsWidgetPluginsL
       
  1750 // -----------------------------------------------------------------------------
       
  1751 //
       
  1752 void CXnEditor::DoHspsWidgetPluginsL()
       
  1753     {        
       
  1754     iHspsWrapper->GetPluginsL( iPluginConfigurations, KPluginInterface, KKeyWidget );        
       
  1755     iHspsWrapper->GetPluginsL( iPluginConfigurations, KPluginInterface, KKeyTemplate );            
       
  1756     }
       
  1757 
       
  1758 // -----------------------------------------------------------------------------
       
  1759 // from MHsContentController
       
  1760 // -----------------------------------------------------------------------------
       
  1761 //
       
  1762 TInt CXnEditor::WidgetListL( CHsContentInfoArray& aArray )
       
  1763     {
       
  1764     // append the list with native widget and template plugins from HSPS
       
  1765     HspsWidgetPluginsL( aArray.Array() );
       
  1766         
       
  1767     // append the list with published template plugins from CPS 
       
  1768     CpsWidgetPluginsL( aArray.Array() );
       
  1769 
       
  1770     // check whether the plugins can be added or removed
       
  1771     FilterPluginsL( aArray, ETrue );
       
  1772     
       
  1773     return KErrNone;
       
  1774     }
       
  1775 
       
  1776 // -----------------------------------------------------------------------------
       
  1777 // from MHsContentController
       
  1778 // -----------------------------------------------------------------------------
       
  1779 //
       
  1780 TInt CXnEditor::WidgetListL( CHsContentInfo& aInfo, CHsContentInfoArray& aArray )
       
  1781     {
       
  1782     TInt err( KErrNone );
       
  1783     RPointerArray< CXnPluginData > widgets;
       
  1784     CleanupClosePushL( widgets );
       
  1785     
       
  1786     if ( aInfo.Type() == KApplication )
       
  1787         {
       
  1788         if ( aInfo.Uid().CompareF( iViewManager.ActiveAppData().PluginUid() ) == 0 )
       
  1789             {
       
  1790             // Get widgets included in active application configuration
       
  1791             err = iViewManager.PluginDataL( KNullDesC8(), widgets );
       
  1792             }
       
  1793         else
       
  1794             {
       
  1795             // Invalid application configuration
       
  1796             err = KErrArgument;
       
  1797             }
       
  1798         }
       
  1799     else if ( aInfo.Type() == KView )
       
  1800         {
       
  1801         // Get widgets included in a view
       
  1802         err = iViewManager.PluginDataL( aInfo.PluginId(), widgets );
       
  1803         }
       
  1804     else
       
  1805         {
       
  1806         err = KErrArgument;
       
  1807         }
       
  1808     
       
  1809     if ( !err )
       
  1810         {
       
  1811         // Get installed widget content infos
       
  1812         RPointerArray< CHsContentInfo > array;
       
  1813         CleanupStack::PushL( TCleanupItem( DeleteContentInfo, &array ) );
       
  1814         
       
  1815         // get installed widgets and template configurations from HSPS
       
  1816         HspsWidgetPluginsL( array );
       
  1817                 
       
  1818         // get published widgets
       
  1819         CpsWidgetPluginsL( array );
       
  1820                 
       
  1821         // Create content info for each found widget
       
  1822         for ( TInt i = 0; i < widgets.Count(); i++ )
       
  1823             {
       
  1824             CHsContentInfo* info = CreateContentInfoLC( *widgets[i], array );
       
  1825             if ( info )
       
  1826                 {
       
  1827                 aArray.Array().AppendL( info );
       
  1828                 CleanupStack::Pop( info );
       
  1829                 }
       
  1830             }
       
  1831         CleanupStack::PopAndDestroy(); // array
       
  1832         }
       
  1833     
       
  1834     CleanupStack::PopAndDestroy(); // widgets
       
  1835         
       
  1836     return err;
       
  1837     }
       
  1838 
       
  1839 // -----------------------------------------------------------------------------
       
  1840 // from MHsContentController
       
  1841 // -----------------------------------------------------------------------------
       
  1842 //
       
  1843 TInt CXnEditor::ViewListL( CHsContentInfoArray& aArray )
       
  1844     {
       
  1845     RPointerArray< CHsContentInfo >& array( aArray.Array() );
       
  1846     
       
  1847     
       
  1848     // get installed view configurations from HSPS
       
  1849     HspsViewPluginsL( array );
       
  1850     
       
  1851     FilterViewListL( aArray );
       
  1852     
       
  1853     return KErrNone;
       
  1854     }
       
  1855 
       
  1856 // -----------------------------------------------------------------------------
       
  1857 // from MHsContentController
       
  1858 // -----------------------------------------------------------------------------
       
  1859 //
       
  1860 TInt CXnEditor::ViewListL( CHsContentInfo& aInfo, CHsContentInfoArray& aArray )
       
  1861     {
       
  1862     TInt err( KErrNone );
       
  1863 
       
  1864     if ( aInfo.Type() == KApplication )
       
  1865         {
       
  1866         if ( aInfo.Uid().CompareF( iViewManager.ActiveAppData().PluginUid() ) == 0 )
       
  1867             {
       
  1868             // Get list of views in active application configuration
       
  1869             CXnRootData& appData( iViewManager.ActiveAppData() );
       
  1870             RPointerArray< CXnPluginData >& views( appData.PluginData() );
       
  1871             
       
  1872             // Get installed view content infos
       
  1873             RPointerArray< CHsContentInfo > array;
       
  1874             CleanupStack::PushL( TCleanupItem( DeleteContentInfo, &array ) );
       
  1875             HspsViewPluginsL( array );
       
  1876                     
       
  1877             // Create content info for each found view
       
  1878             for ( TInt i = 0; i < views.Count(); i++ )
       
  1879                 {
       
  1880                 CHsContentInfo* info = CreateContentInfoLC( *views[i], array );
       
  1881                 if ( info )
       
  1882                     {
       
  1883                     CXnViewData* view = static_cast < CXnViewData* >( views[ i ] );
       
  1884                     info->SetIsFull( IsViewFull( *view ) );
       
  1885                     aArray.Array().AppendL( info );
       
  1886                     CleanupStack::Pop( info );
       
  1887                     }
       
  1888                 }
       
  1889             CleanupStack::PopAndDestroy(); // array
       
  1890             }
       
  1891         else
       
  1892             {
       
  1893             // Invalid application configuration
       
  1894             err = KErrArgument;
       
  1895             }
       
  1896         }
       
  1897     else
       
  1898         {
       
  1899         // Invalid argument
       
  1900         err = KErrArgument;
       
  1901         }
       
  1902     
       
  1903     return err;
       
  1904     }
       
  1905 
       
  1906 // -----------------------------------------------------------------------------
       
  1907 // from MHsContentController
       
  1908 // -----------------------------------------------------------------------------
       
  1909 //
       
  1910 TInt CXnEditor::AppListL( CHsContentInfoArray& aArray )
       
  1911     {
       
  1912     RPointerArray< CHsContentInfo >& array( aArray.Array() );
       
  1913     
       
  1914     // get installed application configurations from HSPS
       
  1915     HspsApplicationPluginsL( array );
       
  1916     
       
  1917     return KErrNone;
       
  1918     }
       
  1919 
       
  1920 // -----------------------------------------------------------------------------
       
  1921 // from MHsContentController
       
  1922 // -----------------------------------------------------------------------------
       
  1923 //
       
  1924 TInt CXnEditor::AddWidgetL( CHsContentInfo& aInfo )
       
  1925     {
       
  1926     TInt ret( KErrNone );    
       
  1927 
       
  1928     const TDesC8& type( aInfo.Type() );
       
  1929     
       
  1930     if ( ( type != KKeyWidget && type != KKeyTemplate ) ||
       
  1931          aInfo.Uid() == KNullDesC8  || !aInfo.CanBeAdded() )
       
  1932         {
       
  1933         // malformed content info
       
  1934         return KErrArgument;
       
  1935         }
       
  1936 
       
  1937     CXnPluginData* plugin( NULL );
       
  1938     
       
  1939     if( iTargetPlugin )
       
  1940         {
       
  1941         plugin = DeterminePlugin( iViewManager, iTargetPlugin );
       
  1942         }
       
  1943     else
       
  1944         {
       
  1945         plugin = DeterminePlugin( iViewManager );
       
  1946         }
       
  1947     
       
  1948     iTargetPlugin = NULL;
       
  1949     
       
  1950     // the widget can not be added. Return proper error code
       
  1951     if ( IsCurrentViewFull() || !plugin )
       
  1952         {
       
  1953         return KHsErrorViewFull;
       
  1954         }
       
  1955     else
       
  1956         {
       
  1957         TInt result;
       
  1958         if ( aInfo.Type() != KKeyTemplate() )
       
  1959             { 
       
  1960             result = NonTemplateWidgetCanBeAddedRemovedL( aInfo ); 
       
  1961             }
       
  1962         else
       
  1963             {
       
  1964             result = TemplateWidgetCanBeAddedRemovedL( aInfo );
       
  1965             } 
       
  1966         
       
  1967         if ( !( result & ECanBeAdded ) )
       
  1968             {
       
  1969             return KHsErrorMaxInstanceCountExceeded;
       
  1970             } 
       
  1971         }
       
  1972     
       
  1973     ret = iViewManager.LoadWidgetToPluginL( aInfo, *plugin );
       
  1974     
       
  1975     if( ret == KErrNone )
       
  1976         {
       
  1977         CXnNode* node( plugin->Owner()->LayoutNode() );
       
  1978         TBool widgetOk( iViewManager.UiEngine().AnalyseAddedWidgetL( *node ) );
       
  1979     
       
  1980         if( !widgetOk )
       
  1981             {
       
  1982             iViewManager.UnloadWidgetFromPluginL( *plugin );
       
  1983             
       
  1984             ret = KHsErrorDoesNotFit;
       
  1985             }        
       
  1986         }
       
  1987     
       
  1988     return ret;
       
  1989     }
       
  1990 
       
  1991 // -----------------------------------------------------------------------------
       
  1992 // from MHsContentController
       
  1993 // -----------------------------------------------------------------------------
       
  1994 //
       
  1995 TInt CXnEditor::RemoveWidgetL( CHsContentInfo& aInfo )
       
  1996     {
       
  1997     if ( !aInfo.CanBeRemoved() || aInfo.PluginId() == KNullDesC8 || 
       
  1998         ( aInfo.Type() != KKeyWidget && aInfo.Type() != KKeyTemplate ) )
       
  1999         {
       
  2000         return KErrArgument;
       
  2001         }
       
  2002     
       
  2003     TInt retval( KErrNotFound );
       
  2004     
       
  2005     RPointerArray< CXnPluginData > plugins;
       
  2006     CleanupClosePushL( plugins );
       
  2007     
       
  2008     // Search only from active view
       
  2009     iViewManager.PluginDataL( plugins );
       
  2010     
       
  2011     CXnPluginData* plugin( DeterminePlugin( plugins, aInfo ) ); 
       
  2012                             
       
  2013     if ( plugin && plugin->Removable() )
       
  2014         {
       
  2015         retval = iViewManager.UnloadWidgetFromPluginL( *plugin );
       
  2016         }  
       
  2017     
       
  2018     CleanupStack::PopAndDestroy( &plugins );
       
  2019     
       
  2020     return retval;
       
  2021     }
       
  2022 
       
  2023 // -----------------------------------------------------------------------------
       
  2024 // from MHsContentController
       
  2025 // -----------------------------------------------------------------------------
       
  2026 //
       
  2027 TInt CXnEditor::AddViewL( CHsContentInfo& aInfo )
       
  2028     {
       
  2029     if ( !aInfo.CanBeAdded() || aInfo.Uid() == KNullDesC8 || 
       
  2030         aInfo.Type() != KView )
       
  2031         {
       
  2032         return KErrArgument;
       
  2033         }
       
  2034           
       
  2035     return iViewManager.AddViewL( aInfo );
       
  2036     }
       
  2037 
       
  2038 // -----------------------------------------------------------------------------
       
  2039 // from MHsContentController
       
  2040 // -----------------------------------------------------------------------------
       
  2041 //
       
  2042 TInt CXnEditor::RemoveViewL( CHsContentInfo& aInfo )
       
  2043     {
       
  2044     if ( !aInfo.CanBeRemoved() || aInfo.PluginId() == KNullDesC8 || 
       
  2045         aInfo.Type() != KView )
       
  2046         {
       
  2047         return KErrArgument;
       
  2048         }
       
  2049     
       
  2050     return iViewManager.RemoveViewL( aInfo );
       
  2051     }
       
  2052 
       
  2053 // -----------------------------------------------------------------------------
       
  2054 // from MHsContentController
       
  2055 // -----------------------------------------------------------------------------
       
  2056 //
       
  2057 TInt CXnEditor::ActivateViewL( CHsContentInfo& aInfo )
       
  2058     {
       
  2059     if ( aInfo.Type() != KView )
       
  2060         {
       
  2061         return KErrArgument;
       
  2062         }
       
  2063     
       
  2064     return iViewManager.ActivateViewL( aInfo.PluginId() );
       
  2065     }
       
  2066 
       
  2067 // -----------------------------------------------------------------------------
       
  2068 // from MHsContentController
       
  2069 // -----------------------------------------------------------------------------
       
  2070 //
       
  2071 TInt CXnEditor::ActivateAppL( CHsContentInfo& aInfo )
       
  2072     {
       
  2073     if ( aInfo.Type() != KApplication )
       
  2074         {
       
  2075         return KErrArgument;
       
  2076         }
       
  2077     
       
  2078     return iViewManager.ActivateAppL( aInfo.Uid() );     
       
  2079     }
       
  2080 
       
  2081 // -----------------------------------------------------------------------------
       
  2082 // from MHsContentController
       
  2083 // -----------------------------------------------------------------------------
       
  2084 //
       
  2085 TInt CXnEditor::ActiveViewL( CHsContentInfo& aInfo )
       
  2086     {
       
  2087 
       
  2088     TInt err( KErrNone );
       
  2089         
       
  2090     CXnViewData& viewData( iViewManager.ActiveViewData() );
       
  2091     
       
  2092     CHspsConfiguration* view( iHspsWrapper->GetPluginConfigurationL( viewData.PluginId() ) );
       
  2093     CleanupStack::PushL( view );
       
  2094     if ( view )
       
  2095         {
       
  2096         aInfo.SetNameL( view->PluginInfo().Name() );
       
  2097         aInfo.SetPluginIdL( viewData.PluginId() );
       
  2098         aInfo.SetUidL( view->PluginInfo().Uid() );
       
  2099         aInfo.SetTypeL( view->PluginInfo().Type() );
       
  2100         aInfo.SetDescriptionL( view->PluginInfo().Description() );
       
  2101         aInfo.SetIconPathL( view->PluginInfo().LogoIcon() );
       
  2102         aInfo.SetIsFull( IsViewFull( viewData ) );        
       
  2103         }
       
  2104     else
       
  2105         {
       
  2106         err = KErrNotFound;
       
  2107         }
       
  2108         
       
  2109     CleanupStack::PopAndDestroy( view );
       
  2110     
       
  2111     return err;     
       
  2112     }
       
  2113 
       
  2114 // -----------------------------------------------------------------------------
       
  2115 // from MHsContentController
       
  2116 // -----------------------------------------------------------------------------
       
  2117 //
       
  2118 TInt CXnEditor::ActiveAppL( CHsContentInfo& aInfo )
       
  2119     {
       
  2120     
       
  2121     TInt err( KErrNone );
       
  2122     CHspsConfiguration* app = iHspsWrapper->GetAppConfigurationL();
       
  2123     CleanupStack::PushL( app );
       
  2124 
       
  2125     if ( app->PluginInfo().Uid().Length() > 0 )
       
  2126         {
       
  2127         aInfo.SetNameL( app->PluginInfo().Name() );
       
  2128         aInfo.SetUidL( app->PluginInfo().Uid() );
       
  2129         aInfo.SetTypeL( app->PluginInfo().Type() );
       
  2130         aInfo.SetDescriptionL( app->PluginInfo().Description() );
       
  2131         aInfo.SetIconPathL( app->PluginInfo().LogoIcon() );
       
  2132 
       
  2133         CXnRootData& appData( iViewManager.ActiveAppData() );
       
  2134         if ( appData.PluginData().Count() < appData.MaxPages() )
       
  2135             {
       
  2136             aInfo.SetIsFull( EFalse );
       
  2137             }
       
  2138         else
       
  2139             {
       
  2140             aInfo.SetIsFull( ETrue );
       
  2141             }
       
  2142         }
       
  2143     else
       
  2144         {
       
  2145         err = KErrNotFound;
       
  2146         }
       
  2147     
       
  2148     CleanupStack::PopAndDestroy( app );
       
  2149     return err;     
       
  2150     }
       
  2151 
       
  2152 // -----------------------------------------------------------------------------
       
  2153 // CXnEditor::CreateContentInfoLC
       
  2154 // -----------------------------------------------------------------------------
       
  2155 //
       
  2156 CHsContentInfo* CXnEditor::CreateContentInfoLC( CXnPluginData& aPlugin, 
       
  2157     RPointerArray< CHsContentInfo >& aInfos )
       
  2158     {
       
  2159     CHsContentInfo* contentInfo( NULL );
       
  2160     if ( aPlugin.Occupied() )
       
  2161         {
       
  2162         for ( TInt i = 0; i < aInfos.Count() && !contentInfo; i++ )
       
  2163             {
       
  2164             CHsContentInfo* info = aInfos[i];
       
  2165             if ( ( !aPlugin.PublisherName().Length() && 
       
  2166                    aPlugin.PluginUid().CompareF( info->Uid() ) == 0 ) ||
       
  2167                  ( aPlugin.PublisherName().Length() &&
       
  2168                    aPlugin.PublisherName().CompareF( info->PublisherId() ) == 0 )
       
  2169                 )
       
  2170                 {
       
  2171                 contentInfo = info->CloneL();
       
  2172                 CleanupStack::PushL( contentInfo );
       
  2173                 contentInfo->SetPluginIdL( aPlugin.PluginId() );
       
  2174                 contentInfo->SetCanBeRemoved( aPlugin.Removable() );
       
  2175                 }
       
  2176             }
       
  2177         }
       
  2178     return contentInfo;
       
  2179     }
       
  2180 
       
  2181 // -----------------------------------------------------------------------------
       
  2182 // CXnEditor::IsViewFull
       
  2183 // -----------------------------------------------------------------------------
       
  2184 //
       
  2185 TBool CXnEditor::IsViewFull( CXnViewData& aViewData )
       
  2186     {
       
  2187     TBool isFull( ETrue );
       
  2188 
       
  2189     RPointerArray< CXnPluginData >& plugins( 
       
  2190             aViewData.PluginData() );
       
  2191 
       
  2192     for ( TInt i = 0; i < plugins.Count(); i++ )
       
  2193         {
       
  2194         CXnPluginData* plugin = plugins[ i ];
       
  2195 
       
  2196         if ( !plugin->Occupied() )
       
  2197             {
       
  2198             isFull = EFalse;
       
  2199             break;
       
  2200             }
       
  2201         }
       
  2202     
       
  2203     return isFull;
       
  2204     }
       
  2205 
       
  2206 // -----------------------------------------------------------------------------
       
  2207 // CXnBackgroundManager::OOMSysHandler
       
  2208 // -----------------------------------------------------------------------------
       
  2209 //
       
  2210 CXnOomSysHandler& CXnEditor::OomSysHandler() const
       
  2211     {
       
  2212     __ASSERT_DEBUG( iOomSysHandler , User::Panic( _L("xneditor"), 0 ) );
       
  2213 
       
  2214     return *iOomSysHandler;
       
  2215     }
       
  2216 
       
  2217 // End of file