diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index c77b302e5..afeed00ef 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -151,6 +151,7 @@ set( libGuiSources widgets/infowidgets/SourceInfoWidget.cpp widgets/infowidgets/ArtistInfoWidget.cpp widgets/infowidgets/AlbumInfoWidget.cpp + widgets/infowidgets/TrackInfoWidget.cpp widgets/Breadcrumb.cpp widgets/BreadcrumbButton.cpp ) @@ -218,6 +219,7 @@ set( libSources database/DatabaseCommand_AddSource.cpp database/DatabaseCommand_SourceOffline.cpp database/DatabaseCommand_CollectionStats.cpp + database/DatabaseCommand_TrackStats.cpp database/DatabaseCommand_LoadPlaylistEntries.cpp database/DatabaseCommand_ModifyPlaylist.cpp database/DatabaseCommand_PlaybackHistory.cpp @@ -312,6 +314,7 @@ set( libUI ${libUI} widgets/infowidgets/SourceInfoWidget.ui widgets/infowidgets/ArtistInfoWidget.ui widgets/infowidgets/AlbumInfoWidget.ui + widgets/infowidgets/TrackInfoWidget.ui playlist/topbar/TopBar.ui playlist/QueueView.ui context/ContextWidget.ui diff --git a/src/libtomahawk/database/DatabaseCommand_TrackStats.cpp b/src/libtomahawk/database/DatabaseCommand_TrackStats.cpp new file mode 100644 index 000000000..a85397dee --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_TrackStats.cpp @@ -0,0 +1,90 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "DatabaseCommand_TrackStats.h" + +#include "DatabaseImpl.h" +#include "SourceList.h" +#include "utils/Logger.h" + +using namespace Tomahawk; + + +DatabaseCommand_TrackStats::DatabaseCommand_TrackStats( const query_ptr& query, QObject* parent ) + : DatabaseCommand( parent ) + , m_query( query ) +{ +} + + +DatabaseCommand_TrackStats::DatabaseCommand_TrackStats( const artist_ptr& artist, QObject* parent ) + : DatabaseCommand( parent ) + , m_artist( artist ) +{ +} + + +void +DatabaseCommand_TrackStats::exec( DatabaseImpl* dbi ) +{ + TomahawkSqlQuery query = dbi->newquery(); + + if ( !m_query.isNull() ) + { + int artid = dbi->artistId( m_query->artist(), false ); + if( artid < 1 ) + return; + + int trkid = dbi->trackId( artid, m_query->track(), false ); + if( trkid < 1 ) + return; + + query.prepare( "SELECT * " + "FROM playback_log " + "WHERE track = ?" ); + query.addBindValue( trkid ); + query.exec(); + } + else if ( !m_artist.isNull() ) + { + query.prepare( "SELECT playback_log.* " + "FROM playback_log, track " + "WHERE playback_log.track = track.id AND track.artist = ?" ); + query.addBindValue( m_artist->id() ); + query.exec(); + } + + QList< Tomahawk::PlaybackLog > playbackData; + while ( query.next() ) + { + Tomahawk::PlaybackLog log; + log.source = SourceList::instance()->get( query.value( 1 ).toInt() ); // source + log.timestamp = query.value( 3 ).toUInt(); + log.secsPlayed = query.value( 4 ).toUInt(); + + if ( !log.source.isNull() ) + playbackData.append( log ); + } + + if ( !m_query.isNull() ) + m_query->setPlaybackHistory( playbackData ); + else + m_artist->setPlaybackHistory( playbackData ); + + emit done( playbackData ); +} diff --git a/src/libtomahawk/database/DatabaseCommand_TrackStats.h b/src/libtomahawk/database/DatabaseCommand_TrackStats.h new file mode 100644 index 000000000..2b8b5483b --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_TrackStats.h @@ -0,0 +1,51 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef DATABASECOMMAND_TRACKSTATS_H +#define DATABASECOMMAND_TRACKSTATS_H + +#include + +#include "DatabaseCommand.h" +#include "Typedefs.h" +#include "Query.h" +#include "Artist.h" + +#include "DllMacro.h" + +class DLLEXPORT DatabaseCommand_TrackStats : public DatabaseCommand +{ +Q_OBJECT + +public: + explicit DatabaseCommand_TrackStats( const Tomahawk::query_ptr& query, QObject* parent = 0 ); + explicit DatabaseCommand_TrackStats( const Tomahawk::artist_ptr& artist, QObject* parent = 0 ); + + virtual void exec( DatabaseImpl* lib ); + virtual bool doesMutates() const { return false; } + virtual QString commandname() const { return "trackstats"; } + +signals: + void done( QList< Tomahawk::PlaybackLog >& playbackData ); + +private: + Tomahawk::query_ptr m_query; + Tomahawk::artist_ptr m_artist; +}; + +#endif // DATABASECOMMAND_TRACKSTATS_H