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