1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
5
* Tomahawk is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Tomahawk is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
19
#ifndef DATABASECOMMAND_LOGPLAYBACK_H
20
#define DATABASECOMMAND_LOGPLAYBACK_H
23
#include <QVariantMap>
25
#include "database/DatabaseCommandLoggable.h"
26
#include "SourceList.h"
33
class DLLEXPORT DatabaseCommand_LogPlayback : public DatabaseCommandLoggable
36
Q_PROPERTY( QString artist READ artist WRITE setArtist )
37
Q_PROPERTY( QString track READ track WRITE setTrack )
38
Q_PROPERTY( unsigned int playtime READ playtime WRITE setPlaytime )
39
Q_PROPERTY( unsigned int secsPlayed READ secsPlayed WRITE setSecsPlayed )
40
Q_PROPERTY( unsigned int trackDuration READ trackDuration WRITE setTrackDuration )
41
Q_PROPERTY( int action READ action WRITE setAction )
50
explicit DatabaseCommand_LogPlayback( QObject* parent = 0 )
51
: DatabaseCommandLoggable( parent ), m_playtime( 0 ), m_secsPlayed( 0 ), m_trackDuration( 0 )
54
explicit DatabaseCommand_LogPlayback( const Tomahawk::query_ptr& query, Action action, uint timeStamp, QObject* parent = 0 )
55
: DatabaseCommandLoggable( parent ), m_query( query ), m_secsPlayed( 0 ), m_action( action )
57
m_playtime = timeStamp;
59
setSource( SourceList::instance()->getLocal() );
61
setArtist( query->artist() );
62
setTrack( query->track() );
65
explicit DatabaseCommand_LogPlayback( const Tomahawk::result_ptr& result, Action action, unsigned int secsPlayed = 0, QObject* parent = 0 )
66
: DatabaseCommandLoggable( parent ), m_result( result ), m_secsPlayed( secsPlayed ), m_action( action )
68
m_playtime = QDateTime::currentDateTimeUtc().toTime_t();
69
m_trackDuration = result->duration();
70
setSource( SourceList::instance()->getLocal() );
72
setArtist( result->artist()->name() );
73
setTrack( result->track() );
76
virtual QString commandname() const { return "logplayback"; }
78
virtual void exec( DatabaseImpl* );
79
virtual void postCommitHook();
81
virtual bool doesMutates() const { return true; }
82
virtual bool singletonCmd() const { return ( m_action == Started ); }
83
virtual bool localOnly() const;
84
virtual bool groupable() const { return true; }
86
QString artist() const { return m_artist; }
87
void setArtist( const QString& s ) { m_artist = s; }
89
QString track() const { return m_track; }
90
void setTrack( const QString& s ) { m_track = s; }
92
unsigned int playtime() const { return m_playtime; }
93
void setPlaytime( unsigned int i ) { m_playtime = i; }
95
unsigned int secsPlayed() const { return m_secsPlayed; }
96
void setSecsPlayed( unsigned int i ) { m_secsPlayed = i; }
98
unsigned int trackDuration() const { return m_trackDuration; }
99
void setTrackDuration( unsigned int trackDuration ) { m_trackDuration = trackDuration; }
101
int action() const { return m_action; }
102
void setAction( int a ) { m_action = (Action)a; }
105
void trackPlaying( const Tomahawk::query_ptr& query, unsigned int duration );
106
void trackPlayed( const Tomahawk::query_ptr& query );
109
Tomahawk::result_ptr m_result;
110
Tomahawk::query_ptr m_query;
114
unsigned int m_playtime;
115
unsigned int m_secsPlayed;
116
unsigned int m_trackDuration;
120
#endif // DATABASECOMMAND_LOGPLAYBACK_H