PageRenderTime 29ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/src/libtomahawk/database/DatabaseCommand_SocialAction.h

http://github.com/tomahawk-player/tomahawk
C Header | 194 lines | 60 code | 28 blank | 106 comment | 0 complexity | 4d16a3e134b7c87d963b9fa80497457f MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2011, Christopher Reichert <creichert07@gmail.com>
  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_SOCIALACTION_H
 20#define DATABASECOMMAND_SOCIALACTION_H
 21
 22#include <QDateTime>
 23#include "database/DatabaseCommandLoggable.h"
 24
 25#include "SourceList.h"
 26#include "Typedefs.h"
 27#include "Artist.h"
 28#include "Track.h"
 29
 30#include "DllMacro.h"
 31
 32namespace Tomahawk
 33{
 34
 35/**
 36 * \class DatabaseCommand_SocialAction
 37 * \brief Database command used to write social actions to database.
 38 *
 39 * This Database command allows Tomahawk to write social actions to
 40 * the local database. These social actions can be interfaced with social
 41 * networking API's such as LastFm, Facebook, or Twitter to allow the user
 42 * to sync these actions with their accounts on these sites.
 43 *
 44 * \see DatabaseCommand_LoadSocialActions
 45 */
 46class DLLEXPORT DatabaseCommand_SocialAction : public DatabaseCommandLoggable
 47{
 48    Q_OBJECT
 49    Q_PROPERTY( QString action READ action WRITE setAction )
 50    Q_PROPERTY( QString comment READ comment WRITE setComment )
 51    Q_PROPERTY( int timestamp READ timestamp WRITE setTimestamp )
 52    Q_PROPERTY( QString artist READ artist WRITE setArtist )
 53    Q_PROPERTY( QString track READ track WRITE setTrack )
 54
 55public:
 56
 57    /**
 58     * \brief Default constructor for DatabaseCommand_SocialAction.
 59     *
 60     * Constructs an empty database command for a social action.
 61     */
 62    explicit DatabaseCommand_SocialAction( QObject* parent = 0 )
 63        : DatabaseCommandLoggable( parent )
 64    {}
 65
 66    /**
 67     * \brief Overloaded constructor for DatabaseCommand_SocialAction.
 68     * \param track A Tomahawk Track object.
 69     * \param action Name of the social action to be written to the database.
 70     * \param comment Comment associated with this social action.
 71     * \param parent Parent class.
 72     *
 73     * Constructor which creates a new database command for the specified social action.
 74     */
 75    explicit DatabaseCommand_SocialAction( const Tomahawk::trackdata_ptr& track, QString action, QString comment = QString(), QObject* parent = 0 )
 76        : DatabaseCommandLoggable( parent )
 77        , m_track( track )
 78        , m_comment( comment )
 79        , m_action( action )
 80    {
 81        setSource( SourceList::instance()->getLocal() );
 82
 83        m_artist = track->artist();
 84        m_title = track->track();
 85        m_timestamp = QDateTime::currentDateTime().toTime_t();
 86    }
 87
 88    /**
 89     * \brief Returns the name of this database command.
 90     * \return QString containing the database command name 'socialaction'.
 91     */
 92    QString commandname() const Q_DECL_OVERRIDE { return "socialaction"; }
 93
 94    /**
 95     * \brief Executes the database command.
 96     * \param dbi Database instance.
 97     *
 98     * This method prepares an sql query to write this social action
 99     * into the local database.
100     */
101    void exec( DatabaseImpl* dbi ) Q_DECL_OVERRIDE;
102
103    /**
104     * \brief Triggers a Database Sync.
105     */
106    void postCommitHook() Q_DECL_OVERRIDE;
107
108    /**
109     * \brief Returns the artist associated with this database command.
110     * \return Name of the artist.
111     * \see setArtist()
112     */
113    virtual QString artist() const { return m_artist; }
114
115    /**
116     * \brief Sets the artist name for this database command.
117     * \param s QString containing the artist name.
118     * \see artist()
119     */
120    virtual void setArtist( const QString& s ) { m_artist = s; }
121
122    /**
123     * \brief Returns the track name associated with this social action.
124     * \return QString containing the track name.
125     * \see setTrack()
126     */
127    virtual QString track() const { return m_title; }
128
129    /**
130     * \brief Sets the track name associated with this database command.
131     * \param track QString containing the track name.
132     * \see track()
133     */
134    virtual void setTrack( const QString& title ) { m_title = title; }
135
136    /**
137     * \brief Returns the social action for this database command instance.
138     * \return QString containing the action name.
139     * \see setAction()
140     */
141    QString action() const { return m_action; }
142
143    /**
144     * \brief Sets the social actions
145     * \param a QString containing action to be set in this class.
146     * \see action()
147     */
148    void setAction( QString a ) { m_action = a; }
149
150    /**
151     * \brief Returns comment associated with this social action.
152     * \return QString containing comment associated with this social action.
153     * \see setComment()
154     */
155    virtual QString comment() const { return m_comment; }
156
157    /**
158     * \brief Sets the comment associated with this social action.
159     * \param com Comment associated with this social action.
160     * \see comment()
161     */
162    virtual void setComment( const QString& com ) { m_comment = com; }
163
164    /**
165     * \brief Returns the timestamp associated with this social action.
166     * \return unsigned integer containing timestamp
167     * \see setTimesetamp()
168     */
169    virtual int timestamp() const { return m_timestamp; }
170
171    /**
172     * \brief Sets the timestamp associated with this social action.
173     * \param ts unsigned integer associated with this social action.
174     * \see timestamp()
175     */
176    virtual void setTimestamp( const int ts ) { m_timestamp = ts; }
177
178    bool doesMutates() const Q_DECL_OVERRIDE { return true; }
179    bool groupable() const Q_DECL_OVERRIDE { return true; }
180
181protected:
182    Tomahawk::trackdata_ptr m_track;
183
184private:
185    QString m_artist;
186    QString m_title;
187    int m_timestamp;
188    QString m_comment;
189    QString m_action; //! currently used values: Love, Inbox
190};
191
192}
193
194#endif // DATABASECOMMAND_SOCIALACTION_H