From 27b4c0b2c4a9c556132146d2dcd00f233df46360 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 28 Nov 2012 10:49:43 +0100 Subject: [PATCH] * Fixed Listening Along. --- src/libtomahawk/SourcePlaylistInterface.cpp | 49 ++++++++++++++------- src/libtomahawk/SourcePlaylistInterface.h | 2 +- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/libtomahawk/SourcePlaylistInterface.cpp b/src/libtomahawk/SourcePlaylistInterface.cpp index 0e62bfb03..5e10f3b25 100644 --- a/src/libtomahawk/SourcePlaylistInterface.cpp +++ b/src/libtomahawk/SourcePlaylistInterface.cpp @@ -28,7 +28,7 @@ using namespace Tomahawk; -SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::Source *source, Tomahawk::PlaylistModes::LatchMode latchMode ) +SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::Source* source, Tomahawk::PlaylistModes::LatchMode latchMode ) : PlaylistInterface() , m_source( source ) , m_currentItem( 0 ) @@ -53,7 +53,18 @@ SourcePlaylistInterface::~SourcePlaylistInterface() void SourcePlaylistInterface::setCurrentIndex( qint64 index ) { - Q_UNUSED( index ); + if ( index == 1 ) + m_gotNextItem = false; +} + + +qint64 +SourcePlaylistInterface::indexOfResult( const Tomahawk::result_ptr& result ) const +{ + if ( nextResult() == result ) + return 1; + else + return -1; } @@ -64,7 +75,7 @@ SourcePlaylistInterface::siblingIndex( int itemsAway, qint64 rootIndex ) const Q_UNUSED( rootIndex ); if ( nextResult() ) - return 0; + return 1; else return -1; } @@ -73,23 +84,22 @@ SourcePlaylistInterface::siblingIndex( int itemsAway, qint64 rootIndex ) const Tomahawk::result_ptr SourcePlaylistInterface::nextResult() const { - tDebug( LOGEXTRA ) << Q_FUNC_INFO; if ( !sourceValid() ) { - tDebug( LOGEXTRA ) << Q_FUNC_INFO << "Source no longer valid"; + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Source no longer valid"; m_currentItem = Tomahawk::result_ptr(); return m_currentItem; } else if ( !hasNextResult() ) { - tDebug( LOGEXTRA ) << Q_FUNC_INFO << "This song was already fetched or the source isn't playing anything"; + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "This song was already fetched or the source isn't playing anything"; return Tomahawk::result_ptr(); } - m_gotNextItem = false; - if ( m_source.data()->currentTrack()->numResults() ) + { m_currentItem = m_source.data()->currentTrack()->results().first(); + } else m_currentItem = result_ptr(); @@ -129,7 +139,10 @@ QList SourcePlaylistInterface::tracks() const { QList tracks; - return tracks; // FIXME (with what?) + if ( nextResult() ) + tracks << nextResult()->toQuery(); + + return tracks; } @@ -175,17 +188,21 @@ SourcePlaylistInterface::resolvingFinished( bool hasResults ) Tomahawk::query_ptr SourcePlaylistInterface::queryAt( qint64 index ) const { - Q_UNUSED( index ); - - Tomahawk::result_ptr res = nextResult(); - return res->toQuery(); + if ( index == 1 ) + { + Tomahawk::result_ptr res = nextResult(); + return res->toQuery(); + } + else + return Tomahawk::query_ptr(); } Tomahawk::result_ptr SourcePlaylistInterface::resultAt( qint64 index ) const { - Q_UNUSED( index ); - - return nextResult(); + if ( index == 1 ) + return nextResult(); + else + return Tomahawk::result_ptr(); } diff --git a/src/libtomahawk/SourcePlaylistInterface.h b/src/libtomahawk/SourcePlaylistInterface.h index 71debd955..4d0193afe 100644 --- a/src/libtomahawk/SourcePlaylistInterface.h +++ b/src/libtomahawk/SourcePlaylistInterface.h @@ -46,7 +46,7 @@ public: virtual void setCurrentIndex( qint64 index ); 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 { Q_UNUSED( result ); Q_ASSERT( false ); return -1; } + virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const; virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const { Q_UNUSED( query ); Q_ASSERT( false ); return -1; } virtual qint64 siblingIndex( int itemsAway, qint64 rootIndex = -1 ) const;