mpxplugins/viewplugins/views/commonplaybackview/src/mpxcommonplaybackviewimp.cpp
changeset 0 ff3acec5bc43
child 1 8118492f1bdf
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Implementation of Common Playback view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <aknViewAppUi.h>
       
    22 #include <eikmenub.h>
       
    23 #include <featmgr.h>
       
    24 #include <StringLoader.h>
       
    25 #include <eikapp.h>
       
    26 #include <AknUtils.h>
       
    27 #include <akntitle.h>
       
    28 #include <aknnotewrappers.h>
       
    29 #include <aknnavi.h>
       
    30 #include <hlplch.h>
       
    31 #include <bautils.h>
       
    32 #include <centralrepository.h>
       
    33 #include <avkon.hrh>
       
    34 #include <avkon.rsg>
       
    35 #include <bldvariant.hrh>
       
    36 #include <caf/caferr.h>
       
    37 #include <aknsoundsystem.h>
       
    38 #include <AknDlgShut.h>
       
    39 #include <ctsydomainpskeys.h>
       
    40 #include <aknclearer.h>
       
    41 
       
    42 
       
    43 #include <e32const.h>
       
    44 #ifdef UPNP_INCLUDED
       
    45 #include <upnpcopycommand.h> 
       
    46 #endif
       
    47 
       
    48 #include <apgcli.h> // For FF_FMTX
       
    49 #include <AknWaitDialog.h>
       
    50 
       
    51 #include <aknSDData.h>
       
    52 #include <AknMediatorFacade.h>
       
    53 #include "mplayersecondarydisplayapi.h"
       
    54 
       
    55 #include <data_caging_path_literals.hrh>
       
    56 #include <layoutmetadata.cdl.h>
       
    57 #include <mpxcommonplaybackview.rsg>
       
    58 
       
    59 
       
    60 #include <mpxfmtx.rsg>
       
    61 #include <mpxcommonui.rsg>
       
    62 #include <mpxplaybackutility.h>
       
    63 #include <mpxplaybackmessage.h>
       
    64 #include <mpxmessagegeneraldefs.h>
       
    65 #include <mpxplaybackmessagedefs.h>
       
    66 #include <mpxcollectionplaylist.h>
       
    67 #include <mpxcollectionpath.h>
       
    68 #include <mpxcollectionmessage.h>
       
    69 #include <mpxviewutility.h>
       
    70 #include <mpxmusicplayerviewplugin.hrh>
       
    71 #include <mpxmedia.h>
       
    72 #include <mpxmediaarray.h>
       
    73 #include <mpxmediageneraldefs.h>
       
    74 #include <mpxmediamusicdefs.h>
       
    75 #include <mpxmediadrmdefs.h>
       
    76 #include <mpxmediacontainerdefs.h>
       
    77 #include <mpxcollectionutility.h>
       
    78 #include <mpxcollectionhelperfactory.h>
       
    79 #include <mpxviewplugin.h>
       
    80 #include <mpxviewpluginmanager.h>
       
    81 #include <mpxmusicplayerviewplugin.hrh>
       
    82 #include <mpxsubscription.h>
       
    83 #include <mpxuser.h>
       
    84 #include <mpxpskeywatcher.h>
       
    85 #include <mpxcenrepwatcher.h>
       
    86 #include <hwrmfmtx.h> // TFmTxState
       
    87 #include <AiwServiceHandler.h>
       
    88 #include <mediarecognizer.h>
       
    89 #ifdef BACKSTEPPING_INCLUDED
       
    90 #include <mpxbacksteppingutility.h>
       
    91 #endif // BACKSTEPPING_INCLUDED
       
    92 #include <UsbWatcherInternalPSKeys.h>
       
    93 #include <usbpersonalityids.h>
       
    94 
       
    95 #include "mpxconstants.h"
       
    96 #include <mpxappui.hrh>
       
    97 #include "mpxcommonplaybackview.hrh"
       
    98 #include "mpxcommonplaybackviewimp.h"
       
    99 #include "mpxcommonplaybackviewcontainer.h"
       
   100 #include "mpxcommonplaybackviewlayout.h"
       
   101 #include "mpxalbumartutil.h"
       
   102 #include "mpxcommonuihelper.h"
       
   103 #include <mpxinternalcrkeys.h>
       
   104 #include <mpxtlshelper.h>
       
   105 #include "mpxlog.h"
       
   106 
       
   107 #include <akntoolbar.h>
       
   108 #include <aknbutton.h>
       
   109 #include "mpxviewprivatepskeys.h"
       
   110 
       
   111 // CONSTANTS
       
   112 const TInt KMPXOneSecInMilliSecs( 1000 );
       
   113 const TUid KMPXEqualizerViewImplementationId = { 0x101FFC77 };
       
   114 const TInt KMPXPostponeForHandleDelayedError( 1000000 ); // 1S
       
   115 const TInt KMPXPlaybackViewWindowBackground = -1;
       
   116 
       
   117 // for freqency display in the format of "XXX.XX"
       
   118 const TInt KMPXFMFreqWidth        = 6;
       
   119 const TInt KMPXFMFreqDecimalPlace = 2;
       
   120 const TInt KMPXOneMhzInOneKhz     = 1000;
       
   121 const TUid KFmTxAppUid            = { 0x10282BEF };
       
   122 
       
   123 #ifdef BACKSTEPPING_INCLUDED
       
   124 const TInt KMaxIntLen( 10 );
       
   125 _LIT8( KMVPrefix, "MVviewID:" );
       
   126 const TInt KMVPrefixLen( 9 );
       
   127 #endif // BACKSTEPPING_INCLUDED
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // NOTE: All the FM Tx related values below originated from the files:
       
   131 //       - HWRMFmTx.h
       
   132 //       - HWRMFmTxDomainCRKeys.h
       
   133 //       - HWRMFmTxDomainPSKeys.h
       
   134 //
       
   135 //       These values should be kept in sync with the original copies.  The
       
   136 //       intention of keeping a copy here is to de-couple the MPX Music Player
       
   137 //       from the Hardware Resource Manager who is the owner of the keys, as
       
   138 //       FM Tx is not yet available for the platform.  Eventually, this should
       
   139 //       be removed as FM Tx becomes part of the platform.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 const TUid KCRUidFmTxCenRes = { 0x20008EA6 }; // FM TX Repository ID
       
   143 const TUid KPSUidHWRMFmTx   = { 0x101F7A02 }; // FM TX category ID
       
   144 
       
   145 // FM Tx frequency (kHz) key ID of the FM TX CenRep
       
   146 const TUint32 KFmTxCenResKeyFrequency = 0x00000001;
       
   147 
       
   148 // FM Transmitter status key ID of the FM TX property.
       
   149 // Note: This data is interpreted as TFmTxState below
       
   150 const TUint32 KHWRMFmTxStatus  = 0x00000001;
       
   151 
       
   152 _LIT( KMPXCommonPlaybackRscPath, "mpxcommonplaybackview.rsc" );
       
   153 
       
   154 _LIT( KMPXFMTXRscPath, "mpxfmtx.rsc" );
       
   155 
       
   156 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   157 _LIT(KMPXPnRealAudioMimeType, "audio/x-pn-realaudio");
       
   158 _LIT(KMPXRealAudioMimeType, "audio/x-realaudio");
       
   159 _LIT(KMPXRnRealAudioMimeType, "audio/vnd.rn-realaudio");
       
   160 #endif
       
   161 
       
   162 
       
   163 // ======== MEMBER FUNCTIONS ========
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Symbian 2nd phase constructor can leave.
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C void CMPXCommonPlaybackViewImp::ConstructL()
       
   171     {
       
   172     MPX_FUNC( "CMPXCommonPlaybackViewImp::ConstructL" );
       
   173 
       
   174     CCoeEnv* coeEnv = iEikonEnv;
       
   175     TParse parse;
       
   176     parse.Set( KMPXCommonPlaybackRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
   177     TFileName resourceFile( parse.FullName() );
       
   178     User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) );
       
   179     BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile );
       
   180     iResourceOffset = coeEnv->AddResourceFileL( resourceFile );
       
   181 
       
   182 	if ( FeatureManager::FeatureSupported( KFeatureIdFmtx ) )
       
   183 		{
       
   184     	parse.Set( KMPXFMTXRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
   185     	TFileName fmtxResourceFile( parse.FullName() );
       
   186     	User::LeaveIfError( MPXUser::CompleteWithDllPath( fmtxResourceFile ) );
       
   187     	BaflUtils::NearestLanguageFile( coeEnv->FsSession(), fmtxResourceFile );
       
   188     	iFMTXResourceOffset = coeEnv->AddResourceFileL( fmtxResourceFile );
       
   189 		}
       
   190 
       
   191     // Monitor for view activation
       
   192     AppUi()->AddViewActivationObserverL( this );
       
   193 
       
   194     // Get the playback utility instance from engine.
       
   195     iPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault );
       
   196     iPlaybackUtility->AddObserverL( *this );
       
   197 
       
   198     iMPXUtility = CMPXAlbumArtUtil::NewL();
       
   199 
       
   200     iEmbedded = iEikonEnv->StartedAsServerApp();
       
   201 
       
   202     // Get an instance of view utility
       
   203     iViewUtility = MMPXViewUtility::UtilityL();
       
   204     iViewUtility->AddObserverL( this );
       
   205 
       
   206     TInt flags( 0 );
       
   207     CRepository* repository( CRepository::NewL( KCRUidMPXMPFeatures ));
       
   208     User::LeaveIfError( repository->Get( KMPXMPLocalVariation, flags ));
       
   209     delete repository;
       
   210     repository = NULL;
       
   211 
       
   212     iChangeRTForAllProfiles =
       
   213         static_cast<TBool>( flags & KMPXChangeRTForAll );
       
   214 
       
   215     // Pre-load Equalizer & Audio Effects views
       
   216     iViewUtility->PreLoadViewL(
       
   217         TUid::Uid( KMPXPluginTypeEqualizerUid ) );
       
   218     iViewUtility->PreLoadViewL(
       
   219         TUid::Uid( KMPXPluginTypeAudioEffectsUid ) );
       
   220 
       
   221     iLayout = new (ELeave) CMPXCommonPlaybackViewLayout();
       
   222 
       
   223     iCollectionUtility = MMPXCollectionUtility::NewL( this );
       
   224 
       
   225 #ifdef __USE_MESSAGE_SUBSCRIPTION
       
   226     // Subscribe to only a few messages from collection utility
       
   227     CMPXSubscription* subscription( CMPXSubscription::NewL() );
       
   228     CleanupStack::PushL( subscription );
       
   229     CMPXSubscriptionItem* subItem1( CMPXSubscriptionItem::NewL() );
       
   230     CleanupStack::PushL( subItem1 );
       
   231     subItem1->SetTObjectValueL( KMPXMessageGeneralId, KMPXMessageGeneral );
       
   232     subItem1->SetTObjectValueL( KMPXMessageGeneralEvent, TMPXCollectionMessage::EBroadcastEvent );
       
   233     subItem1->SetTObjectValueL( KMPXMessageGeneralType, EMcMsgDiskRemoved );
       
   234     subscription->AddItemL( *subItem1 );
       
   235     CMPXSubscriptionItem* subItem2( CMPXSubscriptionItem::CopyL( *subItem1 ));
       
   236     CleanupStack::PushL( subItem2 );
       
   237     subItem2->SetTObjectValueL( KMPXMessageGeneralType, EMcMsgUSBMassStorageStart );
       
   238     subscription->AddItemL( *subItem2 );
       
   239     CMPXSubscriptionItem* subItem3( CMPXSubscriptionItem::CopyL( *subItem1 ));
       
   240     CleanupStack::PushL( subItem3 );
       
   241     subItem3->SetTObjectValueL( KMPXMessageGeneralType, EMcMsgUSBMTPStart );
       
   242     subscription->AddItemL( *subItem3 );
       
   243     CMPXSubscriptionItem* subItem4( CMPXSubscriptionItem::CopyL( *subItem1 ));
       
   244     CleanupStack::PushL( subItem4 );
       
   245     subItem4->SetTObjectValueL( KMPXMessageGeneralType, EMcMsgFormatStart );
       
   246     subscription->AddItemL( *subItem4 );
       
   247     CMPXSubscriptionItem* subItem5( CMPXSubscriptionItem::CopyL( *subItem1 ));
       
   248     CleanupStack::PushL( subItem5 );
       
   249     subItem5->SetTObjectValueL( KMPXMessageGeneralType, EMcMsgUSBMassStorageEnd );
       
   250     subscription->AddItemL( *subItem5 );
       
   251     CMPXSubscriptionItem* subItem6( CMPXSubscriptionItem::CopyL( *subItem1 ));
       
   252     CleanupStack::PushL( subItem6 );
       
   253     subItem6->SetTObjectValueL( KMPXMessageGeneralType, EMcMsgUSBMTPEnd );
       
   254     subscription->AddItemL( *subItem6 );
       
   255     CMPXSubscriptionItem* subItem7( CMPXSubscriptionItem::CopyL( *subItem1 ));
       
   256     CleanupStack::PushL( subItem7 );
       
   257     subItem7->SetTObjectValueL( KMPXMessageGeneralType, EMcMsgFormatEnd );
       
   258     subscription->AddItemL( *subItem7 );
       
   259     CMPXSubscriptionItem* subItem8( CMPXSubscriptionItem::NewL() );
       
   260     CleanupStack::PushL( subItem8 );
       
   261     subItem8->SetTObjectValueL( KMPXMessageGeneralId, KMPXMessageGeneral );
       
   262     subItem8->SetTObjectValueL( KMPXMessageGeneralEvent, TMPXCollectionMessage::EPathChanged );
       
   263     subItem8->SetTObjectValueL( KMPXMessageGeneralType, EMcPathChangedByOpen );
       
   264     subItem8->SetTObjectValueL( KMPXMessageGeneralData, EMcItemOpened );
       
   265     subscription->AddItemL( *subItem8 );
       
   266     iCollectionUtility->Collection().AddSubscriptionL( *subscription );
       
   267     CleanupStack::PopAndDestroy( subItem8 );
       
   268     CleanupStack::PopAndDestroy( subItem7 );
       
   269     CleanupStack::PopAndDestroy( subItem6 );
       
   270     CleanupStack::PopAndDestroy( subItem5 );
       
   271     CleanupStack::PopAndDestroy( subItem4 );
       
   272     CleanupStack::PopAndDestroy( subItem3 );
       
   273     CleanupStack::PopAndDestroy( subItem2 );
       
   274     CleanupStack::PopAndDestroy( subItem1 );
       
   275     CleanupStack::PopAndDestroy( subscription );
       
   276 #endif
       
   277 
       
   278     iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL();
       
   279     iCommonUiHelper = CMPXCommonUiHelper::NewL( iCollectionUtility );
       
   280 
       
   281     // initialize FeatureManager
       
   282     FeatureManager::InitializeLibL();
       
   283 
       
   284     if ( FeatureManager::FeatureSupported( KFeatureIdFmtx ) )
       
   285         {
       
   286         // Since support of FM Tx remains the same within the lifetime of this
       
   287         // view, it is safe to determine whether to create the associated
       
   288         // PS & CR watcher here.
       
   289 
       
   290         // create the PS Key watcher to receive notification when FM
       
   291         // transmission status changes
       
   292         iPSKeyWatcher =
       
   293             CMPXPSKeyWatcher::NewL( KPSUidHWRMFmTx, KHWRMFmTxStatus, this );
       
   294 
       
   295         // create the Central Repository watcher to receive notification when
       
   296         // the value of the FM Frequency CR key is changed.
       
   297         iCRWatcher = CMPXCenRepWatcher::NewL(
       
   298             KCRUidFmTxCenRes,
       
   299             KFmTxCenResKeyFrequency,
       
   300             this );
       
   301         }
       
   302 
       
   303     iStartPlaybackIndex = KErrNotFound;
       
   304     iLastSkipDirection = 1;
       
   305     iSkipBtnPressed = EFalse;
       
   306 
       
   307     // Set to EFalse to avoid handling
       
   308     // errors if the view has not been activated
       
   309     // before.
       
   310     iLastPBViewActivated = EFalse;
       
   311 
       
   312     iDatabaseNotReady = EFalse;
       
   313     iIgnoredByUsbEvent = EFalse;
       
   314 #ifdef _DEBUG
       
   315     iExitOptionHidden = EFalse;
       
   316 #else // _DEBUG
       
   317     iExitOptionHidden = iCommonUiHelper->ExitOptionHiddenL() && !iEmbedded;
       
   318 #endif // _DEBUG
       
   319 
       
   320     // Support for Camese Super Distribution
       
   321 #ifdef __CAMESE_SUPERDISTRIBUTION_SUPPORT
       
   322     iCameseSuperDistSupport = ETrue;
       
   323 #endif
       
   324     iMediaRecognizer = CMediaRecognizer::NewL();
       
   325     if ( iServiceHandler == NULL)
       
   326         {
       
   327         iServiceHandler = CAiwServiceHandler::NewL();
       
   328         MPX_DEBUG1("CMPXCollectionViewImp::ConstructL() Attaching 'Assign as' menu service...");
       
   329         MPX_TRAP( iErrorAttachAssignMenu, iServiceHandler->AttachMenuL( R_MPX_USE_AS_CASCADE,
       
   330                                                    R_MPX_AIW_ASSIGN_INTEREST ) );
       
   331         }
       
   332 #ifdef BACKSTEPPING_INCLUDED
       
   333     // Initialize the Back Stepping Service Utility with the MPX Music Player
       
   334     iBackSteppingUtility = MMPXBackSteppingUtility::UtilityL();
       
   335     iBackSteppingUtility->InitializeL(
       
   336         TUid::Uid( KMusicPlayerAppUidConstant ) );
       
   337 #endif // BACKSTEPPING_INCLUDED
       
   338 
       
   339 #ifdef UPNP_INCLUDED
       
   340     if (!iUpnpCopyCommand )
       
   341         {
       
   342    	    MPX_TRAPD ( error, iUpnpCopyCommand = CUpnpCopyCommand::NewL() );   
       
   343 		    if ( error == KErrNone )
       
   344             {
       
   345             iUpnpFrameworkSupport = ETrue;
       
   346             }
       
   347         else
       
   348             {
       
   349             iUpnpFrameworkSupport = EFalse;
       
   350 			iUpnpCopyCommand = NULL;
       
   351             }
       
   352         }
       
   353 #endif
       
   354     iIsffButtonPressed = EFalse;
       
   355     iDelayedErrorTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   356     }
       
   357 
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // Destructor
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 EXPORT_C CMPXCommonPlaybackViewImp::~CMPXCommonPlaybackViewImp()
       
   364     {
       
   365     MPX_DEBUG1( "CMPXCommonPlaybackViewImp::~CMPXCommonPlaybackViewImp entering" );
       
   366 
       
   367     AppUi()->RemoveViewActivationObserver( this );
       
   368 
       
   369     delete iMPXUtility;
       
   370     delete iMedia;
       
   371     delete iIdle;
       
   372 
       
   373     if ( iServiceHandler )
       
   374         {
       
   375         iServiceHandler->DetachMenu( R_MPX_USE_AS_CASCADE,
       
   376                                  R_MPX_AIW_ASSIGN_INTEREST );
       
   377         delete iServiceHandler;
       
   378         delete iMediaRecognizer;
       
   379         }
       
   380 
       
   381     delete iDelayedExit;
       
   382 
       
   383     if ( iPSKeyWatcher )
       
   384         {
       
   385         delete iPSKeyWatcher;
       
   386         }
       
   387 
       
   388     if ( iCRWatcher )
       
   389         {
       
   390         delete iCRWatcher;
       
   391         }
       
   392 
       
   393     if ( iPlaybackUtility )
       
   394         {
       
   395         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
       
   396         iPlaybackUtility->Close();
       
   397         }
       
   398 
       
   399     if ( iViewUtility )
       
   400         {
       
   401         iViewUtility->RemoveObserver( this );
       
   402         iViewUtility->Close();
       
   403         }
       
   404 
       
   405     if ( iResourceOffset )
       
   406         {
       
   407         iEikonEnv->DeleteResourceFile( iResourceOffset );
       
   408         }
       
   409 
       
   410    	if ( iFMTXResourceOffset )
       
   411        	{
       
   412        	iEikonEnv->DeleteResourceFile( iFMTXResourceOffset );
       
   413        	}
       
   414 
       
   415 #ifdef BACKSTEPPING_INCLUDED
       
   416     if( iBackSteppingUtility )
       
   417         {
       
   418         iBackSteppingUtility->Close();
       
   419         }
       
   420 #endif // BACKSTEPPING_INCLUDED
       
   421 
       
   422     if ( iContainer )
       
   423         {
       
   424         AppUi()->RemoveFromStack( iContainer );
       
   425         delete iContainer;
       
   426         }
       
   427     delete iLayout;
       
   428 
       
   429     if ( iUpnpFrameworkSupport )
       
   430         {
       
   431         iPlayersList.Close();
       
   432         delete iSubPlayerName;
       
   433 #ifdef UPNP_INCLUDED
       
   434         if (iUpnpCopyCommand)
       
   435             {
       
   436             delete iUpnpCopyCommand;
       
   437             }
       
   438 #endif
       
   439         }
       
   440     delete iWaitNote;
       
   441 
       
   442     if ( iCollectionUtility )
       
   443         {
       
   444         iCollectionUtility->Close();
       
   445         }
       
   446 
       
   447     if ( iCollectionUiHelper )
       
   448         {
       
   449         iCollectionUiHelper->Close();
       
   450         }
       
   451 
       
   452     delete iCommonUiHelper;
       
   453     delete iUserPlaylists;
       
   454 
       
   455     if ( iKeySoundDisabled )
       
   456         {
       
   457         iAvkonViewAppUi->KeySounds()->PopContext();
       
   458         }
       
   459 
       
   460     // free up the FeatureManager
       
   461     FeatureManager::UnInitializeLib();
       
   462     if(iDelayedErrorTimer)
       
   463     	{
       
   464     	iDelayedErrorTimer->Cancel();
       
   465     	delete iDelayedErrorTimer;
       
   466     	}
       
   467     
       
   468     delete iOldUri;
       
   469     MPX_DEBUG1( "CMPXCommonPlaybackViewImp::~CMPXCommonPlaybackViewImp exiting" );
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // Updates playback view.
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateViewL()
       
   477     {
       
   478     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateViewL" );
       
   479 
       
   480     if ( iContainer && !iSwitchingView )
       
   481         {
       
   482         UpdatePlaybackState( iPlaybackState );
       
   483         UpdateTrackInfoL( iMedia );
       
   484         UpdateTrackPlaybackPositionL( iPosition, iDuration );
       
   485         UpdateTrackPosInPlaylistL();
       
   486         UpdateAlbumArtL( iMedia );
       
   487         UpdateDownloadStateLabelL();
       
   488 
       
   489         UpdateFMTransmitterInfoL( ETrue );
       
   490 
       
   491         // Retrieve current repeat & random modes
       
   492         iPlaybackUtility->PropertyL( *this, EPbPropertyRandomMode );
       
   493         iPlaybackUtility->PropertyL( *this, EPbPropertyRepeatMode );
       
   494         }
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------------------------
       
   498 // Updates track info field.
       
   499 // ---------------------------------------------------------------------------
       
   500 //
       
   501 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateTrackInfoL(
       
   502     const CMPXMedia* aMedia )
       
   503     {
       
   504     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateTrackInfo" );
       
   505 
       
   506     if ( iContainer && !iSwitchingView )
       
   507         {
       
   508         if ( aMedia )
       
   509             {
       
   510             if ( aMedia->IsSupported( KMPXMediaGeneralTitle ) )
       
   511                 {
       
   512                 iContainer->UpdateLabelL(
       
   513                     ETextTrack,
       
   514                     aMedia->ValueText( KMPXMediaGeneralTitle ) );
       
   515                 }
       
   516             else if ( aMedia->IsSupported( KMPXMediaGeneralUri ) )
       
   517                 {
       
   518                 TParsePtrC filePath(
       
   519                     aMedia->ValueText( KMPXMediaGeneralUri ) );
       
   520                 iContainer->UpdateLabelL(
       
   521                     ETextTrack, filePath.Name() );
       
   522                 }
       
   523             else
       
   524                 {
       
   525                 iContainer->UpdateLabelL(
       
   526                     ETextTrack, KNullDesC );
       
   527                 }
       
   528 
       
   529             if ( aMedia->IsSupported( KMPXMediaMusicArtist ) )
       
   530                 {
       
   531                 const TDesC& artist =
       
   532                     aMedia->ValueText( KMPXMediaMusicArtist );
       
   533                 if ( artist != KNullDesC )
       
   534                     {
       
   535                     iContainer->UpdateLabelL(
       
   536                         ETextArtist,
       
   537                         artist );
       
   538                     }
       
   539                 else
       
   540                     {
       
   541                     // Display unknown artist as artist
       
   542                     HBufC* unknownArtistText =
       
   543                         StringLoader::LoadLC( R_MPX_PBV_UNKNOWN_ARTIST_LABEL );
       
   544                     iContainer->UpdateLabelL(
       
   545                         ETextArtist, *unknownArtistText );
       
   546                     CleanupStack::PopAndDestroy( unknownArtistText );
       
   547                     }
       
   548                 }
       
   549             else
       
   550                 {
       
   551                 // Display unknown artist as artist
       
   552                 HBufC* unknownArtistText =
       
   553                     StringLoader::LoadLC( R_MPX_PBV_UNKNOWN_ARTIST_LABEL );
       
   554                 iContainer->UpdateLabelL(
       
   555                     ETextArtist, *unknownArtistText );
       
   556                 CleanupStack::PopAndDestroy( unknownArtistText );
       
   557                 }
       
   558 
       
   559 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   560             if ( iMedia->IsSupported( KMPXMediaGeneralMimeType ) )
       
   561                 {
       
   562                 // Get mime type
       
   563                 const TDesC& mimeType = iMedia->ValueText(
       
   564                     KMPXMediaGeneralMimeType );
       
   565                 const TBool realAudioMode =
       
   566                     ( mimeType.Compare( KMPXPnRealAudioMimeType ) == 0 ) ||
       
   567                     ( mimeType.Compare( KMPXRealAudioMimeType ) == 0) ||
       
   568                     ( mimeType.Compare( KMPXRnRealAudioMimeType ) == 0 );
       
   569 
       
   570                 // Set the real audio mode
       
   571                 iContainer->SetRealAudioMode( realAudioMode );
       
   572                 }
       
   573 #endif
       
   574             }
       
   575         else
       
   576             {
       
   577             // Display nothing if properties is NULL
       
   578             iContainer->UpdateLabelL(
       
   579                 ETextTrack, KNullDesC );
       
   580             iContainer->UpdateLabelL(
       
   581                 ETextArtist, KNullDesC );
       
   582 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   583             // reset real audio mode
       
   584             iContainer->SetRealAudioMode( EFalse );
       
   585 #endif
       
   586             }
       
   587         }
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // Update current playback state.
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 EXPORT_C void CMPXCommonPlaybackViewImp::UpdatePlaybackState(
       
   595     TMPXPlaybackState aPlaybackState )
       
   596     {
       
   597     MPX_DEBUG2("CMPXCommonPlaybackViewImp::UpdatePlaybackState(%d): Entering", aPlaybackState);
       
   598 
       
   599     if ( iContainer && !iSwitchingView )
       
   600         {
       
   601         TMPXPbvPlaybackMode mode( EInvalidMode );
       
   602 
       
   603         switch ( aPlaybackState )
       
   604             {
       
   605             case EPbStateNotInitialised:
       
   606                 {
       
   607                 mode = iPlaybackUtility->Source() ? EUninitialized: ENoTracksMode;
       
   608                 break;
       
   609                 }
       
   610             case EPbStateInitialising:
       
   611                 {
       
   612                 mode = EInitialising;
       
   613                 break;
       
   614                 }
       
   615             case EPbStatePlaying:
       
   616                 {
       
   617                 mode = EPlayMode;
       
   618                 iIgnoredByUsbEvent = EFalse;
       
   619                 break;
       
   620                 }
       
   621             case EPbStatePaused:
       
   622                 {
       
   623                 mode = EPauseMode;
       
   624                 break;
       
   625                 }
       
   626             case EPbStateStopped:
       
   627                 {
       
   628                 mode = EStopMode;
       
   629                 break;
       
   630                 }
       
   631             case EPbStateBuffering:
       
   632                 {
       
   633                 mode = EBufferingMode;
       
   634                 break;
       
   635                 }
       
   636             default:
       
   637                 {
       
   638                 // Pass
       
   639                 break;
       
   640                 }
       
   641             }
       
   642 
       
   643         if ( EInvalidMode != mode )
       
   644             {
       
   645             iPlaybackState = aPlaybackState;
       
   646             iContainer->SetMode( mode );
       
   647             }
       
   648 
       
   649         iContainer->UpdateButtons( aPlaybackState );
       
   650         }
       
   651     else
       
   652         {
       
   653         // If no container, just need to update state
       
   654         switch ( aPlaybackState )
       
   655             {
       
   656             case EPbStateNotInitialised:
       
   657             case EPbStateInitialising:
       
   658             case EPbStatePlaying:
       
   659             case EPbStatePaused:
       
   660             case EPbStateStopped:
       
   661                 {
       
   662                 iPlaybackState = aPlaybackState;
       
   663                 break;
       
   664                 }
       
   665             default:
       
   666                 {
       
   667                 // Pass
       
   668                 // Ignore other state changes such as skipping, etc.
       
   669                 break;
       
   670                 }
       
   671             }
       
   672         }
       
   673     MPX_DEBUG1("CMPXCommonPlaybackViewImp::UpdatePlaybackState(): Exiting");
       
   674     }
       
   675 
       
   676 // ---------------------------------------------------------------------------
       
   677 // Updates track's playback position.
       
   678 // ---------------------------------------------------------------------------
       
   679 //
       
   680 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateTrackPlaybackPositionL(
       
   681     TInt aPos,
       
   682     TInt aDuration )
       
   683     {
       
   684     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateTrackPlaybackPosition" );
       
   685 
       
   686     if ( iContainer && !iSwitchingView )
       
   687         {
       
   688         if ( aPos > aDuration )
       
   689             {
       
   690             aPos = aDuration;
       
   691             }
       
   692         switch ( iPlaybackState )
       
   693             {
       
   694             case EPbStatePaused:
       
   695             case EPbStatePlaying:
       
   696                 {
       
   697                 iContainer->UpdateTimeIndicatorsL( aPos, aDuration );
       
   698                 break;
       
   699                 }
       
   700             case EPbStateStopped:
       
   701             case EPbStateInitialising:
       
   702                 {
       
   703                 iContainer->UpdateTimeIndicatorsL( aPos, aDuration );
       
   704                 } // falls through
       
   705             case EPbStateNotInitialised:
       
   706                 {
       
   707                 iContainer->UpdateDurationLabelL( aDuration );
       
   708                 break;
       
   709                 }
       
   710             default:
       
   711                 {
       
   712                 // Do nothing
       
   713                 break;
       
   714                 }
       
   715             }
       
   716         }
       
   717     }
       
   718 
       
   719 // ---------------------------------------------------------------------------
       
   720 // Updates track's album art.
       
   721 // ---------------------------------------------------------------------------
       
   722 //
       
   723 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateAlbumArtL(
       
   724     const CMPXMedia* aMedia )
       
   725     {
       
   726     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateAlbumArt" );
       
   727 
       
   728     if ( iContainer && !iSwitchingView )
       
   729         {
       
   730         TInt err( KErrNone );
       
   731         if ( aMedia && aMedia->IsSupported(KMPXMediaGeneralUri))
       
   732             {
       
   733             const TDesC& album = aMedia->ValueText( KMPXMediaGeneralUri );
       
   734             if(!iOldUri || iOldUri->Compare(album)!= 0)
       
   735                 {  
       
   736 
       
   737                 TRect albumArtRect(
       
   738                         iLayout->IndicatorLayout(
       
   739                                 ClientRect(), EAlbumArtArea ) );
       
   740 
       
   741             MPX_TRAP( err,
       
   742                 iMPXUtility->ExtractAlbumArtL(
       
   743                     *aMedia,
       
   744                     *iContainer,
       
   745                     albumArtRect.Size() ); );
       
   746                 delete iOldUri;
       
   747                 iOldUri = NULL;
       
   748                 iOldUri=album.AllocL();
       
   749                 } 
       
   750             }
       
   751 
       
   752         if (KErrNone != err )
       
   753             {
       
   754             // If error, show default album art
       
   755             MPX_DEBUG2("CMPXCommonPlaybackViewImp::UpdateAlbumArt(): err = %d", err);
       
   756             iContainer->ExtractAlbumArtCompleted( NULL, KErrNone );
       
   757             }
       
   758         }
       
   759     }
       
   760 
       
   761 // ---------------------------------------------------------------------------
       
   762 // Updates track position in playlist field.
       
   763 // ---------------------------------------------------------------------------
       
   764 //
       
   765 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateTrackPosInPlaylistL()
       
   766     {
       
   767     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateTrackPosInPlaylist" );
       
   768 
       
   769     if ( iContainer && !iSwitchingView )
       
   770         {
       
   771         TBool emptyCount( EFalse );
       
   772         TInt count( 0 );
       
   773         TInt index( 0 );
       
   774 
       
   775         MMPXSource* s = iPlaybackUtility->Source();
       
   776         if ( s )
       
   777             {
       
   778             CMPXCollectionPlaylist* playlist = s->PlaylistL();
       
   779             if ( playlist )
       
   780                 {
       
   781                 count = playlist->Count();
       
   782                 index = playlist->PathIndex( playlist->Index() );
       
   783                 delete playlist;
       
   784                 playlist = NULL;
       
   785                 }
       
   786             }
       
   787         MPX_DEBUG3("CMPXCommonPlaybackViewImp::UpdateTrackPosInPlaylistL: index = %d, count = %d", index, count );
       
   788 
       
   789         // not display for progressive mode & embedded track mode
       
   790         TMPXLaunchMode mode = MPXTlsHelper::LaunchMode();
       
   791 
       
   792         if ( count )
       
   793             {
       
   794             if ( EMPXLaunchModeTrack != mode )
       
   795                 {
       
   796                 // Current index (1-based) if playlist is non-empty
       
   797                 // Magic: array granularity
       
   798                 CArrayFixFlat<TInt>* params =
       
   799                     new ( ELeave ) CArrayFixFlat<TInt>( 2 );
       
   800                 CleanupStack::PushL( params );
       
   801                 params->AppendL( index + 1 );
       
   802                 params->AppendL( count );
       
   803                 HBufC* plcounter = StringLoader::LoadLC(
       
   804                     R_MPX_PBV_PLAYLIST_ITEM_COUNTER_LABEL, *params );
       
   805                 iContainer->UpdateLabelL(
       
   806                     ETextPlaylistCount,
       
   807                     *plcounter );
       
   808                 CleanupStack::PopAndDestroy( plcounter );
       
   809                 CleanupStack::PopAndDestroy( params );
       
   810                 //iContainer->UpdateLabelL( ETextEmpty, KNullDesC );
       
   811                 }
       
   812             else
       
   813                 {
       
   814                 emptyCount = ETrue;
       
   815                 }
       
   816             }
       
   817         else
       
   818             {
       
   819             emptyCount = ETrue;
       
   820 
       
   821             // Display empty state text
       
   822             //HBufC* noTracksText =
       
   823             //    StringLoader::LoadLC( R_MPX_PBV_NO_TRACKS_LABEL );
       
   824             //iContainer->UpdateLabelL(
       
   825              //   ETextEmpty, *noTracksText );
       
   826             //CleanupStack::PopAndDestroy( noTracksText );
       
   827             }
       
   828 
       
   829         if ( emptyCount )
       
   830             {
       
   831             // Empty string if playlist is empty
       
   832             iContainer->UpdateLabelL(
       
   833                 ETextPlaylistCount,
       
   834                 KNullDesC );
       
   835             }
       
   836         }
       
   837     }
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // Updates download state label.
       
   841 // ---------------------------------------------------------------------------
       
   842 //
       
   843 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateDownloadStateLabelL()
       
   844     {
       
   845     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateDownloadStateLabelL" );
       
   846     // Do not show opening popup
       
   847     }
       
   848 
       
   849 // ---------------------------------------------------------------------------
       
   850 // Updates Title Pane.
       
   851 // ---------------------------------------------------------------------------
       
   852 //
       
   853 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateTitlePaneL()
       
   854     {
       
   855     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateTitlePaneL" );
       
   856 
       
   857     CAknTitlePane* title( static_cast<CAknTitlePane*>
       
   858             ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ))));
       
   859     if ( title )
       
   860         {
       
   861         HBufC* titleText( StringLoader::LoadLC(
       
   862             R_MPX_PLAYBACKVIEW_TITLE ));
       
   863         title->SetTextL( *titleText );
       
   864         CleanupStack::PopAndDestroy( titleText );
       
   865         }
       
   866     }
       
   867 
       
   868 // ---------------------------------------------------------------------------
       
   869 // Updates FM Transmitter Info
       
   870 // ---------------------------------------------------------------------------
       
   871 //
       
   872 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateFMTransmitterInfoL(
       
   873     TBool aForceUpdate )
       
   874     {
       
   875     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::UpdateFMTransmitterInfoL" );
       
   876 
       
   877     if ( iContainer && !iSwitchingView )
       
   878         {
       
   879         if ( FeatureManager::FeatureSupported( KFeatureIdFmtx ) )
       
   880             {
       
   881             // if FM Transmitter is supported feature, retrieve the state of
       
   882             // the FM Transmitter
       
   883             TInt value(EFmTxStateUnknown);
       
   884             TInt freqKHz = 0;
       
   885 
       
   886             if ( iPSKeyWatcher->GetValue( value ) == KErrNone )
       
   887                 {
       
   888                 MPX_DEBUG2( "CMPXCommonPlaybackViewImp::UpdateFMTransmitterInfoL iPSKeyWatcher value %d", value);
       
   889                 // EFmTxStatePowerSaveAccessory & EFmTxStatePowerSaveInactivity
       
   890                 // are considered as off
       
   891                 if ( value == EFmTxStateActive ||
       
   892                      value == EFmTxStateInactive )
       
   893                     {
       
   894                     // if FM Transmitter is turned on, retrieve the frequency
       
   895                     MPX_TRAPD( err, freqKHz = iCRWatcher->CurrentValueL() );
       
   896                     if ( err != KErrNone )
       
   897                         {
       
   898                         freqKHz = 0;
       
   899                         }
       
   900                     }
       
   901                 }
       
   902 
       
   903             MPX_DEBUG4( "CMPXCommonPlaybackViewImp::UpdateFMTransmitterInfoL iFMTxFreqKHz %d freqKHz %d aForceUpdate %d", iFMTxFreqKHz, freqKHz, aForceUpdate);
       
   904             if ( iFMTxFreqKHz != freqKHz || aForceUpdate )
       
   905                 {
       
   906                 // if the FM Transmitter state has been changed from one active
       
   907                 // to another and it's frequency value changed, or if FM
       
   908                 // Transmitter is changed from an active to an inactive state,
       
   909                 // or vice versa, update the frequency display and save the new
       
   910                 // value
       
   911                 iFMTxFreqKHz = freqKHz;
       
   912 
       
   913                 // Create display string and default it to an empty string
       
   914                 RBuf freqTxt;
       
   915                 freqTxt.Assign( NULL );
       
   916 
       
   917                 CleanupClosePushL( freqTxt );
       
   918 
       
   919                 // display the frequncy if it's a valid value
       
   920                 if ( iFMTxFreqKHz > 0 )
       
   921                     {
       
   922                     TReal freqMHz = static_cast<TReal> (iFMTxFreqKHz) /
       
   923                         static_cast<TReal> (KMPXOneMhzInOneKhz);
       
   924 
       
   925                     TRealFormat realFormat(
       
   926                         KMPXFMFreqWidth,
       
   927                         KMPXFMFreqDecimalPlace);
       
   928 
       
   929                     // display frequecy as : XXX.XX Mhz
       
   930                     TBuf<KMPXFMFreqWidth + 1> freqMHzStr;
       
   931                     TInt err = freqMHzStr.Num( freqMHz, realFormat );
       
   932                     if ( err > 0 )
       
   933                         {
       
   934                         HBufC* labelFormatText = StringLoader::LoadL(
       
   935                             R_MPX_FM_FREQUENCY_LABEL,
       
   936                             freqMHzStr );
       
   937 
       
   938                         // ownership transferred
       
   939                         freqTxt.Assign(labelFormatText);
       
   940                         }
       
   941                     }
       
   942 
       
   943                 iContainer->UpdateLabelL(
       
   944                     ETextFMFrequency, freqTxt );
       
   945 
       
   946                 CleanupStack::PopAndDestroy( &freqTxt );
       
   947                 }
       
   948             }
       
   949         }
       
   950     }
       
   951 
       
   952 // ---------------------------------------------------------------------------
       
   953 // Handle playback message.
       
   954 // ---------------------------------------------------------------------------
       
   955 //
       
   956 EXPORT_C void CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL(
       
   957     const CMPXMessage& aMessage )
       
   958     {
       
   959     MPX_FUNC_EX("CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL");
       
   960 
       
   961     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   962     if ( KMPXMessagePbMediaChanged == id )
       
   963         {
       
   964         MPX_DEBUG1("CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL: PbMediaChanged");
       
   965         if ( aMessage.IsSupported( KMPXMessagePbMedia ) )
       
   966             {
       
   967             CMPXMedia* media( aMessage.Value<CMPXMedia>( KMPXMessagePbMedia ) );
       
   968             User::LeaveIfNull( media );
       
   969             DoHandleMediaL( *media, KErrNone );
       
   970             }
       
   971         }
       
   972     else if ( KMPXMessageGeneral == id )
       
   973         {
       
   974         TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
   975         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
   976         switch ( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) )
       
   977             {
       
   978             case TMPXPlaybackMessage::EPropertyChanged:
       
   979                 {
       
   980                 MPX_DEBUG2( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL - EPropertyChanged(%d)", type );
       
   981                 TMPXPlaybackProperty property(
       
   982                     static_cast<TMPXPlaybackProperty>( type ) );
       
   983                 TInt error( KErrNone );
       
   984 
       
   985                 DoHandlePropertyL( property, data, error );
       
   986                 break;
       
   987                 }
       
   988             case TMPXPlaybackMessage::EStateChanged:
       
   989                 {
       
   990                 MPX_DEBUG2( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL - EStateChanged(%d)", type );
       
   991 
       
   992                 TMPXPlaybackState state =
       
   993                     static_cast<TMPXPlaybackState>( type );
       
   994                 if ( ( data == KErrNotSupported ) &&
       
   995                      ( state == EPbStatePaused ) )
       
   996                     {
       
   997                     if ( iLastPBViewActivated )
       
   998                         {
       
   999                         // In UPnP case, this will display an error message
       
  1000                         iCommandSender = ECsMediaKey;
       
  1001                         IsCommandSupportedL();
       
  1002                         }
       
  1003                     }
       
  1004                 else if ( (( data == KErrAccessDenied ) || ( data == KErrDied ) || ( data == KErrInUse )) &&
       
  1005                           ( state == EPbStatePaused ))
       
  1006                     {
       
  1007                     if ( iLastPBViewActivated &&
       
  1008                          MPXUser::IsCallOngoing( EPSCTsyCallTypeH324Multimedia ))
       
  1009                         {
       
  1010                         iCommonUiHelper->HandleErrorL( KMPXErrorVideoCall );
       
  1011                         }
       
  1012                     }
       
  1013                 else
       
  1014                     {
       
  1015                     DoHandleStateChangedL( state, data );
       
  1016                     }
       
  1017                 break;
       
  1018                 }
       
  1019             case TMPXPlaybackMessage::EMediaChanged:
       
  1020                 {
       
  1021                 MPX_DEBUG1( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL - EMediaChanged()");
       
  1022                     RequestMediaL();
       
  1023                 if ( iIdle )
       
  1024                     {
       
  1025                     if ( iIdle->IsActive() )
       
  1026                         {
       
  1027                         MPX_DEBUG1( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL() iIdle active, canceling" );
       
  1028                         iIdle->Cancel();
       
  1029                         }
       
  1030                     delete iIdle;
       
  1031                     iIdle = NULL;
       
  1032                     }
       
  1033                 break;
       
  1034                 }
       
  1035             case TMPXPlaybackMessage::ECommandReceived:
       
  1036                 {
       
  1037                 MPX_DEBUG2( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL - ECommandReceived(%d)", type );
       
  1038                 break;
       
  1039                 }
       
  1040             case TMPXPlaybackMessage::ESkipping:
       
  1041                 {
       
  1042                 MPX_DEBUG2( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL - ESkipping(%d)", data );
       
  1043                 if ( iContainer )
       
  1044                     {
       
  1045                     iContainer->SetMode( EMediaKeySkipping );
       
  1046                     }
       
  1047                 TInt offset( data );
       
  1048                 if ( offset < 0 )
       
  1049                     {
       
  1050                     iLastSkipDirection = -1;
       
  1051                     }
       
  1052                 else
       
  1053                     {
       
  1054                     iLastSkipDirection = 1;
       
  1055                     }
       
  1056                 iSkipping = ETrue;
       
  1057                 break;
       
  1058                 }
       
  1059             case TMPXPlaybackMessage::ESkipEnd:
       
  1060                 {
       
  1061                 MPX_DEBUG1( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL - ESkipEnd()");
       
  1062                 iSkipping = EFalse;
       
  1063                 break;
       
  1064                 }
       
  1065             case TMPXPlaybackMessage::EPlaylistUpdated:
       
  1066                 {
       
  1067                 MPX_DEBUG1( "CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL - EPlaylistUpdated()");
       
  1068                 // Do not retrive media again if in the middle of handling an error
       
  1069                 if ( KErrNone == iDelayedError )
       
  1070                     {
       
  1071                     TBool noTracks( ETrue );
       
  1072                     MMPXSource* source = iPlaybackUtility->Source();
       
  1073                     if ( source )
       
  1074                         {
       
  1075                         CMPXCollectionPlaylist* pl( source->PlaylistL() );
       
  1076                         if ( pl )
       
  1077                             {
       
  1078                             CleanupStack::PushL( pl );
       
  1079                             if ( pl->Count() > 0 )
       
  1080                                 {
       
  1081                                 // Only update media if in foreground
       
  1082                                 if ( iContainer )
       
  1083                                     {
       
  1084                                     RequestMediaL();
       
  1085                                     }
       
  1086                                 else
       
  1087                                     {
       
  1088                                     // If in background, wait for view to be activated
       
  1089                                     // before requesting media again
       
  1090                                     delete iMedia;
       
  1091                                     iMedia = NULL;
       
  1092                                     }
       
  1093                                 noTracks = EFalse;
       
  1094                                 }
       
  1095                             CleanupStack::PopAndDestroy( pl );
       
  1096                             }
       
  1097                         }
       
  1098                     if ( noTracks )
       
  1099                         {
       
  1100                         delete iMedia;
       
  1101                         iMedia = NULL;
       
  1102                         iPlaybackState = EPbStateNotInitialised;
       
  1103                         UpdateViewL();
       
  1104                         }
       
  1105                     }
       
  1106                 break;
       
  1107                 }
       
  1108             case TMPXPlaybackMessage::EInitializeComplete:
       
  1109                 {
       
  1110                 // Reset flag, done opening new item.
       
  1111                 MPX_DEBUG1("CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL()");
       
  1112                 MPX_DEBUG1("    > EInitializeComplete Reset New Item Opened Flag");
       
  1113                 iNewItemOpened = EFalse;
       
  1114                 break;
       
  1115 				}
       
  1116             default:
       
  1117                 {
       
  1118                 MPX_DEBUG4("CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL(): Ignore message %d %d %d",
       
  1119                             aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ), type, data);
       
  1120                 break;
       
  1121                 }
       
  1122             }
       
  1123         }
       
  1124     }
       
  1125 
       
  1126 // ---------------------------------------------------------------------------
       
  1127 // Handle playback property.
       
  1128 // ---------------------------------------------------------------------------
       
  1129 //
       
  1130 EXPORT_C void CMPXCommonPlaybackViewImp::DoHandlePropertyL(
       
  1131     TMPXPlaybackProperty aProperty,
       
  1132     TInt aValue,
       
  1133     TInt aError )
       
  1134     {
       
  1135     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::DoHandlePropertyL" );
       
  1136     MPX_DEBUG4( "HandlePropertyL - Property(%d); Value(%d); Error(%d)", aProperty, aValue, aError );
       
  1137 
       
  1138     if ( KErrNone == aError )
       
  1139         {
       
  1140         switch ( aProperty  )
       
  1141             {
       
  1142             case EPbPropertyPosition:
       
  1143                 {
       
  1144                 iPosition = aValue / KMPXOneSecInMilliSecs;
       
  1145                 if( !iIsTapped )
       
  1146                     {
       
  1147                     UpdateTrackPlaybackPositionL( iPosition, iDuration );
       
  1148                     break;
       
  1149                     }
       
  1150                 else
       
  1151                     {
       
  1152                     iIsTapped = EFalse;
       
  1153                     // retrieve iCurrentPlayerType info
       
  1154                     GetCurrentPlayerDetails();
       
  1155                     if ( iCurrentPlayerType == EPbRemote )
       
  1156                         {
       
  1157                         UpdateTrackPlaybackPositionL( iOldPosition, iDuration );
       
  1158                         break;
       
  1159                         }
       
  1160                     else
       
  1161                         {
       
  1162                         UpdateTrackPlaybackPositionL( iPosition, iDuration );
       
  1163                         break;
       
  1164                         }
       
  1165                     }
       
  1166                 }
       
  1167             case EPbPropertyDuration:
       
  1168                 {
       
  1169                 iDuration = aValue / KMPXOneSecInMilliSecs;
       
  1170                 break;
       
  1171                 }
       
  1172             case EPbPropertyRandomMode:
       
  1173                 {
       
  1174                 iRandomMode = aValue;
       
  1175                 if ( iContainer )
       
  1176                     {
       
  1177                     iContainer->SetRandomMode( aValue );
       
  1178                     }
       
  1179                 break;
       
  1180                 }
       
  1181             case EPbPropertyRepeatMode:
       
  1182                 {
       
  1183                 iRepeatMode = aValue;
       
  1184                 if ( iContainer )
       
  1185                     {
       
  1186                     iContainer->SetRepeatMode(
       
  1187                         EPbRepeatAll == aValue, EPbRepeatOne == aValue );
       
  1188                     }
       
  1189                 break;
       
  1190                 }
       
  1191             default:
       
  1192                 {
       
  1193                 break;
       
  1194                 }
       
  1195             }
       
  1196         }
       
  1197     else
       
  1198         {
       
  1199         HandleErrorL( aError );
       
  1200         }
       
  1201     }
       
  1202 
       
  1203 // ---------------------------------------------------------------------------
       
  1204 // Handle media properties.
       
  1205 // Notes: The client is responsible for delete the object of aProperties.
       
  1206 // ---------------------------------------------------------------------------
       
  1207 //
       
  1208 EXPORT_C void CMPXCommonPlaybackViewImp::DoHandleMediaL(
       
  1209     const CMPXMedia& aMedia,
       
  1210     TInt aError )
       
  1211     {
       
  1212     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::DoHandleMediaL" );
       
  1213     MPX_DEBUG2("CMPXCommonPlaybackViewImp::DoHandleMediaL(): aError = %d", aError);
       
  1214 
       
  1215     delete iMedia;
       
  1216     iMedia = NULL;
       
  1217     if ( KErrNone == aError )
       
  1218         {
       
  1219         iMedia = CMPXMedia::NewL( aMedia );
       
  1220 
       
  1221         UpdateTrackPosInPlaylistL();
       
  1222         UpdateTrackInfoL( iMedia );
       
  1223         UpdateAlbumArtL( iMedia );
       
  1224         
       
  1225 
       
  1226         // Update duration if previously not available
       
  1227         if ( iMedia->IsSupported( KMPXMediaGeneralDuration ) )
       
  1228             {
       
  1229             iDuration = iMedia->ValueTObjectL<TInt>( KMPXMediaGeneralDuration ) /
       
  1230                 KMPXOneSecInMilliSecs;
       
  1231             UpdateTrackPlaybackPositionL( iPosition, iDuration );
       
  1232             }
       
  1233 
       
  1234         // If there's a delayed error, handle it now
       
  1235         // that the media object has arrived
       
  1236         if ( iDelayedError != KErrNone )
       
  1237             {
       
  1238             // if repeat mode is off, delay to handle this error.
       
  1239             if ( EPbRepeatOff == iRepeatMode )
       
  1240                 {
       
  1241                 // save current index
       
  1242                 iErrIndex = KErrNotFound;
       
  1243                 if (iPlaybackUtility)
       
  1244                     {
       
  1245                     MMPXSource* source( iPlaybackUtility->Source() );
       
  1246                     if ( source )
       
  1247                         {
       
  1248                         CMPXCollectionPlaylist* pl( source->PlaylistL() );
       
  1249                         if ( pl )
       
  1250                             {
       
  1251                             CleanupStack::PushL( pl );
       
  1252                             iErrIndex = pl->Index();
       
  1253                             CleanupStack::PopAndDestroy( pl );
       
  1254                             }
       
  1255                         }
       
  1256                     }
       
  1257                 // startup timer for handling delayed error
       
  1258                 TCallBack cb( HandleDelayedError, this );
       
  1259                 if (iDelayedErrorTimer->IsActive())
       
  1260                     {
       
  1261                     iDelayedErrorTimer->Cancel();
       
  1262                     }
       
  1263                 iDelayedErrorTimer->Start( KMPXPostponeForHandleDelayedError,
       
  1264                         KMPXPostponeForHandleDelayedError,
       
  1265                         cb );
       
  1266                 // reset iDelayedError
       
  1267                 iLastDelayedErr = iDelayedError;
       
  1268                 iDelayedError = KErrNone;
       
  1269                 }
       
  1270             else
       
  1271                 {
       
  1272                 // if repeat mode isn't off, handle it at once.
       
  1273                 if (iDelayedErrorTimer->IsActive())
       
  1274                     {
       
  1275                     iDelayedErrorTimer->Cancel();
       
  1276                     }
       
  1277 
       
  1278                 // Copy error code and reset iDelayedError, this is becuase
       
  1279                 // a media event may be called while handling this error
       
  1280                 TInt err( iDelayedError );
       
  1281                 iDelayedError = KErrNone;
       
  1282                 HandleErrorL( err );
       
  1283                 }
       
  1284             }
       
  1285         }
       
  1286     else
       
  1287         {
       
  1288         
       
  1289 #ifndef CAMESE_IN_DRM_UTILITY		
       
  1290         // Check if Camese Support is enabled and
       
  1291         // if the error is caused by PV being unable
       
  1292         // to retrieve media properties before handling
       
  1293         // the error here.
       
  1294         if (iCameseSuperDistSupport && aError == KErrPermissionDenied)
       
  1295             {
       
  1296             // Clear delayed errors.
       
  1297             iDelayedError = KErrNone;
       
  1298             return;
       
  1299             }
       
  1300 #endif
       
  1301         HandleErrorL(aError);
       
  1302 
       
  1303         if ( aError == iDelayedError )
       
  1304             {
       
  1305             iDelayedError = KErrNone;
       
  1306             }
       
  1307         }
       
  1308     }
       
  1309 
       
  1310 // ---------------------------------------------------------------------------
       
  1311 // Handle playback state changed.
       
  1312 // ---------------------------------------------------------------------------
       
  1313 //
       
  1314 EXPORT_C void CMPXCommonPlaybackViewImp::DoHandleStateChangedL(
       
  1315     TMPXPlaybackState aState,
       
  1316     TInt aData )
       
  1317     {
       
  1318     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::DoHandleStateChangedL" );
       
  1319     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::DoHandleStateChangedL %d", aState );
       
  1320     UpdatePlaybackState( aState );
       
  1321 
       
  1322     switch ( aState )
       
  1323         {
       
  1324         case EPbStateStopped:
       
  1325         case EPbStateNotInitialised:
       
  1326             {
       
  1327             UpdateTrackPlaybackPositionL( 0, iDuration );
       
  1328             break;
       
  1329             }
       
  1330         case EPbStateInitialising:
       
  1331             {
       
  1332             // Save the start playback index
       
  1333             if ( KErrNotFound == iStartPlaybackIndex &&
       
  1334                  KErrNotFound != aData )
       
  1335                 {
       
  1336                 iStartPlaybackIndex = aData;
       
  1337                 }
       
  1338             UpdateDownloadStateLabelL();
       
  1339             iDelayedErrorTimer->Cancel();
       
  1340             break;
       
  1341             }
       
  1342         case EPbStatePlaying:
       
  1343         case EPbStatePaused:
       
  1344         default:
       
  1345             {
       
  1346             MPX_PERF_CHECKPT("Playback state changes to Play/Pause");
       
  1347             iStartPlaybackIndex = KErrNotFound;
       
  1348             iLastSkipDirection = 1;
       
  1349             break;
       
  1350             }
       
  1351         }
       
  1352     }
       
  1353 
       
  1354 // ---------------------------------------------------------------------------
       
  1355 // Get simple embedded mode.
       
  1356 // ---------------------------------------------------------------------------
       
  1357 //
       
  1358 EXPORT_C TBool CMPXCommonPlaybackViewImp::SimpleEmbeddedMode() const
       
  1359     {
       
  1360     return iEmbedded;
       
  1361     }
       
  1362 
       
  1363 // ---------------------------------------------------------------------------
       
  1364 // Get embedded status.
       
  1365 // ---------------------------------------------------------------------------
       
  1366 //
       
  1367 EXPORT_C TBool CMPXCommonPlaybackViewImp::IsEmbedded() const
       
  1368     {
       
  1369     return iEmbedded;
       
  1370     }
       
  1371 
       
  1372 // ---------------------------------------------------------------------------
       
  1373 // Displays error notes.
       
  1374 // ---------------------------------------------------------------------------
       
  1375 //
       
  1376 EXPORT_C void CMPXCommonPlaybackViewImp::HandleErrorL( TInt aError )
       
  1377     {
       
  1378     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::HandleErrorL(%d): Entering", aError );
       
  1379     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::HandleErrorL iIgnoredByUsbEvent(%d):", iIgnoredByUsbEvent );
       
  1380     if ( aError )
       
  1381         {
       
  1382         TInt currentIndex( KErrNotFound );
       
  1383         TInt nextIndex( KErrNotFound );
       
  1384         TInt plCount( KErrNotFound );
       
  1385         MMPXSource* source( iPlaybackUtility->Source() );
       
  1386         if ( source )
       
  1387             {
       
  1388             CMPXCollectionPlaylist* pl( source->PlaylistL() );
       
  1389             if ( pl )
       
  1390                 {
       
  1391                 CleanupStack::PushL( pl );
       
  1392                 currentIndex = pl->Index();
       
  1393                 if ( iLastSkipDirection < 0 )
       
  1394                     {
       
  1395                     pl->Previous( ETrue );
       
  1396                     }
       
  1397                 else
       
  1398                     {
       
  1399                     pl->Next( ETrue );
       
  1400                     }
       
  1401                 nextIndex = pl->Index();
       
  1402                 plCount = pl->Count();
       
  1403                 CleanupStack::PopAndDestroy( pl );
       
  1404                 }
       
  1405             }
       
  1406 
       
  1407         // MMF framework will return KErrArgument/KErrCompletion if it reaches
       
  1408         // the end of a partially downloaded file.  The downloaded portion of
       
  1409         // the file should still be playable in this case.
       
  1410         if ( KErrNotFound != nextIndex && !iIgnoredByUsbEvent &&
       
  1411         	 KErrDisMounted != aError &&
       
  1412             ( ( KErrArgument != aError && KErrCompletion != aError ) ||
       
  1413               iPlaybackState != EPbStatePlaying ))
       
  1414             {
       
  1415             // Check if all tracks are invalid, or if there's only
       
  1416             // 1 track in the playlist
       
  1417             if ( nextIndex == iStartPlaybackIndex ||
       
  1418                  plCount == 1 ||
       
  1419                  EPbRepeatOne == iRepeatMode)
       
  1420                 {
       
  1421                 aError = KMPXAllTracksInvalid;
       
  1422                 }
       
  1423             }
       
  1424 
       
  1425         // Igore these messages when USB event just happened
       
  1426         if (iIgnoredByUsbEvent &&
       
  1427             (aError == KErrCANoRights ||
       
  1428             aError == KErrPathNotFound ||
       
  1429             aError == KErrDisMounted )
       
  1430             )
       
  1431             {
       
  1432             iIgnoredByUsbEvent = EFalse;
       
  1433             return;
       
  1434             }
       
  1435         
       
  1436         // else iIgnoredByUsbEvent==EFalse, then furtherly check USB status in central repository.
       
  1437         else if ( !iIgnoredByUsbEvent )
       
  1438         	{
       
  1439             TInt usbStatus;
       
  1440             RProperty::Get( KPSUidUsbWatcher, KUsbWatcherSelectedPersonality, usbStatus );
       
  1441         
       
  1442             if ( KUsbPersonalityIdMS == usbStatus && KErrDisMounted == aError  )
       
  1443             	{
       
  1444             	// Igore this error when USB is avtive in MassStrorage mode.
       
  1445             	return;
       
  1446             	}
       
  1447             }
       
  1448 
       
  1449         switch ( aError )
       
  1450             {
       
  1451             case KMPXRightsAboutToExpire:
       
  1452             case KErrCANotSupported:
       
  1453             case KErrCANoPermission:
       
  1454             case KErrCANoRights:
       
  1455             case KErrCANoAgent:
       
  1456             case KErrCAOutOfRange:
       
  1457             case KErrCAPendingRights:
       
  1458             case KErrCASizeNotDetermined:
       
  1459             case KErrCANewFileHandleRequired:
       
  1460             case KErrPermissionDenied:
       
  1461                 {
       
  1462                 TBool skip(ETrue);
       
  1463 
       
  1464                 if ( iMedia )
       
  1465                     {
       
  1466                     if ( iMedia->IsSupported( KMPXMediaDrmType ) )
       
  1467                         {
       
  1468                         TMPXMediaDrmType type(
       
  1469                             iMedia->ValueTObjectL<TMPXMediaDrmType>(
       
  1470                                 KMPXMediaDrmType ) );
       
  1471 
       
  1472                         // Only display DRM error message for WMDRM
       
  1473                         // if it's the first song selected
       
  1474                         if ( EMPXDrmTypeWMA == type &&
       
  1475                              currentIndex == iStartPlaybackIndex)
       
  1476                             {
       
  1477 #ifndef CAMESE_IN_DRM_UTILITY
       
  1478                             MPX_DEBUG2("CMPXCommonPlaybackViewImp::HandleErrorL iCameseSuperDistSupport %d", iCameseSuperDistSupport);
       
  1479                             // Only handle the error if Camese is disabled.
       
  1480                             if (!iCameseSuperDistSupport)
       
  1481                                 {
       
  1482                                 MPX_DEBUG2("CMPXCommonPlaybackViewImp::HandleErrorL iNewItemOpened %d", iNewItemOpened);
       
  1483                                 if (iNewItemOpened)
       
  1484                                     {
       
  1485                                     iPlaybackUtility->CommandL( EPbCmdStop );
       
  1486                                     iCommonUiHelper->HandleErrorL( aError, iMedia );
       
  1487                                     // If Camese is off and we
       
  1488                                     // received the collection message
       
  1489                                     // indicating we are opening a new item,
       
  1490                                     // disable skipping on this error.
       
  1491                                     // We just stop playback.
       
  1492                                     skip = EFalse;
       
  1493 
       
  1494                                     // Reset the Start Playback Index.
       
  1495                                     iStartPlaybackIndex = KErrNotFound;
       
  1496                                     }
       
  1497                                 }
       
  1498                             else if (iNewItemOpened)
       
  1499 #else
       
  1500                                 if (iNewItemOpened)
       
  1501 #endif
       
  1502                                     {
       
  1503                                     MPX_DEBUG1("CMPXPlaybackViewImp::HandleErrorL Skip Disabled - New Item");
       
  1504 
       
  1505                                 // If Camese is on and we
       
  1506                                 // received the collection message
       
  1507                                 // indicating we are opening a new item,
       
  1508                                 // disable skipping on this error. Camese will handle
       
  1509                                 // postdelivery in this case.
       
  1510                                 skip = EFalse;
       
  1511 
       
  1512                                 // Reset the Start Playback Index.
       
  1513                                 iStartPlaybackIndex = KErrNotFound;
       
  1514                                 }
       
  1515                             }
       
  1516                         }
       
  1517                     }
       
  1518 
       
  1519                 if (skip)
       
  1520                     {
       
  1521                     SkipOnErrorL( currentIndex, plCount );
       
  1522                     }
       
  1523                 break;
       
  1524                 }
       
  1525             case KErrAccessDenied:
       
  1526                 {
       
  1527                 // Only display error message if first one selected to play
       
  1528                 if ( currentIndex == iStartPlaybackIndex )
       
  1529                     {
       
  1530                     iCommonUiHelper->HandleErrorL( aError, iMedia );
       
  1531                     }
       
  1532                 SkipOnErrorL( currentIndex, plCount );
       
  1533                 break;
       
  1534                 }
       
  1535             case KErrNotSupported:
       
  1536             case KErrCorrupt:
       
  1537             case KErrNotFound:
       
  1538             case KErrPathNotFound:
       
  1539             case KErrDivideByZero:
       
  1540             case KErrGeneral: 
       
  1541                 {
       
  1542                 // USB dismounts the disk, it cannot find any records
       
  1543                 if( !iDatabaseNotReady )
       
  1544                     {
       
  1545                     SkipOnErrorL( currentIndex, plCount );
       
  1546                     }
       
  1547                 break;
       
  1548                 }
       
  1549             case KMPXAllTracksInvalid:
       
  1550                 {
       
  1551                 HandleAllTracksInvalidL();
       
  1552                 break;
       
  1553                 }
       
  1554             case KErrArgument:
       
  1555             case KErrCompletion:
       
  1556                 {
       
  1557                 TBool skip( ETrue );
       
  1558 
       
  1559                 // UI specs say theres two cases where it stops and
       
  1560                 // does not skip to the next song.
       
  1561                 // First case is if not repeat all and playback has
       
  1562                 // reached the end of the list and gone to the first song.
       
  1563                 // Second case is if not repeat all and the user is skipping
       
  1564                 // backwards and reached the first song
       
  1565                 if ( EPbRepeatAll != iRepeatMode &&
       
  1566                      0 == currentIndex &&
       
  1567                      -1 == iLastSkipDirection)
       
  1568                     {
       
  1569                     skip = EFalse;
       
  1570                     }
       
  1571 
       
  1572                 // Skip to next/previous track
       
  1573                 if ( skip )
       
  1574                     {
       
  1575                     if ( iLastSkipDirection < 0 )
       
  1576                         {
       
  1577                         iPlaybackUtility->CommandL( EPbCmdPrevious );
       
  1578                         }
       
  1579                     else
       
  1580                         {
       
  1581                         iPlaybackUtility->CommandL( EPbCmdNext );
       
  1582                         }
       
  1583                     }
       
  1584                 break;
       
  1585                 }
       
  1586             case KErrDiskFull:
       
  1587                 {
       
  1588                 iCommonUiHelper->HandleErrorL( aError, iMedia );
       
  1589                 break;
       
  1590                 }
       
  1591             default:
       
  1592                 {
       
  1593                 iPlaybackUtility->CommandL( EPbCmdStop );
       
  1594                 iCommonUiHelper->HandleErrorL( aError, iMedia );
       
  1595                 break;
       
  1596                 }
       
  1597             }
       
  1598         }
       
  1599 
       
  1600     // Reset flag after error handling is done.
       
  1601     MPX_DEBUG1("CMPXPlaybackViewImp::HandleErrorL()");
       
  1602     MPX_DEBUG1("    > Reset New Item Opened Flag");
       
  1603     iNewItemOpened = EFalse;
       
  1604 
       
  1605     MPX_DEBUG1( "CMPXCommonPlaybackViewImp::HandleErrorL: Exiting");
       
  1606     }
       
  1607 
       
  1608 // ---------------------------------------------------------------------------
       
  1609 // Displays error note for when all tracks are invalid,
       
  1610 // and goes back to collection list view
       
  1611 // ---------------------------------------------------------------------------
       
  1612 //
       
  1613 EXPORT_C void CMPXCommonPlaybackViewImp::HandleAllTracksInvalidL()
       
  1614     {
       
  1615     MPX_DEBUG1("CMPXCommonPlaybackViewImp::HandleAllTracksInvalidL: Entering");
       
  1616     MPX_DEBUG2("CMPXCommonPlaybackViewImp::HandleAllTracksInvalidL: iDatabaseNotReady (%d)", iDatabaseNotReady);
       
  1617 
       
  1618     iPlaybackUtility->CommandL( EPbCmdStop );
       
  1619     UpdatePlaybackState( EPbStateStopped );
       
  1620 
       
  1621     TInt mpxWindowGroupId = CEikonEnv::Static()->RootWin().Identifier();
       
  1622 
       
  1623     // Usb event happened.
       
  1624     if (iDatabaseNotReady)
       
  1625         {
       
  1626         iIgnoredByUsbEvent = ETrue;
       
  1627         }
       
  1628 
       
  1629     // Do not display error if view is not active
       
  1630     if ( iContainer && !iDatabaseNotReady &&
       
  1631          iCommonUiHelper->IsForegroundApplication(mpxWindowGroupId) &&
       
  1632          iViewUtility->ActiveViewType() != TUid::Uid( KMPXPluginTypeEqualizerUid ) )
       
  1633         {
       
  1634         iCommonUiHelper->HandleErrorL( KMPXAllTracksInvalid, iMedia );
       
  1635 
       
  1636         // Check foreground again just in case of user presses end key and switch
       
  1637         // to idle application while error notes are showing
       
  1638         // do not switch view when USB events ongoing
       
  1639         if (!iDatabaseNotReady &&
       
  1640          iCommonUiHelper->IsForegroundApplication(mpxWindowGroupId))
       
  1641             {
       
  1642                 HandleCommandL( EAknSoftkeyBack );
       
  1643             }
       
  1644 
       
  1645         iStartPlaybackIndex = KErrNotFound;
       
  1646         iLastSkipDirection = 1;
       
  1647 
       
  1648         // Reset the playlist to point to the first item
       
  1649         // in list, but do not initialize the song for
       
  1650         // playback
       
  1651         MMPXSource* source( iPlaybackUtility->Source() );
       
  1652         if ( source )
       
  1653             {
       
  1654             CMPXCollectionPlaylist* pl( source->PlaylistL() );
       
  1655             if ( pl )
       
  1656                 {
       
  1657                 CleanupStack::PushL( pl );
       
  1658                 pl->SetToFirst();
       
  1659                 iPlaybackUtility->InitL( *pl, EFalse );
       
  1660                 CleanupStack::PopAndDestroy( pl );
       
  1661                 }
       
  1662             }
       
  1663         }
       
  1664 
       
  1665 
       
  1666     MPX_DEBUG1("CMPXCommonPlaybackViewImp::HandleAllTracksInvalidL: Exiting");
       
  1667     }
       
  1668 
       
  1669 // ---------------------------------------------------------------------------
       
  1670 // Checks whether or not to skip to next track on an error
       
  1671 // ---------------------------------------------------------------------------
       
  1672 //
       
  1673 EXPORT_C void CMPXCommonPlaybackViewImp::SkipOnErrorL(
       
  1674     TInt aCurrentIndex,
       
  1675     TInt aCount )
       
  1676     {
       
  1677     MPX_DEBUG3("CMPXCommonPlaybackViewImp::SkipOnErrorL(%d %d): Entering", aCurrentIndex, aCount);
       
  1678 
       
  1679     TBool skip( ETrue );
       
  1680     TBool displayError( EFalse );
       
  1681 
       
  1682     // If playlist is invalid, don't skip. Fix for error EJPJ-7CVAJX.
       
  1683     if ( aCurrentIndex == KErrNotFound && aCount == KErrNotFound )
       
  1684         {
       
  1685         skip = EFalse;
       
  1686         iCommonUiHelper->HandleErrorL( KErrCorrupt );
       
  1687         }
       
  1688     // UI specs say theres two cases where it stops and
       
  1689     // does not skip to the next song.
       
  1690     // First case is if not repeat all and playback has
       
  1691     // reached the end of the list and gone to the first song.
       
  1692     // Second case is if not repeat all and the user is skipping
       
  1693     // backwards and reached the first song
       
  1694     else if ( EPbRepeatAll != iRepeatMode )
       
  1695         {
       
  1696         if ( 0 == aCurrentIndex &&
       
  1697              -1 == iLastSkipDirection )
       
  1698             {
       
  1699             skip = EFalse;
       
  1700             displayError = ETrue;
       
  1701             }
       
  1702         else if ( aCurrentIndex == aCount-1 &&
       
  1703                   1 == iLastSkipDirection )
       
  1704             {
       
  1705             skip = EFalse;
       
  1706             displayError = ETrue;
       
  1707             }
       
  1708         }
       
  1709    if ( EPbRepeatAll == iRepeatMode )
       
  1710        {
       
  1711        if ( aCurrentIndex == aCount-1 &&
       
  1712                 1 == iLastSkipDirection )
       
  1713            {
       
  1714            skip = EFalse;
       
  1715            displayError = ETrue;
       
  1716            }
       
  1717         }
       
  1718 
       
  1719     // Skip to next/previous track
       
  1720     if ( skip )
       
  1721         {
       
  1722         if ( iLastSkipDirection < 0 )
       
  1723             {
       
  1724             iPlaybackUtility->CommandL( EPbCmdPrevious );
       
  1725             }
       
  1726         else
       
  1727             {
       
  1728             iPlaybackUtility->CommandL( EPbCmdNext );
       
  1729             }
       
  1730         }
       
  1731 
       
  1732     // Display error message
       
  1733     if ( displayError )
       
  1734         {
       
  1735         HandleAllTracksInvalidL();
       
  1736         }
       
  1737 
       
  1738     MPX_DEBUG1("CMPXCommonPlaybackViewImp::SkipOnErrorL: Exiting");
       
  1739     }
       
  1740 
       
  1741 // ---------------------------------------------------------------------------
       
  1742 // Function to display information notes
       
  1743 // ---------------------------------------------------------------------------
       
  1744 //
       
  1745 EXPORT_C void CMPXCommonPlaybackViewImp::DisplayInfoNoteL( TInt aResourceId )
       
  1746     {
       
  1747     HBufC* text = StringLoader::LoadLC( aResourceId );
       
  1748     CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue );
       
  1749     dlg->ExecuteLD( *text );
       
  1750     CleanupStack::PopAndDestroy( text );
       
  1751     }
       
  1752 
       
  1753 // ---------------------------------------------------------------------------
       
  1754 // Function to display confirmation notes
       
  1755 // ---------------------------------------------------------------------------
       
  1756 //
       
  1757 EXPORT_C void CMPXCommonPlaybackViewImp::DisplayConfirmionNoteL( TInt aResourceId )
       
  1758     {
       
  1759     HBufC* text = StringLoader::LoadLC( aResourceId );
       
  1760     CAknConfirmationNote* dlg = new ( ELeave ) CAknConfirmationNote( ETrue );
       
  1761     dlg->ExecuteLD( *text );
       
  1762     CleanupStack::PopAndDestroy( text );
       
  1763     }
       
  1764 
       
  1765 // ---------------------------------------------------------------------------
       
  1766 // Set process priority.
       
  1767 // ---------------------------------------------------------------------------
       
  1768 //
       
  1769 EXPORT_C void CMPXCommonPlaybackViewImp::SetProcessPriority()
       
  1770     {
       
  1771     RProcess thisProcess;
       
  1772     TProcessPriority  pPriority = thisProcess.Priority();
       
  1773 
       
  1774     // Check if playback state is not playing, set to background
       
  1775     TMPXPlaybackState state( EPbStateNotInitialised );
       
  1776     TRAP_IGNORE( state = iPlaybackUtility->StateL() );
       
  1777 
       
  1778     if ( EPbStatePlaying != state && pPriority == EPriorityHigh )
       
  1779         {
       
  1780         MPX_DEBUG1( "CMPXCommonPlaybackViewImp::SetProcessPriority -- setting process priority to EPriorityBackground" );
       
  1781         thisProcess.SetPriority( EPriorityBackground );
       
  1782         }
       
  1783     }
       
  1784 
       
  1785 // ---------------------------------------------------------------------------
       
  1786 // Launch equalizer dialog.
       
  1787 // ---------------------------------------------------------------------------
       
  1788 //
       
  1789 EXPORT_C void CMPXCommonPlaybackViewImp::LaunchEqualizerL()
       
  1790     {
       
  1791 
       
  1792     // Activate Equalizer dialog via View Framework
       
  1793     iViewUtility->ActivateViewL( TUid::Uid( KMPXPluginTypeEqualizerUid ) );
       
  1794 
       
  1795     iContainer->SetRect( ClientRect() );
       
  1796     iContainer->DrawDeferred();
       
  1797     iSwitchingView = EFalse;
       
  1798     }
       
  1799 
       
  1800 
       
  1801 // ---------------------------------------------------------------------------
       
  1802 // Launch Music Settings view.
       
  1803 // ---------------------------------------------------------------------------
       
  1804 //
       
  1805 EXPORT_C void CMPXCommonPlaybackViewImp::LaunchMusicSettingsL()
       
  1806     {
       
  1807     // Activate Audio Effects view via View Framework
       
  1808     iViewUtility->ActivateViewL(
       
  1809         TUid::Uid( KMPXPluginTypeAudioEffectsUid ) );
       
  1810     }
       
  1811 
       
  1812 // ---------------------------------------------------------------------------
       
  1813 // Launch FM Transmitter application
       
  1814 // ---------------------------------------------------------------------------
       
  1815 //
       
  1816 EXPORT_C void CMPXCommonPlaybackViewImp::LaunchFMTransmitterL()
       
  1817     {
       
  1818     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::LaunchFMTransmitterL" );
       
  1819 
       
  1820     if ( FeatureManager::FeatureSupported( KFeatureIdFmtx ) )
       
  1821         {
       
  1822         TApaTaskList tasList( iCoeEnv->WsSession() );
       
  1823         TApaTask task = tasList.FindApp( KFmTxAppUid );
       
  1824         if ( task.Exists() )
       
  1825             {
       
  1826             task.BringToForeground();
       
  1827             }
       
  1828         else
       
  1829             {
       
  1830             RProcess process;
       
  1831             TApaAppInfo appInfo;
       
  1832             RApaLsSession session;
       
  1833             if ( KErrNone == session.Connect() )
       
  1834                 {
       
  1835                 CleanupClosePushL( session );
       
  1836                 TThreadId threadId;
       
  1837                 session.CreateDocument( KNullDesC, KFmTxAppUid, threadId );
       
  1838                 CleanupStack::PopAndDestroy(&session);
       
  1839                 }
       
  1840             }
       
  1841         }
       
  1842     }
       
  1843 
       
  1844 // ---------------------------------------------------------------------------
       
  1845 // Request for the media object
       
  1846 // ---------------------------------------------------------------------------
       
  1847 //
       
  1848 EXPORT_C void CMPXCommonPlaybackViewImp::RequestMediaL( TBool aDrm /*=EFalse*/ )
       
  1849     {
       
  1850     MPX_DEBUG1("CMPXCommonPlaybackViewImp::RequestMediaL(): entering");
       
  1851 
       
  1852     MMPXSource* s = iPlaybackUtility->Source();
       
  1853     if ( s )
       
  1854         {
       
  1855         RArray<TMPXAttribute> attrs;
       
  1856         CleanupClosePushL(attrs);
       
  1857         attrs.Append( KMPXMediaGeneralBasic |
       
  1858                       KMPXMediaGeneralUri |
       
  1859                       KMPXMediaGeneralMimeType |
       
  1860                       KMPXMediaGeneralDuration );
       
  1861         attrs.Append( KMPXMediaMusicAlbumArtFileName |
       
  1862                       KMPXMediaMusicArtist |
       
  1863                       KMPXMediaMusicAlbum );
       
  1864         if ( aDrm )
       
  1865             {
       
  1866             attrs.Append( KMPXMediaDrmAll );
       
  1867             }
       
  1868         else
       
  1869             {
       
  1870             // If not retrieving all drm attributes, then
       
  1871             // minimal is retrieve the protected flag and
       
  1872             // automated flag
       
  1873             attrs.Append( KMPXMediaDrmProtected |
       
  1874                           KMPXMediaDrmCanSetAutomated );
       
  1875             }
       
  1876         s->MediaL( attrs.Array(), *this );
       
  1877         CleanupStack::PopAndDestroy( &attrs );
       
  1878         }
       
  1879     MPX_DEBUG1("CMPXCommonPlaybackViewImp::RequestMediaL(): exiting");
       
  1880     }
       
  1881 
       
  1882 // -----------------------------------------------------------------------------
       
  1883 // CMPXCommonPlaybackViewImp::PrepareStatusPaneForPlaybackViewL
       
  1884 // -----------------------------------------------------------------------------
       
  1885 //
       
  1886 void CMPXCommonPlaybackViewImp::PrepareStatusPaneForPlaybackViewL()
       
  1887     {
       
  1888     iPreviousStatusPaneLayout = StatusPane()->CurrentLayoutResId();
       
  1889     TInt resId( KErrNone );
       
  1890 
       
  1891     if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  1892         {
       
  1893         if ( iPreviousStatusPaneLayout != R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT )
       
  1894             {
       
  1895             resId = R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT;
       
  1896             }
       
  1897         }
       
  1898 
       
  1899     if ( KErrNone != resId )
       
  1900         {
       
  1901         CAknLocalScreenClearer* clearer = CAknLocalScreenClearer::NewLC( ETrue );
       
  1902         StatusPane()->SwitchLayoutL( resId );
       
  1903         CleanupStack::PopAndDestroy( clearer );
       
  1904         }
       
  1905     else if ( iContainer )
       
  1906         {
       
  1907         iContainer->SetRect( ClientRect() );
       
  1908         }
       
  1909     }
       
  1910 
       
  1911 // -----------------------------------------------------------------------------
       
  1912 // CMPXCommonPlaybackViewImp::PrepareStatusPaneForExitingViewL
       
  1913 // -----------------------------------------------------------------------------
       
  1914 //
       
  1915 void CMPXCommonPlaybackViewImp::PrepareStatusPaneForExitingViewL()
       
  1916     {
       
  1917     MPX_FUNC_EX("CMPXCommonPlaybackViewImp::PrepareStatusPaneForExitingViewL()");
       
  1918     if ( StatusPane()->CurrentLayoutResId() !=
       
  1919          iPreviousStatusPaneLayout)
       
  1920         {
       
  1921         StatusPane()->SwitchLayoutL( iPreviousStatusPaneLayout );
       
  1922         }
       
  1923     }
       
  1924 
       
  1925 // ---------------------------------------------------------------------------
       
  1926 // From MMPXPlaybackObserver
       
  1927 // Handle playback message.
       
  1928 // ---------------------------------------------------------------------------
       
  1929 //
       
  1930 EXPORT_C void CMPXCommonPlaybackViewImp::HandlePlaybackMessage(
       
  1931     CMPXMessage* aMessage, TInt aError )
       
  1932     {
       
  1933     MPX_DEBUG2("-->CMPXCommonPlaybackViewImp::HandlePlaybackMessage(): aError = %d", aError);
       
  1934     if ( aError == KErrNone && aMessage )
       
  1935         {
       
  1936         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
  1937         }
       
  1938     else if ( aError != KErrNone && iLastPBViewActivated )
       
  1939         {
       
  1940         TRAP_IGNORE( DoHandleErrorPlaybackMessageL( aError ) );
       
  1941         }
       
  1942     MPX_DEBUG2("<--CMPXCommonPlaybackViewImp::HandlePlaybackMessage(): aError = %d", aError);
       
  1943     }
       
  1944 
       
  1945 // ---------------------------------------------------------------------------
       
  1946 // From MMPXPlaybackCallback
       
  1947 // Handle playback property.
       
  1948 // ---------------------------------------------------------------------------
       
  1949 //
       
  1950 EXPORT_C void CMPXCommonPlaybackViewImp::HandlePropertyL(
       
  1951     TMPXPlaybackProperty aProperty,
       
  1952     TInt aValue,
       
  1953     TInt aError )
       
  1954     {
       
  1955     TRAP_IGNORE( DoHandlePropertyL( aProperty, aValue, aError ) );
       
  1956     }
       
  1957 
       
  1958 // ---------------------------------------------------------------------------
       
  1959 // From MMPXPlaybackCallback
       
  1960 // Method is called continously until aComplete=ETrue, signifying that
       
  1961 // it is done and there will be no more callbacks
       
  1962 // Only new items are passed each time
       
  1963 // ---------------------------------------------------------------------------
       
  1964 //
       
  1965 EXPORT_C void CMPXCommonPlaybackViewImp::HandleSubPlayerNamesL(
       
  1966     TUid /* aPlayer */,
       
  1967     const MDesCArray* /* aSubPlayers */,
       
  1968     TBool /* aComplete */,
       
  1969     TInt /* aError */ )
       
  1970     {
       
  1971     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::HandleSubPlayerNamesL" );
       
  1972     }
       
  1973 
       
  1974 // ---------------------------------------------------------------------------
       
  1975 // From MMPXPlaybackCallback
       
  1976 // Handle media event.
       
  1977 // Notes: The client is responsible for delete the object of aProperties.
       
  1978 // ---------------------------------------------------------------------------
       
  1979 //
       
  1980 EXPORT_C void CMPXCommonPlaybackViewImp::HandleMediaL(
       
  1981     const CMPXMedia& aMedia,
       
  1982     TInt aError )
       
  1983     {
       
  1984     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::HandleMediaL" );
       
  1985     TRAP_IGNORE( DoHandleMediaL( aMedia, aError ));
       
  1986     }
       
  1987 
       
  1988 // ---------------------------------------------------------------------------
       
  1989 // From MMPXCollectionMediaObserver
       
  1990 // Handle extended media properties
       
  1991 // ---------------------------------------------------------------------------
       
  1992 //
       
  1993 EXPORT_C void CMPXCommonPlaybackViewImp::HandleCollectionMediaL(
       
  1994     const CMPXMedia& aMedia,
       
  1995     TInt aError )
       
  1996     {
       
  1997     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::HandleCollectionMediaL" );
       
  1998     TRAP_IGNORE( DoHandleMediaL( aMedia, aError ));
       
  1999     }
       
  2000 
       
  2001 // ---------------------------------------------------------------------------
       
  2002 // From CAknView
       
  2003 // Command handling function.
       
  2004 // ---------------------------------------------------------------------------
       
  2005 //
       
  2006 EXPORT_C void CMPXCommonPlaybackViewImp::HandleCommandL( TInt aCommand )
       
  2007     {
       
  2008     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::HandleCommandL(%d) entering", aCommand );
       
  2009 
       
  2010     switch (aCommand)
       
  2011         {
       
  2012         case EAknCmdHelp:
       
  2013             {
       
  2014             HlpLauncher::LaunchHelpApplicationL(
       
  2015                 iEikonEnv->WsSession(),
       
  2016                 AppUi()->AppHelpContextL() );
       
  2017             break;
       
  2018             }
       
  2019         case EAknSoftkeyBack:
       
  2020             {
       
  2021             AppUi()->HandleCommandL( EMPXCmdGotoCollection );
       
  2022             #ifdef BACKSTEPPING_INCLUDED
       
  2023             // let Back Stepping Service handle the event
       
  2024             TInt statusInfo( KMPXBackSteppingNotConsumed );
       
  2025             if ( iViewUtility &&
       
  2026                 ( iViewUtility->ActiveViewType() != KNullUid ) )
       
  2027                 {
       
  2028                 TInt viewId( iViewUtility->ActiveViewType().iUid );
       
  2029                 TBuf8<KMVPrefixLen + KMaxIntLen> buf;
       
  2030                 buf.Copy( KMVPrefix );
       
  2031                 buf.AppendNum( viewId );
       
  2032                 statusInfo = iBackSteppingUtility->HandleBackCommandL( buf );
       
  2033                 MPX_DEBUG3("CMPXCommonPlaybackViewImp::HandleCommandL - viewid=0x%x, statusInfo=%d",
       
  2034                      viewId, statusInfo );
       
  2035                 }
       
  2036             if ( statusInfo == KMPXBackSteppingNotConsumed )
       
  2037             #endif // BACKSTEPPING_INCLUDED
       
  2038                 {
       
  2039                 if ( !iBacking )
       
  2040                     {
       
  2041                     // event not consumed by Back Stepping utility, handle here
       
  2042                     //
       
  2043                     // Status pane has to be modified before view gets deactivated
       
  2044 
       
  2045                     MMPXSource* source = iPlaybackUtility->Source();
       
  2046                     if ( source )
       
  2047                         {
       
  2048                         CMPXCollectionPlaylist* playlist = source->PlaylistL();
       
  2049                         if ( playlist )
       
  2050                             {
       
  2051                             CleanupStack::PushL( playlist );
       
  2052     						CMPXCollectionPath* browsePath( iCollectionUtility->Collection().PathL() );
       
  2053 							CleanupStack::PushL( browsePath );
       
  2054 					        MPX_DEBUG_PATH(*browsePath);
       
  2055 
       
  2056                             if ( playlist->Count() )
       
  2057                                 {
       
  2058                                 CMPXCollectionPath* pbPath =
       
  2059                                     CMPXCollectionPath::NewL( playlist->Path() );
       
  2060                                 CleanupStack::PushL( pbPath );
       
  2061                                 MPX_DEBUG_PATH(*pbPath);
       
  2062 
       
  2063                                 TInt playbackPathCount( pbPath->Levels() );
       
  2064                                 // if both path are at the same level, we need to check further
       
  2065                                 TBool isEqual( ETrue );
       
  2066                                 if ( browsePath->Levels() == playbackPathCount )
       
  2067                                     {
       
  2068                                     // Check id at each level
       
  2069                                     for ( TInt i = 0; i < playbackPathCount - 1; i++ )
       
  2070                                         {
       
  2071                                         if ( browsePath->Id( i ) != pbPath->Id( i ) )
       
  2072                                             {
       
  2073                                             isEqual = EFalse;
       
  2074                                             break;
       
  2075                                             }
       
  2076                                         }
       
  2077                                     }
       
  2078                                 else
       
  2079                                     {
       
  2080                                     isEqual = EFalse;
       
  2081                                     }
       
  2082       
       
  2083                                 if ( isEqual ) // if they're the same path
       
  2084 									{
       
  2085 									pbPath->Back();
       
  2086 									iViewUtility->PushDefaultHistoryL();
       
  2087 									iCollectionUtility->Collection().OpenL( *pbPath );
       
  2088 									}
       
  2089 								else // we want to reopen the browse path
       
  2090 									{
       
  2091 									browsePath->Back();
       
  2092 									iCollectionUtility->Collection().OpenL( *browsePath );
       
  2093 									}
       
  2094                                 CleanupStack::PopAndDestroy( pbPath );
       
  2095                                 }
       
  2096                             else
       
  2097                                 {
       
  2098                                 // TO-DO: check if collection is empty, activate
       
  2099                                 // music main menu? or change ui spec
       
  2100                                 AppUi()->HandleCommandL( EAknSoftkeyBack );
       
  2101                                 }
       
  2102                             CleanupStack::PopAndDestroy( browsePath );
       
  2103                             CleanupStack::PopAndDestroy( playlist );
       
  2104                             }
       
  2105                         else
       
  2106                             {
       
  2107                             AppUi()->HandleCommandL( EAknSoftkeyBack );
       
  2108                             }
       
  2109                         }
       
  2110                     else
       
  2111                         {
       
  2112                         CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
  2113                         CleanupStack::PushL( cpath );
       
  2114                         while ( cpath->Levels() > 1 )
       
  2115                             {
       
  2116                             cpath->Back();
       
  2117                             }
       
  2118                         iCollectionUtility->Collection().OpenL( *cpath );
       
  2119                         CleanupStack::PopAndDestroy( cpath );
       
  2120                         }
       
  2121                     iBacking = ETrue;
       
  2122                     }
       
  2123                 }
       
  2124             break;
       
  2125             }
       
  2126         case EAknCmdExit:
       
  2127         case EAknSoftkeyExit:
       
  2128         case EEikCmdExit:
       
  2129             {
       
  2130             AppUi()->HandleCommandL( aCommand );
       
  2131             break;
       
  2132             }
       
  2133         case EMPXPbvCmdGotoMusicMenu:
       
  2134             {
       
  2135             AppUi()->HandleCommandL( EMPXCmdGotoCollection );
       
  2136             TInt val(0);
       
  2137             CRepository* repository = CRepository::NewL( KCRUidMPXMPFeatures );
       
  2138             repository->Get( KMPXMPLocalVariation, val );
       
  2139             TBool startInAlbumMenu = val&KMPXStartMusicPlayerinArtistsandAlbums ? ETrue : EFalse;
       
  2140             delete repository;
       
  2141             
       
  2142             if ( startInAlbumMenu )
       
  2143                 {
       
  2144                 CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
       
  2145                 CleanupStack::PushL( cpath );
       
  2146                 cpath->AppendL(3); // Albums
       
  2147                 MPX_DEBUG_PATH(*cpath);
       
  2148                 iCollectionUtility->Collection().OpenL( *cpath );
       
  2149                 CleanupStack::PopAndDestroy( cpath );                
       
  2150                 }
       
  2151             else
       
  2152                 {
       
  2153                 // Handle Goto Music menu
       
  2154                 CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
       
  2155                 CleanupStack::PushL( cpath );
       
  2156                 MPX_DEBUG_PATH (*cpath);
       
  2157                 iCollectionUtility->Collection().OpenL( *cpath );
       
  2158                 CleanupStack::PopAndDestroy( cpath );
       
  2159                 }
       
  2160             // Make sure status pane layout is usual when going
       
  2161             // directly to music menu
       
  2162             // Status pane has to be modified before view gets deactivated
       
  2163             break;
       
  2164             }
       
  2165         case EMPXPbvCmdPlay:
       
  2166             {
       
  2167             if ( iEmbedded )
       
  2168                 {
       
  2169                 iPlaybackUtility->CommandL( EPbCmdDisableEffect );
       
  2170                 }
       
  2171             iPlaybackUtility->CommandL( EPbCmdPlay );
       
  2172             break;
       
  2173             }
       
  2174         case EMPXPbvCmdStop:
       
  2175             {
       
  2176             iPlaybackUtility->CommandL( EPbCmdStop );
       
  2177             break;
       
  2178             }
       
  2179         case EMPXPbvCmdPause:
       
  2180             {
       
  2181             MPX_PERF_CHECKPT("Pause command issued");
       
  2182             iPlaybackUtility->CommandL( EPbCmdPause );
       
  2183             break;
       
  2184             }
       
  2185         case EMPXPbvCmdPlayPause:
       
  2186             {
       
  2187             iPlaybackUtility->CommandL( EPbCmdPlayPause );
       
  2188             break;
       
  2189             }
       
  2190         case EMPXPbvCmdSeekForward:
       
  2191             {
       
  2192             iSkipBtnPressed = ETrue;
       
  2193             iCommandSender = ECsRenderer;
       
  2194             if ( IsCommandSupportedL() )
       
  2195                 {
       
  2196                 iPlaybackUtility->CommandL( EPbCmdStartSeekForward );
       
  2197                 if ( !iKeySoundDisabled )
       
  2198                     {
       
  2199                     iAvkonViewAppUi->KeySounds()->PushContextL(
       
  2200                         R_MPX_PBV_LEFT_RIGHT_KEYS_SILENT );
       
  2201                     iKeySoundDisabled = ETrue;
       
  2202                     }
       
  2203                 }
       
  2204             iUnsupportedNoteDisabled = EFalse;
       
  2205             iIsffButtonPressed = ETrue;
       
  2206             break;
       
  2207             }
       
  2208         case EMPXPbvCmdSeekBackward:
       
  2209             {
       
  2210             iSkipBtnPressed = ETrue;
       
  2211             iCommandSender = ECsRenderer;
       
  2212             if ( IsCommandSupportedL() )
       
  2213                 {
       
  2214                 iPlaybackUtility->CommandL( EPbCmdStartSeekBackward );
       
  2215                 if ( !iKeySoundDisabled )
       
  2216                     {
       
  2217                     iAvkonViewAppUi->KeySounds()->PushContextL(
       
  2218                         R_MPX_PBV_LEFT_RIGHT_KEYS_SILENT );
       
  2219                     iKeySoundDisabled = ETrue;
       
  2220                     }
       
  2221                 }
       
  2222             iUnsupportedNoteDisabled = EFalse;
       
  2223             iIsffButtonPressed = ETrue;
       
  2224             break;
       
  2225             }
       
  2226         case EMPXPbvCmdEndSeek:
       
  2227             {
       
  2228             iSkipBtnPressed = EFalse;
       
  2229             iIsffButtonPressed = EFalse;
       
  2230 			iUnsupportedNoteDisabled = EFalse;
       
  2231             iPlaybackUtility->CommandL( EPbCmdStopSeeking );
       
  2232             if ( iKeySoundDisabled )
       
  2233                 {
       
  2234                 iAvkonViewAppUi->KeySounds()->PopContext();
       
  2235                 iKeySoundDisabled = EFalse;
       
  2236                 }
       
  2237             break;
       
  2238             }
       
  2239         case EMPXPbvCmdNextListItem:
       
  2240             {
       
  2241             // When user skips a track, reset the start playback index
       
  2242             iStartPlaybackIndex = KErrNotFound;
       
  2243             iDelayedErrorTimer->Cancel();
       
  2244 
       
  2245             iPlaybackUtility->CommandL( EPbCmdNext );
       
  2246             break;
       
  2247             }
       
  2248         case EMPXPbvCmdPreviousListItem:
       
  2249             {
       
  2250             // When user skips a track, reset the start playback index
       
  2251             iStartPlaybackIndex = KErrNotFound;
       
  2252             iDelayedErrorTimer->Cancel();
       
  2253 
       
  2254             iPlaybackUtility->CommandL( EPbCmdPrevious );
       
  2255             break;
       
  2256             }
       
  2257         case EMPXPbvCmdDecreaseVolume:
       
  2258             {
       
  2259             iPlaybackUtility->CommandL( EPbCmdDecreaseVolume );
       
  2260             break;
       
  2261             }
       
  2262         case EMPXPbvCmdIncreaseVolume:
       
  2263             {
       
  2264             iPlaybackUtility->CommandL( EPbCmdIncreaseVolume );
       
  2265             break;
       
  2266             }
       
  2267          case EMPXPbvCmdPosition:
       
  2268             {
       
  2269             iIsTapped = ETrue;
       
  2270             iCommandSender = ECsRenderer;
       
  2271             if ( IsCommandSupportedL() && ( iCurrentPlayerType != EPbRemote ) )
       
  2272                 {
       
  2273             TInt newPosition = iContainer->GetNewSongPosition();
       
  2274             iPlaybackUtility->SetL( EPbPropertyPosition, newPosition);
       
  2275                 }
       
  2276             else
       
  2277                 {
       
  2278                 iUnsupportedNoteDisabled = EFalse;
       
  2279                 }
       
  2280             break;
       
  2281             }
       
  2282         case EMPXPbvCmdRepeatOne:
       
  2283             {
       
  2284             iPlaybackUtility->SetL( EPbPropertyRepeatMode, EPbRepeatOne );
       
  2285             break;
       
  2286             }
       
  2287         case EMPXPbvCmdRepeatAll:
       
  2288             {
       
  2289             iPlaybackUtility->SetL( EPbPropertyRepeatMode, EPbRepeatAll );
       
  2290             break;
       
  2291             }
       
  2292         case EMPXPbvCmdRepeatOff:
       
  2293             {
       
  2294             iPlaybackUtility->SetL( EPbPropertyRepeatMode, EPbRepeatOff );
       
  2295             break;
       
  2296             }
       
  2297         case EMPXPbvCmdRandomOn:
       
  2298             {
       
  2299             iPlaybackUtility->SetL( EPbPropertyRandomMode, ETrue );
       
  2300             break;
       
  2301             }
       
  2302         case EMPXPbvCmdRandomOff:
       
  2303             {
       
  2304             iPlaybackUtility->SetL( EPbPropertyRandomMode, EFalse );
       
  2305             break;
       
  2306             }
       
  2307         case EMPXCmdAfterSaveUseAsCascade:
       
  2308             {
       
  2309             CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
  2310             MPX_DEBUG1( "Todd CMPXCommonPlaybackViewImp::HandleCommandL aCommand=EMPXCmdAfterSaveUseAsCascade" );
       
  2311             FillAiwParametersL(paramList, ETrue);
       
  2312             iServiceHandler->ExecuteMenuCmdL(EMPXPbvCmdUseAsCascade, paramList,
       
  2313                 iServiceHandler->OutParamListL());
       
  2314             break;
       
  2315             }
       
  2316         // The clip was saved before setting clip as profile ringtone
       
  2317         case EMPXCmdAfterSaveAiwCmdAssign:
       
  2318             {
       
  2319             CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
  2320             MPX_DEBUG1( "Todd CMPXCommonPlaybackViewImp::HandleCommandL aCommand=EMPXCmdAfterSaveAiwCmdAssign" );
       
  2321             FillAiwParametersL(paramList, ETrue);
       
  2322             iServiceHandler->ExecuteMenuCmdL(EMPXPbvCmdAiwCmdAssign, paramList,
       
  2323                 iServiceHandler->OutParamListL());
       
  2324             break;
       
  2325             }
       
  2326         case EMPXPbvCmdUseAsCascade:
       
  2327         case EMPXPbvCmdAiwCmdAssign:
       
  2328             {
       
  2329             CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
  2330             FillAiwParametersL(paramList, EFalse);
       
  2331             iServiceHandler->ExecuteMenuCmdL(aCommand, paramList,
       
  2332                 iServiceHandler->OutParamListL());
       
  2333             break;
       
  2334             }
       
  2335         case EMPXPbvCmdEqualizer:
       
  2336             {
       
  2337             LaunchEqualizerL();
       
  2338             break;
       
  2339             }
       
  2340         case EMPXPbvCmdOpenMusicSettings:
       
  2341             {
       
  2342             LaunchMusicSettingsL();
       
  2343             break;
       
  2344             }
       
  2345 
       
  2346         case EMPXPbvCmdUpnpPlayViaLocal:
       
  2347             {
       
  2348             if ( iUpnpFrameworkSupport )
       
  2349                 {
       
  2350                 SelectNewPlayerL( aCommand );
       
  2351                 }
       
  2352             break;
       
  2353             }
       
  2354         case EMPXPbvCmdFMTransmitter:
       
  2355             {
       
  2356             LaunchFMTransmitterL();
       
  2357             break;
       
  2358             }
       
  2359         case EMPXPbvCmdAddToSavedPlaylist:
       
  2360             {
       
  2361             AddToSavedPlaylistL();
       
  2362             break;
       
  2363             }
       
  2364         case EMPXPbvCmdAddToNewPlaylist:
       
  2365             {
       
  2366             AddToNewPlaylistL();
       
  2367             break;
       
  2368             }
       
  2369         case EMPXCmdNext:
       
  2370         case EMPXCmdPrevious:
       
  2371             // When user skips a track, reset the start playback index
       
  2372             iStartPlaybackIndex = KErrNotFound;
       
  2373         case EMPXCmdPlay:
       
  2374         case EMPXCmdPause:
       
  2375         case EMPXCmdPlayPause:
       
  2376         case EMPXCmdStop:
       
  2377         case EMPXCmdSeekForward:
       
  2378         case EMPXCmdSeekBackward:
       
  2379         case EMPXCmdStopSeeking:
       
  2380             {
       
  2381             // check if current view is empty
       
  2382             TInt count( 0 );
       
  2383             MMPXSource* s = iPlaybackUtility->Source();
       
  2384             if ( s )
       
  2385                 {
       
  2386                 CMPXCollectionPlaylist* playlist = s->PlaylistL();
       
  2387                 if ( playlist )
       
  2388                     {
       
  2389                     count = playlist->Count();
       
  2390                     }
       
  2391                 delete playlist;
       
  2392                 }
       
  2393 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  2394                 AppUi()->HandleCommandL( aCommand );
       
  2395             count = count; // avoid compilation warning.
       
  2396 #else
       
  2397             if ( count > 0 )
       
  2398                 {
       
  2399                 // only handle command if current playlist is not empty
       
  2400                 AppUi()->HandleCommandL( aCommand );
       
  2401                 }
       
  2402 #endif
       
  2403             break;
       
  2404             }
       
  2405         case EMPXCmdVolumeUp:
       
  2406         case EMPXCmdVolumeDown:
       
  2407         case EMPXCmdVolumeMute:
       
  2408         case EMPXCmdVolumeUnMute:
       
  2409         case EMPXCmdVolumeChanged:
       
  2410             {
       
  2411             AppUi()->HandleCommandL( aCommand );
       
  2412             break;
       
  2413             }
       
  2414         default:
       
  2415             {
       
  2416             if ( iUpnpFrameworkSupport )
       
  2417                 {
       
  2418                 if ( aCommand >= EMPXPbvCmdUpnpPlayViaRemotePlayer )
       
  2419                     {
       
  2420                     SelectNewPlayerL( aCommand );
       
  2421                     }
       
  2422                 else
       
  2423                     {
       
  2424                     AppUi()->HandleCommandL( aCommand );
       
  2425                     }
       
  2426                 }
       
  2427             else
       
  2428                 {
       
  2429                 AppUi()->HandleCommandL( aCommand );
       
  2430                 }
       
  2431             break;
       
  2432             }
       
  2433         }
       
  2434     MPX_DEBUG1( "CMPXCommonPlaybackViewImp::HandleCommandL() exiting" );
       
  2435     }
       
  2436 
       
  2437 // ---------------------------------------------------------------------------
       
  2438 // From CAknView
       
  2439 // Processes user commands.
       
  2440 // ---------------------------------------------------------------------------
       
  2441 //
       
  2442 EXPORT_C void CMPXCommonPlaybackViewImp::ProcessCommandL( TInt aCommand )
       
  2443     {
       
  2444     MPX_DEBUG2("CMPXCommonPlaybackViewImp::ProcessCommandL(%d): entering", aCommand);
       
  2445     if ( aCommand == EAknCmdExit )
       
  2446         {
       
  2447         if ( MenuBar() )
       
  2448             {
       
  2449             MenuBar()->StopDisplayingMenuBar();
       
  2450             }
       
  2451         HandleCommandL( aCommand );
       
  2452         }
       
  2453     CAknView::ProcessCommandL( aCommand );
       
  2454     MPX_DEBUG1("CMPXCommonPlaybackViewImp::ProcessCommandL(): exiting");
       
  2455     }
       
  2456 
       
  2457 // ---------------------------------------------------------------------------
       
  2458 // From CAknView
       
  2459 // Event handler for status pane size changes.
       
  2460 // ---------------------------------------------------------------------------
       
  2461 //
       
  2462 EXPORT_C void CMPXCommonPlaybackViewImp::HandleStatusPaneSizeChange()
       
  2463     {
       
  2464     if ( iContainer && !iSwitchingView )
       
  2465         {
       
  2466         TUid activeView = iViewUtility->ActiveViewImplementationUid();
       
  2467         if ( KMPXEqualizerViewImplementationId == activeView )
       
  2468             {
       
  2469             iContainer->AdjustOrdinalPosition( KMPXPlaybackViewWindowBackground );
       
  2470             }
       
  2471         else 
       
  2472             {
       
  2473             iContainer->SetRect( ClientRect() );
       
  2474             iContainer->DrawDeferred();
       
  2475             }
       
  2476         }
       
  2477     }
       
  2478 
       
  2479 // ---------------------------------------------------------------------------
       
  2480 // From CAknView
       
  2481 // Handles a view activation.
       
  2482 // ---------------------------------------------------------------------------
       
  2483 //
       
  2484 EXPORT_C void CMPXCommonPlaybackViewImp::DoActivateL(
       
  2485     const TVwsViewId& /* aPrevViewId */,
       
  2486     TUid /* aCustomMessageId */,
       
  2487     const TDesC8& /* aCustomMessage */ )
       
  2488     {
       
  2489     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::DoActivateL()" );
       
  2490 
       
  2491     iSwitchingView = EFalse;
       
  2492     iDatabaseNotReady = EFalse;
       
  2493 	iUnsupportedNoteDisabled = EFalse;
       
  2494     delete iOldUri;
       
  2495     iOldUri = NULL;
       
  2496     CAknToolbar* toolbar = Toolbar();
       
  2497     if ( toolbar )
       
  2498         {
       
  2499         AppUi()->AddToStackL(toolbar, 
       
  2500         		ECoeStackPriorityCba,
       
  2501                 ECoeStackFlagRefusesFocus 
       
  2502                 | ECoeStackFlagRefusesAllKeys );
       
  2503         toolbar->MakeVisible( ETrue );
       
  2504         toolbar->HideItemsAndDrawOnlyBackground(EFalse);
       
  2505         toolbar->SetToolbarVisibility(ETrue);
       
  2506         }
       
  2507     PrepareStatusPaneForPlaybackViewL();
       
  2508 
       
  2509     iRandomMode = KErrNotFound;
       
  2510     iRepeatMode = KErrNotFound;
       
  2511 
       
  2512     iBacking = EFalse;
       
  2513     // Update view
       
  2514     // use idle call back since extracting album art binary data is slow
       
  2515     if ( iIdle )
       
  2516         {
       
  2517         if ( iIdle->IsActive() )
       
  2518             {
       
  2519             MPX_DEBUG1( "CMPXCommonPlaybackViewImp::DoActivateL() iIdle active, canceling" );
       
  2520             iIdle->Cancel();
       
  2521             }
       
  2522         delete iIdle;
       
  2523         iIdle = NULL;
       
  2524         }
       
  2525     iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
  2526     iIdle->Start( TCallBack( CMPXCommonPlaybackViewImp::DeferredAlbumArtExtractCallback, this ) );
       
  2527 
       
  2528     // Retrieve current repeat & random modes, fix for EJZU-7NZ9CD 
       
  2529     iPlaybackUtility->PropertyL( *this, EPbPropertyRandomMode );
       
  2530     iPlaybackUtility->PropertyL( *this, EPbPropertyRepeatMode );
       
  2531 
       
  2532     // Set title
       
  2533     // Ignore errors from updating title pane since if that is not
       
  2534     // updated, still want to activate view
       
  2535     TRAP_IGNORE(
       
  2536         {
       
  2537         UpdateTitlePaneL();
       
  2538         CAknNavigationControlContainer* naviPane(
       
  2539             static_cast<CAknNavigationControlContainer*>
       
  2540             ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ))));
       
  2541         if ( naviPane )
       
  2542             {
       
  2543             naviPane->PushDefaultL();
       
  2544             }
       
  2545         } );
       
  2546 
       
  2547     CEikButtonGroupContainer* cba = Cba();
       
  2548     if ( cba )
       
  2549         {
       
  2550         CCoeControl* control = cba->ButtonGroup()->AsControl();
       
  2551         static_cast<CEikCba*>( control )->
       
  2552             SetSkinBackgroundId( KAknsIIDQsnBgAreaControlMp );
       
  2553 
       
  2554 #ifdef __ENABLE_MSK
       
  2555         iCommonUiHelper->SetMiddleSoftKeyLabelL(
       
  2556             *cba,
       
  2557             R_TEXT_SOFTKEY_EMPTY,
       
  2558             EAknSoftkeyForwardKeyEvent );
       
  2559 #endif // __ENABLE_MSK
       
  2560         }
       
  2561 
       
  2562     iPlaybackState = iPlaybackUtility->StateL();
       
  2563     MPX_DEBUG2("CMPXCommonPlaybackViewImp::DoActivateL(): state = %d", iPlaybackState);
       
  2564     if ( iPlaybackState == EPbStateInitialising )
       
  2565         {
       
  2566         delete iMedia;
       
  2567         iMedia = NULL;
       
  2568         UpdatePlaybackState( iPlaybackState );
       
  2569         UpdateTrackInfoL( iMedia );
       
  2570         }
       
  2571     else
       
  2572         {
       
  2573         // reset iNewItemOpened when Playback view is activated when state is
       
  2574         //  not initializing (e.g. user pressed Go to Now Playing view)
       
  2575         MPX_DEBUG1("CMPXCommonPlaybackViewImp::DoActivateL() reset iNewItemOpened");
       
  2576 #ifndef CAMESE_IN_DRM_UTILITY
       
  2577         if (iCameseSuperDistSupport)
       
  2578             {
       
  2579             iNewItemOpened = EFalse;
       
  2580             }
       
  2581 #endif
       
  2582         if ( iMedia == NULL )
       
  2583             {
       
  2584             MMPXSource* s = iPlaybackUtility->Source();
       
  2585             if (  s )
       
  2586                 {
       
  2587                 CMPXCollectionPlaylist* playlist( s->PlaylistL() );
       
  2588                 if ( playlist )
       
  2589                     {
       
  2590                     CleanupStack::PushL( playlist );
       
  2591                     if ( playlist->Count() > 0 )
       
  2592                         {
       
  2593                         RequestMediaL();
       
  2594                         UpdatePlaybackState( iPlaybackState );
       
  2595                         }
       
  2596                     else
       
  2597                         {
       
  2598                         // playlist count is 0, no tracks
       
  2599                         iPlaybackState = EPbStateNotInitialised;
       
  2600                         }
       
  2601                     CleanupStack::PopAndDestroy( playlist );
       
  2602                     }
       
  2603                 else
       
  2604                     {
       
  2605                     // If empty playlist, then no tracks
       
  2606                     iPlaybackState = EPbStateNotInitialised;
       
  2607                     }
       
  2608                 }
       
  2609             }
       
  2610         }
       
  2611     }
       
  2612 
       
  2613 // ---------------------------------------------------------------------------
       
  2614 // From CAknView
       
  2615 // View deactivation function.
       
  2616 // ---------------------------------------------------------------------------
       
  2617 //
       
  2618 EXPORT_C void CMPXCommonPlaybackViewImp::DoDeactivate()
       
  2619     {
       
  2620     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::DoDeactivate()" );
       
  2621     iMPXUtility->CancelRequest();
       
  2622 
       
  2623     if ( iContainer )
       
  2624         {
       
  2625         AppUi()->RemoveFromStack( iContainer );
       
  2626         delete iContainer;
       
  2627         iContainer = NULL;
       
  2628         iBacking = ETrue;
       
  2629         }
       
  2630     // Hide the toolbar when view is deactivated. Otherwise it may interfere
       
  2631     // with other views (e.g. Antriksh based collection view) that doesn't have
       
  2632     // toolbar to not draw correctly.
       
  2633     CAknToolbar* toolbar = Toolbar();
       
  2634     if ( toolbar )
       
  2635         {
       
  2636         toolbar->HideItemsAndDrawOnlyBackground(ETrue);
       
  2637         toolbar->SetToolbarVisibility(EFalse);
       
  2638         toolbar->MakeVisible(EFalse);
       
  2639         AppUi()->RemoveFromStack( toolbar );
       
  2640         }
       
  2641     }
       
  2642 
       
  2643 // ---------------------------------------------------------------------------
       
  2644 // From CAknView
       
  2645 // Foreground event handling function.
       
  2646 // ---------------------------------------------------------------------------
       
  2647 //
       
  2648 EXPORT_C void CMPXCommonPlaybackViewImp::HandleForegroundEventL( TBool aForeground )
       
  2649     {
       
  2650     MPX_DEBUG2( "--->CMPXCommonPlaybackViewImp::HandleForegroundEventL(%d)", aForeground );
       
  2651 
       
  2652 #ifdef BACKSTEPPING_INCLUDED
       
  2653     TInt statusInfo( KMPXBackSteppingNotConsumed );
       
  2654     MPX_DEBUG3("CMPXCommonPlaybackViewImp::HandleForegroundEventL - is in foreground=%d, this view=0x%x",
       
  2655         aForeground, Id().iUid );
       
  2656     if( aForeground &&
       
  2657         iViewUtility &&
       
  2658         ( iViewUtility->ActiveViewImplementationUid() != KNullUid ) )
       
  2659         {
       
  2660         TInt viewId( iViewUtility->ActiveViewType().iUid );
       
  2661         TBuf8<KMVPrefixLen + KMaxIntLen> buf;
       
  2662         buf.Copy( KMVPrefix );
       
  2663         buf.AppendNum( viewId );
       
  2664 
       
  2665         TRAP_IGNORE(
       
  2666             statusInfo =
       
  2667                 iBackSteppingUtility->ForwardActivationEventL( buf, ETrue );
       
  2668             );
       
  2669         MPX_DEBUG3("CMPXCommonPlaybackViewImp::HandleForegroundEventL - viewId=0x%x, statusInfo=%d", viewId, statusInfo );
       
  2670         }
       
  2671 #endif // BACKSTEPPING_INCLUDED
       
  2672 
       
  2673         // Reset state when view's visibility is changed.
       
  2674         iSwitchingView = EFalse;
       
  2675 
       
  2676         CAknView::HandleForegroundEventL( aForeground );
       
  2677         if ( iContainer )
       
  2678             {
       
  2679             iContainer->HandleForegroundEventL( aForeground );
       
  2680             if ( aForeground )
       
  2681                 {
       
  2682                 if ( iMedia )
       
  2683                     {
       
  2684                     MPX_DEBUG1( "CMPXCommonPlaybackViewImp::HandleForegroundEventL iMedia valid" );
       
  2685                     MMPXSource* s = iPlaybackUtility->Source();
       
  2686                     if ( s && iMedia->IsSupported( KMPXMediaGeneralId ) )
       
  2687                         {
       
  2688                         CMPXCollectionPlaylist* playlist = s->PlaylistL();
       
  2689                         if ( playlist )
       
  2690                             {
       
  2691                             MPX_DEBUG1( "CMPXCommonPlaybackViewImp::HandleForegroundEventL playlist valid" );
       
  2692                             const CMPXCollectionPath& path = playlist->Path();
       
  2693                             TMPXItemId id( path.Id() );
       
  2694                             delete playlist;
       
  2695                             TMPXItemId cacheId(
       
  2696                                 iMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  2697                             if ( id != cacheId )
       
  2698                                 {
       
  2699                                 MPX_DEBUG1( "CMPXCommonPlaybackViewImp::HandleForegroundEventL requesting media" );
       
  2700                                 RequestMediaL();
       
  2701                                 UpdateTitlePaneL();
       
  2702                                 }
       
  2703                             }
       
  2704                         }
       
  2705                     }
       
  2706 
       
  2707                 iContainer->StartMarquee( ETextTrack );
       
  2708                 iContainer->StartMarquee( ETextArtist );
       
  2709                 iContainer->DrawNow();
       
  2710                 }
       
  2711             }
       
  2712 
       
  2713     // to stop seek when music player goes to background.
       
  2714     if ( !aForeground && iIsffButtonPressed )
       
  2715         {
       
  2716         iIsffButtonPressed = EFalse;
       
  2717         iContainer->RestoreButtons( iPlaybackState );
       
  2718         iPlaybackUtility->CommandL( EPbCmdStopSeeking );
       
  2719         }
       
  2720 
       
  2721     MPX_DEBUG1( "<---CMPXCommonPlaybackViewImp::HandleForegroundEventL()" );
       
  2722     }
       
  2723 
       
  2724 // ---------------------------------------------------------------------------
       
  2725 // From MEikMenuObserver
       
  2726 // Dynamically initialises a menu pane.
       
  2727 // ---------------------------------------------------------------------------
       
  2728 //
       
  2729 EXPORT_C void CMPXCommonPlaybackViewImp::DynInitMenuPaneL(
       
  2730     TInt aResourceId,
       
  2731     CEikMenuPane* aMenuPane )
       
  2732     {
       
  2733     TInt usbUnblockingStatus;
       
  2734     RProperty::Get( KMPXViewPSUid,
       
  2735                     KMPXUSBUnblockingPSStatus, 
       
  2736                     usbUnblockingStatus);
       
  2737 
       
  2738     switch ( aResourceId )
       
  2739         {
       
  2740         case R_MPX_PLAYBACK_VIEW_MENU:
       
  2741             {
       
  2742             if ( iIsffButtonPressed )
       
  2743                 {
       
  2744                 iIsffButtonPressed = EFalse;
       
  2745                 iContainer->RestoreButtons( iPlaybackState );
       
  2746                 iPlaybackUtility->CommandL( EPbCmdStopSeeking );
       
  2747                 }
       
  2748             if ( !iMedia )
       
  2749                 {
       
  2750                 aMenuPane->SetItemDimmed(
       
  2751                     EMPXPbvCmdRandom,
       
  2752                     ETrue );
       
  2753                 aMenuPane->SetItemDimmed(
       
  2754                     EMPXPbvCmdRepeat,
       
  2755                     ETrue );
       
  2756                 aMenuPane->SetItemDimmed(
       
  2757                     EMPXPbvCmdFMTransmitter,
       
  2758                     ETrue );
       
  2759                 aMenuPane->SetItemDimmed(
       
  2760                     EMPXPbvCmdUpnpPlayVia,
       
  2761                     ETrue );
       
  2762                 aMenuPane->SetItemDimmed(
       
  2763                     EMPXPbvCmdEqualizer,
       
  2764                     ETrue );
       
  2765                 aMenuPane->SetItemDimmed(
       
  2766                     EMPXPbvCmdOpenMusicSettings,
       
  2767                     ETrue );
       
  2768                 aMenuPane->SetItemDimmed(
       
  2769                     EMPXPbvCmdAddToPlaylist,
       
  2770                     ETrue );
       
  2771                 aMenuPane->SetItemDimmed(
       
  2772                     EMPXPbvCmdUseAsCascade,
       
  2773                     ETrue );
       
  2774                 }
       
  2775             else
       
  2776                 {
       
  2777                 if ( KErrNotFound == iRandomMode && iEmbedded )
       
  2778                     {
       
  2779                     aMenuPane->SetItemDimmed(
       
  2780                         EMPXPbvCmdRandom,
       
  2781                         ETrue );
       
  2782                     }
       
  2783                 if ( KErrNotFound == iRepeatMode && iEmbedded )
       
  2784                     {
       
  2785                     aMenuPane->SetItemDimmed(
       
  2786                         EMPXPbvCmdRepeat,
       
  2787                         ETrue );
       
  2788                     }
       
  2789 
       
  2790                 TBool addToPlDimmed( ETrue );
       
  2791                 MMPXSource* s( iPlaybackUtility->Source() );
       
  2792                 if ( s )
       
  2793                     {
       
  2794                     CMPXCollectionPlaylist* playlist( s->PlaylistL() );
       
  2795                     if ( playlist )
       
  2796                         {
       
  2797                         CleanupStack::PushL( playlist );
       
  2798                         TInt count( playlist->Count() );
       
  2799                         if ( count > 0 )
       
  2800                             {
       
  2801                             addToPlDimmed = EFalse;
       
  2802                             }
       
  2803                         CleanupStack::PopAndDestroy( playlist );
       
  2804                         }
       
  2805                     }
       
  2806                 if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  2807                     {
       
  2808                     aMenuPane->SetItemDimmed( EMPXPbvCmdAddToPlaylist, ETrue );
       
  2809                     }
       
  2810                 else
       
  2811                     {
       
  2812                     aMenuPane->SetItemDimmed( EMPXPbvCmdAddToPlaylist, addToPlDimmed );
       
  2813                     }
       
  2814                 TBool isOfflineMode( EFalse );
       
  2815                 TBool isFormatNotSupported( EFalse );
       
  2816                 if ( !isOfflineMode && iMedia )
       
  2817                     {
       
  2818                     if ( iMedia->IsSupported( KMPXMediaDrmProtected ) )
       
  2819                         {
       
  2820                         if ( iMedia->ValueTObjectL<TBool>( KMPXMediaDrmProtected ) &&
       
  2821                             iMedia->IsSupported( KMPXMediaDrmCanSetAutomated ) )
       
  2822                             {
       
  2823                             // if it's drm protected, check if
       
  2824                             // KMPXMediaDrmCanSetAutomated
       
  2825                             isFormatNotSupported = !(
       
  2826                                 iMedia->ValueTObjectL<TBool>( KMPXMediaDrmCanSetAutomated ) );
       
  2827                             }
       
  2828                         }
       
  2829                     }
       
  2830                     aMenuPane->SetItemDimmed(
       
  2831                         EMPXPbvCmdUseAsCascade,
       
  2832                     !iMedia || isFormatNotSupported ||
       
  2833                         iPlaybackState == EPbStateInitialising );
       
  2834 
       
  2835                 // if help is not enabled, do not show "help"
       
  2836                 if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
  2837                     {
       
  2838                     aMenuPane->SetItemDimmed(
       
  2839                         EAknCmdHelp,
       
  2840                         ETrue );
       
  2841                     }
       
  2842 
       
  2843                 // Check if FM Transmitter is supported
       
  2844                 if ( !FeatureManager::FeatureSupported( KFeatureIdFmtx ) )
       
  2845 					{
       
  2846 					aMenuPane->SetItemDimmed(
       
  2847 						EMPXPbvCmdFMTransmitter,
       
  2848 						ETrue );
       
  2849 					}
       
  2850 
       
  2851 
       
  2852                 if ( iUpnpFrameworkSupport )
       
  2853                     {
       
  2854                     if ( !iMedia || !IsUpnpVisible() )
       
  2855                         {
       
  2856                         GetCurrentPlayerDetails();
       
  2857                         if ( iCurrentPlayerType == EPbLocal )
       
  2858                             {
       
  2859                             aMenuPane->SetItemDimmed(
       
  2860                                 EMPXPbvCmdUpnpPlayVia,
       
  2861                                 ETrue);
       
  2862                             }
       
  2863                         }
       
  2864                     }
       
  2865                 else
       
  2866                     {
       
  2867                     aMenuPane->SetItemDimmed( EMPXPbvCmdUpnpPlayVia, ETrue);
       
  2868                     }
       
  2869             aMenuPane->SetItemDimmed( EAknCmdExit, iExitOptionHidden );
       
  2870                 if (iServiceHandler->HandleSubmenuL(*aMenuPane))
       
  2871                     {
       
  2872                     return;
       
  2873                     }
       
  2874                 }
       
  2875             break;
       
  2876             }
       
  2877         case R_MPX_PLAYBACK_PLAY_VIA_SUB_MENU:
       
  2878             {
       
  2879             if ( iUpnpFrameworkSupport )
       
  2880                 {
       
  2881                 AddPlayersNamesToMenuL( *aMenuPane );
       
  2882                 }
       
  2883             break;
       
  2884             }
       
  2885         case R_MPX_PLAYBACK_REPEAT_SUB_MENU:
       
  2886             {
       
  2887             TInt symbolOff = EEikMenuItemSymbolIndeterminate;
       
  2888             TInt symbolAll = EEikMenuItemSymbolIndeterminate;
       
  2889             TInt symbolOne = EEikMenuItemSymbolIndeterminate;
       
  2890 
       
  2891             if ( EPbRepeatOff == iRepeatMode )
       
  2892                 {
       
  2893                 symbolOff = EEikMenuItemSymbolOn;
       
  2894                 }
       
  2895             else if ( EPbRepeatAll == iRepeatMode )
       
  2896                 {
       
  2897                 symbolAll = EEikMenuItemSymbolOn;
       
  2898                 }
       
  2899             else
       
  2900                 {
       
  2901                 symbolOne = EEikMenuItemSymbolOn;
       
  2902                 }
       
  2903 
       
  2904             aMenuPane->SetItemButtonState(
       
  2905                 EMPXPbvCmdRepeatOff,
       
  2906                 symbolOff );
       
  2907             aMenuPane->SetItemButtonState(
       
  2908                 EMPXPbvCmdRepeatAll,
       
  2909                 symbolAll );
       
  2910             aMenuPane->SetItemButtonState(
       
  2911                 EMPXPbvCmdRepeatOne,
       
  2912                 symbolOne );
       
  2913             break;
       
  2914             }
       
  2915         case R_MPX_PLAYBACK_RANDOM_SUB_MENU:
       
  2916             {
       
  2917             TInt symbolOff = EEikMenuItemSymbolOn;
       
  2918             TInt symbolOn = EEikMenuItemSymbolIndeterminate;
       
  2919 
       
  2920             if ( iRandomMode )
       
  2921                 {
       
  2922                 symbolOff = EEikMenuItemSymbolIndeterminate;
       
  2923                 symbolOn = EEikMenuItemSymbolOn;
       
  2924                 }
       
  2925 
       
  2926             aMenuPane->SetItemButtonState(
       
  2927                 EMPXPbvCmdRandomOn,
       
  2928                 symbolOn );
       
  2929             aMenuPane->SetItemButtonState(
       
  2930                 EMPXPbvCmdRandomOff,
       
  2931                 symbolOff );
       
  2932             break;
       
  2933             }
       
  2934         case R_MPX_PBV_ADD_TO_PL_SUB_MENU:
       
  2935             {
       
  2936             TBool dim( ETrue );
       
  2937             delete iUserPlaylists;
       
  2938             iUserPlaylists = NULL;
       
  2939             iUserPlaylists = iCommonUiHelper->FindPlaylistsL();
       
  2940             if ( iUserPlaylists )
       
  2941                 {
       
  2942                 const CMPXMediaArray* mediaArray =
       
  2943                     iUserPlaylists->Value<CMPXMediaArray>(
       
  2944                     KMPXMediaArrayContents );
       
  2945                 User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  2946                
       
  2947                 TInt entriesCount( mediaArray->Count() );
       
  2948                 MPX_DEBUG2( "CMPXCommonPlaybackViewImp::DynInitMenuPaneL Entry count = %d", entriesCount );
       
  2949                 if ( entriesCount > 0 )
       
  2950                     {
       
  2951                     dim = EFalse;
       
  2952                     }
       
  2953                 }
       
  2954             aMenuPane->SetItemDimmed( EMPXPbvCmdAddToSavedPlaylist, dim );
       
  2955             break;
       
  2956             }
       
  2957         default:
       
  2958             {
       
  2959             // Do nothing
       
  2960             break;
       
  2961             }
       
  2962         }
       
  2963     if ( iServiceHandler->IsAiwMenu(aResourceId))
       
  2964         {
       
  2965         MPX_DEBUG1( "CMPXCollectionViewImp::DynInitMenuPaneL(): Aiw menu for assign" );
       
  2966         CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
  2967         FillAiwParametersL(paramList, EFalse);
       
  2968         iServiceHandler->InitializeMenuPaneL(*aMenuPane,
       
  2969                                             aResourceId,
       
  2970                                             EMPXPbvCmdAiwCmdAssign,
       
  2971                                             paramList);
       
  2972         MPX_DEBUG1( "CMPXCollectionViewImp::DynInitMenuPaneL(): Aiw menu for assign end" );
       
  2973         }
       
  2974     }
       
  2975 
       
  2976 // ---------------------------------------------------------------------------
       
  2977 // From MMPXLayoutSwitchObserver
       
  2978 // Callback function when layout is changed.
       
  2979 // ---------------------------------------------------------------------------
       
  2980 //
       
  2981 EXPORT_C void CMPXCommonPlaybackViewImp::HandleLayoutChange()
       
  2982     {
       
  2983     iContainer->ExtractAlbumArtCompleted( NULL, KErrNone );
       
  2984     if (iContainer && !iSwitchingView)
       
  2985         {
       
  2986         if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  2987             {
       
  2988             TUid activeView = iViewUtility->ActiveViewImplementationUid();
       
  2989             
       
  2990             // only switch to flat if current view is not equalizer
       
  2991             // since it'll mess up equilizer's screen
       
  2992             if ( StatusPane()->CurrentLayoutResId() !=
       
  2993                  R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT &&
       
  2994                  activeView != KMPXEqualizerViewImplementationId )
       
  2995                 {
       
  2996                 TRAP_IGNORE(
       
  2997                     StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT ));
       
  2998                 }
       
  2999             }
       
  3000         else
       
  3001             {
       
  3002             if ( StatusPane()->CurrentLayoutResId() !=
       
  3003                  R_AVKON_STATUS_PANE_LAYOUT_USUAL )
       
  3004                 {
       
  3005                 TRAP_IGNORE(
       
  3006                     StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL ));
       
  3007                 }
       
  3008             }
       
  3009 
       
  3010         iContainer->SetRect( ClientRect() );
       
  3011         delete iOldUri;
       
  3012         iOldUri = NULL;         
       
  3013         // Update album art
       
  3014         TRAP_IGNORE( UpdateAlbumArtL( iMedia ));
       
  3015         TRAP_IGNORE( UpdateTrackInfoL( iMedia ));
       
  3016         iContainer->DrawDeferred();
       
  3017         }
       
  3018     }
       
  3019 
       
  3020 // ---------------------------------------------------------------------------
       
  3021 // From MCoeViewDeactivationObserver
       
  3022 // Handles the activation of the view aNewlyActivatedViewId before
       
  3023 // the old view aViewIdToBeDeactivated is to be deactivated.
       
  3024 // ---------------------------------------------------------------------------
       
  3025 //
       
  3026 EXPORT_C void CMPXCommonPlaybackViewImp::HandleViewActivation(
       
  3027     const TVwsViewId& aNewlyActivatedViewId,
       
  3028     const TVwsViewId& aViewIdToBeDeactivated )
       
  3029     {
       
  3030     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::HandleViewActivation AV" );
       
  3031     // Check if this view is going to be deactivated
       
  3032     if ( aViewIdToBeDeactivated.iViewUid == Id() )
       
  3033         {
       
  3034         if ( aNewlyActivatedViewId.iViewUid != Id() )
       
  3035             {
       
  3036             iSwitchingView = ETrue;
       
  3037             }
       
  3038         }
       
  3039 
       
  3040     if ( iPBViewToBeActivated )
       
  3041         {
       
  3042         iLastPBViewActivated = ( aNewlyActivatedViewId.iViewUid == Id() );
       
  3043         MPX_DEBUG2( "CMPXCommonPlaybackViewImp::HandleViewActivation iLastPBViewActivated %d", iLastPBViewActivated );
       
  3044         }
       
  3045     }
       
  3046 
       
  3047 // ---------------------------------------------------------------------------
       
  3048 // From MMPXViewActivationObserver
       
  3049 // Handle view activation.
       
  3050 // ---------------------------------------------------------------------------
       
  3051 //
       
  3052 EXPORT_C void CMPXCommonPlaybackViewImp::HandleViewActivation(
       
  3053     const TUid& aCurrentViewType,
       
  3054     const TUid& /*aPreviousViewType*/ )
       
  3055     {
       
  3056     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::HandleViewActivation VF" );
       
  3057     iPBViewToBeActivated = ( KMPXPluginTypePlaybackUid == aCurrentViewType.iUid );
       
  3058     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::HandleViewActivation iPBViewToBeActivated %d", iPBViewToBeActivated );
       
  3059     }
       
  3060 // ---------------------------------------------------------------------------
       
  3061 // From MMPXViewActivationObserver
       
  3062 // ---------------------------------------------------------------------------
       
  3063 //
       
  3064 EXPORT_C void CMPXCommonPlaybackViewImp::HandleViewUpdate(
       
  3065     TUid /* aViewUid */,
       
  3066     MMPXViewActivationObserver::TViewUpdateEvent /* aUpdateEvent */,
       
  3067     TBool /* aLoaded */,
       
  3068     TInt /* aData */)
       
  3069     {
       
  3070     // Do nothing, this should be handled by the AppUI
       
  3071     }
       
  3072 
       
  3073 // ---------------------------------------------------------------------------
       
  3074 // From MMPXPSKeyObserver
       
  3075 // Handle PS event
       
  3076 // ---------------------------------------------------------------------------
       
  3077 //
       
  3078 EXPORT_C void CMPXCommonPlaybackViewImp::HandlePSEvent(
       
  3079     TUid aUid,
       
  3080     TInt aKey )
       
  3081     {
       
  3082     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::HandlePSEvent %d", aKey );
       
  3083 
       
  3084    	if ( aUid == KPSUidHWRMFmTx && aKey == KHWRMFmTxStatus )
       
  3085        	{
       
  3086        	// only responds to FM TX key value change
       
  3087        	TRAP_IGNORE( UpdateFMTransmitterInfoL() );
       
  3088        	}
       
  3089     }
       
  3090 
       
  3091 // ---------------------------------------------------------------------------
       
  3092 // From MMPXCenRepObserver
       
  3093 // Handle PS event
       
  3094 // ---------------------------------------------------------------------------
       
  3095 //
       
  3096 EXPORT_C void CMPXCommonPlaybackViewImp::HandleSettingChange(
       
  3097     const TUid& aRepositoryUid,
       
  3098     TUint32 aSettingId )
       
  3099     {
       
  3100     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::HandleSettingChange %d", aSettingId );
       
  3101 
       
  3102 	if ( aRepositoryUid == KCRUidFmTxCenRes &&
       
  3103 		 aSettingId == KFmTxCenResKeyFrequency )
       
  3104 		{
       
  3105 		// only responds to FM Tx Frequency value change
       
  3106 		TRAP_IGNORE( UpdateFMTransmitterInfoL() );
       
  3107 		}
       
  3108     }
       
  3109 
       
  3110 // -----------------------------------------------------------------------------
       
  3111 // CMPXCommonPlaybackViewImp::IsUpnpVisible
       
  3112 // Taken from Gallery upnp support implementation
       
  3113 // -----------------------------------------------------------------------------
       
  3114 //
       
  3115 EXPORT_C TBool CMPXCommonPlaybackViewImp::IsUpnpVisible()
       
  3116     {
       
  3117     MPX_FUNC( "CMPXCommonPlaybackViewImp::IsUpnpVisible" );
       
  3118     TBool returnValue = EFalse;
       
  3119     
       
  3120 #ifdef UPNP_INCLUDED
       
  3121    	if ( iUpnpCopyCommand && iUpnpFrameworkSupport ) 	  
       
  3122         {
       
  3123         returnValue = iUpnpCopyCommand->IsAvailableL();   
       
  3124         }
       
  3125 #endif
       
  3126     return returnValue; 
       
  3127 
       
  3128     }
       
  3129 
       
  3130 // -----------------------------------------------------------------------------
       
  3131 // CMPXCommonPlaybackViewImp::AddPlayersNamesToMenuL
       
  3132 // Add all available players names to the Play via submenu
       
  3133 // -----------------------------------------------------------------------------
       
  3134 //
       
  3135 EXPORT_C void CMPXCommonPlaybackViewImp::AddPlayersNamesToMenuL(
       
  3136     CEikMenuPane& aMenuPane )
       
  3137     {
       
  3138     if ( iUpnpFrameworkSupport )
       
  3139         {
       
  3140         RArray<TMPXPlaybackPlayerType> playerTypes;
       
  3141         CleanupClosePushL(playerTypes);
       
  3142 
       
  3143         MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  3144         manager.GetPlayerTypesL(playerTypes);
       
  3145 
       
  3146         GetCurrentPlayerDetails();
       
  3147 
       
  3148         TInt countPlayersTypes( playerTypes.Count() );
       
  3149         TInt countLocalType( 0 );
       
  3150         TInt countRemoteType( 0 );
       
  3151 
       
  3152         if ( countPlayersTypes >= 1 )
       
  3153             {
       
  3154             iPlayersList.Close();
       
  3155 
       
  3156             for ( TInt i = 0; i < countPlayersTypes; i++)
       
  3157                 {
       
  3158                 MPX_DEBUG3( "playerTypes[%d]: %d", i, playerTypes[i] );
       
  3159                 switch (playerTypes[i])
       
  3160                     {
       
  3161                     case EPbLocal:
       
  3162                         {
       
  3163                         // we only show 1 specific type once in the menu
       
  3164                         if ( countLocalType == 0 )
       
  3165                             {
       
  3166                             AddPlayerNameToMenuL( aMenuPane,
       
  3167                                                 EMPXPbvCmdUpnpPlayViaLocal,
       
  3168                                                 manager,
       
  3169                                                 playerTypes[i] );
       
  3170 
       
  3171                             countLocalType++;
       
  3172                             }
       
  3173                         break;
       
  3174                         }
       
  3175                     case EPbRemote:
       
  3176                         {
       
  3177                         // we only show 1 specific type once in the menu
       
  3178                         if ( countRemoteType == 0 )
       
  3179                             {
       
  3180                             AddPlayerNameToMenuL( aMenuPane,
       
  3181                                                 EMPXPbvCmdUpnpPlayViaRemotePlayer,
       
  3182                                                 manager,
       
  3183                                                 playerTypes[i] );
       
  3184                             countRemoteType++;
       
  3185                             }
       
  3186                         break;
       
  3187                         }
       
  3188                     default:
       
  3189                         {
       
  3190                         // default case is handled in the next loop, we want
       
  3191                         // to add any "other" player at the end of the list
       
  3192                         break;
       
  3193                         }
       
  3194                     }
       
  3195                 } // for loop
       
  3196 
       
  3197             for ( TInt i = 0; i < countPlayersTypes; i++)
       
  3198                 {
       
  3199                 MPX_DEBUG3( "playerTypes[%d]: %d", i, playerTypes[i] );
       
  3200                 // EPbLocal and EPbRemote were already added to the
       
  3201                 // submenu in the previous loop
       
  3202                 if ( playerTypes[i] != EPbLocal &&
       
  3203                      playerTypes[i] != EPbRemote )
       
  3204                     {
       
  3205                     // EPbUnknown or else
       
  3206                     TBool alreadyInTheList( EFalse );
       
  3207 
       
  3208                     for ( TInt j = 0; j < i; j++)
       
  3209                         {
       
  3210                         // if the new playertype is already in the list
       
  3211                         if ( playerTypes[i] == playerTypes[j] )
       
  3212                             {
       
  3213                             alreadyInTheList = ETrue;
       
  3214                             break;
       
  3215                             }
       
  3216                         }
       
  3217 
       
  3218                     if ( !alreadyInTheList )
       
  3219                         {
       
  3220                         HBufC* buf = manager.PlayerTypeDisplayNameL(playerTypes[i]);
       
  3221 
       
  3222                         if ( buf )
       
  3223                             {
       
  3224                             CleanupStack::PushL(buf);
       
  3225                             AddPlayerNameToMenuL( aMenuPane,
       
  3226                                                 EMPXPbvCmdUpnpPlayViaRemotePlayer,
       
  3227                                                 manager,
       
  3228                                                 playerTypes[i],
       
  3229                                                 *buf );
       
  3230                             CleanupStack::PopAndDestroy(buf);
       
  3231                             }
       
  3232                         // else we don't do anything. other player type is not
       
  3233                         // currently supported. Implementation will be finalized
       
  3234                         // when the requirement is defined.
       
  3235                         }
       
  3236                     }
       
  3237                 }
       
  3238             }
       
  3239 
       
  3240         CleanupStack::PopAndDestroy(&playerTypes);
       
  3241 
       
  3242         if ( iPlayersList.Count() <= 1 )
       
  3243             {
       
  3244             aMenuPane.SetItemDimmed( EMPXPbvCmdUpnpPlayViaRemotePlayer,
       
  3245                                       ETrue );
       
  3246             }
       
  3247         }
       
  3248     else
       
  3249         {
       
  3250         // Remove compilation warnings
       
  3251         (void)aMenuPane;
       
  3252         }
       
  3253     }
       
  3254 
       
  3255 // -----------------------------------------------------------------------------
       
  3256 // CMPXCommonPlaybackViewImp::AddPlayerNameToMenuL
       
  3257 // Add 1 player name to the submenu
       
  3258 // -----------------------------------------------------------------------------
       
  3259 //
       
  3260 EXPORT_C void CMPXCommonPlaybackViewImp::AddPlayerNameToMenuL(
       
  3261     CEikMenuPane& aMenuPane,
       
  3262     TInt aCommandId,
       
  3263     MMPXPlayerManager& aPlayerManager,
       
  3264     TMPXPlaybackPlayerType& aPlayerType,
       
  3265     const TDesC& aMenuText )
       
  3266     {
       
  3267     if ( iUpnpFrameworkSupport )
       
  3268         {
       
  3269         RArray<TUid> players;
       
  3270         CleanupClosePushL(players);
       
  3271         aPlayerManager.GetPlayerListL(players, aPlayerType);
       
  3272 
       
  3273         // For now we only keep the first player we find
       
  3274         // Local player is always the first one in the list
       
  3275         // Ui spec limitation
       
  3276         MPX_DEBUG2( "players[0]: %d", players[0].iUid );
       
  3277         if ( aCommandId == EMPXPbvCmdUpnpPlayViaLocal )
       
  3278             {
       
  3279             iPlayersList.Insert(players[0], 0);
       
  3280             }
       
  3281         else if ( ( aCommandId == EMPXPbvCmdUpnpPlayViaRemotePlayer ) &&
       
  3282                   (iPlayersList.Count() > 1) )
       
  3283             {
       
  3284             iPlayersList.Insert(players[0], 1);
       
  3285             }
       
  3286         else
       
  3287             {
       
  3288             iPlayersList.AppendL(players[0]);
       
  3289             }
       
  3290         CleanupStack::PopAndDestroy(&players);
       
  3291 
       
  3292         // if the player is of unknown type
       
  3293         if ( ( aCommandId != EMPXPbvCmdUpnpPlayViaRemotePlayer ) &&
       
  3294              ( aCommandId != EMPXPbvCmdUpnpPlayViaLocal ) )
       
  3295             {
       
  3296             CEikMenuPaneItem::SData menuItem;
       
  3297             menuItem.iText.Copy( aMenuText );
       
  3298             menuItem.iCascadeId = 0;
       
  3299             menuItem.iFlags = EEikMenuItemRadioEnd;
       
  3300 
       
  3301             menuItem.iCommandId = aCommandId + (iPlayersList.Count() - 1);
       
  3302             aCommandId = menuItem.iCommandId;
       
  3303 
       
  3304             aMenuPane.AddMenuItemL( menuItem );
       
  3305             }
       
  3306 
       
  3307         if ( iCurrentPlayerType == aPlayerType )
       
  3308             {
       
  3309             aMenuPane.SetItemButtonState( aCommandId, EEikMenuItemSymbolOn );
       
  3310             }
       
  3311         }
       
  3312     else
       
  3313         {
       
  3314         // Remove compilation warnings
       
  3315         (void)aMenuPane;
       
  3316         (void)aCommandId;
       
  3317         (void)aPlayerManager;
       
  3318         (void)aPlayerType;
       
  3319         (void)aMenuText;
       
  3320         }
       
  3321     }
       
  3322 
       
  3323 // -----------------------------------------------------------------------------
       
  3324 // CMPXCommonPlaybackViewImp::GetCurrentPlayerDetails
       
  3325 // Retrieves the current player name and type
       
  3326 // -----------------------------------------------------------------------------
       
  3327 //
       
  3328 EXPORT_C void CMPXCommonPlaybackViewImp::GetCurrentPlayerDetails()
       
  3329     {
       
  3330     if ( iUpnpFrameworkSupport )
       
  3331         {
       
  3332 
       
  3333         MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  3334         TUid currentlyUsedPlayer;
       
  3335         TInt currentlyUsedSubPlayer;
       
  3336         iCurrentPlayerType = EPbLocal;
       
  3337         delete iSubPlayerName;
       
  3338         iSubPlayerName = NULL;
       
  3339 
       
  3340         TRAP_IGNORE( manager.GetSelectionL( iCurrentPlayerType,
       
  3341                                             currentlyUsedPlayer,
       
  3342                                             currentlyUsedSubPlayer,
       
  3343                                             iSubPlayerName) );
       
  3344         }
       
  3345     }
       
  3346 
       
  3347 // -----------------------------------------------------------------------------
       
  3348 // CMPXCommonPlaybackViewImp::SelectNewPlayerL
       
  3349 // Selects a new player for audio playback
       
  3350 // -----------------------------------------------------------------------------
       
  3351 //
       
  3352 EXPORT_C void CMPXCommonPlaybackViewImp::SelectNewPlayerL(
       
  3353     TInt aCommand )
       
  3354     {
       
  3355     if ( iUpnpFrameworkSupport )
       
  3356         {
       
  3357         MPX_FUNC_EX( "CMPXPlaybackViewImp::SelectNewPlayerL()" );
       
  3358         MPX_DEBUG2( "CMPXPlaybackViewImp::SelectNewPlayerL(%d)", aCommand );
       
  3359 
       
  3360         TInt errorSelectPlayer( KErrCancel );
       
  3361 
       
  3362         MMPXSource* source = iPlaybackUtility->Source();
       
  3363         CMPXCollectionPlaylist* playlist = NULL;
       
  3364         if ( source )
       
  3365             {
       
  3366             playlist = source->PlaylistL();
       
  3367             if ( playlist )
       
  3368                 {
       
  3369                 iPlaybackUtility->CommandL(EPbCmdPreserveState);
       
  3370                 CleanupStack::PushL( playlist );
       
  3371                 }
       
  3372             }
       
  3373 
       
  3374         switch (aCommand)
       
  3375             {
       
  3376             case EMPXPbvCmdUpnpPlayViaLocal:
       
  3377                 {
       
  3378                 // if Local is not already the current player, select it
       
  3379                 if ( iCurrentPlayerType != EPbLocal )
       
  3380                     {
       
  3381                     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  3382                     MPX_TRAP( errorSelectPlayer, manager.ClearSelectPlayersL() );
       
  3383                     }
       
  3384                 break;
       
  3385                 }
       
  3386             default:
       
  3387                 {
       
  3388                 if ( aCommand >= EMPXPbvCmdUpnpPlayViaRemotePlayer )
       
  3389                     {
       
  3390                     HBufC* buf = HBufC::NewLC( KMaxUidName );
       
  3391                     buf->Des().AppendNum(
       
  3392                          (iPlayersList[aCommand -
       
  3393                                        EMPXPbvCmdUpnpPlayViaLocal]).iUid );
       
  3394 
       
  3395                     // ActivateViewL leaves with KErrCancel if the dialog is
       
  3396                     // cancelled
       
  3397                     // ActivateViewL leaves with KErrInUse if the selected player
       
  3398                     // is already the active player
       
  3399                     MPX_TRAP(errorSelectPlayer, iViewUtility->ActivateViewL(
       
  3400                                     TUid::Uid( KMPXPluginTypeUPnPBrowseDialogUid ),
       
  3401                                     buf ));
       
  3402                     CleanupStack::PopAndDestroy( buf );
       
  3403                     }
       
  3404                 break;
       
  3405                 }
       
  3406             }
       
  3407 
       
  3408         // A new player was successfully selected, playback view changes
       
  3409         if ( errorSelectPlayer == KErrNone )
       
  3410             {
       
  3411             if ( playlist )
       
  3412                 {
       
  3413                 iViewUtility->PushDefaultHistoryL();
       
  3414                 iPlaybackUtility->InitL( *playlist, ETrue );
       
  3415                 }
       
  3416             }
       
  3417 
       
  3418         if (playlist)
       
  3419             {
       
  3420             CleanupStack::PopAndDestroy( playlist );
       
  3421             }
       
  3422         }
       
  3423     else
       
  3424         {
       
  3425         // Remove compilation warnings
       
  3426         (void)aCommand;
       
  3427         }
       
  3428     }
       
  3429 
       
  3430 // -----------------------------------------------------------------------------
       
  3431 // CMPXCommonPlaybackViewImp::AddToSavedPlaylistL
       
  3432 // Adds current item to a saved playlist
       
  3433 // -----------------------------------------------------------------------------
       
  3434 //
       
  3435 EXPORT_C void CMPXCommonPlaybackViewImp::AddToSavedPlaylistL()
       
  3436     {
       
  3437     MPX_DEBUG1("CMPXPlaybackViewImp::AddToSavedPlaylistL(): entering");
       
  3438 
       
  3439     ASSERT( iMedia );
       
  3440     if ( !iUserPlaylists )
       
  3441         {
       
  3442         iUserPlaylists = iCommonUiHelper->FindPlaylistsL();
       
  3443         }
       
  3444 
       
  3445     CMPXMedia* media = PrepareMediaForPlaylistLC( *iMedia );
       
  3446     MPX_TRAPD( err, iCommonUiHelper->AddToSavedPlaylistL(
       
  3447         *iUserPlaylists,
       
  3448         *media,
       
  3449         this,
       
  3450         this ) );
       
  3451     CleanupStack::PopAndDestroy( media );
       
  3452     if ( KErrNone != err )
       
  3453         {
       
  3454         HandleErrorL( err );
       
  3455         }
       
  3456     delete iUserPlaylists;
       
  3457     iUserPlaylists = NULL;
       
  3458 
       
  3459     MPX_DEBUG1("CMPXPlaybackViewImp::AddToSavedPlaylistL(): exiting");
       
  3460     }
       
  3461 
       
  3462 // -----------------------------------------------------------------------------
       
  3463 // CMPXCommonPlaybackViewImp::AddToNewPlaylistL
       
  3464 // Adds current item to a new playlist
       
  3465 // -----------------------------------------------------------------------------
       
  3466 //
       
  3467 EXPORT_C void CMPXCommonPlaybackViewImp::AddToNewPlaylistL()
       
  3468     {
       
  3469     MPX_DEBUG1("CMPXPlaybackViewImp::AddToNewPlaylistL(): entering");
       
  3470 
       
  3471     if ( iMedia )
       
  3472         {
       
  3473         CMPXMedia* media( PrepareMediaForPlaylistLC( *iMedia ));
       
  3474         iCommonUiHelper->CreatePlaylistL(
       
  3475             *media,
       
  3476             this,
       
  3477             this );
       
  3478         CleanupStack::PopAndDestroy( media );
       
  3479         }
       
  3480     delete iUserPlaylists;
       
  3481     iUserPlaylists = NULL;
       
  3482 
       
  3483     MPX_DEBUG1("CMPXPlaybackViewImp::AddToNewPlaylistL(): exiting");
       
  3484     }
       
  3485 
       
  3486 // ---------------------------------------------------------------------------
       
  3487 // PrepareMediaForPlaylistLC
       
  3488 // Prepares media for adding to a playlist
       
  3489 // ---------------------------------------------------------------------------
       
  3490 //
       
  3491 EXPORT_C CMPXMedia* CMPXCommonPlaybackViewImp::PrepareMediaForPlaylistLC(
       
  3492     const CMPXMedia& aMedia )
       
  3493     {
       
  3494     MPX_DEBUG1("CMPXPlaybackViewImp::PrepareMediaForPlaylistLC() entering");
       
  3495 
       
  3496     CMPXMedia* media = CMPXMedia::NewL();
       
  3497     CleanupStack::PushL( media );
       
  3498     CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
  3499     CleanupStack::PushL( mediaArray );
       
  3500     CMPXMedia* entry = CMPXMedia::NewL( aMedia );
       
  3501     CleanupStack::PushL( entry );
       
  3502     mediaArray->AppendL( entry );
       
  3503     CleanupStack::Pop( entry );
       
  3504     media->SetCObjectValueL(
       
  3505         KMPXMediaArrayContents,
       
  3506         mediaArray );
       
  3507     media->SetTObjectValueL(
       
  3508         KMPXMediaArrayCount,
       
  3509         mediaArray->Count() );
       
  3510     CleanupStack::PopAndDestroy( mediaArray );
       
  3511     MPX_DEBUG1("CMPXPlaybackViewImp::PrepareMediaForPlaylistLC() exiting");
       
  3512     return media;
       
  3513     }
       
  3514 
       
  3515 // -----------------------------------------------------------------------------
       
  3516 // CMPXCommonPlaybackViewImp::IsCommandSupportedL
       
  3517 // Check if the command is supported by the remote player
       
  3518 // -----------------------------------------------------------------------------
       
  3519 //
       
  3520 EXPORT_C TBool CMPXCommonPlaybackViewImp::IsCommandSupportedL()
       
  3521     {
       
  3522     TBool forwardCommand = ETrue;
       
  3523     if ( iUpnpFrameworkSupport && IsUpnpVisible() )
       
  3524         {
       
  3525         // retrieve iCurrentPlayerType info
       
  3526         GetCurrentPlayerDetails();
       
  3527 
       
  3528         if ( iCurrentPlayerType != EPbLocal)
       
  3529             {
       
  3530             // show error note, only in first key press
       
  3531 		    if( !iUnsupportedNoteDisabled )
       
  3532 			    {
       
  3533 			    iUnsupportedNoteDisabled = ETrue;
       
  3534 			    iOldPosition = iPosition;
       
  3535 			    if( iContainer && iIsTapped )
       
  3536 			        {
       
  3537 			        iContainer->SetNewSongPosition( iPosition * KMPXOneSecInMilliSecs );
       
  3538 			        }
       
  3539 			    HBufC* dialogText = NULL;
       
  3540 			    TBool setText = EFalse;
       
  3541                 switch ( iCommandSender )
       
  3542                     {
       
  3543                     case ECsMediaKey:
       
  3544                         {
       
  3545                         dialogText = StringLoader::LoadLC( R_MPX_MEDIA_KEYS_NOT_SUPPORTED );
       
  3546                         setText = ETrue;
       
  3547                         break;
       
  3548                         }
       
  3549                     case ECsRenderer:
       
  3550                         {
       
  3551                         dialogText = StringLoader::LoadLC( R_MPX_REQUEST_REJECTED );
       
  3552                         setText = ETrue;
       
  3553                         break;
       
  3554                         }
       
  3555                     default:
       
  3556                         {
       
  3557                         break;
       
  3558                         }
       
  3559                     }
       
  3560                 
       
  3561                 if( setText )
       
  3562                     {
       
  3563                 CAknErrorNote* errNote = new(ELeave) CAknErrorNote(ETrue);
       
  3564                 errNote->SetTimeout(CAknNoteDialog::ELongTimeout);
       
  3565                 errNote->ExecuteLD( *dialogText );
       
  3566                 CleanupStack::PopAndDestroy( dialogText );
       
  3567                 forwardCommand = EFalse;
       
  3568                     }
       
  3569 			    }
       
  3570             }
       
  3571         }
       
  3572     return forwardCommand;
       
  3573     }
       
  3574 
       
  3575 // ---------------------------------------------------------------------------
       
  3576 // From MProgressDialogCallback
       
  3577 // Callback method. Get's called when a dialog is dismissed
       
  3578 // ---------------------------------------------------------------------------
       
  3579 //
       
  3580 EXPORT_C void CMPXCommonPlaybackViewImp::DialogDismissedL( TInt aButtonId )
       
  3581     {
       
  3582     MPX_DEBUG2("--->CMPXCommonPlaybackViewImp::DialogDismissedL(%d)", aButtonId);
       
  3583     switch (aButtonId)
       
  3584         {
       
  3585         case EAknSoftkeyCancel:
       
  3586         case EAknSoftkeyDone:
       
  3587             {
       
  3588             break;
       
  3589             }
       
  3590         default:
       
  3591             {
       
  3592             break;
       
  3593             }
       
  3594         }
       
  3595     MPX_DEBUG1("<---CMPXCommonPlaybackViewImp::DialogDismissedL()");
       
  3596     }
       
  3597 
       
  3598 // ---------------------------------------------------------------------------
       
  3599 // From MMPXCHelperObserver
       
  3600 // Callback method. Get's called when a dialog is dismissed
       
  3601 // ---------------------------------------------------------------------------
       
  3602 //
       
  3603 EXPORT_C void CMPXCommonPlaybackViewImp::HandleOperationCompleteL( TCHelperOperation /*aOperation*/,
       
  3604                                                                    TInt aError,
       
  3605                                                                    void* aArgument )
       
  3606     {
       
  3607     MPX_DEBUG2("CMPXPlaybackViewImp::HandleAddCompletedL(%d) entering", aError);
       
  3608 
       
  3609     CMPXMedia* playlist = (CMPXMedia*) aArgument;
       
  3610     CleanupStack::PushL( playlist );
       
  3611 
       
  3612     iCommonUiHelper->DismissWaitNoteL();
       
  3613     if ( KErrNone == aError )
       
  3614         {
       
  3615         const TDesC& title( playlist->ValueText( KMPXMediaGeneralTitle ) );
       
  3616         HBufC* confirmTxt( StringLoader::LoadLC(
       
  3617             R_MPX_QTN_MUS_NOTE_TRACK_ADDED_TO_PL,
       
  3618             title ));
       
  3619         CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote();
       
  3620 
       
  3621         TMPlayerSecondaryDisplayNote noteId( EMPlayerNoteAddSongToPlaylist );
       
  3622         note->PublishDialogL(
       
  3623             noteId,
       
  3624             KMPlayerNoteCategory );
       
  3625         CAknMediatorFacade* covercl( AknMediatorFacade( note ) );
       
  3626         if ( covercl )
       
  3627             {
       
  3628             covercl->BufStream() << title;
       
  3629             }
       
  3630 
       
  3631         note->ExecuteLD( *confirmTxt );
       
  3632         CleanupStack::PopAndDestroy( confirmTxt );
       
  3633         }
       
  3634     else
       
  3635         {
       
  3636         HandleErrorL( aError );
       
  3637         }
       
  3638     CleanupStack::PopAndDestroy( playlist );
       
  3639     MPX_DEBUG1("CMPXPlaybackViewImp::HandleAddCompletedL() exiting");
       
  3640     }
       
  3641 
       
  3642 // -----------------------------------------------------------------------------
       
  3643 // From MMPXCollectionObserver
       
  3644 // -----------------------------------------------------------------------------
       
  3645 //
       
  3646 EXPORT_C void CMPXCommonPlaybackViewImp::HandleCollectionMessage(CMPXMessage* aMsg,
       
  3647                                                                  TInt aErr )
       
  3648     {
       
  3649     TRAP_IGNORE( DoHandleCollectionMessageL( aMsg, aErr ) );
       
  3650     }
       
  3651 
       
  3652 // -----------------------------------------------------------------------------
       
  3653 // From MMPXCollectionObserver
       
  3654 // -----------------------------------------------------------------------------
       
  3655 //
       
  3656 EXPORT_C void CMPXCommonPlaybackViewImp::HandleOpenL(const CMPXMedia& /*aEntries*/, TInt /*aIndex*/,
       
  3657                                                      TBool /*aComplete*/, TInt /*aError*/)
       
  3658     {
       
  3659     // Do Nothing
       
  3660     }
       
  3661 
       
  3662 // -----------------------------------------------------------------------------
       
  3663 // From MMPXCollectionObserver
       
  3664 // -----------------------------------------------------------------------------
       
  3665 //
       
  3666 EXPORT_C void CMPXCommonPlaybackViewImp::HandleOpenL(const CMPXCollectionPlaylist& /*aPlaylist*/,
       
  3667                                                      TInt /*aError*/)
       
  3668     {
       
  3669     // Do Nothing
       
  3670     }
       
  3671 
       
  3672 // -----------------------------------------------------------------------------
       
  3673 // From MMPXCollectionObserver
       
  3674 // -----------------------------------------------------------------------------
       
  3675 //
       
  3676 EXPORT_C void CMPXCommonPlaybackViewImp::HandleCommandComplete(CMPXCommand* /*aCommandResult*/,
       
  3677                                                                TInt /*aError*/)
       
  3678     {
       
  3679     // Do Nothing
       
  3680     }
       
  3681 
       
  3682 // ----------------------------------------------------------------------------
       
  3683 // void CMPXCommonPlaybackViewImp::DeferredAlbumArtExtractCallback
       
  3684 // call back function for deferred view updates.
       
  3685 // ----------------------------------------------------------------------------
       
  3686 //
       
  3687 TInt CMPXCommonPlaybackViewImp::DeferredAlbumArtExtractCallback( TAny* aPtr )
       
  3688     {
       
  3689     MPX_FUNC( "CMPXCommonPlaybackViewImp::DeferredAlbumArtExtractCallback" );
       
  3690     CMPXCommonPlaybackViewImp* self =
       
  3691         static_cast<CMPXCommonPlaybackViewImp*>( aPtr );
       
  3692     TRAP_IGNORE( self->UpdateViewL() );
       
  3693     return KErrNone;
       
  3694     }
       
  3695 
       
  3696 //----------------------------------------------------------------------------
       
  3697 // CMPXCommonPlaybackViewImp::DelayedExit
       
  3698 // call back function for delayed view deactivation
       
  3699 //----------------------------------------------------------------------------
       
  3700 //
       
  3701 TInt CMPXCommonPlaybackViewImp::DelayedExit( TAny* aPtr )
       
  3702     {
       
  3703     MPX_FUNC( "CMPXCommonPlaybackViewImp::DelayedExit" );
       
  3704     CMPXCommonPlaybackViewImp* self =
       
  3705         static_cast<CMPXCommonPlaybackViewImp*>( aPtr );
       
  3706     TRAP_IGNORE( self->HandleCommandL(EAknSoftkeyBack) );
       
  3707     return KErrNone;
       
  3708     }
       
  3709 
       
  3710 // ---------------------------------------------------------------------------
       
  3711 // Handle playback error message.
       
  3712 // ---------------------------------------------------------------------------
       
  3713 //
       
  3714 void CMPXCommonPlaybackViewImp::DoHandleErrorPlaybackMessageL( TInt aError )
       
  3715     {
       
  3716     MPX_DEBUG2( "CMPXCommonPlaybackViewImp::DoHandleErrorPlaybackMessage(): Handle the error %d", aError);
       
  3717 
       
  3718     // Request media to handle error. We need to do that in
       
  3719     // order to request DRM details.
       
  3720     iDelayedError = aError;
       
  3721     RequestMediaL( ETrue );
       
  3722     }
       
  3723 
       
  3724 // ---------------------------------------------------------------------------
       
  3725 // Handle collection message
       
  3726 // ---------------------------------------------------------------------------
       
  3727 //
       
  3728 void CMPXCommonPlaybackViewImp::DoHandleCollectionMessageL(
       
  3729     CMPXMessage* aMsg, TInt /*aErr*/ )
       
  3730     {
       
  3731     MPX_FUNC_EX( "CMPXCommonPlaybackViewImp::DoHandleCollectionMessageL" );
       
  3732     if( aMsg )
       
  3733         {
       
  3734         TMPXMessageId id( aMsg->ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  3735         if ( KMPXMessageGeneral == id )
       
  3736             {
       
  3737             TInt event( aMsg->ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
  3738             TInt op( aMsg->ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  3739             TInt data( aMsg->ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  3740 
       
  3741             if( event == TMPXCollectionMessage::EBroadcastEvent &&
       
  3742                 op == EMcMsgDiskRemoved &&
       
  3743                 iContainer &&
       
  3744                 iViewUtility->ActiveViewType() != TUid::Uid(KMPXPluginTypeWaitNoteDialogUid) )
       
  3745                 {
       
  3746                 TRAP_IGNORE( AknDialogShutter::ShutDialogsL( *CEikonEnv::Static() ) );
       
  3747                 StopDisplayingMenuBar();
       
  3748                 TRAP_IGNORE( UpdateTitlePaneL() );  // some dialogs change the title. ie equalizer
       
  3749                 }
       
  3750             else if( event == TMPXCollectionMessage::EBroadcastEvent )
       
  3751                 {
       
  3752                 if( op == EMcMsgUSBMassStorageStart ||
       
  3753                     op == EMcMsgUSBMTPStart ||
       
  3754                     op == EMcMsgFormatStart )
       
  3755                     {
       
  3756                     iDatabaseNotReady = ETrue;
       
  3757                     }
       
  3758                 else if( op == EMcMsgUSBMassStorageEnd ||
       
  3759                          op == EMcMsgUSBMTPEnd ||
       
  3760                          op == EMcMsgFormatEnd )
       
  3761                     {
       
  3762                     iDatabaseNotReady = EFalse;
       
  3763                     }
       
  3764                 else if( op == EMcMsgDiskInserted )
       
  3765                     {
       
  3766                     // Need to reset the prev/next buttons state if they are pressed at the moment.
       
  3767                     if (iSkipBtnPressed)
       
  3768                         {
       
  3769                         if ( AknLayoutUtils::PenEnabled() )
       
  3770                             {
       
  3771                             if ( Toolbar() )
       
  3772                                 {
       
  3773                                 CAknToolbar* toolbar = Toolbar();
       
  3774                                 CAknButton* skipControl;
       
  3775                                 skipControl = (CAknButton*)(toolbar->ComponentControl( 0 ));
       
  3776                                 skipControl->ResetState();
       
  3777                                 skipControl->DrawNow();
       
  3778 
       
  3779                                 skipControl = (CAknButton*)(toolbar->ComponentControl( 2 ));
       
  3780                                 skipControl->ResetState();
       
  3781                                 skipControl->DrawNow();
       
  3782                                 }
       
  3783                             }
       
  3784                         iSkipBtnPressed = EFalse;
       
  3785                         }
       
  3786                     }
       
  3787                 }
       
  3788             else if (event == TMPXCollectionMessage::EPathChanged &&
       
  3789                      op == EMcPathChangedByOpen &&
       
  3790                      data == EMcItemOpened)
       
  3791                 { // Open new entries
       
  3792                 MPX_DEBUG1("CMPXPlaybackViewImp::HandleCollectionMessage() New Item Opened");
       
  3793                 iNewItemOpened = ETrue;
       
  3794                 delete iMedia;
       
  3795                 iMedia = NULL;
       
  3796                 }
       
  3797             }
       
  3798         }
       
  3799     }
       
  3800 
       
  3801 // -----------------------------------------------------------------------------
       
  3802 // CMPXCommonPlaybackViewImp::FillAiwParameters
       
  3803 // -----------------------------------------------------------------------------
       
  3804 //
       
  3805 void CMPXCommonPlaybackViewImp::FillAiwParametersL(
       
  3806     CAiwGenericParamList& aParamList, TBool aSaved )
       
  3807     {
       
  3808     TFileName location(NULL);
       
  3809     if ( aSaved )
       
  3810         {
       
  3811         location = MPXTlsHelper::FilePath();
       
  3812         }
       
  3813 
       
  3814     if ( !location.Length())
       
  3815         {
       
  3816         location = iMedia->ValueText( KMPXMediaGeneralUri );
       
  3817         }
       
  3818 
       
  3819     MPX_DEBUG1( "Todd CMPXCommonPlaybackViewImp::FillAiwParametersL location=" );
       
  3820     #ifdef _DEBUG
       
  3821         RDebug::RawPrint(location);
       
  3822     #endif
       
  3823 
       
  3824     TPtrC mimeType(iMedia->ValueText( KMPXMediaGeneralMimeType ));
       
  3825     MPX_DEBUG1( "Todd CMPXCommonPlaybackViewImp::FillAiwParametersL mime=" );
       
  3826     #ifdef _DEBUG
       
  3827         RDebug::RawPrint(mimeType);
       
  3828     #endif
       
  3829     TAiwVariant varMime(mimeType);
       
  3830     if ( !mimeType.Length() && ( iMediaRecognizer ) )
       
  3831         {
       
  3832         varMime.Set(iMediaRecognizer->MimeTypeL(location));
       
  3833         }
       
  3834     TAiwGenericParam paramMime(EGenericParamMIMEType, varMime);
       
  3835     aParamList.Reset();
       
  3836     aParamList.AppendL(paramMime);
       
  3837     TAiwVariant varFile(location);
       
  3838     TAiwGenericParam paramFile(EGenericParamFile, varFile);
       
  3839     aParamList.AppendL(paramFile);
       
  3840     }
       
  3841 
       
  3842 // ---------------------------------------------------------------------------
       
  3843 // Updates the middle softkey display
       
  3844 // ---------------------------------------------------------------------------
       
  3845 //
       
  3846 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateMiddleSoftKeyDisplayL()
       
  3847     {
       
  3848     MPX_FUNC("CMPXCommonPlaybackViewImp::UpdateMiddleSoftKeyDisplayL");
       
  3849 
       
  3850     if (iContainer)
       
  3851             {
       
  3852         CEikButtonGroupContainer* cba = Cba();
       
  3853         if (cba)
       
  3854             {
       
  3855             MMPXSource* s = iPlaybackUtility->Source();
       
  3856             if ( s )
       
  3857                 {
       
  3858                 CMPXCollectionPlaylist* playlist = s->PlaylistL();
       
  3859                 if ( playlist )
       
  3860                     {
       
  3861                     if ( playlist->Count() > 0 )
       
  3862                         {
       
  3863                         TMPXPlaybackState state = iPlaybackUtility->StateL();
       
  3864 
       
  3865                         if ((state == EPbStateInitialising) ||(state == EPbStatePlaying))
       
  3866                             {
       
  3867                             iCommonUiHelper->SetMiddleSoftKeyLabelL( *cba, R_QTN_MSK_PAUSE, EAknSoftkeyForwardKeyEvent);
       
  3868                             }
       
  3869                         else
       
  3870                             {
       
  3871                             iCommonUiHelper->SetMiddleSoftKeyLabelL( *cba, R_QTN_MSK_PLAY, EAknSoftkeyForwardKeyEvent);
       
  3872                             }
       
  3873                         }
       
  3874                     delete playlist;
       
  3875                     }
       
  3876                 }
       
  3877             MPX_DEBUG1("CMPXCommonPlaybackViewImp::UpdateMiddleSoftKeyDisplayL - new label displayed");
       
  3878 
       
  3879             cba->DrawDeferred();
       
  3880             }
       
  3881         }
       
  3882     }
       
  3883 
       
  3884 // ---------------------------------------------------------------------------
       
  3885 // Updates the middle toolbar button
       
  3886 // ---------------------------------------------------------------------------
       
  3887 //
       
  3888 EXPORT_C void CMPXCommonPlaybackViewImp::UpdateToolbar()
       
  3889     {
       
  3890     MPX_FUNC("CMPXCommonPlaybackViewImp::UpdateToolbar");
       
  3891 
       
  3892     if ( AknLayoutUtils::PenEnabled() )
       
  3893         {
       
  3894         if ( Toolbar() )
       
  3895             {
       
  3896             CAknToolbar* toolbar = Toolbar();
       
  3897             toolbar->SetDimmed( EFalse );
       
  3898             CAknButton* rwControl;
       
  3899             rwControl = (CAknButton*)(toolbar->ComponentControl( 0 ));
       
  3900             CAknButton* pausePlayControl;
       
  3901             pausePlayControl = (CAknButton*)(toolbar->ComponentControl( 1 ));
       
  3902             CAknButton* fwControl;
       
  3903             fwControl = (CAknButton*)(toolbar->ComponentControl( 2 ));                                   
       
  3904             MMPXSource* s = iPlaybackUtility->Source();
       
  3905             if ( s )
       
  3906                 {
       
  3907                 CMPXCollectionPlaylist* playlist = s->PlaylistL();
       
  3908                 if ( playlist )
       
  3909                     {
       
  3910                     if ( playlist->Count() > 0 )
       
  3911                         {
       
  3912                         if( pausePlayControl )
       
  3913                         	{
       
  3914 	                        TMPXPlaybackState state = iPlaybackUtility->StateL();
       
  3915 	                        if ((state == EPbStateInitialising) || (state == EPbStatePlaying))
       
  3916 	                           {
       
  3917 	                           pausePlayControl->SetCurrentState(0, ETrue);
       
  3918 	                           }
       
  3919 	                        else
       
  3920 	                           {
       
  3921 	                           pausePlayControl->SetCurrentState(1, ETrue);
       
  3922 	                           }
       
  3923                         	}
       
  3924 
       
  3925 						if( rwControl && fwControl )
       
  3926 							{
       
  3927 							rwControl->SetDimmed( EFalse );
       
  3928 							rwControl->DrawNow();
       
  3929 							fwControl->SetDimmed( EFalse );
       
  3930 							fwControl->DrawNow();
       
  3931                     		}
       
  3932                         }
       
  3933 
       
  3934                     delete playlist;
       
  3935                     }
       
  3936                 else
       
  3937                     {
       
  3938                     if( pausePlayControl )
       
  3939                     	{
       
  3940 	                    TMPXPlaybackState state = iPlaybackUtility->StateL();
       
  3941 	                    if ( ( state == EPbStateInitialising ) ||
       
  3942 	                           ( state == EPbStatePlaying ) )
       
  3943 	                        {
       
  3944 	                        pausePlayControl->SetCurrentState( 0, ETrue );
       
  3945 	                        }
       
  3946 	                    else
       
  3947 	                        {
       
  3948 	                        pausePlayControl->SetCurrentState( 1, ETrue );
       
  3949 	                        }
       
  3950 	                    }
       
  3951                     }
       
  3952                 }
       
  3953             else
       
  3954                 {
       
  3955                 toolbar->SetDimmed( ETrue );
       
  3956                 }
       
  3957             }
       
  3958         }
       
  3959     }
       
  3960 // ----------------------------------------------------------------------------
       
  3961 // Callback function of timer to handle delayed error
       
  3962 // ----------------------------------------------------------------------------
       
  3963 //
       
  3964 TInt CMPXCommonPlaybackViewImp::HandleDelayedError( TAny* aPtr )
       
  3965     {
       
  3966     CMPXCommonPlaybackViewImp* pv = reinterpret_cast<CMPXCommonPlaybackViewImp*>( aPtr );
       
  3967     pv->iDelayedErrorTimer->Cancel();
       
  3968     
       
  3969     // compare index
       
  3970     if ( pv->iPlaybackUtility )
       
  3971     	{
       
  3972         MMPXSource* source( pv->iPlaybackUtility->Source() );
       
  3973         if ( source )
       
  3974     	    {
       
  3975             CMPXCollectionPlaylist* pl( source->PlaylistL() );
       
  3976         	if ( pl )
       
  3977                 {
       
  3978                 CleanupStack::PushL( pl );
       
  3979                 if ( pv->iErrIndex == pl->Index() )
       
  3980                 	{
       
  3981                 	pv->HandleErrorL( pv->iLastDelayedErr );
       
  3982                 	}
       
  3983                 CleanupStack::PopAndDestroy( pl );
       
  3984                 }
       
  3985             }
       
  3986     	}
       
  3987 
       
  3988     return KErrNone;
       
  3989     }
       
  3990 //  End of File