idlefw/plugins/mcsplugin/publisher/src/mcsplugindata.cpp
branchRCL_3
changeset 18 bd874ee5e5e2
parent 9 d0529222e3f0
child 19 502e5d91ad42
equal deleted inserted replaced
9:d0529222e3f0 18:bd874ee5e5e2
    16 */
    16 */
    17 #include <mcsmenuitem.h>
    17 #include <mcsmenuitem.h>
    18 #include <mcsmenufilter.h>
    18 #include <mcsmenufilter.h>
    19 #include <itemmap.h>
    19 #include <itemmap.h>
    20 #include <aistrcnv.h>
    20 #include <aistrcnv.h>
       
    21 #include <favouritesdbobserver.h>
       
    22 #include <favouritesdb.h>        
    21 
    23 
    22 #include "mcsplugindata.h"
    24 #include "mcsplugindata.h"
    23 #include "mcspluginengine.h"
    25 #include "mcspluginengine.h"
    24 
    26 
    25 using namespace HSPluginSettingsIf;
    27 using namespace HSPluginSettingsIf;
    26 
    28 
    27 _LIT8( KAppUid, "271012080" );
       
    28 _LIT( KMenuAttrParam, "param" );
    29 _LIT( KMenuAttrParam, "param" );
    29 _LIT( KMenuAttrLocked, "locked" );
    30 _LIT( KMenuAttrLocked, "locked" );
    30 _LIT8( KProperNameType, "type" );
    31 _LIT8( KProperNameType, "type" );
    31 _LIT8( KProperNameParam, "param" );
    32 _LIT8( KProperNameParam, "param" );
    32 _LIT8( KProperNameUid, "uid" );
    33 _LIT8( KProperNameUid, "uid" );
    33 _LIT8( KProperNameView, "view" );
    34 _LIT8( KProperNameView, "view" );
    34 _LIT8( KProperValueFolder, "folder" );
    35 _LIT8( KProperValueFolder, "folder" );
    35 _LIT8( KProperValueBookmark, "bookmark" );
    36 _LIT8( KProperValueBookmark, "bookmark" );
    36 _LIT8( KProperValueAppl, "application" );
    37 _LIT8( KProperValueAppl, "application" );
    37 
    38 
       
    39 _LIT( KUrl, "url" );
       
    40 _LIT( KMenuIconFile, "aimcsplugin.mif" );
       
    41 _LIT( KMenuIconId, "16386" );
       
    42 _LIT( KMenuMaskId, "16387" );
       
    43 _LIT( KInitialRefCount, "1" );
       
    44 _LIT( KMenuAttrRefcount, "ref_count" );
       
    45 _LIT( KMyMenuData, "matrixmenudata" );
       
    46 
       
    47 
    38 // ======== LOCAL FUNCTIONS ========
    48 // ======== LOCAL FUNCTIONS ========
    39 
    49 
    40 static void ItemMapArrayCleanupFunc( TAny* aPointerArray )
    50 static void ItemMapArrayCleanupFunc( TAny* aPointerArray )
    41     {
    51     {
    42     RPointerArray<CItemMap>* p = static_cast<RPointerArray<CItemMap>*>( aPointerArray ); 
    52     RPointerArray<CItemMap>* p = static_cast<RPointerArray<CItemMap>*>( aPointerArray ); 
    93 // Symbian 2nd phase constructor can leave
   103 // Symbian 2nd phase constructor can leave
    94 // ---------------------------------------------------------------------------
   104 // ---------------------------------------------------------------------------
    95 //
   105 //
    96 void CMCSPluginData::ConstructL()
   106 void CMCSPluginData::ConstructL()
    97     {
   107     {
    98      // AILaunch uid in decimal format
   108     iPluginSettings = CHomescreenSettings::Instance();
    99     iPluginSettings = CHomescreenSettings::NewL( KAppUid,
   109     if( iPluginSettings == NULL )
   100                                                  iInstanceUid,
   110         {
   101                                                  this );
   111         User::Leave( KErrUnknown );
       
   112         }
       
   113     iPluginSettings->AddObserverL( this );
       
   114 
       
   115     iSaveWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation );
       
   116 
       
   117     iMenu.OpenL( KMyMenuData );
       
   118 
   102     UpdateDataL();
   119     UpdateDataL();
   103     }
   120     }
   104 
   121 
   105 // ---------------------------------------------------------------------------
   122 // ---------------------------------------------------------------------------
   106 // Destructor
   123 // Destructor
   107 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   108 //
   125 //
   109 CMCSPluginData::~CMCSPluginData()
   126 CMCSPluginData::~CMCSPluginData()
   110     {   
   127     {
       
   128     if( iPluginSettings )
       
   129         {
       
   130         iPluginSettings->RemoveObserver( this );
       
   131         }
       
   132 
   111     iData.Close();
   133     iData.Close();
   112     delete iPluginSettings;
   134     iMenu.Close();
       
   135 
       
   136     delete iSaveWatcher;
   113     }
   137     }
   114 
   138 
   115 // ---------------------------------------------------------------------------
   139 // ---------------------------------------------------------------------------
   116 // Gets the instance specific settings from HSPS and creates data items
   140 // Gets the instance specific settings from HSPS and creates data items
   117 // ---------------------------------------------------------------------------
   141 // ---------------------------------------------------------------------------
   165 
   189 
   166 // ---------------------------------------------------------------------------
   190 // ---------------------------------------------------------------------------
   167 // 
   191 // 
   168 // ---------------------------------------------------------------------------
   192 // ---------------------------------------------------------------------------
   169 //
   193 //
   170 TInt CMCSPluginData::SettingsChangedL( const TDesC8& /*aEvent*/,  const TDesC8& /*aPluginName*/,
   194 void CMCSPluginData::SettingsChangedL( const TDesC8& /*aEvent*/,  const TDesC8& /*aPluginName*/,
   171                            const TDesC8& /*aPluginUid*/, const TDesC8& /*aPluginId*/ )
   195                            const TDesC8& /*aPluginUid*/, const TDesC8& aPluginId )
   172     {
   196     {
   173     UpdateDataL();
   197     if( aPluginId.CompareF( iInstanceUid ) == 0 )
   174     return KErrNone;
   198         {
       
   199         UpdateDataL();
       
   200         }   
   175     }
   201     }
   176 
   202 
   177 // ---------------------------------------------------------------------------
   203 // ---------------------------------------------------------------------------
   178 // Gets the menu item from engine using the setting properties as filter
   204 // Gets the menu item from engine using the setting properties as filter
   179 // ---------------------------------------------------------------------------
   205 // ---------------------------------------------------------------------------
   361                     properties[i]->SetValueL( KNullDesC8 );
   387                     properties[i]->SetValueL( KNullDesC8 );
   362                     }
   388                     }
   363                 }
   389                 }
   364             }
   390             }
   365         }
   391         }
   366 		// ETrue tells that changes are stored also to plugin reference 
   392     // ETrue tells that changes are stored also to plugin reference 
   367     iPluginSettings->SetSettingsL( iInstanceUid, settingItems, ETrue );
   393     iPluginSettings->SetSettingsL( iInstanceUid, settingItems, ETrue );
   368     CleanupStack::PopAndDestroy( &settingItems );
   394     CleanupStack::PopAndDestroy( &settingItems );
   369     }
   395     }
   370 
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // Gets MCS Plugin folder ID. This hidden folder in matrixmenudata.xml is used 
       
   399 // for storing run-time generated menuitems
       
   400 // ---------------------------------------------------------------------------
       
   401 //
       
   402 TInt CMCSPluginData::GetMCSPluginFolderIdL()
       
   403     {
       
   404     TInt folderId;
       
   405     
       
   406     _LIT( KMCSFolder, "mcsplugin_folder" );
       
   407 
       
   408     CMenuItem* item( NULL );
       
   409     CMenuFilter* filter = CMenuFilter::NewL();
       
   410     CleanupStack::PushL( filter );
       
   411     filter->SetType( KMenuTypeFolder );
       
   412     filter->HaveAttributeL( KMenuAttrLongName, KMCSFolder );
       
   413 
       
   414     const TInt rootId = iMenu.RootFolderL();
       
   415     RArray<TMenuItem> itemArray;
       
   416     CleanupClosePushL( itemArray );
       
   417     iMenu.GetItemsL( itemArray, rootId, filter, ETrue );
       
   418     if ( itemArray.Count() > 0 )
       
   419         {
       
   420         item = CMenuItem::OpenL( iMenu, itemArray[0] );
       
   421         folderId = item->Id();
       
   422         }
       
   423     else 
       
   424         {
       
   425         folderId = iMenu.RootFolderL();
       
   426         }
       
   427     CleanupStack::PopAndDestroy( &itemArray );
       
   428     CleanupStack::PopAndDestroy( filter ); 
       
   429 
       
   430     delete item; 
       
   431 
       
   432     return folderId;
       
   433     }
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // Creates bookmark menu item if it does not exist
       
   437 // ---------------------------------------------------------------------------
       
   438 //
       
   439 void CMCSPluginData::CreateBkmMenuItemsL()
       
   440     {
       
   441     RPointerArray<CItemMap> settings;
       
   442     TCleanupItem settingsCleanupItem( ItemMapArrayCleanupFunc, &settings );
       
   443     CleanupStack::PushL( settingsCleanupItem );
       
   444     iPluginSettings->GetSettingsL( iInstanceUid, settings );
       
   445 
       
   446     RFavouritesSession bookmarkSess;
       
   447     RFavouritesDb bookmarkDb;
       
   448 
       
   449     User::LeaveIfError( bookmarkSess.Connect() );
       
   450     User::LeaveIfError( bookmarkDb.Open( bookmarkSess, KBrowserBookmarks ));
       
   451 
       
   452     TInt count = settings.Count();
       
   453     for( TInt i = 0; i < count; i++ )
       
   454        {
       
   455         CItemMap* itemMap = settings[i];
       
   456         RPointerArray<HSPluginSettingsIf::CPropertyMap>& properties
       
   457             = itemMap->Properties();
       
   458 
       
   459         TPtrC8 uid8, type;
       
   460 
       
   461         for( TInt j = 0; j < properties.Count(); j++ )
       
   462             {
       
   463 
       
   464             if( properties[j]->Name() == KProperNameType )
       
   465                 {
       
   466                 type.Set( properties[j]->Value() );
       
   467                 }
       
   468             else if ( properties[j]->Name() == KProperNameUid )
       
   469                 {
       
   470                 uid8.Set( properties[j]->Value() );
       
   471                 }
       
   472             }
       
   473 
       
   474         if( type == KProperValueBookmark )
       
   475             {
       
   476             TMenuItem menuItem = CreateMenuItemL( properties );
       
   477 
       
   478             CActiveSchedulerWait* wait = 
       
   479                             new ( ELeave ) CActiveSchedulerWait;
       
   480             CleanupStack::PushL( wait );
       
   481             
       
   482             if( menuItem.Id() == 0 )
       
   483                 {
       
   484                 TLex8 uidLex( uid8.Mid( 1, uid8.Length() - 2 ) );
       
   485                 TUint32 id;
       
   486                 uidLex.Val(id, EHex);
       
   487 
       
   488                 CFavouritesItem* bkmItem = CFavouritesItem::NewLC();
       
   489                 TInt bcount = bookmarkDb.Get( TInt32( id ), *bkmItem );
       
   490 
       
   491                 HBufC *uid( NULL );
       
   492                 uid = AiUtility::CopyToBufferL( uid, uid8 );
       
   493                 CleanupStack::PushL( uid );
       
   494 
       
   495                 CMenuItem* newItem = CMenuItem::CreateL( iMenu, 
       
   496                                                          KMenuTypeUrl, 
       
   497                                                          GetMCSPluginFolderIdL(),
       
   498                                                          0 );
       
   499                 CleanupStack::PushL( newItem );
       
   500 
       
   501                 newItem->SetAttributeL( KMenuAttrUid, *uid );
       
   502                 newItem->SetAttributeL( KMenuAttrLongName, bkmItem->Name() );
       
   503                 newItem->SetAttributeL( KMenuAttrIconFile, KMenuIconFile );
       
   504                 newItem->SetAttributeL( KMenuAttrIconId, KMenuIconId );
       
   505                 newItem->SetAttributeL( KMenuAttrMaskId, KMenuMaskId );
       
   506                 newItem->SetAttributeL( KMenuAttrRefcount, KInitialRefCount );
       
   507                 newItem->SetAttributeL( KUrl , bkmItem->Url() );
       
   508 
       
   509                 CMenuOperation* op = newItem->SaveL( iSaveWatcher->iStatus );
       
   510                 TInt newId = newItem->Id();
       
   511                 iData[i].MenuItem().SetId( newId );
       
   512 
       
   513                 iSaveWatcher->StopAndWatch( op, wait );
       
   514 
       
   515                 // Start the nested scheduler loop.
       
   516                 wait->Start();
       
   517 
       
   518                 CleanupStack::Pop( newItem );
       
   519                 CleanupStack::PopAndDestroy( uid );
       
   520                 CleanupStack::PopAndDestroy( bkmItem );
       
   521                 }
       
   522             else
       
   523                 {
       
   524                 CMenuItem* item = CMenuItem::OpenL( iMenu, menuItem );
       
   525 
       
   526                 if( iEngine.UpdateMenuItemsRefCountL( item, 1 ) > 0 )
       
   527                     {
       
   528                     CMenuOperation* op = item->SaveL( iSaveWatcher->iStatus );
       
   529                     iSaveWatcher->StopAndWatch( op, wait );
       
   530                     // Start the nested scheduler loop.
       
   531                     wait->Start();
       
   532                     }
       
   533                 }
       
   534 
       
   535             CleanupStack::PopAndDestroy( wait );
       
   536             wait = NULL;
       
   537             }
       
   538         }
       
   539     CleanupStack::PopAndDestroy(); // settingsCleanupItem
       
   540     }