mpxmusicplayer/app/src/mpxappui.cpp
changeset 0 ff3acec5bc43
child 2 b70d77332e66
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:  Application UI class required by AVKON application architecture.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <AknGlobalNote.h>
       
    22 #include <avkon.hrh>
       
    23 #include <apgwgnam.h>
       
    24 #include <hlplch.h>
       
    25 #include <e32base.h>
       
    26 #include <e32property.h>
       
    27 #include <eikproc.h>
       
    28 #include <apacln.h>
       
    29 #include <coeutils.h>
       
    30 #include <StringLoader.h>
       
    31 #include <textresolver.h>
       
    32 #include <aknnotewrappers.h>
       
    33 #include <AknTaskList.h>
       
    34 #include <aknview.h>
       
    35 #include <featmgr.h>
       
    36 #include <centralrepository.h>
       
    37 #include <settingsinternalcrkeys.h>
       
    38 #include <ctsydomainpskeys.h>
       
    39 #include <caf/caferr.h>
       
    40 #include <eikapp.h>
       
    41 #include <pathinfo.h>
       
    42 #include <sysutil.h>
       
    43 #include <apgcli.h>
       
    44 #include <AknDlgShut.h>
       
    45 #include <aknconsts.h>
       
    46 #include <activeidle2domainpskeys.h>
       
    47 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
    48 #include <AiwGenericParam.h>
       
    49 #endif
       
    50 
       
    51 #include <mpxplaybackutility.h>
       
    52 #include <mpxcollectionutility.h>
       
    53 #include <mpxplaybackmessage.h>
       
    54 #include <mpxviewutility.h>
       
    55 #include <mpxmusicplayerviewplugin.hrh>
       
    56 #include <mpx.rsg>
       
    57 #include <mpxcollectionmessage.h>
       
    58 #include <mpxcollectionplaylist.h>
       
    59 #include <mpxcollectionpath.h>
       
    60 #include <mpxcollectionplugin.hrh>
       
    61 #include <mpxmedia.h>
       
    62 #include <mpxmediageneraldefs.h>
       
    63 #include <mpxmediadrmdefs.h>
       
    64 #include <mpxcollectionuihelper.h>
       
    65 #include <mpxcollectionhelperfactory.h>
       
    66 #include <mpxmediaarray.h>
       
    67 #include <mpxmediacontainerdefs.h>
       
    68 #include <mpxmediakeyhandler.h>
       
    69 #include <mpxharvesterutility.h>
       
    70 #include <mpxdrmmediautility.h>
       
    71 #include <mpxcollectionmessagedefs.h>
       
    72 #include <mpxmessagegeneraldefs.h>
       
    73 #include <mpxcollectionplugin.hrh>
       
    74 #include <mpxcommandgeneraldefs.h>
       
    75 #include <mpxcollectioncommanddefs.h>
       
    76 
       
    77 // Cover UI start
       
    78 //#ifdef __COVER_DISPLAY
       
    79 #include <aknSDData.h>
       
    80 #include <AknMediatorFacade.h>
       
    81 #include <MediatorCommandInitiator.h>
       
    82 #include <MediatorDomainUIDs.h>
       
    83 #include "mplayersecondarydisplayapi.h"
       
    84 #include <featmgr.h>
       
    85 //#endif
       
    86 // Cover UI end
       
    87 
       
    88 #ifdef __CAMESE_SUPERDISTRIBUTION_SUPPORT 
       
    89 #include "camesedrmhandler.h"
       
    90 #endif 
       
    91 
       
    92 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
    93 #include <DocumentHandler.h>
       
    94 #include <apmstd.h>
       
    95 #endif //RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
    96 
       
    97 #include "mpxinternalcrkeys.h"
       
    98 #include "mpxcommandhandler.h"
       
    99 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   100 #include <AiwGenericParam.h>
       
   101 #include "mpxPDcommandhandler.h"
       
   102 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   103 #include "mpxcommonuihelper.h"
       
   104 #include <mpxcommonui.rsg> //for R_MPX_FILE_NOT_FOUND_TEXT
       
   105 #include "mpxappui.h"
       
   106 #include "mpxcontroller.h"
       
   107 #include "mpxrestorepath.h"
       
   108 #include "mpxdocument.h"
       
   109 #include "mpxtlshelper.h"
       
   110 #include "mpxlog.h"
       
   111 #include "mpxappui.hrh"
       
   112 #include <mpxconstants.h>
       
   113 #include <mpxviewpluginmanager.h>
       
   114 #include <mpxviewplugin.h>
       
   115 
       
   116 #include <iaupdate.h>
       
   117 #include <iaupdateparameters.h>
       
   118 #include <iaupdateresult.h>
       
   119 
       
   120 // CONSTANTS
       
   121 _LIT( KMPXLineChange, "\n" );
       
   122 _LIT(KMPXMusicplayerPrivateFolder, "\\private\\");
       
   123 _LIT(KMPXMusicPlayerExec, "mpx.exe" );
       
   124 
       
   125 const TInt KMPXMusicPlayerAlreadySaved( -5000 );
       
   126 
       
   127 // Application Uid for Active Idle app
       
   128 #ifdef __ACTIVE_IDLE
       
   129 const TUid KMPXUidIdleApp = { 0x101FD64C };
       
   130 #else
       
   131 const TUid KMPXUidIdleApp = KPSUidActiveIdle2; // use this one instead because the "aisystemuids.hrh" is not export
       
   132 #endif
       
   133 
       
   134 // MusicPlayer SIS Package UID
       
   135 #define KMPXMusicPlayerSISPkgUid  0x101FFC62 
       
   136 
       
   137 _LIT8( KMmMessage, "mm://musicsuite?action=exit" );
       
   138 const TInt KMmUid3( 0x101f4cd2 );
       
   139 
       
   140 // Granularity for ring tone mime types array
       
   141 const TInt KMPXRingToneMimeTypesGranularity( 10 );
       
   142 
       
   143 const TInt KMPXMinVolume( 0 );
       
   144 const TInt KMPXMaxVolume(100);
       
   145 
       
   146 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   147 _LIT8(KDataTypeRAM,"audio/x-pn-realaudio-plugin");
       
   148 #endif //RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   149 
       
   150 const TInt KMaxIntLen( 10 );
       
   151 _LIT8( KMVPrefix, "MVviewID:" );
       
   152 const TInt KMVPrefixLen( 9 );
       
   153 
       
   154 const TUid  KLocalPlaybackUid = { 0x101FFC06 };
       
   155 const TUid  KPhoneAppUid      = {0x100058B3};
       
   156 const TInt  KWaitNoteImpUid   = 0x101FFC6C; // refresh wait note UID
       
   157 const TInt KLowestMemoryNeeded = 5242880; //5 Mbytes
       
   158 
       
   159 const TUid KCRUidMPXMPSettings = {0x101FFCDC};
       
   160 const TUint32 KMPXMPPlaybackRandomMode = 0x0B;
       
   161 const TUint32 KMPXMPPlaybackRepeatMode = 0x0C;
       
   162 
       
   163 // ======== MEMBER FUNCTIONS ========
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // C++ default constructor.
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 CMPXAppUi::CMPXAppUi()
       
   170     : iRingToneMimeTypes( KMPXRingToneMimeTypesGranularity ),
       
   171       iCurrentIndex( KErrNotFound ), iSaveMode( EMPXSaveModeIdle ),
       
   172       iStandAlone(EFalse),
       
   173       iMaxVolume(KMPXMaxVolume)
       
   174 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   175       ,iAppStartedByBrowser(EFalse)
       
   176       ,iPdPbvStartedByBrowser(EFalse)
       
   177       ,icollectionBrowsed(EFalse)
       
   178 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   179 #ifdef FF_OOM_MONITOR2_COMPONENT   //__ENABLE_MPX_BUSYSETTING_FOR_OOM2
       
   180       ,iOomPriority( ROomMonitorSession::EOomPriorityNormal )
       
   181 #endif //FF_OOM_MONITOR2_COMPONENT
       
   182     {
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Symbian 2nd phase constructor can leave.
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CMPXAppUi::ConstructL()
       
   191     {
       
   192     MPX_FUNC( "CMPXAppUi::ConstructL" );
       
   193 #ifndef __ENABLE_MSK
       
   194     BaseConstructL( EAknEnableSkin 
       
   195 #ifdef SINGLE_CLICK_INCLUDED
       
   196     | EAknSingleClickCompatible
       
   197 #endif
       
   198 	);
       
   199 #else
       
   200     BaseConstructL( EAknEnableSkin | EAknEnableMSK 
       
   201 #ifdef SINGLE_CLICK_INCLUDED
       
   202     | EAknSingleClickCompatible
       
   203 #endif
       
   204 	);
       
   205 #endif // __ENABLE_MSK
       
   206 
       
   207     iCommonUiHelper = CMPXCommonUiHelper::NewL();
       
   208 
       
   209 // Cover UI start
       
   210 //#ifdef __COVER_DISPLAY
       
   211 // initialize FeatureManager
       
   212     FeatureManager::InitializeLibL();
       
   213 
       
   214     // Check updates from IAD, continue UI launching even if something fails there
       
   215     TRAP_IGNORE( CheckUpdatesL() );
       
   216 
       
   217     if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
       
   218         {
       
   219         iCoverDisplay = ETrue;
       
   220         iCommandInitiator = CMediatorCommandInitiator::NewL( NULL );
       
   221         }
       
   222     else
       
   223         {
       
   224         iCoverDisplay = EFalse;
       
   225         }
       
   226 //#endif // __COVER_DISPLAY
       
   227 // Cover UI end
       
   228 
       
   229     if ( MPXUser::IsCallOngoing( EPSCTsyCallTypeH324Multimedia ) )
       
   230         {
       
   231         HBufC* text =
       
   232             StringLoader::LoadLC( R_MPX_VIDEO_CALL_ONGOING );
       
   233         CAknGlobalNote* globalInfoNote = CAknGlobalNote::NewLC();
       
   234 
       
   235 // Cover UI start
       
   236 //#ifdef __COVER_DISPLAY
       
   237     if ( iCoverDisplay )
       
   238         {
       
   239         CAknSDData* sddata = CAknSDData::NewL(
       
   240             KMPlayerNoteCategory,
       
   241             EMPlayerNoteVideoCall,
       
   242             KNullDesC8);
       
   243         globalInfoNote->SetSecondaryDisplayData(sddata); // ownership transferred
       
   244         }
       
   245 //#endif //__COVER_DISPLAY
       
   246 // Cover UI end
       
   247 
       
   248         globalInfoNote->ShowNoteL(
       
   249             EAknGlobalInformationNote,
       
   250             text->Des() );
       
   251         CleanupStack::PopAndDestroy( globalInfoNote );
       
   252         CleanupStack::PopAndDestroy( text );
       
   253         Exit();
       
   254         return;
       
   255         }
       
   256 
       
   257     //check memory
       
   258 #ifdef FF_OOM_MONITOR2_COMPONENT
       
   259     CheckAvailableMemoryByOomL( KLowestMemoryNeeded );
       
   260 #else
       
   261     CheckAvailableMemory( KLowestMemoryNeeded );
       
   262 #endif    //FF_OOM_MONITOR2_COMPONENT
       
   263 
       
   264     if ( !IsEmbedded() )
       
   265         {
       
   266         // Do we support podcasting in music player?
       
   267         // Event if repository get fails, it will default to EFalse
       
   268         //
       
   269         TInt val(0);
       
   270         CRepository* repository = CRepository::NewL( KCRUidMPXMPFeatures );
       
   271         repository->Get( KMPXMPLocalVariation, val );
       
   272         iDisablePodcasting = val&KMPXDisablePodcastingOption ? ETrue : EFalse;
       
   273         iStartInAlbumMenu = val&KMPXStartMusicPlayerinArtistsandAlbums ? ETrue : EFalse;
       
   274         delete repository;
       
   275         CreateMemberVariablesL();
       
   276 
       
   277         TUid defaultView( iViewUtility->DefaultViewUid() );
       
   278 
       
   279         // Pre-load views in standalone mode
       
   280         iViewUtility->PreLoadViewsL( TUid::Uid( KMusicPlayerAppUidConstant ) );
       
   281 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
   282         iCollectionUtility->Collection().OpenL(
       
   283             TUid::Uid(EMPXCollectionPluginMusic));
       
   284 #endif
       
   285 
       
   286 		if ( iStartInAlbumMenu )
       
   287 			{
       
   288 
       
   289 			// We want to open the music player to the albums level for 9.2
       
   290 			// Changes in other areas will also be needed.
       
   291 
       
   292 			CMPXCollectionPath* path = iCollectionUiHelper->MusicMenuPathL();
       
   293 			CleanupStack::PushL( path );
       
   294 			path->AppendL(3); // Albums
       
   295 			MPX_DEBUG_PATH(*path);
       
   296 			iCollectionUtility->Collection().OpenL( *path );
       
   297 			CleanupStack::PopAndDestroy( path );
       
   298 			}
       
   299 		else
       
   300 			{
       
   301 			CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
   302 			CleanupStack::PushL( path );
       
   303 			MPX_DEBUG1("CMPXAppUi::ConstructL() current collection path");
       
   304 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
   305         MPX_DEBUG1("CMPXAppUi::ConstructL() restoring stale path");
       
   306         CMPXCollectionPath* mainMusicMenu = CMPXCollectionPath::NewL();
       
   307         CleanupStack::PushL( mainMusicMenu );
       
   308         mainMusicMenu->AppendL(0x101FFC3A);
       
   309         iCollectionUtility->Collection().OpenL( *mainMusicMenu );
       
   310         CleanupStack::PopAndDestroy( mainMusicMenu );
       
   311         CleanupStack::PopAndDestroy( path );
       
   312 #else
       
   313         MPX_DEBUG1( "CMPXAppUi::ConstructL wrong path" );
       
   314         if( path->Levels() > 1 )
       
   315             {
       
   316             // Correct the path by opening 0 levels
       
   317             MPX_DEBUG1("CMPXAppUi::ConstructL() restoring stale path");
       
   318             CMPXCollectionPath* root = CMPXCollectionPath::NewL();
       
   319             CleanupStack::PushL( root );
       
   320             iCollectionUtility->Collection().OpenL( *root );
       
   321             CleanupStack::PopAndDestroy( root );
       
   322             }
       
   323         CleanupStack::PopAndDestroy( path );
       
   324 #endif
       
   325 			}
       
   326 
       
   327 
       
   328         if ( defaultView != KNullUid )
       
   329             {
       
   330             iViewUtility->SetAsDefaultViewL( defaultView );
       
   331             }
       
   332         else
       
   333             {
       
   334             iViewUtility->SetAsDefaultViewL(
       
   335                 TUid::Uid( KMPXPluginTypeMainUid ) );
       
   336             }
       
   337 
       
   338 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
   339         // Startup database checker
       
   340         iController = CMPXController::NewL(iDisablePodcasting);
       
   341 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
   342 
       
   343         // Only in stand alone mode
       
   344         iHarvesterUtility = CMPXHarvesterFactory::NewL();
       
   345         iHarvesterUtility->CheckForSystemEventsL();
       
   346 
       
   347 #ifdef _DEBUG
       
   348         TBool iExitOptionHidden = EFalse;
       
   349 #else // _DEBUG
       
   350         TBool iExitOptionHidden = iCommonUiHelper->ExitOptionHiddenL();
       
   351 #endif // _DEBUG
       
   352         if(iExitOptionHidden)
       
   353             {
       
   354             // Do not offer choice to exit application from task swapper.
       
   355             CEikonEnv::Static()->SetSystem( ETrue );
       
   356             }
       
   357 
       
   358         RProcess proc;
       
   359         CleanupClosePushL( proc );
       
   360         CMPXCommonUiHelper::SetStandAloneModePId( proc.Id().Id() );
       
   361         CleanupStack::PopAndDestroy( &proc );
       
   362         }
       
   363 
       
   364     iRingToneMimeTypes.AppendL(_L("application/vnd.nokia.ringing-tone"));
       
   365     iRingToneMimeTypes.AppendL(_L("audio/x-midi"));
       
   366     iRingToneMimeTypes.AppendL(_L("audio/midi"));
       
   367     iRingToneMimeTypes.AppendL(_L("audio/sp-midi"));
       
   368     iRingToneMimeTypes.AppendL(_L("audio/amr"));
       
   369     iRingToneMimeTypes.AppendL(_L("audio/amr-wb"));
       
   370     iRingToneMimeTypes.AppendL(_L("audio/awb"));
       
   371     iRingToneMimeTypes.AppendL(_L("audio/x-amr"));
       
   372     iRingToneMimeTypes.AppendL(_L("audio/audio/vnd.nokia.mobile-xmf"));
       
   373     iLaunchModePlaying = EFalse;
       
   374     }
       
   375 
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // Destructor
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 CMPXAppUi::~CMPXAppUi()
       
   382     {
       
   383     MPX_DEBUG1( "-->CMPXAppUi::~CMPXAppUi()" );
       
   384 #ifdef FF_OOM_MONITOR2_COMPONENT
       
   385     SetMpxOomPriorityL( ROomMonitorSession::EOomPriorityNormal );
       
   386 #endif //FF_OOM_MONITOR2_COMPONENT
       
   387 
       
   388     if ( !IsEmbedded() )
       
   389         {
       
   390         CMPXCommonUiHelper::SetStandAloneModePId( 0 );
       
   391         }
       
   392 
       
   393 // Cover UI Start
       
   394 // #ifdef __COVER_DISPLAY
       
   395 
       
   396     FeatureManager::UnInitializeLib();
       
   397     delete iCommandInitiator;
       
   398 
       
   399 // #endif // __COVER_DISPLAY
       
   400 // Cover UI End
       
   401     delete iPathRestore;
       
   402     delete iController;
       
   403     delete iProcessParameter;
       
   404 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   405     delete iPdParameterHandler;
       
   406 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   407     delete iIdle;
       
   408 
       
   409     if ( iCollectionUtility )
       
   410         {
       
   411         iCollectionUtility->Close();
       
   412         }
       
   413 
       
   414     if ( iPlaybackUtility )
       
   415         {
       
   416         TRAP_IGNORE( iPlaybackUtility->CommandL( EPbCmdClose ) );
       
   417         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
       
   418         iPlaybackUtility->Close();
       
   419         }
       
   420 
       
   421     if ( iViewUtility )
       
   422         {
       
   423         iViewUtility->RemoveObserver( this );
       
   424         iViewUtility->Close();
       
   425         }
       
   426     delete iCommonUiHelper;
       
   427 
       
   428     if( iCollectionUiHelper )
       
   429         {
       
   430         iCollectionUiHelper->Close();
       
   431         }
       
   432 
       
   433     if ( iCollectionHelper )
       
   434         {
       
   435         iCollectionHelper->Close();
       
   436         }
       
   437     if( iHarvesterUtility )
       
   438         {
       
   439         iHarvesterUtility->Close();
       
   440         }
       
   441 
       
   442     delete iMediaKeyHandler;
       
   443     delete iSettingsRepository;
       
   444     iFile.Close();
       
   445     iDeferredViewActivationUid.Close();
       
   446     delete iSavePath;
       
   447     iRingToneMimeTypes.Reset();
       
   448 
       
   449     delete iSaveHelper;
       
   450 #ifdef __CAMESE_SUPERDISTRIBUTION_SUPPORT 
       
   451     delete iCameseDrmHandler;
       
   452 #endif 
       
   453 
       
   454 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   455     delete iDocHandler;
       
   456 #endif //RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   457 
       
   458     CleanUpdateParams();
       
   459 
       
   460     MPX_DEBUG1( "<--CMPXAppUi::~CMPXAppUi()" );
       
   461     }
       
   462 
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // Querying whether the application is launched in embedded mode or not.
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 TBool CMPXAppUi::IsEmbedded() const
       
   469     {
       
   470     return iEikonEnv->StartedAsServerApp();
       
   471     }
       
   472 
       
   473 
       
   474 // ---------------------------------------------------------------------------
       
   475 // Opens temporary playlist or album from buffer.
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 void CMPXAppUi::OpenPlaylistFromBufferL(
       
   479     const TDesC& aBuffer,
       
   480     TDesC& aName )
       
   481     {
       
   482     MPX_FUNC( "CMPXAppUi::OpenPlaylistFromBufferL" );
       
   483     TPtrC bufPtr( aBuffer );
       
   484     TInt offset = 0;
       
   485     CMPXMediaArray* tracksArray = CMPXMediaArray::NewL();
       
   486     CleanupStack::PushL( tracksArray );
       
   487 
       
   488     while ( bufPtr.Length() > 0 )
       
   489         {
       
   490         offset = bufPtr.Find( KMPXLineChange );
       
   491         CMPXMedia* track = CMPXMedia::NewL();
       
   492         CleanupStack::PushL( track );
       
   493         track->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem);
       
   494         track->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong );
       
   495         if ( offset == KErrNotFound )
       
   496             {
       
   497             TParsePtrC fn( bufPtr );
       
   498             track->SetTextValueL( KMPXMediaGeneralTitle, fn.Name() );
       
   499             track->SetTextValueL( KMPXMediaGeneralUri, bufPtr );
       
   500             // Set bufPtr to the end of buffer
       
   501             bufPtr.Set( bufPtr.Right( 0 ) ); //magic
       
   502             }
       
   503         else
       
   504             {
       
   505             TParsePtrC fn( bufPtr.Left( offset ) );
       
   506             track->SetTextValueL( KMPXMediaGeneralTitle, fn.Name() );
       
   507             track->SetTextValueL( KMPXMediaGeneralUri, fn.FullName() );
       
   508             // Move past the line feed
       
   509             bufPtr.Set( bufPtr.Mid( ++offset ) );
       
   510             }
       
   511         tracksArray->AppendL( track );
       
   512         CleanupStack::Pop( track );
       
   513         }
       
   514 
       
   515     CMPXMedia* media = CMPXMedia::NewL();
       
   516     CleanupStack::PushL( media );
       
   517     media->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem);
       
   518     media->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXPlaylist );
       
   519     if ( aName.Length() > 0 )
       
   520         {
       
   521         media->SetTObjectValueL( KMPXMediaGeneralTitle, aName );
       
   522         }
       
   523     media->SetCObjectValueL( KMPXMediaArrayContents, tracksArray );
       
   524     media->SetTObjectValueL( KMPXMediaArrayCount, tracksArray->Count() );
       
   525     iCollectionUiHelper->OpenL( MPXTlsHelper::HostUid(), *media,
       
   526                                 this, EMPXCollectionPluginMusic );
       
   527     CleanupStack::PopAndDestroy( media );
       
   528     CleanupStack::PopAndDestroy( tracksArray );
       
   529     }
       
   530 
       
   531 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   532 // -----------------------------------------------------------------------------
       
   533 // CMPXAppUi::ForwardAiwParametersToMediaPlayer
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 CAiwGenericParamList* CMPXAppUi::CreateForwardAiwParametersLC(
       
   537         const CAiwGenericParamList* aParamList) const
       
   538     {
       
   539     MPX_FUNC( "CMPXAppUi::ForwardAiwParametersToMediaPlayerL" );
       
   540 
       
   541     //Read parameters that were appended to the parameter list
       
   542 
       
   543     //Creates a new parameter list which will be forwarded to Media Player
       
   544     CAiwGenericParamList* newParamList = CAiwGenericParamList::NewLC();
       
   545 
       
   546     if (aParamList)
       
   547         {
       
   548         TInt index = 0;
       
   549 
       
   550         //param contains the specific parameter being looked for in the parameter list
       
   551         //if found, append it again so it can be passed to Media Player
       
   552 
       
   553         //Move parameter
       
   554         const TAiwGenericParam* param = aParamList->FindFirst(index,
       
   555                                             EGenericParamAllowMove);
       
   556         if (param)
       
   557             {
       
   558             TBool allowMove(ETrue);
       
   559             TAiwVariant allowMoveVariant(allowMove);
       
   560             TAiwGenericParam genericParamAllowMove(EGenericParamAllowMove,
       
   561                                                    allowMoveVariant);
       
   562             newParamList->AppendL(genericParamAllowMove);
       
   563             }
       
   564 
       
   565         index = 0;
       
   566         param = NULL;
       
   567         //Save parameter
       
   568         param = aParamList->FindFirst(index, EGenericParamAllowSave);
       
   569         if (param)
       
   570             {
       
   571             TBool allowSave(ETrue);
       
   572             TAiwVariant allowSaveVariant(allowSave);
       
   573             TAiwGenericParam genericParamAllowSave(EGenericParamAllowSave,
       
   574                                                    allowSaveVariant);
       
   575             newParamList->AppendL(genericParamAllowSave);
       
   576             }
       
   577 
       
   578         index = 0;
       
   579         param = NULL;
       
   580         //Resolution parameter
       
   581         param = aParamList->FindFirst(index, EGenericParamResolution);
       
   582         if (param)
       
   583             {
       
   584             //For future use
       
   585             }
       
   586 
       
   587         index = 0;
       
   588         param = NULL;
       
   589         //File parameter
       
   590         param = aParamList->FindFirst(index, EGenericParamFile);
       
   591         if (param)
       
   592             {
       
   593             TDataType dataType( _L8("audio/x-pn-realaudio") );
       
   594             TAiwVariant filename( _L8("c:\\system\\temp\\RtspTemp.ram") );
       
   595             TAiwGenericParam param( EGenericParamFile, filename );
       
   596             newParamList->AppendL( param );
       
   597             }
       
   598 
       
   599         index = 0;
       
   600         param = NULL;
       
   601         //Access Point parameter
       
   602         param = aParamList->FindFirst(index, EGenericParamAccessPoint);
       
   603         if (param)
       
   604             {
       
   605             TInt32 value = 0;
       
   606             TInt32 ret = param->Value().Get(value);
       
   607             if (ret)
       
   608                 {
       
   609                 TAiwVariant accessPointVariant(value);
       
   610                 TAiwGenericParam genericParamAccessPoint(EGenericParamAccessPoint,
       
   611                                                          accessPointVariant);
       
   612                 newParamList->AppendL(genericParamAccessPoint);
       
   613                 }
       
   614             }
       
   615         }
       
   616     return newParamList;
       
   617     }
       
   618 #endif
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 // Opens the specified file in response to a corresponding message.
       
   622 // ---------------------------------------------------------------------------
       
   623 //
       
   624 void CMPXAppUi::OpenFileL(
       
   625     CFileStore*& /* aFileStore */,
       
   626     RFile& aFile,
       
   627     const CAiwGenericParamList* aParams )
       
   628     {
       
   629     MPX_FUNC( "CMPXAppUi::OpenFileL" );
       
   630 
       
   631     // Duplicate the file handle passed in before
       
   632     // creating the member variables.
       
   633     TFileName filename;
       
   634     aFile.FullName( filename );
       
   635     iFile.Close();
       
   636     iFile.Duplicate( aFile );
       
   637     aFile.Close();
       
   638 
       
   639     if ( IsEmbedded() )
       
   640         {
       
   641         CreateMemberVariablesL();
       
   642         iViewUtility->PreLoadViewL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ));
       
   643         }
       
   644 
       
   645 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   646     // Get MIME type
       
   647     RApaLsSession apa;
       
   648     User::LeaveIfError( apa.Connect() );
       
   649     CleanupClosePushL( apa );
       
   650     TDataRecognitionResult result;
       
   651     User::LeaveIfError( apa.RecognizeData( iFile, result ));
       
   652     CleanupStack::PopAndDestroy( &apa );
       
   653 
       
   654     TDataType dataType = TDataType( KDataTypeRAM() );
       
   655 
       
   656     if ( result.iDataType == dataType )
       
   657         {
       
   658         CAiwGenericParamList* paramList = CreateForwardAiwParametersLC(aParams);
       
   659         iDocHandler->OpenFileEmbeddedL(iFile, dataType, *paramList);
       
   660         CleanupStack::PopAndDestroy(paramList);
       
   661         iDocHandler->SetExitObserver(this);
       
   662         }
       
   663     else
       
   664 #endif //RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
   665         {
       
   666         // Open File with Collection Helper
       
   667         iCollectionUiHelper->OpenL( MPXTlsHelper::HostUid(), filename,
       
   668                                     this, EMPXCollectionPluginMusic );
       
   669         }
       
   670     }
       
   671 
       
   672 
       
   673 // ---------------------------------------------------------------------------
       
   674 // CMPXAppUi::ActivatePhoneAppL
       
   675 // ---------------------------------------------------------------------------
       
   676 //
       
   677 void CMPXAppUi::ActivatePhoneAppL()
       
   678     {
       
   679     MPX_FUNC( "CMPXAppUi::ActivatePhoneAppL" );
       
   680     TApaTaskList apaTaskList( CCoeEnv::Static()->WsSession() );
       
   681     TApaTask apaTask = apaTaskList.FindApp( KPhoneAppUid );
       
   682     if ( apaTask.Exists() )
       
   683         {
       
   684         // Bring phone to foreground
       
   685         apaTask.BringToForeground();
       
   686         }
       
   687 
       
   688     // Move Music Player to background
       
   689     // magic: -1 = force wg to background
       
   690     }
       
   691 
       
   692 // ----------------------------------------------------------------------------
       
   693 // void CMPXAppUi::DeferredExitCallback
       
   694 // call back function for deferred exit.
       
   695 // ----------------------------------------------------------------------------
       
   696 //
       
   697 TInt CMPXAppUi::DeferredExitCallback( TAny* aPtr )
       
   698     {
       
   699     MPX_FUNC( "CMPXAppUi::DeferredExitCallback" );
       
   700     CMPXAppUi* self = static_cast<CMPXAppUi*>( aPtr );
       
   701     TRAP_IGNORE( self->HandleCommandL( EEikCmdExit ) );
       
   702     return KErrNone;
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // Start a waitnote dialog
       
   707 // ---------------------------------------------------------------------------
       
   708 //
       
   709 void CMPXAppUi::StartWaitNoteL( TWaitNoteType aNoteType )
       
   710     {
       
   711     CloseWaitNoteL();
       
   712     TUid waitnoteId = TUid::Uid( KMPXPluginTypeWaitNoteDialogUid );
       
   713     TPckg<TWaitNoteType> note = aNoteType;
       
   714     HBufC* arg = MPXUser::AllocL( note );
       
   715     CleanupStack::PushL( arg );
       
   716     iViewUtility->ActivateViewL( waitnoteId, arg );
       
   717     CleanupStack::PopAndDestroy( arg );
       
   718     }
       
   719 
       
   720 // ---------------------------------------------------------------------------
       
   721 // Close the waitnote dialog
       
   722 // ---------------------------------------------------------------------------
       
   723 //
       
   724 void CMPXAppUi::CloseWaitNoteL()
       
   725     {
       
   726     TUid waitnoteId = TUid::Uid( KMPXPluginTypeWaitNoteDialogUid );
       
   727     TUid activeView = iViewUtility->ActiveViewType();
       
   728     if( activeView == waitnoteId )
       
   729         {
       
   730         CMPXViewPlugin* pi =
       
   731             iViewUtility->ViewPluginManager().PluginL( TUid::Uid(KWaitNoteImpUid) );
       
   732         pi->DeactivateView();
       
   733         }
       
   734     }
       
   735 
       
   736 // ---------------------------------------------------------------------------
       
   737 // From MMPXMediaKeyHandlerObserver.
       
   738 // Handle media key commands.
       
   739 // ---------------------------------------------------------------------------
       
   740 //
       
   741 void CMPXAppUi::HandleMediaKeyCommand(
       
   742     const TMPXPlaybackCommand aCommand,
       
   743     const TInt aData )
       
   744     {
       
   745     MPX_FUNC( "CMPXAppUi::HandleMediaKeyCommand" );
       
   746 
       
   747     switch ( aCommand )
       
   748         {
       
   749         case EPbCmdSetVolume:
       
   750             {
       
   751             TMPXPlaybackState playerState( EPbStateNotInitialised );
       
   752             playerState = iPlaybackUtility->StateL();
       
   753             if ( !MPXUser::IsCallOngoing( KMPXCallTypeGenericVoice ) ||
       
   754                 ( playerState == EPbStatePlaying ) ||
       
   755                 ( playerState == EPbStateSeekingForward ) ||
       
   756                 ( playerState == EPbStateSeekingBackward ) ||
       
   757                 iPdParameterHandler )
       
   758                 {
       
   759                 TMPXPlaybackState pdPlayerState( EPbStateNotInitialised );
       
   760                 if ( iPdParameterHandler )
       
   761                     {
       
   762                     pdPlayerState = iPdParameterHandler->PdStateL();
       
   763                     }
       
   764                 
       
   765                 // only process command if there no call ongoing
       
   766                 // or if we're actively playing during call
       
   767                 if ( IsForeground() || EPbStatePlaying == playerState || EPbStatePlaying == pdPlayerState )
       
   768                     {
       
   769 					if ( aData != iCurrentVolume )
       
   770                         {
       
   771                         SetVolume( aData );
       
   772                         }
       
   773                     // popup volume control even if volume didn't change
       
   774                     HandlePopupL( EPbCmdSetVolume );
       
   775                     }
       
   776                 }
       
   777             break;
       
   778             }
       
   779         case EPbCmdMuteVolume:
       
   780             {
       
   781             TMPXPlaybackState playerState( EPbStateNotInitialised );
       
   782             playerState = iPlaybackUtility->StateL();
       
   783             if ( !MPXUser::IsCallOngoing( KMPXCallTypeGenericVoice ) ||
       
   784                 ( playerState == EPbStatePlaying ) ||
       
   785                 ( playerState == EPbStateSeekingForward ) ||
       
   786                 ( playerState == EPbStateSeekingBackward ) )
       
   787                 {
       
   788                 // only process command if there no call ongoing
       
   789                 // or if we're actively playing during call
       
   790                 if ( IsForeground() || EPbStatePlaying == playerState )
       
   791                     {
       
   792                     MuteVolume();
       
   793                     HandlePopupL( EPbCmdMuteVolume );
       
   794                     }
       
   795                 }
       
   796             break;
       
   797             }
       
   798         case EPbCmdUnMuteVolume:
       
   799             {
       
   800             TMPXPlaybackState playerState( EPbStateNotInitialised );
       
   801             playerState = iPlaybackUtility->StateL();
       
   802             if ( !MPXUser::IsCallOngoing( KMPXCallTypeGenericVoice ) ||
       
   803                 ( playerState == EPbStatePlaying ) ||
       
   804                 ( playerState == EPbStateSeekingForward ) ||
       
   805                 ( playerState == EPbStateSeekingBackward ) )
       
   806                 {
       
   807                 // only process command if there no call ongoing
       
   808                 // or if we're actively playing during call
       
   809                 if ( IsForeground() || EPbStatePlaying == playerState )
       
   810                     {
       
   811                     UnMuteVolume();
       
   812                     HandlePopupL( EPbCmdUnMuteVolume );
       
   813                     }
       
   814                 }
       
   815             break;
       
   816             }
       
   817         default:
       
   818             {
       
   819             // Dispatches all other commands
       
   820 
       
   821             TBool foregroundApp( IsForeground() );
       
   822             if ( !IsDisplayingMenuOrDialog() && foregroundApp )
       
   823                 {
       
   824                 // Forward the command to view to handle when
       
   825                 // music is foreground app and not displaying
       
   826                 // dialogs or the options menu
       
   827                 if ( iView )
       
   828                     {
       
   829                     MPX_DEBUG2( "CMPXAppUi::HandleMediaKeyCommand sending command %d to view", MPXCmdForPbCmd(aCommand) );
       
   830                     iView->HandleCommandL( MPXCmdForPbCmd(aCommand) );
       
   831                     }
       
   832                 }
       
   833             else
       
   834                 {
       
   835                 TMPXPlaybackState playerState( EPbStateNotInitialised );
       
   836                 playerState = iPlaybackUtility->StateL();
       
   837                 if ( foregroundApp && IsDisplayingDialog() )
       
   838                     {
       
   839                     // displaying dialog in the foreground
       
   840                     if ( EPbStatePlaying == playerState ||
       
   841                          EPbStatePaused == playerState ||
       
   842                          EPbStateSeekingForward == playerState ||
       
   843                          EPbStateSeekingBackward == playerState ||
       
   844                          aCommand == EPbCmdPlay ||
       
   845                          aCommand == EPbCmdPlayPause  )
       
   846                         {
       
   847                         // In playing/paused state, all media keys are active.
       
   848                         // Now playing view is not bring to foreground.
       
   849                         // Seeking forward/backwards is also "playing"
       
   850                         MPX_DEBUG2( "CMPXAppUi::HandleMediaKeyCommand Dialog displaying, sending command %d to DoHandleMediaKeyCommandL", aCommand );
       
   851                         DoHandleMediaKeyCommandL( aCommand );
       
   852                         }
       
   853                     else
       
   854                         {
       
   855                         MPX_DEBUG2( "CMPXAppUi::HandleMediaKeyCommand Dialog displaying, inactive state, command %d ignored", aCommand );
       
   856                         }
       
   857                     }
       
   858                 else
       
   859                     {
       
   860                     // displaying menu/not foreground, pass to view to handle only play command
       
   861                     if ( EPbStatePlaying == playerState ||
       
   862                         EPbStatePaused == playerState ||
       
   863                         EPbStateSeekingForward == playerState ||
       
   864                         EPbStateSeekingBackward == playerState )
       
   865                         {
       
   866                         MPX_DEBUG2( "CMPXAppUi::HandleMediaKeyCommand Menu displaying/not foreground, sending command %d to DoHandleMediaKeyCommandL", aCommand );
       
   867                         DoHandleMediaKeyCommandL( aCommand );
       
   868                         }
       
   869                     else if ( ( aCommand == EPbCmdPlay || aCommand == EPbCmdPlayPause ) && iView )
       
   870                         {
       
   871                         if ( !foregroundApp )
       
   872                             {
       
   873                             MPX_DEBUG2( "CMPXAppUi::HandleMediaKeyCommand Menu displaying/not foreground, active idle foreground, sending command %d to DoHandleMediaKeyCommandL", aCommand );
       
   874                             // not foreground, play without loading playback view
       
   875                             DoHandleMediaKeyCommandL( aCommand );
       
   876                             }
       
   877                         else
       
   878                             {
       
   879                             MPX_DEBUG2( "CMPXAppUi::HandleMediaKeyCommand Menu displaying/not foreground, sending command %d to view", aCommand );
       
   880                             iView->HandleCommandL( MPXCmdForPbCmd(aCommand) );
       
   881                             }
       
   882                         }
       
   883                     else if ( aCommand == EPbCmdPlay || aCommand == EPbCmdPlayPause )
       
   884                         {
       
   885                         // play command without a view, this case
       
   886                         // happens when music player is started in starter
       
   887                         // and has not been activated yet
       
   888                         // if music player gets this event, that means embedded mode
       
   889                         // is not active. safe to just use TApaTask to switch task
       
   890                         // bring music player to foreground in this case
       
   891                         TApaTaskList tasList( CEikonEnv::Static()->WsSession() );
       
   892                         TApaTask task =
       
   893                              tasList.FindApp( KAppUidMusicPlayerX );
       
   894                         if ( task.Exists() )
       
   895                             {
       
   896                             task.BringToForeground();
       
   897                             }
       
   898                         }
       
   899                     else
       
   900                         {
       
   901                         MPX_DEBUG2( "CMPXAppUi::HandleMediaKeyCommand Menu displaying/not foreground, inactive state, command %d ignored", aCommand );
       
   902                         }
       
   903                     }
       
   904                 }
       
   905             break;
       
   906             }
       
   907         }
       
   908     }
       
   909 
       
   910 // ---------------------------------------------------------------------------
       
   911 // Additional handling of media key commands.
       
   912 // Determine if the command will be passed to the playback engine.
       
   913 // ---------------------------------------------------------------------------
       
   914 //
       
   915 void CMPXAppUi::DoHandleMediaKeyCommandL(
       
   916     TMPXPlaybackCommand aCommand )
       
   917     {
       
   918     MPX_FUNC( "CMPXAppUi::DoHandleMediaKeyCommandL" );
       
   919 
       
   920     TBool handleCommand(EFalse);
       
   921     TMPXPlaybackState playerState( iPlaybackUtility->StateL() );
       
   922 
       
   923     MMPXSource* source( iPlaybackUtility->Source() );
       
   924     switch ( aCommand )
       
   925         {
       
   926         case EPbCmdPlay:
       
   927         case EPbCmdPause:
       
   928         case EPbCmdPlayPause:
       
   929             {
       
   930 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   931             if ( source || iPdParameterHandler )
       
   932 #else
       
   933             if ( source )
       
   934 #endif
       
   935                 {
       
   936                 handleCommand = ETrue;
       
   937                 }
       
   938             break;
       
   939             }
       
   940         case EPbCmdStop:
       
   941             {
       
   942             handleCommand = ETrue;
       
   943             break;
       
   944             }
       
   945         case EPbCmdNext:
       
   946             {
       
   947             // TODO: Invalid if in progressive download mode??
       
   948 
       
   949             // ignore next key in stopped mode, except when
       
   950             // the foreground is playbackview
       
   951             if (( EPbStateStopped != playerState ||
       
   952                   KMPXPluginTypePlaybackUid == iCurrentViewType.iUid ||
       
   953                   KMPXPluginTypeEmbeddedPlaybackUid == iCurrentViewType.iUid  ) &&
       
   954                 source )
       
   955                 {
       
   956                 handleCommand = ETrue;
       
   957                 }
       
   958             break;
       
   959             }
       
   960         case EPbCmdPrevious:
       
   961             {
       
   962             // TODO: Invalid if in progressive download mode??
       
   963 
       
   964             // ignore previous key in stopped mode, except when
       
   965             // the foreground is playbackview 
       
   966             if (( EPbStateStopped != playerState ||
       
   967                   KMPXPluginTypePlaybackUid == iCurrentViewType.iUid ||
       
   968                   KMPXPluginTypeEmbeddedPlaybackUid == iCurrentViewType.iUid) &&
       
   969                 source )
       
   970                 {
       
   971                 handleCommand = ETrue;
       
   972                 }
       
   973             break;
       
   974             }
       
   975         case EPbCmdStartSeekForward:
       
   976             {
       
   977             // TODO: Invalid if in progressive download mode??
       
   978             if (( EPbStatePlaying == playerState ||
       
   979                   EPbStatePaused == playerState ||
       
   980                   EPbStateSeekingBackward == playerState ) &&
       
   981                 source )
       
   982                 {
       
   983                 handleCommand = ETrue;
       
   984                 }
       
   985             break;
       
   986             }
       
   987         case EPbCmdStartSeekBackward:
       
   988             {
       
   989             // TODO: Invalid if in progressive download mode??
       
   990             if (( EPbStatePlaying == playerState ||
       
   991                   EPbStatePaused == playerState ||
       
   992                   EPbStateSeekingForward == playerState  ) &&
       
   993                 source )
       
   994                 {
       
   995                 handleCommand = ETrue;
       
   996                 }
       
   997             break;
       
   998             }
       
   999         case EPbCmdStopSeeking:
       
  1000             {
       
  1001             if (( EPbStateSeekingForward == playerState ||
       
  1002                   EPbStateSeekingBackward == playerState ) &&
       
  1003                 source )
       
  1004                 {
       
  1005                 handleCommand = ETrue;
       
  1006                 }
       
  1007             break;
       
  1008             }
       
  1009         default:
       
  1010             {
       
  1011             // Do nothing
       
  1012             break;
       
  1013             }
       
  1014         }
       
  1015 
       
  1016     if ( handleCommand )
       
  1017         {
       
  1018 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  1019 
       
  1020         if (iPdParameterHandler)
       
  1021             {
       
  1022             iPdParameterHandler->HandleCommandL( aCommand );
       
  1023             }
       
  1024         else
       
  1025             {
       
  1026             iPlaybackUtility->CommandL( aCommand );
       
  1027             }
       
  1028 #else
       
  1029         iPlaybackUtility->CommandL( aCommand );
       
  1030 #endif
       
  1031         // Control popup behaviour
       
  1032         HandlePopupL( aCommand );
       
  1033         }
       
  1034     }
       
  1035 
       
  1036 // -----------------------------------------------------------------------------
       
  1037 // Control popup behaviour.
       
  1038 // -----------------------------------------------------------------------------
       
  1039 //
       
  1040 void CMPXAppUi::HandlePopupL(
       
  1041     TMPXPlaybackCommand aCommand )
       
  1042     {
       
  1043     MPX_FUNC( "CMPXAppUi::HandlePopupL" );
       
  1044     TBool showPlaybackPopup( ETrue );
       
  1045     TBool showVolumePopup( ETrue );
       
  1046 
       
  1047     if ( IsForeground() )
       
  1048         {
       
  1049         switch ( iCurrentViewType.iUid )
       
  1050             {
       
  1051             case KMPXPluginTypePlaybackUid:
       
  1052             case KMPXPluginTypeEmbeddedPlaybackUid:
       
  1053             case KMPXPluginTypeMainUid:
       
  1054                 {
       
  1055                 // do not show playback popup in these views
       
  1056                 MPX_DEBUG2( "CMPXAppUi::HandlePopupL active view type is 0x%x, not showing popup", iCurrentViewType.iUid );
       
  1057                 showPlaybackPopup = EFalse;
       
  1058                 break;
       
  1059                 }
       
  1060             default:
       
  1061                 {
       
  1062                 MPX_DEBUG2( "CMPXAppUi::HandlePopupL active view type is 0x%x, showing popup", iCurrentViewType.iUid );
       
  1063                 break;
       
  1064                 }
       
  1065             }
       
  1066         }
       
  1067     else if ( !IsForeground() && IsActiveIdleEnabled() && IsIdleAppForeground() )
       
  1068         {
       
  1069         showPlaybackPopup = EFalse;
       
  1070         }
       
  1071 
       
  1072     if ( !IsForeground())
       
  1073         {
       
  1074         if ( IsActiveIdleEnabled() && IsIdleAppForeground() )
       
  1075             {
       
  1076             showVolumePopup = ETrue;
       
  1077             }
       
  1078         else
       
  1079             {
       
  1080             showVolumePopup = EFalse;
       
  1081             }
       
  1082         }
       
  1083 
       
  1084     switch ( aCommand )
       
  1085         {
       
  1086         case EPbCmdStop:
       
  1087             {
       
  1088             iMediaKeyHandler->DismissNotifier( EDisplayMediaPopup );
       
  1089             break;
       
  1090             }
       
  1091         case EPbCmdPrevious:
       
  1092         case EPbCmdNext:
       
  1093             {
       
  1094             if ( showPlaybackPopup )
       
  1095                 {
       
  1096                 // skip backwards should start timer right away
       
  1097                 // because it'll not receive events to trigger the timer
       
  1098                 // if skipping multiple songs, the timer will be reset
       
  1099                 // everytime it reaches a song
       
  1100 
       
  1101                 // skip fowards should also start timer right away
       
  1102                 // becuase if it's the last song, there won't be any events
       
  1103                 // to trigger the timer
       
  1104                 iMediaKeyHandler->ShowPlaybackPopupL( EMPXPopupTimeout );
       
  1105                 }
       
  1106             break;
       
  1107             }
       
  1108         case EPbCmdPlay:
       
  1109         case EPbCmdPause:
       
  1110         case EPbCmdPlayPause:
       
  1111         case EPbCmdStartSeekForward:
       
  1112         case EPbCmdStartSeekBackward:
       
  1113             {
       
  1114             if ( showPlaybackPopup )
       
  1115                 {
       
  1116                 iMediaKeyHandler->ShowPlaybackPopupL( EMPXPopupNoTimeout );
       
  1117                 }
       
  1118             break;
       
  1119             }
       
  1120         case EPbCmdStopSeeking:
       
  1121             {
       
  1122             if ( showPlaybackPopup )
       
  1123                 {
       
  1124                 iMediaKeyHandler->ShowPlaybackPopupL( EMPXPopupTimeout );
       
  1125                 }
       
  1126             break;
       
  1127             }
       
  1128         case EPbCmdSetVolume:
       
  1129         case EPbCmdMuteVolume:
       
  1130         case EPbCmdUnMuteVolume:
       
  1131             {
       
  1132             if ( showVolumePopup && iMediaKeyHandler)
       
  1133                 {
       
  1134                 // display pop up volume control
       
  1135                 iMediaKeyHandler->ShowVolumePopupL();
       
  1136                 }
       
  1137             break;
       
  1138             }
       
  1139         default:
       
  1140             {
       
  1141             // Do nothing
       
  1142             break;
       
  1143             }
       
  1144         }
       
  1145     }
       
  1146 
       
  1147 // -----------------------------------------------------------------------------
       
  1148 // Check if Active Idle app is on foreground
       
  1149 // -----------------------------------------------------------------------------
       
  1150 //
       
  1151 TBool CMPXAppUi::IsIdleAppForeground()
       
  1152     {
       
  1153     MPX_FUNC( "CMPXAppUi::IsIdleAppForeground" );
       
  1154     TBool isIdleActive( EFalse );
       
  1155     // Gets the window group id of the app in foreground
       
  1156     RWsSession& wsSession = CCoeEnv::Static()->WsSession();
       
  1157     TInt windowGroupId = wsSession.GetFocusWindowGroup();
       
  1158     if ( windowGroupId >= 0 )
       
  1159         {
       
  1160         TRAP_IGNORE(
       
  1161             {
       
  1162             CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(
       
  1163                 wsSession, windowGroupId );
       
  1164 
       
  1165             isIdleActive = ( wgName->AppUid() == KMPXUidIdleApp );
       
  1166             delete wgName;
       
  1167             } );
       
  1168         }
       
  1169 
       
  1170     return isIdleActive;
       
  1171     }
       
  1172 
       
  1173 // -----------------------------------------------------------------------------
       
  1174 // Check if Active Idle is enabled
       
  1175 // -----------------------------------------------------------------------------
       
  1176 //
       
  1177 TBool CMPXAppUi::IsActiveIdleEnabled()
       
  1178     {
       
  1179     MPX_FUNC( "CMPXAppUi::IsActiveIdleEnabled" );
       
  1180     TBool res( EFalse );
       
  1181 
       
  1182 #ifdef __ACTIVE_IDLE
       
  1183     if (! FeatureManager::FeatureSupported( KFeatureIdActiveIdle ) )
       
  1184         return EFalse;
       
  1185 #endif
       
  1186     if ( !iSettingsRepository )
       
  1187         {
       
  1188         TRAP_IGNORE(
       
  1189             {
       
  1190             iSettingsRepository = CRepository::NewL(
       
  1191                 KCRUidPersonalizationSettings );
       
  1192             } );
       
  1193         }
       
  1194 
       
  1195     if ( iSettingsRepository )
       
  1196         {
       
  1197         TInt value( 0 );
       
  1198         TInt err( iSettingsRepository->Get( KSettingsActiveIdleState, value ) );
       
  1199         if ( !err && value )
       
  1200             {
       
  1201             res = ETrue;
       
  1202             }
       
  1203         }
       
  1204     return res;
       
  1205     }
       
  1206 
       
  1207 // ---------------------------------------------------------------------------
       
  1208 // Creates and initializes all member variables
       
  1209 // ---------------------------------------------------------------------------
       
  1210 //
       
  1211 void CMPXAppUi::CreateMemberVariablesL()
       
  1212     {
       
  1213     MPX_FUNC("CMPXAppUi::CreateMemberVariablesL()");
       
  1214 
       
  1215     TUid playbackMode( KAppUidMusicPlayerX );
       
  1216     TUid collectionMode( KAppUidMusicPlayerX );
       
  1217     if ( IsEmbedded() )
       
  1218         {
       
  1219         playbackMode = KPbModeNewPlayer;
       
  1220         collectionMode = MPXTlsHelper::HostUid(); // Collection context == host UID
       
  1221         }
       
  1222 
       
  1223     if ( !iCollectionUtility )
       
  1224         {
       
  1225         iCollectionUtility = MMPXCollectionUtility::NewL( this, collectionMode );
       
  1226         }
       
  1227 
       
  1228     // Get an instance of view utility
       
  1229     if ( !iViewUtility )
       
  1230         {
       
  1231         iViewUtility = MMPXViewUtility::UtilityL();
       
  1232         iViewUtility->AddObserverL( this );
       
  1233         iViewUtility->ConstructDefaultViewHistoryL();
       
  1234         }
       
  1235 
       
  1236     if ( !iCollectionUiHelper )
       
  1237         {
       
  1238         iCollectionUiHelper = CMPXCollectionHelperFactory:: NewCollectionUiHelperL();
       
  1239         }
       
  1240 
       
  1241     // Create a new playback utility instance
       
  1242     if ( !iPlaybackUtility )
       
  1243         {
       
  1244         iPlaybackUtility = MMPXPlaybackUtility::UtilityL( playbackMode );
       
  1245         iPlaybackUtility->AddObserverL( *this );
       
  1246 
       
  1247         // get the current Volume and Max Volume
       
  1248         iPlaybackUtility->PropertyL(*this, EPbPropertyVolume);
       
  1249         iPlaybackUtility->PropertyL(*this, EPbPropertyMaxVolume);
       
  1250         if( !IsEmbedded() )
       
  1251             {
       
  1252             TInt randomMode = 0;
       
  1253             TInt repeatMode = 0;
       
  1254             
       
  1255             CRepository* repository = CRepository::NewL( KCRUidMPXMPSettings );
       
  1256             repository->Get( KMPXMPPlaybackRandomMode, randomMode );
       
  1257             repository->Get( KMPXMPPlaybackRepeatMode, repeatMode );
       
  1258             delete repository;
       
  1259             repository = NULL;
       
  1260             
       
  1261             MPX_DEBUG3("CMPXAppUi::CreateMemberVariablesL() randomMode(%d), repeatMode(%d)", randomMode, repeatMode);
       
  1262             
       
  1263             iPlaybackUtility->SetL( EPbPropertyRandomMode, randomMode );
       
  1264             iPlaybackUtility->SetL( EPbPropertyRepeatMode, repeatMode );
       
  1265             }
       
  1266         }
       
  1267 
       
  1268     if ( !iMediaKeyHandler )
       
  1269         {
       
  1270         // Handle media key in appui
       
  1271         iMediaKeyHandler = MMPXMediaKeyHandler::NewL(
       
  1272             EDisplayVolumePopup | EDisplayMediaPopup,
       
  1273             this );
       
  1274         }
       
  1275 
       
  1276     if( !IsEmbedded() )
       
  1277         {
       
  1278         iPathRestore = CMPXRestorePath::NewL( iPlaybackUtility,
       
  1279                                               iCollectionUiHelper );
       
  1280 
       
  1281         // Fetch the music collection UID
       
  1282         RArray<TUid> uid;
       
  1283         CleanupClosePushL( uid );
       
  1284         uid.AppendL( TUid::Uid(EMPXCollectionPluginMusic) );
       
  1285         iMusicCollectionId = iCollectionUtility->CollectionIDL( uid.Array() );
       
  1286 
       
  1287         // Fetch the podcast collection UID
       
  1288         if( !iDisablePodcasting )
       
  1289             {
       
  1290             uid.Reset();
       
  1291             uid.AppendL( TUid::Uid(EMPXCollectionPluginPodCast) );
       
  1292             iPodcastCollectionId = iCollectionUtility->CollectionIDL( uid.Array() );;
       
  1293             }
       
  1294 
       
  1295         CleanupStack::PopAndDestroy( &uid );
       
  1296         }
       
  1297 #ifdef __CAMESE_SUPERDISTRIBUTION_SUPPORT 
       
  1298     // In case Camese Superdistribution is enabled,
       
  1299     // we just need to initialize the Camese Drm Handler
       
  1300     // object. It will act as a collection utility
       
  1301     // observer and will handle WMDRM protected content
       
  1302     // in lieu of the AppUi.
       
  1303     if ( !iCameseDrmHandler )
       
  1304         {
       
  1305         iCameseDrmHandler = CCameseDrmHandler::NewL(iFile);
       
  1306         }
       
  1307 #endif
       
  1308 
       
  1309 #ifdef RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
  1310     if( !iDocHandler )
       
  1311         {
       
  1312         iDocHandler = CDocumentHandler::NewL(iEikonEnv->Process());
       
  1313         }
       
  1314 #endif //RD_RA_SUPPORT_FOR_MUSIC_PLAYER
       
  1315     }
       
  1316 
       
  1317 // ---------------------------------------------------------------------------
       
  1318 // Save file
       
  1319 // ---------------------------------------------------------------------------
       
  1320 //
       
  1321 void CMPXAppUi::DoSaveL()
       
  1322     {
       
  1323     MPX_DEBUG1("CMPXAppUi::DoSaveL(): entering");
       
  1324     ASSERT( iFile.SubSessionHandle() );
       
  1325 
       
  1326     // Get target path
       
  1327     TFileName newFile;
       
  1328     CreateAutomaticSavePathL( newFile );
       
  1329     delete iSavePath;
       
  1330     iSavePath = NULL;
       
  1331     iSavePath = newFile.AllocL();
       
  1332 
       
  1333     // display waiting note
       
  1334     TParsePtrC fileParse( newFile );
       
  1335     HBufC* string( StringLoader::LoadLC( R_MPX_SAVE_ONE_ITEM_WAIT_NOTE,
       
  1336                                          fileParse.Name() ));
       
  1337 // Cover UI start
       
  1338 //#ifdef __COVER_DISPLAY
       
  1339         if ( iCommandInitiator )
       
  1340         {
       
  1341         HBufC8* filename8 = HBufC8::NewLC( KMaxFileName );
       
  1342         filename8->Des().Copy( fileParse.Name() );
       
  1343         TPtrC name(KNullDesC);
       
  1344         name.Set( fileParse.Name() );
       
  1345         HBufC8* data = HBufC8::NewLC(KMaxFileName);
       
  1346 
       
  1347         TPtr8 dataPtr = data->Des();
       
  1348         RDesWriteStream str(dataPtr);
       
  1349 
       
  1350         TPtrC8 b(KNullDesC8);
       
  1351         b.Set(*filename8);
       
  1352 
       
  1353         str << b;
       
  1354         str.CommitL();
       
  1355 
       
  1356         iCommandInitiator->IssueCommand( KMediatorSecondaryDisplayDomain,
       
  1357                                         KMPlayerNoteCategory,
       
  1358                                         EMPlayerNoteSaveOneItem,
       
  1359                                         TVersion (0,0,0),
       
  1360                                         *data );
       
  1361         CleanupStack::PopAndDestroy(2);
       
  1362         }
       
  1363 //#endif // __COVER_DISPLAY
       
  1364 // Cover UI end
       
  1365 
       
  1366     iCommonUiHelper->ShowWaitNoteL(
       
  1367         *string,
       
  1368         R_AVKON_SOFTKEYS_EMPTY,
       
  1369         EFalse,
       
  1370         this );
       
  1371     CleanupStack::PopAndDestroy( string );
       
  1372 
       
  1373     TMPXLaunchMode mode( MPXTlsHelper::LaunchMode() );
       
  1374     iPausedForSave = EFalse;
       
  1375     if ( EMPXLaunchModeTrack == mode )
       
  1376         {
       
  1377         // Close the file in playback engine
       
  1378         iPlaybackUtility->CommandL( EPbCmdPreservePosition );
       
  1379         iPlaybackUtility->CommandL( EPbCmdPreserveState );
       
  1380         iPlaybackUtility->CommandL( EPbCmdClose );
       
  1381         }
       
  1382     else
       
  1383         {
       
  1384         if ( EPbStatePlaying == iPlaybackUtility->StateL() )
       
  1385             {
       
  1386             iPlaybackUtility->CommandL( EPbCmdPause );
       
  1387             iPausedForSave = ETrue;
       
  1388             }
       
  1389         }
       
  1390 
       
  1391     // Check disk space
       
  1392     TBool allowMove( MPXTlsHelper::AllowMove() );
       
  1393 #ifdef RD_MULTIPLE_DRIVE
       
  1394     // Only need to check if on phone memory. All other drives were
       
  1395     // checked while creating the automatic save path
       
  1396     if( fileParse.Drive().CompareF( PathInfo::PhoneMemoryRootPath().Left(2) ) == 0 )
       
  1397 #else
       
  1398     // Do not need to check if on memory card as that was already done
       
  1399     if( fileParse.Drive().CompareF( PathInfo::MemoryCardRootPath().Left(2) ) != 0 )
       
  1400 #endif // RD_MULTIPLE_DRIVE
       
  1401         {
       
  1402         // If a file is being moved then there is no need to check for
       
  1403         // available space, as moving the file doesn't increase space consumption
       
  1404         // Check is still needed if a file is being copied
       
  1405         RFs& fs( iEikonEnv->FsSession() );
       
  1406         TInt size( 0 );
       
  1407         iFile.Size( size );
       
  1408         if ( !allowMove )
       
  1409             {
       
  1410             if ( SysUtil::FFSSpaceBelowCriticalLevelL( &fs, size ) )
       
  1411                 {
       
  1412                 iCommonUiHelper->DismissWaitNoteL();
       
  1413                 User::Leave( KErrDiskFull ); // Phone memory full, Avkon shows note
       
  1414                 }
       
  1415             }
       
  1416         }
       
  1417 
       
  1418     // Create save helper if not created
       
  1419     if ( !iSaveHelper )
       
  1420         {
       
  1421         iSaveHelper = CMPXSaveHelper::NewL( this, this );
       
  1422         }
       
  1423 
       
  1424     // s60 change. playlist could be opened from messaging app.
       
  1425     // in the case we don't want to copy in async mode
       
  1426     if (( EMPXLaunchModeTrack != MPXTlsHelper::LaunchMode() )
       
  1427         && (!iCommonUiHelper->IsHostMessagingL()))
       
  1428         {
       
  1429         iSaveHelper->StartCopyOperationL( iFile, newFile, allowMove );
       
  1430         iFile.Close();
       
  1431         }
       
  1432     else
       
  1433         {
       
  1434         if ( iCommonUiHelper->IsHostMessagingL() )
       
  1435             {
       
  1436             // save ringtone. We need to do sync call to save file because
       
  1437             // the asyc calls doesn't guarantee the file is copied completely.
       
  1438             // This is deal with a situation when set ringtone from messaging app
       
  1439             // that the ringtone files are kept in proviate directory.
       
  1440             iSaveHelper->StartCopyOperationL( iFile, newFile, EFalse, ETrue );
       
  1441             }
       
  1442         else
       
  1443             {
       
  1444             iSaveHelper->StartCopyOperationL( iFile, newFile, allowMove );
       
  1445             iFile.Close();
       
  1446             }
       
  1447         }
       
  1448 
       
  1449     MPX_DEBUG1("CMPXAppUi::DoSaveL(): exiting");
       
  1450     }
       
  1451 
       
  1452 // -----------------------------------------------------------------------------
       
  1453 // CreateAutomaticSavePathL
       
  1454 // -----------------------------------------------------------------------------
       
  1455 //
       
  1456 void CMPXAppUi::CreateAutomaticSavePathL( TFileName& aNewPath )
       
  1457     {
       
  1458     MPX_DEBUG1("CMPXAppUi::CreateAutomaticSavePathL(): entering");
       
  1459 
       
  1460     RFs& fs( iEikonEnv->FsSession() );
       
  1461     TFileName fileName;
       
  1462     iFile.FullName( fileName );
       
  1463     TParsePtrC fileParse( fileName );
       
  1464 
       
  1465     // Get the size and check if there's enough room to store
       
  1466     TInt size( 0 );
       
  1467     User::LeaveIfError( iFile.Size( size ));
       
  1468 
       
  1469 #ifdef RD_MULTIPLE_DRIVE
       
  1470     // Get the next available drive (internal mass store, MMC or phone memory)
       
  1471     HBufC* defaultRootPath( iCommonUiHelper->AvailableDriveLC( size ) );
       
  1472     aNewPath = *defaultRootPath;
       
  1473     CleanupStack::PopAndDestroy( defaultRootPath );
       
  1474 #else
       
  1475     HBufC* defaultRootPath( iCommonUiHelper->DefaultDriveLC() );
       
  1476     aNewPath = *defaultRootPath;
       
  1477     CleanupStack::PopAndDestroy( defaultRootPath );
       
  1478     if ( aNewPath.CompareF( PathInfo::MemoryCardRootPath()) == 0 )
       
  1479         {
       
  1480         // only if memory card is supported, check if there is enough space
       
  1481         // on the card.
       
  1482         TBool isBelowCritical( EFalse );
       
  1483         TRAPD( err, isBelowCritical =
       
  1484                     SysUtil::MMCSpaceBelowCriticalLevelL( &fs, size ));
       
  1485         if ( err || isBelowCritical )
       
  1486             {
       
  1487             aNewPath = PathInfo::PhoneMemoryRootPath();
       
  1488             }
       
  1489         }
       
  1490 #endif // RD_MULTIPLE_DRIVE
       
  1491 
       
  1492     TInt pathResId( KErrNotFound );
       
  1493 
       
  1494     // Get MIME type to see if it's a ringtone
       
  1495     RApaLsSession apa;
       
  1496     User::LeaveIfError( apa.Connect() );
       
  1497     CleanupClosePushL( apa );
       
  1498     TDataRecognitionResult result;
       
  1499     User::LeaveIfError( apa.RecognizeData( iFile, result ));
       
  1500     CleanupStack::PopAndDestroy( &apa );
       
  1501     TPtrC resultPtr( result.iDataType.Des() );
       
  1502     TInt val( 0 );
       
  1503     if ( iRingToneMimeTypes.Find( resultPtr, val ) == 0 )
       
  1504         {
       
  1505         pathResId = R_MPX_TARGETFOLDER_RINGTONES;
       
  1506         }
       
  1507     else if ( iCommonUiHelper->IsHostMessagingL() )
       
  1508         {
       
  1509         pathResId = R_MPX_TARGETFOLDER_ATTACHMENT;
       
  1510         }
       
  1511     else
       
  1512         {
       
  1513         pathResId = R_MPX_TARGETFOLDER_DOWNLOADS;
       
  1514         }
       
  1515 
       
  1516     HBufC* defaultPath( StringLoader::LoadLC( pathResId ));
       
  1517     aNewPath += *defaultPath;
       
  1518     aNewPath += fileParse.NameAndExt();
       
  1519     CleanupStack::PopAndDestroy( defaultPath );
       
  1520 
       
  1521     if ( !ConeUtils::FileExists( aNewPath ) )
       
  1522         {
       
  1523         User::LeaveIfError(
       
  1524             Application()->GenerateFileName( fs, aNewPath ));
       
  1525         }
       
  1526     else if ( iCommonUiHelper->IsHostMessagingL() )
       
  1527         {
       
  1528         MPXTlsHelper::SetNeedSave( EFalse );
       
  1529         }
       
  1530 
       
  1531     MPX_DEBUG1("CMPXAppUi::CreateAutomaticSavePathL(): exiting");
       
  1532     }
       
  1533 
       
  1534 // -----------------------------------------------------------------------------
       
  1535 // HandlePostSaveOperationL
       
  1536 // -----------------------------------------------------------------------------
       
  1537 //
       
  1538 void CMPXAppUi::HandlePostSaveOperationL()
       
  1539     {
       
  1540     MPX_DEBUG1("CMPXAppUi::HandlePostSaveOperationL(): entering");
       
  1541 
       
  1542     if ( iSaveMode == EMPXExitAppAfterSave )
       
  1543         {
       
  1544         MPX_DEBUG1( "CMPXAppUi::HandlePostSaveOperationL() exit after save" );
       
  1545         iSaveMode = EMPXSaveModeIdle;
       
  1546         iFile.Close();
       
  1547         RunAppShutter();
       
  1548         }
       
  1549     else if ( iSaveMode == EMPXExitHostAppAfterSave )
       
  1550         {
       
  1551         MPX_DEBUG1( "CMPXAppUi::HandlePostSaveOperationL() exit host app after save" );
       
  1552         iSaveMode = EMPXSaveModeIdle;
       
  1553         iFile.Close();
       
  1554         CAknEnv::RunAppShutter();
       
  1555         }
       
  1556     else
       
  1557         {
       
  1558         MPX_DEBUG1( "CMPXAppUi::HandlePostSaveOperationL() reopen" );
       
  1559         if ( EMPXLaunchModeTrack == MPXTlsHelper::LaunchMode() )
       
  1560             {
       
  1561             if ( iSavePath )
       
  1562                 {
       
  1563                 iCollectionUiHelper->OpenL( MPXTlsHelper::HostUid(),
       
  1564                                             *iSavePath,
       
  1565                                             this,
       
  1566                                             EMPXCollectionPluginMusic );
       
  1567                 delete iSavePath;
       
  1568                 iSavePath = NULL;
       
  1569                 // User may set ringtone or contact more than once so don't close it after save.
       
  1570                 // The iFile.Close will be called at destructor. It is safe because we are
       
  1571                 // in Embedded mode.
       
  1572                 if ( EMPXLaunchModeTrack != MPXTlsHelper::LaunchMode() )
       
  1573                     {
       
  1574                     iFile.Close();
       
  1575                     }
       
  1576                 }
       
  1577             else
       
  1578                 {
       
  1579                 if ( iFile.SubSessionHandle() )
       
  1580                     {
       
  1581                     TFileName filename;
       
  1582                     iFile.FullName( filename );
       
  1583                     iCollectionUiHelper->OpenL( MPXTlsHelper::HostUid(),
       
  1584                                                 filename,
       
  1585                                                 this,
       
  1586                                                 EMPXCollectionPluginMusic );
       
  1587                     }
       
  1588                 }
       
  1589             }
       
  1590         else
       
  1591             {
       
  1592             if ( iPausedForSave )
       
  1593                 {
       
  1594                 iPlaybackUtility->CommandL( EPbCmdPlay );
       
  1595                 }
       
  1596             }
       
  1597         iSaveMode = EMPXSaveModeIdle;
       
  1598         }
       
  1599 
       
  1600     MPX_DEBUG1("CMPXAppUi::HandlePostSaveOperationL(): exiting");
       
  1601     }
       
  1602 
       
  1603 // ---------------------------------------------------------------------------
       
  1604 // From MMPXPlaybackObserver
       
  1605 // Handle playback message.
       
  1606 // ---------------------------------------------------------------------------
       
  1607 //
       
  1608 void CMPXAppUi::HandlePlaybackMessage(
       
  1609     CMPXMessage* aMessage, TInt aError )
       
  1610     {
       
  1611     TBool skip = EFalse;
       
  1612 
       
  1613 #ifdef __CAMESE_SUPERDISTRIBUTION_SUPPORT       
       
  1614     if (aMessage)
       
  1615         {            
       
  1616         TMPXMessageId* id( aMessage->Value<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  1617         if ( id )
       
  1618             {
       
  1619             if ( KMPXMessageGeneral == *id )
       
  1620                 {
       
  1621                 // Prefilter the playback event before passing in to 
       
  1622                 // AppUi handler.        
       
  1623                 MPX_TRAP( aError, HandleCamesePlaybackPreProcessingL(*aMessage, skip) );
       
  1624                 }
       
  1625             }
       
  1626         }
       
  1627 #endif  
       
  1628 
       
  1629     if ( !skip && aError == KErrNone && aMessage )
       
  1630         {
       
  1631         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
  1632         }
       
  1633     }
       
  1634 
       
  1635 // ---------------------------------------------------------------------------
       
  1636 // From MMPXCollectionObserver.
       
  1637 // Handle media properties.
       
  1638 // ---------------------------------------------------------------------------
       
  1639 //
       
  1640 void CMPXAppUi::HandleCollectionMediaL(
       
  1641         const CMPXMedia& aMedia,
       
  1642         TInt aError )
       
  1643     {
       
  1644     MPX_FUNC( "CMPXAppUi::HandleCollectionMediaL" );
       
  1645     TBool okToOpen( ETrue );
       
  1646 
       
  1647     const CMPXMedia* media( &aMedia );
       
  1648 
       
  1649     // Check if rights OK
       
  1650     if ( !aError )
       
  1651         {
       
  1652         // First make sure it's a DRM file and the file protection type
       
  1653         if ( media->IsSupported( KMPXMediaDrmProtected ) &&
       
  1654                 media->IsSupported( KMPXMediaDrmType ) )
       
  1655             {
       
  1656             TBool prot(
       
  1657                     media->ValueTObjectL<TBool>( KMPXMediaDrmProtected ) );
       
  1658             if ( prot )
       
  1659                 {
       
  1660 #ifdef CAMESE_IN_DRM_UTILITY
       
  1661                 // OMA and WMDRM cases will be handled with same logic now
       
  1662                 okToOpen = HandleDRMProtectionL(*media);
       
  1663 #else
       
  1664                 TMPXMediaDrmType type( 
       
  1665                         media->ValueTObjectL<TMPXMediaDrmType>( KMPXMediaDrmType ) );
       
  1666                 if ( EMPXDrmTypeWMA == type )
       
  1667                     {
       
  1668                     okToOpen = HandleWMAProtectionL();
       
  1669                     }
       
  1670 
       
  1671                 else
       
  1672                     {
       
  1673                     okToOpen = HandleDRMProtectionL(*media);
       
  1674                     }
       
  1675 #endif                        
       
  1676                 }
       
  1677 
       
  1678             }
       
  1679         }
       
  1680     else
       
  1681         {
       
  1682         okToOpen = EFalse;
       
  1683 #ifndef __CAMESE_SUPERDISTRIBUTION_SUPPORT
       
  1684         // Leave Error Handling for Camese Ui
       
  1685         // if Camese support is enabled
       
  1686         iCommonUiHelper->HandleErrorL( aError );
       
  1687 #endif
       
  1688         }
       
  1689 
       
  1690     // If all checking passed then open
       
  1691     if ( okToOpen )
       
  1692         {
       
  1693         iCollectionUtility->Collection().OpenL();
       
  1694         }
       
  1695     else if ( MPXTlsHelper::NeedSave() )
       
  1696         {
       
  1697         MPX_DEBUG1( "CMPXAppUi::HandleCollectionMediaL open failed, attempting to save" );
       
  1698         HandleCommandL( EMPXCmdSaveAndExit );
       
  1699         }
       
  1700     }
       
  1701 
       
  1702     // ---------------------------------------------------------------------------
       
  1703     // CMPXAppUi::HandleWMAProtectionL
       
  1704     // ---------------------------------------------------------------------------
       
  1705     //
       
  1706 TBool CMPXAppUi::HandleWMAProtectionL()
       
  1707     {
       
  1708 #ifdef __CAMESE_SUPERDISTRIBUTION_SUPPORT    
       
  1709 
       
  1710     if ( !IsPlaybackRemote() )
       
  1711         {
       
  1712         // Indicates we are currently handling WMA Protected Media
       
  1713         iHandlingProtectedWMAMedia = ETrue;  
       
  1714         }
       
  1715 #endif
       
  1716     // Regardless of Camese support enabled or not,
       
  1717     // we always proceed to starting playback of
       
  1718     // protected WMA media.      
       
  1719     return ETrue;       
       
  1720     }
       
  1721 
       
  1722     // ---------------------------------------------------------------------------
       
  1723     // CMPXAppUi::HandleDRMProtectionL
       
  1724     // ---------------------------------------------------------------------------
       
  1725     //
       
  1726     TBool CMPXAppUi::HandleDRMProtectionL(const CMPXMedia& aMedia)
       
  1727         {
       
  1728         TBool okToOpen( ETrue );
       
  1729 
       
  1730     // DRM Protection
       
  1731     // Now check the rights status and if it's about to expire.
       
  1732     if ( aMedia.IsSupported( KMPXMediaDrmRightsStatus ) &&
       
  1733          aMedia.IsSupported( KMPXMediaDrmAboutToExpire ) )
       
  1734         {
       
  1735         TMPXMediaDrmRightsStatus status(
       
  1736             aMedia.ValueTObjectL<TMPXMediaDrmRightsStatus>(
       
  1737                 KMPXMediaDrmRightsStatus ) );
       
  1738         TBool aboutToExpire(
       
  1739             aMedia.ValueTObjectL<TBool>( KMPXMediaDrmAboutToExpire) );
       
  1740 
       
  1741         // Preview clips cannot be saved
       
  1742         if ( EMPXDrmRightsPreview == status )
       
  1743             {
       
  1744             MPXTlsHelper::SetNeedSave( EFalse );
       
  1745             }
       
  1746 
       
  1747         RFile* file( NULL );
       
  1748         if ( iFile.SubSessionHandle() &&
       
  1749              MPXTlsHelper::LaunchMode() != EMPXLaunchModePlaylist )
       
  1750             {
       
  1751             file = &iFile;
       
  1752             }
       
  1753 
       
  1754         // Display error message if about to expire, or if
       
  1755         // there are no rights
       
  1756         if ( aboutToExpire )
       
  1757             {
       
  1758             TInt ret( iCommonUiHelper->HandleErrorL(
       
  1759                         KMPXRightsAboutToExpire, &aMedia, file ));
       
  1760             if ( KErrNone != ret )
       
  1761                 {
       
  1762                 okToOpen = EFalse;
       
  1763                 }
       
  1764             }
       
  1765         else if ( EMPXDrmRightsMissing == status ||
       
  1766                 EMPXDrmRightsExpired == status )
       
  1767             {
       
  1768             // DRMStream:
       
  1769             // for silent cases the rights may have been recieved
       
  1770             TInt ret( iCommonUiHelper->HandleErrorL( KErrCANoRights, &aMedia, file ));
       
  1771             if ( KErrNone != ret )
       
  1772                 {
       
  1773                 okToOpen = EFalse;
       
  1774                 }
       
  1775             }
       
  1776 
       
  1777         if ( !okToOpen )
       
  1778             {
       
  1779             // If embedded and no rights, then close
       
  1780             if ( IsEmbedded() )
       
  1781                 {
       
  1782                 // Only close embedded mode if not a playlist
       
  1783                 if ( MPXTlsHelper::LaunchMode() != EMPXLaunchModePlaylist )
       
  1784                     {
       
  1785                     RunAppShutter();
       
  1786                     }
       
  1787                 else
       
  1788                     {
       
  1789                     // Reset collection path and save index
       
  1790                     MMPXCollection& col( iCollectionUtility->Collection() );
       
  1791                     CMPXCollectionPath* cPath( col.PathL() );
       
  1792                     CleanupStack::PushL( cPath );
       
  1793                     iCurrentIndex = cPath->Index();
       
  1794                     cPath->Back();
       
  1795                     col.OpenL( *cPath );
       
  1796                     CleanupStack::PopAndDestroy( cPath );
       
  1797                     }
       
  1798                 }
       
  1799 
       
  1800             // If standalone and no rights, mark item as invalid
       
  1801             // and reset collection path
       
  1802             else
       
  1803                 {
       
  1804                 // Check if DRM Flag is already mark as invalid, only set if it's not.
       
  1805                 MMPXCollection& col( iCollectionUtility->Collection() );
       
  1806                 TBool setDrm( ETrue );
       
  1807                 TBool clearOtherFlags( EFalse );
       
  1808                 TUint flag( 0 );
       
  1809 
       
  1810                 if ( aMedia.IsSupported( KMPXMediaGeneralFlags ))
       
  1811                     {
       
  1812                     flag = aMedia.ValueTObjectL<TUint>( KMPXMediaGeneralFlags );
       
  1813                     if ( flag & KMPXMediaGeneralFlagsIsDrmLicenceInvalid )
       
  1814                         {
       
  1815                         setDrm = EFalse;
       
  1816                         }
       
  1817                     if ( flag & KMPXMediaGeneralFlagsIsCorrupted ||
       
  1818                          flag & KMPXMediaGeneralFlagsIsInvalid )
       
  1819                         {
       
  1820                         clearOtherFlags = ETrue;
       
  1821                         }
       
  1822                     }
       
  1823                 if ( setDrm )
       
  1824                     {
       
  1825                     CMPXMedia* entry( CMPXMedia::NewL( aMedia ));
       
  1826                     CleanupStack::PushL( entry );
       
  1827 
       
  1828                     flag = KMPXMediaGeneralFlagsSetOrUnsetBit |
       
  1829                            KMPXMediaGeneralFlagsIsDrmLicenceInvalid;
       
  1830                     entry->SetTObjectValueL( KMPXMediaGeneralFlags, flag );
       
  1831                     SetMediaL( *entry );
       
  1832                     CleanupStack::PopAndDestroy( entry );
       
  1833                     }
       
  1834 
       
  1835                 // Reset corrupted and invalid flags if they are set
       
  1836                 if ( clearOtherFlags )
       
  1837                     {
       
  1838                     CMPXMedia* entry( CMPXMedia::NewL( aMedia ));
       
  1839                     CleanupStack::PushL( entry );
       
  1840 
       
  1841                     flag = KMPXMediaGeneralFlagsIsCorrupted |
       
  1842                            KMPXMediaGeneralFlagsIsInvalid;
       
  1843                     entry->SetTObjectValueL( KMPXMediaGeneralFlags, flag );
       
  1844                     SetMediaL( *entry );
       
  1845                     CleanupStack::PopAndDestroy( entry );
       
  1846                     }
       
  1847 
       
  1848                 // Reset collection path and save index
       
  1849                 CMPXCollectionPath* cPath( col.PathL() );
       
  1850                 CleanupStack::PushL( cPath );
       
  1851                 iCurrentIndex = cPath->Index();
       
  1852                 cPath->Back();
       
  1853                 col.OpenL( *cPath );
       
  1854                 CleanupStack::PopAndDestroy( cPath );
       
  1855                 }
       
  1856             }
       
  1857         }
       
  1858     else
       
  1859         {
       
  1860         // If rights status and about to expire attributes are
       
  1861         // not set, retrieve them.
       
  1862         RArray<TMPXAttribute> attrs;
       
  1863         CleanupClosePushL(attrs);
       
  1864         attrs.Append( TMPXAttribute( KMPXMediaIdGeneral,
       
  1865                                      EMPXMediaGeneralBasic |
       
  1866                                      EMPXMediaGeneralUri |
       
  1867                                      EMPXMediaGeneralFlags |
       
  1868                                      EMPXMediaGeneralCollectionId |
       
  1869                                      EMPXMediaGeneralId ));
       
  1870         attrs.Append( KMPXMediaDrmAll );
       
  1871         CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  1872         CleanupStack::PushL( cPath );
       
  1873         iCollectionUtility->Collection().MediaL(
       
  1874             *cPath,
       
  1875             attrs.Array() );
       
  1876         CleanupStack::PopAndDestroy( cPath );
       
  1877         CleanupStack::PopAndDestroy( &attrs );
       
  1878         okToOpen = EFalse;
       
  1879         }
       
  1880 
       
  1881     return okToOpen;
       
  1882     }
       
  1883 
       
  1884 // ---------------------------------------------------------------------------
       
  1885 // Handle Broadcast messages from the collection
       
  1886 // ---------------------------------------------------------------------------
       
  1887 //
       
  1888 void CMPXAppUi::HandleBroadcastMessageL( const CMPXMessage& aMessage )
       
  1889     {
       
  1890     // Disable media keys during system operations.
       
  1891     TInt op( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  1892     MPX_DEBUG2( "CMPXAppUi::HandleBroadcastMessageL EBroadcastEvent, op = %d", op );
       
  1893     if( op == EMcMsgUSBMassStorageStart ||
       
  1894         op == EMcMsgUSBMTPStart ||
       
  1895         op == EMcMsgRefreshStart ||
       
  1896         op == EMcMsgFormatStart )
       
  1897         {
       
  1898         MPX_DEBUG1( "CMPXAppUi::HandleBroadcastMessageL EBroadcastEvent disable media key" );
       
  1899         if ( !IsEmbedded() || op != EMcMsgUSBMTPStart )
       
  1900             {
       
  1901             iMediaKeyHandler->SetEnableMediaKeys( EFalse );
       
  1902             }
       
  1903         }
       
  1904     else if( op == EMcMsgUSBMassStorageEnd ||
       
  1905              op == EMcMsgUSBMTPEnd ||
       
  1906              op == EMcMsgRefreshEnd ||
       
  1907              op == EMcMsgFormatEnd )
       
  1908         {
       
  1909         MPX_DEBUG1( "CMPXAppUi::HandleBroadcastMessageL EBroadcastEvent enable media key" );
       
  1910         if ( !IsEmbedded() || op != EMcMsgUSBMTPEnd )
       
  1911             {
       
  1912             iMediaKeyHandler->SetEnableMediaKeys( ETrue );
       
  1913             }
       
  1914         }
       
  1915     if (op == EMcMsgRefreshEnd)
       
  1916         {
       
  1917         TInt err = aMessage.ValueTObjectL<TInt>(KMPXMessageGeneralData);
       
  1918 
       
  1919         MPX_DEBUG2("EMcMsgRefreshEnd, err = %d", err);
       
  1920 
       
  1921         if (err < KErrNone)
       
  1922             iCommonUiHelper->HandleErrorL(err);
       
  1923         }
       
  1924 
       
  1925     // Re-open the path so that the view can be refreshed,
       
  1926     // because there could be changes in the view contents
       
  1927     //
       
  1928     if ( op == EMcMsgUSBMassStorageStart ||
       
  1929          op == EMcMsgUSBMTPStart )
       
  1930         {
       
  1931         iIsUsbOnGoing = ETrue;
       
  1932         if ( iProcessParameter )
       
  1933             {
       
  1934             iProcessParameter->SetUsbInUse( ETrue );
       
  1935             }
       
  1936         }
       
  1937     if ( op == EMcMsgUSBMassStorageEnd ||
       
  1938         op == EMcMsgUSBMTPEnd )
       
  1939         {
       
  1940         iIsUsbOnGoing = EFalse;
       
  1941         if ( iProcessParameter )
       
  1942             {
       
  1943             iProcessParameter->SetUsbInUse( EFalse );
       
  1944             }
       
  1945         if( op == EMcMsgUSBMTPEnd )
       
  1946             {
       
  1947             DoUpdatePluginRefreshedTimeL();
       
  1948             }
       
  1949         }
       
  1950     if( op == EMcMsgFormatStart )
       
  1951         {
       
  1952         iFormattingOnGoing = ETrue;
       
  1953         }
       
  1954     else if( op == EMcMsgFormatEnd )
       
  1955         {
       
  1956         iFormattingOnGoing = EFalse;
       
  1957         }
       
  1958     else if ( op == EMcMsgRefreshStart )
       
  1959         {
       
  1960         iRefreshOnGoing = ETrue;
       
  1961         if( iProcessParameter )
       
  1962             {
       
  1963             iProcessParameter->SetRefreshState( ETrue );
       
  1964             }
       
  1965         }
       
  1966     else if ( op == EMcMsgRefreshEnd )
       
  1967         {
       
  1968         iRefreshOnGoing = EFalse;
       
  1969         if( iProcessParameter )
       
  1970             {
       
  1971             iProcessParameter->SetRefreshState( EFalse );
       
  1972             }
       
  1973         }
       
  1974 
       
  1975     if ( op == EMcMsgUSBMTPEnd )
       
  1976         {
       
  1977             if ( !IsEmbedded() )
       
  1978                 {
       
  1979                 CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL ( );
       
  1980                 CleanupStack::PushL ( cPath );
       
  1981                 TBool usbDiskRemovalEvent(EFalse);
       
  1982                 if ( (op == EMcMsgDiskRemoved) && iIsUsbOnGoing )
       
  1983                     {
       
  1984                     usbDiskRemovalEvent = ETrue;
       
  1985                     }
       
  1986 
       
  1987                 if ( cPath->Levels ( )> 1 && !iFormattingOnGoing && !usbDiskRemovalEvent &&
       
  1988                      iCurrentViewType.iUid != KMPXPluginTypePlaybackUid &&
       
  1989                      iCurrentViewType.iUid != KMPXPluginTypeAudioEffectsUid )
       
  1990                     {
       
  1991 
       
  1992                         cPath->Back ( );
       
  1993                         iCollectionUtility->Collection().OpenL ( *cPath );
       
  1994                         
       
  1995                     }
       
  1996                 CleanupStack::PopAndDestroy ( cPath );
       
  1997                 }
       
  1998 
       
  1999         }
       
  2000     else if ( op == EMcMsgDiskRemoved )
       
  2001         {
       
  2002         if ( !IsEmbedded() )
       
  2003             {
       
  2004             CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL ( );
       
  2005             CleanupStack::PushL ( cPath );
       
  2006             TBool usbDiskRemovalEvent(EFalse);
       
  2007             if ( (op == EMcMsgDiskRemoved) && iIsUsbOnGoing )
       
  2008                 {
       
  2009                 usbDiskRemovalEvent = ETrue;
       
  2010                 }
       
  2011 
       
  2012             if ( cPath->Levels ( )> 1 && !iFormattingOnGoing && !usbDiskRemovalEvent &&
       
  2013                  iCurrentViewType.iUid != KMPXPluginTypePlaybackUid )
       
  2014                 {
       
  2015 
       
  2016                     cPath->Back ( );
       
  2017                     iCollectionUtility->Collection().OpenL ( *cPath );
       
  2018                     
       
  2019                 }
       
  2020             CleanupStack::PopAndDestroy ( cPath );
       
  2021             }
       
  2022         }
       
  2023     // Re-open the collection view after a refresh
       
  2024     // and after album art or metadata dialog or add songs editor dialog closes
       
  2025     if (((op == EMcMsgRefreshEnd ) || (op == EMcMsgUSBMassStorageEnd))
       
  2026             && (IsActiveView(KMPXPluginTypeAlbumArtEditorUid)
       
  2027                     || IsActiveView(KMPXPluginTypeMetadataEditorUid)
       
  2028                     || IsActiveView( KMPXPluginTypeAddSongsEditorUid ) ) )
       
  2029         {
       
  2030         if ( !IsEmbedded() )
       
  2031             {
       
  2032             iRefreshCollectionView = ETrue;
       
  2033             }
       
  2034         }
       
  2035     // Re-open the collection view after a refresh
       
  2036     // if we were currently in collection view.
       
  2037     if( op == EMcMsgRefreshEnd && IsActiveView(KMPXPluginTypeCollectionUid))
       
  2038         {
       
  2039         if( !IsEmbedded() )
       
  2040             {
       
  2041             iRefreshCollectionView = EFalse;
       
  2042             CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
  2043             CleanupStack::PushL( path );
       
  2044             if( path->Levels() > 1 &&
       
  2045                 iCurrentViewType.iUid != KMPXPluginTypePlaybackUid )
       
  2046                 {
       
  2047                 path->Back();
       
  2048                 iCollectionUtility->Collection().OpenL( *path );
       
  2049                 }
       
  2050             CleanupStack::PopAndDestroy( path );
       
  2051             }
       
  2052         }
       
  2053     }
       
  2054 
       
  2055 // ---------------------------------------------------------------------------
       
  2056 // Handles commands passed in by other applications
       
  2057 // ---------------------------------------------------------------------------
       
  2058 //
       
  2059 void CMPXAppUi::HandleCommandParametersL( const TDesC8& aCommand )
       
  2060     {
       
  2061     MPX_FUNC( "CMPXAppUi::HandleCommandParametersL" );
       
  2062     if ( !iIgnoreExternalCommand && aCommand.Size() > 0 )
       
  2063         {
       
  2064         delete iProcessParameter;
       
  2065         iProcessParameter = NULL;
       
  2066         TUid collectionMode( KAppUidMusicPlayerX );
       
  2067         if ( IsEmbedded() )
       
  2068             {
       
  2069             collectionMode = MPXTlsHelper::HostUid(); // Collection context == host UID
       
  2070             }
       
  2071         iProcessParameter = CMPXCommandHandler::NewL(
       
  2072             iPlaybackUtility, collectionMode, aCommand );
       
  2073 
       
  2074         TBool fwdStandAlone( iProcessParameter->ForwardCmdToStandAloneMode() );
       
  2075         TBool fwdNowPlaying( iProcessParameter->ForwardCmdToNowPlaying() );
       
  2076 
       
  2077         MPX_DEBUG2( "CMPXAppUi::HandleCommandParametersL iIsUsbOnGoing = %d", iIsUsbOnGoing );
       
  2078         // if ActiveIdle plugin sends a command i.e., EMPXCmdFwdNowPlaying, it doesn't make any dialogs dismiss.
       
  2079         if ( !fwdNowPlaying && iCurrentViewType.iUid != KMPXPluginTypeWaitNoteDialogUid && !iIsUsbOnGoing )
       
  2080             {
       
  2081             MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL dismissing dialogs" );
       
  2082             // dismiss all the dialogs except scaning wait note
       
  2083             AknDialogShutter::ShutDialogsL( *CEikonEnv::Static() );
       
  2084             }
       
  2085 
       
  2086         iCmdActivatedViewTypeId = iProcessParameter->ActivatedViewTypeId();
       
  2087         MPX_DEBUG2( "CMPXAppUi::HandleCommandParametersL activated view type= =0x%x",
       
  2088             iCmdActivatedViewTypeId );
       
  2089 
       
  2090         MPX_DEBUG3( "CMPXAppUi::HandleCommandParametersL should forward to standalone %d, now playing %d", fwdStandAlone, fwdNowPlaying );
       
  2091 
       
  2092         RArray<TProcessId> procArray;
       
  2093         CleanupClosePushL( procArray );
       
  2094         TProcessId npProcId( 0 );
       
  2095         MMPXPlaybackUtility* activePbU = MMPXPlaybackUtility::UtilityL( KPbModeActivePlayer );
       
  2096         activePbU->GetClientsL( procArray );
       
  2097         activePbU->Close();
       
  2098         npProcId = procArray[ 0 ];
       
  2099         CleanupStack::PopAndDestroy( &procArray );
       
  2100 
       
  2101         TInt64 standAlonePId( CMPXCommonUiHelper::StandAloneModePId() );
       
  2102 
       
  2103         RProcess currProc;
       
  2104         TProcessId currPId( currProc.Id() );
       
  2105         currProc.Close();
       
  2106 
       
  2107         MPX_DEBUG2( "CMPXAppUi::HandleCommandParametersL current pid 0x%lx", currPId.Id() );
       
  2108         MPX_DEBUG2( "CMPXAppUi::HandleCommandParametersL nppid 0x%lx", npProcId.Id() );
       
  2109         MPX_DEBUG2( "CMPXAppUi::HandleCommandParametersL standalone pid 0x%lx", standAlonePId );
       
  2110 
       
  2111         if ( ( !fwdStandAlone && !fwdNowPlaying ) || // no forward
       
  2112              ( fwdStandAlone && ( currPId.Id() == standAlonePId ) ) || // we're standalone mode
       
  2113              ( fwdNowPlaying && ( currPId == npProcId ) ) ) // we are now playing
       
  2114             {
       
  2115             if ( iPathRestore )
       
  2116                 {
       
  2117                 if ( !iPathRestore->Initialized() &&
       
  2118                     iProcessParameter->IsInitPlaybackEngineNeeded() )
       
  2119                     {
       
  2120                     if ( iPathRestore->IsInitializing() )
       
  2121                         {
       
  2122                         MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL command handling delayed until path restore completes" );
       
  2123                         // delay command processing until path restore is complete
       
  2124                         iDelayedParameterHandling = ETrue;
       
  2125                         }
       
  2126                     else
       
  2127                         {
       
  2128                         MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL canceling path restore" );
       
  2129                         // command will init playback engine, can cancel path restore's init
       
  2130                         iPathRestore->CancelInit();
       
  2131                         }
       
  2132                     }
       
  2133                 }
       
  2134             if ( !iDelayedParameterHandling )
       
  2135                 {
       
  2136                 // command should be handled locally
       
  2137                 iProcessParameter->ProcessMessageL( iIsUsbOnGoing, iRefreshOnGoing, iFormattingOnGoing );
       
  2138                 }
       
  2139             }
       
  2140         else
       
  2141             {
       
  2142             TInt64 procId( 0 );
       
  2143             if ( iProcessParameter->ForwardCmdToStandAloneMode() )
       
  2144                 {
       
  2145                 MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL forwarding to standalone" );
       
  2146                 procId = standAlonePId;
       
  2147                 }
       
  2148             else if ( iProcessParameter->ForwardCmdToNowPlaying() )
       
  2149                 {
       
  2150                 MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL forwarding to now playing" );
       
  2151                 procId = npProcId.Id();
       
  2152                 }
       
  2153             delete iProcessParameter;
       
  2154             iProcessParameter = NULL;
       
  2155 
       
  2156             if ( procId != 0 )
       
  2157                 {
       
  2158                 // standalone music player exist, forward command to it
       
  2159                 RWsSession& wsSession( iCoeEnv->WsSession() );
       
  2160                 TInt wgId( MPXUser::FindWindowGroupIdL( procId, wsSession ) );
       
  2161                 MPX_DEBUG2( "CMPXAppUi::HandleCommandParametersL() forwarding message to wgId 0x%x", wgId );
       
  2162                 wsSession.SendMessageToWindowGroup( wgId, KAppUidMusicPlayerX, aCommand );
       
  2163                 }
       
  2164             else
       
  2165                 {
       
  2166                 MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL no music player instance, starting a new one" );
       
  2167                 // no music player instance, start a new one
       
  2168                 RApaLsSession ls;
       
  2169                 CleanupClosePushL( ls );
       
  2170                 User::LeaveIfError( ls.Connect() );
       
  2171                 TApaAppInfo appInfo;
       
  2172                 User::LeaveIfError( ls.GetAppInfo( appInfo, KAppUidMusicPlayerX ) );
       
  2173                 CApaCommandLine* apaCommandLine = CApaCommandLine::NewLC();
       
  2174                 apaCommandLine->SetExecutableNameL( appInfo.iFullName );
       
  2175                 apaCommandLine->SetTailEndL( aCommand );
       
  2176                 User::LeaveIfError( ls.StartApp( *apaCommandLine ) );
       
  2177                 CleanupStack::PopAndDestroy(); // apaCommandLine
       
  2178                 CleanupStack::PopAndDestroy(); // ls
       
  2179                 }
       
  2180             }
       
  2181         }
       
  2182     else if ( iIgnoreExternalCommand )
       
  2183         {
       
  2184         MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL command to be ignored, requested by views" );
       
  2185         // bring musicplayer to foreground
       
  2186         // have to use window group to activate, in case some other window
       
  2187         // has higher priority than us (e.g. playback popup and volume popup)
       
  2188         RWindowGroup myWin = CEikonEnv::Static()->RootWin();
       
  2189         myWin.SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
  2190         }
       
  2191     else
       
  2192         {
       
  2193         MPX_DEBUG1( "CMPXAppUi::HandleCommandParametersL invalid parameter length, command ignored" );
       
  2194         }
       
  2195     }
       
  2196 
       
  2197 // ---------------------------------------------------------------------------
       
  2198 // Handle playback message.
       
  2199 // ---------------------------------------------------------------------------
       
  2200 //
       
  2201 void CMPXAppUi::DoHandlePlaybackMessageL(
       
  2202     const CMPXMessage& aMessage )
       
  2203     {
       
  2204     MPX_FUNC( "CMPXAppUi::DoHandlePlaybackMessageL" );
       
  2205 
       
  2206     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  2207     if ( KMPXMessageGeneral == id )
       
  2208         {
       
  2209         switch ( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) )
       
  2210             {
       
  2211             case TMPXPlaybackMessage::EPlayerChanged:
       
  2212                 {
       
  2213                 MPX_DEBUG1( "CMPXAppUi::DoHandlePlaybackMessageL EPlayerChanged" );
       
  2214                 // get the current Volume and Max Volume
       
  2215                 iPlaybackUtility->PropertyL(*this, EPbPropertyVolume);
       
  2216                 iPlaybackUtility->PropertyL(*this, EPbPropertyMaxVolume);
       
  2217                 HandlePlaybackPlayerChangedL();
       
  2218                 break;
       
  2219                 }
       
  2220             case TMPXPlaybackMessage::EInitializeComplete:
       
  2221                 {
       
  2222                 MPX_DEBUG1( "CMPXAppUi::DoHandlePlaybackMessageL init complete" );
       
  2223                 TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  2224                 if ( ( IsEmbedded() || iPathRestore && iPathRestore->Initialized() ) && data )
       
  2225                     {
       
  2226                     TMPXLaunchMode mode = MPXTlsHelper::LaunchMode();
       
  2227                     if ( EMPXLaunchModeStopped != mode &&
       
  2228                        EMPXLaunchModeUnknown!= mode )
       
  2229                         {
       
  2230                         // Play the track
       
  2231                         MPX_DEBUG1( "CMPXAppUi::DoHandlePlaybackMessageL send play command" );
       
  2232                         CMPXCommand* cmd( CMPXCommand::NewL() );
       
  2233                         CleanupStack::PushL( cmd );
       
  2234                         cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId,
       
  2235                                                KMPXCommandIdPlaybackGeneral );
       
  2236                         cmd->SetTObjectValueL<TInt>( KMPXCommandPlaybackGeneralType,
       
  2237                                                EPbCmdPlay );
       
  2238                         cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync,
       
  2239                                                       ETrue );
       
  2240                         cmd->SetTObjectValueL<TBool>( KMPXCommandPlaybackGeneralNoBuffer,
       
  2241                                                 ETrue );
       
  2242                         iPlaybackUtility->CommandL( *cmd );
       
  2243                         CleanupStack::PopAndDestroy( cmd );
       
  2244                         }
       
  2245                     }
       
  2246                 else // iPathRestore not initialized
       
  2247                     {
       
  2248                     if ( iPathRestore )
       
  2249                         {
       
  2250                         iPathRestore->SetInitialized( ETrue );
       
  2251                         }
       
  2252 
       
  2253                     if ( iStandAlone )
       
  2254                         {
       
  2255                         iPlaybackUtility->CommandL( EPbCmdPlay );
       
  2256                         }
       
  2257 
       
  2258                     if ( iDelayedParameterHandling )
       
  2259                         {
       
  2260                         MPX_DEBUG1( "CMPXAppUi::DoHandlePlaybackMessageL start command handling" );
       
  2261                         iDelayedParameterHandling = EFalse;
       
  2262                         iProcessParameter->ProcessMessageL( iIsUsbOnGoing, iRefreshOnGoing, iFormattingOnGoing );
       
  2263                         }
       
  2264                     }
       
  2265 
       
  2266                 break;
       
  2267                 }
       
  2268             case TMPXPlaybackMessage::EPlayerUnavailable:
       
  2269                 {
       
  2270                 MPX_DEBUG1( "CMPXAppUi::DoHandlePlaybackMessageL EPlayerUnavailable" );
       
  2271                 iUPnPUnavailableEventFromCollection = EFalse;
       
  2272 
       
  2273                 MMPXSource* source = iPlaybackUtility->Source();
       
  2274                 if ( source )
       
  2275                     {
       
  2276                     CMPXCollectionPlaylist* playlist = source->PlaylistL();
       
  2277                     if ( playlist )
       
  2278                         {
       
  2279                         CleanupStack::PushL( playlist );
       
  2280                         iPlaybackUtility->PlayerManager().ClearSelectPlayersL();
       
  2281                         MPX_DEBUG2( "CMPXAppUi::DoHandlePlaybackMessageL playlist index = %d", playlist->Index());
       
  2282                         iPlaybackUtility->InitL( *playlist, ETrue );
       
  2283                         CleanupStack::PopAndDestroy( playlist );
       
  2284                         }
       
  2285                     }
       
  2286 
       
  2287                 if ( iCurrentViewType.iUid != KMPXPluginTypePlaybackUid )
       
  2288                     {
       
  2289                     iUPnPUnavailableEventFromCollection = ETrue;
       
  2290                     }
       
  2291 
       
  2292                 break;
       
  2293                 }
       
  2294             case TMPXPlaybackMessage::EPropertyChanged:
       
  2295                 {
       
  2296                 TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  2297                 TMPXPlaybackProperty property(
       
  2298                     static_cast<TMPXPlaybackProperty>( type ) );
       
  2299                 if ( property == EPbPropertyVolume )
       
  2300                     {
       
  2301                     iCurrentVolume = aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData );
       
  2302                     MPX_DEBUG2( "CMPXAppUi::DoHandlePlaybackMessageL iCurrentVolume = %d", iCurrentVolume );
       
  2303                     }
       
  2304                 else if( property == EPbPropertyRandomMode 
       
  2305                         || property == EPbPropertyRepeatMode )
       
  2306                     {
       
  2307                     TInt value = aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData );
       
  2308                     TUint32 key = KMPXMPPlaybackRandomMode;
       
  2309                     if( property == EPbPropertyRepeatMode )
       
  2310                         {
       
  2311                         key = KMPXMPPlaybackRepeatMode;
       
  2312                         }
       
  2313                     MPX_DEBUG3( "CMPXAppUi::DoHandlePlaybackMessageL EPropertyChanged key = %d, value = %d", key, value );
       
  2314                     CRepository* repository = CRepository::NewL( KCRUidMPXMPSettings );
       
  2315                     repository->Set( key, value );
       
  2316                     delete repository;
       
  2317                     repository = NULL;
       
  2318                     }
       
  2319                 break;
       
  2320                 }
       
  2321             case TMPXPlaybackMessage::EStateChanged:
       
  2322                 {
       
  2323                 TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  2324                 TMPXPlaybackState state(
       
  2325                     static_cast<TMPXPlaybackState>( type ) );
       
  2326 
       
  2327 #ifndef FF_OOM_MONITOR2_COMPONENT
       
  2328                 // Obtain wgname
       
  2329                 // Gets the window group id of the app in foreground
       
  2330                 RWsSession& wsSession( iCoeEnv->WsSession() );
       
  2331                 RWindowGroup myWin = iEikonEnv->RootWin();
       
  2332                 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, myWin.Identifier() );
       
  2333 #endif  //FF_OOM_MONITOR2_COMPONENT
       
  2334                 switch( state )
       
  2335                     {
       
  2336                     case EPbStateInitialising:
       
  2337                     case EPbStatePlaying:
       
  2338                     case EPbStatePaused:
       
  2339                     case EPbStateSeekingForward:
       
  2340                     case EPbStateSeekingBackward:
       
  2341                     case EPbStateBuffering:
       
  2342                     case EPbStateDownloading:
       
  2343                         {
       
  2344 #ifdef FF_OOM_MONITOR2_COMPONENT
       
  2345                         SetMpxOomPriorityL( ROomMonitorSession::EOomPriorityBusy );
       
  2346 #else
       
  2347                         wgName->SetBusy(ETrue);
       
  2348 #endif //FF_OOM_MONITOR2_COMPONENT
       
  2349                         break;
       
  2350                         }
       
  2351                     case EPbStateNotInitialised:
       
  2352                     case EPbStateStopped:
       
  2353                     case EPbStateShuttingDown:
       
  2354                         {
       
  2355 #ifdef FF_OOM_MONITOR2_COMPONENT
       
  2356                         SetMpxOomPriorityL( ROomMonitorSession::EOomPriorityNormal );
       
  2357 #else
       
  2358                         wgName->SetBusy(EFalse);
       
  2359 #endif //FF_OOM_MONITOR2_COMPONENT
       
  2360                         break;
       
  2361                         }
       
  2362                     default:
       
  2363                         {
       
  2364                         break;
       
  2365                         }
       
  2366                     }
       
  2367 #ifndef FF_OOM_MONITOR2_COMPONENT
       
  2368                 CleanupStack::PopAndDestroy();  //wgName
       
  2369 #endif //FF_OOM_MONITOR2_COMPONENT
       
  2370 
       
  2371                 break;
       
  2372                 }
       
  2373             case TMPXPlaybackMessage::EError:
       
  2374                 {
       
  2375                 MPX_DEBUG2( "CMPXAppUi::DoHandlePlaybackMessageL error = %d", aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  2376                 break;
       
  2377                 }
       
  2378             default:
       
  2379                 {
       
  2380                 break;
       
  2381                 }
       
  2382             }
       
  2383         }
       
  2384     }
       
  2385 
       
  2386 #ifdef __CAMESE_SUPERDISTRIBUTION_SUPPORT   
       
  2387 // ---------------------------------------------------------------------------
       
  2388 // Handle Camese Playback Message Preprocessing
       
  2389 // ---------------------------------------------------------------------------
       
  2390 //
       
  2391 void CMPXAppUi::HandleCamesePlaybackPreProcessingL(const CMPXMessage& aMessage,                                                   
       
  2392                                                    TBool& aSkipEvent)
       
  2393     {
       
  2394     aSkipEvent = EFalse;
       
  2395     
       
  2396     // Pre-filter events, avoiding handling if Camese 
       
  2397     // is handling WMA songs in pre-init phase.     
       
  2398     if (iHandlingProtectedWMAMedia)
       
  2399         {
       
  2400         TInt event = aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent );
       
  2401         if (event == TMPXPlaybackMessage::EPlayerChanged)            
       
  2402             { 
       
  2403             MPX_DEBUG1("CMPXAppUi::HandleCamesePlaybackPreProcessingL EPlayerChanged");
       
  2404 
       
  2405             // Do not allow processing of the player changed stage
       
  2406             // to avoid view switching.
       
  2407             aSkipEvent = ETrue;     
       
  2408             }
       
  2409         else if (event == TMPXPlaybackMessage::EInitializeComplete)
       
  2410             {
       
  2411             MPX_DEBUG1("CMPXAppUi::HandleCamesePlaybackPreProcessingL EStateChanged EInitializeComplete");
       
  2412             // Execute view switching now.
       
  2413             HandlePlaybackPlayerChangedL();  
       
  2414             // Finished Protected Media Handling stage.
       
  2415             iHandlingProtectedWMAMedia = EFalse;                                                    
       
  2416             }
       
  2417         else if (event == TMPXPlaybackMessage::EError)
       
  2418             {
       
  2419             MPX_DEBUG2( "CMPXAppUi::HandleCamesePlaybackPreProcessingL error = %d", aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  2420 
       
  2421             // Finished Protected Media Handling stage.
       
  2422             iHandlingProtectedWMAMedia = EFalse;
       
  2423             }
       
  2424         }   
       
  2425     }
       
  2426 #endif
       
  2427 
       
  2428 // ---------------------------------------------------------------------------
       
  2429 // Handle playback message for player changed.
       
  2430 // ---------------------------------------------------------------------------
       
  2431 //
       
  2432  void CMPXAppUi::HandlePlaybackPlayerChangedL()
       
  2433     {
       
  2434     // Don't switch views if we are getting player changed
       
  2435     // event from path restore or when we switch player because of a UPnP
       
  2436     // Unavailable event in Collection view
       
  2437     //
       
  2438     if ( !iUPnPUnavailableEventFromCollection &&
       
  2439          ( IsEmbedded() || iPathRestore ) )
       
  2440         {
       
  2441         if( iPathRestore && !iPathRestore->Initialized() )
       
  2442             {
       
  2443             iPathRestore->CancelInit();
       
  2444             }
       
  2445         MMPXPlayer* player =
       
  2446             iPlaybackUtility->PlayerManager().CurrentPlayer();
       
  2447         TUid pluginUid( KNullUid );
       
  2448         RArray<TUid> array;
       
  2449         CleanupClosePushL( array );
       
  2450 
       
  2451         if ( player )
       
  2452             {
       
  2453             pluginUid = player->UidL();
       
  2454             MPX_DEBUG2( "CMPXAppUi::HandlePlaybackPlayerChangedL pluginUid uid = 0x%x", pluginUid.iUid );
       
  2455             array.AppendL( pluginUid );
       
  2456             }
       
  2457 
       
  2458         MMPXSource* source = iPlaybackUtility->Source();
       
  2459         if ( source )
       
  2460             {
       
  2461             CMPXCollectionPlaylist* playlist = source->PlaylistL();
       
  2462             if ( playlist )
       
  2463                 {
       
  2464                 CleanupStack::PushL( playlist );
       
  2465                 CMPXCollectionPath* pbPath =
       
  2466                     CMPXCollectionPath::NewL( playlist->Path() );
       
  2467                 CleanupStack::PushL( pbPath );
       
  2468                 if ( pbPath->Levels() > 0 )
       
  2469                     {
       
  2470                     MPX_DEBUG2( "CMPXAppUi::HandlePlaybackPlayerChangedL collection uid = 0x%x", pbPath->Id( 0 ).iId1 );
       
  2471                     array.AppendL( TUid::Uid( pbPath->Id( 0 ) ) );
       
  2472                     }
       
  2473                 CleanupStack::PopAndDestroy( pbPath );
       
  2474                 CleanupStack::PopAndDestroy( playlist );
       
  2475                 }
       
  2476             }
       
  2477 
       
  2478         if ( IsEmbedded() )
       
  2479             {
       
  2480             array.AppendL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ));
       
  2481             }
       
  2482         else
       
  2483             {
       
  2484             array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid ) );
       
  2485             }
       
  2486         iViewUtility->ActivateViewL( array );
       
  2487         CleanupStack::PopAndDestroy( &array );
       
  2488 
       
  2489         MPX_DEBUG2( "-->Plugin Uid:(%d)", pluginUid.iUid );
       
  2490         }
       
  2491     iUPnPUnavailableEventFromCollection = EFalse;
       
  2492     }
       
  2493 
       
  2494 
       
  2495 // ---------------------------------------------------------------------------
       
  2496 // Callback function to signal that saving a file is complete
       
  2497 // ---------------------------------------------------------------------------
       
  2498 //
       
  2499 void CMPXAppUi::DoHandleSaveCompleteL( TInt aErr )
       
  2500     {
       
  2501     MPX_DEBUG2("CMPXAppUi::DoHandleSaveCompleteL(%d) entering", aErr);
       
  2502 
       
  2503     if( iIsUsbOnGoing && (aErr != KErrNone) )
       
  2504         {
       
  2505         // Kill mpx embedded mode so usb can start
       
  2506         //
       
  2507         MPX_DEBUG1("CMPXAppUi::HandleAddFileCompleteL usb ongoing");
       
  2508         iSaveMode = EMPXExitAppAfterSave;
       
  2509         HandlePostSaveOperationL();
       
  2510         }
       
  2511     else if ( !iCancelFileMan )
       
  2512         {
       
  2513         if ( !aErr )
       
  2514             {
       
  2515             if ( !iCollectionHelper )
       
  2516                 {
       
  2517                 iCollectionHelper = CMPXCollectionHelperFactory::NewCollectionHelperL();
       
  2518                 }
       
  2519             iCollectionHelper->AddL( *iSavePath, this );
       
  2520             if ( iView )
       
  2521                 {
       
  2522                 if ( iSaveMode == EMPXAssignRingtone )
       
  2523                     {
       
  2524                     TRAP_IGNORE(
       
  2525                         MPXTlsHelper::SetFilePath( iSavePath->Des() );
       
  2526                         iView->HandleCommandL( EMPXCmdAfterSaveAiwCmdAssign ));
       
  2527                     MPXTlsHelper::SetNeedSave( EFalse );
       
  2528                     }
       
  2529                 else if ( iSaveMode == EMPXAssignContact )
       
  2530                     {
       
  2531                     TRAP_IGNORE(
       
  2532                         iView->HandleCommandL( EMPXCmdAfterSaveUseAsCascade ));
       
  2533                     MPXTlsHelper::SetNeedSave( EFalse );
       
  2534                     }
       
  2535                 }
       
  2536             }
       
  2537         else
       
  2538             {
       
  2539             iCommonUiHelper->DismissWaitNoteL();
       
  2540             iCommonUiHelper->HandleErrorL( aErr );
       
  2541             delete iSavePath;
       
  2542             iSavePath = NULL;
       
  2543             if ( iView )
       
  2544                 {
       
  2545                 iView->HandleCommandL( EMPXCmdSaveCancelled );
       
  2546                 }
       
  2547             HandlePostSaveOperationL();
       
  2548             }
       
  2549         }
       
  2550     else
       
  2551         {
       
  2552         MPX_DEBUG1("CMPXAppUi::DoHandleSaveCompleteL() during cancel, starting callback" );
       
  2553         iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
  2554         iSaveMode = EMPXSaveModeIdle;
       
  2555         iIdle->Start( TCallBack( CMPXAppUi::DeferredExitCallback, this ) );
       
  2556         }
       
  2557 
       
  2558     MPX_DEBUG1("CMPXAppUi::DoHandleSaveCompleteL() exiting" );
       
  2559     }
       
  2560 
       
  2561 // -----------------------------------------------------------------------------
       
  2562 // Handle collection message
       
  2563 // -----------------------------------------------------------------------------
       
  2564 //
       
  2565 void CMPXAppUi::DoHandleCollectionMessageL( const CMPXMessage& aMessage )
       
  2566     {
       
  2567     MPX_FUNC( "CMPXAppUi::DoHandleCollectionMessageL" );
       
  2568 
       
  2569     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  2570     if ( KMPXCustomMessageId == id )
       
  2571         {
       
  2572         // This is a custom collection message
       
  2573         //
       
  2574         TInt colId = aMessage.ValueTObjectL<TInt>( TMPXAttribute( KMPXCustomMessageId,
       
  2575                                                       EMPXCustomMessageCollectionId ) );
       
  2576         TInt op = aMessage.ValueTObjectL<TInt>( TMPXAttribute( KMPXCustomMessageId,
       
  2577                                                    EMPXCustomMessageEventType ) );
       
  2578         TInt err = aMessage.ValueTObjectL<TInt>( TMPXAttribute( KMPXCustomMessageId,
       
  2579                                                     EMPXCustomMessageErrorCode ) );
       
  2580 
       
  2581         MPX_DEBUG4("CMPXAppUi::DoHandleCollectionMessageL -- KMPXCustomMessageId \
       
  2582                     %i %i %i", colId, op, err);
       
  2583 
       
  2584         if( colId == iMusicCollectionId.iUid ||
       
  2585             colId == iPodcastCollectionId.iUid )
       
  2586             {
       
  2587             if( op == EMcsOpen )
       
  2588                 {
       
  2589                 // @todo, need UI spec
       
  2590                 // popup special error note for out of disk
       
  2591                 iCommonUiHelper->HandleErrorL( err );
       
  2592                 }
       
  2593             }
       
  2594         }
       
  2595     else if ( KMPXMessageGeneral == id )
       
  2596         {
       
  2597         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
  2598         TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  2599         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  2600 
       
  2601         MPX_DEBUG3( "CMPXAppUi::DoHandleCollectionMessageL Event = %d, Type() = %d",
       
  2602             event, type );
       
  2603         if ( event == TMPXCollectionMessage::ECollectionChanged && !SuppressCollectionView() )
       
  2604             {
       
  2605             MPX_DEBUG1( "CMPXAppUi::DoHandleCollectionMessageL ECollectionChanged" );
       
  2606             if ( EMPXLaunchModeTrack != MPXTlsHelper::LaunchMode() )
       
  2607                 {
       
  2608                 CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  2609                 CleanupStack::PushL( cPath );
       
  2610                 if ( cPath->Levels() != 1 )
       
  2611                     {
       
  2612                     RArray<TUid> uids;
       
  2613                     CleanupClosePushL( uids );
       
  2614                    if ( iLaunchModePlaying && EMPXLaunchModePlaylist == MPXTlsHelper::LaunchMode() )
       
  2615                         {
       
  2616                         iLaunchModePlaying = EFalse;
       
  2617                         cPath->SelectL(TMPXItemId(0));
       
  2618                         iCollectionUtility->Collection().OpenL( *cPath );
       
  2619                         }
       
  2620                     else
       
  2621                         {
       
  2622                         uids.AppendL( TUid::Uid( KMPXPluginTypeCollectionUid ) );
       
  2623                         uids.AppendL( TUid::Uid( data ) );
       
  2624                         }
       
  2625 
       
  2626                     // If transitioning from Now Playing to Collection view,
       
  2627                     // We have to set the selection index
       
  2628                     // Only applicable if path levels is > 2, ie not music / podcast menu
       
  2629                     //
       
  2630                     if( iCurrentViewType.iUid == KMPXPluginTypePlaybackUid )
       
  2631                         {
       
  2632                         MMPXSource* s = iPlaybackUtility->Source();
       
  2633                         if( s && cPath->Levels() > 2 )
       
  2634                             {
       
  2635                             CMPXCollectionPlaylist* pl = s->PlaylistL();
       
  2636                             TInt browsePathCount = cPath->Count();
       
  2637 
       
  2638                             if (pl &&
       
  2639                                 browsePathCount > 0) // don't set index since this playlist
       
  2640                                                      // no longer contains any items, this can
       
  2641                                                      // happen in the case of autoplaylists and cause
       
  2642                                                      // a hang
       
  2643                                 {
       
  2644                                 CleanupStack::PushL( pl );
       
  2645                                 TInt playlistIndex = pl->Path().Index();
       
  2646                                 if(playlistIndex < browsePathCount)
       
  2647                                     {
       
  2648                                     iCollectionUtility->Collection().CommandL(EMcCmdSelect,
       
  2649                                                                               playlistIndex);
       
  2650                                     }
       
  2651                                 CleanupStack::PopAndDestroy( pl );
       
  2652                                 }
       
  2653                             }
       
  2654                         }
       
  2655 
       
  2656                     // Activate the collection view
       
  2657                     MPX_DEBUG2( "CMPXAppUi::DoHandleCollectionMessageL cpath depth = %d", cPath->Levels() );
       
  2658                     // only activate collection view when it's not at plugin selection
       
  2659                     // screen, it is handled by main view
       
  2660 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  2661                     icollectionBrowsed = ETrue;
       
  2662 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  2663                     iViewUtility->ActivateViewL( uids );
       
  2664                     CleanupStack::PopAndDestroy( &uids );
       
  2665                     }
       
  2666                 CleanupStack::PopAndDestroy( cPath );
       
  2667                 }
       
  2668             }
       
  2669         else if ( event == TMPXCollectionMessage::EPathChanged &&
       
  2670             !SuppressCollectionView() &&
       
  2671             type == EMcPathChangedByOpen &&
       
  2672             data == EMcItemOpened)
       
  2673             { // Open new entries
       
  2674 
       
  2675             MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL EPathChanged EMcItemOpened" );
       
  2676 
       
  2677             // First get media to check for protected state
       
  2678             RArray<TMPXAttribute> attrs;
       
  2679             CleanupClosePushL(attrs);
       
  2680             attrs.Append( TMPXAttribute( KMPXMediaIdGeneral,
       
  2681                                          EMPXMediaGeneralBasic |
       
  2682                                          EMPXMediaGeneralUri ));
       
  2683 
       
  2684             attrs.Append( TMPXAttribute( KMPXMediaIdDrm,
       
  2685                                          EMPXMediaDrmType |
       
  2686                                          EMPXMediaDrmProtected ));
       
  2687             CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  2688             CleanupStack::PushL( cPath );
       
  2689             if( cPath->Count() > 0 )
       
  2690                 {
       
  2691                 iCollectionUtility->Collection().MediaL(
       
  2692                     *cPath,
       
  2693                     attrs.Array() );
       
  2694                 }
       
  2695             else
       
  2696                 {
       
  2697                 // OpenL the blank playlist
       
  2698                 iCollectionUtility->Collection().OpenL();
       
  2699                 }
       
  2700             // Default start up state for local playback is Playing
       
  2701             MPXTlsHelper::SetLaunchModeL( EMPXLaunchModePlaying );
       
  2702             CleanupStack::PopAndDestroy( cPath );
       
  2703             CleanupStack::PopAndDestroy( &attrs );
       
  2704             }
       
  2705         else if( event == TMPXCollectionMessage::EPathChanged &&
       
  2706             !SuppressCollectionView() &&
       
  2707             type == EMcPathChangedByOpen &&
       
  2708             data == EMcContainerOpened  &&
       
  2709             ( iCurrentViewType.iUid == KMPXPluginTypePlaybackUid ||
       
  2710               iCurrentViewType.iUid == KMPXPluginTypeEmbeddedPlaybackUid ||
       
  2711               iCurrentViewType.iUid == KMPXPluginTypeAudioEffectsUid ||
       
  2712               iCurrentViewType.iUid == KMPXPluginTypeEqualizerUid) )
       
  2713             {
       
  2714             MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL EPathChanged EMcContainerOpened" );
       
  2715             CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  2716             CleanupStack::PushL( cPath );
       
  2717 
       
  2718             TInt levels( cPath->Levels() );
       
  2719             if ( levels != 1 )
       
  2720                 {
       
  2721                 iDeferredViewActivationUid.Reset();
       
  2722                 if ( iLaunchModePlaying && EMPXLaunchModePlaylist == MPXTlsHelper::LaunchMode() )
       
  2723                     {
       
  2724                     iLaunchModePlaying = EFalse;
       
  2725                     cPath->SelectL(TMPXItemId(0));
       
  2726                     iCollectionUtility->Collection().OpenL( *cPath );
       
  2727                     }
       
  2728                 else
       
  2729                     {
       
  2730                     iDeferredViewActivationUid.AppendL( TUid::Uid( KMPXPluginTypeCollectionUid ) );
       
  2731                     iDeferredViewActivationUid.AppendL( TUid::Uid( data ) );
       
  2732                     }
       
  2733                 // add the collection uid to make sure the correct view is
       
  2734                 // activated
       
  2735                 if ( levels > 0 )
       
  2736                     {
       
  2737                     iDeferredViewActivationUid.AppendL( TUid::Uid( cPath->Id( 0 ) ) );
       
  2738                     }
       
  2739 
       
  2740                 // Set selection to playlist index if transitioning from
       
  2741                 // playback to collection view
       
  2742                 // Only applicable if path levels is > 2, ie not music / podcast menu
       
  2743                 //
       
  2744                 MMPXSource* s = iPlaybackUtility->Source();
       
  2745                 if( s && levels > 2 )
       
  2746                     {
       
  2747                     CMPXCollectionPlaylist* pl = s->PlaylistL();
       
  2748                     TInt browsePathCount = cPath->Count();
       
  2749 
       
  2750                     // don't set index since this playlist
       
  2751                     // no longer contains any items, this can
       
  2752                     // happen in the case of autoplaylists and cause
       
  2753                     // a hang
       
  2754                     //
       
  2755                     // Make sure we are the same level and the same container before making index call
       
  2756                     //
       
  2757                     if (pl &&
       
  2758                         browsePathCount > 0 &&
       
  2759                         levels == pl->Path().Levels() &&
       
  2760                         cPath->Id(levels-2) == pl->Path().Id(levels-2) )
       
  2761                         {
       
  2762                         CleanupStack::PushL( pl );
       
  2763                         TInt playlistIndex = pl->Path().Index();
       
  2764 
       
  2765                         if(playlistIndex < browsePathCount)
       
  2766                             {
       
  2767                             iCollectionUtility->Collection().CommandL(EMcCmdSelect,
       
  2768                                                                      playlistIndex);
       
  2769                             }
       
  2770                         CleanupStack::PopAndDestroy( pl );
       
  2771                         }
       
  2772                     }
       
  2773 
       
  2774                 MPX_DEBUG2( "CMPXAppUi::HandleCollectionMessageL cpath depth = %d", cPath->Levels() );
       
  2775                 if ( IsForeground() )
       
  2776                     {
       
  2777                     MPX_DEBUG3( "CMPXAppUi::HandleCollectionMessageL Activating view now CurUid=0x%x, DefUid=0x%x", iCurrentViewType.iUid, iDeferredViewActivationUid[iDeferredViewActivationUid.Count()-1].iUid);
       
  2778                     // only activate collection view when it's not at plugin selection
       
  2779                     // screen, it is handled by main view
       
  2780                     iViewUtility->ActivateViewL( iDeferredViewActivationUid );
       
  2781                     iDeferredViewActivationUid.Reset();
       
  2782                     }
       
  2783                 else
       
  2784                     {
       
  2785                     MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL musicplayer in background, deferred view activation" );
       
  2786                     }
       
  2787                 }
       
  2788             CleanupStack::PopAndDestroy( cPath );
       
  2789             }
       
  2790 
       
  2791         else if( event == TMPXCollectionMessage::EPathChanged &&
       
  2792             type == EMcPathChangedByOpen &&
       
  2793             data == EMcContainerOpened )
       
  2794             {
       
  2795             MPXTlsHelper::SetLaunchModeL( EMPXLaunchModePlaying );
       
  2796             CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  2797             CleanupStack::PushL( cPath );
       
  2798 
       
  2799             if ( cPath->Levels() == 1 && !IsEmbedded() &&
       
  2800                 iCurrentViewType.iUid != KMPXPluginTypeMainUid &&
       
  2801                 iCurrentViewType.iUid != KMPXPluginTypeWaitNoteDialogUid &&
       
  2802                 !SuppressCollectionView() )
       
  2803                 {
       
  2804                 // activate main view if other clients navigated to first level
       
  2805                 if ( IsForeground() )
       
  2806                     {
       
  2807                     MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL Switching to main view" );
       
  2808                     iViewUtility->ActivateViewL(
       
  2809                         TUid::Uid( KMPXPluginTypeMainUid ) );
       
  2810                     }
       
  2811                 else
       
  2812                     {
       
  2813                     MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL musicplayer in background, deferred view activation" );
       
  2814                     iDeferredViewActivationUid.Reset();
       
  2815                     iDeferredViewActivationUid.Append( TUid::Uid( KMPXPluginTypeMainUid ) );
       
  2816                     }
       
  2817                 }
       
  2818 
       
  2819 			TInt level(2);
       
  2820 			if ( iStartInAlbumMenu )
       
  2821 				{
       
  2822 				level = 3;
       
  2823 				}
       
  2824 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  2825             // Music Player opens directly at level 2 so we need to initialize
       
  2826             // the path then
       
  2827             if( cPath->Levels() == level && iPathRestore && !iPathRestore->Initialized() && !iStandAlone )
       
  2828 #else
       
  2829             if( cPath->Levels() == 1 && iPathRestore && !iPathRestore->Initialized() )
       
  2830 #endif
       
  2831                 {
       
  2832                 if ( iProcessParameter )
       
  2833                     {
       
  2834                     if ( !iProcessParameter->IsPathInited() )
       
  2835                         {
       
  2836                         MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL load path" );
       
  2837                         iPathRestore->LoadPathL();
       
  2838                         }
       
  2839                     else
       
  2840                         {
       
  2841                         MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL path inited by command handler, not restore path" );
       
  2842                         }
       
  2843                     }
       
  2844                 else
       
  2845                     {
       
  2846                     MPX_DEBUG1( "CMPXAppUi::HandleCollectionMessageL load path" );
       
  2847                     iPathRestore->LoadPathL();
       
  2848                     }
       
  2849                 }
       
  2850             else if ( iCurrentIndex != KErrNotFound )
       
  2851                 {
       
  2852                 iCollectionUtility->Collection().CommandL( EMcCmdSelect, iCurrentIndex );
       
  2853                 iCurrentIndex = KErrNotFound;
       
  2854                 iCollectionUtility->Collection().OpenL();
       
  2855                 }
       
  2856             CleanupStack::PopAndDestroy( cPath );
       
  2857             }
       
  2858 
       
  2859         else if( event == TMPXCollectionMessage::EBroadcastEvent )
       
  2860             {
       
  2861             HandleBroadcastMessageL( aMessage );
       
  2862             }
       
  2863         }
       
  2864     }
       
  2865 
       
  2866 // -----------------------------------------------------------------------------
       
  2867 // CMPXAppUi::IsPlaybackRemote
       
  2868 // -----------------------------------------------------------------------------
       
  2869 //
       
  2870 TBool CMPXAppUi::IsPlaybackRemote()
       
  2871     {
       
  2872     TBool isRemote = EFalse;
       
  2873 
       
  2874     TMPXPlaybackPlayerType type( EPbLocal );
       
  2875     TUid uid;
       
  2876     TInt index;
       
  2877     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  2878     HBufC* subPlayerName = NULL;
       
  2879     TRAP_IGNORE( manager.GetSelectionL( type, uid, index, subPlayerName ) );
       
  2880     delete subPlayerName;
       
  2881 
       
  2882 //#ifdef __UPNP_FRAMEWORK_2_0_
       
  2883     if ( FeatureManager::FeatureSupported( KFeatureIdUpnpFramework20 ) )
       
  2884         {
       
  2885         // Check for Remote, since in embedded mode
       
  2886         // playback utility will report type as Unknown.
       
  2887         if ( type == EPbRemote )
       
  2888             {
       
  2889             isRemote = ETrue;
       
  2890             }
       
  2891         }
       
  2892 
       
  2893 //#endif //__UPNP_FRAMEWORK_2_0_
       
  2894 
       
  2895     return isRemote;
       
  2896     }
       
  2897 
       
  2898 // -----------------------------------------------------------------------------
       
  2899 // CMPXAppUi::SetMediaL
       
  2900 // -----------------------------------------------------------------------------
       
  2901 //
       
  2902 void CMPXAppUi::SetMediaL( CMPXMedia& aMedia )
       
  2903     {
       
  2904     // Set to collection
       
  2905     CMPXCommand* cmd( CMPXCommand::NewL() );
       
  2906     CleanupStack::PushL( cmd );
       
  2907     cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdCollectionSet );
       
  2908     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue );
       
  2909     TUid colId( aMedia.ValueTObjectL<TUid>(KMPXMediaGeneralCollectionId));
       
  2910     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
  2911     cmd->SetCObjectValueL<CMPXMedia>( KMPXCommandColSetMedia, &aMedia );
       
  2912     iCollectionUtility->Collection().CommandL( *cmd );
       
  2913     CleanupStack::PopAndDestroy( cmd );
       
  2914     }
       
  2915 
       
  2916 // ---------------------------------------------------------------------------
       
  2917 // Handle Custom messages from the collection
       
  2918 // ---------------------------------------------------------------------------
       
  2919 //
       
  2920 void CMPXAppUi::HandleCollectionMessage( CMPXMessage* aMessage, TInt aError )
       
  2921     {
       
  2922     if ( aError == KErrNone && aMessage )
       
  2923         {
       
  2924         TRAP_IGNORE( DoHandleCollectionMessageL( *aMessage ) )
       
  2925         }
       
  2926     }
       
  2927 
       
  2928 // ---------------------------------------------------------------------------
       
  2929 // From MMPXCollectionObserver.
       
  2930 // Handles the collection entries being opened.
       
  2931 // ---------------------------------------------------------------------------
       
  2932 //
       
  2933 void CMPXAppUi::HandleOpenL(
       
  2934     const CMPXMedia& /* aEntries */,
       
  2935     TInt /* aIndex */,
       
  2936     TBool /* aComplete */,
       
  2937     TInt aError )
       
  2938     {
       
  2939     if ( aError != KErrNone )
       
  2940         {
       
  2941         // Clip the collection path to root level and reopen
       
  2942         // This could happen after a USB refresh event where the
       
  2943         // item no longer exists
       
  2944         //
       
  2945         CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
  2946         CleanupStack::PushL( path );
       
  2947         while( path->Levels() > 1)
       
  2948             {
       
  2949             path->Back();
       
  2950             }
       
  2951         iCollectionUtility->Collection().OpenL( *path );
       
  2952         CleanupStack::PopAndDestroy( path );
       
  2953         }
       
  2954     }
       
  2955 
       
  2956 
       
  2957 // ---------------------------------------------------------------------------
       
  2958 // From MMPXCollectionObserver.
       
  2959 // Handles the item being opened.
       
  2960 // ---------------------------------------------------------------------------
       
  2961 //
       
  2962 void CMPXAppUi::HandleOpenL(
       
  2963     const CMPXCollectionPlaylist& aPlaylist,
       
  2964     TInt aError )
       
  2965     {
       
  2966     MPX_FUNC("CMPXAppUi::HandleOpenL()");
       
  2967     if ( KErrNone == aError )
       
  2968         {
       
  2969         if( !IsEmbedded() )
       
  2970             {
       
  2971             TInt count ( aPlaylist.Count() ) ;
       
  2972 
       
  2973             // temporarily disable repeat and shuffle if playlist
       
  2974             // is a podcast playlist and the list is not empty.
       
  2975             if(KMPXUidPodcastDBPlugin == TUid::Uid((TInt)aPlaylist.Path().Id(0)))
       
  2976                 {
       
  2977                 if(count > 0)
       
  2978                     {
       
  2979                     CMPXCollectionPlaylist* tmpPlaylist =
       
  2980                                     CMPXCollectionPlaylist::NewL( aPlaylist );
       
  2981                     CleanupStack::PushL( tmpPlaylist );
       
  2982                     tmpPlaylist->SetRepeatEnabled( EFalse );
       
  2983                     tmpPlaylist->SetShuffleEnabledL( EFalse );
       
  2984                     iPlaybackUtility->InitL( *tmpPlaylist, ETrue );
       
  2985                     CleanupStack::PopAndDestroy( tmpPlaylist );
       
  2986                     }
       
  2987                 else
       
  2988                     {
       
  2989                     // Empty now playing
       
  2990                     //
       
  2991                     CMPXCollectionPlaylist* tmpPlaylist =
       
  2992                                     CMPXCollectionPlaylist::NewL( aPlaylist );
       
  2993                     CleanupStack::PushL( tmpPlaylist );
       
  2994                     tmpPlaylist->SetRepeatEnabled( EFalse );
       
  2995                     tmpPlaylist->SetShuffleEnabledL( EFalse );
       
  2996                     iPlaybackUtility->InitL( *tmpPlaylist, ETrue );
       
  2997 
       
  2998                     RArray<TUid> array;
       
  2999                     CleanupClosePushL( array );
       
  3000 
       
  3001                     CMPXCollectionPath* pbPath =
       
  3002                             CMPXCollectionPath::NewL( tmpPlaylist->Path() );
       
  3003                     CleanupStack::PushL( pbPath );
       
  3004                     if ( pbPath->Levels() > 0 )
       
  3005                         {
       
  3006                         array.AppendL( TUid::Uid( pbPath->Id( 0 ) ) );
       
  3007                         }
       
  3008                     CleanupStack::PopAndDestroy( pbPath );
       
  3009 
       
  3010                     array.AppendL( KLocalPlaybackUid );
       
  3011 
       
  3012                     if ( IsEmbedded() )
       
  3013                         {
       
  3014                         array.AppendL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ));
       
  3015                         }
       
  3016                     else
       
  3017                         {
       
  3018                         array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid ) );
       
  3019                         }
       
  3020                     iViewUtility->ActivateViewL( array );
       
  3021                     CleanupStack::PopAndDestroy( &array );
       
  3022                     CleanupStack::PopAndDestroy( tmpPlaylist );
       
  3023                     }
       
  3024                 }
       
  3025             else
       
  3026                 {
       
  3027 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3028                 if ( iPdParameterHandler && !iPdParameterHandler->IsPlaybackCompleted())
       
  3029                     {
       
  3030                         iPdParameterHandler->HandleCommandL(EPbCmdPause);
       
  3031                     }
       
  3032 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3033                 if ( count > 0 )
       
  3034                     {
       
  3035                     iPlaybackUtility->InitL( aPlaylist, ETrue );
       
  3036                     }
       
  3037                 else if( count == 0 &&
       
  3038                          iPathRestore->Initialized() )
       
  3039                     {
       
  3040                     // Empty now playing
       
  3041                     //
       
  3042                     iPlaybackUtility->InitL( aPlaylist, EFalse );
       
  3043 
       
  3044                     RArray<TUid> array;
       
  3045                     CleanupClosePushL( array );
       
  3046 
       
  3047                     CMPXCollectionPath* pbPath =
       
  3048                             CMPXCollectionPath::NewL( aPlaylist.Path() );
       
  3049                     CleanupStack::PushL( pbPath );
       
  3050                     if ( pbPath->Levels() > 0 )
       
  3051                         {
       
  3052                         array.AppendL( TUid::Uid( pbPath->Id( 0 ) ) );
       
  3053                         }
       
  3054                     CleanupStack::PopAndDestroy( pbPath );
       
  3055 
       
  3056                     if ( IsEmbedded() )
       
  3057                         {
       
  3058                         array.AppendL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ));
       
  3059                         }
       
  3060                     else
       
  3061                         {
       
  3062                         array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid ) );
       
  3063                         }
       
  3064                     iViewUtility->ActivateViewL( array );
       
  3065                     CleanupStack::PopAndDestroy( &array );
       
  3066                     }
       
  3067                 }
       
  3068             // ETrue->initialize next song concurrently
       
  3069             }
       
  3070         else
       
  3071             {
       
  3072             // aPlaylist is const, must copy
       
  3073             //
       
  3074             CMPXCollectionPlaylist* tmp =
       
  3075                                     CMPXCollectionPlaylist::NewL( aPlaylist );
       
  3076             CleanupStack::PushL( tmp );
       
  3077             tmp->SetEmbeddedPlaylist( ETrue );
       
  3078             tmp->SetRepeatEnabled( EFalse );
       
  3079             tmp->SetShuffleEnabledL( EFalse );
       
  3080             iPlaybackUtility->InitL( *tmp, ETrue );
       
  3081             CleanupStack::PopAndDestroy( tmp );
       
  3082             }
       
  3083         }
       
  3084     }
       
  3085 
       
  3086 // ---------------------------------------------------------------------------
       
  3087 // From MMPXCHelperEmbeddedOpenObserver
       
  3088 // Handles OpenL from that occured in embedded mode
       
  3089 // ---------------------------------------------------------------------------
       
  3090 //
       
  3091 void CMPXAppUi::HandleEmbeddedOpenL( TInt aErr, TMPXGeneralCategory aCategory  )
       
  3092     {
       
  3093     MPX_FUNC( "CMPXAppUi::HandleEmbeddedOpenL" );
       
  3094     if( aErr != KErrNone )
       
  3095         {
       
  3096         iCommonUiHelper->HandleErrorL( aErr );
       
  3097 
       
  3098         // Kill MPX
       
  3099         RunAppShutter();
       
  3100         }
       
  3101     else // No error, set the launch mode
       
  3102         {
       
  3103         iPlaybackUtility->CommandL( EPbCmdDisableEffect );
       
  3104         if( aCategory == EMPXPlaylist )
       
  3105             {
       
  3106             if ( MPXTlsHelper::LaunchMode() == EMPXLaunchModePlaying )
       
  3107                 {
       
  3108                 iLaunchModePlaying = ETrue;
       
  3109                 }
       
  3110             MPXTlsHelper::SetLaunchModeL( EMPXLaunchModePlaylist );
       
  3111             }
       
  3112         else // ( aCategory == EMPXSong )
       
  3113             {
       
  3114             MPXTlsHelper::SetLaunchModeL( EMPXLaunchModeTrack );
       
  3115             iViewUtility->ActivateViewL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ));
       
  3116             }
       
  3117         }
       
  3118     }
       
  3119 
       
  3120 // ---------------------------------------------------------------------------
       
  3121 // From MMPXViewActivationObserver.
       
  3122 // Handle view activation.
       
  3123 // ---------------------------------------------------------------------------
       
  3124 //
       
  3125 void CMPXAppUi::HandleViewActivation(
       
  3126     const TUid& aCurrentViewType,
       
  3127     const TUid& aPreviousViewType )
       
  3128     {
       
  3129     MPX_FUNC( "CMPXAppUi::HandleViewActivation" );
       
  3130     MPX_DEBUG3("CurrentViewType=0x%x, PreviousViewType=0x%x", aCurrentViewType.iUid, aPreviousViewType.iUid);
       
  3131     iCurrentViewType = aCurrentViewType;
       
  3132     iPreviousViewType = aPreviousViewType;
       
  3133     iDeferredViewActivationUid.Reset();
       
  3134 
       
  3135     switch ( aCurrentViewType.iUid )
       
  3136         {
       
  3137         case KMPXPluginTypePlaybackUid:
       
  3138             {
       
  3139             if ( IsForeground() )
       
  3140                 {
       
  3141                 iMediaKeyHandler->DismissNotifier( EDisplayMediaPopup );
       
  3142                 }
       
  3143             break;
       
  3144             }
       
  3145       
       
  3146         case KMPXPluginTypeCollectionUid:
       
  3147             {
       
  3148             if (iRefreshCollectionView )
       
  3149                 {
       
  3150                 iRefreshCollectionView = EFalse;
       
  3151                 TRAP_IGNORE(ReOpenPathL());
       
  3152                 }
       
  3153             break;
       
  3154             }
       
  3155         default:
       
  3156             {
       
  3157             // Do nothing
       
  3158             break;
       
  3159             }
       
  3160         }
       
  3161     }
       
  3162 
       
  3163 // ---------------------------------------------------------------------------
       
  3164 // From CEikAppUi.
       
  3165 // Opens the specified file
       
  3166 // ---------------------------------------------------------------------------
       
  3167 //
       
  3168 void CMPXAppUi::HandleViewUpdate(
       
  3169     TUid /* aViewUid */,
       
  3170     MMPXViewActivationObserver::TViewUpdateEvent /* aUpdateEvent */,
       
  3171     TBool /* aLoaded */,
       
  3172     TInt /* aData */)
       
  3173     {
       
  3174     MPX_FUNC( "CMPXAppUi::HandleViewUpdate" );
       
  3175     }
       
  3176 
       
  3177 // ---------------------------------------------------------------------------
       
  3178 // From CEikAppUi.
       
  3179 // Opens the specified file
       
  3180 // ---------------------------------------------------------------------------
       
  3181 //
       
  3182 void CMPXAppUi::OpenFileL( const TDesC& aFileName )
       
  3183     {
       
  3184     MPX_FUNC( "CMPXAppUi::OpenFileL" );
       
  3185 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3186    if ( iPdParameterHandler )
       
  3187         {
       
  3188         // no need to open file at this time.
       
  3189         return;
       
  3190         }
       
  3191 #endif //RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3192     if ( IsEmbedded() )
       
  3193         {
       
  3194         CreateMemberVariablesL();
       
  3195 
       
  3196         iViewUtility->PreLoadViewL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ));
       
  3197     // Open file with collection helper
       
  3198     iCollectionUiHelper->OpenL( MPXTlsHelper::HostUid(),
       
  3199                                 aFileName, this,
       
  3200                                 EMPXCollectionPluginMusic );
       
  3201         }
       
  3202     else
       
  3203         {
       
  3204        
       
  3205         MPX_DEBUG1( "CMPXAppUi::OpenFileL Standalone" );
       
  3206         TDataType datatype( TUid::Uid( KMusicPlayerAppUidConstant ) );
       
  3207         iDocHandler->OpenTempFileL( aFileName, iFile );
       
  3208         
       
  3209         CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();
       
  3210         TMPXLaunchMode  mode( EMPXLaunchModeStopped );
       
  3211         TAiwVariant value(  mode );
       
  3212         TAiwGenericParam param( EGenericParamPlayerInitMode, value );
       
  3213         paramList->AppendL( param ); // Takes ownership
       
  3214 
       
  3215         TRAPD( err, iDocHandler->OpenFileEmbeddedL( iFile, datatype, *paramList ));
       
  3216 
       
  3217         //
       
  3218         //  ignore some document handler errors
       
  3219         //
       
  3220         if ( err == KErrServerTerminated )
       
  3221             {
       
  3222             //
       
  3223             //  Document handler leaves with -15 if end key is pressed when
       
  3224             //  embedded application is not fully started or embedded
       
  3225             //  application panics in start up.  So we can only close the
       
  3226             //  App in this point and hope that user is press end key
       
  3227             //
       
  3228             HandleCommandL( EEikCmdExit );
       
  3229             }
       
  3230         else if ( err != KErrNone )
       
  3231             {
       
  3232             //  Reset error since it was handled here and
       
  3233             //  the program will exit
       
  3234             //
       
  3235             User::Leave( err );
       
  3236             }
       
  3237 
       
  3238         CleanupStack::PopAndDestroy(paramList);
       
  3239         MPX_DEBUG1( "CMPXAppUi::OpenFileL Register as callback for exit" );
       
  3240         iDocHandler->SetExitObserver(this);
       
  3241         
       
  3242         iStandAlone = ETrue;
       
  3243             
       
  3244         }
       
  3245     }
       
  3246 
       
  3247 // ---------------------------------------------------------------------------
       
  3248 // From CCoeAppUi.
       
  3249 // Handle foreground event.
       
  3250 // ---------------------------------------------------------------------------
       
  3251 //
       
  3252 void CMPXAppUi::HandleForegroundEventL(
       
  3253     TBool aForeground )
       
  3254     {
       
  3255     MPX_FUNC_EX( "CMPXAppUi::HandleForegroundEventL" );
       
  3256 
       
  3257     if ( !aForeground )
       
  3258         {
       
  3259         // music player is going to background
       
  3260         // set key repeat rate to normal avkon rate
       
  3261         CEikonEnv::Static()->WsSession().SetKeyboardRepeatRate(
       
  3262             KAknKeyboardRepeatInitialDelay, KAknStandardKeyboardRepeatRate );
       
  3263         CEikonEnv::Static()->WsSession().Flush();
       
  3264         }
       
  3265 
       
  3266     // Dismiss playback popup if foreground app is active idle or playback
       
  3267     // view is on foreground
       
  3268     if ( ( !aForeground && IsActiveIdleEnabled() && IsIdleAppForeground() )
       
  3269         || ( aForeground
       
  3270             && ( KMPXPluginTypePlaybackUid == iCurrentViewType.iUid ) ) )
       
  3271         {
       
  3272         iMediaKeyHandler->DismissNotifier( EDisplayMediaPopup );
       
  3273         }
       
  3274 
       
  3275     if ( aForeground && iDeferredViewActivationUid.Count() != 0 )
       
  3276         {
       
  3277         MPX_DEBUG1( "CMPXAppUi::HandleForegroundEventL deferred view activation, activating" );
       
  3278         iViewUtility->ActivateViewL( iDeferredViewActivationUid );
       
  3279         iDeferredViewActivationUid.Reset();
       
  3280         }
       
  3281 
       
  3282     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
  3283     }
       
  3284 
       
  3285 // ---------------------------------------------------------------------------
       
  3286 // From CEikAppUi.
       
  3287 // Owerwritten -> file opening
       
  3288 // (app startup via shell commands)
       
  3289 // ---------------------------------------------------------------------------
       
  3290 //
       
  3291 TBool CMPXAppUi::ProcessCommandParametersL(
       
  3292     TApaCommand /*aCommand*/,
       
  3293     TFileName& aDocumentName,
       
  3294     const TDesC8& /*aTail*/ )
       
  3295     {
       
  3296     MPX_FUNC_EX( "CMPXAppUi::ProcessCommandParametersL TApaCommand" );
       
  3297     return ConeUtils::FileExists( aDocumentName );
       
  3298     }
       
  3299 
       
  3300 
       
  3301 // ---------------------------------------------------------------------------
       
  3302 // Launch matrix menu suite with specific message
       
  3303 // ---------------------------------------------------------------------------
       
  3304 //
       
  3305 void CMPXAppUi::LaunchMmViewL( const TDesC8& aMessage )
       
  3306     {
       
  3307     TApaTaskList taskList( iCoeEnv->WsSession() );
       
  3308     TApaTask task = taskList.FindApp( TUid::Uid( KMmUid3 ) );
       
  3309 
       
  3310     if ( task.Exists() )
       
  3311         {
       
  3312         task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ), 
       
  3313              aMessage );
       
  3314         }
       
  3315     }  
       
  3316 
       
  3317 // ---------------------------------------------------------------------------
       
  3318 // From CEikAppUi.
       
  3319 // Handle commands.
       
  3320 // ---------------------------------------------------------------------------
       
  3321 //
       
  3322 void CMPXAppUi::HandleCommandL(
       
  3323     TInt aCommand )
       
  3324     {
       
  3325     MPX_FUNC( "CMPXAppUi::HandleCommandL" );
       
  3326     TMPXPlaybackCommand cmd = EPbCmdEnd;
       
  3327     switch ( aCommand )
       
  3328         {
       
  3329         case EMPXCmdPlay:
       
  3330         case EMPXCmdPause:
       
  3331         case EMPXCmdPlayPause:
       
  3332         case EMPXCmdStop:
       
  3333         case EMPXCmdNext:
       
  3334         case EMPXCmdPrevious:
       
  3335         case EMPXCmdSeekForward:
       
  3336         case EMPXCmdSeekBackward:
       
  3337         case EMPXCmdStopSeeking:
       
  3338             {
       
  3339             switch ( aCommand )
       
  3340                 {
       
  3341                 case EMPXCmdPlay:
       
  3342                     cmd = EPbCmdPlay;
       
  3343                     break;
       
  3344                 case EMPXCmdPause:
       
  3345                     cmd = EPbCmdPause;
       
  3346                     break;
       
  3347                 case EMPXCmdPlayPause:
       
  3348                     cmd = EPbCmdPlayPause;
       
  3349                     break;
       
  3350                 case EMPXCmdStop:
       
  3351                     cmd = EPbCmdStop;
       
  3352                     break;
       
  3353                 case EMPXCmdNext:
       
  3354                     cmd = EPbCmdNext;
       
  3355                     break;
       
  3356                 case EMPXCmdPrevious:
       
  3357                     cmd = EPbCmdPrevious;
       
  3358                     break;
       
  3359                 case EMPXCmdSeekForward:
       
  3360                     cmd = EPbCmdStartSeekForward;
       
  3361                     break;
       
  3362                 case EMPXCmdSeekBackward:
       
  3363                     cmd = EPbCmdStartSeekBackward;
       
  3364                     break;
       
  3365                 case EMPXCmdStopSeeking:
       
  3366                     cmd = EPbCmdStopSeeking;
       
  3367                     break;
       
  3368                 default:
       
  3369                     break;
       
  3370                 }
       
  3371             DoHandleMediaKeyCommandL( cmd );
       
  3372             break;
       
  3373             }
       
  3374         case EMPXCmdGoToNowPlaying:
       
  3375             {
       
  3376 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3377 
       
  3378             TBool pdPlaybackCompleted(EFalse);
       
  3379             if ( iPdParameterHandler )
       
  3380                 {
       
  3381                 pdPlaybackCompleted = iPdParameterHandler->IsPlaybackCompleted();
       
  3382                 if ( pdPlaybackCompleted )
       
  3383                     {
       
  3384                     delete iPdParameterHandler;
       
  3385                     iPdParameterHandler = NULL;
       
  3386                     }
       
  3387                 }
       
  3388 
       
  3389             MMPXPlaybackUtility* activePlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeActivePlayer );
       
  3390 
       
  3391             MMPXPlayer* player =
       
  3392                 activePlaybackUtility->PlayerManager().CurrentPlayer();
       
  3393             TUid pluginUid( KNullUid );
       
  3394             RArray<TUid> array;
       
  3395             CleanupClosePushL( array );
       
  3396 
       
  3397 
       
  3398             MMPXSource* source = activePlaybackUtility->Source();
       
  3399             CMPXCollectionPlaylist* pl = NULL;
       
  3400             if( source )
       
  3401                 {
       
  3402                 pl = source->PlaylistL();
       
  3403                 }
       
  3404 
       
  3405             if ( pl || !pdPlaybackCompleted )
       
  3406                 {
       
  3407                 if (pl)
       
  3408                   delete pl;
       
  3409                 if ( player )
       
  3410                     {
       
  3411                     array.AppendL( player->UidL() );
       
  3412                     if ( IsEmbedded() )
       
  3413                         {
       
  3414                         array.AppendL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ) );
       
  3415                         }
       
  3416                     }
       
  3417                 else
       
  3418                     {
       
  3419                     if ( IsEmbedded() )
       
  3420                         {
       
  3421                         array.AppendL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ) );
       
  3422                         }
       
  3423                     else
       
  3424                         {
       
  3425                         array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid ) );
       
  3426                         }
       
  3427                     }
       
  3428 
       
  3429                 // add the collection plugin UID to ensure the correct
       
  3430                 // last playback view is activated
       
  3431                 //MMPXSource* source = activePlaybackUtility->Source();
       
  3432                 if( source )
       
  3433                     {
       
  3434                     CMPXCollectionPlaylist* pl = source->PlaylistL();
       
  3435                     if (pl)
       
  3436                         {
       
  3437                         CleanupStack::PushL( pl );
       
  3438                         const CMPXCollectionPath& path = pl->Path();
       
  3439                         if(path.Levels() > 0)
       
  3440                             {
       
  3441                             array.AppendL(TUid::Uid(path.Id(0)));
       
  3442                             }
       
  3443                         CleanupStack::PopAndDestroy( pl );
       
  3444                         }
       
  3445                     }
       
  3446                 else if ( !iPathRestore->Initialized() )
       
  3447                     {
       
  3448                     if ( iPathRestore->RooPathId() != KNullUid )
       
  3449                         {
       
  3450                         array.AppendL( iPathRestore->RooPathId() );
       
  3451                         }
       
  3452                     }
       
  3453                 }
       
  3454             else
       
  3455                 {
       
  3456                 CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  3457                 CleanupStack::PushL( cPath );
       
  3458 
       
  3459                 array.AppendL( TUid::Uid( KMPXPluginTypeCollectionUid ) );
       
  3460                 if ( cPath->Levels() > 0 )
       
  3461                     {
       
  3462                     array.AppendL( TUid::Uid( cPath->Id( 0 ) ) );
       
  3463                     }
       
  3464                 CleanupStack::PopAndDestroy( cPath );
       
  3465                 }
       
  3466 
       
  3467             if ( iAppStartedByBrowser && !icollectionBrowsed && pdPlaybackCompleted)
       
  3468                 {
       
  3469                 activePlaybackUtility->Close();
       
  3470                 CleanupStack::PopAndDestroy( &array );
       
  3471                 RunAppShutter();
       
  3472                 break;
       
  3473                 }
       
  3474             else
       
  3475                 {
       
  3476                 activePlaybackUtility->Close();
       
  3477                 iViewUtility->ActivateViewL( array );
       
  3478                 CleanupStack::PopAndDestroy( &array );
       
  3479                 }
       
  3480 
       
  3481             break;
       
  3482             }
       
  3483 #else // RD_BROWSER_PROGRESSIVE_DOWNLOAD not supported
       
  3484             MMPXPlayer* player =
       
  3485                 iPlaybackUtility->PlayerManager().CurrentPlayer();
       
  3486             TUid pluginUid( KNullUid );
       
  3487             RArray<TUid> array;
       
  3488             CleanupClosePushL( array );
       
  3489 
       
  3490             if ( player )
       
  3491                 {
       
  3492                 array.AppendL( player->UidL() );
       
  3493                 if ( IsEmbedded() )
       
  3494                     {
       
  3495                     array.AppendL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ) );
       
  3496                     }
       
  3497                 }
       
  3498             else
       
  3499                 {
       
  3500                 if ( IsEmbedded() )
       
  3501                     {
       
  3502                     array.AppendL( TUid::Uid( KMPXPluginTypeEmbeddedPlaybackUid ) );
       
  3503                     }
       
  3504                 else
       
  3505                     {
       
  3506                     array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid ) );
       
  3507                     }
       
  3508                 }
       
  3509 
       
  3510             // add the collection plugin UID to ensure the correct
       
  3511             // last playback view is activated
       
  3512             MMPXSource* source = iPlaybackUtility->Source();
       
  3513             if( source )
       
  3514                 {
       
  3515                 CMPXCollectionPlaylist* pl = source->PlaylistL();
       
  3516                 if (pl)
       
  3517                     {
       
  3518                     CleanupStack::PushL( pl );
       
  3519                     const CMPXCollectionPath& path = pl->Path();
       
  3520                     if(path.Levels() > 0)
       
  3521                         {
       
  3522                         array.AppendL(TUid::Uid(path.Id(0)));
       
  3523                         }
       
  3524                     CleanupStack::PopAndDestroy( pl );
       
  3525                     }
       
  3526                 }
       
  3527 
       
  3528             iViewUtility->ActivateViewL( array );
       
  3529             CleanupStack::PopAndDestroy( &array );
       
  3530             break;
       
  3531             }
       
  3532 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3533 
       
  3534         case EMPXCmdVolumeChanged:
       
  3535             cmd = EPbCmdSetVolume;
       
  3536             HandlePopupL(cmd);
       
  3537             break;
       
  3538         case EMPXCmdIgnoreExternalCommand:
       
  3539             {
       
  3540             iIgnoreExternalCommand = ETrue;
       
  3541             break;
       
  3542             }
       
  3543         case EMPXCmdHandleExternalCommand:
       
  3544             {
       
  3545             iIgnoreExternalCommand = EFalse;
       
  3546             break;
       
  3547             }
       
  3548         case EMPXCmdHideApp:
       
  3549             {
       
  3550             // Move Music Player to background
       
  3551             // magic: -1 = force wg to background
       
  3552             iEikonEnv->RootWin().SetOrdinalPosition( -1 );
       
  3553             break;
       
  3554             }
       
  3555 
       
  3556         case EAknSoftkeyBack:
       
  3557             {
       
  3558 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3559             if ( iViewUtility->ViewHistoryDepth() == 1 || iAppStartedByBrowser )
       
  3560                 {
       
  3561                 HandleCommandL( EEikCmdExit );
       
  3562                 }
       
  3563 
       
  3564             else if ( iPbvStartedByBrowser && !iAppStartedByBrowser )
       
  3565                 {
       
  3566                 iPbvStartedByBrowser = EFalse;
       
  3567 
       
  3568                 if( iPdParameterHandler )
       
  3569                     {
       
  3570                     if( !( iPdParameterHandler->IsPlaybackCompleted() ) )
       
  3571                         {
       
  3572 
       
  3573                         iPdParameterHandler->HandleCommandL( EPbCmdStop );
       
  3574                         }
       
  3575                     iPdParameterHandler->HandleCommandL( EPbCmdClose );
       
  3576                     delete iPdParameterHandler;
       
  3577                     iPdParameterHandler = NULL;
       
  3578                     }
       
  3579 
       
  3580                 iRefreshCollectionView = ETrue;
       
  3581                 iViewUtility->ActivatePreviousViewL();
       
  3582                 BringUpBrowserL();
       
  3583                 }
       
  3584 
       
  3585             else if ( !iPdParameterHandler || !iAppStartedByBrowser )
       
  3586                 {
       
  3587                 iViewUtility->ActivatePreviousViewL();
       
  3588                 }
       
  3589 
       
  3590             else
       
  3591                 {
       
  3592                 HandleCommandL( EEikCmdExit );
       
  3593                 }
       
  3594 #else
       
  3595             // if we're in top level of our local view stack,
       
  3596             // back command exits the app.  otherwise activate
       
  3597             // the previous view in our local view stack
       
  3598             if ( iViewUtility->ViewHistoryDepth() == 1 )
       
  3599                 {
       
  3600                 HandleCommandL( EEikCmdExit );
       
  3601                 }
       
  3602             else
       
  3603                 {
       
  3604                 iViewUtility->ActivatePreviousViewL();
       
  3605                 }
       
  3606 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3607             break;
       
  3608             }
       
  3609         case EEikCmdExit: // fall through        
       
  3610         case EAknCmdExit:
       
  3611 		case EAknSoftkeyExit:
       
  3612 			{
       
  3613             if ( iView && KMPXPluginTypeCollectionUid == iCurrentViewType.iUid )
       
  3614                 {
       
  3615                 MPX_DEBUG2( "CMPXAppUi::HandleCommand() "
       
  3616                             "sending EMPXCmdCancelReorder to view %d",
       
  3617                             KMPXPluginTypeCollectionUid );
       
  3618                 iView->HandleCommandL( EMPXCmdCancelReorder );
       
  3619                 }
       
  3620             CloseWaitNoteL();
       
  3621 
       
  3622 			if( aCommand == EAknCmdExit || aCommand == EEikCmdExit ) 
       
  3623 				{
       
  3624 				TKeyEvent key;
       
  3625 				key.iCode = EKeyEscape;
       
  3626 				key.iModifiers = 0;
       
  3627 
       
  3628 				// Under EQ it is possible to have multiple dialogs open
       
  3629 				TInt err( KErrNone );
       
  3630 				while( IsDisplayingDialog() && err == KErrNone )
       
  3631 					{
       
  3632 					TRAP( err, iCoeEnv->SimulateKeyEventL(key,EEventKey); )
       
  3633 					}
       
  3634 
       
  3635 				// Options/Exit selected, close also the MM suite
       
  3636                 if( aCommand == EAknCmdExit )
       
  3637                     {
       
  3638                     LaunchMmViewL( KMmMessage );
       
  3639                     }
       
  3640 				}
       
  3641 
       
  3642             if ( iSaveMode != EMPXSaveModeIdle )
       
  3643                 {
       
  3644                 iCancelFileMan = ETrue;
       
  3645                 }
       
  3646             else
       
  3647                 {
       
  3648                 if( iPathRestore )
       
  3649                     {
       
  3650                     TRAP_IGNORE(iPathRestore->SavePathL());
       
  3651                     }
       
  3652 
       
  3653                 if ( iPlaybackUtility )
       
  3654                     {
       
  3655                     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  3656                     TRAP_IGNORE( manager.ClearSelectPlayersL() );
       
  3657                     iPlaybackUtility->CommandL( EPbCmdClose );
       
  3658                     }
       
  3659 
       
  3660                 Exit();
       
  3661                 }
       
  3662             break;
       
  3663             }
       
  3664         case EAknCmdHelp:
       
  3665             {
       
  3666             HlpLauncher::LaunchHelpApplicationL(
       
  3667                 iEikonEnv->WsSession(),
       
  3668                 AppHelpContextL() );
       
  3669             break;
       
  3670             }
       
  3671         case EMPXCmdSaveAndReopen:
       
  3672             {
       
  3673             iCancelFileMan = EFalse;
       
  3674             iSaveMode = EMPXOpenAfterSave;
       
  3675             MPX_TRAPD( err, DoSaveL());
       
  3676             if ( KErrNone != err )
       
  3677                 {
       
  3678                 HandleSaveComplete( err );
       
  3679                 }
       
  3680             break;
       
  3681             }
       
  3682         case EMPXCmdIsFileSaved:
       
  3683             {
       
  3684             TFileName SavedAudioFile;
       
  3685             CreateAutomaticSavePathL( SavedAudioFile );
       
  3686             break;
       
  3687             }
       
  3688         case EMPXCmdSaveForUseAsContact:
       
  3689         case EMPXCmdSaveForUseAsRingtone:
       
  3690             {
       
  3691             iCancelFileMan = EFalse;
       
  3692             ASSERT( iFile.SubSessionHandle() );
       
  3693             TBool abort = EFalse;
       
  3694             TBool aiwExecuted = EFalse;
       
  3695             TFileName fullName;
       
  3696             iFile.FullName( fullName );
       
  3697             TParsePtrC fileParse( fullName );
       
  3698             TBool isPrivate = (fileParse.NamePresent() &&
       
  3699                 !KMPXMusicplayerPrivateFolder().CompareF(
       
  3700                     fileParse.Path().Left(
       
  3701                         KMPXMusicplayerPrivateFolder().Length())));
       
  3702             TFileName savedFile;
       
  3703             CreateAutomaticSavePathL( savedFile );
       
  3704 
       
  3705 
       
  3706             if ( isPrivate && !ConeUtils::FileExists( savedFile ) )
       
  3707                 {
       
  3708                 HBufC* string( StringLoader::LoadLC( R_MPX_QUERY_CONF_SAVE_DOWNLOADED,
       
  3709                                                      fileParse.Name() ));
       
  3710                 CAknQueryDialog* confirmationDlg( CAknQueryDialog::NewL(
       
  3711                     CAknQueryDialog::EConfirmationTone ));
       
  3712                 if ( confirmationDlg->ExecuteLD( R_MPX_SAVE_SONG_CONFIRMATION_QUERY,
       
  3713                                                  *string ))
       
  3714                     {
       
  3715                     // User wants to save the file and execute AIW function
       
  3716                     if ( aCommand == EMPXCmdSaveForUseAsRingtone )
       
  3717                         {
       
  3718                         iSaveMode = EMPXAssignRingtone;
       
  3719                         }
       
  3720                     else if ( aCommand == EMPXCmdSaveForUseAsContact )
       
  3721                         {
       
  3722                         iSaveMode = EMPXAssignContact;
       
  3723                         }
       
  3724                     MPX_TRAPD( err, DoSaveL() );
       
  3725                     if ( KErrNone != err )
       
  3726                         {
       
  3727                         HandleSaveComplete( err );
       
  3728                         }
       
  3729                     abort = EFalse;
       
  3730                     aiwExecuted = ETrue;
       
  3731                     if ( iView )
       
  3732                         {
       
  3733                         iView->HandleCommandL( EMPXCmdSaveComplete );
       
  3734                         }
       
  3735                     }
       
  3736                 else
       
  3737                     {
       
  3738                     if ( iView )
       
  3739                         {
       
  3740                         iView->HandleCommandL( EMPXCmdSaveNotProgress );
       
  3741                         }
       
  3742                     abort = ETrue;
       
  3743                     }
       
  3744                 CleanupStack::PopAndDestroy( string );
       
  3745                 }
       
  3746             else if ( ConeUtils::FileExists( savedFile ) )
       
  3747                 {
       
  3748                 if ( iView )
       
  3749                     {
       
  3750                     iView->HandleCommandL( EMPXCmdSaveNotProgress );
       
  3751                     }
       
  3752                 MPXTlsHelper::SetFilePath( savedFile );
       
  3753                 }
       
  3754 
       
  3755             if ( !abort && !aiwExecuted )
       
  3756                 {
       
  3757                 if ( aCommand == EMPXCmdSaveForUseAsRingtone )
       
  3758                     {
       
  3759                     TRAP_IGNORE(
       
  3760                         iView->HandleCommandL( EMPXCmdAfterSaveAiwCmdAssign ));
       
  3761                     }
       
  3762                 else if ( aCommand == EMPXCmdSaveForUseAsContact )
       
  3763                     {
       
  3764                     TRAP_IGNORE(
       
  3765                         iView->HandleCommandL( EMPXCmdAfterSaveUseAsCascade ));
       
  3766                     }
       
  3767                 }
       
  3768             break;
       
  3769             }
       
  3770         case EMPXCmdSaveAndExit: // fall though
       
  3771         case EMPXCmdSaveAndExitHostApp:
       
  3772             {
       
  3773             iCancelFileMan = EFalse;
       
  3774             ASSERT( iFile.SubSessionHandle() );
       
  3775             TFileName fullName;
       
  3776             iFile.FullName( fullName );
       
  3777             TParsePtrC fileParse( fullName );
       
  3778             HBufC* string( StringLoader::LoadLC( R_MPX_QUERY_CONF_SAVE_DOWNLOADED,
       
  3779                                                  fileParse.Name() ));
       
  3780             CAknQueryDialog* confirmationDlg( CAknQueryDialog::NewL(
       
  3781                 CAknQueryDialog::EConfirmationTone ));
       
  3782 //#ifdef __COVER_DISPLAY
       
  3783             confirmationDlg->PublishDialogL(
       
  3784                     EMPlayerQueryNotSaved,
       
  3785                     KMPlayerNoteCategory);
       
  3786 
       
  3787             CAknMediatorFacade* covercl(
       
  3788                 AknMediatorFacade( confirmationDlg ) );
       
  3789             if ( covercl )
       
  3790                 {
       
  3791                 covercl->BufStream() << fileParse.Name();
       
  3792                 }
       
  3793 //#endif //__COVER_DISPLAY
       
  3794 
       
  3795             if ( confirmationDlg->ExecuteLD( R_MPX_SAVE_SONG_CONFIRMATION_QUERY,
       
  3796                                              *string ))
       
  3797                 {
       
  3798                 iSaveMode = ( aCommand == EMPXCmdSaveAndExit ?
       
  3799                     EMPXExitAppAfterSave : EMPXExitHostAppAfterSave );
       
  3800                 MPX_TRAPD( err, DoSaveL() );
       
  3801                 if ( KErrNone != err )
       
  3802                     {
       
  3803                     HandleSaveComplete( err );
       
  3804                     }
       
  3805                 }
       
  3806             else
       
  3807                 {
       
  3808                 if ( aCommand == EMPXCmdSaveAndExit )
       
  3809                     {
       
  3810                     RunAppShutter();
       
  3811                     }
       
  3812                 else
       
  3813                     {
       
  3814                     // EMPXCmdSaveAndExitHostApp
       
  3815                     CAknEnv::RunAppShutter();
       
  3816                     }
       
  3817                 }
       
  3818             CleanupStack::PopAndDestroy( string );
       
  3819             break;
       
  3820             }
       
  3821         case EAknCmdTaskSwapper:
       
  3822             {
       
  3823             // Handle command when Music Player is selected in Multitasker
       
  3824             // and Music Player is the foreground app.
       
  3825             break;
       
  3826             }
       
  3827 
       
  3828         case EMPXCmdGotoCollection:
       
  3829             {
       
  3830 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3831             iPdPbvStartedByBrowser = EFalse;
       
  3832             icollectionBrowsed = ETrue;
       
  3833 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3834             iStandAlone = EFalse;
       
  3835 
       
  3836             break;
       
  3837             }
       
  3838 
       
  3839         default:
       
  3840             {
       
  3841             // do nothing if the command is not reconized
       
  3842             MPX_DEBUG2( "CMPXAppUi::HandleCommandL unknown command 0x%x", aCommand );
       
  3843             break;
       
  3844             }
       
  3845         }
       
  3846     }
       
  3847 
       
  3848 
       
  3849 // ---------------------------------------------------------------------------
       
  3850 // From CEikAppUi.
       
  3851 // Handle window server events.
       
  3852 // ---------------------------------------------------------------------------
       
  3853 //
       
  3854 void CMPXAppUi::HandleWsEventL(
       
  3855     const TWsEvent& aEvent,
       
  3856     CCoeControl* aDestination )
       
  3857     {
       
  3858     MPX_FUNC_EX( "CMPXAppUi::HandleWsEventL" );
       
  3859     if ( aEvent.Type() == KAknUidValueEndKeyCloseEvent )
       
  3860         {
       
  3861 		TMPXPlaybackState playerState( EPbStateNotInitialised );
       
  3862 		if( iPlaybackUtility )
       
  3863 			{
       
  3864 			TRAP_IGNORE( playerState = iPlaybackUtility->StateL() );
       
  3865 			}
       
  3866 
       
  3867         if ( ( iCommonUiHelper->ExitOptionHiddenL() && !IsEmbedded() ) ||
       
  3868 			EPbStatePlaying == playerState ||
       
  3869 			EPbStatePaused == playerState )
       
  3870             {
       
  3871             // Go back to Idle when End key is pressed in non-embedded mode or
       
  3872             // player is in playing/paused mode
       
  3873             if( IsForeground() )
       
  3874                 {
       
  3875                 ActivatePhoneAppL();
       
  3876                 }
       
  3877             return;
       
  3878             }
       
  3879         }
       
  3880 
       
  3881     // Notify the playback popup that orientation is about to change
       
  3882     if( iMediaKeyHandler && aEvent.Type() == EEventScreenDeviceChanged )
       
  3883         {
       
  3884         iMediaKeyHandler->NotifyOrientationChangeBegin();
       
  3885         }
       
  3886 
       
  3887     CAknAppUi::HandleWsEventL( aEvent, aDestination );
       
  3888     }
       
  3889 
       
  3890 // ---------------------------------------------------------------------------
       
  3891 // From MCoeMessageObserver.
       
  3892 // Handle messages from windows server.
       
  3893 // ---------------------------------------------------------------------------
       
  3894 //
       
  3895 MCoeMessageObserver::TMessageResponse CMPXAppUi::HandleMessageL(
       
  3896     TUint32 aClientHandleOfTargetWindowGroup,
       
  3897     TUid aMessageUid,
       
  3898     const TDesC8& aMessageParameters )
       
  3899     {
       
  3900     MPX_FUNC_EX( "CMPXAppUi::HandleMessageL" );
       
  3901 
       
  3902     MCoeMessageObserver::TMessageResponse ret( EMessageNotHandled );
       
  3903 
       
  3904     if ( aMessageUid == KAppUidMusicPlayerX )
       
  3905         {
       
  3906         MPX_DEBUG2( "CMPXAppUi::HandleMessageL Message received for music player, size = %d", aMessageParameters.Size() );
       
  3907         // message for music player
       
  3908         HandleCommandParametersL( aMessageParameters );
       
  3909         ret = EMessageHandled;
       
  3910         }
       
  3911 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3912     else if ( aMessageUid == KNullUid )
       
  3913         {
       
  3914         ASSERT(!IsEmbedded());////browser should not send messages to music player if it is not RootApp.
       
  3915         if ( aMessageParameters.Length() )
       
  3916             {
       
  3917             if ( IsBrowserClosed(aMessageParameters) )
       
  3918                 {
       
  3919                 if ( iAppStartedByBrowser )
       
  3920                     {
       
  3921                     RunAppShutter();
       
  3922                     return EMessageHandled;
       
  3923                     }
       
  3924                 }
       
  3925             else
       
  3926                 {
       
  3927                 if (!iPdParameterHandler)
       
  3928                     {
       
  3929                     iPdParameterHandler = CMPXPdCommandHandler::NewL(iPlaybackUtility);
       
  3930                     }
       
  3931                 if(KErrNotFound == iPdParameterHandler->HandleCommandParametersL( aMessageParameters )) // File or dl id do not exist.
       
  3932                     {
       
  3933                     iCommonUiHelper->DisplayInfoNoteL(R_MPX_FILE_NOT_FOUND_TEXT);
       
  3934                     HandleCommandL(EMPXCmdGoToNowPlaying);
       
  3935                     BringUpBrowserL();
       
  3936                     }
       
  3937                 else
       
  3938                     {
       
  3939                     iPbvStartedByBrowser = ETrue;
       
  3940                     }
       
  3941                 ret = EMessageHandled;
       
  3942                 }
       
  3943             }
       
  3944         }
       
  3945 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3946     else
       
  3947         {
       
  3948         ret = CAknViewAppUi::HandleMessageL(
       
  3949             aClientHandleOfTargetWindowGroup,
       
  3950             aMessageUid,
       
  3951             aMessageParameters );
       
  3952         }
       
  3953     return ret;
       
  3954     }
       
  3955 
       
  3956 // -----------------------------------------------------------------------------
       
  3957 // From CEikAppUi.
       
  3958 // process message sent by another application
       
  3959 // -----------------------------------------------------------------------------
       
  3960 //
       
  3961 void CMPXAppUi::ProcessMessageL(
       
  3962         TUid aUid, const TDesC8& aParams )
       
  3963     {
       
  3964     MPX_FUNC_EX( "CMPXAppUi::ProcessMessageL" );
       
  3965     if ( aUid == KAppUidMusicPlayerX )
       
  3966         {
       
  3967         // message for music player
       
  3968         MPX_DEBUG2( "CMPXAppUi::ProcessMessageL Message received for music player, size = %d", aParams.Size() );
       
  3969         HandleCommandParametersL( aParams );
       
  3970         }
       
  3971     }
       
  3972 
       
  3973 // -----------------------------------------------------------------------------
       
  3974 // From CEikAppUi.
       
  3975 // process command line parameter
       
  3976 // -----------------------------------------------------------------------------
       
  3977 //
       
  3978 TBool CMPXAppUi::ProcessCommandParametersL( CApaCommandLine& aCommandLine )
       
  3979     {
       
  3980     MPX_FUNC_EX( "CMPXAppUi::ProcessCommandParametersL CApaCommandLine" );
       
  3981 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  3982     if (EApaCommandOpen == aCommandLine.Command())
       
  3983         {
       
  3984         TPtrC param = aCommandLine.DocumentName();
       
  3985         if ( param.Length() )
       
  3986             {
       
  3987             if (!ConeUtils::FileExists(param))
       
  3988                 {
       
  3989                 iAppStartedByBrowser = ETrue;
       
  3990                 iPdPbvStartedByBrowser = ETrue;
       
  3991                 // Convert param to 8-bit.
       
  3992                 HBufC8* param8 = HBufC8::NewLC( param.Length() );
       
  3993                 param8->Des().Copy( param );
       
  3994                 if ( IsBrowserClosed(*param8) )
       
  3995                     {
       
  3996                     Exit();
       
  3997                     }
       
  3998                 else
       
  3999                     {
       
  4000                     if (!iPdParameterHandler)
       
  4001                         {
       
  4002                         iPdParameterHandler = CMPXPdCommandHandler::NewL(iPlaybackUtility);//this is where it is created the first time
       
  4003                         }
       
  4004                     if ( KErrNotFound == iPdParameterHandler->HandleCommandParametersL( *param8 ) )
       
  4005                         {
       
  4006                         delete iPdParameterHandler;
       
  4007                         iPdParameterHandler = NULL;
       
  4008                         iCommonUiHelper->DisplayInfoNoteL(R_MPX_FILE_NOT_FOUND_TEXT);
       
  4009                         BringUpBrowserL();
       
  4010                         Exit();
       
  4011                         }
       
  4012                     else
       
  4013                         {
       
  4014                         // Default start up state for Progressive Download playback is Playing
       
  4015                         MPXTlsHelper::SetLaunchModeL( EMPXLaunchModePlaying );
       
  4016                         }
       
  4017                     }
       
  4018                 CleanupStack::PopAndDestroy( param8 );
       
  4019                 }
       
  4020             }
       
  4021         }
       
  4022 #endif  // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  4023     const TPtrC8 command = aCommandLine.TailEnd();
       
  4024         if ( command.Size() > 0 )
       
  4025         {
       
  4026         HandleCommandParametersL( command );
       
  4027         }
       
  4028     return ETrue;
       
  4029     }
       
  4030 
       
  4031 // ---------------------------------------------------------------------------
       
  4032 // From MMPXSaveHelperObserver
       
  4033 // Callback function to signal that saving a file is complete
       
  4034 // ---------------------------------------------------------------------------
       
  4035 //
       
  4036 void CMPXAppUi::HandleSaveComplete( TInt aErr )
       
  4037     {
       
  4038     MPX_DEBUG2("CMPXAppUi::HandleSaveComplete(%d) entering", aErr);
       
  4039     TRAP_IGNORE( DoHandleSaveCompleteL( aErr ) );
       
  4040     MPX_DEBUG1("CMPXAppUi::HandleSaveComplete() exiting" );
       
  4041     }
       
  4042 
       
  4043 // ---------------------------------------------------------------------------
       
  4044 // From MMPXCollectionHelperObserver
       
  4045 // Callback function to signal that adding a file is complete
       
  4046 // ---------------------------------------------------------------------------
       
  4047 //
       
  4048 void CMPXAppUi::HandleAddFileCompleteL( TInt aErr )
       
  4049     {
       
  4050     MPX_DEBUG2("CMPXAppUi::HandleAddFileCompleteL(%d) entering", aErr);
       
  4051 
       
  4052     iCommonUiHelper->DismissWaitNoteL();
       
  4053 
       
  4054     // close collectionhelper since it is not needed now
       
  4055     if ( iCollectionHelper )
       
  4056         {
       
  4057         iCollectionHelper->Close();
       
  4058         iCollectionHelper = NULL;
       
  4059         }
       
  4060 
       
  4061     if ( !aErr )
       
  4062         {
       
  4063         if (( iSaveMode != EMPXAssignRingtone ) &&
       
  4064             ( iSaveMode != EMPXAssignContact ))
       
  4065             {
       
  4066             iCommonUiHelper->DisplayConfirmNoteL( R_MPX_SAVED_TO_COLLECTION_NOTE );
       
  4067             }
       
  4068         }
       
  4069     else if ( KErrNotSupported == aErr )
       
  4070         {
       
  4071         iCommonUiHelper->DisplayConfirmNoteL( R_MPX_SAVED_NOTE );
       
  4072         }
       
  4073     else if( iIsUsbOnGoing && (aErr != KErrNone) )
       
  4074         {
       
  4075         // Kill mpx embedded mode so usb can start
       
  4076         //
       
  4077         MPX_DEBUG1("CMPXAppUi::HandleAddFileCompleteL usb ongoing");
       
  4078         iSaveMode = EMPXExitAppAfterSave;
       
  4079         }
       
  4080     else
       
  4081         {
       
  4082         iCommonUiHelper->HandleErrorL( aErr );
       
  4083         }
       
  4084 
       
  4085     if ( iView )
       
  4086         {
       
  4087         iView->HandleCommandL( EMPXCmdSaveComplete );
       
  4088         }
       
  4089 
       
  4090     HandlePostSaveOperationL();
       
  4091 
       
  4092     MPX_DEBUG1("CMPXAppUi::HandleAddFileCompleteL() exiting" );
       
  4093     }
       
  4094 
       
  4095 // ---------------------------------------------------------------------------
       
  4096 // From MProgressDialogCallback.
       
  4097 // Get's called when a dialog is dismissed.
       
  4098 // ---------------------------------------------------------------------------
       
  4099 //
       
  4100 void CMPXAppUi::DialogDismissedL( TInt aButtonId )
       
  4101     {
       
  4102     MPX_DEBUG1("CMPXAppUi::DialogDismissedL");
       
  4103 
       
  4104 // Cover UI start
       
  4105 //#ifdef __COVER_DISPLAY
       
  4106     if ( iCommandInitiator )
       
  4107         {
       
  4108         iCommandInitiator->CancelCommand( KMediatorSecondaryDisplayDomain,
       
  4109                                     KMPlayerNoteCategory,
       
  4110                                     EMPlayerNoteSaveOneItem );
       
  4111         }
       
  4112 //#endif
       
  4113 // Cover UI end
       
  4114 
       
  4115     if ( aButtonId == EAknSoftkeyCancel && iView )
       
  4116         {
       
  4117         iView->HandleCommandL( EMPXCmdSaveCancelled );
       
  4118         if ( iSaveMode != EMPXSaveModeIdle )
       
  4119             {
       
  4120             iCancelFileMan = ETrue;
       
  4121             if( iSaveHelper )
       
  4122                 {
       
  4123                 iSaveHelper->Cancel();
       
  4124                 }
       
  4125             iSaveMode = EMPXSaveModeIdle;
       
  4126             }
       
  4127         }
       
  4128     MPX_DEBUG1("CMPXAppUi::DialogDismissedL");
       
  4129     }
       
  4130 
       
  4131 // -----------------------------------------------------------------------------
       
  4132 // CMPXAppUi::NotifyFileManOperation
       
  4133 // -----------------------------------------------------------------------------
       
  4134 //
       
  4135 MFileManObserver::TControl CMPXAppUi::NotifyFileManOperation()
       
  4136     {
       
  4137     MPX_DEBUG1("CMPXAppUi::NotifyFileManOperation(): entering");
       
  4138     // this code is run in CFileMan working thread.
       
  4139     if( iCancelFileMan )
       
  4140         {
       
  4141         MPX_DEBUG1("CMPXAppUi::NotifyFileManOperation(): ECancel");
       
  4142         return MFileManObserver::ECancel;
       
  4143         }
       
  4144     return MFileManObserver::EContinue;
       
  4145     }
       
  4146 
       
  4147 // -----------------------------------------------------------------------------
       
  4148 // CMPXAppUi::DoUpdatePluginRefreshedTimeL
       
  4149 // -----------------------------------------------------------------------------
       
  4150 //
       
  4151 void CMPXAppUi::DoUpdatePluginRefreshedTimeL()
       
  4152     {
       
  4153     CMPXCommand* cmd = CMPXCommand::NewL();
       
  4154     CleanupStack::PushL( cmd );
       
  4155     cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdUpdateRefreshTime );
       
  4156     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue );
       
  4157 
       
  4158     // Update Music
       
  4159     cmd->SetTObjectValueL<TUid>( KMPXCommandGeneralCollectionId, iMusicCollectionId );
       
  4160     iCollectionUtility->Collection().CommandL( *cmd );
       
  4161 
       
  4162     // Update Podcast
       
  4163     if( !iDisablePodcasting )
       
  4164         {
       
  4165         cmd->SetTObjectValueL<TUid>( KMPXCommandGeneralCollectionId, iPodcastCollectionId );
       
  4166         iCollectionUtility->Collection().CommandL( *cmd );
       
  4167         }
       
  4168     CleanupStack::PopAndDestroy( cmd );
       
  4169     }
       
  4170 
       
  4171 // -----------------------------------------------------------------------------
       
  4172 // CMPXAppUi::HandlePropertyL
       
  4173 // -----------------------------------------------------------------------------
       
  4174 //
       
  4175 void CMPXAppUi::HandlePropertyL(TMPXPlaybackProperty aProperty, TInt aValue, TInt aError)
       
  4176     {
       
  4177     if (aError == KErrNone)
       
  4178         {
       
  4179         switch (aProperty)
       
  4180             {
       
  4181         case EPbPropertyVolume:
       
  4182             {
       
  4183             iCurrentVolume = aValue;
       
  4184             }
       
  4185             break;
       
  4186 
       
  4187         case EPbPropertyMaxVolume:
       
  4188             {
       
  4189             iMaxVolume = aValue;
       
  4190             }
       
  4191             break;
       
  4192 
       
  4193         default:
       
  4194             break;
       
  4195             }
       
  4196         }
       
  4197     else
       
  4198         {
       
  4199         // How to handle error?
       
  4200         }
       
  4201     }
       
  4202 
       
  4203 
       
  4204 // -----------------------------------------------------------------------------
       
  4205 // CMPXAppUi::HandleSubPlayerNamesL
       
  4206 // -----------------------------------------------------------------------------
       
  4207 //
       
  4208 void CMPXAppUi::HandleSubPlayerNamesL(
       
  4209     TUid /*aPlayer*/,
       
  4210     const MDesCArray* /*aSubPlayers*/,
       
  4211     TBool /*aComplete*/,
       
  4212     TInt /*aError*/)
       
  4213     {
       
  4214 
       
  4215     }
       
  4216 
       
  4217 // -----------------------------------------------------------------------------
       
  4218 // CMPXAppUi::HandleMediaL
       
  4219 // -----------------------------------------------------------------------------
       
  4220 //
       
  4221 void CMPXAppUi::HandleMediaL(
       
  4222     const CMPXMedia& /*aProperties*/,
       
  4223     TInt /*aError*/)
       
  4224     {
       
  4225 
       
  4226     }
       
  4227 // -----------------------------------------------------------------------------
       
  4228 // CMPXAppUi::IsActiveView
       
  4229 // -----------------------------------------------------------------------------
       
  4230 //
       
  4231 TBool CMPXAppUi::IsActiveView(TInt aViewType )
       
  4232     {
       
  4233     return (iCurrentViewType.iUid == aViewType ) || ((iCurrentViewType.iUid == KMPXPluginTypeWaitNoteDialogUid ) && (iPreviousViewType.iUid == aViewType));
       
  4234     }
       
  4235 
       
  4236 // -----------------------------------------------------------------------------
       
  4237 // CMPXAppUi::ReOpenPathL
       
  4238 // -----------------------------------------------------------------------------
       
  4239 //
       
  4240 void CMPXAppUi::ReOpenPathL()
       
  4241     {
       
  4242     CMPXCollectionPath* path = iCollectionUtility->Collection().PathL ( );
       
  4243     CleanupStack::PushL ( path );
       
  4244     if ( path->Levels ( )> 1 )
       
  4245         {
       
  4246         path->Back ( );
       
  4247         iCollectionUtility->Collection().OpenL ( *path );
       
  4248         }
       
  4249     CleanupStack::PopAndDestroy ( path );
       
  4250     }
       
  4251 
       
  4252 // -----------------------------------------------------------------------------
       
  4253 // CMPXAppUi::HandleServerAppExit
       
  4254 // -----------------------------------------------------------------------------
       
  4255 //
       
  4256 void CMPXAppUi::HandleServerAppExit(TInt /*aReason*/)
       
  4257     {
       
  4258         RunAppShutter();
       
  4259     }
       
  4260 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  4261 // -----------------------------------------------------------------------------
       
  4262 // CMPXAppUi::IsBrowserClosed
       
  4263 // -----------------------------------------------------------------------------
       
  4264 //
       
  4265 TBool CMPXAppUi::IsBrowserClosed(
       
  4266     const TDesC8& aParams )
       
  4267     {
       
  4268     TBool ret(EFalse);
       
  4269     CBufFlat* paramBuf = CBufFlat::NewL( /*anExpandSize*/1 );
       
  4270     CleanupStack::PushL( paramBuf );
       
  4271     paramBuf->InsertL( 0, aParams );
       
  4272     RBufReadStream readStream( *paramBuf );
       
  4273 
       
  4274     CAiwGenericParamList* genParList = CAiwGenericParamList::NewLC( readStream );
       
  4275 
       
  4276     TInt index = 0;
       
  4277     const TAiwGenericParam* paramTerminate = genParList->FindFirst( index,
       
  4278         EGenericParamTerminate, EVariantTypeTInt32 );
       
  4279     TInt32 terminateID = 0;
       
  4280     if ( paramTerminate )
       
  4281         {
       
  4282         paramTerminate->Value().Get( terminateID );
       
  4283         }
       
  4284 
       
  4285     if ( terminateID )
       
  4286         {
       
  4287         ret = ETrue;
       
  4288         }
       
  4289 
       
  4290     CleanupStack::PopAndDestroy( genParList );
       
  4291     CleanupStack::PopAndDestroy( paramBuf );
       
  4292 
       
  4293     return ret;
       
  4294     }
       
  4295 
       
  4296 // ---------------------------------------------------------
       
  4297 // Bring Browser application to the foreground.
       
  4298 // ---------------------------------------------------------
       
  4299 //
       
  4300 TBool CMPXAppUi::BringUpBrowserL()
       
  4301     {
       
  4302     TBool browserFound(EFalse);
       
  4303     RWsSession& wsSession=iEikonEnv->WsSession();
       
  4304     CAknTaskList* taskList = CAknTaskList::NewL( wsSession );
       
  4305     TApaTask task = taskList->FindRootApp( TUid::Uid(KMPXBrowserUid) );
       
  4306     delete taskList;
       
  4307     if( task.Exists() )
       
  4308         {
       
  4309         task.BringToForeground();
       
  4310         browserFound = ETrue;
       
  4311         }
       
  4312     return browserFound;
       
  4313     }
       
  4314 
       
  4315 #endif // RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  4316 
       
  4317 // -----------------------------------------------------------------------------
       
  4318 // CMPXAppUi::SuppressCollectionView
       
  4319 // -----------------------------------------------------------------------------
       
  4320 //
       
  4321 TBool CMPXAppUi::SuppressCollectionView()
       
  4322     {
       
  4323 #ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
  4324             return ( iPdPbvStartedByBrowser || iStandAlone );
       
  4325 #else
       
  4326             return ( iStandAlone );
       
  4327 #endif
       
  4328     }
       
  4329 
       
  4330 // -----------------------------------------------------------------------------
       
  4331 // CMPXAppUi::SetVolume
       
  4332 // -----------------------------------------------------------------------------
       
  4333 //
       
  4334 void CMPXAppUi::SetVolume( const TInt aVolume )
       
  4335     {
       
  4336     CMPXCommand* cmd( CMPXCommand::NewL() );
       
  4337     CleanupStack::PushL( cmd );
       
  4338     cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXCommandIdPlaybackGeneral );
       
  4339     cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  4340     cmd->SetTObjectValueL<TBool>( KMPXCommandPlaybackGeneralNoBuffer, ETrue );
       
  4341     cmd->SetTObjectValueL<TInt>( KMPXCommandPlaybackGeneralType, EPbCmdSetVolume );
       
  4342     cmd->SetTObjectValueL<TUint>( KMPXCommandPlaybackGeneralData, aVolume );
       
  4343     iPlaybackUtility->CommandL( *cmd );
       
  4344     CleanupStack::PopAndDestroy( cmd );
       
  4345     }
       
  4346 
       
  4347 // -----------------------------------------------------------------------------
       
  4348 // CMPXAppUi::MuteVolume
       
  4349 // -----------------------------------------------------------------------------
       
  4350 //
       
  4351 void CMPXAppUi::MuteVolume()
       
  4352     {
       
  4353     CMPXCommand* cmd( CMPXCommand::NewL() );
       
  4354     CleanupStack::PushL( cmd );
       
  4355     cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXCommandIdPlaybackGeneral );
       
  4356     cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  4357     cmd->SetTObjectValueL<TBool>( KMPXCommandPlaybackGeneralNoBuffer, ETrue );
       
  4358     cmd->SetTObjectValueL<TInt>( KMPXCommandPlaybackGeneralType, EPbCmdMuteVolume );
       
  4359     iPlaybackUtility->CommandL( *cmd );
       
  4360     CleanupStack::PopAndDestroy( cmd );
       
  4361     }
       
  4362 
       
  4363 // -----------------------------------------------------------------------------
       
  4364 // CMPXAppUi::UnMuteVolume
       
  4365 // -----------------------------------------------------------------------------
       
  4366 //
       
  4367 void CMPXAppUi::UnMuteVolume()
       
  4368     {
       
  4369     CMPXCommand* cmd( CMPXCommand::NewL() );
       
  4370     CleanupStack::PushL( cmd );
       
  4371     cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXCommandIdPlaybackGeneral );
       
  4372     cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  4373     cmd->SetTObjectValueL<TBool>( KMPXCommandPlaybackGeneralNoBuffer, ETrue );
       
  4374     cmd->SetTObjectValueL<TInt>( KMPXCommandPlaybackGeneralType, EPbCmdUnMuteVolume );
       
  4375     iPlaybackUtility->CommandL( *cmd );
       
  4376     CleanupStack::PopAndDestroy( cmd );
       
  4377     }
       
  4378 
       
  4379 // -----------------------------------------------------------------------------
       
  4380 // CMPXAppUi::UnMuteVolume
       
  4381 // -----------------------------------------------------------------------------
       
  4382 //
       
  4383 TInt CMPXAppUi::MPXCmdForPbCmd(
       
  4384     TMPXPlaybackCommand aCommand )
       
  4385     {
       
  4386     TInt cmd( KErrNotFound );
       
  4387 
       
  4388     switch ( aCommand )
       
  4389         {
       
  4390         case EPbCmdStop:
       
  4391             {
       
  4392             cmd = EMPXCmdStop;
       
  4393             break;
       
  4394             }
       
  4395         case EPbCmdPlay:
       
  4396             {
       
  4397             cmd = EMPXCmdPlay;
       
  4398             break;
       
  4399             }
       
  4400         case EPbCmdPause:
       
  4401             {
       
  4402             cmd = EMPXCmdPause;
       
  4403             break;
       
  4404             }
       
  4405         case EPbCmdPlayPause:
       
  4406             {
       
  4407             cmd = EMPXCmdPlayPause;
       
  4408             break;
       
  4409             }
       
  4410         case EPbCmdNext:
       
  4411             {
       
  4412             cmd = EMPXCmdNext;
       
  4413             break;
       
  4414             }
       
  4415         case EPbCmdPrevious:
       
  4416             {
       
  4417             cmd = EMPXCmdPrevious;
       
  4418             break;
       
  4419             }
       
  4420         case EPbCmdStartSeekForward:
       
  4421             {
       
  4422             cmd = EMPXCmdSeekForward;
       
  4423             break;
       
  4424             }
       
  4425         case EPbCmdStartSeekBackward:
       
  4426             {
       
  4427             cmd = EMPXCmdSeekBackward;
       
  4428             break;
       
  4429             }
       
  4430         case EPbCmdStopSeeking:
       
  4431             {
       
  4432             cmd = EMPXCmdStopSeeking;
       
  4433             break;
       
  4434             }
       
  4435         default:
       
  4436             {
       
  4437             // Command not found
       
  4438             break;
       
  4439             }
       
  4440         }
       
  4441     return cmd;
       
  4442     }
       
  4443 
       
  4444 // -----------------------------------------------------------------------------
       
  4445 // CMPXAppUi::CheckAvailableMemory
       
  4446 // -----------------------------------------------------------------------------
       
  4447 //
       
  4448 void CMPXAppUi::CheckAvailableMemory( TInt aNeedMemory )
       
  4449     {
       
  4450     TMemoryInfoV1Buf info;
       
  4451     UserHal::MemoryInfo(info);
       
  4452     if( info().iFreeRamInBytes < aNeedMemory )
       
  4453         {
       
  4454         HBufC* title =
       
  4455             StringLoader::LoadLC( R_MPX_NO_MEMORY_INFO );
       
  4456         CAknGlobalNote* infoNote = CAknGlobalNote::NewLC();
       
  4457         infoNote->ShowNoteL(
       
  4458             EAknGlobalInformationNote,
       
  4459             title->Des() );
       
  4460         CleanupStack::PopAndDestroy( infoNote );
       
  4461         CleanupStack::PopAndDestroy( title );
       
  4462         Exit();
       
  4463         return;
       
  4464         }
       
  4465     }
       
  4466 
       
  4467 
       
  4468 // -----------------------------------------------------------------------------
       
  4469 // CMPXAppUi::CheckUpdatesComplete
       
  4470 // from base class MIAUpdateObserver
       
  4471 // -----------------------------------------------------------------------------
       
  4472 //
       
  4473 void CMPXAppUi::CheckUpdatesComplete( TInt aErrorCode, TInt aAvailableUpdates )
       
  4474     {
       
  4475     MPX_DEBUG2("CMPXAppUi::CheckUpdatesComplete(UpdatesComplete: %d) entering", aErrorCode);
       
  4476     if ( aErrorCode == KErrNone )
       
  4477         {
       
  4478             MPX_DEBUG2("CMPXAppUi::CheckUpdatesComplete(AvailableUpdates: %d)", aAvailableUpdates);
       
  4479             if ( aAvailableUpdates > 0 )
       
  4480                 {
       
  4481                 // There were some updates available. Let's ask if the user wants to update them.
       
  4482                 iUpdate->UpdateQuery();
       
  4483                 }
       
  4484             else
       
  4485                 {
       
  4486                 // No updates available. CIAUpdate object could be deleted
       
  4487                 CleanUpdateParams();
       
  4488                 }
       
  4489         }
       
  4490         MPX_DEBUG1( "CMPXAppUi::CheckUpdatesComplete() exiting" );
       
  4491     }
       
  4492 
       
  4493 // -----------------------------------------------------------------------------
       
  4494 // CMPXAppUi::UpdateComplete
       
  4495 // from base class MIAUpdateObserver
       
  4496 // -----------------------------------------------------------------------------
       
  4497 //
       
  4498 void CMPXAppUi::UpdateComplete( TInt /*aErrorCode*/, CIAUpdateResult* aResultDetails )
       
  4499     {
       
  4500     MPX_DEBUG1( "CMPXAppUi::UpdateComplete() entering" );
       
  4501     // The update process that the user started from IAUpdate UI is now completed.
       
  4502     if(aResultDetails)
       
  4503         {
       
  4504         delete aResultDetails; // Ownership was transferred, so this must be deleted by the client
       
  4505         aResultDetails = NULL;
       
  4506         }
       
  4507 
       
  4508     // We do not need the client-server session anymore, let's delete the object to close the session
       
  4509     CleanUpdateParams();
       
  4510     MPX_DEBUG1( "CMPXAppUi::UpdateComplete() exiting" );
       
  4511     }
       
  4512 
       
  4513 // -----------------------------------------------------------------------------
       
  4514 // CMPXAppUi::UpdateQueryComplete
       
  4515 // from base class MIAUpdateObserver
       
  4516 // -----------------------------------------------------------------------------
       
  4517 //
       
  4518 void CMPXAppUi::UpdateQueryComplete( TInt aErrorCode, TBool aUpdateNow )
       
  4519     {
       
  4520     MPX_DEBUG2("CMPXAppUi::UpdateQueryComplete(QueryComplete: %d) entering", aErrorCode);
       
  4521     if ( aErrorCode == KErrNone )
       
  4522         {
       
  4523         MPX_DEBUG2("CMPXAppUi::UpdateQueryComplete(UpdateNow: %d) ", aUpdateNow);
       
  4524         if ( aUpdateNow )
       
  4525             {
       
  4526             // User choosed to update now, so let's launch the IAUpdate UI.
       
  4527             iUpdate->ShowUpdates( *iParameters );
       
  4528             }
       
  4529         else
       
  4530             {
       
  4531             // The answer was 'Later'. CIAUpdate object could be deleted
       
  4532             CleanUpdateParams();
       
  4533             }
       
  4534          }
       
  4535     MPX_DEBUG1( "CMPXAppUi::UpdateQueryComplete() exiting" );
       
  4536     }
       
  4537 
       
  4538 // -----------------------------------------------------------------------------
       
  4539 // CMPXAppUi::UpdateQueryComplete
       
  4540 // -----------------------------------------------------------------------------
       
  4541 //
       
  4542 void CMPXAppUi::CleanUpdateParams()
       
  4543     {
       
  4544     MPX_DEBUG1( "CMPXAppUi::CleanUpdateParams() entering" );
       
  4545     if(iUpdate)
       
  4546         {
       
  4547         delete iUpdate;
       
  4548         iUpdate = NULL;
       
  4549         }
       
  4550     if(iParameters)
       
  4551         {
       
  4552         delete iParameters;
       
  4553         iParameters = NULL;
       
  4554         }
       
  4555     MPX_DEBUG1( "CMPXAppUi::CleanUpdateParams() exiting" );
       
  4556     }
       
  4557 
       
  4558 // -----------------------------------------------------------------------------
       
  4559 // CMPXAppUi::CheckUpdatesL
       
  4560 // -----------------------------------------------------------------------------
       
  4561 //
       
  4562 void CMPXAppUi::CheckUpdatesL()
       
  4563     {
       
  4564     MPX_DEBUG1( "CMPXAppUi::CheckUpdatesL() entering" );
       
  4565     if ( FeatureManager::FeatureSupported( KFeatureIdIAUpdate ) )
       
  4566         {
       
  4567         MPX_DEBUG1( "CMPXAppUi::CheckUpdatesL() IAD Update supported" );
       
  4568 
       
  4569         TRAP_IGNORE( iUpdate = CIAUpdate::NewL( *this ) );
       
  4570 
       
  4571         MPX_DEBUG1( "CMPXAppUi::CheckUpdatesL() IAD Update Client Created" );
       
  4572 
       
  4573         if ( iUpdate )
       
  4574             {
       
  4575             MPX_DEBUG1( "CMPXAppUi::CheckUpdatesL() creating IAD Update paramentes" );
       
  4576             iParameters = CIAUpdateParameters::NewL();
       
  4577 
       
  4578             // Search for updates using SIS package UID
       
  4579             iParameters->SetUid( TUid::Uid( KMPXMusicPlayerSISPkgUid ) );
       
  4580 
       
  4581             //mpx.exe to be started after update is finished
       
  4582             iParameters->SetCommandLineExecutableL( KMPXMusicPlayerExec );
       
  4583 
       
  4584             //check the updates
       
  4585             iUpdate->CheckUpdates( *iParameters );
       
  4586             }
       
  4587         }
       
  4588     MPX_DEBUG1( "CMPXAppUi::CheckUpdatesL() exiting" );
       
  4589     }
       
  4590 
       
  4591 #ifdef FF_OOM_MONITOR2_COMPONENT
       
  4592 // -----------------------------------------------------------------------------
       
  4593 // CMPXAppUi::SetMpxOomPriorityL
       
  4594 // -----------------------------------------------------------------------------
       
  4595 //
       
  4596 void CMPXAppUi::SetMpxOomPriorityL( ROomMonitorSession::TOomPriority aPriority )
       
  4597     {
       
  4598     if( aPriority != iOomPriority )
       
  4599         {
       
  4600         ROomMonitorSession monitorSession;
       
  4601         User::LeaveIfError ( monitorSession.Connect() );
       
  4602         // No leaving code after this point, so no need to use cleanup stack
       
  4603         monitorSession.SetOomPriority( aPriority );
       
  4604         iOomPriority = aPriority;
       
  4605         monitorSession.Close(); // CLOSE THE OOM SESSION....
       
  4606         }
       
  4607     }
       
  4608 
       
  4609 // -----------------------------------------------------------------------------
       
  4610 // CMPXAppUi::CheckAvailableMemoryByOomL
       
  4611 // -----------------------------------------------------------------------------
       
  4612 //
       
  4613 void  CMPXAppUi::CheckAvailableMemoryByOomL( TInt aNeedMemory )
       
  4614     {
       
  4615     ROomMonitorSession oomMonitor;
       
  4616     User::LeaveIfError( oomMonitor.Connect() );
       
  4617     // No leaving code after this point, so no need to use cleanup stack
       
  4618     TInt errorCode = oomMonitor.RequestFreeMemory( aNeedMemory );
       
  4619     oomMonitor.Close();
       
  4620 
       
  4621     if ( errorCode != KErrNone )
       
  4622         {
       
  4623         // NOT ENOUGH MEMORY ....Show Information note and exit out..
       
  4624         HBufC* title = StringLoader::LoadLC( R_MPX_NO_MEMORY_INFO );
       
  4625         CAknGlobalNote* infoNote = CAknGlobalNote::NewLC();
       
  4626         infoNote->ShowNoteL(
       
  4627             EAknGlobalInformationNote,
       
  4628             title->Des() );
       
  4629         CleanupStack::PopAndDestroy( infoNote );
       
  4630         CleanupStack::PopAndDestroy( title );
       
  4631         Exit();
       
  4632         }
       
  4633     }
       
  4634 #endif // FF_OOM_MONITOR2_COMPONENT
       
  4635 
       
  4636 // End of File