1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 16:29:43 +01:00

* Added DatabaseCommand_TrackStats. This will eventually be merged with PlaybackHistory.

This commit is contained in:
Christian Muehlhaeuser 2012-05-05 16:44:25 +02:00
parent b9e772f3e3
commit e27976c8a1
3 changed files with 144 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,90 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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 );
}

View File

@ -0,0 +1,51 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef DATABASECOMMAND_TRACKSTATS_H
#define DATABASECOMMAND_TRACKSTATS_H
#include <QVariantMap>
#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