diff --git a/src/libtomahawk/ArtistPlaylistInterface.cpp b/src/libtomahawk/ArtistPlaylistInterface.cpp index 031de4368..033093930 100644 --- a/src/libtomahawk/ArtistPlaylistInterface.cpp +++ b/src/libtomahawk/ArtistPlaylistInterface.cpp @@ -54,22 +54,18 @@ ArtistPlaylistInterface::~ArtistPlaylistInterface() void ArtistPlaylistInterface::setCurrentIndex( qint64 index ) { - Q_UNUSED( index ); - Q_ASSERT( false ); - -/* m_currentTrack = index; - m_currentItem = m_queries.at( index )->results().first();*/ + m_currentTrack = index; + m_currentItem = m_queries.at( index )->results().first(); } qint64 ArtistPlaylistInterface::siblingIndex( int itemsAway, qint64 rootIndex ) const { - Q_UNUSED( itemsAway ); - Q_UNUSED( rootIndex ); - Q_ASSERT( false ); + qint64 p = m_currentTrack; + if ( rootIndex >= 0 ) + p = rootIndex; -/* qint64 p = m_currentTrack; p += itemsAway; if ( p < 0 ) @@ -78,9 +74,7 @@ ArtistPlaylistInterface::siblingIndex( int itemsAway, qint64 rootIndex ) const if ( p >= m_queries.count() ) return -1; - return p;*/ - - return -1; + return p; } @@ -232,3 +226,58 @@ ArtistPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks ) m_finished = true; emit tracksLoaded( m_mode, m_collection ); } + + +qint64 +ArtistPlaylistInterface::indexOfResult( const Tomahawk::result_ptr& result ) const +{ + int i = 0; + foreach ( const Tomahawk::query_ptr& query, m_queries ) + { + if ( query->numResults() && query->results().contains( result ) ) + return i; + + i++; + } + + return -1; +} + + +qint64 +ArtistPlaylistInterface::indexOfQuery( const Tomahawk::query_ptr& query ) const +{ + int i = 0; + foreach ( const Tomahawk::query_ptr& q, m_queries ) + { + if ( q->equals( query ) ) + return i; + + i++; + } + + return -1; +} + + +query_ptr +ArtistPlaylistInterface::queryAt( qint64 index ) const +{ + if ( index >= 0 && index < m_queries.count() ) + { + return m_queries.at( index ); + } + + return Tomahawk::query_ptr(); +} + + +result_ptr +ArtistPlaylistInterface::resultAt( qint64 index ) const +{ + Tomahawk::query_ptr query = queryAt( index ); + if ( query && query->numResults() ) + return query->results().first(); + + return Tomahawk::result_ptr(); +} diff --git a/src/libtomahawk/ArtistPlaylistInterface.h b/src/libtomahawk/ArtistPlaylistInterface.h index 369ca9f30..dd0508a51 100644 --- a/src/libtomahawk/ArtistPlaylistInterface.h +++ b/src/libtomahawk/ArtistPlaylistInterface.h @@ -45,10 +45,10 @@ public: virtual void setCurrentIndex( qint64 index ); virtual qint64 siblingIndex( int itemsAway, qint64 rootIndex = -1 ) const; - virtual Tomahawk::result_ptr resultAt( qint64 index ) const { Q_UNUSED( index ); Q_ASSERT( false ); return Tomahawk::result_ptr(); } - virtual Tomahawk::query_ptr queryAt( qint64 index ) const { Q_UNUSED( index ); Q_ASSERT( false ); return Tomahawk::query_ptr(); } - virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const { Q_UNUSED( result ); Q_ASSERT( false ); return -1; } - virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const { Q_UNUSED( query ); Q_ASSERT( false ); return -1; } + virtual Tomahawk::result_ptr resultAt( qint64 index ) const; + virtual Tomahawk::query_ptr queryAt( qint64 index ) const; + virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const; + virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const; virtual Tomahawk::result_ptr currentItem() const;