musichomescreen_multiview/musiccontentpublisher/src/musiccontentpublisher.cpp
branchRCL_3
changeset 53 3de6c4cf6b67
child 66 1f1dad4af8f8
equal deleted inserted replaced
52:14979e23cb5e 53:3de6c4cf6b67
       
     1 /*
       
     2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Manages MCP plugins, and content publishing.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mpxlog.h>                     // MPX_DEBUG
       
    19 #include <liwservicehandler.h>
       
    20 #include <liwvariant.h>
       
    21 #include <liwgenericparam.h>
       
    22 
       
    23 #include <mcpplugin.h>
       
    24 #include <mcppluginuids.hrh>
       
    25 #include <fbs.h>
       
    26 #include <coemain.h>
       
    27 #include <AknsUtils.h>
       
    28 #include <gdi.h>
       
    29 #include <musichomescreen.rsg>
       
    30 #include <bautils.h>
       
    31 #include <data_caging_path_literals.hrh>
       
    32 #include <s32mem.h>
       
    33 #include <e32hashtab.h>
       
    34 
       
    35 #include "cpglobals.h" //This will be moved to domain API (HSFW)
       
    36 #include "musiccontentpublisher.h"
       
    37 #include "pluginmanager.h"
       
    38 #include "mcpharvesterpublisherobserver.h"
       
    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 
       
    48 _LIT( KPubData,        "publisher" );
       
    49 
       
    50 _LIT8( KMyActive, "active" );
       
    51 _LIT8( KMyDeActive, "deactive");
       
    52 _LIT8( KMySuspend, "suspend");
       
    53 _LIT8( KMyResume, "resume");
       
    54 _LIT8( KMyPluginshutdown, "pluginshutdown");
       
    55 _LIT8( KMySystemshutdown, "systemshutdown");
       
    56 _LIT8( KMyActionMap, "action_map" );
       
    57 _LIT8( KMyItem, "item" );
       
    58 _LIT8( KMyAdd, "Add" );
       
    59 _LIT8( KMyMusic, "music");
       
    60 _LIT8( KMyItemId, "item_id" );
       
    61 _LIT( KMyActionName, "data" );
       
    62 
       
    63 _LIT( KEmpty, "" );
       
    64 
       
    65 _LIT( KMWPublisher, "MWPublisher");
       
    66 _LIT( KactionMessageToMusicPlayer, "MessageToMusicPlayer" );
       
    67 _LIT( KGoToAlbumView, "GoToAlbumView" );
       
    68 _LIT8( KMessage, "message" );
       
    69 
       
    70 //for application launcher AHPlugin
       
    71 const TInt KMmUid3AsTInt( 0x101f4cd2 );
       
    72 const TInt KMSGUidAsTInt( 0x10003A39 );
       
    73 const TInt KDelayTime( 6000000 ); // CPeriodic timer
       
    74 _LIT8( KAdditionalData, "additional_data" );
       
    75 _LIT( KLaunchApp, "launch_application" );
       
    76 _LIT( KMessageWithTail, "message_with_tail" );
       
    77 _LIT8( KMessageForMMOpenMusicSuiteWithHide, "mm://root/musicsuite?exit=hide");
       
    78 
       
    79 _LIT( KResourceFile, "z:musichomescreen.rsc");
       
    80 
       
    81 // ======== MEMBER FUNCTIONS ========
       
    82 
       
    83 CMusicContentPublisher::TDestinationItem::TDestinationItem(const TMCPDestinationItem& aItem):
       
    84     iType( reinterpret_cast<const TUint16*>(aItem.type) ),
       
    85     iDataKey ( reinterpret_cast<const TUint8*>(aItem.dataKey ) ),
       
    86     iMaskKey ( reinterpret_cast<const TUint8*>(aItem.maskKey ) )
       
    87     {}
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // Constructor
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CMusicContentPublisher::CMusicContentPublisher( MLiwInterface* aCPSInterface ):
       
    95         iCPSInterface (aCPSInterface)
       
    96     {
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Symbian 2nd phase constructor can leave.
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CMusicContentPublisher::ConstructL()
       
   104     {
       
   105     MPX_DEBUG1("CMusicContentPublisher::ConstructL <---");
       
   106     //Load the destination translation table.
       
   107     TInt dstl (sizeof(KMCPDestinationInfo)/sizeof(TMCPDestinationItem));
       
   108     for (TInt i = 0; i < dstl; i++)
       
   109         {
       
   110         iDestinationMap.InsertL(KMCPDestinationInfo[i].id, 
       
   111                                 TDestinationItem(KMCPDestinationInfo[i]));
       
   112         }
       
   113     
       
   114     dstl = (sizeof(KMCPImageDestinationInfo)/sizeof(
       
   115             TMCPImageDestinationInfoItem));
       
   116     for (TInt i = 0; i < dstl; i++)
       
   117         {
       
   118         iImageDestinationSizeMap.Insert(KMCPImageDestinationInfo[i].id,
       
   119                 TSize(KMCPImageDestinationInfo[i].sizex,
       
   120                         KMCPImageDestinationInfo[i].sizey));
       
   121         }
       
   122     
       
   123     MPX_DEBUG1("CMusicContentPublisher::ConstructL loading resources");
       
   124     //Load Loc strings
       
   125     RFs fs;
       
   126     User::LeaveIfError(fs.Connect());
       
   127     CleanupClosePushL(fs);  
       
   128     TFileName fileName;
       
   129     TParse* parseObj = new(ELeave) TParse();
       
   130     TInt errInt = parseObj->Set( KResourceFile(),&KDC_APP_RESOURCE_DIR,NULL );
       
   131     if(KErrNone != errInt)
       
   132       {
       
   133       delete parseObj;
       
   134       User::Leave(errInt);
       
   135       }
       
   136     fileName = parseObj->FullName();
       
   137     delete parseObj;
       
   138     BaflUtils::NearestLanguageFile(fs,fileName);
       
   139     if(!BaflUtils::FileExists(fs,fileName))
       
   140         {
       
   141         User::Leave(KErrNotFound);
       
   142         }
       
   143     RResourceFile resourceFile;
       
   144     resourceFile.OpenL(fs,fileName);
       
   145     CleanupClosePushL(resourceFile);
       
   146     resourceFile.ConfirmSignatureL();
       
   147     GetLocalizedStringL(resourceFile, iGoToMusicBuffer, R_MUSICHOMESCREEN_GO_TO_MUSIC);
       
   148     CleanupStack::PopAndDestroy(&resourceFile);
       
   149     CleanupStack::PopAndDestroy(&fs);
       
   150     MPX_DEBUG1("CMusicContentPublisher::ConstructL resources loaded");
       
   151     
       
   152     // connect to the skin server, to receive skin changed event.
       
   153     User::LeaveIfError(iAknsSrvSession.Connect(this));
       
   154     
       
   155     // enable skin.
       
   156     AknsUtils::InitSkinSupportL();
       
   157     	
       
   158     iDeferredPublish = new (ELeave) CAsyncCallBack(TCallBack(DoPublish, this), 
       
   159                                                    CActive::EPriorityLow);
       
   160 
       
   161     MPX_DEBUG1("CMusicContentPublisher::ConstructL subscribing to observer");
       
   162  
       
   163     // Observer must be registered before the publisher
       
   164     // When publisher is registered, HS gets the notification and starts sending the events immediately.
       
   165     // Late registration of observer causes missing events.
       
   166 
       
   167     // 1. Register the Observer
       
   168     CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
       
   169     filter->InsertL( KPublisherId, TLiwVariant( KMWPublisher ) );
       
   170     filter->InsertL( KContentId, TLiwVariant( KAll) );
       
   171     filter->InsertL( KContentType, TLiwVariant( KAll ) );
       
   172     iHPObserver = CMCPHarvesterPublisherObserver::NewL(this);
       
   173     iHPObserver->RegisterL(filter);
       
   174     CleanupStack::PopAndDestroy(filter);
       
   175 
       
   176     // 2. Register the Publisher 
       
   177     TUint id = RegisterPublisherL( 
       
   178             KMWPublisher,
       
   179             KAll, 
       
   180             KAll );
       
   181     
       
   182     MPX_DEBUG1("CMusicContentPublisher::ConstructL initializing content");
       
   183     PublishDefaultL();
       
   184     iUpdateIdle = CPeriodic::NewL(CActive::EPriorityStandard);
       
   185     
       
   186     MPX_DEBUG1("CMusicContentPublisher::ConstructL --->");
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // Two-phased constructor.
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 CMusicContentPublisher* CMusicContentPublisher::NewL(  
       
   194         MLiwInterface* aCPSInterface )
       
   195     {
       
   196     CMusicContentPublisher* self = new ( ELeave ) CMusicContentPublisher( 
       
   197             aCPSInterface );
       
   198     CleanupStack::PushL( self );
       
   199     self->ConstructL();
       
   200     CleanupStack::Pop( self );
       
   201     return self;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // Destructor
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 CMusicContentPublisher::~CMusicContentPublisher()
       
   209     {
       
   210     
       
   211     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher <---");
       
   212     delete iDeferredPublish;
       
   213     if(iHPObserver)
       
   214         {
       
   215         MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher deleting observer");
       
   216         delete iHPObserver; 
       
   217         }
       
   218     delete iGoToMusicBuffer;
       
   219     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher closing destination maps");
       
   220     iImageDestinationSizeMap.Close();
       
   221     iDestinationMap.Close();
       
   222     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher resetting bitmap cache");
       
   223     ResetBitmapCache();
       
   224     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher closing skin server session");
       
   225     iAknsSrvSession.Close();
       
   226     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher deleting plugin manager");
       
   227     delete iPluginManager;
       
   228     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher resetting publishing maps");
       
   229     iPublishingDataMap.Close();
       
   230     iPublishingActionMap.Close();
       
   231     MPX_DEBUG1("CMusicContentPublisher::~CMusicContentPublisher --->");
       
   232     if ( iInstanceId )
       
   233     	{
       
   234     	delete iInstanceId;
       
   235     	}
       
   236     
       
   237     if ( iUpdateIdle )
       
   238         {
       
   239         iUpdateIdle->Cancel();
       
   240         delete iUpdateIdle;
       
   241         }    
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // 
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 void CMusicContentPublisher::PublishDefaultL()
       
   249     {
       
   250     MPX_FUNC("CMusicContentPublisher::PublishDefaultL");
       
   251     PublishImageL(NULL,EMusicWidgetImage1,KEmpty);
       
   252     InstallGoToAlbumL( EMusicWidgetTrigger1 );
       
   253     PublishTextL( NULL,EMusicWidgetDefaultText, *iGoToMusicBuffer );
       
   254     PublishTextL( NULL,EMusicWidgetText1, KEmpty );
       
   255     PublishImageL(NULL,EMusicWidgetToolbarB1,KEmpty);
       
   256     PublishImageL(NULL,EMusicWidgetToolbarB2,KEmpty);
       
   257     PublishImageL(NULL,EMusicWidgetToolbarB3,KEmpty);
       
   258     InstallEmptyActionL(EMusicWidgetTB1Trigger);
       
   259     InstallEmptyActionL(EMusicWidgetTB2Trigger);
       
   260     InstallEmptyActionL(EMusicWidgetTB3Trigger);
       
   261     InstallGoToAlbumL( EMusicWidgetTrigger2 );
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // 
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CMusicContentPublisher::InstallGoToMusicL(
       
   269         TMCPTriggerDestination aDestination )
       
   270     {
       
   271     MPX_DEBUG1("CMusicContentPublisher::InstallGoToMusicL <---");
       
   272     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   273     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   274     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10282E5F ) ) );
       
   275     mapData->InsertL( KType, TLiwVariant( KLaunchApp ) );
       
   276     mapData->InsertL( KLaunchMethod, TLiwVariant( KMessageWithTail ) );
       
   277     mapData->InsertL(KApplicationUid,
       
   278             TLiwVariant(TInt32(KMmUid3AsTInt) ) );
       
   279         mapData->InsertL( KAdditionalData, 
       
   280             TLiwVariant( KMessageForMMOpenMusicSuiteWithHide ) );
       
   281     mapData->InsertL(KMessageUid,
       
   282             TLiwVariant(TInt32(KMSGUidAsTInt) ) );
       
   283     
       
   284     mapTrigger->InsertL( KData, TLiwVariant( mapData ) );
       
   285     
       
   286     PublishActionL( NULL, aDestination, mapTrigger );
       
   287     
       
   288     CleanupStack::PopAndDestroy( mapData );
       
   289     CleanupStack::PopAndDestroy( mapTrigger );
       
   290     MPX_DEBUG1("CMusicContentPublisher::InstallGoToMusicL --->");
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 // 
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 void CMusicContentPublisher::InstallGoToAlbumL(
       
   298         TMCPTriggerDestination aDestination )
       
   299     {
       
   300     MPX_DEBUG1("CMusicContentPublisher::InstallGoToAlbumL <---");
       
   301     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   302     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   303     
       
   304     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10207C16 ) ) );
       
   305        mapData->InsertL( KType, TLiwVariant( KactionMessageToMusicPlayer ) );
       
   306        mapData->InsertL( KMessage, TLiwVariant( KGoToAlbumView ) );
       
   307     mapTrigger->InsertL( KData, TLiwVariant( mapData ) );
       
   308     
       
   309     PublishActionL( NULL, aDestination, mapTrigger );
       
   310     
       
   311     CleanupStack::PopAndDestroy( mapData );
       
   312     CleanupStack::PopAndDestroy( mapTrigger );
       
   313     MPX_DEBUG1("CMusicContentPublisher::InstallGoToAlbumL --->");
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // 
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CMusicContentPublisher::InstallEmptyActionL(
       
   321         TMCPTriggerDestination aDestination )
       
   322     {
       
   323     MPX_DEBUG1("CMusicContentPublisher::InstallEmptyActionL <---");
       
   324     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   325     PublishActionL( NULL, aDestination, mapTrigger );
       
   326     CleanupStack::PopAndDestroy( mapTrigger );
       
   327     MPX_DEBUG1("CMusicContentPublisher::InstallEmptyActionL --->");
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------------------------------
       
   331 // Get a heap descriptor from the resource file
       
   332 // ----------------------------------------------------------------------------
       
   333 //
       
   334 void CMusicContentPublisher::GetLocalizedStringL(RResourceFile& aResourceFile,
       
   335         HBufC*& aRetBuf, TInt aResourceId )
       
   336    {
       
   337    MPX_DEBUG1("CMusicContentPublisher::GetLocalizedStringL <---");
       
   338    HBufC8* dataBuffer = aResourceFile.AllocReadLC(aResourceId);
       
   339    TResourceReader theReader;
       
   340    theReader.SetBuffer(dataBuffer);
       
   341    aRetBuf = theReader.ReadHBufCL();
       
   342    CleanupStack::PopAndDestroy(dataBuffer);
       
   343    MPX_DEBUG1("CMusicContentPublisher::GetLocalizedStringL --->");
       
   344    }
       
   345 
       
   346 // ----------------------------------------------------------------------------
       
   347 // Trigger deferred publishing through an active object
       
   348 // ----------------------------------------------------------------------------
       
   349 //
       
   350 void CMusicContentPublisher::PublishDeferred()
       
   351     {
       
   352     MPX_FUNC("CMusicContentPublisher::PublishDeferred");
       
   353     if ( iWidgetForeground )
       
   354         {
       
   355         iDeferredPublish->CallBack();
       
   356         }
       
   357     }
       
   358 
       
   359 // ----------------------------------------------------------------------------
       
   360 // Run deferred publishing
       
   361 // ----------------------------------------------------------------------------
       
   362 //
       
   363  TInt CMusicContentPublisher::DoPublish(TAny * aMusicContentPublisher)
       
   364     {
       
   365     MPX_FUNC("CMusicContentPublisher::DoPublish");
       
   366     CMusicContentPublisher * self = static_cast<CMusicContentPublisher*>(aMusicContentPublisher);
       
   367     if ( self->iWidgetForeground )
       
   368         {
       
   369         TRAPD(err, self->DoPublishModifiedL());
       
   370         if (err != KErrNone)
       
   371             {
       
   372             MPX_DEBUG2("CMusicContentPublisher::DoPublish failed, err=%d", err);
       
   373             }
       
   374         }    
       
   375     return KErrNone;
       
   376     }
       
   377      
       
   378 // ----------------------------------------------------------------------------
       
   379 // Publish all content
       
   380 // ----------------------------------------------------------------------------
       
   381 //
       
   382 void CMusicContentPublisher::DoPublishAllL()
       
   383     {
       
   384     MPX_FUNC("CMusicContentPublisher::DoPublishAllL");
       
   385     if (iCPSInterface && iInstanceId)
       
   386         {
       
   387         CLiwMap * datamap = iPublishingDataMap.GetAllLC();
       
   388         CLiwMap * actionmap = iPublishingActionMap.GetAllLC();
       
   389 
       
   390         CLiwDefaultMap * cpdata = CLiwDefaultMap::NewLC( );
       
   391         cpdata->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   392         cpdata->InsertL( KContentType , TLiwVariant( KMyMusic ) );
       
   393         cpdata->InsertL( KContentId  , TLiwVariant( iInstanceId ) );
       
   394         cpdata->InsertL( KDataMap  , TLiwVariant( datamap ) );
       
   395         cpdata->InsertL( KActionMap  , TLiwVariant( actionmap ) );
       
   396 
       
   397         MPX_DEBUG2("CMusicContentPublisher::DoPublishAllL Add in %S", iInstanceId);
       
   398         DoPublishCmdL( KAdd, KItem, cpdata );
       
   399         
       
   400         CleanupStack::PopAndDestroy( cpdata );
       
   401         CleanupStack::PopAndDestroy( actionmap );
       
   402         CleanupStack::PopAndDestroy( datamap );
       
   403         }
       
   404     }
       
   405 
       
   406 // ----------------------------------------------------------------------------
       
   407 // Publish modified content
       
   408 // ----------------------------------------------------------------------------
       
   409 //
       
   410 void CMusicContentPublisher::DoPublishModifiedL()
       
   411     {
       
   412     MPX_FUNC("CMusicContentPublisher::DoPublishModifiedL");
       
   413     if (iCPSInterface && iInstanceId )
       
   414         {
       
   415         // Must re-publish all data and actions even if only one of them has changed,
       
   416         // otherwise non-modified data might go missing        
       
   417         CLiwMap * datamap = NULL;
       
   418         if ( iPublishingDataMap.IsModified() )
       
   419             {
       
   420             datamap = iPublishingDataMap.GetAllLC();
       
   421             }
       
   422 
       
   423         CLiwMap * actionmap = NULL;
       
   424         if ( iPublishingActionMap.IsModified() )
       
   425             {
       
   426             actionmap = iPublishingActionMap.GetAllLC();
       
   427             }
       
   428         if ( datamap || actionmap )
       
   429             {
       
   430             CLiwMap * cpdata = CLiwDefaultMap::NewLC( );
       
   431             cpdata->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   432             cpdata->InsertL( KContentType , TLiwVariant( KMyMusic ) );
       
   433             cpdata->InsertL( KContentId  , TLiwVariant( iInstanceId ) );
       
   434             if ( datamap && datamap->Count() )
       
   435                 {
       
   436                 cpdata->InsertL( KDataMap  , TLiwVariant( datamap ) );
       
   437                 }
       
   438             if ( actionmap && actionmap->Count() )
       
   439                 {
       
   440                 cpdata->InsertL( KActionMap  , TLiwVariant( actionmap ) );
       
   441                 }
       
   442 
       
   443             MPX_DEBUG2("CMusicContentPublisher::DoPublishModifiedL Add in %S", iInstanceId);
       
   444             DoPublishCmdL( KAdd, KItem, cpdata );
       
   445         
       
   446             CleanupStack::PopAndDestroy( cpdata );
       
   447             }
       
   448         if (actionmap)
       
   449             {
       
   450             CleanupStack::PopAndDestroy( actionmap );
       
   451             }
       
   452         if (datamap)
       
   453             {
       
   454             CleanupStack::PopAndDestroy( datamap );
       
   455             }
       
   456         }
       
   457     }
       
   458 
       
   459 // ---------------------------------------------------------------------------
       
   460 // Remove all content
       
   461 // ---------------------------------------------------------------------------
       
   462 //
       
   463 void CMusicContentPublisher::DoPublishDeleteAllL()
       
   464     {
       
   465     MPX_FUNC("CMusicContentPublisher::DoPublishDeleteAllL");
       
   466     if( iCPSInterface && iInstanceId)
       
   467         {
       
   468         CLiwDefaultMap * cpdata = CLiwDefaultMap::NewLC( );
       
   469         cpdata->InsertL( KPublisherId , TLiwVariant( KMWPublisher ) );
       
   470         cpdata->InsertL( KContentType , TLiwVariant( KAll ) );
       
   471         cpdata->InsertL( KContentId  , TLiwVariant( iInstanceId ) );
       
   472 
       
   473         MPX_DEBUG2("CMusicContentPublisher::DoPublishDeleteAllL Delete All in %S", iInstanceId);
       
   474         DoPublishCmdL( KDelete, KFilter, cpdata );
       
   475 
       
   476         CleanupStack::PopAndDestroy( cpdata );
       
   477         }  
       
   478     }
       
   479     
       
   480 // ---------------------------------------------------------------------------
       
   481 // Execute a CMD to iCPSInterface
       
   482 // ---------------------------------------------------------------------------
       
   483 //
       
   484 void CMusicContentPublisher::DoPublishCmdL(const TDesC8& aCmd, 
       
   485 	                                         const TDesC8& aKey, 
       
   486 	                                         const CLiwMap * aValue)
       
   487     {
       
   488     MPX_FUNC("CMusicContentPublisher::DoPublishCmdL");
       
   489     CLiwGenericParamList * inParam = CLiwGenericParamList::NewLC();
       
   490     TLiwGenericParam cptype( KType , TLiwVariant( KCpData ) );
       
   491     inParam->AppendL( cptype );
       
   492     TLiwGenericParam item( aKey, TLiwVariant( aValue ) ); 
       
   493     inParam->AppendL( item );
       
   494 
       
   495     CLiwGenericParamList * outParam = CLiwGenericParamList::NewLC();
       
   496 
       
   497     iCPSInterface->ExecuteCmdL( aCmd , *inParam, *outParam);
       
   498 
       
   499     CleanupStack::PopAndDestroy( outParam );
       
   500     CleanupStack::PopAndDestroy( inParam );
       
   501     }
       
   502     
       
   503 // ---------------------------------------------------------------------------
       
   504 // Resets all the graphical elements.
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void CMusicContentPublisher::ResetL()
       
   508     {
       
   509     MPX_DEBUG1("CMusicContentPublisher::ResetL <---");
       
   510     //Plugin deletion is handled by the pluginmanager.
       
   511     iActivePlugin = NULL;
       
   512     //Reset The Widget
       
   513     PublishDefaultL();
       
   514     MPX_DEBUG1("CMusicContentPublisher::Reset --->");
       
   515     }
       
   516 // ---------------------------------------------------------------------------
       
   517 // 
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 TSize CMusicContentPublisher::GetImageDestinationSize(
       
   521         TMCPImageDestination aDst)
       
   522     {
       
   523     MPX_DEBUG1("CMusicContentPublisher::GetImageDestinationSize <---");
       
   524     TSize * ret;
       
   525     ret = iImageDestinationSizeMap.Find(aDst);
       
   526     if (ret)
       
   527         {
       
   528         MPX_DEBUG1("CMusicContentPublisher::GetImageDestinationSize --->");
       
   529         return *ret;    
       
   530         }
       
   531     else
       
   532         {
       
   533         MPX_DEBUG1("CMusicContentPublisher::GetImageDestinationSize --->");
       
   534         return TSize(0,0);
       
   535         }
       
   536     }
       
   537 
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // Destroys the bitmaps saved on the cache.
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 void CMusicContentPublisher::ResetBitmapCache()
       
   544     {
       
   545     MPX_DEBUG1("CMusicContentPublisher::ResetBitmapCache <---");
       
   546     THashMapIter<TInt, TBmpMsk> iter(iBitmapCache);
       
   547     TBmpMsk const* ptr = iter.NextValue();
       
   548     CFbsBitmap* bmp( NULL );
       
   549     CFbsBitmap* msk( NULL );
       
   550     while ( ptr )
       
   551         {
       
   552         bmp = ptr->bitmap;
       
   553         msk = ptr->mask;
       
   554         delete bmp;
       
   555         bmp = NULL;
       
   556         delete msk;
       
   557         msk = NULL;
       
   558         ptr = iter.NextValue();
       
   559         }
       
   560     iBitmapCache.Close();
       
   561     MPX_DEBUG1("CMusicContentPublisher::ResetBitmapCache --->");
       
   562     }
       
   563     
       
   564 // ---------------------------------------------------------------------------
       
   565 // 
       
   566 // ---------------------------------------------------------------------------
       
   567 //
       
   568 TUint CMusicContentPublisher::RegisterPublisherL( 
       
   569     const TDesC& aPublisherId, 
       
   570     const TDesC& aContentId,
       
   571     const TDesC& aContentType )
       
   572     {
       
   573     MPX_DEBUG1("CMusicContentPublisher::RegisterPublisherL <---");
       
   574     TUint id( 0 );
       
   575     if( iCPSInterface )
       
   576         {   
       
   577         CLiwGenericParamList* inparam( CLiwGenericParamList::NewLC() );
       
   578         CLiwGenericParamList* outparam( CLiwGenericParamList::NewLC() );
       
   579 
       
   580         TLiwGenericParam type( KType, TLiwVariant( KPubData ));
       
   581         inparam->AppendL( type );
       
   582         CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
       
   583         CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC();
       
   584         CLiwDefaultMap* actionmap( NULL );
       
   585 
       
   586         // Create the data map for publisher registry
       
   587         cpdatamap->InsertL( KContentType, TLiwVariant( aContentType ));
       
   588         cpdatamap->InsertL( KContentId, TLiwVariant( aContentId ));
       
   589         cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
       
   590 
       
   591         
       
   592         // Create the action map for publisher registry
       
   593         actionmap = CLiwDefaultMap::NewLC();
       
   594         actionmap->InsertL(KMyActive, TLiwVariant( KMyActionName ));
       
   595         actionmap->InsertL(KMyDeActive, TLiwVariant( KMyActionName ));
       
   596         actionmap->InsertL(KMySuspend, TLiwVariant( KMyActionName ));
       
   597         actionmap->InsertL(KMyResume, TLiwVariant( KMyActionName ));
       
   598  
       
   599         cpdatamap->InsertL( KMyActionMap, TLiwVariant(actionmap));
       
   600         CleanupStack::PopAndDestroy( actionmap );
       
   601         
       
   602         TLiwGenericParam item( KMyItem, TLiwVariant( cpdatamap ));        
       
   603         inparam->AppendL( item );
       
   604         
       
   605         iCPSInterface->ExecuteCmdL( KMyAdd , *inparam, *outparam);
       
   606         id = ExtractItemId(*outparam);
       
   607         
       
   608         CleanupStack::PopAndDestroy( datamap );
       
   609         CleanupStack::PopAndDestroy( cpdatamap );
       
   610         item.Reset();
       
   611         type.Reset();   
       
   612         CleanupStack::PopAndDestroy(outparam);
       
   613         CleanupStack::PopAndDestroy(inparam);
       
   614         }
       
   615     MPX_DEBUG1("CMusicContentPublisher::RegisterPublisherL --->");
       
   616     return id;
       
   617     }
       
   618 
       
   619 TUint CMusicContentPublisher::ExtractItemId( const CLiwGenericParamList& aInParamList )
       
   620     {
       
   621     MPX_DEBUG1("CMusicContentPublisher::ExtractItemId <---");
       
   622     TUint result ( 0 );
       
   623     TInt pos( 0 );
       
   624     aInParamList.FindFirst( pos, KMyItemId );
       
   625     if( pos != KErrNotFound )
       
   626         {
       
   627         // item id present - extract and return
       
   628         aInParamList[pos].Value().Get( result );
       
   629         }
       
   630     MPX_DEBUG1("CMusicContentPublisher::ExtractItemId --->");
       
   631     return result;
       
   632     }
       
   633  
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // Publishes an image from path to the required destination
       
   637 // ---------------------------------------------------------------------------
       
   638 //
       
   639 void CMusicContentPublisher::PublishImageL( CMCPPlugin* aPlugin,  
       
   640         TMCPImageDestination aDestination, 
       
   641         const TDesC& aImagePath )
       
   642     {
       
   643     MPX_FUNC("CMusicContentPublisher::PublishImageL");
       
   644     if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   645         {
       
   646         MPX_DEBUG2("CMusicContentPublisher::PublishImageL deprecated aDestination=%d", aDestination);
       
   647         return;
       
   648         }
       
   649 
       
   650     if( iCPSInterface && iActivePlugin == aPlugin )
       
   651         {
       
   652         TDestinationItem & destination (iDestinationMap.FindL( aDestination ));
       
   653         iPublishingDataMap.SetL( destination.iDataKey, aImagePath );
       
   654         iPublishingDataMap.Reset( destination.iMaskKey );
       
   655         PublishDeferred();
       
   656         }
       
   657     }
       
   658 
       
   659 // ---------------------------------------------------------------------------
       
   660 // Publishes an image from bitmap handle to the required destination
       
   661 // ---------------------------------------------------------------------------
       
   662 //
       
   663 void CMusicContentPublisher::PublishImageL( CMCPPlugin* aPlugin, 
       
   664         TMCPImageDestination aDestination,
       
   665         TInt aBitmapHandle,
       
   666         TInt aMaskBitmapHandle)
       
   667     {
       
   668     MPX_FUNC("CMusicContentPublisher::PublishImageL");
       
   669     if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   670         {
       
   671         MPX_DEBUG2("CMusicContentPublisher::PublishImageL deprecated aDestination=%d", aDestination);
       
   672         return;
       
   673         }
       
   674     if( iCPSInterface && iActivePlugin == aPlugin )
       
   675         {
       
   676         TDestinationItem & destination (iDestinationMap.FindL( aDestination ));
       
   677         
       
   678         iPublishingDataMap.SetL( destination.iDataKey, aBitmapHandle  );
       
   679         
       
   680         if (aMaskBitmapHandle)
       
   681             {
       
   682             iPublishingDataMap.SetL( destination.iMaskKey, aMaskBitmapHandle );
       
   683             }
       
   684         else
       
   685             {
       
   686             iPublishingDataMap.Reset( destination.iMaskKey );
       
   687             }
       
   688         PublishDeferred();
       
   689         }
       
   690     }
       
   691 
       
   692 // ---------------------------------------------------------------------------
       
   693 // Publishes an image from skin id and mif to the required destination
       
   694 // ---------------------------------------------------------------------------
       
   695 //
       
   696 void CMusicContentPublisher::PublishImageL(CMCPPlugin* aPlugin, 
       
   697         TMCPImageDestination aDestination,
       
   698         const TAknsItemID& aID,
       
   699         const TDesC& aFilename,
       
   700         const TInt aFileBitmapId,
       
   701         const TInt aFileMaskId )
       
   702     {
       
   703     MPX_FUNC("CMusicContentPublisher::PublishImageL");
       
   704     if ( aDestination >= EMusicMenuMusicInfoImage1 )
       
   705         {
       
   706         MPX_DEBUG2("CMusicContentPublisher::PublishImageL deprecated aDestination=%d", aDestination);
       
   707         return;
       
   708         }
       
   709         
       
   710     TBmpMsk* bitmapandmask;
       
   711     bitmapandmask = iBitmapCache.Find(aID.iMajor+aID.iMinor);
       
   712     CFbsBitmap* bitmap = NULL;
       
   713     CFbsBitmap* mask = NULL;
       
   714     if (!bitmapandmask)
       
   715         {
       
   716         // Load from skin
       
   717         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   718         AknsUtils::CreateIconL(
       
   719                     skin,
       
   720                     aID,
       
   721                     bitmap,
       
   722                     mask,
       
   723                     aFilename,
       
   724                     aFileBitmapId,
       
   725                     aFileMaskId);
       
   726         AknIconUtils::SetSize(
       
   727                 bitmap,
       
   728                 GetImageDestinationSize(aDestination),
       
   729                 EAspectRatioPreserved );
       
   730         AknIconUtils::SetSize(mask,
       
   731                 GetImageDestinationSize(aDestination),
       
   732                 EAspectRatioPreserved );
       
   733         TBmpMsk bmpAndMsk;
       
   734         bmpAndMsk.bitmap=bitmap;
       
   735         bmpAndMsk.mask=mask;
       
   736         iBitmapCache.Insert(aID.iMajor+aID.iMinor,bmpAndMsk);
       
   737         bitmapandmask = iBitmapCache.Find(aID.iMajor+aID.iMinor);
       
   738         __ASSERT_DEBUG(bitmapandmask,User::Invariant());
       
   739         }
       
   740     bitmap = bitmapandmask->bitmap;
       
   741     mask = bitmapandmask->mask;
       
   742     
       
   743     PublishImageL( aPlugin, aDestination, bitmap->Handle() , mask->Handle()); 
       
   744     }
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // Publishes a text from path to the required destination
       
   748 // ---------------------------------------------------------------------------
       
   749 //
       
   750 void CMusicContentPublisher::PublishTextL( CMCPPlugin* aPlugin, 
       
   751         TMCPTextDestination aDestination, 
       
   752         const TDesC& aText )
       
   753     {
       
   754     MPX_FUNC("CMusicContentPublisher::PublishTextL");
       
   755     if ( aDestination >= EMusicMenuMusicInfoLine1 )
       
   756         {
       
   757         MPX_DEBUG2("CMusicContentPublisher::PublishTextL deprecated aDestination=%d", aDestination);
       
   758         return;
       
   759         }
       
   760 
       
   761     if( iCPSInterface && iActivePlugin == aPlugin)
       
   762         {
       
   763         TPtrC8 dataKey (iDestinationMap.FindL(aDestination).iDataKey);
       
   764         TPtrC  text;
       
   765         text.Set( aText );
       
   766         iPublishingDataMap.SetL ( dataKey, text );
       
   767         PublishDeferred();
       
   768         }  
       
   769     }
       
   770 
       
   771 // ---------------------------------------------------------------------------
       
   772 // Publishes an action from a trigger map to the required destination
       
   773 // ---------------------------------------------------------------------------
       
   774 //
       
   775 void CMusicContentPublisher::PublishActionL( CMCPPlugin* aPlugin, 
       
   776         TMCPTriggerDestination aDestination,
       
   777         CLiwDefaultMap* aTriggerMap )
       
   778     {
       
   779     MPX_FUNC("CMusicContentPublisher::PublishActionL");
       
   780     if ( aDestination >= EMusicMenuMusicInfoTrigger )
       
   781         {
       
   782         MPX_DEBUG2("CMusicContentPublisher::PublishActionL deprecated aDestination=%d", aDestination);
       
   783         return;
       
   784         }
       
   785 
       
   786     if( iCPSInterface && iActivePlugin == aPlugin)
       
   787         {
       
   788         TDestinationItem & destination ( iDestinationMap.FindL( aDestination ) );
       
   789         iPublishingActionMap.SetL( destination.iDataKey , aTriggerMap );
       
   790         PublishDeferred();
       
   791         }
       
   792     }
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // Called when a plugin becomes active, it deactivates the previous plugin.
       
   796 // ---------------------------------------------------------------------------
       
   797 //
       
   798 void CMusicContentPublisher::BecameActiveL( CMCPPlugin* aPlugin )
       
   799     {
       
   800     MPX_FUNC("CMusicContentPublisher::BecameActiveL");
       
   801     if ( iActivePlugin != aPlugin )
       
   802         {
       
   803         if ( iActivePlugin )
       
   804             {
       
   805             MPX_DEBUG1("CMusicContentPublisher::BecameActiveL deactivating old plugin");
       
   806             DoPublishDeleteAllL();
       
   807             iActivePlugin->Deactivate();
       
   808             iPublishingDataMap.Close();
       
   809             iPublishingActionMap.Close();
       
   810             }
       
   811         iActivePlugin = aPlugin;
       
   812         }
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------------------------
       
   816 // Callback function for CPeriodic.
       
   817 // ---------------------------------------------------------------------------
       
   818 //   
       
   819 TInt CMusicContentPublisher::UpdateCallback(TAny* aContentPublisher)
       
   820     {
       
   821     MPX_FUNC("CMusicContentPublisher::UpdateCallback");
       
   822     
       
   823     CMusicContentPublisher* self = 
       
   824             reinterpret_cast<CMusicContentPublisher*> (aContentPublisher);
       
   825     self->DoUpdate();
       
   826     
       
   827     return EFalse;
       
   828     }
       
   829 
       
   830 // ---------------------------------------------------------------------------
       
   831 // Create plugin manager.
       
   832 // ---------------------------------------------------------------------------
       
   833 //   
       
   834 void CMusicContentPublisher::DoUpdate()
       
   835     {
       
   836     MPX_FUNC("CMusicContentPublisher::DoUpdate")
       
   837     
       
   838     TRAP_IGNORE( iPluginManager = CPluginManager::NewL(
       
   839             TUid::Uid( KMCPPluginUid ), 
       
   840             static_cast<MMCPPluginObserver*>( this ),
       
   841             this ));    
       
   842     iUpdateIdle->Cancel();
       
   843     }
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // From CContentHarvesterPlugin
       
   847 // This function updates information in CPS storage
       
   848 // ---------------------------------------------------------------------------
       
   849 //    
       
   850 void CMusicContentPublisher::UpdateL() 
       
   851     {
       
   852     MPX_FUNC("CMusicContentPublisher::UpdateL");
       
   853         
       
   854     // Construct plugin manager asynchronously for not to block the caller
       
   855     // thread
       
   856     if ( !iPluginManager && !iUpdateIdle->IsActive())
       
   857         {
       
   858         MPX_DEBUG1("CMusicContentPublisher::UpdateL creating the plugin manager");
       
   859         
       
   860         iUpdateIdle->Start(KDelayTime, KDelayTime, TCallBack(UpdateCallback,this));
       
   861         }
       
   862     }
       
   863 
       
   864 // ---------------------------------------------------------------------------
       
   865 // From MAknsSkinChangeObserver.
       
   866 // Called by the skin server when skin content is changed and the
       
   867 // connected client wants to be informed.
       
   868 // ---------------------------------------------------------------------------
       
   869 // 
       
   870 void CMusicContentPublisher::SkinContentChanged()
       
   871     {
       
   872     MPX_DEBUG1("CMusicContentPublisher::SkinContentChanged <---");
       
   873     ResetBitmapCache();
       
   874     if(iActivePlugin)
       
   875         {
       
   876         iActivePlugin->SkinChanged();
       
   877         }
       
   878     MPX_DEBUG1("CMusicContentPublisher::SkinContentChanged --->");
       
   879     }
       
   880 
       
   881 void CMusicContentPublisher::HandlePublisherNotificationL( const TDesC& aContentId, 
       
   882 	                                                         const TDesC8& aTrigger )
       
   883     {
       
   884     MPX_DEBUG2_8("-->CMusicContentPublisher::HandlePublisherNotificationL %S", &aTrigger);
       
   885     if ( aTrigger == KMyActive )
       
   886         {
       
   887         delete iInstanceId;
       
   888         iInstanceId = NULL;
       
   889         iInstanceId = aContentId.AllocL();
       
   890         DoPublishAllL();
       
   891         }
       
   892     else if ( aTrigger ==  KMyDeActive )
       
   893         {
       
   894         delete iInstanceId;  
       
   895         iInstanceId = NULL;
       
   896         }
       
   897     else if ( aTrigger ==  KMySuspend && iWidgetForeground)
       
   898         {
       
   899         iWidgetForeground = EFalse;
       
   900         }
       
   901     else if ( aTrigger ==  KMyResume && !iWidgetForeground)
       
   902         {
       
   903         iWidgetForeground = ETrue;
       
   904         DoPublishModifiedL();
       
   905         }
       
   906     else if ( aTrigger == KMyPluginshutdown || aTrigger == KMySystemshutdown )
       
   907         {
       
   908         DoPublishDeleteAllL();   // Delete the data only if widget is removed or Phone is shutting down.
       
   909 		}
       
   910 
       
   911     MPX_DEBUG1("<--CMusicContentPublisher::HandlePublisherNotificationL");
       
   912     }
       
   913 
       
   914 
       
   915 //  End of File
       
   916