From 0bde2a55213c613bdd9e942dc3ba2738a73e84ee Mon Sep 17 00:00:00 2001
From: Christian Muehlhaeuser <muesli@gmail.com>
Date: Mon, 22 Apr 2013 09:23:54 +0200
Subject: [PATCH] * Now-Playing signals can use tracks instead.

---
 src/libtomahawk/Source.cpp                  | 20 ++++++++++----------
 src/libtomahawk/Source.h                    |  8 ++++----
 src/libtomahawk/SourcePlaylistInterface.cpp |  6 ++++--
 src/libtomahawk/SourcePlaylistInterface.h   |  2 +-
 4 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp
index ccfc1669c..1dd523862 100644
--- a/src/libtomahawk/Source.cpp
+++ b/src/libtomahawk/Source.cpp
@@ -227,10 +227,10 @@ Source::avatar( TomahawkUtils::ImageMode style, const QSize& size )
 //     tLog() << "****************************************************************************************";
 //     tLog() << peerInfos().count() << "PEERS FOR " << friendlyName();
     QPixmap result;
-    foreach( const peerinfo_ptr& peerInfo, peerInfos() )
+    foreach ( const peerinfo_ptr& peerInfo, peerInfos() )
     {
 //         peerInfoDebug(peerInfo) << !peerInfo->avatar().isNull();
-        if( !peerInfo.isNull() && !peerInfo->avatar( style, size ).isNull() )
+        if ( !peerInfo.isNull() && !peerInfo->avatar( style, size ).isNull() )
         {
             result =  peerInfo->avatar( style, size );
             break;
@@ -443,26 +443,26 @@ Source::playlistInterface()
 
 
 void
-Source::onPlaybackStarted( const Tomahawk::query_ptr& query, unsigned int duration )
+Source::onPlaybackStarted( const Tomahawk::track_ptr& track, unsigned int duration )
 {
-    tLog( LOGVERBOSE ) << Q_FUNC_INFO << query->toString();
+    tLog( LOGVERBOSE ) << Q_FUNC_INFO << track->toString();
 
-    m_currentTrack = query;
+    m_currentTrack = track->toQuery();
     m_currentTrackTimer.start( duration * 1000 + 900000 ); // duration comes in seconds
 
     if ( m_playlistInterface.isNull() )
         playlistInterface();
 
-    emit playbackStarted( query );
+    emit playbackStarted( track );
     emit stateChanged();
 }
 
 
 void
-Source::onPlaybackFinished( const Tomahawk::query_ptr& query )
+Source::onPlaybackFinished( const Tomahawk::track_ptr& track, unsigned int playtime, unsigned int secsPlayed )
 {
-    tDebug() << Q_FUNC_INFO << query->toString();
-    emit playbackFinished( query );
+    tDebug() << Q_FUNC_INFO << track->toString();
+    emit playbackFinished( track, playtime, secsPlayed );
 
     m_currentTrack.clear();
     emit stateChanged();
@@ -625,7 +625,7 @@ Source::textStatus() const
 
     if ( !currentTrack().isNull() )
     {
-        return currentTrack()->artist() + " - " + currentTrack()->track();
+        return currentTrack()->queryTrack()->artist() + " - " + currentTrack()->queryTrack()->track();
     }
 
     // do not use isOnline() here - it will always return true for the local source
diff --git a/src/libtomahawk/Source.h b/src/libtomahawk/Source.h
index 8b46033ed..0f93c8f86 100644
--- a/src/libtomahawk/Source.h
+++ b/src/libtomahawk/Source.h
@@ -113,8 +113,8 @@ signals:
 
     void stats( const QVariantMap& );
 
-    void playbackStarted( const Tomahawk::query_ptr& query );
-    void playbackFinished( const Tomahawk::query_ptr& query );
+    void playbackStarted( const Tomahawk::track_ptr& track );
+    void playbackFinished( const Tomahawk::track_ptr& track, unsigned int playtime, unsigned int secsPlayed );
 
     void stateChanged();
     void commandsFinished();
@@ -138,8 +138,8 @@ private slots:
 
     void onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::State oldstate, const QString& info );
 
-    void onPlaybackStarted( const Tomahawk::query_ptr& query, unsigned int duration );
-    void onPlaybackFinished( const Tomahawk::query_ptr& query );
+    void onPlaybackStarted( const Tomahawk::track_ptr& track, unsigned int duration );
+    void onPlaybackFinished( const Tomahawk::track_ptr& track, unsigned int playtime, unsigned int secsPlayed );
     void trackTimerFired();
 
     void executeCommands();
diff --git a/src/libtomahawk/SourcePlaylistInterface.cpp b/src/libtomahawk/SourcePlaylistInterface.cpp
index 04066b486..810869048 100644
--- a/src/libtomahawk/SourcePlaylistInterface.cpp
+++ b/src/libtomahawk/SourcePlaylistInterface.cpp
@@ -37,7 +37,7 @@ SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::Source* source, Toma
     setLatchMode( latchMode );
 
     if ( !m_source.isNull() )
-        connect( m_source.data(), SIGNAL( playbackStarted( const Tomahawk::query_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::query_ptr& ) ) );
+        connect( m_source.data(), SIGNAL( playbackStarted( const Tomahawk::track_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::track_ptr& ) ) );
 
     if ( AudioEngine::instance() )
         connect( AudioEngine::instance(), SIGNAL( paused() ), SLOT( audioPaused() ) );
@@ -164,9 +164,11 @@ SourcePlaylistInterface::reset()
 
 
 void
-SourcePlaylistInterface::onSourcePlaybackStarted( const Tomahawk::query_ptr& query )
+SourcePlaylistInterface::onSourcePlaybackStarted( const Tomahawk::track_ptr& track )
 {
     tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
+
+    query_ptr query = track->toQuery();
     connect( query.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( resolvingFinished( bool ) ) );
     Pipeline::instance()->resolve( query );
     m_gotNextItem = false;
diff --git a/src/libtomahawk/SourcePlaylistInterface.h b/src/libtomahawk/SourcePlaylistInterface.h
index 38fb20cad..4da706c95 100644
--- a/src/libtomahawk/SourcePlaylistInterface.h
+++ b/src/libtomahawk/SourcePlaylistInterface.h
@@ -75,7 +75,7 @@ public slots:
     virtual void audioPaused() { setLatchMode( PlaylistModes::StayOnSong ); }
 
 private slots:
-    void onSourcePlaybackStarted( const Tomahawk::query_ptr& query );
+    void onSourcePlaybackStarted( const Tomahawk::track_ptr& track );
     void resolvingFinished( bool hasResults );
 
 private: