mpxmusicplayer/app/src/mpxcommandhandler.cpp
changeset 0 ff3acec5bc43
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:  Handles commands passed in by other appilcations
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <bldvariant.hrh>
       
    21 #include <apgtask.h>
       
    22 #include <eikenv.h>
       
    23 #include <mpxcollectionmessage.h>
       
    24 #include <mpxcollectionutility.h>
       
    25 #include <mpxcollectionplaylist.h>
       
    26 #include <mpxcollectionpath.h>
       
    27 #include <mpxcollectionopenutility.h>
       
    28 #include <mpxplaybackutility.h>
       
    29 #include <mpxplaybackmessage.h>
       
    30 #include <mpxviewutility.h>
       
    31 #include <mpxmusicplayerviewplugin.hrh>
       
    32 #include <mpxmediacollectiondetaildefs.h>
       
    33 #include <mpxcollectionhelperfactory.h>
       
    34 #include <mpxcollectionuihelper.h>
       
    35 #include <mpxparameter.h>
       
    36 #include <mpxmessagegeneraldefs.h>
       
    37 #include <mpxplaybackmessagedefs.h>
       
    38 #include <mpxmediacontainerdefs.h>
       
    39 #include <mpxmediaarray.h>
       
    40 
       
    41 #include "mpxtlshelper.h"
       
    42 #include <mpxconstants.h>
       
    43 #include "mpxcommandhandler.h"
       
    44 #include "mpxlog.h"
       
    45 #include <mpxviewpluginmanager.h>
       
    46 #include <mpxviewplugin.h>
       
    47 
       
    48 const TInt KIncrementalFetchCount = 10; // all we need is the first song in all song
       
    49 const TInt KWaitNoteImpUid = 0x101FFC6C; // refresh wait note UID
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ==============================
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // Two-phased constructor.
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 CMPXCommandHandler* CMPXCommandHandler::NewL(
       
    58     MMPXPlaybackUtility* aPlaybackUtility,
       
    59     TUid aCollectionMode,
       
    60     const TDesC8& aParameter )
       
    61     {
       
    62     CMPXCommandHandler* self = NewLC(
       
    63         aPlaybackUtility, aCollectionMode, aParameter );
       
    64     CleanupStack::Pop(self);
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // Two-phased constructor.
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CMPXCommandHandler* CMPXCommandHandler::NewLC(
       
    73     MMPXPlaybackUtility* aPlaybackUtility,
       
    74     TUid aCollectionMode,
       
    75     const TDesC8& aParameter )
       
    76     {
       
    77     CMPXCommandHandler* self = new ( ELeave )
       
    78         CMPXCommandHandler( aPlaybackUtility );
       
    79     CleanupStack::PushL(self);
       
    80     self->ConstructL( aCollectionMode, aParameter );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // C++ constructor can NOT contain any code that might leave.
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CMPXCommandHandler::CMPXCommandHandler(
       
    89     MMPXPlaybackUtility* aPlaybackUtility ):
       
    90     iPlaybackUtility( aPlaybackUtility )
       
    91     ,iPathInited( EFalse )
       
    92     ,iLastPlayedAutostart(EFalse)
       
    93     {
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // Destructor.
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 CMPXCommandHandler::~CMPXCommandHandler()
       
   101     {
       
   102     if ( iPlaybackUtility )
       
   103         {
       
   104         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
       
   105         }
       
   106     if ( iMusicPlayerCollectionUtility )
       
   107         {
       
   108         iMusicPlayerCollectionUtility->Close();
       
   109         }
       
   110     if ( iViewUtility )
       
   111         {
       
   112         iViewUtility->Close();
       
   113         }
       
   114     delete iIsolatedIncOpenUtil;
       
   115     delete iParameter;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // Symbian 2nd phase constructor can leave.
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 void CMPXCommandHandler::ConstructL(
       
   123     TUid aCollectionMode,
       
   124     const TDesC8& aParameter )
       
   125     {
       
   126     iIsolatedIncOpenUtil =
       
   127         CMPXCollectionOpenUtility::NewL( this, KMcModeIsolated );
       
   128     iMusicPlayerCollectionUtility = MMPXCollectionUtility::NewL(
       
   129         this, aCollectionMode );
       
   130     iPlaybackUtility->AddObserverL( *this );
       
   131     iViewUtility = MMPXViewUtility::UtilityL();
       
   132     ExtractMessageL( aParameter );
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // Start processing the command
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CMPXCommandHandler::ProcessMessageL( TBool aIsUsbInUse, TBool aRefreshing, TBool aFormattingOnGoing )
       
   140     {
       
   141     MPX_FUNC( "CMPXCommandHandler::ProcessMessageL" );
       
   142     iPathInited = EFalse;
       
   143     iUsbInUse = aIsUsbInUse;
       
   144     iRefreshOngoing = aRefreshing;
       
   145     if ( iUsbInUse || iRefreshOngoing || aFormattingOnGoing )
       
   146         {
       
   147         MPX_DEBUG1( "CMPXCommandHandler::ProcessMessageL USB/Refresh/Formatting ongoing, bring app to foreground only" );
       
   148         // USB is in use, bring the app to foreground and ignore the message
       
   149         delete iParameter;
       
   150         iParameter = NULL;
       
   151         // have to use window group to activate, in case some other window
       
   152         // has higher priority than us (e.g. playback popup and volume popup)
       
   153         RWindowGroup myWin = CEikonEnv::Static()->RootWin();
       
   154         myWin.SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
   155         }
       
   156     else
       
   157         {
       
   158         if ( iParameter )
       
   159             {
       
   160             if ( CEikonEnv::Static()->StartedAsServerApp() )
       
   161                 {
       
   162                 // embedded mode, can't check if db exist
       
   163                 // just process the message
       
   164                 MPX_DEBUG1( "CMPXCommandHandler::ProcessMessageL embedded mode" );
       
   165                 DoHandleMessageL();
       
   166                 }
       
   167             else
       
   168                 {
       
   169                 // check if DB is created
       
   170                 MPX_DEBUG1( "CMPXCommandHandler::ProcessMessageL check if db is created" );
       
   171                 RArray<TMPXAttribute> atts;
       
   172                 CleanupClosePushL( atts );
       
   173                 atts.Append( KMPXMediaColDetailDBCreated );
       
   174                 if ( iParameter->iCollectionPath )
       
   175                     {
       
   176                     iMusicPlayerCollectionUtility->Collection().MediaL(
       
   177                         *iParameter->iCollectionPath, atts.Array() );
       
   178                     }
       
   179                 else
       
   180                     {
       
   181                     MMPXCollectionUiHelper* colUiHelper =
       
   182                         CMPXCollectionHelperFactory::NewCollectionUiHelperL();
       
   183                     CMPXCollectionPath* cpath = colUiHelper->MusicMenuPathL();
       
   184                     CleanupStack::PushL( cpath );
       
   185                     iMusicPlayerCollectionUtility->Collection().MediaL(
       
   186                         *cpath, atts.Array() );
       
   187                     colUiHelper->Close();
       
   188                     CleanupStack::PopAndDestroy( cpath );
       
   189                     }
       
   190                 CleanupStack::PopAndDestroy( &atts );
       
   191                 }
       
   192             }
       
   193         }
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // Returns if a path has been inited in playback engine
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 TBool CMPXCommandHandler::IsPathInited()
       
   201     {
       
   202     MPX_FUNC( "CMPXCommandHandler::IsPathInited" );
       
   203     return iPathInited;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // Set usb status
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CMPXCommandHandler::SetUsbInUse( TBool aIsUsbInUse )
       
   211     {
       
   212     MPX_FUNC( "CMPXCommandHandler::SetUsbInUse" );
       
   213     iUsbInUse = aIsUsbInUse;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // Set refresh status
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 void CMPXCommandHandler::SetRefreshState( TBool aRefreshing )
       
   221     {
       
   222     MPX_FUNC( "CMPXCommandHandler::aRefreshing" );
       
   223     iRefreshOngoing = aRefreshing;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // Determines if the command should be handled by standalone mode.
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 TBool CMPXCommandHandler::ForwardCmdToStandAloneMode()
       
   231     {
       
   232     MPX_FUNC( "CMPXCommandHandler::ForwardCmdToStandAloneMode" );
       
   233     TBool ret( EFalse );
       
   234     if ( iParameter )
       
   235         {
       
   236         ret = ( iParameter->iCmdForward == EMPXCmdFwdStandAlone );
       
   237         }
       
   238     return ret;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // Determines if the command should be handled by now playing instance
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 TBool CMPXCommandHandler::ForwardCmdToNowPlaying()
       
   246     {
       
   247     MPX_FUNC( "CMPXCommandHandler::ForwardCmdToNowPlaying" );
       
   248     TBool ret( EFalse );
       
   249     if ( iParameter )
       
   250         {
       
   251         ret = ( iParameter->iCmdForward == EMPXCmdFwdNowPlaying );
       
   252         }
       
   253     return ret;
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // Checks if initialize playback engine is needed for current command
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 TBool CMPXCommandHandler::IsInitPlaybackEngineNeeded()
       
   261     {
       
   262     MPX_FUNC( "CMPXCommandHandler::IsInitPlaybackEngineNeeded" );
       
   263     TBool ret( EFalse );
       
   264     if ( iParameter )
       
   265         {
       
   266         ret = ( iParameter->iPathType == EMPXTypeCollectionPlaylist );
       
   267         }
       
   268     return ret;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // Extracts the activated view type from the command
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 TInt CMPXCommandHandler::ActivatedViewTypeId()
       
   276     {
       
   277     MPX_FUNC( "CMPXCommandHandler::ActivatedViewTypeId" );
       
   278     TInt id( 0 );
       
   279     if ( iParameter )
       
   280         {
       
   281         id = iParameter->iType.iUid;
       
   282         }
       
   283     return id;
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // From MMPXCollectionObserver.
       
   288 // Handle media properties.
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CMPXCommandHandler::HandleCollectionMediaL(
       
   292     const CMPXMedia& aMedia,
       
   293     TInt aError )
       
   294     {
       
   295     MPX_FUNC( "CMPXCommandHandler::HandleCollectionMediaL" );
       
   296     TBool bringToForeground( EFalse );
       
   297 
       
   298     TUid waitnoteId = TUid::Uid( KMPXPluginTypeWaitNoteDialogUid );
       
   299     TUid activeView = iViewUtility->ActiveViewType();
       
   300     if( activeView == waitnoteId && !iUsbInUse && !iRefreshOngoing )
       
   301         {
       
   302         CMPXViewPlugin* pi =
       
   303             iViewUtility->ViewPluginManager().PluginL( TUid::Uid(KWaitNoteImpUid) );
       
   304         pi->DeactivateView();
       
   305         }
       
   306 
       
   307     if ( aError == KErrNone )
       
   308         {
       
   309         if( aMedia.IsSupported( KMPXMediaColDetailDBCreated ) )
       
   310             {
       
   311             TBool dbCreated( aMedia.ValueTObjectL<TBool>( KMPXMediaColDetailDBCreated ) );
       
   312             if ( dbCreated )
       
   313                 {
       
   314                 MPX_DEBUG1( "CMPXCommandHandler::HandleCollectionMediaL DB status ok" );
       
   315                 DoHandleMessageL();
       
   316                 }
       
   317             else
       
   318                 {
       
   319                 MPX_DEBUG1( "CMPXCommandHandler::HandleCollectionMediaL DB not created" );
       
   320                 if ( !iUsbInUse && !iRefreshOngoing )
       
   321                     {
       
   322                     iViewUtility->ActivateViewL( TUid::Uid( KMPXPluginTypeMainUid ) );
       
   323                     }
       
   324                 else
       
   325                     {
       
   326                     MPX_DEBUG1( "CMPXCommandHandler::HandleCollectionMediaL USB in use/Refreshing, not activating view" );
       
   327                     }
       
   328                 bringToForeground = ETrue;
       
   329                 }
       
   330             }
       
   331         }
       
   332     else
       
   333         {
       
   334         MPX_DEBUG1( "CMPXCommandHandler::HandleCollectionMediaL error getting DB status" );
       
   335         if ( !iUsbInUse && !iRefreshOngoing )
       
   336             {
       
   337             iViewUtility->ActivateViewL( TUid::Uid( KMPXPluginTypeMainUid ) );
       
   338             }
       
   339         else
       
   340             {
       
   341             MPX_DEBUG1( "CMPXCommandHandler::HandleCollectionMediaL USB in use/Refreshing, not activating view" );
       
   342             }
       
   343         bringToForeground = ETrue;
       
   344         }
       
   345 
       
   346     if ( bringToForeground )
       
   347         {
       
   348         MPX_DEBUG1( "CMPXCommandHandler::HandleCollectionMediaL bringing app to foreground" );
       
   349         // have to use window group to activate, in case some other window
       
   350         // has higher priority than us (e.g. playback popup and volume popup)
       
   351         RWindowGroup myWin = CEikonEnv::Static()->RootWin();
       
   352         myWin.SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
   353         }
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // From MMPXCollectionObserver.
       
   358 // Handle collection message.
       
   359 // ---------------------------------------------------------------------------
       
   360 //
       
   361 void CMPXCommandHandler::HandleCollectionMessage(
       
   362     CMPXMessage* aMessage, TInt aError )
       
   363     {
       
   364     if ( aError == KErrNone && aMessage )
       
   365         {
       
   366         TRAP_IGNORE( DoHandleCollectionMessageL( *aMessage ) );
       
   367         }
       
   368     }
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // From MMPXCollectionObserver.
       
   372 // Handles the collection entries being opened.
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CMPXCommandHandler::HandleOpenL(
       
   376     const CMPXMedia& aEntries,
       
   377     TInt /* aIndex */,
       
   378     TBool /* aComplete */,
       
   379     TInt aError  )
       
   380     {
       
   381     MPX_FUNC( "CMPXCommandHandler::HandleOpenL 4" );
       
   382     if ( iCollectionPlaylistState ==
       
   383         TMPXCollectionPlaylistSetupStateOpenPath )
       
   384         {
       
   385         if ( !aError )
       
   386             {
       
   387             const CMPXMediaArray* mediaArray(
       
   388                 aEntries.Value<CMPXMediaArray>( KMPXMediaArrayContents ) );
       
   389             User::LeaveIfNull( const_cast<CMPXMediaArray*>( mediaArray ));
       
   390             if ( mediaArray->Count() > 0 )
       
   391                 {
       
   392                 CMPXCollectionPath* cPath( iIsolatedIncOpenUtil->PathL() );
       
   393                 CleanupStack::PushL( cPath );
       
   394                 if ( cPath->Id( cPath->Levels() - 1 ) != KMPXInvalidItemId )
       
   395                     {
       
   396                     iIsolatedIncOpenUtil->Stop();
       
   397                     InitPlaybackEngineL( *cPath );
       
   398                     }
       
   399                 CleanupStack::PopAndDestroy( cPath );
       
   400                 }
       
   401             else
       
   402                 {
       
   403                 // if there's nothing to open, check if the parameter
       
   404                 // contains a view to open
       
   405                 DoHandleMessageL();
       
   406                 }
       
   407             }
       
   408         else
       
   409             {
       
   410             iCollectionPlaylistState = TMPXCollectionPlaylistSetupStateIdle;
       
   411             }
       
   412         }
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------------------------
       
   416 // From MMPXCollectionObserver.
       
   417 // Handles the item being opened.
       
   418 // ---------------------------------------------------------------------------
       
   419 //
       
   420 void CMPXCommandHandler::HandleOpenL(
       
   421     const CMPXCollectionPlaylist& /*aPlaylist*/,
       
   422     TInt /*aError*/ )
       
   423     {
       
   424     MPX_FUNC("CMPXCommandHandler::HandleOpenL 2");
       
   425     // Not used
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // Handle playback message.
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CMPXCommandHandler::HandlePlaybackMessage(
       
   433     CMPXMessage* aMessage, TInt aError )
       
   434     {
       
   435     if ( aError == KErrNone && aMessage )
       
   436         {
       
   437         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
   438         }
       
   439     }
       
   440 
       
   441 // ---------------------------------------------------------------------------
       
   442 // Initialize the playback engine with a collection path
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 void CMPXCommandHandler::InitPlaybackEngineL( CMPXCollectionPath& aPath )
       
   446     {
       
   447     MPX_FUNC( "CMPXCommandHandler::InitPlaybackEngineL" );
       
   448     CMPXCollectionPlaylist* playlist = CMPXCollectionPlaylist::NewL( aPath );
       
   449     CleanupStack::PushL( playlist );
       
   450     if ( iCollectionPlaylistState ==
       
   451         TMPXCollectionPlaylistSetupStateOpenPath )
       
   452         {
       
   453         playlist->SetToIndex(KErrNotFound);
       
   454         }
       
   455     iCollectionPlaylistState =
       
   456         TMPXCollectionPlaylistSetupStateInitPlaybackEngine;
       
   457     iPlaybackUtility->InitL( *playlist, ETrue );
       
   458     iPathInited = ETrue;
       
   459     CleanupStack::PopAndDestroy( playlist );
       
   460     }
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // DoHandleMessageL
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 void CMPXCommandHandler::DoHandleMessageL()
       
   467     {
       
   468     MPX_FUNC( "CMPXCommandHandler::DoHandleMessageL" );
       
   469 
       
   470     TBool isNeedSetWindowGroup = ETrue;
       
   471     TBool pathOpened( EFalse );
       
   472     iUnhandledMessage = EFalse;
       
   473     TUid appToActivate( KAppUidMusicPlayerX );
       
   474     if ( CEikonEnv::Static()->StartedAsServerApp() )
       
   475         {
       
   476         // if it's embedded mode
       
   477         appToActivate = MPXTlsHelper::HostUid();
       
   478         }
       
   479 
       
   480     MPX_DEBUG3( "CMPXCommandHandler::DoHandleMessageL iUsbInUse = %d, iRefreshOngoing = %d", iUsbInUse, iRefreshOngoing );
       
   481     if ( iParameter && !iUsbInUse && !iRefreshOngoing )
       
   482         {
       
   483         if ( iParameter->iCollectionPath )
       
   484             {
       
   485             if ( iParameter->iPathType != EMPXTypeCollectionPlaylist )
       
   486                 {
       
   487                 // if it's a collection path, use music player collection
       
   488                 // utility to open it.  Collection server understands collection path
       
   489                 // with indexes but not ids.
       
   490                 MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL iCollectionPath defined, path" );
       
   491                 iMusicPlayerCollectionUtility->Collection().OpenL(
       
   492                     *iParameter->iCollectionPath );
       
   493                 }
       
   494             else
       
   495                 {
       
   496                 MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL iCollectionPath defined, playlist" );
       
   497                 // if it's collection playlist path, need to use isolated
       
   498                 // collection utility to translate it to real uids
       
   499                 iCollectionPlaylistState =
       
   500                     TMPXCollectionPlaylistSetupStateOpenPath;
       
   501                 RArray<TMPXAttribute> attrs;
       
   502                 CleanupClosePushL( attrs );
       
   503                 TArray<TMPXAttribute> ary = attrs.Array();
       
   504                 iIsolatedIncOpenUtil->Stop();
       
   505                 iIsolatedIncOpenUtil->SetDelay( 0 );
       
   506                 iIsolatedIncOpenUtil->StartL( *iParameter->iCollectionPath, ary, KIncrementalFetchCount,
       
   507                                       0, CMPXCollectionOpenUtility::EFetchNormal );
       
   508                 CleanupStack::PopAndDestroy( &attrs );
       
   509                 }
       
   510             pathOpened = ETrue;
       
   511             }
       
   512         if ( iParameter->iType != KNullUid )
       
   513             {
       
   514             if ( pathOpened )
       
   515                 {
       
   516                 MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL path opened, view activation deffered" );
       
   517                 // path opened, need to wait for callback before handling
       
   518                 // view switching
       
   519                 iUnhandledMessage = ETrue;
       
   520                 delete iParameter->iCollectionPath;
       
   521                 iParameter->iCollectionPath = NULL;
       
   522                 }
       
   523             else
       
   524                 {
       
   525                 MPX_DEBUG2( "CMPXCommandHandler::DoHandleMessageL activate view 0x%x", iParameter->iType.iUid );
       
   526                 if ( iParameter->iType.iUid == KMPXPluginTypePlaybackUid && appToActivate == KAppUidMusicPlayerX )
       
   527                     {
       
   528                     // push default view history in case for view jumps
       
   529                     iViewUtility->PushDefaultHistoryL();
       
   530                     // only do this when it's not embedded mode
       
   531                     MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL activate playback view special handling" );
       
   532                     // special handling needed for playback view activation
       
   533                     MMPXPlayer* player =
       
   534                         iPlaybackUtility->PlayerManager().CurrentPlayer();
       
   535                     RArray<TUid> array;
       
   536                     CleanupClosePushL( array );
       
   537 
       
   538                     array.AppendL( iParameter->iType );
       
   539                     if ( player )
       
   540                         {
       
   541                         array.AppendL( player->UidL() );
       
   542                         }
       
   543 
       
   544                     // add the collection plugin UID to ensure the correct
       
   545                     // last playback view is activated
       
   546                     MMPXSource* source = iPlaybackUtility->Source();
       
   547                     if( source )
       
   548                         {
       
   549                         CMPXCollectionPlaylist* pl = source->PlaylistL();
       
   550                         if ( pl )
       
   551                             {
       
   552                             CleanupStack::PushL( pl );
       
   553                             const CMPXCollectionPath& path = pl->Path();
       
   554                             if( path.Levels() > 0 )
       
   555                                 {
       
   556                                 MPX_DEBUG2( "CMPXCommandHandler::DoHandleMessageL appending UID 0x%x", path.Id( 0 ).iId1 );
       
   557                                 array.AppendL( TUid::Uid( path.Id( 0 ) ) );
       
   558                                 }
       
   559                             CleanupStack::PopAndDestroy( pl );
       
   560                             }
       
   561                         }
       
   562                     if ( !iUsbInUse && !iRefreshOngoing )
       
   563                         {
       
   564                         iViewUtility->ActivateViewL( array );
       
   565                         }
       
   566                     else
       
   567                         {
       
   568                         MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL USB in use/Refreshing, not activating view" );
       
   569                         }
       
   570                     CleanupStack::PopAndDestroy( &array );
       
   571                     }
       
   572                 else if ( iParameter->iType.iUid == KMPXPluginTypeLastPlayedUid && appToActivate == KAppUidMusicPlayerX )
       
   573                     {
       
   574                     // push default view history in case for view jumps
       
   575                     iViewUtility->PushDefaultHistoryL();
       
   576                     // only do this when it's not embedded mode
       
   577                     MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL activate playback view special handling" );
       
   578                     // special handling needed for playback view activation
       
   579                     MMPXPlayer* player =
       
   580                         iPlaybackUtility->PlayerManager().CurrentPlayer();
       
   581                     RArray<TUid> array;
       
   582                     CleanupClosePushL( array );
       
   583 
       
   584                     array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid) );
       
   585                     if ( player )
       
   586                         {
       
   587                         array.AppendL( player->UidL() );
       
   588                         }
       
   589 
       
   590                     // add the collection plugin UID to ensure the correct
       
   591                     // last playback view is activated
       
   592                     MMPXSource* source = iPlaybackUtility->Source();
       
   593                     if( source )
       
   594                         {
       
   595                         CMPXCollectionPlaylist* pl = source->PlaylistL();
       
   596                         if ( pl )
       
   597                             {
       
   598                             CleanupStack::PushL( pl );
       
   599                             const CMPXCollectionPath& path = pl->Path();
       
   600                             if( path.Levels() > 0 )
       
   601                                 {
       
   602                                 MPX_DEBUG2( "CMPXCommandHandler::DoHandleMessageL appending UID 0x%x", path.Id( 0 ).iId1 );
       
   603                                 array.AppendL( TUid::Uid( path.Id( 0 ) ) );
       
   604                                 }
       
   605                             CleanupStack::PopAndDestroy( pl );
       
   606                             }
       
   607                         }
       
   608                     if ( !iUsbInUse && !iRefreshOngoing )
       
   609                         {
       
   610                         iLastPlayedAutostart = ETrue;
       
   611                         TRAP_IGNORE(iPlaybackUtility->CommandL( EPbCmdPlay ));
       
   612                         RWindowGroup myWin = CEikonEnv::Static()->RootWin();
       
   613                         if ( myWin.OrdinalPosition() == 0 ) //top window
       
   614                             {
       
   615                             iViewUtility->ActivateViewL( array );
       
   616                             }
       
   617                         else 
       
   618                             {
       
   619                             isNeedSetWindowGroup = EFalse;
       
   620                         	}
       
   621                         }
       
   622                     else
       
   623                         {
       
   624                         MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL USB in use/Refreshing, not activating view" );
       
   625                         }
       
   626                     CleanupStack::PopAndDestroy( &array );
       
   627                     }
       
   628                 else if ( appToActivate == KAppUidMusicPlayerX )
       
   629                     {
       
   630                     if ( !iUsbInUse && !iRefreshOngoing )
       
   631                         {
       
   632                         RArray<TUid> array;
       
   633                         CleanupClosePushL( array );
       
   634                         array.AppendL( iParameter->iType );
       
   635                         if ( iParameter->iType.iUid == KMPXPluginTypeCollectionUid && appToActivate == KAppUidMusicPlayerX )
       
   636                             {
       
   637                             CMPXCollectionPath* cpath( iMusicPlayerCollectionUtility->Collection().PathL() );
       
   638                             CleanupStack::PushL( cpath );
       
   639                             if( cpath->Levels() > 0 )
       
   640                                 {
       
   641                                 MPX_DEBUG2( "CMPXCommandHandler::DoHandleMessageL appending UID 0x%x", cpath->Id( 0 ).iId1 );
       
   642                                 array.AppendL( TUid::Uid( cpath->Id( 0 ) ) );
       
   643                                 }
       
   644                             CleanupStack::PopAndDestroy( cpath );
       
   645                             }
       
   646                         // push default view history in case for view jumps
       
   647                         iViewUtility->PushDefaultHistoryL();
       
   648                         // only do this if it's not embedded mode
       
   649                         iViewUtility->ActivateViewL( array );
       
   650                         CleanupStack::PopAndDestroy( &array );
       
   651                         }
       
   652                     else
       
   653                         {
       
   654                         MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL USB in use/Refreshing, not activating view" );
       
   655                         }
       
   656                     }
       
   657                 else
       
   658                     {
       
   659                     MPX_DEBUG1( "CMPXCommandHandler::DoHandleMessageL embedded mode, not activating view" );
       
   660                     }
       
   661                 }
       
   662             }
       
   663         }
       
   664     if ( !iUnhandledMessage || iUsbInUse || iRefreshOngoing )
       
   665         {
       
   666         // after the message is handled, delete it
       
   667         delete iParameter;
       
   668         iParameter = NULL;
       
   669         // have to use window group to activate, in case some other window
       
   670         // has higher priority than us (e.g. playback popup and volume popup)
       
   671         if ( isNeedSetWindowGroup )
       
   672             {
       
   673             RWindowGroup myWin = CEikonEnv::Static()->RootWin();
       
   674             myWin.SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
   675             }
       
   676         }
       
   677     }
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 // ExtractMessageL
       
   681 // -----------------------------------------------------------------------------
       
   682 //
       
   683 void CMPXCommandHandler::ExtractMessageL( const TDesC8& aMessage )
       
   684     {
       
   685     MPX_FUNC( "CMPXCommandHandler::ExtractMessageL" );
       
   686     ASSERT( aMessage.Length() > 0 );
       
   687     delete iParameter;
       
   688     iParameter = NULL;
       
   689     CBufBase* buffer = CBufFlat::NewL( aMessage.Size() );
       
   690     CleanupStack::PushL( buffer );
       
   691     buffer->ResizeL( aMessage.Size() );
       
   692     buffer->Write( 0, aMessage );
       
   693     RBufReadStream readStream( *buffer );
       
   694     CleanupClosePushL( readStream );
       
   695     iParameter = new ( ELeave ) CMPXParameter();
       
   696     iParameter->InternalizeL( readStream );
       
   697     CleanupStack::PopAndDestroy( &readStream );
       
   698     CleanupStack::PopAndDestroy( buffer );
       
   699     }
       
   700 
       
   701 // -----------------------------------------------------------------------------
       
   702 // Handle playback message
       
   703 // -----------------------------------------------------------------------------
       
   704 //
       
   705 void CMPXCommandHandler::DoHandlePlaybackMessageL( const CMPXMessage& aMessage )
       
   706     {
       
   707     MPX_FUNC( "CMPXCommandHandler::DoHandlePlaybackMessageL" );
       
   708     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   709     if ( KMPXMessageGeneral == id )
       
   710         {
       
   711         switch ( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) )
       
   712             {
       
   713             case TMPXPlaybackMessage::EInitializeComplete:
       
   714                 {
       
   715                 if ( iCollectionPlaylistState ==
       
   716                     TMPXCollectionPlaylistSetupStateInitPlaybackEngine )
       
   717                     {
       
   718                     iViewUtility->PushDefaultHistoryL();
       
   719                     iPlaybackUtility->CommandL( EPbCmdPlay );
       
   720                     iCollectionPlaylistState =
       
   721                         TMPXCollectionPlaylistSetupStateIdle;
       
   722                     delete iParameter;
       
   723                     iParameter = NULL;
       
   724                     RWindowGroup myWin = CEikonEnv::Static()->RootWin();
       
   725                     myWin.SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
   726                     }
       
   727                 if (iLastPlayedAutostart)
       
   728                     {
       
   729                     iPlaybackUtility->CommandL( EPbCmdPlay );
       
   730                     iLastPlayedAutostart = EFalse;
       
   731                     }
       
   732                 break;
       
   733                 }
       
   734             default:
       
   735                 {
       
   736                 // ignore other playback messages
       
   737                 break;
       
   738                 }
       
   739             }
       
   740         }
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // Handle collection message
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 void CMPXCommandHandler::DoHandleCollectionMessageL( const CMPXMessage& aMessage )
       
   748     {
       
   749     MPX_FUNC( "CMPXCommandHandler::DoHandleCollectionMessageL" );
       
   750     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   751     if ( KMPXMessageGeneral == id )
       
   752         {
       
   753         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
   754         TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
   755         MPX_DEBUG3( "CMPXCommandHandler::HandleCollectionMessage Event = %d, Type() = %d",
       
   756             event, type );
       
   757         if ( iUnhandledMessage )
       
   758             {
       
   759             DoHandleMessageL();
       
   760             }
       
   761         else
       
   762             {
       
   763             // do nothing
       
   764             }
       
   765         }
       
   766     }
       
   767 
       
   768 // End of File