mpengine/src/mpmpxcollectionframeworkwrapper_p.cpp
changeset 35 fdb31ab341af
parent 34 2c5162224003
child 32 c163ef0b758d
equal deleted inserted replaced
34:2c5162224003 35:fdb31ab341af
    76       iIsolatedCollectionHelper( 0 ),
    76       iIsolatedCollectionHelper( 0 ),
    77       iPlaybackUtility( 0 ),
    77       iPlaybackUtility( 0 ),
    78       iCollectionData( 0 ),
    78       iCollectionData( 0 ),
    79       iIsolatedCollectionData( 0 ),
    79       iIsolatedCollectionData( 0 ),
    80       iFirstIncrementalOpen( EFalse ),
    80       iFirstIncrementalOpen( EFalse ),
    81       iUserPlaylists( 0 )
    81       iUserPlaylists( 0 ),
       
    82       iRepeatFeature( ETrue ),
       
    83       iShuffleFeature( ETrue ),
       
    84       iReopen( EFalse )
    82 {
    85 {
    83     TX_LOG
    86     TX_LOG
    84 }
    87 }
    85 
    88 
    86 /*!
    89 /*!
   113 }
   116 }
   114 
   117 
   115 /*!
   118 /*!
   116  \internal
   119  \internal
   117  */
   120  */
   118 void MpMpxCollectionFrameworkWrapperPrivate::init( MpCommon::MpViewMode viewMode, TUid hostUid )
   121 void MpMpxCollectionFrameworkWrapperPrivate::init( TUid hostUid )
   119 {
   122 {
   120 
   123 
   121     iViewMode = viewMode;
       
   122     mHostUid = hostUid;
   124     mHostUid = hostUid;
   123     TRAPD( err, DoInitL() );
   125     TRAPD( err, DoInitL() );
   124     if ( err != KErrNone ) {
   126     if ( err != KErrNone ) {
   125         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   127         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   126     }
   128     }
   152  \internal
   154  \internal
   153  */
   155  */
   154 void MpMpxCollectionFrameworkWrapperPrivate::reopenCollection()
   156 void MpMpxCollectionFrameworkWrapperPrivate::reopenCollection()
   155 {
   157 {
   156     TRAPD( err, DoReopenCollectionL() );
   158     TRAPD( err, DoReopenCollectionL() );
   157     if ( err != KErrNone ) {
   159     if ( err == KErrNone ) {
       
   160         iReopen = ETrue;
       
   161     }
       
   162     else {
   158         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   163         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   159     }
   164     }
   160 }
   165 }
   161 
   166 
   162 /*!
   167 /*!
   216 /*!
   221 /*!
   217  \internal
   222  \internal
   218  */
   223  */
   219 void MpMpxCollectionFrameworkWrapperPrivate::deleteSongs( QList<int> &selection )
   224 void MpMpxCollectionFrameworkWrapperPrivate::deleteSongs( QList<int> &selection )
   220 {
   225 {
   221     TRAPD( err, DoDeleteSongsL( selection ) );
   226     TCollectionContext context = iCollectionData->context();
   222     if ( err != KErrNone ) {
   227     int err;
       
   228     if ( context == ECollectionContextArtistAlbumsTBone
       
   229          || context == ECollectionContextAlbumsTBone ) {
       
   230         TRAP( err, DoDeleteAlbumSongsL( selection ) );
       
   231     }
       
   232     else {
       
   233         TRAP( err, DoDeleteSongsL( selection ) );
       
   234     }
       
   235     if ( err == KErrNone ) {
       
   236         // send signal that deleting has started.
       
   237         emit q_ptr->deleteStarted(iCollectionData->context(), selection.count());
       
   238     }
       
   239     else{
   223         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   240         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   224     }
   241     }
   225 }
   242 }
   226 
   243 
   227 /*!
   244 /*!
   259 /*!
   276 /*!
   260  \internal
   277  \internal
   261  */
   278  */
   262 void MpMpxCollectionFrameworkWrapperPrivate::previewItem( int index )
   279 void MpMpxCollectionFrameworkWrapperPrivate::previewItem( int index )
   263 {
   280 {
   264     TRAPD( err, DoPreviewItemL( index ) );
   281     TCollectionContext context = iCollectionData->context();
       
   282     int err;
       
   283     if ( context == ECollectionContextArtistAlbumsTBone
       
   284          || context == ECollectionContextAlbumsTBone ) {
       
   285         TRAP( err, DoPreviewAlbumSongL( index ) );
       
   286     }
       
   287     else {
       
   288         TRAP( err, DoPreviewSongL( index ) );
       
   289     }
   265     if ( err != KErrNone ) {
   290     if ( err != KErrNone ) {
   266         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   291         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   267     }
   292     }
   268 }
   293 }
   269 
   294 
   301 }
   326 }
   302 
   327 
   303 /*!
   328 /*!
   304  \internal
   329  \internal
   305  */
   330  */
       
   331 void MpMpxCollectionFrameworkWrapperPrivate::cancel()
       
   332 {
       
   333     iCollectionUiHelper->Cancel();
       
   334 }
       
   335 
       
   336 /*!
       
   337  \internal
       
   338  */
       
   339 void MpMpxCollectionFrameworkWrapperPrivate::findAlbumSongs( int index )
       
   340 {
       
   341     TRAPD( err, DoFindAlbumSongsL( index ) );
       
   342     if ( err != KErrNone ) {
       
   343         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
   344     }
       
   345 }
       
   346 
       
   347 /*!
       
   348  \internal
       
   349  */
       
   350 void MpMpxCollectionFrameworkWrapperPrivate::playAlbumSongs( int albumIndex, int songIndex, MpMpxCollectionData* collectionData  )
       
   351 {
       
   352     TRAPD( err, DoPlayAlbumSongsL( albumIndex, songIndex, collectionData ? collectionData : iCollectionData ) );
       
   353     if ( err != KErrNone ) {
       
   354         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
   355     }
       
   356 }
       
   357 
       
   358 /*!
       
   359  \internal
       
   360  */
   306 MpMpxCollectionData *MpMpxCollectionFrameworkWrapperPrivate::collectionData()
   361 MpMpxCollectionData *MpMpxCollectionFrameworkWrapperPrivate::collectionData()
   307 {
   362 {
   308     return iCollectionData;
   363     return iCollectionData;
   309 }
   364 }
   310 
   365 
   311 /*!
   366 /*!
   312  \internal
   367  \internal
       
   368  Result of open or re-open operation to the Collection Framework.
   313  */
   369  */
   314 void MpMpxCollectionFrameworkWrapperPrivate::HandleOpenL( 
   370 void MpMpxCollectionFrameworkWrapperPrivate::HandleOpenL( 
   315     const CMPXMedia& aEntries,
   371     const CMPXMedia& aEntries,
   316     TInt aIndex,
   372     TInt aIndex,
   317     TBool aComplete,
   373     TBool aComplete,
   320     Q_UNUSED( aIndex );
   376     Q_UNUSED( aIndex );
   321     TX_UNUSED( aComplete );
   377     TX_UNUSED( aComplete );
   322     TX_ENTRY_ARGS( "aError=" << aError << "aComplete=" << aComplete );
   378     TX_ENTRY_ARGS( "aError=" << aError << "aComplete=" << aComplete );
   323     if ( aError == KErrNone ) {
   379     if ( aError == KErrNone ) {
   324         if ( iFirstIncrementalOpen ) {
   380         if ( iFirstIncrementalOpen ) {
   325             iCollectionData->setMpxMedia( aEntries );
   381             iCollectionData->setMpxMedia( aEntries, iReopen );
   326             iFirstIncrementalOpen = EFalse;
   382             iFirstIncrementalOpen = EFalse;
       
   383             iReopen = EFalse;
   327         }
   384         }
   328     }
   385     }
   329     else {
   386     else {
   330         TX_LOG_ARGS( "Error: " << aError << "; should never get here." );
   387         TX_LOG_ARGS( "Error: " << aError << "; should never get here." );
   331     }
   388     }
   340     TInt aError )
   397     TInt aError )
   341 {
   398 {
   342     TX_ENTRY_ARGS( "aError=" << aError );
   399     TX_ENTRY_ARGS( "aError=" << aError );
   343 
   400 
   344     if ( aError == KErrNone ) {
   401     if ( aError == KErrNone ) {
   345         if ( !iPlaybackUtility ) {
   402         //TODO: all calls to playback utility should be done via the engine and trough the playback FW wrapper.
   346 
   403         createPlaybackUtilityL();
   347             iPlaybackUtility = MMPXPlaybackUtility::UtilityL( mHostUid );
       
   348 
       
   349             if ( iViewMode == MpCommon::DefaultView ) {
       
   350                 iPlaybackUtility->SetL( EPbPropertyRandomMode, MpSettingsManager::shuffle() ? ETrue : EFalse );
       
   351                 iPlaybackUtility->SetL( EPbPropertyRepeatMode, MpSettingsManager::repeat() ? EPbRepeatAll : EPbRepeatOff );
       
   352             }
       
   353         }
       
   354         iPlaybackUtility->InitL( aPlaylist, ETrue );
   404         iPlaybackUtility->InitL( aPlaylist, ETrue );
   355         emit q_ptr->collectionPlaylistOpened();
   405         emit q_ptr->collectionPlaylistOpened();
   356     }
   406     }
   357     else {
   407     else {
   358         TX_LOG_ARGS( "Error: " << aError << "; should never get here." );
   408         TX_LOG_ARGS( "Error: " << aError << "; should never get here." );
   437 }
   487 }
   438 
   488 
   439 /*!
   489 /*!
   440  \internal
   490  \internal
   441  */
   491  */
       
   492 void MpMpxCollectionFrameworkWrapperPrivate::HandleFindAllL( const CMPXMedia& aResults, TBool aComplete, TInt aError )
       
   493 {
       
   494     Q_UNUSED( aComplete );
       
   495     TX_ENTRY_ARGS( "aError=" << aError );
       
   496 
       
   497     if ( aError == KErrNone ) {
       
   498         iCollectionData->setAlbumContent( aResults );
       
   499     }
       
   500 }
       
   501 
       
   502 /*!
       
   503  \internal
       
   504  */
   442 void MpMpxCollectionFrameworkWrapperPrivate::DoInitL()
   505 void MpMpxCollectionFrameworkWrapperPrivate::DoInitL()
   443 {
   506 {
   444     TX_ENTRY
   507     TX_ENTRY
   445     if ( iViewMode == MpCommon::FetchView ) {
   508     iCollectionUtility = MMPXCollectionUtility::NewL( this, mHostUid );
   446         iCollectionUtility = MMPXCollectionUtility::NewL( this, mHostUid );
   509     iCollectionUiHelper = CMPXCollectionHelperFactory:: NewCollectionUiHelperL( mHostUid );
   447         iCollectionUiHelper = CMPXCollectionHelperFactory:: NewCollectionUiHelperL( mHostUid );
   510     iIncrementalOpenUtil = CMPXCollectionOpenUtility::NewL( this, mHostUid );  
   448         iIncrementalOpenUtil = CMPXCollectionOpenUtility::NewL( this, mHostUid );
       
   449     }
       
   450     else {
       
   451         iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault );
       
   452         iCollectionUiHelper = CMPXCollectionHelperFactory:: NewCollectionUiHelperL();
       
   453         iIncrementalOpenUtil = CMPXCollectionOpenUtility::NewL( this );
       
   454     }
       
   455     
       
   456     iCollectionData = new MpMpxCollectionData();
   511     iCollectionData = new MpMpxCollectionData();
   457     TX_EXIT
   512     TX_EXIT
   458 }
   513 }
   459 
   514 
   460 /*!
   515 /*!
   476         }
   531         }
   477     case ECollectionContextArtists:
   532     case ECollectionContextArtists:
   478         {
   533         {
   479         CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
   534         CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
   480         CleanupStack::PushL( cpath );
   535         CleanupStack::PushL( cpath );
   481         cpath->AppendL( 2 );
   536         cpath->AppendL( BrowseArtist );
   482         iCollectionUtility->Collection().OpenL( *cpath );
   537         iCollectionUtility->Collection().OpenL( *cpath );
   483         CleanupStack::PopAndDestroy( cpath );
   538         CleanupStack::PopAndDestroy( cpath );
   484         break;
   539         break;
   485         }
   540         }
   486     case ECollectionContextAlbums:
   541     case ECollectionContextAlbums:
   487         {
   542         {
   488         CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
   543         CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
   489         CleanupStack::PushL( cpath );
   544         CleanupStack::PushL( cpath );
   490         cpath->AppendL( 3 );
   545         cpath->AppendL( BrowseAlbum );
   491         iCollectionUtility->Collection().OpenL( *cpath );
   546         iCollectionUtility->Collection().OpenL( *cpath );
   492         CleanupStack::PopAndDestroy( cpath );
   547         CleanupStack::PopAndDestroy( cpath );
   493         break;
   548         break;
   494         }
   549         }
   495     case ECollectionContextPlaylists:
   550     case ECollectionContextPlaylists:
   498         CleanupStack::PushL( cpath );
   553         CleanupStack::PushL( cpath );
   499         iCollectionUtility->Collection().OpenL( *cpath );
   554         iCollectionUtility->Collection().OpenL( *cpath );
   500         CleanupStack::PopAndDestroy( cpath );
   555         CleanupStack::PopAndDestroy( cpath );
   501         break;
   556         break;
   502         }
   557         }
   503     case ECollectionContextGenres:
   558     case ECollectionContextAlbumsMediaWall:
   504         {
   559         {
   505         CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
   560         CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL();
   506         CleanupStack::PushL( cpath );
   561         CleanupStack::PushL( cpath );
   507         // Temp
   562         cpath->AppendL( BrowseAlbumMediaWall );
   508         cpath->AppendL( 5 );
       
   509         iCollectionUtility->Collection().OpenL( *cpath );
   563         iCollectionUtility->Collection().OpenL( *cpath );
   510         CleanupStack::PopAndDestroy( cpath );
   564         CleanupStack::PopAndDestroy( cpath );
   511         break;
   565         break;
   512         }
   566         }
   513     default:
   567     default:
   708     int count = selection.count();
   762     int count = selection.count();
   709     TX_ENTRY_ARGS( "selection count=" << count );
   763     TX_ENTRY_ARGS( "selection count=" << count );
   710 
   764 
   711     CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
   765     CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
   712     CleanupStack::PushL( path );
   766     CleanupStack::PushL( path );
   713 
   767     
   714     if (count > 1) {
   768     if (count > 1) {
   715         for ( TInt i = 0; i < count; i++ ){
   769         for ( TInt i = 0; i < count; i++ ){
   716             path->SelectL( selection.at( i ) );
   770             path->SelectL( selection.at( i ) );
   717         }
   771         }
   718     }
   772     }
   719     else {
   773     else {
   720         path->Set( selection.at(0) );
   774         path->Set( selection.at(0) );
   721     }
   775     }
       
   776         
   722     iCollectionUiHelper->DeleteL( *path, this );
   777     iCollectionUiHelper->DeleteL( *path, this );
       
   778     CleanupStack::PopAndDestroy( path );
       
   779     TX_EXIT
       
   780 }
       
   781 
       
   782 /*!
       
   783  \internal
       
   784  */
       
   785 void MpMpxCollectionFrameworkWrapperPrivate::DoDeleteAlbumSongsL( QList<int> &selection )
       
   786 {
       
   787     int count = selection.count();
       
   788     TX_ENTRY_ARGS( "selection count=" << count );
       
   789 
       
   790     CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
       
   791     CleanupStack::PushL( path );
       
   792     MPX_DEBUG_PATH( *path );
       
   793 
       
   794     CMPXMediaArray *mediaArray;
       
   795     const CMPXMedia& container = iCollectionData->containerMedia();
       
   796     mediaArray = const_cast<CMPXMediaArray*>( container.Value<CMPXMediaArray>( KMPXMediaArrayContents ) );
       
   797     int currentAlbumIndex = iCollectionData->currentAlbumIndex();
       
   798     CMPXMedia* album( mediaArray->AtL( currentAlbumIndex ) );
       
   799     if ( album->IsSupported(KMPXMediaArrayContents) ) {
       
   800         const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   801         User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs));
       
   802         int index = selection.at(0);
       
   803         CMPXMedia* song = songs->AtL(index);
       
   804 
       
   805         TMPXItemId id( song->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
   806         path->AppendL( id );   // Append the song ID to be deleted
       
   807         path->Set( 0 );        // Select 1st song
       
   808 
       
   809         iCollectionUiHelper->DeleteL( *path, this );
       
   810     }
   723     CleanupStack::PopAndDestroy( path );
   811     CleanupStack::PopAndDestroy( path );
   724     TX_EXIT
   812     TX_EXIT
   725 }
   813 }
   726 
   814 
   727 /*!
   815 /*!
   782 }
   870 }
   783 
   871 
   784 /*!
   872 /*!
   785  \internal
   873  \internal
   786  */
   874  */
   787 void MpMpxCollectionFrameworkWrapperPrivate::DoPreviewItemL( int index )
   875 void MpMpxCollectionFrameworkWrapperPrivate::DoPreviewSongL( int index )
   788 {
   876 {
   789     TX_ENTRY
   877     TX_ENTRY
   790     if ( !iPlaybackUtility ) {
   878     
   791         iPlaybackUtility = MMPXPlaybackUtility::UtilityL( mHostUid );
       
   792     }
       
   793 
       
   794     // Get the current path
   879     // Get the current path
   795     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
   880     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
   796     CleanupStack::PushL( cpath );
   881     CleanupStack::PushL( cpath );
   797     MPX_DEBUG_PATH( *cpath );
   882     MPX_DEBUG_PATH( *cpath );
   798     cpath->Back();
   883     cpath->Back();
   799 
   884 
       
   885     TMPXItemId id( iCollectionData->itemId(index) );
       
   886     cpath->AppendL( id ); // Top level items of songs
       
   887     cpath->Set( 0 ); // Select 1st song
       
   888 
       
   889     CMPXCollectionPlaylist* playList = CMPXCollectionPlaylist::NewL( *cpath );
       
   890     CleanupStack::PushL( playList );
       
   891     playList->SetToFirst();
       
   892     //TODO: all calls to playback utility should be done via the engine and trough the playback FW wrapper.
       
   893     createPlaybackUtilityL();
       
   894     iPlaybackUtility->InitL( *playList, ETrue );
       
   895     emit q_ptr->collectionPlaylistOpened();
       
   896 
       
   897     CleanupStack::PopAndDestroy( playList );
       
   898     CleanupStack::PopAndDestroy( cpath );
       
   899     TX_EXIT
       
   900 }
       
   901 
       
   902 /*!
       
   903  \internal
       
   904  */
       
   905 void MpMpxCollectionFrameworkWrapperPrivate::DoPreviewAlbumSongL( int index )
       
   906 {
       
   907     TX_ENTRY
       
   908     //TODO: all calls to playback utility should be done via the engine and trough the playback FW wrapper.
       
   909     if ( !iPlaybackUtility ) {
       
   910         iPlaybackUtility = MMPXPlaybackUtility::UtilityL( mHostUid );
       
   911     }
       
   912 
       
   913     // Get the current path
       
   914     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
   915     CleanupStack::PushL( cpath );
       
   916     MPX_DEBUG_PATH( *cpath );
       
   917 
   800     CMPXMediaArray *mediaArray;
   918     CMPXMediaArray *mediaArray;
   801     const CMPXMedia& container = iCollectionData->containerMedia();
   919     const CMPXMedia& container = iCollectionData->containerMedia();
   802     mediaArray = const_cast<CMPXMediaArray*>( container.Value<CMPXMediaArray>( KMPXMediaArrayContents ) );
   920     mediaArray = const_cast<CMPXMediaArray*>( container.Value<CMPXMediaArray>( KMPXMediaArrayContents ) );
   803     CMPXMedia* currentMedia( mediaArray->AtL( index ) );
   921     int currentAlbumIndex = iCollectionData->currentAlbumIndex();
   804     TMPXItemId id( currentMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
   922     CMPXMedia* album( mediaArray->AtL( currentAlbumIndex ) );
   805 
   923     if ( album->IsSupported(KMPXMediaArrayContents) ) {
   806     cpath->AppendL( id ); // Top level items of songs
   924         const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents);
   807     cpath->Set( 0 ); // Select 1st song
   925         User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs));
   808 
   926         CMPXMedia* song = songs->AtL(index);
   809     CMPXCollectionPlaylist* playList = CMPXCollectionPlaylist::NewL( *cpath );
   927 
   810     CleanupStack::PushL( playList );
   928         TMPXItemId id( song->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
   811     playList->SetToFirst();
   929         cpath->AppendL( id );   // Top level items of songs
   812 
   930         cpath->Set( 0 );        // Select 1st song
   813     iPlaybackUtility->InitL( *playList, ETrue );
   931 
   814     emit q_ptr->collectionPlaylistOpened();
   932         CMPXCollectionPlaylist* playList = CMPXCollectionPlaylist::NewL( *cpath );
   815 
   933         CleanupStack::PushL( playList );
   816     CleanupStack::PopAndDestroy( playList );
   934         playList->SetToFirst();
       
   935         //TODO: all calls to playback utility should be done via the engine and trough the playback FW wrapper.
       
   936         iPlaybackUtility->InitL( *playList, ETrue );
       
   937         emit q_ptr->collectionPlaylistOpened();
       
   938 
       
   939         CleanupStack::PopAndDestroy( playList );
       
   940     }
   817     CleanupStack::PopAndDestroy( cpath );
   941     CleanupStack::PopAndDestroy( cpath );
   818     TX_EXIT
   942     TX_EXIT
   819 }
   943 }
   820 
   944 
   821 /*!
   945 /*!
   838 /*!
   962 /*!
   839  \internal
   963  \internal
   840  */
   964  */
   841 void MpMpxCollectionFrameworkWrapperPrivate::DoReorderPlaylistL( int playlistId, int songId, int originalOrdinal, int newOrdinal )
   965 void MpMpxCollectionFrameworkWrapperPrivate::DoReorderPlaylistL( int playlistId, int songId, int originalOrdinal, int newOrdinal )
   842 {
   966 {
   843     iCollectionUiHelper->ReorderPlaylistL( playlistId, songId, originalOrdinal, newOrdinal, this );           
   967     iCollectionUiHelper->ReorderPlaylistL( playlistId, songId, originalOrdinal, newOrdinal, this );
   844 }
   968 }
   845 
   969 
       
   970 /*!
       
   971  \internal
       
   972  */
       
   973 void MpMpxCollectionFrameworkWrapperPrivate::DoFindAlbumSongsL( int index )
       
   974 {
       
   975     const CMPXMedia& container = iCollectionData->containerMedia();
       
   976     const CMPXMediaArray* mediaArray = container.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   977     CMPXMedia* album( mediaArray->AtL( index ) );
       
   978 
       
   979     // Fetch the songs for the selected album
       
   980     TMPXItemId albumId = album->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
   981     CMPXMedia* findCriteria = CMPXMedia::NewL();
       
   982     CleanupStack::PushL( findCriteria );
       
   983     findCriteria->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXGroup );
       
   984     findCriteria->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXSong );
       
   985     findCriteria->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, albumId );
       
   986     RArray<TMPXAttribute> attrs;
       
   987     CleanupClosePushL( attrs );
       
   988     attrs.Append( TMPXAttribute( KMPXMediaIdGeneral,
       
   989                                  EMPXMediaGeneralTitle |
       
   990 								 EMPXMediaGeneralUri |
       
   991                                  EMPXMediaGeneralId |
       
   992                                  EMPXMediaGeneralType |
       
   993                                  EMPXMediaGeneralCategory |
       
   994                                  EMPXMediaGeneralFlags ) );
       
   995     attrs.Append( KMPXMediaMusicAlbumTrack );
       
   996 
       
   997     iCollectionUtility->Collection().FindAllL( *findCriteria, attrs.Array(), *this );
       
   998     CleanupStack::PopAndDestroy( &attrs );
       
   999     CleanupStack::PopAndDestroy( findCriteria );
       
  1000 }
       
  1001 
       
  1002 /*!
       
  1003  \internal
       
  1004  */
       
  1005 void MpMpxCollectionFrameworkWrapperPrivate::DoPlayAlbumSongsL( int albumIndex, int songIndex, MpMpxCollectionData* collectionData  )
       
  1006 {
       
  1007     TX_ENTRY
       
  1008 
       
  1009     RArray<TMPXItemId> ids;
       
  1010     CleanupClosePushL(ids);
       
  1011 
       
  1012     CMPXCollectionPath* cpath;
       
  1013     
       
  1014     //Following check is for a use case for media wall, where it is required 
       
  1015     //to play songs that are browsed by an isolated collection.
       
  1016     if ( collectionData->context() ==  ECollectionContextAlbumsMediaWall ) {
       
  1017         //Get the Media Wall path.
       
  1018         cpath = iCollectionUiHelper->MusicMenuPathL();
       
  1019         CleanupStack::PushL( cpath );
       
  1020         //TODO: change to BrowseAlbumMediaWall befor when merging with olveras changes.
       
  1021         cpath->AppendL( BrowseAlbum );
       
  1022         const TMPXItemId albumId = collectionData->itemId( albumIndex );
       
  1023         //Append the selected album.
       
  1024         RArray<TMPXItemId> items;
       
  1025         CleanupClosePushL(items);
       
  1026         items.AppendL(albumId);
       
  1027         cpath->AppendL(items.Array());
       
  1028         CleanupStack::PopAndDestroy( &items );
       
  1029         cpath->Set( 0 ); // Set the album.
       
  1030         
       
  1031     }
       
  1032     else {
       
  1033         // Get the current path
       
  1034         cpath = iCollectionUtility->Collection().PathL();
       
  1035         CleanupStack::PushL( cpath );
       
  1036         cpath->Set(albumIndex); // Set the selected album
       
  1037     }
       
  1038     MPX_DEBUG_PATH( *cpath );
       
  1039 
       
  1040     CMPXMediaArray *mediaArray;
       
  1041     const CMPXMedia& container = collectionData->containerMedia();
       
  1042     mediaArray = const_cast<CMPXMediaArray*>( container.Value<CMPXMediaArray>( KMPXMediaArrayContents ) );
       
  1043     CMPXMedia* album( mediaArray->AtL( albumIndex ) );
       
  1044     const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
  1045     User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs));
       
  1046 
       
  1047     TInt count = songs->Count();
       
  1048     for ( TInt i = 0; i < count; ++i ) {
       
  1049         CMPXMedia* song = songs->AtL(i);
       
  1050         const TMPXItemId id = song->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  1051         ids.AppendL(id);
       
  1052     }
       
  1053 
       
  1054     cpath->AppendL(ids.Array());    // Top level items of songs
       
  1055     cpath->Set(songIndex);          // Set the selected song
       
  1056     MPX_DEBUG_PATH(*cpath);
       
  1057 
       
  1058     CMPXCollectionPlaylist* playList = CMPXCollectionPlaylist::NewL( *cpath );
       
  1059     CleanupStack::PushL( playList );
       
  1060     
       
  1061     //TODO: all calls to playback utility should be done via the engine and trough the playback FW wrapper.
       
  1062     createPlaybackUtilityL();
       
  1063     iPlaybackUtility->InitL( *playList, ETrue );
       
  1064     emit q_ptr->collectionPlaylistOpened();
       
  1065 
       
  1066     CleanupStack::PopAndDestroy( playList );
       
  1067     CleanupStack::PopAndDestroy( cpath );
       
  1068     CleanupStack::PopAndDestroy( &ids );
       
  1069     TX_EXIT
       
  1070 }
       
  1071 
       
  1072 /*!
       
  1073  \internal
       
  1074  */
       
  1075 void MpMpxCollectionFrameworkWrapperPrivate::setRepeatFeatureEnabled( bool enable ) 
       
  1076 {
       
  1077     iRepeatFeature = enable;
       
  1078 }
       
  1079 
       
  1080 /*!
       
  1081  \internal
       
  1082  */
       
  1083 void MpMpxCollectionFrameworkWrapperPrivate::setShuffleFeatureEnabled( bool enable )
       
  1084 {
       
  1085     iShuffleFeature = enable;
       
  1086 }
   846 
  1087 
   847 /*!
  1088 /*!
   848  \internal
  1089  \internal
   849  */
  1090  */
   850 void MpMpxCollectionFrameworkWrapperPrivate::DoHandleCollectionMessageL( 
  1091 void MpMpxCollectionFrameworkWrapperPrivate::DoHandleCollectionMessageL( 
   870             // Opened a song
  1111             // Opened a song
   871             // This will result in HandleOpenL with CMPXCollectionPlaylist
  1112             // This will result in HandleOpenL with CMPXCollectionPlaylist
   872             iCollectionUtility->Collection().OpenL();
  1113             iCollectionUtility->Collection().OpenL();
   873         }
  1114         }
   874     }
  1115     }
       
  1116     else if( id == KMPXMessageIdItemChanged ) {
       
  1117         emit q_ptr->containerContentsChanged();                     
       
  1118     }  
   875     TX_EXIT
  1119     TX_EXIT
   876 }
  1120 }
   877 
  1121 
   878 
  1122 
   879 /*!
  1123 /*!
   885         MpMpxCollectionData *collectionData )
  1129         MpMpxCollectionData *collectionData )
   886 {
  1130 {
   887     int count = selection.count();
  1131     int count = selection.count();
   888     TX_ENTRY_ARGS( "selection count=" << count );
  1132     TX_ENTRY_ARGS( "selection count=" << count );
   889 
  1133 
   890     const CMPXMedia& container = collectionData->containerMedia();
  1134     const CMPXMediaArray* mediaArray = 0;
   891     const CMPXMediaArray* containerArray = container.Value<CMPXMediaArray>( KMPXMediaArrayContents );
  1135     
   892     User::LeaveIfNull( const_cast<CMPXMediaArray*>( containerArray ) );
  1136     if ( ( collectionData->context() == ECollectionContextArtistAlbumsTBone ) || 
       
  1137          ( collectionData->context() == ECollectionContextAlbumsTBone ) ) {
       
  1138         //There is no need to find the track information, for TBone we cash it under the media itself.
       
  1139         //Fetching song data from container media.
       
  1140         CMPXMedia* album;
       
  1141         const CMPXMediaArray* albumsArray;
       
  1142         albumsArray = collectionData->containerMedia().Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  1143         int index = collectionData->currentAlbumIndex();
       
  1144         if ( index >= 0 ) {
       
  1145             album = albumsArray->AtL( collectionData->currentAlbumIndex() );
       
  1146             mediaArray = album->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  1147         }
       
  1148     }
       
  1149     else {
       
  1150         const CMPXMedia& container = collectionData->containerMedia();
       
  1151         mediaArray = container.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  1152     }
       
  1153        
       
  1154     User::LeaveIfNull( const_cast<CMPXMediaArray*>( mediaArray ) );
   893     CMPXMediaArray* tracksArray( CMPXMediaArray::NewL() );
  1155     CMPXMediaArray* tracksArray( CMPXMediaArray::NewL() );
   894     CleanupStack::PushL( tracksArray );
  1156     CleanupStack::PushL( tracksArray );
   895 
  1157 
   896     CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
  1158     CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
   897     CleanupStack::PushL( path );
  1159     CleanupStack::PushL( path );
   898     TMPXItemId collectionId( path->Id( 0 ) );
  1160     TMPXItemId collectionId( path->Id( 0 ) );
   899     CleanupStack::PopAndDestroy( path );
  1161     CleanupStack::PopAndDestroy( path );
   900 
  1162 
   901     if ( ( collectionData->context() == ECollectionContextAlbums ) || 
  1163     if ( collectionData->context() == ECollectionContextAlbums || 
   902             ( collectionData->context() == ECollectionContextArtistAlbums ) || 
  1164          collectionData->context() == ECollectionContextArtistAlbums ||
   903             ( collectionData->context() == ECollectionContextArtists ) ) {
  1165          collectionData->context() == ECollectionContextArtists ) {
       
  1166         //Container, it is possible to append multiple containers to a playlist. 
       
  1167         //Currently we are just using single selection from the ui.
   904         for ( TInt i = 0; i < count; i++ ) {
  1168         for ( TInt i = 0; i < count; i++ ) {
   905             CMPXMedia* results;
  1169             CMPXMedia* results;
   906             CMPXMedia* container( containerArray->AtL( selection[i] ) );
  1170             CMPXMedia* container( mediaArray->AtL( selection[i] ) );
   907             // Fetch the songs for the selected album
  1171             // Fetch the songs for the selected container
   908             TMPXItemId containerId = container->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
  1172             TMPXItemId containerId = container->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
   909             CMPXMedia* findCriteria = CMPXMedia::NewL();
  1173             CMPXMedia* findCriteria = CMPXMedia::NewL();
   910             CleanupStack::PushL( findCriteria );
  1174             CleanupStack::PushL( findCriteria );
   911             findCriteria->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXGroup );
  1175             findCriteria->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXGroup );
   912             findCriteria->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXSong );
  1176             findCriteria->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXSong );
   914             RArray<TMPXAttribute> attrs;
  1178             RArray<TMPXAttribute> attrs;
   915             CleanupClosePushL( attrs );
  1179             CleanupClosePushL( attrs );
   916             attrs.Append( TMPXAttribute( KMPXMediaIdGeneral,
  1180             attrs.Append( TMPXAttribute( KMPXMediaIdGeneral,
   917                                          EMPXMediaGeneralTitle |
  1181                                          EMPXMediaGeneralTitle |
   918                                          EMPXMediaGeneralId ) );
  1182                                          EMPXMediaGeneralId ) );
   919             if ( collectionData->context() == ECollectionContextArtists ){
       
   920                 attrs.Append( KMPXMediaMusicArtist );
       
   921             }
       
   922             else {
       
   923                 attrs.Append( KMPXMediaMusicAlbumTrack );
       
   924             }
       
   925             results = iCollectionUtility->Collection().FindAllL( *findCriteria, attrs.Array() );
  1183             results = iCollectionUtility->Collection().FindAllL( *findCriteria, attrs.Array() );
   926             CleanupStack::PopAndDestroy( &attrs );
  1184             CleanupStack::PopAndDestroy( &attrs );
   927             CleanupStack::PopAndDestroy( findCriteria );
  1185             CleanupStack::PopAndDestroy( findCriteria );
   928             CleanupStack::PushL( results );
  1186             CleanupStack::PushL( results );
   929             
  1187             
   945             }
  1203             }
   946             CleanupStack::PopAndDestroy( results );
  1204             CleanupStack::PopAndDestroy( results );
   947         }
  1205         }
   948         
  1206         
   949     }
  1207     }
   950     else {   
  1208     else {
       
  1209         //Tracks
   951         for ( TInt i = 0; i < count; i++ ) {
  1210         for ( TInt i = 0; i < count; i++ ) {
   952             CMPXMedia* media( containerArray->AtL( selection.at( i ) ) );
  1211             CMPXMedia* media( mediaArray->AtL( selection.at( i ) ) );
   953             CMPXMedia* entry = CMPXMedia::NewL();
  1212             CMPXMedia* entry = CMPXMedia::NewL();
   954             CleanupStack::PushL( entry );
  1213             CleanupStack::PushL( entry );
   955             entry->SetTextValueL( KMPXMediaGeneralTitle,
  1214             entry->SetTextValueL( KMPXMediaGeneralTitle,
   956                 media->ValueText( KMPXMediaGeneralTitle ) );
  1215                 media->ValueText( KMPXMediaGeneralTitle ) );
   957             entry->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem );
  1216             entry->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem );
   965     }
  1224     }
   966     aMedia.SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem );
  1225     aMedia.SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem );
   967     aMedia.SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXPlaylist );
  1226     aMedia.SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXPlaylist );
   968     aMedia.SetCObjectValueL( KMPXMediaArrayContents, tracksArray );
  1227     aMedia.SetCObjectValueL( KMPXMediaArrayContents, tracksArray );
   969     aMedia.SetTObjectValueL( KMPXMediaArrayCount, tracksArray->Count() );
  1228     aMedia.SetTObjectValueL( KMPXMediaArrayCount, tracksArray->Count() );
   970 
  1229     if ( (tracksArray->Count() ) >= 100){  //Add Songs Progress Dialog for 100 songs or more
       
  1230         emit q_ptr->openAddSongsWaitDialog();
       
  1231     }
       
  1232     
   971     CleanupStack::PopAndDestroy( tracksArray );
  1233     CleanupStack::PopAndDestroy( tracksArray );
   972     TX_EXIT
  1234     TX_EXIT
   973 }
  1235 }
       
  1236 
       
  1237 /*!
       
  1238  \internal
       
  1239  TODO: all calls to playback utility should be done via the engine and trough the playback FW wrapper.
       
  1240  */
       
  1241 void MpMpxCollectionFrameworkWrapperPrivate::createPlaybackUtilityL() 
       
  1242 {
       
  1243     if ( !iPlaybackUtility ) {
       
  1244 
       
  1245         iPlaybackUtility = MMPXPlaybackUtility::UtilityL( mHostUid );
       
  1246 
       
  1247         if ( iShuffleFeature ) {
       
  1248             iPlaybackUtility->SetL( EPbPropertyRandomMode, MpSettingsManager::shuffle() ? ETrue : EFalse );
       
  1249         }
       
  1250         if ( iRepeatFeature ) {
       
  1251             iPlaybackUtility->SetL( EPbPropertyRepeatMode, MpSettingsManager::repeat() ? EPbRepeatAll : EPbRepeatOff );
       
  1252         }
       
  1253     }
       
  1254 }
       
  1255 
       
  1256 //EOF