PageRenderTime 113ms CodeModel.GetById 60ms app.highlight 10ms RepoModel.GetById 40ms app.codeStats 1ms

/src/libtomahawk/database/DatabaseCommand_LogPlayback.h

http://github.com/tomahawk-player/tomahawk
C Header | 110 lines | 70 code | 23 blank | 17 comment | 1 complexity | 910faa5bc16e55d6401a107c3fa38610 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *
  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.
  9 *
 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.
 14 *
 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/>.
 17 */
 18
 19#ifndef DATABASECOMMAND_LOGPLAYBACK_H
 20#define DATABASECOMMAND_LOGPLAYBACK_H
 21
 22#include <QObject>
 23#include <QVariantMap>
 24
 25#include "database/DatabaseCommandLoggable.h"
 26#include "SourceList.h"
 27#include "Typedefs.h"
 28#include "Artist.h"
 29#include "Track.h"
 30
 31#include "DllMacro.h"
 32
 33namespace Tomahawk
 34{
 35
 36class DLLEXPORT DatabaseCommand_LogPlayback : public DatabaseCommandLoggable
 37{
 38Q_OBJECT
 39Q_PROPERTY( QString artist READ artist WRITE setArtist )
 40Q_PROPERTY( QString track READ track WRITE setTrack )
 41Q_PROPERTY( unsigned int playtime READ playtime WRITE setPlaytime )
 42Q_PROPERTY( unsigned int secsPlayed READ secsPlayed WRITE setSecsPlayed )
 43Q_PROPERTY( unsigned int trackDuration READ trackDuration WRITE setTrackDuration )
 44Q_PROPERTY( int action READ action WRITE setAction )
 45
 46public:
 47    enum Action
 48    {
 49        Started = 1,
 50        Finished = 2
 51    };
 52
 53    explicit DatabaseCommand_LogPlayback( QObject* parent = 0 )
 54        : DatabaseCommandLoggable( parent ), m_secsPlayed( 0 ), m_playtime( 0 ), m_trackDuration( 0 )
 55    {}
 56
 57    explicit DatabaseCommand_LogPlayback( const Tomahawk::track_ptr& track, Action action, unsigned int secsPlayed = 0, unsigned int timeStamp = 0, QObject* parent = 0 )
 58        : DatabaseCommandLoggable( parent ), m_secsPlayed( secsPlayed ), m_playtime( timeStamp ), m_action( action )
 59    {
 60        m_trackDuration = track->duration();
 61        setSource( SourceList::instance()->getLocal() );
 62
 63        setArtist( track->artist() );
 64        setTrack( track->track() );
 65    }
 66
 67    virtual QString commandname() const { return "logplayback"; }
 68
 69    virtual void exec( DatabaseImpl* );
 70    virtual void postCommitHook();
 71
 72    virtual bool doesMutates() const { return true; }
 73    virtual bool singletonCmd() const { return ( m_action == Started ); }
 74    virtual bool localOnly() const;
 75    virtual bool groupable() const { return true; }
 76
 77    QString artist() const { return m_artist; }
 78    void setArtist( const QString& s ) { m_artist = s; }
 79
 80    QString track() const { return m_track; }
 81    void setTrack( const QString& s ) { m_track = s; }
 82
 83    unsigned int playtime() const { return m_playtime; }
 84    void setPlaytime( unsigned int i ) { m_playtime = i; }
 85
 86    unsigned int secsPlayed() const { return m_secsPlayed; }
 87    void setSecsPlayed( unsigned int i ) { m_secsPlayed = i; }
 88
 89    unsigned int trackDuration() const { return m_trackDuration; }
 90    void setTrackDuration( unsigned int trackDuration ) { m_trackDuration = trackDuration; }
 91
 92    int action() const { return m_action; }
 93    void setAction( int a ) { m_action = (Action)a; }
 94
 95signals:
 96    void trackPlaying( const Tomahawk::track_ptr& track, unsigned int duration );
 97    void trackPlayed( const Tomahawk::track_ptr& track, const Tomahawk::PlaybackLog& log );
 98
 99private:
100    QString m_artist;
101    QString m_track;
102    unsigned int m_secsPlayed;
103    unsigned int m_playtime;
104    unsigned int m_trackDuration;
105    Action m_action;
106};
107
108}
109
110#endif // DATABASECOMMAND_LOGPLAYBACK_H