~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/database/DatabaseCommand_LogPlayback.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "Query.h"
 
30
 
 
31
#include "DllMacro.h"
 
32
 
 
33
class DLLEXPORT DatabaseCommand_LogPlayback : public DatabaseCommandLoggable
 
34
{
 
35
Q_OBJECT
 
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 )
 
42
 
 
43
public:
 
44
    enum Action
 
45
    {
 
46
        Started = 1,
 
47
        Finished = 2
 
48
    };
 
49
 
 
50
    explicit DatabaseCommand_LogPlayback( QObject* parent = 0 )
 
51
        : DatabaseCommandLoggable( parent ), m_playtime( 0 ), m_secsPlayed( 0 ), m_trackDuration( 0 )
 
52
    {}
 
53
 
 
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 )
 
56
    {
 
57
        m_playtime = timeStamp;
 
58
        m_trackDuration = 0;
 
59
        setSource( SourceList::instance()->getLocal() );
 
60
 
 
61
        setArtist( query->artist() );
 
62
        setTrack( query->track() );
 
63
    }
 
64
 
 
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 )
 
67
    {
 
68
        m_playtime = QDateTime::currentDateTimeUtc().toTime_t();
 
69
        m_trackDuration = result->duration();
 
70
        setSource( SourceList::instance()->getLocal() );
 
71
 
 
72
        setArtist( result->artist()->name() );
 
73
        setTrack( result->track() );
 
74
    }
 
75
 
 
76
    virtual QString commandname() const { return "logplayback"; }
 
77
 
 
78
    virtual void exec( DatabaseImpl* );
 
79
    virtual void postCommitHook();
 
80
 
 
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; }
 
85
 
 
86
    QString artist() const { return m_artist; }
 
87
    void setArtist( const QString& s ) { m_artist = s; }
 
88
 
 
89
    QString track() const { return m_track; }
 
90
    void setTrack( const QString& s ) { m_track = s; }
 
91
 
 
92
    unsigned int playtime() const { return m_playtime; }
 
93
    void setPlaytime( unsigned int i ) { m_playtime = i; }
 
94
 
 
95
    unsigned int secsPlayed() const { return m_secsPlayed; }
 
96
    void setSecsPlayed( unsigned int i ) { m_secsPlayed = i; }
 
97
 
 
98
    unsigned int trackDuration() const { return m_trackDuration; }
 
99
    void setTrackDuration( unsigned int trackDuration ) { m_trackDuration = trackDuration; }
 
100
 
 
101
    int action() const { return m_action; }
 
102
    void setAction( int a ) { m_action = (Action)a; }
 
103
 
 
104
signals:
 
105
    void trackPlaying( const Tomahawk::query_ptr& query, unsigned int duration );
 
106
    void trackPlayed( const Tomahawk::query_ptr& query );
 
107
 
 
108
private:
 
109
    Tomahawk::result_ptr m_result;
 
110
    Tomahawk::query_ptr m_query;
 
111
 
 
112
    QString m_artist;
 
113
    QString m_track;
 
114
    unsigned int m_playtime;
 
115
    unsigned int m_secsPlayed;
 
116
    unsigned int m_trackDuration;
 
117
    Action m_action;
 
118
};
 
119
 
 
120
#endif // DATABASECOMMAND_LOGPLAYBACK_H