//! ----------------------- Get tracks method ---------------------------------- QList<MEDIA::TrackPtr> LocalTrackModel::getItemChildrenTracks(const MEDIA::MediaPtr parent) { //Debug::debug() << " [LocalTrackModel] getItemChildrenTracks"; QList<MEDIA::TrackPtr> result; if(!parent) return result; MEDIA::MediaPtr media = parent; if (media->type() == TYPE_TRACK) { SearchEngine se; bool match = se.mediaMatch( qvariant_cast<MediaSearch>(m_search), MEDIA::TrackPtr::staticCast(media) ); if(match) result.append( MEDIA::TrackPtr::staticCast(media) ); } else { //! Recursive !! for (int i = 0; i < media->childCount(); i++) { result.append( getItemChildrenTracks(media->child(i)) ); } } return result; }
void BrowserView::jump_to_media(MEDIA::MediaPtr media) { VIEW::Id mode; if(!media) return; if(media->type() == TYPE_ARTIST) mode = VIEW::ViewArtist; else if(media->type() == TYPE_ALBUM) mode = VIEW::ViewAlbum; else if(media->type() == TYPE_TRACK) mode = VIEW::ViewTrack; else return; CentralToolBar::instance()->setExplorerFilterText(""); m_scenes[VIEW::ViewArtist]->setFilter(""); m_scenes[VIEW::ViewTuneIn]->setFilter(""); m_scenes[VIEW::ViewFileSystem]->setFilter(""); active_view(mode,"", QVariant()); /* localise item */ QPoint p = static_cast<LocalScene*>(m_scenes[mode])->get_item_position(media); if(!p.isNull()) this->verticalScrollBar()->setSliderPosition( p.y() - 40 ); }
/******************************************************************************* slot_jump_to_media *******************************************************************************/ void BrowserView::slot_jump_to_media() { //Debug::debug() << " [BrowserView] slot_jump_to_media"; QAction *action = qobject_cast<QAction *>(sender()); if(!action) return; MEDIA::MediaPtr media; if(action == ACTIONS()->value(BROWSER_JUMP_TO_MEDIA)) { media = qvariant_cast<MEDIA::MediaPtr>( (ACTIONS()->value(BROWSER_JUMP_TO_MEDIA))->data() ); jump_to_media(media); } else { media = Engine::instance()->playingTrack(); if(!media) return; if(!media->parent()) return; MEDIA::MediaPtr album = media->parent(); MEDIA::MediaPtr artist = album->parent(); if(action == ACTIONS()->value(BROWSER_JUMP_TO_TRACK)) jump_to_media(media); else if(action == ACTIONS()->value(BROWSER_JUMP_TO_ALBUM)) jump_to_media(album); else if(action == ACTIONS()->value(BROWSER_JUMP_TO_ARTIST)) jump_to_media(artist); } }
//! ------------------------- filtering method --------------------------------- bool LocalTrackModel::isMediaMatch(MEDIA::MediaPtr media) { if(m_search.isNull()) return true; if (media->type() == TYPE_TRACK) { SearchEngine se; bool match = se.mediaMatch( qvariant_cast<MediaSearch>(m_search), MEDIA::TrackPtr::staticCast(media) ); if(match) return true; } else { for (int i = 0; i < media->childCount(); i++) if( isMediaMatch( media->child(i) ) ) return true; } return false; }
//! ----------------------- Get rating method ---------------------------------- float LocalTrackModel::getItemAutoRating(const MEDIA::MediaPtr media) { float auto_rating = 0.0; int count = 0; if(!media) return auto_rating; if (media->type() == TYPE_TRACK) { //Debug::debug() << " => getItemAutoRating : return track rating = " << media->data.rating; return MEDIA::TrackPtr::staticCast(media)->rating; } else { //! Recursive !! for (/*count*/; count < media->childCount(); count++) { auto_rating += getItemAutoRating( media->child(count) ); } } float result = media->childCount()!=0 ? float(auto_rating/(media->childCount())) : 0 ; result = double(int(result * 5 * 2 + 0.5)) / (5 * 2); //Debug::debug() << " => getItemAutoRating : rating = " << result; return result; }