mpdata/src/mpmpxcollectiondata_p.cpp
changeset 32 c163ef0b758d
parent 29 8192e5b5c935
child 38 b93f525c9244
equal deleted inserted replaced
29:8192e5b5c935 32:c163ef0b758d
   193 }
   193 }
   194 
   194 
   195 /*!
   195 /*!
   196  \internal
   196  \internal
   197  */
   197  */
   198 int MpMpxCollectionDataPrivate::itemId(int index)
   198 int MpMpxCollectionDataPrivate::itemId( int index )
   199 {
   199 {
   200     TX_ENTRY_ARGS("index=" << index);
   200     TX_ENTRY_ARGS( "index=" << index );
   201     int id = -1;
   201     int id = -1;
   202     TRAPD(err, id = DoGetItemIdL(index));
   202     TRAPD( err, id = DoGetItemIdL( index ) );
   203     if ( err == KErrNone ) {
   203     if ( err == KErrNone ) {
   204         TX_LOG_ARGS("id=" << id);
   204         TX_LOG_ARGS( "id=" << id );
   205     }
   205     }
   206     else {
   206     else {
   207         TX_LOG_ARGS("Error: " << err << "; should never get here.");
   207         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
   208     }
       
   209     TX_EXIT
       
   210     return id;
       
   211 }
       
   212 
       
   213 /*!
       
   214  \internal
       
   215  */
       
   216 int MpMpxCollectionDataPrivate::albumSongId( int index )
       
   217 {
       
   218     TX_ENTRY_ARGS( "index=" << index );
       
   219     int id = -1;
       
   220     TRAPD( err, id = DoGetAlbumSongIdL( index ) );
       
   221     if ( err == KErrNone ) {
       
   222         TX_LOG_ARGS( "id=" << id );
       
   223     }
       
   224     else {
       
   225         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
   208     }
   226     }
   209     TX_EXIT
   227     TX_EXIT
   210     return id;
   228     return id;
   211 }
   229 }
   212 
   230 
   406  */
   424  */
   407 void MpMpxCollectionDataPrivate::setContext( TCollectionContext context )
   425 void MpMpxCollectionDataPrivate::setContext( TCollectionContext context )
   408 {
   426 {
   409     iContext = context;
   427     iContext = context;
   410     TX_LOG_ARGS("Context changed: iContext=" << iContext);
   428     TX_LOG_ARGS("Context changed: iContext=" << iContext);
   411     
   429     loadAlbumsLookup();
       
   430     emit q_ptr->contextChanged(iContext);
       
   431 }
       
   432 
       
   433 /*!
       
   434  \internal
       
   435  */
       
   436 void MpMpxCollectionDataPrivate::setAlbumContent( const CMPXMedia& albumContent )
       
   437 {
       
   438     TX_ENTRY
       
   439     TRAPD(err, DoSetAlbumContentL(albumContent));
       
   440     if ( err == KErrNone ) {
       
   441         TX_LOG_ARGS("Album content is available.");
       
   442         loadAlbumSongsLookup();
       
   443         emit q_ptr->refreshAlbumSongs();
       
   444     }
       
   445     else {
       
   446         TX_LOG_ARGS("Error: " << err << "; should never get here.");
       
   447     }
       
   448     TX_EXIT
       
   449 }
       
   450 
       
   451 /*!
       
   452  \internal
       
   453    Currently only used to lookup playing song album id to index of albums on 
       
   454    media wall.
       
   455  */
       
   456 int MpMpxCollectionDataPrivate::itemIndex( int itemUniqueId )
       
   457 {
       
   458     return albumIdIndexMapping.value( itemUniqueId, -1 );
       
   459 }
       
   460 
       
   461 /*!
       
   462  \internal
       
   463    Currently only used to lookup playing song id to index of song in the 
       
   464    current album on media wall.
       
   465  */
       
   466 int MpMpxCollectionDataPrivate::albumSongIndex( int songUniqueId )
       
   467 {
       
   468     return albumSongIdIndexMapping.value( songUniqueId, -1 );
       
   469 }
       
   470 
       
   471 
       
   472 /*!
       
   473  \internal
       
   474  */
       
   475 void MpMpxCollectionDataPrivate::loadAlbumsLookup()
       
   476 {
   412     //Clearing all the album ids.
   477     //Clearing all the album ids.
   413     albumIdIndexMapping.clear();
   478     albumIdIndexMapping.clear();
   414     if ( iContext == ECollectionContextAlbumsMediaWall) {
   479     if ( iContext == ECollectionContextAlbumsMediaWall) {
   415         //Adding album ids and indixes to the hash, for itemIndex lookup.
   480         //Adding album ids and indixes to the hash, for itemIndex lookup.
   416         //This is disabled for other containers to save resources.
   481         //This is disabled for other containers to save resources.
   417         for ( int i = count() - 1 ; i >= 0 ; i-- ) {
   482         for ( int i = count() - 1 ; i >= 0 ; i-- ) {
   418             albumIdIndexMapping.insert( itemId( i ) , i );
   483             albumIdIndexMapping.insert( itemId( i ) , i );
   419         }
   484         }
   420     }
   485     }
   421     
   486 }
   422     emit q_ptr->contextChanged(iContext);
   487 
   423 }
   488 /*!
   424 
   489  \internal
   425 /*!
   490  */
   426  \internal
   491 void MpMpxCollectionDataPrivate::loadAlbumSongsLookup()
   427  */
   492 {
   428 void MpMpxCollectionDataPrivate::setAlbumContent( const CMPXMedia& albumContent )
   493     //Clearing all the song ids.
   429 {
   494     albumSongIdIndexMapping.clear();
   430     TX_ENTRY
   495     if ( iContext == ECollectionContextAlbumsMediaWall) {
   431     TRAPD(err, DoSetAlbumContentL(albumContent));
   496         //Adding album song ids and indixes to the hash, for albumSongIndex lookup.
   432     if ( err == KErrNone ) {
   497         //This is disabled for other containers to save resources.
   433         TX_LOG_ARGS("Album content is available.");
   498         for ( int i = albumSongsCount() - 1 ; i >= 0 ; i-- ) {
   434         emit q_ptr->refreshAlbumSongs();
   499             albumSongIdIndexMapping.insert( albumSongId( i ) , i );
   435     }
   500         }
   436     else {
   501     }
   437         TX_LOG_ARGS("Error: " << err << "; should never get here.");
       
   438     }
       
   439     TX_EXIT
       
   440 }
       
   441 
       
   442 /*!
       
   443  \internal
       
   444    Currently only used to lookup playing song album id to index of albums on 
       
   445    media wall.
       
   446  */
       
   447 int MpMpxCollectionDataPrivate::itemIndex( int itemUniqueId )
       
   448 {
       
   449     return albumIdIndexMapping.value( itemUniqueId );
       
   450 }
   502 }
   451 
   503 
   452 /*!
   504 /*!
   453  \internal
   505  \internal
   454  */
   506  */
   586 }
   638 }
   587 
   639 
   588 /*!
   640 /*!
   589  \internal
   641  \internal
   590  */
   642  */
       
   643 int MpMpxCollectionDataPrivate::DoGetAlbumSongIdL( int index )
       
   644 {
       
   645     CMPXMedia* album( iMediaArray->AtL( iCurrentAlbumIndex ) );
       
   646     const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   647     User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs));
       
   648     CMPXMedia* song = songs->AtL(index);
       
   649     if ( !song->IsSupported( KMPXMediaGeneralId ) ) {
       
   650         User::Leave(KErrNotFound);
       
   651     }
       
   652     return song->ValueTObjectL<TInt>( KMPXMediaGeneralId );
       
   653 }
       
   654 
       
   655 /*!
       
   656  \internal
       
   657  */
   591 void MpMpxCollectionDataPrivate::DoRemoveItemL( int index )
   658 void MpMpxCollectionDataPrivate::DoRemoveItemL( int index )
   592 {
   659 {
   593     delete iCachedRemovedItem;
   660     delete iCachedRemovedItem;
   594     iCachedRemovedItem = 0;
   661     iCachedRemovedItem = 0;
   595     iCachedRemovedItem = CMPXMedia::NewL( *iMediaArray->AtL( index ) );
   662     iCachedRemovedItem = CMPXMedia::NewL( *iMediaArray->AtL( index ) );
   622         // all we do now is populate the list with the song titles.
   689         // all we do now is populate the list with the song titles.
   623         const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents);
   690         const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents);
   624         iAlbumSongCount = songs->Count();
   691         iAlbumSongCount = songs->Count();
   625         songsAvailable = true;
   692         songsAvailable = true;
   626         TX_LOG_ARGS("Songs available.");
   693         TX_LOG_ARGS("Songs available.");
       
   694         loadAlbumSongsLookup();
   627         emit q_ptr->refreshAlbumSongs();
   695         emit q_ptr->refreshAlbumSongs();
   628     }
   696     }
   629     TX_EXIT
   697     TX_EXIT
   630     return songsAvailable;
   698     return songsAvailable;
   631 }
   699 }