From c85665fc8a26479c7313729ff7476d6f3d9363d8 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 8 Jun 2013 12:07:32 +0200 Subject: [PATCH] * Read chart position when loading TrackStats. --- .../database/DatabaseCommand_TrackStats.cpp | 27 +++++++++++++++++++ .../database/DatabaseCommand_TrackStats.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/libtomahawk/database/DatabaseCommand_TrackStats.cpp b/src/libtomahawk/database/DatabaseCommand_TrackStats.cpp index a8bf44973..7e9d3e9f6 100644 --- a/src/libtomahawk/database/DatabaseCommand_TrackStats.cpp +++ b/src/libtomahawk/database/DatabaseCommand_TrackStats.cpp @@ -50,6 +50,33 @@ DatabaseCommand_TrackStats::exec( DatabaseImpl* dbi ) if ( m_track->trackId() == 0 ) return; + query.prepare( "SELECT COUNT(*) AS counter, track.id " + "FROM playback_log, track " + "WHERE playback_log.source IS NULL AND track.id = playback_log.track " + "GROUP BY track.id " + "ORDER BY counter DESC" ); + query.exec(); + + unsigned int chartPos = 0; + unsigned int chartCount = 0; + const unsigned int trackId = m_track->trackId(); + + QHash< QString, unsigned int > charts; + while ( query.next() ) + { + chartCount++; + + if ( chartPos == 0 && query.value( 1 ).toUInt() == trackId ) + { + chartPos = chartCount; + } + } + + if ( chartPos == 0 ) + chartPos = chartCount; + + emit trackStats( chartPos, chartCount ); + query.prepare( "SELECT * " "FROM playback_log " "WHERE track = ? ORDER BY playtime ASC" ); diff --git a/src/libtomahawk/database/DatabaseCommand_TrackStats.h b/src/libtomahawk/database/DatabaseCommand_TrackStats.h index 1cf23eefe..f7e8f591e 100644 --- a/src/libtomahawk/database/DatabaseCommand_TrackStats.h +++ b/src/libtomahawk/database/DatabaseCommand_TrackStats.h @@ -39,6 +39,7 @@ public: virtual QString commandname() const { return "trackstats"; } signals: + void trackStats( unsigned int totalPlays, unsigned int chartPosition ); void done( const QList< Tomahawk::PlaybackLog >& playbackData ); private: