musichomescreen_multiview/mcpmusicplayer/src/mcpmusicplayer.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:  Updates Music Content Publisher
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mpxlog.h>                     // MPX_DEBUG
       
    19 #include <implementationproxy.h>
       
    20 #include <liwservicehandler.h>
       
    21 #include <liwvariant.h>
       
    22 #include <liwgenericparam.h>
       
    23 #include <StringLoader.h>
       
    24 #include <AknUtils.h>
       
    25 #include <AknsUtils.h>
       
    26 #include <aknsconstants.hrh>
       
    27 #include <musichomescreenicons.mbg>
       
    28 #include <musichomescreen.rsg>
       
    29 #include <bautils.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 #include <mpxmessagegeneraldefs.h>
       
    32 #include <mpxcollectionmessage.h>
       
    33 #include <mpxcollectionutility.h>
       
    34 #include <mpxcollectionframeworkdefs.h>
       
    35 #include <AknTaskList.h>
       
    36 #include <mpxharvesterutility.h>
       
    37 
       
    38 
       
    39 #include "cpglobals.h" //to be moved to domain API
       
    40 
       
    41 #include "mcpmusicplayer.h" 
       
    42 #include "mcpmusicplayeruids.hrh"
       
    43 #include "aiplayerpluginengine.h"
       
    44 #include "filemonitor.h"
       
    45 #include "applicationmonitor.h"
       
    46 #include "pnsmonitor.h"
       
    47 
       
    48 //const TUid  KLocalPlaybackUid = { 0x101FFC06 };
       
    49 const TInt  KMusicPlayerAppUidAsTInt =  0x102072C3;
       
    50 
       
    51 const TInt KMmUid3AsTInt( 0x101f4cd2 );
       
    52 const TInt KMSGUidAsTInt( 0x10003A39 );
       
    53 
       
    54 namespace TBK
       
    55     {
       
    56     const TUint  KSkeep_L          = 0x001; //000000000001
       
    57     const TUint  KSkeep_R          = 0x002; //000000000010
       
    58     const TUint  KPause            = 0x004; //000000000100
       
    59     const TUint  KPlay             = 0x008; //000000001000
       
    60     const TUint  KSkeep_L_dimmed   = 0x010; //000000010000
       
    61     const TUint  KSkeep_R_dimmed   = 0x020; //000000100000
       
    62     const TUint  KPause_dimmed     = 0x040; //000001000000
       
    63     const TUint  KPlay_dimmed      = 0x080; //000010000000
       
    64     const TUint  KPlay_last_played = 0x100; //000100000000
       
    65     }
       
    66 
       
    67 _LIT( KEmpty, "" );
       
    68 
       
    69 
       
    70 _LIT( KMIF, "z:\\resource\\apps\\musichomescreenicons.mif");
       
    71 
       
    72 _LIT( KResourceFile, "z:musichomescreen.rsc");
       
    73 
       
    74 //for music player action handler - playback command
       
    75 _LIT( KActionPlaybackCommand , "PlaybackCommand" );
       
    76 _LIT8( KPBCommand, "command" );
       
    77 
       
    78 //for music player action handler - message to music player
       
    79 _LIT( KactionMessageToMusicPlayer, "MessageToMusicPlayer" );
       
    80 _LIT( KGoToNowPlaying, "GoToNowPlaying" );
       
    81 _LIT( KGoToLastPlayedMinimized, "GoToLastPlayedMinimized" );
       
    82 _LIT( KGoToAlbumView, "GoToAlbumView" );
       
    83 
       
    84 _LIT8( KMessage, "message" );
       
    85 _LIT8( KAdditionalData, "additional_data" );
       
    86 
       
    87 //for application launcher AHPlugin
       
    88 _LIT( KCmdLine, "cmd_line" );
       
    89 _LIT( KLaunchApp, "launch_application" );
       
    90 _LIT( KMessageWithTail, "message_with_tail" );
       
    91 _LIT8( KMessageForMMOpenMusicSuiteWithHide, "mm://root/musicsuite?exit=hide");
       
    92 
       
    93 
       
    94 //for time
       
    95 //_LIT( KSeparator, "/" );
       
    96 _LIT( KSeparatorhyphen, " - " );
       
    97 //_LIT( KMPXZeroDurationMark, "--" );
       
    98 //_LIT( KTitleNowPlaying, "Now Playing" );
       
    99 //_LIT( KTitleLastPlayed, "Last Played" );
       
   100 
       
   101 const TInt KMusicPlayerOpeningTimerInterval = 15000000; // 15 seconds
       
   102 
       
   103 // ======== MEMBER FUNCTIONS ========
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // Constructor
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CMCPMusicPlayer::CMCPMusicPlayer(MMCPPluginObserver* aObserver)
       
   110     {
       
   111     iMHObserver = aObserver;
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // Symbian 2nd phase constructor can leave.
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CMCPMusicPlayer::ConstructL()
       
   119     {
       
   120     MPX_DEBUG1("CMCPMusicPlayer::ConstructL <---");
       
   121     MPX_DEBUG1("CMCPMusicPlayer::ConstructL creating engine");
       
   122     iEngine = CAiPlayerPluginEngine::NewL( *this );
       
   123     MPX_DEBUG1("CMCPMusicPlayer::ConstructL engine created");
       
   124     AknsUtils::InitSkinSupportL();
       
   125     //Load Loc strings
       
   126     MPX_DEBUG1("CMCPMusicPlayer::ConstructL getting resource file");
       
   127     RFs fs;
       
   128     User::LeaveIfError(fs.Connect());
       
   129     CleanupClosePushL(fs);  
       
   130     TFileName fileName;
       
   131     TParse* parseObj = new(ELeave) TParse();
       
   132     TInt errInt = parseObj->Set( KResourceFile(),&KDC_APP_RESOURCE_DIR,NULL );
       
   133     if(KErrNone != errInt)
       
   134       {
       
   135       delete parseObj;
       
   136       User::Leave(errInt);
       
   137       }
       
   138     fileName = parseObj->FullName();
       
   139     delete parseObj;
       
   140     BaflUtils::NearestLanguageFile(fs,fileName);
       
   141     if(!BaflUtils::FileExists(fs,fileName))
       
   142         {
       
   143         User::Leave(KErrNotFound);
       
   144         }
       
   145     RResourceFile resourceFile;
       
   146     resourceFile.OpenL(fs,fileName);
       
   147     CleanupClosePushL(resourceFile);
       
   148     resourceFile.ConfirmSignatureL();
       
   149     GetLocalizedStringL(resourceFile, iGoToMusicBuffer, R_MUSICHOMESCREEN_GO_TO_MUSIC);
       
   150     GetLocalizedStringL(resourceFile, iOpeningBuffer, R_MUSICHOMESCREEN_OPENING);
       
   151     CleanupStack::PopAndDestroy(&resourceFile);
       
   152     CleanupStack::PopAndDestroy(&fs);
       
   153     MPX_DEBUG1("CMCPMusicPlayer::ConstructL resources loaded");
       
   154     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   155     TRAPD(err, iArtBitmapMask = AknsUtils::CreateBitmapL( skin, 
       
   156             KAknsIIDQgnHomePhotoMask ) );
       
   157     if (err == KErrNone)
       
   158         {
       
   159         AknIconUtils::DisableCompression(iArtBitmapMask);
       
   160         TSize size( 70 , 70);
       
   161         AknIconUtils::SetSize( iArtBitmapMask, size );
       
   162         if (iArtBitmapMask->SetDisplayMode( EGray256 ) != KErrNone)
       
   163             {
       
   164             delete iArtBitmapMask;
       
   165             iArtBitmapMask = NULL;
       
   166             }
       
   167         }
       
   168     else
       
   169         {
       
   170         delete iArtBitmapMask;
       
   171         iArtBitmapMask = NULL;
       
   172         }
       
   173     iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault );
       
   174     iHarvester = CMPXHarvesterFactory::NewL();
       
   175     iMusicPlayerOpeningTimer = CPeriodic::NewL( CActive::EPriorityLow );
       
   176     MPX_DEBUG1("CMCPMusicPlayer::ConstructL --->");
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // Two-phased constructor.
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 CMCPMusicPlayer* CMCPMusicPlayer::NewL(MMCPPluginObserver* aObserver)
       
   184     {
       
   185     CMCPMusicPlayer* self = new ( ELeave ) 
       
   186     CMCPMusicPlayer( aObserver );
       
   187     CleanupStack::PushL( self );
       
   188     self->ConstructL();
       
   189     CleanupStack::Pop( self );
       
   190     return self;
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // Destructor
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 CMCPMusicPlayer::~CMCPMusicPlayer()
       
   198     {
       
   199     MPX_DEBUG1("CMCPMusicPlayer::~CMCPMusicPlayer <---");
       
   200     if (iArtCached && iArtBitmap != iCachedArtBitmap)
       
   201         {
       
   202         delete iCachedArtBitmap;
       
   203         }
       
   204     delete iArtBitmap;
       
   205     delete iArtBitmapMask;
       
   206     delete iEngine;
       
   207     delete iFileMonitor;
       
   208     delete iAppMonitor;
       
   209     delete iPNSMonitor;
       
   210     delete iGoToMusicBuffer;
       
   211     delete iOpeningBuffer;
       
   212     if ( iCollectionUtility )
       
   213     	{
       
   214     	iCollectionUtility->Close();
       
   215     	}
       
   216     if ( iHarvester )
       
   217         {
       
   218         iHarvester->Close();
       
   219         }
       
   220     delete iMusicPlayerOpeningTimer;
       
   221     MPX_DEBUG1("CMCPMusicPlayer::~CMCPMusicPlayer --->");
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // 
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 TBool CMCPMusicPlayer::IsOKToPublishData()
       
   230     {
       
   231     return iActive;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // 
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CMCPMusicPlayer::InstallPlaybackCommandActionL(TMPXPlaybackCommand aCmd,
       
   239         TMCPTriggerDestination aDestination)
       
   240     {
       
   241     MPX_DEBUG1("CMCPMusicPlayer::InstallPlaybackCommandActionL <---");
       
   242     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   243     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   244     
       
   245     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10207C16 ) ) );
       
   246     mapData->InsertL( KType, TLiwVariant( KActionPlaybackCommand ) );
       
   247     TInt32 cmd;
       
   248     cmd=static_cast<TInt32>( aCmd );
       
   249     mapData->InsertL( KPBCommand, TLiwVariant( cmd ) );
       
   250     mapTrigger->InsertL( KData , TLiwVariant( mapData ) );
       
   251     
       
   252     iMHObserver->PublishActionL( this, aDestination, mapTrigger );
       
   253     
       
   254     CleanupStack::PopAndDestroy( mapData  );
       
   255     CleanupStack::PopAndDestroy( mapTrigger );
       
   256     MPX_DEBUG1("CMCPMusicPlayer::InstallPlaybackCommandActionL --->");
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // 
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CMCPMusicPlayer::InstallLaunchMusicPlayerL(
       
   264         TMCPTriggerDestination aDestination )
       
   265     {
       
   266     MPX_DEBUG1("CMCPMusicPlayer::InstallLaunchMusicPlayerL <---");
       
   267     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   268     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   269     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10282E5F ) ) );
       
   270     mapData->InsertL( KType, TLiwVariant( KLaunchApp ) );
       
   271     mapData->InsertL( KLaunchMethod, TLiwVariant( KCmdLine ) );
       
   272     mapData->InsertL(KApplicationUid,
       
   273             TLiwVariant(TInt32(KMusicPlayerAppUidAsTInt) ) );
       
   274     mapTrigger->InsertL( KData, TLiwVariant( mapData ) );
       
   275     
       
   276     iMHObserver->PublishActionL( this, aDestination, mapTrigger );
       
   277     
       
   278     CleanupStack::PopAndDestroy( mapData );
       
   279     CleanupStack::PopAndDestroy( mapTrigger );
       
   280     MPX_DEBUG1("CMCPMusicPlayer::InstallLaunchMusicPlayerL --->");
       
   281     }
       
   282 
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // 
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CMCPMusicPlayer::InstallGoToNowPlayingL(
       
   289         TMCPTriggerDestination aDestination )
       
   290     {
       
   291     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToNowPlayingL <---");
       
   292     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   293     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   294     
       
   295     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10207C16 ) ) );
       
   296     mapData->InsertL( KType, TLiwVariant( KactionMessageToMusicPlayer ) );
       
   297     mapData->InsertL( KMessage, TLiwVariant( KGoToNowPlaying ) );
       
   298     mapTrigger->InsertL( KData , TLiwVariant( mapData ) );
       
   299 
       
   300     iMHObserver->PublishActionL( this, aDestination, mapTrigger );
       
   301     
       
   302     CleanupStack::PopAndDestroy( mapData  );
       
   303     CleanupStack::PopAndDestroy( mapTrigger );
       
   304     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToNowPlayingL --->");
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // 
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 void CMCPMusicPlayer::InstallGoToLastPlayedL(
       
   312         TMCPTriggerDestination aDestination )
       
   313     {
       
   314     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToLastPlayedL <---");
       
   315     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   316     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   317     
       
   318     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10207C16 ) ) );
       
   319     mapData->InsertL( KType, TLiwVariant( KactionMessageToMusicPlayer ) );
       
   320     mapData->InsertL( KMessage, TLiwVariant( KGoToLastPlayedMinimized ) );
       
   321     mapTrigger->InsertL( KData , TLiwVariant( mapData ) );
       
   322 
       
   323     iMHObserver->PublishActionL( this, aDestination, mapTrigger );
       
   324     
       
   325     CleanupStack::PopAndDestroy( mapData  );
       
   326     CleanupStack::PopAndDestroy( mapTrigger );
       
   327     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToLastPlayedL --->");
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // 
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CMCPMusicPlayer::InstallGoToMusicL(
       
   335         TMCPTriggerDestination aDestination )
       
   336     {
       
   337     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToMusicL <---");
       
   338     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   339     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   340 
       
   341     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10282E5F ) ) );
       
   342     
       
   343     mapData->InsertL( KType, TLiwVariant( KLaunchApp ) );
       
   344     mapData->InsertL( KLaunchMethod, TLiwVariant( KMessageWithTail ) );
       
   345     mapData->InsertL(KApplicationUid,
       
   346             TLiwVariant(TInt32(KMmUid3AsTInt) ) );
       
   347         mapData->InsertL( KAdditionalData, 
       
   348             TLiwVariant( KMessageForMMOpenMusicSuiteWithHide ) );
       
   349     mapData->InsertL(KMessageUid,
       
   350             TLiwVariant(TInt32(KMSGUidAsTInt) ) );
       
   351     
       
   352     mapTrigger->InsertL( KData, TLiwVariant( mapData ) );
       
   353     
       
   354     iMHObserver->PublishActionL( this, aDestination, mapTrigger );
       
   355     
       
   356     CleanupStack::PopAndDestroy( mapData );
       
   357     CleanupStack::PopAndDestroy( mapTrigger );
       
   358     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToMusicL --->");
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // 
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 void CMCPMusicPlayer::InstallGoToAlbumL(
       
   366         TMCPTriggerDestination aDestination )
       
   367     {
       
   368     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToAlbumL <---");
       
   369     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   370     CLiwDefaultMap* mapData = CLiwDefaultMap::NewLC();
       
   371     
       
   372     mapTrigger->InsertL( KPluginUid, TLiwVariant( TUid::Uid( 0x10207C16 ) ) );
       
   373        mapData->InsertL( KType, TLiwVariant( KactionMessageToMusicPlayer ) );
       
   374        mapData->InsertL( KMessage, TLiwVariant( KGoToAlbumView ) );
       
   375     mapTrigger->InsertL( KData, TLiwVariant( mapData ) );
       
   376     
       
   377     iMHObserver->PublishActionL( this, aDestination, mapTrigger );
       
   378     
       
   379     CleanupStack::PopAndDestroy( mapData );
       
   380     CleanupStack::PopAndDestroy( mapTrigger );
       
   381     MPX_DEBUG1("CMCPMusicPlayer::InstallGoToAlbumL --->");
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // 
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CMCPMusicPlayer::InstallEmptyActionL(
       
   389         TMCPTriggerDestination aDestination )
       
   390     {
       
   391     MPX_DEBUG1("CMCPMusicPlayer::InstallEmptyActionL <---");
       
   392     CLiwDefaultMap* mapTrigger = CLiwDefaultMap::NewLC();
       
   393     iMHObserver->PublishActionL( this, aDestination, mapTrigger );
       
   394     CleanupStack::PopAndDestroy( mapTrigger );
       
   395     MPX_DEBUG1("CMCPMusicPlayer::InstallEmptyActionL --->");
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 // Installs actions and icons in the toolbar.
       
   400 // ---------------------------------------------------------------------------
       
   401 //
       
   402 
       
   403 void CMCPMusicPlayer::UpdateToolBarL(TUint aToolBarState)
       
   404     {
       
   405     MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL <---");
       
   406     if (IsOKToPublishData())
       
   407         {
       
   408         TInt updateState;
       
   409         //we update if there is a change on the state and if the new propery
       
   410         //was set.
       
   411         // updateState = ( new ^ old ) & new = new & ~old
       
   412         updateState = aToolBarState & ~iToolBarState;
       
   413         TAknsItemID iconId;
       
   414         
       
   415         if ( TBK::KSkeep_L & updateState )
       
   416             {
       
   417             iconId.Set( EAknsMajorGeneric, 
       
   418                     EAknsMinorGenericQgnPropImageTbPrev);
       
   419             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB1, iconId, 
       
   420                     KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_prev, 
       
   421                     EMbmMusichomescreeniconsQgn_prop_image_tb_prev_mask);
       
   422             InstallPlaybackCommandActionL(EPbCmdPrevious, 
       
   423                     EMusicWidgetTB1Trigger);
       
   424             iToolBarState |= TBK::KPlay_dimmed;
       
   425             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KSkeep_L");
       
   426             }
       
   427         
       
   428         if ( TBK::KSkeep_R & updateState )
       
   429             {
       
   430             iconId.Set( EAknsMajorGeneric, 
       
   431                     EAknsMinorGenericQgnPropImageTbNext);
       
   432             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB3, iconId, 
       
   433                     KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_next, 
       
   434                     EMbmMusichomescreeniconsQgn_prop_image_tb_next_mask);
       
   435             InstallPlaybackCommandActionL(EPbCmdNext, EMusicWidgetTB3Trigger);
       
   436             iToolBarState |= TBK::KSkeep_R;
       
   437             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KSkeep_R");
       
   438             }
       
   439         
       
   440         if ( TBK::KPause & updateState )
       
   441             {
       
   442             iconId.Set( EAknsMajorGeneric, 
       
   443                     EAknsMinorGenericQgnPropImageTbPause);
       
   444             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB2, iconId, 
       
   445                     KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_pause, 
       
   446                     EMbmMusichomescreeniconsQgn_prop_image_tb_pause_mask);
       
   447             InstallPlaybackCommandActionL(EPbCmdPlayPause,
       
   448                     EMusicWidgetTB2Trigger);
       
   449             iToolBarState |= TBK::KPause;
       
   450             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KPause");
       
   451             }
       
   452         
       
   453         if ( TBK::KPlay & updateState )
       
   454             {
       
   455             iconId.Set( EAknsMajorGeneric, 
       
   456                     EAknsMinorGenericQgnPropImageTbPlay2 );
       
   457             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB2, iconId,
       
   458                     KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_play2, 
       
   459                     EMbmMusichomescreeniconsQgn_prop_image_tb_play2_mask);
       
   460             InstallPlaybackCommandActionL(EPbCmdPlayPause, 
       
   461                     EMusicWidgetTB2Trigger);
       
   462             iToolBarState |= TBK::KPlay;
       
   463             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KPlay");
       
   464             }
       
   465         
       
   466         if ( TBK::KPlay_last_played & updateState )
       
   467             {
       
   468             iconId.Set( EAknsMajorGeneric, 
       
   469                     EAknsMinorGenericQgnPropImageTbPlay2 );
       
   470             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB2, iconId,
       
   471                     KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_play2, 
       
   472                     EMbmMusichomescreeniconsQgn_prop_image_tb_play2_mask);
       
   473             InstallGoToLastPlayedL(EMusicWidgetTB2Trigger); 
       
   474             iToolBarState |= TBK::KPlay_last_played;
       
   475             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KPlay_last_played");
       
   476             }
       
   477         
       
   478         if ( TBK::KSkeep_L_dimmed & updateState )
       
   479             {
       
   480             iconId.Set( EAknsMajorGeneric, 
       
   481                     EAknsMinorGenericQgnPropImageTbPrevDimmed);
       
   482             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB1, iconId, 
       
   483                     KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_prev_dimmed, 
       
   484                     EMbmMusichomescreeniconsQgn_prop_image_tb_prev_dimmed_mask);
       
   485             InstallEmptyActionL( EMusicWidgetTB1Trigger);
       
   486             iToolBarState |= TBK::KSkeep_L_dimmed;
       
   487             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KSkeep_L_dimmed");
       
   488             }
       
   489         
       
   490         if ( TBK::KSkeep_R_dimmed & updateState )
       
   491             {
       
   492             iconId.Set( EAknsMajorGeneric, 
       
   493                     EAknsMinorGenericQgnPropImageTbNextDimmed);
       
   494             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB3, iconId, 
       
   495                 KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_next_dimmed, 
       
   496                 EMbmMusichomescreeniconsQgn_prop_image_tb_next_dimmed_mask);
       
   497             InstallEmptyActionL( EMusicWidgetTB3Trigger);
       
   498             iToolBarState |= TBK::KSkeep_R_dimmed;
       
   499             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KSkeep_R_dimmed");
       
   500             }
       
   501         
       
   502         if ( TBK::KPause_dimmed & updateState )
       
   503             {
       
   504             iconId.Set( EAknsMajorGeneric, 
       
   505                     EAknsMinorGenericQgnPropImageTbPauseDimmed);
       
   506             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB2, iconId, 
       
   507                 KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_pause_dimmed, 
       
   508                 EMbmMusichomescreeniconsQgn_prop_image_tb_pause_dimmed_mask);
       
   509             InstallEmptyActionL( EMusicWidgetTB2Trigger);
       
   510             iToolBarState |= TBK::KPause_dimmed;
       
   511             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KPause_dimmed");
       
   512             }
       
   513         
       
   514         if ( TBK::KPlay_dimmed & updateState )
       
   515             {
       
   516             iconId.Set( EAknsMajorGeneric, 
       
   517                     EAknsMinorGenericQgnPropImageTbPlay2Dimmed);
       
   518             iMHObserver->PublishImageL( this, EMusicWidgetToolbarB2, iconId, 
       
   519                 KMIF, EMbmMusichomescreeniconsQgn_prop_image_tb_play2_dimmed, 
       
   520                 EMbmMusichomescreeniconsQgn_prop_image_tb_play2_dimmed_mask);
       
   521             InstallEmptyActionL( EMusicWidgetTB2Trigger);
       
   522             iToolBarState |= TBK::KPlay_dimmed;
       
   523             MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL KPlay_dimmed");
       
   524             }
       
   525         
       
   526         iToolBarState = aToolBarState;
       
   527         }
       
   528     MPX_DEBUG1("CMCPMusicPlayer::UpdateToolBarL <---");
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // Resets the widget an Music Suite.
       
   533 // ---------------------------------------------------------------------------
       
   534 //
       
   535 void CMCPMusicPlayer::ResetL()
       
   536     {
       
   537     MPX_DEBUG1("CMCPMusicPlayer::ResetL <---");
       
   538     //Note that we are not checking if IsOKToPublishData()This will only get
       
   539     //published if the plugin is still active on the music content publisher
       
   540     //meaning that no other plugin has preempted us.
       
   541     if ( iAppMonitor )
       
   542         {
       
   543         delete iAppMonitor;
       
   544         iAppMonitor = NULL;
       
   545         }
       
   546     if (iFileMonitor)
       
   547         {
       
   548         delete iFileMonitor;
       
   549         iFileMonitor = NULL;
       
   550         }
       
   551     if ( iPNSMonitor )
       
   552         {
       
   553         delete iPNSMonitor;
       
   554         iPNSMonitor = NULL;
       
   555         }
       
   556     //Reset
       
   557     iMHObserver->PublishTextL( this,EMusicWidgetDefaultText, iGoToMusicBuffer->Des() );
       
   558     iMHObserver->PublishImageL(this,EMusicWidgetImage1,KEmpty);
       
   559     InstallGoToAlbumL(EMusicWidgetTrigger1);
       
   560     iMHObserver->PublishTextL( this,EMusicWidgetText1, KEmpty );
       
   561     iMHObserver->PublishImageL(this,EMusicWidgetToolbarB1,KEmpty);
       
   562     iMHObserver->PublishImageL(this,EMusicWidgetToolbarB2,KEmpty);
       
   563     iMHObserver->PublishImageL(this,EMusicWidgetToolbarB3,KEmpty);
       
   564     InstallEmptyActionL(EMusicWidgetTB1Trigger);
       
   565     InstallEmptyActionL(EMusicWidgetTB2Trigger);
       
   566     InstallEmptyActionL(EMusicWidgetTB3Trigger);
       
   567     InstallGoToAlbumL(EMusicWidgetTrigger2);
       
   568     
       
   569     MPX_DEBUG1("CMCPMusicPlayer::ResetL --->");
       
   570     }
       
   571 
       
   572 // ----------------------------------------------------------------------------
       
   573 // Get a heap descriptor from the resource file
       
   574 // ----------------------------------------------------------------------------
       
   575 //
       
   576 void CMCPMusicPlayer::GetLocalizedStringL(RResourceFile& aResourceFile ,HBufC*& aRetBuf,
       
   577         TInt aResourceId )
       
   578    {
       
   579    MPX_DEBUG1("CMCPMusicPlayer::GetLocalizedStringL <---");
       
   580    HBufC8* dataBuffer = aResourceFile.AllocReadLC(aResourceId);
       
   581    TResourceReader theReader;
       
   582    theReader.SetBuffer(dataBuffer);
       
   583    aRetBuf = theReader.ReadHBufCL();
       
   584    CleanupStack::PopAndDestroy(dataBuffer);
       
   585    MPX_DEBUG1("CMCPMusicPlayer::GetLocalizedStringL --->");
       
   586    }
       
   587 
       
   588 // ----------------------------------------------------------------------------
       
   589 // Sets the plugin as active.
       
   590 // ----------------------------------------------------------------------------
       
   591 //
       
   592 void CMCPMusicPlayer::ActivateL()
       
   593     {
       
   594     MPX_DEBUG1("CMCPMusicPlayer::ActivateL <---");
       
   595     if ( iPNSMonitor )
       
   596         {
       
   597         delete iPNSMonitor;
       
   598         iPNSMonitor = NULL;
       
   599         MPX_DEBUG1("CMCPMusicPlayer::ActivateL pns monitor deleted");
       
   600         }
       
   601     iPNSMonitor = CPNSMonitor::NewL(*this);
       
   602     MPX_DEBUG1("CMCPMusicPlayer::ActivateL pns monitor created");
       
   603     iPNSMonitor->Start();
       
   604     if ( iAppMonitor )
       
   605         {
       
   606         delete iAppMonitor;
       
   607         iAppMonitor = NULL;
       
   608         }
       
   609     MPX_DEBUG1("CMCPMusicPlayer::ActivateL app monitor deleted");
       
   610     iAppMonitor = CApplicationMonitor::NewL(*this);
       
   611     MPX_DEBUG1("CMCPMusicPlayer::ActivateL app monitor created");
       
   612     TRAPD(err, 
       
   613             iAppMonitor->StartL( TUid::Uid( KMusicPlayerAppUidAsTInt ) ) 
       
   614           );
       
   615     MPX_DEBUG1("CMCPMusicPlayer::ActivateL app monitor started");
       
   616     if (KErrNone != err) //Music player is not running, it died somehow. 
       
   617         {
       
   618         MPX_DEBUG1("CMCPMusicPlayer::ActivateL music player is not running");
       
   619         if (iFileMonitor)
       
   620             {
       
   621             delete iFileMonitor;
       
   622             iFileMonitor = NULL;
       
   623             }
       
   624         MPX_DEBUG1("CMCPMusicPlayer::ActivateL file monitor deleted");
       
   625         const TDesC& uri = iEngine->Uri();
       
   626         if ( uri != KNullDesC )
       
   627             {
       
   628             MPX_DEBUG1("CMCPMusicPlayer::ActivateL uri is not null creatin file monitor");
       
   629             iFileMonitor = CFileMonitor::NewL(*this);
       
   630             iFileMonitor->StartL( uri );
       
   631             }
       
   632         iActive = EFalse;
       
   633         }
       
   634     else //Music player is running
       
   635         {
       
   636         MPX_DEBUG1("CMCPMusicPlayer::ActivateL music player is running, activating...");
       
   637         iMHObserver->BecameActiveL(this);
       
   638         iActive = ETrue;
       
   639         MPX_DEBUG1("CMCPMusicPlayer::ActivateL we are active now");
       
   640         
       
   641         iMHObserver->PublishTextL( this, EMusicWidgetDefaultText, KEmpty );
       
   642         InstallGoToNowPlayingL(EMusicWidgetTrigger1);
       
   643         DoUpdateTrackInfoL(iEngine->TitleL(), iEngine->Artist());
       
   644         iToolBarState = 0;
       
   645         DoUpdatePlayerStateL( iEngine->PlayerState() );
       
   646         DoUpdateAlbumArtL(iArtCached ? iCachedArtBitmap : iArtBitmap);
       
   647         }
       
   648     MPX_DEBUG1("CMCPMusicPlayer::ActivateL --->");
       
   649     }
       
   650 
       
   651 
       
   652 void CMCPMusicPlayer::DoUpdatePlayerStateL(TMPlayerState aState)
       
   653     {
       
   654     MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL <---");
       
   655     switch ( aState )
       
   656             {
       
   657             case EMPlayerStatePlaying:
       
   658                 {
       
   659                 MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL EMPlayerStatePlaying");
       
   660                 iMusicPlayerOpeningTimer->Cancel();
       
   661                 UpdateToolBarL(TBK::KSkeep_L|TBK::KPause|TBK::KSkeep_R);
       
   662                 break;
       
   663                 }
       
   664             case EMPlayerStatePaused:
       
   665                 {
       
   666                 MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL EMPlayerStatePaused");
       
   667                 UpdateToolBarL(TBK::KSkeep_L|TBK::KPlay|TBK::KSkeep_R);
       
   668                 break;
       
   669                 }
       
   670             case EMPlayerStateSeeking:
       
   671                 {
       
   672                 MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL EMPlayerStateSeeking");
       
   673                 UpdateToolBarL(TBK::KSkeep_L_dimmed |
       
   674                         TBK::KPlay_dimmed |
       
   675                         TBK::KSkeep_R_dimmed);
       
   676                 break;
       
   677                 }
       
   678             case EMPlayerStateStopped:
       
   679                 {
       
   680                 MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL EMPlayerStateStopped");
       
   681                 if ( iBlockingOperationOngoing )
       
   682                     {
       
   683                     UpdateToolBarL( TBK::KSkeep_L_dimmed |
       
   684                             TBK::KPlay_dimmed |
       
   685                             TBK::KSkeep_R_dimmed );
       
   686                     }
       
   687                 else
       
   688                     {
       
   689                     UpdateToolBarL(TBK::KSkeep_L|TBK::KPlay|TBK::KSkeep_R);
       
   690                     }
       
   691                 break;
       
   692                 }
       
   693             default:
       
   694                 MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL default");
       
   695                 break;
       
   696             }
       
   697     MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL --->");
       
   698     }
       
   699 
       
   700 void CMCPMusicPlayer::DoUpdateTrackInfoL(const TDesC& aTitle, const TDesC& aArtist)
       
   701     {
       
   702     MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL <---");
       
   703     if ( IsOKToPublishData() )
       
   704             {
       
   705             HBufC* nowPlayingForMM = HBufC::NewLC( aTitle.Length() + 
       
   706             		                               KSeparatorhyphen().Length() + aArtist.Length() );     
       
   707             TPtr nowPlayingForMMPtr = nowPlayingForMM->Des();
       
   708             if ( &aTitle && aTitle.Length() )
       
   709                 {
       
   710                 nowPlayingForMMPtr.Copy( aTitle );
       
   711                 }
       
   712             if ( &aArtist && aArtist.Length() )
       
   713                 {
       
   714                 nowPlayingForMMPtr.Append(KSeparatorhyphen);
       
   715                 nowPlayingForMMPtr.Append(aArtist);
       
   716                 }            
       
   717             iMHObserver->PublishTextL( this,EMusicWidgetText1, *nowPlayingForMM );
       
   718             CleanupStack::PopAndDestroy( nowPlayingForMM );
       
   719             MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL deliting file monitor");
       
   720             if (iFileMonitor)
       
   721                 {
       
   722                 delete iFileMonitor;
       
   723                 iFileMonitor = NULL;
       
   724                 }
       
   725             
       
   726             const TDesC& uri = iEngine->Uri();
       
   727             if ( uri != KNullDesC )
       
   728                 {
       
   729                 MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL creating file monitor");
       
   730                 iFileMonitor = CFileMonitor::NewL(*this);
       
   731                 iFileMonitor->StartL( uri );
       
   732                 }
       
   733             }
       
   734     MPX_DEBUG1("CMCPMusicPlayer::DoUpdatePlayerStateL --->");
       
   735     }
       
   736 
       
   737 void CMCPMusicPlayer::DoUpdatePlaybackPositionL(TInt /*aPosition*/)
       
   738     {
       
   739     /*
       
   740      * 
       
   741      * This code was left here in case some parts are helpfull
       
   742      *  in the future, here is some code that used to work, 
       
   743      *  Members and APIs used migh have changed.
       
   744      *  
       
   745         if ( IsOKToPublishData() )
       
   746             {
       
   747             const TInt KMPXMinSecSeparatorIndex = 2;
       
   748             const TInt KMPXOneSecInMicroSecs = 1000000;
       
   749             const TInt KMPXOneHourInSeconds = 60 * 60;
       
   750             const TInt KMPXTimeIndicatorLength = 16;
       
   751             
       
   752             TBuf<KMPXTimeIndicatorLength> elapsed;
       
   753             TBuf<KMPXTimeIndicatorLength> total;
       
   754         
       
   755             TInt64 playbackPosInSeconds;
       
   756             TInt64 totalLengthInSeconds;
       
   757         
       
   758             playbackPosInSeconds = aPosition;
       
   759             totalLengthInSeconds = iEngine->Duration();
       
   760             HBufC* longFormatString;
       
   761             HBufC* shortFormatString;
       
   762         
       
   763             longFormatString = StringLoader::LoadL(
       
   764                     R_QTN_TIME_DURAT_LONG_WITH_ZERO );
       
   765             shortFormatString = StringLoader::LoadL(
       
   766                     R_QTN_TIME_DURAT_MIN_SEC_WITH_ZERO) ;
       
   767             TPtrC format = *shortFormatString;
       
   768         
       
   769             if ( totalLengthInSeconds >= KMPXOneHourInSeconds )
       
   770                 {
       
   771                 // For tracks longer than an hour we use different time format and
       
   772                 //a slightly different layout which has more space for the time
       
   773                 //labels.
       
   774                 format.Set( *longFormatString );
       
   775                 }
       
   776         
       
   777             TTime elapsedTime( playbackPosInSeconds * KMPXOneSecInMicroSecs );
       
   778             TTime totalTime( totalLengthInSeconds * KMPXOneSecInMicroSecs );
       
   779         
       
   780             if ( aPosition == 0 )
       
   781                 {
       
   782                 totalLengthInSeconds = 0;
       
   783                 }
       
   784         
       
   785             // Convert total playing time to texts.
       
   786             elapsedTime.FormatL( elapsed, format );
       
   787         
       
   788             if ( totalLengthInSeconds )
       
   789                 {
       
   790                 // Time remaining
       
   791                 totalTime.FormatL( total, format );
       
   792                 }
       
   793             else
       
   794                 {
       
   795                 // Time remaining: --:--
       
   796                 TLocale locale;
       
   797                 TBuf<KMPXTimeIndicatorLength> pos;
       
   798                 TChar separator = locale.TimeSeparator(KMPXMinSecSeparatorIndex);
       
   799                 total = KMPXZeroDurationMark;
       
   800                 total.Append( separator );
       
   801                 total += KMPXZeroDurationMark;
       
   802                 }
       
   803         
       
   804             AknTextUtils::LanguageSpecificNumberConversion( elapsed );
       
   805             AknTextUtils::LanguageSpecificNumberConversion( total );
       
   806             TBuf<128> duration;
       
   807             TBuf<128> elapsedTimebuf;
       
   808         
       
   809             elapsedTimebuf.Copy( elapsed );
       
   810         
       
   811             duration.Copy( elapsed );
       
   812             duration.Append( KSeparator );
       
   813             duration.Append( total );
       
   814         
       
   815             iMHObserver->PublishTextL( this, EMusicWidgetText3, duration );
       
   816         
       
   817             delete longFormatString;
       
   818             delete shortFormatString;
       
   819             }
       
   820      */
       
   821     }
       
   822 
       
   823 void CMCPMusicPlayer::DoUpdateAlbumArtL( CFbsBitmap* aBitmap )
       
   824     {
       
   825     MPX_DEBUG1("CMCPMusicPlayer::DoUpdateAlbumArtL <---");
       
   826     //Make sure that iCachedArtBitmap is deleted or nulled in case it is an alias.
       
   827     //This ensures that the data is not double deleted nor orphan.
       
   828     if ( iCachedArtBitmap && iCachedArtBitmap !=  aBitmap  && iCachedArtBitmap != iArtBitmap)
       
   829         {
       
   830         MPX_DEBUG1("CMCPMusicPlayer::DoUpdateAlbumArtL delete iCachedArtBitmap");
       
   831         delete iCachedArtBitmap;
       
   832         }
       
   833     iCachedArtBitmap = NULL;
       
   834     //Store the new bitmap.
       
   835     if ( aBitmap != iArtBitmap )
       
   836         {
       
   837         MPX_DEBUG1("CMCPMusicPlayer::DoUpdateAlbumArtL delete iArtBitmap");
       
   838         delete iArtBitmap;
       
   839         }
       
   840     iArtBitmap = aBitmap;
       
   841     iArtCached = EFalse;
       
   842     
       
   843     if (iArtBitmap)
       
   844         {
       
   845         TInt handle = iArtBitmap->Handle();
       
   846         if (iArtBitmapMask)
       
   847             {
       
   848             TInt mskHandle = iArtBitmapMask->Handle();
       
   849             iMHObserver->PublishImageL(this,EMusicWidgetImage1,handle,
       
   850                     mskHandle);
       
   851             }
       
   852         else
       
   853             {
       
   854             iMHObserver->PublishImageL(this,EMusicWidgetImage1,handle);
       
   855             }
       
   856         }
       
   857     else
       
   858         {
       
   859         iMHObserver->PublishImageL( this, EMusicWidgetImage1,
       
   860                     KAknsIIDQgnIndiMupDefaultAlbum, 
       
   861                     KMIF, EMbmMusichomescreeniconsQgn_indi_mup_default_album, 
       
   862                     EMbmMusichomescreeniconsQgn_indi_mup_default_album_mask);
       
   863         }
       
   864     MPX_DEBUG1("CMCPMusicPlayer::DoUpdateAlbumArtL --->");
       
   865     }
       
   866 
       
   867 void CMCPMusicPlayer::DoHandleOpeningL()
       
   868     {
       
   869     MPX_DEBUG1("CMCPMusicPlayer::DoHandleOpeningL <---");
       
   870     if ( IsOKToPublishData() )
       
   871         {
       
   872         iMHObserver->PublishTextL( this,EMusicWidgetText1, iOpeningBuffer->Des() );
       
   873         }
       
   874     MPX_DEBUG1("CMCPMusicPlayer::DoHandleOpeningL --->");
       
   875     }
       
   876 
       
   877 void CMCPMusicPlayer::DoHandlePlaylisIsEmptyL()
       
   878     {
       
   879     MPX_DEBUG1("CMCPMusicPlayer::DoHandlePlaylisIsEmptyL <---");
       
   880     iActive = EFalse;
       
   881     ResetL();
       
   882     MPX_DEBUG1("CMCPMusicPlayer::DoHandlePlaylisIsEmptyL --->");
       
   883     }
       
   884 void CMCPMusicPlayer::DoHandleSkinChangedL()
       
   885     {
       
   886     MPX_DEBUG1("CMCPMusicPlayer::DoHandleSkinChangedL <---");
       
   887     //To make sure the mask gets recreated even if we don't use it right now.
       
   888     delete iArtBitmapMask;
       
   889     iArtBitmapMask = NULL;
       
   890     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   891     
       
   892     TRAPD(err, iArtBitmapMask = AknsUtils::CreateBitmapL( skin, 
       
   893             KAknsIIDQgnHomePhotoMask ) );
       
   894     if (err == KErrNone)
       
   895         {
       
   896         AknIconUtils::DisableCompression(iArtBitmapMask);
       
   897         TSize size( 70 , 70);
       
   898         AknIconUtils::SetSize( iArtBitmapMask, size );
       
   899         if (iArtBitmapMask->SetDisplayMode( EGray256 ) != KErrNone)
       
   900             {
       
   901             delete iArtBitmapMask;
       
   902             iArtBitmapMask = NULL;
       
   903             }
       
   904         }
       
   905     else
       
   906         {
       
   907         delete iArtBitmapMask;
       
   908         iArtBitmapMask = NULL;
       
   909         }
       
   910     
       
   911     if (iArtBitmap)
       
   912         {
       
   913         TInt handle = iArtBitmap->Handle();
       
   914         if (iArtBitmapMask)
       
   915             {
       
   916             TInt mskHandle = iArtBitmapMask->Handle();
       
   917             iMHObserver->PublishImageL(
       
   918                     this,
       
   919                     EMusicWidgetImage1,
       
   920                     handle, 
       
   921                     mskHandle);
       
   922             }
       
   923         else
       
   924             {
       
   925             iMHObserver->PublishImageL(
       
   926                     this,
       
   927                     EMusicWidgetImage1,
       
   928                     handle);
       
   929             }
       
   930         }
       
   931     else
       
   932         {
       
   933         iMHObserver->PublishImageL( this, EMusicWidgetImage1,
       
   934                     KAknsIIDQgnIndiMupDefaultAlbum, 
       
   935                     KMIF, EMbmMusichomescreeniconsQgn_indi_mup_default_album, 
       
   936                     EMbmMusichomescreeniconsQgn_indi_mup_default_album_mask);
       
   937         }
       
   938        
       
   939     TUint tbstate = iToolBarState;
       
   940     //To Force a change on the toolbar with the current properties.
       
   941     iToolBarState = 0;
       
   942     if (!iActive)
       
   943         {
       
   944         //This is to force the icons to update, but we still want to keep
       
   945         //the plugin as incative.
       
   946         iActive = ETrue;
       
   947         UpdateToolBarL(tbstate);
       
   948         iActive = EFalse;
       
   949         }
       
   950     else
       
   951         {
       
   952         UpdateToolBarL(tbstate);
       
   953         }
       
   954     MPX_DEBUG1("CMCPMusicPlayer::DoHandleSkinChangedL --->");
       
   955     }
       
   956    
       
   957 
       
   958 
       
   959 // ---------------------------------------------------------------------------
       
   960 // From CMCPPlugin
       
   961 // ---------------------------------------------------------------------------
       
   962 //  
       
   963 void CMCPMusicPlayer::Deactivate()
       
   964     {
       
   965     MPX_DEBUG1("CMCPMusicPlayer::Deactivate() <---");
       
   966     iActive = EFalse;
       
   967     if (iFileMonitor)
       
   968         {
       
   969         delete iFileMonitor;
       
   970         iFileMonitor = NULL;
       
   971         }
       
   972     if (iAppMonitor)
       
   973         {
       
   974         delete iAppMonitor;
       
   975         iAppMonitor = NULL;
       
   976         }
       
   977     if ( iPNSMonitor )
       
   978         {
       
   979         delete iPNSMonitor;
       
   980         iPNSMonitor = NULL;
       
   981         }
       
   982     MPX_DEBUG1("CMCPMusicPlayer::Deactivate() --->");
       
   983     }
       
   984 
       
   985 // ---------------------------------------------------------------------------
       
   986 // From CMCPPlugin
       
   987 // ---------------------------------------------------------------------------
       
   988 //  
       
   989 void CMCPMusicPlayer::SkinChanged()
       
   990     {
       
   991     MPX_DEBUG1("CMCPMusicPlayer::SkinChanged() <---");
       
   992     TRAP_IGNORE( DoHandleSkinChangedL() );
       
   993     MPX_DEBUG1("CMCPMusicPlayer::SkinChanged() --->");
       
   994     }
       
   995 
       
   996 // ---------------------------------------------------------------------------
       
   997 // From MAiPlayerPluginEngineObserver
       
   998 // ---------------------------------------------------------------------------
       
   999 //  
       
  1000 void CMCPMusicPlayer::PlayerStateChanged( TMPlayerState aState )
       
  1001     {
       
  1002     MPX_DEBUG1("CMCPMusicPlayer::PlayerStateChanged <---");
       
  1003     //we want to activate only with states that can be triggered by the user.
       
  1004     if (!iActive && 
       
  1005 	        aState == EMPlayerStatePlaying)
       
  1006         {
       
  1007         //ActivateL updates the whole widget and music suite data.
       
  1008         MPX_DEBUG1("CMCPMusicPlayer::PlayerStateChanged activating");
       
  1009         TRAP_IGNORE( ActivateL() );
       
  1010         }
       
  1011     else
       
  1012         {
       
  1013         MPX_DEBUG1("CMCPMusicPlayer::PlayerStateChanged updating state");
       
  1014         TRAP_IGNORE(DoUpdatePlayerStateL(aState));
       
  1015         }
       
  1016     MPX_DEBUG1("CMCPMusicPlayer::PlayerStateChanged --->");
       
  1017     }
       
  1018 
       
  1019 // ---------------------------------------------------------------------------
       
  1020 // From MAiPlayerPluginEngineObserver
       
  1021 // ---------------------------------------------------------------------------
       
  1022 //  
       
  1023 void CMCPMusicPlayer::TrackInfoChanged( const TDesC& aTitle, 
       
  1024         const TDesC& aArtist )
       
  1025     
       
  1026     {
       
  1027     MPX_DEBUG1("CMCPMusicPlayer::TrackInfoChanged <---");
       
  1028     if (iActive)
       
  1029         {
       
  1030         MPX_DEBUG1("CMCPMusicPlayer::TrackInfoChanged updating track info");
       
  1031         TRAP_IGNORE(DoUpdateTrackInfoL(aTitle, aArtist));
       
  1032         }
       
  1033     MPX_DEBUG1("CMCPMusicPlayer::TrackInfoChanged --->");
       
  1034     }
       
  1035 
       
  1036 // ---------------------------------------------------------------------------
       
  1037 // From MAiPlayerPluginEngineObserver
       
  1038 // ---------------------------------------------------------------------------
       
  1039 //  
       
  1040 void CMCPMusicPlayer::PlaybackPositionChanged( TInt aPosition )
       
  1041     {
       
  1042     TRAP_IGNORE( DoUpdatePlaybackPositionL( aPosition ) );
       
  1043     }
       
  1044 
       
  1045 // ---------------------------------------------------------------------------
       
  1046 // From MAiPlayerPluginEngineObserver
       
  1047 // ---------------------------------------------------------------------------
       
  1048 // 
       
  1049 void CMCPMusicPlayer::AlbumArtChanged( CFbsBitmap* aBitmap )
       
  1050     {
       
  1051     MPX_DEBUG1("CMCPMusicPlayer::AlbumArtChanged <---");
       
  1052     if (!iActive)
       
  1053         {
       
  1054         if (iCachedArtBitmap) 
       
  1055             {
       
  1056             MPX_DEBUG2("CMCPMusicPlayer::AlbumArtChanged dropping bitmap %x", iCachedArtBitmap);
       
  1057             delete iCachedArtBitmap;
       
  1058             } 
       
  1059         iCachedArtBitmap = aBitmap;
       
  1060         iArtCached = ETrue;
       
  1061         }
       
  1062     else
       
  1063         {
       
  1064         MPX_DEBUG1("CMCPMusicPlayer::AlbumArtChanged updating album art");
       
  1065         TRAP_IGNORE( DoUpdateAlbumArtL( aBitmap ) );
       
  1066         }
       
  1067     MPX_DEBUG1("CMCPMusicPlayer::AlbumArtChanged --->");
       
  1068     }
       
  1069 
       
  1070 // ---------------------------------------------------------------------------
       
  1071 // From MAiPlayerPluginEngineObserver
       
  1072 // ---------------------------------------------------------------------------
       
  1073 //  
       
  1074 void CMCPMusicPlayer::Opening()
       
  1075     {
       
  1076     MPX_DEBUG1("CMCPMusicPlayer::Opening <---");
       
  1077     TRAP_IGNORE( DoHandleOpeningL() );
       
  1078     MPX_DEBUG1("CMCPMusicPlayer::Opening --->");
       
  1079     }
       
  1080 
       
  1081 
       
  1082 // ---------------------------------------------------------------------------
       
  1083 // From MAiPlayerPluginEngineObserver
       
  1084 // ---------------------------------------------------------------------------
       
  1085 //  
       
  1086 void CMCPMusicPlayer::PlaylisIsEmpty()
       
  1087     {
       
  1088     TRAP_IGNORE( DoHandlePlaylisIsEmptyL() );
       
  1089     }
       
  1090 // ---------------------------------------------------------------------------
       
  1091 // From MAiPlayerPluginEngineObserver
       
  1092 // ---------------------------------------------------------------------------
       
  1093 //  
       
  1094 void CMCPMusicPlayer::HandleFileRemovedL()
       
  1095     {
       
  1096     MPX_DEBUG1("CMCPMusicPlayer::HandleFileRemovedL <---");
       
  1097     iActive = EFalse;
       
  1098     ResetL();
       
  1099     MPX_DEBUG1("CMCPMusicPlayer::HandleFileRemovedL --->");
       
  1100     }
       
  1101 
       
  1102 
       
  1103 // ---------------------------------------------------------------------------
       
  1104 // From MApplicationMonitorObserver
       
  1105 // ---------------------------------------------------------------------------
       
  1106 // 
       
  1107 void CMCPMusicPlayer::HandleApplicationClosedL(TExitType aReason)
       
  1108     {
       
  1109     MPX_DEBUG1("CMCPMusicPlayer::HandleApplicationClosedL <---");
       
  1110     if (aReason == EExitPanic)
       
  1111         {
       
  1112         MPX_DEBUG1("CMCPMusicPlayer::HandleApplicationClosedL panic");
       
  1113         iActive = EFalse;
       
  1114         ResetL();
       
  1115         }
       
  1116     else
       
  1117         {
       
  1118         MPX_DEBUG1("CMCPMusicPlayer::HandleApplicationClosedL normal close");
       
  1119         UpdateToolBarL( TBK::KSkeep_L_dimmed |
       
  1120                 TBK::KPlay_last_played |
       
  1121                 TBK::KSkeep_R_dimmed );
       
  1122         if (IsOKToPublishData() )
       
  1123             {
       
  1124             iMHObserver->PublishTextL( this, EMusicWidgetDefaultText, KEmpty );
       
  1125             DoUpdateTrackInfoL(iEngine->TitleL(), iEngine->Artist());
       
  1126             DoUpdateAlbumArtL(iArtCached ? iCachedArtBitmap : iArtBitmap);
       
  1127             }
       
  1128         if ( iAppMonitor )
       
  1129             {
       
  1130             MPX_DEBUG1("CMCPMusicPlayer::HandleApplicationClosedL deliting app monitor");
       
  1131             delete iAppMonitor;
       
  1132             iAppMonitor = NULL;
       
  1133             }
       
  1134         
       
  1135         iActive = EFalse;
       
  1136         //in case the app closed before the info was updated.
       
  1137         if (iEngine->TitleL() == KNullDesC)
       
  1138             {
       
  1139             MPX_DEBUG1("CMCPMusicPlayer::HandleApplicationClosedL there is no title - resetting");
       
  1140             ResetL();
       
  1141             }
       
  1142         }
       
  1143     MPX_DEBUG1("CMCPMusicPlayer::HandleApplicationClosedL --->");
       
  1144     }
       
  1145 // ---------------------------------------------------------------------------
       
  1146 // From MMPXCollectionObserver
       
  1147 // Handle collection messages.
       
  1148 // ---------------------------------------------------------------------------
       
  1149 //
       
  1150 void CMCPMusicPlayer::HandleCollectionMessage( CMPXMessage* aMsg, TInt aErr )
       
  1151     {
       
  1152     MPX_DEBUG1("--->CMCPMusicPlayer::HandleCollectionMessage()");
       
  1153     if ( aErr == KErrNone && aMsg )
       
  1154         {
       
  1155         TRAP_IGNORE( HandleCollectionMessageL( aMsg ));
       
  1156         }
       
  1157     MPX_DEBUG1("<---CMCPMusicPlayer::HandleCollectionMessage()");
       
  1158     }
       
  1159 // ---------------------------------------------------------------------------
       
  1160 // Handle collection messages.
       
  1161 // ---------------------------------------------------------------------------
       
  1162 //
       
  1163 void CMCPMusicPlayer::HandleCollectionMessageL( CMPXMessage* aMsg )
       
  1164     {
       
  1165     MPX_DEBUG1("--->CMCPMusicPlayer::HandleCollectionMessageL()");
       
  1166     TMPXMessageId messageId = aMsg->ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId );
       
  1167     if ( messageId == KMPXMessageGeneral )
       
  1168         {
       
  1169         DoHandleGeneralMessageL( *aMsg );
       
  1170         }
       
  1171     MPX_DEBUG1("<---CMCPMusicPlayer::HandleCollectionMessageL()");
       
  1172     }
       
  1173 // ---------------------------------------------------------------------------
       
  1174 // Handle collection general message.
       
  1175 // ---------------------------------------------------------------------------
       
  1176 //
       
  1177 void CMCPMusicPlayer::DoHandleGeneralMessageL(const CMPXMessage& aMsg)
       
  1178     {
       
  1179     TInt event = aMsg.ValueTObjectL<TInt> ( KMPXMessageGeneralEvent );
       
  1180     TInt type = aMsg.ValueTObjectL<TInt> ( KMPXMessageGeneralType );
       
  1181     MPX_DEBUG3("--->CMCPMusicPlayer::DoHandleGeneralMessageL(), event = %d, type = %d", event, type);
       
  1182 
       
  1183     
       
  1184     if ( event == TMPXCollectionMessage::EBroadcastEvent
       
  1185         && ( type == EMcMsgUSBMassStorageStart || 
       
  1186              type == EMcMsgUSBMTPStart ||
       
  1187              type == EMcMsgRefreshStart ))
       
  1188         {
       
  1189         iBlockingOperationOngoing = ETrue;
       
  1190         MPX_DEBUG2("CMCPMusicPlayer::DoHandleGeneralMessageL(), iBlockingOperationOngoing changed to: %d", 
       
  1191                   iBlockingOperationOngoing );
       
  1192         UpdateToolBarL( TBK::KSkeep_L_dimmed |
       
  1193                 TBK::KPlay_dimmed |
       
  1194                 TBK::KSkeep_R_dimmed );
       
  1195         }
       
  1196     else if ( event == TMPXCollectionMessage::EBroadcastEvent
       
  1197             && ( type == EMcMsgUSBMassStorageEnd || 
       
  1198                  type == EMcMsgUSBMTPEnd ||
       
  1199                  type == EMcMsgRefreshEnd ))
       
  1200         {
       
  1201         iBlockingOperationOngoing = EFalse;
       
  1202         MPX_DEBUG2("CMCPMusicPlayer::DoHandleGeneralMessageL(), iBlockingOperationOngoing changed to: %d", 
       
  1203                    iBlockingOperationOngoing );
       
  1204         DoUpdatePlayerStateL( iEngine->PlayerState() );
       
  1205         if ( IsOKToPublishData() )
       
  1206             {
       
  1207             iMHObserver->PublishTextL( this, EMusicWidgetDefaultText,
       
  1208                     KEmpty );
       
  1209             DoUpdateTrackInfoL( iEngine->TitleL(), iEngine->Artist() );
       
  1210             DoUpdateAlbumArtL( iArtCached ? iCachedArtBitmap : iArtBitmap );
       
  1211             }
       
  1212         }
       
  1213     MPX_DEBUG3("<---CMCPMusicPlayer::DoHandleGeneralMessageL(), event = %d, type = %d", event, type);
       
  1214     }
       
  1215 // ---------------------------------------------------------------------------
       
  1216 // From MMPXCollectionObserver
       
  1217 // ---------------------------------------------------------------------------  
       
  1218 //
       
  1219 void CMCPMusicPlayer::HandleOpenL( const CMPXMedia& /*aEntries*/,
       
  1220         TInt /*aIndex*/, TBool /*aComplete*/, TInt /*aError*/ )
       
  1221     {
       
  1222     // Do nothing
       
  1223     }
       
  1224 
       
  1225 // ---------------------------------------------------------------------------
       
  1226 // From MMPXCollectionObserver
       
  1227 // ---------------------------------------------------------------------------
       
  1228 //
       
  1229 void CMCPMusicPlayer::HandleOpenL( const CMPXCollectionPlaylist& /*aPlaylist*/,
       
  1230         TInt /*aError*/ )
       
  1231     {
       
  1232     // Do nothing
       
  1233     }
       
  1234 
       
  1235 // ---------------------------------------------------------------------------
       
  1236 // From MMPXCollectionMediaObserver
       
  1237 // ---------------------------------------------------------------------------
       
  1238 void CMCPMusicPlayer::HandleCollectionMediaL( const CMPXMedia& /*aMedia*/, TInt /*aError*/ )
       
  1239     {
       
  1240     // Do nothing
       
  1241     }
       
  1242 
       
  1243 // ---------------------------------------------------------------------------
       
  1244 // From MPNSMonitorObserver
       
  1245 // ---------------------------------------------------------------------------
       
  1246 // 
       
  1247 void CMCPMusicPlayer::OpeningMusicPlayer()
       
  1248     {
       
  1249     MPX_DEBUG1("CMCPMusicPlayer::OpeningMusicPlayer <---");
       
  1250     // in this position, iActive is EFalse, so we can not call function
       
  1251     // DoHandleOpeningL() directly.
       
  1252     TRAP_IGNORE( 
       
  1253             iMHObserver->PublishTextL( this,
       
  1254                     EMusicWidgetText1,
       
  1255                     iOpeningBuffer->Des() ) );
       
  1256     
       
  1257     TCallBack cb( MusicPlayerOpeningTimerCallback, this );
       
  1258     iMusicPlayerOpeningTimer->Cancel();
       
  1259     iMusicPlayerOpeningTimer->Start( KMusicPlayerOpeningTimerInterval,
       
  1260             KMusicPlayerOpeningTimerInterval, cb );
       
  1261 
       
  1262     MPX_DEBUG1("CMCPMusicPlayer::OpeningMusicPlayer --->");
       
  1263     }
       
  1264 
       
  1265 // ----------------------------------------------------------------------------
       
  1266 // Music Player opening timer callback
       
  1267 // ----------------------------------------------------------------------------
       
  1268 //
       
  1269 TInt CMCPMusicPlayer::MusicPlayerOpeningTimerCallback( TAny* aPtr )
       
  1270     {
       
  1271     MPX_DEBUG1("CMCPMusicPlayer::MusicPlayerOpeningTimerCallback <---");     
       
  1272     if ( EMPlayerStatePlaying != static_cast<CMCPMusicPlayer*>(aPtr)->iEngine->PlayerState() )
       
  1273         {
       
  1274         MPX_DEBUG1("CMCPMusicPlayer::MusicPlayerOpeningTimerCallback Music Player not Playing");
       
  1275         //Reset the widget and menu, music player is not running and playing.
       
  1276         static_cast<CMCPMusicPlayer*>(aPtr)->iActive = EFalse;
       
  1277         TRAP_IGNORE( static_cast<CMCPMusicPlayer*>(aPtr)->ResetL() );
       
  1278         }
       
  1279     static_cast<CMCPMusicPlayer*>(aPtr)->iMusicPlayerOpeningTimer->Cancel();
       
  1280     
       
  1281     MPX_DEBUG1("CMCPMusicPlayer::MusicPlayerOpeningTimerCallback --->");
       
  1282     return KErrNone;
       
  1283     }
       
  1284  //  End of File