180 mCollectionData = mMpEngine->collectionData(); |
180 mCollectionData = mMpEngine->collectionData(); |
181 qRegisterMetaType<TCollectionContext>("TCollectionContext"); |
181 qRegisterMetaType<TCollectionContext>("TCollectionContext"); |
182 connect( mCollectionData, SIGNAL( contextChanged( TCollectionContext ) ), |
182 connect( mCollectionData, SIGNAL( contextChanged( TCollectionContext ) ), |
183 this, SLOT( setContext( TCollectionContext ) ), |
183 this, SLOT( setContext( TCollectionContext ) ), |
184 Qt::QueuedConnection ); |
184 Qt::QueuedConnection ); |
185 mCollectionDataModel = new MpCollectionDataModel( mCollectionData ); |
185 mCollectionDataModel = new MpCollectionDataModel( mCollectionData , mMpEngine->playbackData()); |
186 |
186 |
187 connect( mCollectionDataModel, SIGNAL( dataReloaded() ), |
187 connect( mCollectionDataModel, SIGNAL( dataReloaded() ), |
188 this, SLOT( containerDataChanged() ) ); |
188 this, SLOT( containerDataChanged() ) ); |
189 |
189 |
190 mDocumentLoader = new MpCollectionDocumentLoader(); |
190 mDocumentLoader = new MpCollectionDocumentLoader(); |
287 mActivated = false; |
287 mActivated = false; |
288 |
288 |
289 closeActiveDialog( true ); |
289 closeActiveDialog( true ); |
290 |
290 |
291 setNavigationAction( 0 ); |
291 setNavigationAction( 0 ); |
292 TX_EXIT |
|
293 } |
|
294 |
|
295 /*! |
|
296 Sets the default collection - AllSongs |
|
297 */ |
|
298 void MpCollectionView::setDefaultView() |
|
299 { |
|
300 TX_ENTRY |
|
301 if ( mCollectionContext != ECollectionContextAllSongs ) { |
|
302 // Open 'All Songs' by default |
|
303 mMpEngine->openCollection( ECollectionContextAllSongs ); |
|
304 } |
|
305 |
|
306 |
|
307 TX_EXIT |
292 TX_EXIT |
308 } |
293 } |
309 |
294 |
310 /*! |
295 /*! |
311 Returns view activation status. |
296 Returns view activation status. |
456 switch ( mCollectionContext ) { |
441 switch ( mCollectionContext ) { |
457 case ECollectionContextAllSongs: |
442 case ECollectionContextAllSongs: |
458 case ECollectionContextArtistAllSongs: |
443 case ECollectionContextArtistAllSongs: |
459 case ECollectionContextPlaylistSongs: |
444 case ECollectionContextPlaylistSongs: |
460 doOpen = false; |
445 doOpen = false; |
461 songUri = mCollectionData->itemData( index, MpMpxCollectionData::Uri ); |
446 if (!mCollectionData->hasItemProperty(index, MpMpxCollectionData::Corrupted)) { |
462 emit songSelected( songUri ); |
447 songUri = mCollectionData->itemData( index, MpMpxCollectionData::Uri ); |
|
448 emit songSelected( songUri ); |
|
449 } |
|
450 else { |
|
451 showCorruptedNote(); |
|
452 } |
463 break; |
453 break; |
464 case ECollectionContextArtistAlbumsTBone: |
454 case ECollectionContextArtistAlbumsTBone: |
465 case ECollectionContextAlbumsTBone: |
455 case ECollectionContextAlbumsTBone: |
466 doOpen = false; |
456 doOpen = false; |
467 songUri = mCollectionData->albumSongData( index, MpMpxCollectionData::Uri ); |
457 if (!mCollectionData->hasAlbumSongProperty(index, MpMpxCollectionData::Corrupted)) { |
468 emit songSelected( songUri ); |
458 songUri = mCollectionData->albumSongData( index, MpMpxCollectionData::Uri ); |
|
459 emit songSelected( songUri ); |
|
460 } |
|
461 else { |
|
462 showCorruptedNote(); |
|
463 } |
469 break; |
464 break; |
470 default: |
465 default: |
471 break; |
466 break; |
472 } |
467 } |
473 } |
468 } |
487 // Album view going into T-bone. We don't actually open the |
482 // Album view going into T-bone. We don't actually open the |
488 // collection. Just fake an open. |
483 // collection. Just fake an open. |
489 mCollectionData->setContext( ECollectionContextAlbumsTBone ); |
484 mCollectionData->setContext( ECollectionContextAlbumsTBone ); |
490 } |
485 } |
491 else { |
486 else { |
492 // Real open. Forward it to the engine. |
487 switch ( mCollectionContext ) { |
493 mMpEngine->openCollectionItem( index ); |
488 case ECollectionContextAllSongs: |
|
489 case ECollectionContextArtistAllSongs: |
|
490 case ECollectionContextPlaylistSongs: |
|
491 if (!mCollectionData->hasItemProperty(index, MpMpxCollectionData::Corrupted)) { |
|
492 mMpEngine->openCollectionItem( index ); |
|
493 } |
|
494 else { |
|
495 showCorruptedNote(); |
|
496 } |
|
497 break; |
|
498 case ECollectionContextArtists: |
|
499 case ECollectionContextPlaylists: |
|
500 mMpEngine->openCollectionItem( index ); |
|
501 default: |
|
502 break; |
|
503 } |
494 } |
504 } |
495 } |
505 } |
496 TX_EXIT |
506 TX_EXIT |
497 } |
507 } |
498 |
508 |
512 play album with \a albumIndex starting with the songs with \a songIndex. |
522 play album with \a albumIndex starting with the songs with \a songIndex. |
513 */ |
523 */ |
514 void MpCollectionView::playAlbumSongs( int albumIndex, int songIndex ) |
524 void MpCollectionView::playAlbumSongs( int albumIndex, int songIndex ) |
515 { |
525 { |
516 TX_ENTRY_ARGS( "albumIndex=" << albumIndex << "songIndex=" << songIndex ); |
526 TX_ENTRY_ARGS( "albumIndex=" << albumIndex << "songIndex=" << songIndex ); |
517 mMpEngine->playAlbumSongs(albumIndex, songIndex); |
527 if (!mCollectionData->hasAlbumSongProperty(songIndex, MpMpxCollectionData::Corrupted)) { |
|
528 mMpEngine->playAlbumSongs(albumIndex, songIndex); |
|
529 } |
|
530 else { |
|
531 showCorruptedNote(); |
|
532 } |
518 TX_EXIT |
533 TX_EXIT |
519 } |
534 } |
520 |
535 |
521 /*! |
536 /*! |
522 Slot to be called when back/quit softkey is pressed. |
537 Slot to be called when back/quit softkey is pressed. |
618 /*! |
633 /*! |
619 Slot to be called when 'Shuffle play all' is clicked by the user from the menu. |
634 Slot to be called when 'Shuffle play all' is clicked by the user from the menu. |
620 */ |
635 */ |
621 void MpCollectionView::shufflePlayAll() |
636 void MpCollectionView::shufflePlayAll() |
622 { |
637 { |
|
638 TX_ENTRY |
623 mMpEngine->setShuffle( true ); |
639 mMpEngine->setShuffle( true ); |
624 MpSettingsManager::setShuffle( true ); |
640 MpSettingsManager::setShuffle( true ); |
625 int index = generateShuffleIndex(); |
641 int index = generateShuffleIndex(); |
626 switch ( mCollectionContext ) { |
642 switch ( mCollectionContext ) { |
627 case ECollectionContextArtistAlbumsTBone: |
643 case ECollectionContextArtistAlbumsTBone: |
793 mActivationWaiting = false; |
810 mActivationWaiting = false; |
794 activateView(); |
811 activateView(); |
795 } |
812 } |
796 else { |
813 else { |
797 closeActiveDialog(); |
814 closeActiveDialog(); |
798 |
815 |
799 //Update cache, even if collection is in background. |
816 // Update cache, even if collection is in background. |
800 //Library refreshing could be triggered at any point due USB/MMC events. |
817 // Library refreshing could be triggered at any point due USB/MMC events. |
801 mMpEngine->reopenCollection(); |
818 if ( mCollectionContext == ECollectionContextAllSongs ) { |
|
819 mMpEngine->reopenCollection(); |
|
820 } |
|
821 // We force to go to the all songs collection when the refresh is finished. |
|
822 else{ |
|
823 openSongs(); |
|
824 } |
802 } |
825 } |
803 TX_EXIT |
826 TX_EXIT |
804 } |
827 } |
805 |
828 |
806 /*! |
829 /*! |
1174 void MpCollectionView::setBannerVisibility( bool visible ) |
1197 void MpCollectionView::setBannerVisibility( bool visible ) |
1175 { |
1198 { |
1176 bool ok = false; |
1199 bool ok = false; |
1177 if ( visible ) { |
1200 if ( visible ) { |
1178 mDocumentLoader->load( MUSIC_COLLECTION_DOCML, "showBanner", &ok ); |
1201 mDocumentLoader->load( MUSIC_COLLECTION_DOCML, "showBanner", &ok ); |
1179 mNowPlayingBanner->show(); |
|
1180 } |
1202 } |
1181 else { |
1203 else { |
1182 mDocumentLoader->load( MUSIC_COLLECTION_DOCML, "hideBanner", &ok ); |
1204 mDocumentLoader->load( MUSIC_COLLECTION_DOCML, "hideBanner", &ok ); |
1183 mNowPlayingBanner->hide(); |
|
1184 } |
1205 } |
1185 |
1206 |
1186 if ( !ok ) { |
1207 if ( !ok ) { |
1187 TX_LOG_ARGS( "Error: invalid xml file." ); |
1208 TX_LOG_ARGS( "Error: invalid xml file." ); |
1188 Q_ASSERT_X( ok, "MpCollectionView::setBannerVisibility", "invalid xml file" ); |
1209 Q_ASSERT_X( ok, "MpCollectionView::setBannerVisibility", "invalid xml file" ); |
1189 } |
1210 } |
1190 } |
1211 } |
1191 |
1212 |
1192 /*! |
1213 /*! |
1193 \internal |
1214 \internal |
1194 Generates a random index for shuffle all. |
1215 Generates a random index for shuffle all. In case of All Songs, due to incremental open |
|
1216 delay, the chosen index may not be available yet. In such case, narrow down the upper limit |
|
1217 and regenerate until a valid index is found. |
1195 */ |
1218 */ |
1196 int MpCollectionView::generateShuffleIndex() |
1219 int MpCollectionView::generateShuffleIndex() |
1197 { |
1220 { |
1198 int low = 0; |
1221 int low = 0; |
1199 int high = 0; |
1222 int high = 0; |
|
1223 bool tbone; |
1200 switch ( mCollectionContext ) { |
1224 switch ( mCollectionContext ) { |
1201 case ECollectionContextArtistAlbumsTBone: |
1225 case ECollectionContextArtistAlbumsTBone: |
1202 case ECollectionContextAlbumsTBone: |
1226 case ECollectionContextAlbumsTBone: |
|
1227 tbone = true; |
1203 high = mCollectionData->albumSongsCount(); |
1228 high = mCollectionData->albumSongsCount(); |
1204 break; |
1229 break; |
1205 default: |
1230 default: |
|
1231 tbone = false; |
1206 high = mCollectionData->count(); |
1232 high = mCollectionData->count(); |
1207 break; |
1233 break; |
1208 } |
1234 } |
1209 |
1235 |
|
1236 bool validIndex = false; |
|
1237 int index = 0; |
|
1238 int songId; |
1210 time_t seconds; |
1239 time_t seconds; |
1211 time( &seconds ); |
1240 while ( !validIndex ) { |
1212 srand( ( unsigned int ) seconds ); |
1241 time( &seconds ); |
1213 |
1242 srand( ( unsigned int ) seconds ); |
1214 int index = rand() % ( high - low + 1 ) + low; |
1243 index = rand() % ( high - low + 1 ) + low; |
|
1244 |
|
1245 if ( tbone ) { |
|
1246 songId = mCollectionData->albumSongId(index); |
|
1247 } |
|
1248 else { |
|
1249 songId = mCollectionData->itemId(index); |
|
1250 } |
|
1251 |
|
1252 if ( songId != -1 ) { |
|
1253 // Got a valid index; exit the loop. |
|
1254 validIndex = true; |
|
1255 } |
|
1256 else { |
|
1257 // Invalid index; re-select an index, but narrow down the |
|
1258 // upper range to increase the change of hitting a valid index. |
|
1259 high = index; |
|
1260 } |
|
1261 TX_LOG_ARGS( "index=" << index << "valid=" << validIndex ); |
|
1262 } |
1215 return index; |
1263 return index; |
1216 } |
1264 } |
1217 |
1265 |
1218 /*! |
1266 /*! |
1219 \internal |
1267 \internal |