musichomescreen_multiview/musiccontentpublisher/src/musiccontentpublisher.cpp
branchRCL_3
changeset 17 c8156a91d13c
parent 2 b70d77332e66
child 18 c54d95799c80
equal deleted inserted replaced
15:171e07ac910f 17:c8156a91d13c
    35 #include "cpglobals.h" //This will be moved to domain API (HSFW)
    35 #include "cpglobals.h" //This will be moved to domain API (HSFW)
    36 #include "musiccontentpublisher.h"
    36 #include "musiccontentpublisher.h"
    37 #include "pluginmanager.h"
    37 #include "pluginmanager.h"
    38 #include "mcpharvesterpublisherobserver.h"
    38 #include "mcpharvesterpublisherobserver.h"
    39 
    39 
       
    40 // These extend macros in <mpxlog.h>
       
    41 
       
    42 #ifdef _DEBUG
       
    43 #define MPX_DEBUG2_8(cstr, p) RDebug::Printf(cstr, p)
       
    44 #else
       
    45 #define MPX_DEBUG2_8(cstr, p)
       
    46 #endif
       
    47 
    40 _LIT( KPubData,        "publisher" );
    48 _LIT( KPubData,        "publisher" );
    41 
       
    42 
    49 
    43 _LIT8( KMyActive, "active" );
    50 _LIT8( KMyActive, "active" );
    44 _LIT8( KMyDeActive, "deactive");
    51 _LIT8( KMyDeActive, "deactive");
    45 _LIT8( KMySuspend, "suspend");
    52 _LIT8( KMySuspend, "suspend");
    46 _LIT8( KMyResume, "resume");
    53 _LIT8( KMyResume, "resume");
    47 _LIT8( KMyActionMap, "action_map" );
    54 _LIT8( KMyActionMap, "action_map" );
    48 _LIT8( KMyItem, "item" );
    55 _LIT8( KMyItem, "item" );
    49 _LIT8( KMyAdd, "Add" );
    56 _LIT8( KMyAdd, "Add" );
       
    57 _LIT8( KMyMusic, "music");
    50 _LIT8( KMyItemId, "item_id" );
    58 _LIT8( KMyItemId, "item_id" );
    51 _LIT( KMyActionName, "data" );
    59 _LIT( KMyActionName, "data" );
    52 
    60 
    53 _LIT( KEmpty, "" );
    61 _LIT( KEmpty, "" );
    54 _LIT( KLoc, "LOC:");
    62 
    55 _LIT( KWildCard, "*");
       
    56 
       
    57 _LIT( KNowPlaying, "LOC:NOW PLAYING" );
       
    58 _LIT( KLastPlayed, "LOC:LAST PLAYED" );
       
    59 _LIT( KMask, "_mask");
       
    60 _LIT( KMWPublisher, "MWPublisher");
    63 _LIT( KMWPublisher, "MWPublisher");
    61 _LIT( KactionMessageToMusicPlayer, "MessageToMusicPlayer" );
    64 _LIT( KactionMessageToMusicPlayer, "MessageToMusicPlayer" );
    62 _LIT( KGoToAlbumView, "GoToAlbumView" );
    65 _LIT( KGoToAlbumView, "GoToAlbumView" );
    63 _LIT8( KMessage, "message" );
    66 _LIT8( KMessage, "message" );
    64 
    67 
    72 
    75 
    73 _LIT( KResourceFile, "z:musichomescreen.rsc");
    76 _LIT( KResourceFile, "z:musichomescreen.rsc");
    74 
    77 
    75 // ======== MEMBER FUNCTIONS ========
    78 // ======== MEMBER FUNCTIONS ========
    76 
    79 
       
    80 CMusicContentPublisher::TDestinationItem::TDestinationItem(const TMCPDestinationItem& aItem):
       
    81     iType( reinterpret_cast<const TUint16*>(aItem.type) ),
       
    82     iDataKey ( reinterpret_cast<const TUint8*>(aItem.dataKey ) ),
       
    83     iMaskKey ( reinterpret_cast<const TUint8*>(aItem.maskKey ) )
       
    84     {}
       
    85 
       
    86 
    77 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    78 // Constructor
    88 // Constructor
    79 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
    80 //
    90 //
    81 CMusicContentPublisher::CMusicContentPublisher( MLiwInterface* aCPSInterface ):
    91 CMusicContentPublisher::CMusicContentPublisher( MLiwInterface* aCPSInterface ):
    93     //Load the destination translation table.
   103     //Load the destination translation table.
    94     TInt dstl (sizeof(KMCPDestinationInfo)/sizeof(TMCPDestinationItem));
   104     TInt dstl (sizeof(KMCPDestinationInfo)/sizeof(TMCPDestinationItem));
    95     for (TInt i = 0; i < dstl; i++)
   105     for (TInt i = 0; i < dstl; i++)
    96         {
   106         {
    97         iDestinationMap.InsertL(KMCPDestinationInfo[i].id, 
   107         iDestinationMap.InsertL(KMCPDestinationInfo[i].id, 
    98                 KMCPDestinationInfo[i]);
   108                                 TDestinationItem(KMCPDestinationInfo[i]));
    99         }
   109         }
   100     
   110     
   101     dstl = (sizeof(KMCPImageDestinationInfo)/sizeof(
   111     dstl = (sizeof(KMCPImageDestinationInfo)/sizeof(
   102             TMCPImageDestinationInfoItem));
   112             TMCPImageDestinationInfoItem));
   103     for (TInt i = 0; i < dstl; i++)
   113     for (TInt i = 0; i < dstl; i++)
   129         }
   139         }
   130     RResourceFile resourceFile;
   140     RResourceFile resourceFile;
   131     resourceFile.OpenL(fs,fileName);
   141     resourceFile.OpenL(fs,fileName);
   132     CleanupClosePushL(resourceFile);
   142     CleanupClosePushL(resourceFile);
   133     resourceFile.ConfirmSignatureL();
   143     resourceFile.ConfirmSignatureL();
   134     GetLocalizedStringL(resourceFile, iLastPlayedBuffer, R_MUSICHOMESCREEN_LAST_PLAYED);
       
   135     GetLocalizedStringL(resourceFile, iNowPlayingBuffer, R_MUSICHOMESCREEN_NOW_PLAYING);
       
   136     GetLocalizedStringL(resourceFile, iGoToMusicBuffer, R_MUSICHOMESCREEN_GO_TO_MUSIC);
   144     GetLocalizedStringL(resourceFile, iGoToMusicBuffer, R_MUSICHOMESCREEN_GO_TO_MUSIC);
   137     CleanupStack::PopAndDestroy(&resourceFile);
   145     CleanupStack::PopAndDestroy(&resourceFile);
   138     CleanupStack::PopAndDestroy(&fs);
   146     CleanupStack::PopAndDestroy(&fs);
   139     MPX_DEBUG1("CMusicContentPublisher::ConstructL resources loaded");
   147     MPX_DEBUG1("CMusicContentPublisher::ConstructL resources loaded");
   140     
   148     
   141     // connect to the skin server, to receive skin changed event.
   149     // connect to the skin server, to receive skin changed event.
   142     iAknsSrvSession.Connect(this);
   150     iAknsSrvSession.Connect(this);
   143     
   151     
   144     // enable skin.
   152     // enable skin.
   145     AknsUtils::InitSkinSupportL();
   153     AknsUtils::InitSkinSupportL();
       
   154     	
       
   155     iDeferredPublish = new (ELeave) CAsyncCallBack(TCallBack(DoPublish, this), 
       
   156                                                    CActive::EPriorityLow);
   146 
   157 
   147     MPX_DEBUG1("CMusicContentPublisher::ConstructL subscribing to observer");
   158     MPX_DEBUG1("CMusicContentPublisher::ConstructL subscribing to observer");
   148  
   159  
   149     TUint id = RegisterPublisherL( 
   160     TUint id = RegisterPublisherL( 
   150             KMWPublisher,
   161             KMWPublisher,
   151             KAll, 
   162             KAll, 
   152             KAll );
   163             KAll );
   153         
   164         
   154     if( id != 0 )
   165     if( id != 0 )
   155         {
   166         {
   156     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
   167         CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
   157 
   168 
   158     filter->InsertL( KPublisherId, TLiwVariant( KMWPublisher ) );
   169         filter->InsertL( KPublisherId, TLiwVariant( KMWPublisher ) );
   159     filter->InsertL( KContentId, TLiwVariant( KAll) );
   170         filter->InsertL( KContentId, TLiwVariant( KAll) );
   160     filter->InsertL( KContentType, TLiwVariant( KAll ) );
   171         filter->InsertL( KContentType, TLiwVariant( KAll ) );
   161 
   172 
   162     iHPObserver = CMCPHarvesterPublisherObserver::NewL(this);
   173         iHPObserver = CMCPHarvesterPublisherObserver::NewL(this);
   163     iHPObserver->RegisterL(filter);
   174         iHPObserver->RegisterL(filter);
   164     CleanupStack::PopAndDestroy(filter);
   175         CleanupStack::PopAndDestroy(filter);
   165         }
   176         }
   166     //Reset the music menu info
   177     
   167     InstallEmptyActionL(EMusicMenuMusicInfoTrigger);
   178     MPX_DEBUG1("CMusicContentPublisher::ConstructL initializing content");
   168     PublishTextL( NULL, EMusicMenuMusicInfoLine1, iLastPlayedBuffer->Des() );
   179     PublishDefaultL();
   169     PublishTextL( NULL, EMusicMenuMusicInfoLine2, KEmpty );
       
   170     PublishImageL( NULL, EMusicMenuMusicInfoImage1, KEmpty );
       
   171     
   180     
   172     MPX_DEBUG1("CMusicContentPublisher::ConstructL --->");
   181     MPX_DEBUG1("CMusicContentPublisher::ConstructL --->");
   173     }
   182     }
   174 
   183 
   175 // ---------------------------------------------------------------------------
   184 // ---------------------------------------------------------------------------
   193 //
   202 //
   194 CMusicContentPublisher::~CMusicContentPublisher()
   203 CMusicContentPublisher::~CMusicContentPublisher()
   195     {
   204     {
   196     
   205     
   197     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher <---");
   206     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher <---");
       
   207     delete iDeferredPublish;
   198     if(iHPObserver)
   208     if(iHPObserver)
   199         {
   209         {
   200         MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher deleting observer");
   210         MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher deleting observer");
   201         delete iHPObserver; 
   211         delete iHPObserver; 
   202         }
   212         }
   203     delete iNowPlayingBuffer;
       
   204     delete iLastPlayedBuffer;
       
   205     delete iGoToMusicBuffer;
   213     delete iGoToMusicBuffer;
   206     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher closing destination maps");
   214     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher closing destination maps");
   207     iImageDestinationSizeMap.Close();
   215     iImageDestinationSizeMap.Close();
   208     iDestinationMap.Close();
   216     iDestinationMap.Close();
   209     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher resetting bitmap cache");
   217     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher resetting bitmap cache");
   210     ResetBitmapCache();
   218     ResetBitmapCache();
   211     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher closing skin server session");
   219     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher closing skin server session");
   212     iAknsSrvSession.Close();
   220     iAknsSrvSession.Close();
   213     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher deleting plugin manager");
   221     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher deleting plugin manager");
   214     delete iPluginManager;
   222     delete iPluginManager;
   215     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher resetting publishing buffers");
   223     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher resetting publishing maps");
   216     ResetPublishingBuffers();
   224     iPublishingDataMap.Close();
       
   225     iPublishingActionMap.Close();
   217     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher --->");
   226     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher --->");
   218     if ( iInstanceId )
   227     if ( iInstanceId )
   219     	{
   228     	{
   220     	delete iInstanceId;
   229     	delete iInstanceId;
   221     	}
   230     	}
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // 
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CMusicContentPublisher::PublishDefaultL()
       
   238     {
       
   239     MPX_FUNC("CMusicContentPublisher::PublishDefaultL");
       
   240     PublishImageL(NULL,EMusicWidgetImage1,KEmpty);
       
   241     InstallGoToAlbumL( EMusicWidgetTrigger1 );
       
   242     PublishTextL( NULL,EMusicWidgetDefaultText, *iGoToMusicBuffer );
       
   243     PublishTextL( NULL,EMusicWidgetText1, KEmpty );
       
   244     PublishImageL(NULL,EMusicWidgetToolbarB1,KEmpty);
       
   245     PublishImageL(NULL,EMusicWidgetToolbarB2,KEmpty);
       
   246     PublishImageL(NULL,EMusicWidgetToolbarB3,KEmpty);
       
   247     InstallEmptyActionL(EMusicWidgetTB1Trigger);
       
   248     InstallEmptyActionL(EMusicWidgetTB2Trigger);
       
   249     InstallEmptyActionL(EMusicWidgetTB3Trigger);
       
   250     InstallGoToAlbumL( EMusicWidgetTrigger2 );
   222     }
   251     }
   223 
   252 
   224 // ---------------------------------------------------------------------------
   253 // ---------------------------------------------------------------------------
   225 // 
   254 // 
   226 // ---------------------------------------------------------------------------
   255 // ---------------------------------------------------------------------------
   284     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
   313     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
   285     PublishActionL( NULL, aDestination, mapTrigger );
   314     PublishActionL( NULL, aDestination, mapTrigger );
   286     CleanupStack::PopAndDestroy( mapTrigger );
   315     CleanupStack::PopAndDestroy( mapTrigger );
   287     MPX_DEBUG1("CMusicContentPublisher::InstallEmptyActionL --->");
   316     MPX_DEBUG1("CMusicContentPublisher::InstallEmptyActionL --->");
   288     }
   317     }
   289 // ---------------------------------------------------------------------------
       
   290 // 
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CMusicContentPublisher::MapEnumToDestinationInfoL(TInt aEnum,
       
   294         TPtrC& aType, TPtrC8& aDataKey, TPtrC& aContent)
       
   295     {
       
   296     MPX_DEBUG1("CMusicContentPublisher::MapEnumToDestinationInfoL <---");
       
   297     TMCPDestinationItem* tmpdstitemp;
       
   298     tmpdstitemp = iDestinationMap.Find(aEnum);
       
   299     
       
   300     if (tmpdstitemp)
       
   301         {
       
   302         TPtrC type ( reinterpret_cast<const TUint16*>(
       
   303                 tmpdstitemp->type) );
       
   304         TPtrC8 dataKey ( reinterpret_cast<const TUint8*>(
       
   305                 tmpdstitemp->dataKey ) );
       
   306         TPtrC content ( reinterpret_cast<const TUint16*>(
       
   307                 tmpdstitemp->content) );
       
   308 
       
   309         aType.Set(type);
       
   310         aDataKey.Set(dataKey);
       
   311 
       
   312         if ( !content.Compare( KWildCard ) )
       
   313             {
       
   314             aContent.Set(iInstanceId ? iInstanceId->Des(): KNullDesC() );
       
   315             }
       
   316         else
       
   317             {
       
   318             aContent.Set(content);
       
   319             }
       
   320         }
       
   321     else
       
   322         {
       
   323         //API user provided an invalid destination or the destination is not
       
   324         //defined properly.
       
   325         __ASSERT_DEBUG(EFalse,User::Invariant());
       
   326         }
       
   327     MPX_DEBUG1("CMusicContentPublisher::MapEnumToDestinationInfoL --->");
       
   328     }
       
   329 
   318 
   330 // ----------------------------------------------------------------------------
   319 // ----------------------------------------------------------------------------
   331 // Get a heap descriptor from the resource file
   320 // Get a heap descriptor from the resource file
   332 // ----------------------------------------------------------------------------
   321 // ----------------------------------------------------------------------------
   333 //
   322 //
   342    CleanupStack::PopAndDestroy(dataBuffer);
   331    CleanupStack::PopAndDestroy(dataBuffer);
   343    MPX_DEBUG1("CMusicContentPublisher::GetLocalizedStringL --->");
   332    MPX_DEBUG1("CMusicContentPublisher::GetLocalizedStringL --->");
   344    }
   333    }
   345 
   334 
   346 // ----------------------------------------------------------------------------
   335 // ----------------------------------------------------------------------------
   347 // Publishes buffered data and actions.
   336 // Trigger deferred publishing through an active object
   348 // ----------------------------------------------------------------------------
   337 // ----------------------------------------------------------------------------
   349 //
   338 //
   350 void CMusicContentPublisher::DoPublishL()
   339 void CMusicContentPublisher::PublishDeferred()
   351     {
   340     {
   352     MPX_DEBUG1("CMusicContentPublisher::DoPublishL <---");
   341     MPX_FUNC("CMusicContentPublisher::PublishDeferred");
   353     THashMapIter<TInt, TMyBufferItem> dataIter( iPublishingDataBuffers );
   342     if ( iWidgetForeground )
   354     MPX_DEBUG1("CMusicContentPublisher::DoPublishL publishing data");
   343         {
   355     
   344         iDeferredPublish->CallBack();
   356     TMyBufferItem const* itemptr;
   345         }
   357     itemptr = dataIter.NextValue();
   346     }
   358     while (itemptr)
   347 
   359         {
   348 // ----------------------------------------------------------------------------
   360         CLiwGenericParamList* inParam = CLiwGenericParamList::NewLC();
   349 // Run deferred publishing
   361         CLiwGenericParamList* outParam = CLiwGenericParamList::NewLC();
   350 // ----------------------------------------------------------------------------
   362         
   351 //
   363         TPtrC8 dataKey;
   352  TInt CMusicContentPublisher::DoPublish(TAny * aMusicContentPublisher)
   364         TPtrC type;
   353     {
   365         TPtrC content;
   354     MPX_FUNC("CMusicContentPublisher::DoPublish");
   366         MapEnumToDestinationInfoL(*dataIter.CurrentKey(), type, dataKey, content);
   355     CMusicContentPublisher * self = static_cast<CMusicContentPublisher*>(aMusicContentPublisher);
   367         
   356     if ( self->iWidgetForeground )
   368         TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
   357         {
   369         inParam->AppendL( cptype );
   358         TRAPD(err, self->DoPublishModifiedL());
   370         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC( );
   359         if (err != KErrNone)
   371         
   360             {
   372         
   361             MPX_DEBUG2("CMusicContentPublisher::DoPublish failed, err=%d", err);
   373         RMemReadStream rs( itemptr->buf, itemptr->size );
   362             }
   374         CLiwDefaultMap* map = CLiwDefaultMap::NewLC( rs );
   363         }    
   375          
   364     return KErrNone;
   376         cpdatamap->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
   365     }
   377         cpdatamap->InsertL( KContentType , TLiwVariant( type ) );
   366      
   378         cpdatamap->InsertL( KContentId  , TLiwVariant( content ) );
   367 // ----------------------------------------------------------------------------
   379         cpdatamap->InsertL( KDataMap  , TLiwVariant( map ) );
   368 // Publish all content
   380     
   369 // ----------------------------------------------------------------------------
   381         TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ) ); 
   370 //
   382         inParam->AppendL( item );
   371 void CMusicContentPublisher::DoPublishAllL()
   383  
   372     {
   384         iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
   373     MPX_FUNC("CMusicContentPublisher::DoPublishAllL");
   385         CleanupStack::PopAndDestroy( map );
   374     if (iCPSInterface && iInstanceId)
   386         CleanupStack::PopAndDestroy( cpdatamap );
   375         {
   387         CleanupStack::PopAndDestroy( outParam );
   376         CLiwMap * datamap = iPublishingDataMap.GetAllLC();
   388         CleanupStack::PopAndDestroy( inParam );
   377         CLiwMap * actionmap = iPublishingActionMap.GetAllLC();
   389         
   378 
   390         itemptr = dataIter.NextValue();
   379         CLiwDefaultMap * cpdata = CLiwDefaultMap::NewLC( );
   391         }
   380         cpdata->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
   392         
   381         cpdata->InsertL( KContentType , TLiwVariant( KMyMusic ) );
   393     //The order in wich we publish is important, actions should be published after the data contents.
   382         cpdata->InsertL( KContentId  , TLiwVariant( iInstanceId ) );
   394     THashMapIter<TInt, TMyBufferItem> actionIter( iPublishingActionBuffers );
   383         cpdata->InsertL( KDataMap  , TLiwVariant( datamap ) );
   395     MPX_DEBUG1("CMusicContentPublisher::DoPublishL publishing actions");
   384         cpdata->InsertL( KActionMap  , TLiwVariant( actionmap ) );
   396     
   385 
   397     itemptr = NULL;
   386         MPX_DEBUG2("CMusicContentPublisher::DoPublishAllL Add in %S", iInstanceId);
   398     itemptr = actionIter.NextValue();
   387         DoPublishCmdL( KAdd, KItem, cpdata );
   399     while (itemptr)
   388         
   400         {
   389         CleanupStack::PopAndDestroy( cpdata );
   401         CLiwGenericParamList* inParam = CLiwGenericParamList::NewLC();
   390         CleanupStack::PopAndDestroy( actionmap );
   402         CLiwGenericParamList* outParam = CLiwGenericParamList::NewLC();
   391         CleanupStack::PopAndDestroy( datamap );
   403         
   392         }
   404         TPtrC8 dataKey;
   393     }
   405         TPtrC type;
   394 
   406         TPtrC content;
   395 // ----------------------------------------------------------------------------
   407         MapEnumToDestinationInfoL( *actionIter.CurrentKey(), type, dataKey, content );
   396 // Publish modified content
   408         
   397 // ----------------------------------------------------------------------------
   409         TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
   398 //
   410         inParam->AppendL( cptype );
   399 void CMusicContentPublisher::DoPublishModifiedL()
   411         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC( );
   400     {
   412         
   401     MPX_FUNC("CMusicContentPublisher::DoPublishModifiedL");
   413         
   402     if (iCPSInterface && iInstanceId )
   414         RMemReadStream rs( itemptr->buf, itemptr->size );
   403         {
   415         CLiwDefaultMap* map = CLiwDefaultMap::NewLC( rs );
   404         CLiwMap * datamap = iPublishingDataMap.GetModifiedLC();
   416          
   405         // Must re-publish all actions even if only one of them has changed,
   417         cpdatamap->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
   406         // otherwise non-modified actions won't work any more
   418         cpdatamap->InsertL( KContentType , TLiwVariant( type ) );
   407         CLiwMap * actionmap = NULL;
   419         cpdatamap->InsertL( KContentId  , TLiwVariant( content ) );
   408         if ( iPublishingActionMap.IsModified() )
   420         cpdatamap->InsertL( KMyActionMap  , TLiwVariant( map ) );
   409             {
   421     
   410             actionmap = iPublishingActionMap.GetAllLC();
   422         TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ) ); 
   411             }
   423         inParam->AppendL( item );
   412         if ( datamap || actionmap )
   424  
   413             {
   425         iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
   414             CLiwMap * cpdata = CLiwDefaultMap::NewLC( );
   426         CleanupStack::PopAndDestroy( map );
   415             cpdata->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
   427         CleanupStack::PopAndDestroy( cpdatamap );
   416             cpdata->InsertL( KContentType , TLiwVariant( KMyMusic ) );
   428         CleanupStack::PopAndDestroy( outParam );
   417             cpdata->InsertL( KContentId  , TLiwVariant( iInstanceId ) );
   429         CleanupStack::PopAndDestroy( inParam );
   418             if ( datamap && datamap->Count() )
   430         
   419                 {
   431         itemptr = actionIter.NextValue();
   420                 cpdata->InsertL( KDataMap  , TLiwVariant( datamap ) );
   432         }
   421                 }
   433     MPX_DEBUG1("CMusicContentPublisher::CMusicContentPublisher::DoPublishL --->");
   422             if ( actionmap && actionmap->Count() )
   434     }
   423                 {
   435 
   424                 cpdata->InsertL( KActionMap  , TLiwVariant( actionmap ) );
       
   425                 }
       
   426 
       
   427             MPX_DEBUG2("CMusicContentPublisher::DoPublishModifiedL Add in %S", iInstanceId);
       
   428             DoPublishCmdL( KAdd, KItem, cpdata );
       
   429         
       
   430             CleanupStack::PopAndDestroy( cpdata );
       
   431             }
       
   432         if (actionmap)
       
   433             {
       
   434             CleanupStack::PopAndDestroy( actionmap );
       
   435             }
       
   436         if (datamap)
       
   437             {
       
   438             CleanupStack::PopAndDestroy( datamap );
       
   439             }
       
   440         }
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // Remove all content
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 void CMusicContentPublisher::DoPublishDeleteAllL()
       
   448     {
       
   449     MPX_FUNC("CMusicContentPublisher::DoPublishDeleteAllL");
       
   450     if( iCPSInterface && iInstanceId)
       
   451         {
       
   452         CLiwDefaultMap * cpdata = CLiwDefaultMap::NewLC( );
       
   453         cpdata->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   454         cpdata->InsertL( KContentType , TLiwVariant( KAll ) );
       
   455         cpdata->InsertL( KContentId  , TLiwVariant( iInstanceId ) );
       
   456 
       
   457         MPX_DEBUG2("CMusicContentPublisher::DoPublishDeleteAllL Delete All in %S", iInstanceId);
       
   458         DoPublishCmdL( KDelete, KFilter, cpdata );
       
   459 
       
   460         CleanupStack::PopAndDestroy( cpdata );
       
   461         }  
       
   462     }
       
   463     
       
   464 // ---------------------------------------------------------------------------
       
   465 // Execute a CMD to iCPSInterface
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 void CMusicContentPublisher::DoPublishCmdL(const TDesC8& aCmd, 
       
   469 	                                         const TDesC8& aKey, 
       
   470 	                                         const CLiwMap * aValue)
       
   471     {
       
   472     MPX_FUNC("CMusicContentPublisher::DoPublishCmdL");
       
   473     CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC();
       
   474     TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
       
   475     inParam->AppendL( cptype );
       
   476     TLiwGenericParam item( aKey, TLiwVariant( aValue ) ); 
       
   477     inParam->AppendL( item );
       
   478 
       
   479     CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC();
       
   480 
       
   481     iCPSInterface->ExecuteCmdL( aCmd , *inParam, *outParam);
       
   482 
       
   483     CleanupStack::PopAndDestroy( outParam );
       
   484     CleanupStack::PopAndDestroy( inParam );
       
   485     }
       
   486     
   436 // ---------------------------------------------------------------------------
   487 // ---------------------------------------------------------------------------
   437 // Resets all the graphical elements.
   488 // Resets all the graphical elements.
   438 // ---------------------------------------------------------------------------
   489 // ---------------------------------------------------------------------------
   439 //
   490 //
   440 void CMusicContentPublisher::ResetL()
   491 void CMusicContentPublisher::ResetL()
   441     {
   492     {
   442     MPX_DEBUG1("CMusicContentPublisher::ResetL <---");
   493     MPX_DEBUG1("CMusicContentPublisher::ResetL <---");
   443     //Plugin deletion is handled by the pluginmanager.
   494     //Plugin deletion is handled by the pluginmanager.
   444     iActivePlugin = NULL;
   495     iActivePlugin = NULL;
   445     //Reset The Widget
   496     //Reset The Widget
   446     PublishImageL(NULL,EMusicWidgetImage1,KEmpty);
   497     PublishDefaultL();
   447     InstallGoToAlbumL(EMusicWidgetTrigger1);
       
   448     PublishTextL( NULL,EMusicWidgetText1, KEmpty );
       
   449     PublishImageL(NULL,EMusicWidgetToolbarB1,KEmpty);
       
   450     PublishImageL(NULL,EMusicWidgetToolbarB2,KEmpty);
       
   451     PublishImageL(NULL,EMusicWidgetToolbarB3,KEmpty);
       
   452     InstallEmptyActionL(EMusicWidgetTB1Trigger);
       
   453     InstallEmptyActionL(EMusicWidgetTB2Trigger);
       
   454     InstallEmptyActionL(EMusicWidgetTB3Trigger);
       
   455     PublishTextL( NULL,EMusicWidgetDefaultText, iGoToMusicBuffer->Des() );  
       
   456     InstallGoToAlbumL(EMusicWidgetTrigger2);
       
   457 
       
   458     //Reset the music menu info
       
   459     InstallEmptyActionL(EMusicMenuMusicInfoTrigger);
       
   460     PublishTextL( NULL, EMusicMenuMusicInfoLine1, iLastPlayedBuffer->Des() );
       
   461     PublishTextL( NULL, EMusicMenuMusicInfoLine2, KEmpty );
       
   462     PublishImageL( NULL, EMusicMenuMusicInfoImage1, KEmpty );
       
   463     MPX_DEBUG1("CMusicContentPublisher::Reset --->");
   498     MPX_DEBUG1("CMusicContentPublisher::Reset --->");
   464     }
   499     }
   465 // ---------------------------------------------------------------------------
   500 // ---------------------------------------------------------------------------
   466 // 
   501 // 
   467 // ---------------------------------------------------------------------------
   502 // ---------------------------------------------------------------------------
   509     iBitmapCache.Close();
   544     iBitmapCache.Close();
   510     MPX_DEBUG1("CMusicContentPublisher::ResetBitmapCache --->");
   545     MPX_DEBUG1("CMusicContentPublisher::ResetBitmapCache --->");
   511     }
   546     }
   512     
   547     
   513 // ---------------------------------------------------------------------------
   548 // ---------------------------------------------------------------------------
   514 // Destroys the publishing buffers.
   549 // 
   515 // ---------------------------------------------------------------------------
   550 // ---------------------------------------------------------------------------
   516 //
   551 //
   517 void CMusicContentPublisher::ResetPublishingBuffers()
       
   518     {
       
   519     THashMapIter<TInt, TMyBufferItem> dataIter( iPublishingDataBuffers );
       
   520     THashMapIter<TInt, TMyBufferItem> actionIter( iPublishingActionBuffers );
       
   521     
       
   522     TMyBufferItem const* itemptr;
       
   523     itemptr = dataIter.NextValue();
       
   524     while (itemptr)
       
   525         {
       
   526         User::Free(itemptr->buf);
       
   527         dataIter.RemoveCurrent();
       
   528         itemptr = dataIter.NextValue();
       
   529         }
       
   530     iPublishingDataBuffers.Close();
       
   531     itemptr = NULL;
       
   532     itemptr = actionIter.NextValue();
       
   533     while (itemptr)
       
   534         {
       
   535         User::Free(itemptr->buf);
       
   536         actionIter.RemoveCurrent();
       
   537         itemptr = actionIter.NextValue();
       
   538         }
       
   539     iPublishingActionBuffers.Close();
       
   540     }
       
   541 
       
   542 TUint CMusicContentPublisher::RegisterPublisherL( 
   552 TUint CMusicContentPublisher::RegisterPublisherL( 
   543     const TDesC& aPublisherId, 
   553     const TDesC& aPublisherId, 
   544     const TDesC& aContentId,
   554     const TDesC& aContentId,
   545     const TDesC& aContentType )
   555     const TDesC& aContentType )
   546     {
   556     {
   603         }
   613         }
   604     MPX_DEBUG1("CMusicContentPublisher::ExtractItemId --->");
   614     MPX_DEBUG1("CMusicContentPublisher::ExtractItemId --->");
   605     return result;
   615     return result;
   606     }
   616     }
   607  
   617  
   608  // ---------------------------------------------------------------------------
       
   609 // removes CPS entry for the required destination
       
   610 // ---------------------------------------------------------------------------
       
   611 //
       
   612 void CMusicContentPublisher::RemoveL( TInt aDestination )
       
   613     {
       
   614     MPX_DEBUG1("CMusicContentPublisher::RemoveL <---");
       
   615     if( iCPSInterface )
       
   616         {
       
   617         CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC();
       
   618         CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC();
       
   619         TPtrC8 dataKey;
       
   620         TPtrC type;
       
   621         TPtrC content;
       
   622         MapEnumToDestinationInfoL(aDestination, type, dataKey, content);
       
   623         TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
       
   624         inParam->AppendL( cptype );
       
   625         CLiwDefaultMap * cpdatamap = CLiwDefaultMap::NewLC( );
       
   626         cpdatamap->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   627         cpdatamap->InsertL( KContentType , TLiwVariant( type ) );
       
   628         cpdatamap->InsertL( KContentId  , TLiwVariant( content ) );
       
   629         TLiwGenericParam item( KFilter, TLiwVariant( cpdatamap ) ); 
       
   630         inParam->AppendL( item );
       
   631         iCPSInterface->ExecuteCmdL( KDelete , *inParam, *outParam);
       
   632         CleanupStack::PopAndDestroy( cpdatamap );
       
   633         CleanupStack::PopAndDestroy( outParam );
       
   634         CleanupStack::PopAndDestroy( inParam );
       
   635         }  
       
   636     MPX_DEBUG1("CMusicContentPublisher::RemoveL --->");
       
   637     }
       
   638 
   618 
   639 // ---------------------------------------------------------------------------
   619 // ---------------------------------------------------------------------------
   640 // Publishes an image from path to the required destination
   620 // Publishes an image from path to the required destination
   641 // ---------------------------------------------------------------------------
   621 // ---------------------------------------------------------------------------
   642 //
   622 //
   643 void CMusicContentPublisher::PublishImageL( CMCPPlugin* aPlugin,  
   623 void CMusicContentPublisher::PublishImageL( CMCPPlugin* aPlugin,  
   644         TMCPImageDestination aDestination, 
   624         TMCPImageDestination aDestination, 
   645         const TDesC& aImagePath )
   625         const TDesC& aImagePath )
   646     {
   626     {
   647     MPX_DEBUG1("CMusicContentPublisher::PublishImageL <---");
   627     MPX_FUNC("CMusicContentPublisher::PublishImageL");
       
   628     if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   629         {
       
   630         MPX_DEBUG2("CMusicContentPublisher::PublishImageL deprecated aDestination=%d", aDestination);
       
   631         return;
       
   632         }
       
   633 
   648     if( iCPSInterface && iActivePlugin == aPlugin )
   634     if( iCPSInterface && iActivePlugin == aPlugin )
   649         {
   635         {
   650         CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC();
   636         TDestinationItem & destination (iDestinationMap.FindL( aDestination ));
   651         CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC();
   637         iPublishingDataMap.SetL( destination.iDataKey, aImagePath );
   652         
   638         iPublishingDataMap.Reset( destination.iMaskKey );
   653         TPtrC8 dataKey;
   639         PublishDeferred();
   654         TPtrC type;
   640         }
   655         TPtrC content;
       
   656         MapEnumToDestinationInfoL(aDestination, type, dataKey, content);
       
   657         
       
   658         TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
       
   659         inParam->AppendL( cptype );
       
   660         CLiwDefaultMap * cpdatamap = CLiwDefaultMap::NewLC( );
       
   661         CLiwDefaultMap * map = CLiwDefaultMap::NewLC( );
       
   662         
       
   663          
       
   664         map->InsertL(dataKey, TLiwVariant( aImagePath ) );
       
   665         
       
   666         cpdatamap->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   667         cpdatamap->InsertL( KContentType , TLiwVariant( type ) );
       
   668         cpdatamap->InsertL( KContentId  , TLiwVariant( content ) );
       
   669         cpdatamap->InsertL( KDataMap  , TLiwVariant( map ) );
       
   670     
       
   671         TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ) ); 
       
   672         inParam->AppendL( item );
       
   673         
       
   674         if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   675             {
       
   676             iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
       
   677             }
       
   678         else
       
   679             {
       
   680             if ( iWidgetForeground )
       
   681                 {
       
   682                 iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
       
   683                 }
       
   684             TMyBufferItem* ptr;
       
   685             ptr = iPublishingDataBuffers.Find(aDestination);
       
   686             if (ptr) //remove the old one
       
   687                 {
       
   688                 User::Free(ptr->buf);
       
   689                 iPublishingDataBuffers.Remove(aDestination);
       
   690                 }
       
   691             TInt sz = map->Size();
       
   692             TMyBufferItem bufferitem;
       
   693             bufferitem.size = map->Size();
       
   694             bufferitem.buf = User::AllocL(map->Size());
       
   695             RMemWriteStream ws(bufferitem.buf, bufferitem.size);
       
   696             map->ExternalizeL(ws);
       
   697             iPublishingDataBuffers.Insert(aDestination, bufferitem);
       
   698             }
       
   699         CleanupStack::PopAndDestroy( map );
       
   700         CleanupStack::PopAndDestroy( cpdatamap );
       
   701         CleanupStack::PopAndDestroy( outParam );
       
   702         CleanupStack::PopAndDestroy( inParam );
       
   703         }   
       
   704     MPX_DEBUG1("CMusicContentPublisher::PublishImageL --->");
       
   705     }
   641     }
   706 
   642 
   707 // ---------------------------------------------------------------------------
   643 // ---------------------------------------------------------------------------
   708 // Publishes an image from bitmap handle to the required destination
   644 // Publishes an image from bitmap handle to the required destination
   709 // ---------------------------------------------------------------------------
   645 // ---------------------------------------------------------------------------
   711 void CMusicContentPublisher::PublishImageL( CMCPPlugin* aPlugin, 
   647 void CMusicContentPublisher::PublishImageL( CMCPPlugin* aPlugin, 
   712         TMCPImageDestination aDestination,
   648         TMCPImageDestination aDestination,
   713         TInt aBitmapHandle,
   649         TInt aBitmapHandle,
   714         TInt aMaskBitmapHandle)
   650         TInt aMaskBitmapHandle)
   715     {
   651     {
   716     MPX_DEBUG1("CMusicContentPublisher::PublishImageL <---");
   652     MPX_FUNC("CMusicContentPublisher::PublishImageL");
       
   653     if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   654         {
       
   655         MPX_DEBUG2("CMusicContentPublisher::PublishImageL deprecated aDestination=%d", aDestination);
       
   656         return;
       
   657         }
   717     if( iCPSInterface && iActivePlugin == aPlugin )
   658     if( iCPSInterface && iActivePlugin == aPlugin )
   718         {
   659         {
   719         CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC();
   660         TDestinationItem & destination (iDestinationMap.FindL( aDestination ));
   720         CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC();
   661         
   721         
   662         iPublishingDataMap.SetL( destination.iDataKey, aBitmapHandle  );
   722         TPtrC8 dataKey;
       
   723         TPtrC type;
       
   724         TPtrC content;
       
   725         MapEnumToDestinationInfoL(aDestination, type, dataKey, content);
       
   726         
       
   727         TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
       
   728         inParam->AppendL( cptype );
       
   729         CLiwDefaultMap * cpdatamap = CLiwDefaultMap::NewLC( );
       
   730         CLiwDefaultMap * map = CLiwDefaultMap::NewLC( );
       
   731         
       
   732          
       
   733         if (aDestination == EMusicMenuMusicInfoImage1)
       
   734             {
       
   735             //Matrix Menu expects a Tint32 (TVariantTypeId::EVariantTypeTInt32)   
       
   736             map->InsertL(dataKey, TLiwVariant( TInt32( aBitmapHandle ) ) );
       
   737             }
       
   738         else 
       
   739             {
       
   740             //Homescreen expects a TBool/TInt 
       
   741             //(TVariantTypeId::EVariantTypeTBool)
       
   742             map->InsertL(dataKey, TLiwVariant( aBitmapHandle ) );
       
   743             }
       
   744         
   663         
   745         if (aMaskBitmapHandle)
   664         if (aMaskBitmapHandle)
   746             {
   665             {
   747             HBufC8* maskResult = HBufC8::NewLC( 
   666             iPublishingDataMap.SetL( destination.iMaskKey, aMaskBitmapHandle );
   748                     dataKey.Length() + KMask().Length() );
       
   749             TPtr8 maskResultPtr = maskResult->Des();
       
   750             maskResultPtr.Append( dataKey );
       
   751             maskResultPtr.Append( KMask );
       
   752             if (aDestination == EMusicMenuMusicInfoImage1)
       
   753                 {
       
   754                 //Matrix Menu expects a Tint32 (TVariantTypeId::EVariantTypeTInt32)   
       
   755                 map->InsertL(maskResultPtr, TLiwVariant( (TInt32)aMaskBitmapHandle ) );
       
   756                 }
       
   757             else 
       
   758                 {
       
   759                 //Homescreen expects a TBool/TInt 
       
   760                 //(TVariantTypeId::EVariantTypeTBool)
       
   761                 map->InsertL(maskResultPtr, TLiwVariant( aMaskBitmapHandle ) );
       
   762                 }
       
   763             CleanupStack::PopAndDestroy( maskResult );
       
   764             }
       
   765         
       
   766         cpdatamap->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   767         cpdatamap->InsertL( KContentType , TLiwVariant( type ) );
       
   768         cpdatamap->InsertL( KContentId  , TLiwVariant( content ) );
       
   769         cpdatamap->InsertL( KDataMap  , TLiwVariant( map ) );
       
   770     
       
   771         TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ) ); 
       
   772         inParam->AppendL( item );
       
   773         
       
   774         if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   775             {
       
   776             iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
       
   777             }
   667             }
   778         else
   668         else
   779             {
   669             {
   780             if ( iWidgetForeground )
   670             iPublishingDataMap.Reset( destination.iMaskKey );
   781                 {
   671             }
   782                 iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );  	
   672         PublishDeferred();
   783                 }
   673         }
   784             TMyBufferItem* ptr;
       
   785             ptr = iPublishingDataBuffers.Find(aDestination);
       
   786             if (ptr) //remove the old one
       
   787                 {
       
   788                 User::Free(ptr->buf);
       
   789                 iPublishingDataBuffers.Remove(aDestination);
       
   790                 }
       
   791             TInt sz = map->Size();
       
   792             TMyBufferItem bufferitem;
       
   793             bufferitem.size = map->Size();
       
   794             bufferitem.buf = User::AllocL(map->Size());
       
   795             RMemWriteStream ws(bufferitem.buf, bufferitem.size);
       
   796             map->ExternalizeL(ws);
       
   797             iPublishingDataBuffers.Insert(aDestination, bufferitem);
       
   798             }
       
   799         CleanupStack::PopAndDestroy( map );
       
   800         CleanupStack::PopAndDestroy( cpdatamap );
       
   801         CleanupStack::PopAndDestroy( outParam );
       
   802         CleanupStack::PopAndDestroy( inParam );
       
   803         }
       
   804     MPX_DEBUG1("CMusicContentPublisher::PublishImageL --->");
       
   805     }
   674     }
   806 
   675 
   807 // ---------------------------------------------------------------------------
   676 // ---------------------------------------------------------------------------
   808 // Publishes an image from skin id and mif to the required destination
   677 // Publishes an image from skin id and mif to the required destination
   809 // ---------------------------------------------------------------------------
   678 // ---------------------------------------------------------------------------
   813         const TAknsItemID& aID,
   682         const TAknsItemID& aID,
   814         const TDesC& aFilename,
   683         const TDesC& aFilename,
   815         const TInt aFileBitmapId,
   684         const TInt aFileBitmapId,
   816         const TInt aFileMaskId )
   685         const TInt aFileMaskId )
   817     {
   686     {
   818     MPX_DEBUG1("CMusicContentPublisher::PublishImageL <---");
   687     MPX_FUNC("CMusicContentPublisher::PublishImageL");
       
   688     if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   689         {
       
   690         MPX_DEBUG2("CMusicContentPublisher::PublishImageL deprecated aDestination=%d", aDestination);
       
   691         return;
       
   692         }
       
   693         
   819     TBmpMsk* bitmapandmask;
   694     TBmpMsk* bitmapandmask;
   820     bitmapandmask = iBitmapCache.Find(aID.iMajor+aID.iMinor);
   695     bitmapandmask = iBitmapCache.Find(aID.iMajor+aID.iMinor);
   821     CFbsBitmap* bitmap = NULL;
   696     CFbsBitmap* bitmap = NULL;
   822     CFbsBitmap* mask = NULL;
   697     CFbsBitmap* mask = NULL;
   823     if (!bitmapandmask)
   698     if (!bitmapandmask)
   848         }
   723         }
   849     bitmap = bitmapandmask->bitmap;
   724     bitmap = bitmapandmask->bitmap;
   850     mask = bitmapandmask->mask;
   725     mask = bitmapandmask->mask;
   851     
   726     
   852     PublishImageL( aPlugin, aDestination, bitmap->Handle() , mask->Handle()); 
   727     PublishImageL( aPlugin, aDestination, bitmap->Handle() , mask->Handle()); 
   853     MPX_DEBUG1("CMusicContentPublisher::PublishImageL --->");
       
   854     }
   728     }
   855 
   729 
   856 // ---------------------------------------------------------------------------
   730 // ---------------------------------------------------------------------------
   857 // Publishes a text from path to the required destination
   731 // Publishes a text from path to the required destination
   858 // ---------------------------------------------------------------------------
   732 // ---------------------------------------------------------------------------
   859 //
   733 //
   860 void CMusicContentPublisher::PublishTextL( CMCPPlugin* aPlugin, 
   734 void CMusicContentPublisher::PublishTextL( CMCPPlugin* aPlugin, 
   861         TMCPTextDestination aDestination, 
   735         TMCPTextDestination aDestination, 
   862         const TDesC& aText )
   736         const TDesC& aText )
   863     {
   737     {
   864     MPX_DEBUG1("CMusicContentPublisher::PublishTextL <---");
   738     MPX_FUNC("CMusicContentPublisher::PublishTextL");
       
   739     if ( aDestination >= EMusicMenuMusicInfoLine1 )
       
   740         {
       
   741         MPX_DEBUG2("CMusicContentPublisher::PublishTextL deprecated aDestination=%d", aDestination);
       
   742         return;
       
   743         }
       
   744 
   865     if( iCPSInterface && iActivePlugin == aPlugin)
   745     if( iCPSInterface && iActivePlugin == aPlugin)
   866         {
   746         {
   867         CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC();
   747         TPtrC8 dataKey (iDestinationMap.FindL(aDestination).iDataKey);
   868         CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC();
   748         TPtrC  text;
   869         
   749         text.Set( aText );
   870         TPtrC8 dataKey;
   750         iPublishingDataMap.SetL ( dataKey, text );
   871         TPtrC type;
   751         PublishDeferred();
   872         TPtrC content;
       
   873         MapEnumToDestinationInfoL(aDestination, type, dataKey, content);
       
   874         
       
   875         TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
       
   876         inParam->AppendL( cptype );
       
   877         CLiwDefaultMap * cpdatamap = CLiwDefaultMap::NewLC( );
       
   878         CLiwDefaultMap * map = CLiwDefaultMap::NewLC( );
       
   879         
       
   880         if (KErrNotFound == aText.Find(KLoc))
       
   881             {
       
   882             map->InsertL( dataKey , TLiwVariant( aText ) );    
       
   883             }
       
   884         else
       
   885             {
       
   886             if ( ! aText.Compare( KNowPlaying ) )
       
   887                 {
       
   888                 map->InsertL( dataKey , TLiwVariant( iNowPlayingBuffer ) );
       
   889                 }
       
   890             else if ( ! aText.Compare( KLastPlayed ) )
       
   891                 {
       
   892                 map->InsertL( dataKey , TLiwVariant( iLastPlayedBuffer ) );
       
   893                 }
       
   894             else
       
   895                 {
       
   896                 map->InsertL( dataKey , TLiwVariant( aText ) );
       
   897                 }
       
   898             }
       
   899         
       
   900         cpdatamap->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   901         cpdatamap->InsertL( KContentType , TLiwVariant( type ) );
       
   902         cpdatamap->InsertL( KContentId  , TLiwVariant( content ) );
       
   903         cpdatamap->InsertL( KDataMap  , TLiwVariant( map ) );
       
   904         
       
   905         TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ) ); 
       
   906         inParam->AppendL( item );
       
   907         
       
   908         if ( aDestination >= EMusicMenuMusicInfoLine1 )
       
   909             {
       
   910             if (aText  != KEmpty)
       
   911                 {
       
   912                 iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
       
   913                 }
       
   914             else
       
   915                 {
       
   916                 iCPSInterface->ExecuteCmdL( KDelete , *inParam, *outParam);
       
   917                 }
       
   918             }
       
   919         else
       
   920             {
       
   921             if ( iWidgetForeground )
       
   922                 {
       
   923                 iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );        	
       
   924                 }
       
   925             TMyBufferItem* ptr;
       
   926             ptr = iPublishingDataBuffers.Find(aDestination);
       
   927             if (ptr) //remove the old one
       
   928                 {
       
   929                 User::Free(ptr->buf);
       
   930                 iPublishingDataBuffers.Remove(aDestination);
       
   931                 }
       
   932             TInt sz = map->Size();
       
   933             TMyBufferItem bufferitem;
       
   934             bufferitem.size = map->Size();
       
   935             bufferitem.buf = User::AllocL(map->Size());
       
   936             RMemWriteStream ws(bufferitem.buf, bufferitem.size);
       
   937             map->ExternalizeL(ws);
       
   938             iPublishingDataBuffers.Insert(aDestination, bufferitem);
       
   939             }
       
   940         CleanupStack::PopAndDestroy( map );
       
   941         CleanupStack::PopAndDestroy( cpdatamap );
       
   942         CleanupStack::PopAndDestroy( outParam );
       
   943         CleanupStack::PopAndDestroy( inParam );
       
   944         }  
   752         }  
   945     MPX_DEBUG1("CMusicContentPublisher::PublishTextL --->");
       
   946     }
   753     }
   947 
   754 
   948 // ---------------------------------------------------------------------------
   755 // ---------------------------------------------------------------------------
   949 // Publishes an action from a trigger map to the required destination
   756 // Publishes an action from a trigger map to the required destination
   950 // ---------------------------------------------------------------------------
   757 // ---------------------------------------------------------------------------
   951 //
   758 //
   952 void CMusicContentPublisher::PublishActionL( CMCPPlugin* aPlugin, 
   759 void CMusicContentPublisher::PublishActionL( CMCPPlugin* aPlugin, 
   953         TMCPTriggerDestination aDestination,
   760         TMCPTriggerDestination aDestination,
   954         CLiwDefaultMap* aTriggerMap )
   761         CLiwDefaultMap* aTriggerMap )
   955     {
   762     {
   956     MPX_DEBUG1("CMusicContentPublisher::PublishActionL <---");
   763     MPX_FUNC("CMusicContentPublisher::PublishActionL");
   957      if( iCPSInterface && iActivePlugin == aPlugin)
   764     if ( aDestination >= EMusicMenuMusicInfoTrigger )
   958         {
   765         {
   959         CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC();
   766         MPX_DEBUG2("CMusicContentPublisher::PublishActionL deprecated aDestination=%d", aDestination);
   960         CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC();
   767         return;
   961         
   768         }
   962         TPtrC8 triggerKey;
   769 
   963         TPtrC hostType;
   770     if( iCPSInterface && iActivePlugin == aPlugin)
   964         TPtrC hostContent;
   771         {
   965         
   772         TDestinationItem & destination ( iDestinationMap.FindL( aDestination ) );
   966         MapEnumToDestinationInfoL(aDestination, hostType, triggerKey, 
   773         iPublishingActionMap.SetL( destination.iDataKey , aTriggerMap );
   967                 hostContent);
   774         PublishDeferred();
   968         
   775         }
   969         TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
       
   970         inParam->AppendL( cptype );
       
   971         
       
   972         CLiwDefaultMap * cpdatamap = CLiwDefaultMap::NewLC( );
       
   973         cpdatamap->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   974         cpdatamap->InsertL( KContentType , TLiwVariant( hostType ) );
       
   975         cpdatamap->InsertL( KContentId  , TLiwVariant( hostContent ) );
       
   976         
       
   977         CLiwDefaultMap * actionmap = CLiwDefaultMap::NewLC( );
       
   978         actionmap->InsertL( triggerKey , TLiwVariant( aTriggerMap ) );
       
   979         cpdatamap->InsertL( KActionMap  , TLiwVariant( actionmap ) );
       
   980         
       
   981         TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ) ); 
       
   982         inParam->AppendL( item );
       
   983         
       
   984         if ( aDestination >= EMusicMenuMusicInfoTrigger )
       
   985             {
       
   986             iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
       
   987             }
       
   988         else
       
   989             {
       
   990             if ( iWidgetForeground )
       
   991                 {
       
   992             	  iCPSInterface->ExecuteCmdL( KAdd , *inParam, *outParam );
       
   993                 }
       
   994             TMyBufferItem* ptr;
       
   995             ptr = iPublishingActionBuffers.Find(aDestination);
       
   996             if (ptr) //remove the old one
       
   997                 {
       
   998                 User::Free(ptr->buf);
       
   999                 iPublishingActionBuffers.Remove(aDestination);
       
  1000                 }
       
  1001             TInt sz = actionmap->Size();
       
  1002             TMyBufferItem bufferitem;
       
  1003             bufferitem.size = actionmap->Size();
       
  1004             bufferitem.buf = User::AllocL(actionmap->Size());
       
  1005             RMemWriteStream ws(bufferitem.buf, bufferitem.size);
       
  1006             actionmap->ExternalizeL(ws);
       
  1007             iPublishingActionBuffers.Insert(aDestination, bufferitem);
       
  1008             }
       
  1009         CleanupStack::PopAndDestroy( actionmap );
       
  1010         CleanupStack::PopAndDestroy( cpdatamap );
       
  1011         CleanupStack::PopAndDestroy( outParam );
       
  1012         CleanupStack::PopAndDestroy( inParam );
       
  1013         }
       
  1014     MPX_DEBUG1("CMusicContentPublisher::PublishActionL --->");
       
  1015     }
   776     }
  1016 
   777 
  1017 // ---------------------------------------------------------------------------
   778 // ---------------------------------------------------------------------------
  1018 // Called when a plugin becomes active, it deactivates the previous plugin.
   779 // Called when a plugin becomes active, it deactivates the previous plugin.
  1019 // ---------------------------------------------------------------------------
   780 // ---------------------------------------------------------------------------
  1020 //
   781 //
  1021 void CMusicContentPublisher::BecameActiveL( CMCPPlugin* aPlugin )
   782 void CMusicContentPublisher::BecameActiveL( CMCPPlugin* aPlugin )
  1022     {
   783     {
  1023     MPX_DEBUG1("CMusicContentPublisher::BecameActiveL <---");
   784     MPX_FUNC("CMusicContentPublisher::BecameActiveL");
  1024     if ( iActivePlugin != aPlugin )
   785     if ( iActivePlugin != aPlugin )
  1025         {
   786         {
  1026         if ( iActivePlugin )
   787         if ( iActivePlugin )
  1027             {
   788             {
  1028             MPX_DEBUG1("CMusicContentPublisher::BecameActiveL deactivating old plugin");
   789             MPX_DEBUG1("CMusicContentPublisher::BecameActiveL deactivating old plugin");
       
   790             DoPublishDeleteAllL();
  1029             iActivePlugin->Deactivate();
   791             iActivePlugin->Deactivate();
  1030             MPX_DEBUG1("CMusicContentPublisher::BecameActiveL plugin deactivated");
   792             iPublishingDataMap.Close();
  1031             PublishImageL( iActivePlugin, EMusicMenuMusicInfoImage1, KEmpty );
   793             iPublishingActionMap.Close();
  1032             }
   794             }
  1033         iActivePlugin = aPlugin;
   795         iActivePlugin = aPlugin;
  1034         }
   796         }
  1035     MPX_DEBUG1("CMusicContentPublisher::BecameActiveL --->");
       
  1036     }
   797     }
  1037 // ---------------------------------------------------------------------------
   798 // ---------------------------------------------------------------------------
  1038 // From CContentHarvesterPlugin
   799 // From CContentHarvesterPlugin
  1039 // This function updates information in CPS storage
   800 // This function updates information in CPS storage
  1040 // ---------------------------------------------------------------------------
   801 // ---------------------------------------------------------------------------
  1041 //    
   802 //    
  1042 void CMusicContentPublisher::UpdateL() 
   803 void CMusicContentPublisher::UpdateL() 
  1043     {
   804     {
  1044     MPX_DEBUG1("CMusicContentPublisher::UpdateL <---");
   805     MPX_FUNC("CMusicContentPublisher::UpdateL");
  1045     if ( !iPluginManager )
   806     if ( !iPluginManager )
  1046         {
   807         {
  1047         MPX_DEBUG1("CMusicContentPublisher::UpdateL creating the plugin manager");
   808         MPX_DEBUG1("CMusicContentPublisher::UpdateL creating the plugin manager");
  1048         iPluginManager = CPluginManager::NewL(
   809         iPluginManager = CPluginManager::NewL(
  1049                 TUid::Uid( KMCPPluginUid ), 
   810                 TUid::Uid( KMCPPluginUid ), 
  1050                 static_cast<MMCPPluginObserver*>( this ),
   811                 static_cast<MMCPPluginObserver*>( this ),
  1051                 this );
   812                 this );
  1052         }
   813         }
  1053     MPX_DEBUG1("CMusicContentPublisher::UpdateL --->");
       
  1054     }
   814     }
  1055 
   815 
  1056 // ---------------------------------------------------------------------------
   816 // ---------------------------------------------------------------------------
  1057 // From MAknsSkinChangeObserver.
   817 // From MAknsSkinChangeObserver.
  1058 // Called by the skin server when skin content is changed and the
   818 // Called by the skin server when skin content is changed and the
  1068         iActivePlugin->SkinChanged();
   828         iActivePlugin->SkinChanged();
  1069         }
   829         }
  1070     MPX_DEBUG1("CMusicContentPublisher::SkinContentChanged --->");
   830     MPX_DEBUG1("CMusicContentPublisher::SkinContentChanged --->");
  1071     }
   831     }
  1072 
   832 
  1073 void CMusicContentPublisher::HandlePublisherNotificationL( const TDesC& aContentId, const TDesC8& aTrigger )
   833 void CMusicContentPublisher::HandlePublisherNotificationL( const TDesC& aContentId, 
  1074     {
   834 	                                                         const TDesC8& aTrigger )
  1075     MPX_DEBUG1("CMusicContentPublisher::HandlePublisherNotificationL <---");
   835     {
  1076     if ( aTrigger == KMyActive && !iWidgetActivated)
   836     MPX_DEBUG2_8("-->CMusicContentPublisher::HandlePublisherNotificationL %S", &aTrigger);
  1077         {
   837     if ( aTrigger == KMyActive )
  1078         iWidgetActivated = ETrue;
   838         {
  1079         MPX_DEBUG1("CMusicContentPublisher::HandlePublisherNotificationL activate");
   839         delete iInstanceId;
       
   840         iInstanceId = NULL;
       
   841         iInstanceId = aContentId.AllocL();
       
   842         DoPublishAllL();
       
   843         }
       
   844     else if ( aTrigger ==  KMyDeActive )
       
   845         {
       
   846         DoPublishDeleteAllL();
       
   847         delete iInstanceId;
       
   848         iInstanceId = NULL;
       
   849         }
       
   850     else if ( aTrigger ==  KMySuspend && iWidgetForeground)
       
   851         {
       
   852         iWidgetForeground = EFalse;
       
   853         }
       
   854     else if ( aTrigger ==  KMyResume && !iWidgetForeground)
       
   855         {
       
   856         iWidgetForeground = ETrue;
  1080         if ( !iInstanceId )
   857         if ( !iInstanceId )
  1081             {
   858             {
       
   859             // CPS framework does not always send 'active' message during boot
  1082             iInstanceId = aContentId.AllocL();
   860             iInstanceId = aContentId.AllocL();
  1083             //Reset The Widget
   861             DoPublishAllL();
  1084             MPX_DEBUG1("CMusicContentPublisher::HandlePublisherNotificationL activate --> Reset Widget");
       
  1085             RDebug::Print(aContentId);
       
  1086             PublishImageL(NULL,EMusicWidgetImage1,KEmpty);
       
  1087             InstallGoToAlbumL( EMusicWidgetTrigger1 );
       
  1088             PublishTextL( NULL,EMusicWidgetText1, KEmpty );
       
  1089             PublishImageL(NULL,EMusicWidgetToolbarB1,KEmpty);
       
  1090             PublishImageL(NULL,EMusicWidgetToolbarB2,KEmpty);
       
  1091             PublishImageL(NULL,EMusicWidgetToolbarB3,KEmpty);
       
  1092             InstallEmptyActionL(EMusicWidgetTB1Trigger);
       
  1093             InstallEmptyActionL(EMusicWidgetTB2Trigger);
       
  1094             InstallEmptyActionL(EMusicWidgetTB3Trigger);
       
  1095             PublishTextL( NULL,EMusicWidgetDefaultText, iGoToMusicBuffer->Des() );
       
  1096             InstallGoToAlbumL( EMusicWidgetTrigger2 );
       
  1097             }
   862             }
  1098         else
   863         else
  1099             {
   864             {
  1100             delete iInstanceId;
   865             DoPublishModifiedL();
  1101             iInstanceId = NULL;
   866             }
  1102             iInstanceId = aContentId.AllocL();
   867         }
  1103             }
   868     MPX_DEBUG1("<--CMusicContentPublisher::HandlePublisherNotificationL");
  1104         }
       
  1105     else if ( aTrigger ==  KMyDeActive && iWidgetActivated)
       
  1106         {
       
  1107         iWidgetActivated = EFalse;
       
  1108         MPX_DEBUG1("CMusicContentPublisher::HandlePublisherNotificationL deactivate");
       
  1109         //Removing al the CPS entrys to prevent flicker of old text and unwanted images (old/expired handles).
       
  1110         RemoveL( EMusicWidgetImage1 );
       
  1111         RemoveL( EMusicWidgetText1 );
       
  1112         RemoveL( EMusicWidgetToolbarB1 );
       
  1113         RemoveL( EMusicWidgetToolbarB2 );
       
  1114         RemoveL( EMusicWidgetToolbarB3 );
       
  1115         RemoveL( EMusicWidgetDefaultText );
       
  1116         }
       
  1117     else if ( aTrigger ==  KMySuspend && iWidgetActivated && iWidgetForeground)
       
  1118         {
       
  1119         MPX_DEBUG1("CMusicContentPublisher::HandlePublisherNotificationL suspend");
       
  1120         iWidgetForeground = EFalse;
       
  1121         }
       
  1122     else if ( aTrigger ==  KMyResume && iWidgetActivated && !iWidgetForeground)
       
  1123         {
       
  1124         MPX_DEBUG1("CMusicContentPublisher::HandlePublisherNotificationL resume");
       
  1125         iWidgetForeground = ETrue;
       
  1126         DoPublishL();
       
  1127         }
       
  1128     MPX_DEBUG1("CMusicContentPublisher::HandlePublisherNotificationL --->");
       
  1129     }
   869     }
  1130 
   870 
  1131 
   871 
  1132 //  End of File
   872 //  End of File
  1133 
   873