/src/libtomahawk/database/DatabaseCommand_LoadSocialActions.h

http://github.com/tomahawk-player/tomahawk · C Header · 123 lines · 42 code · 18 blank · 63 comment · 0 complexity · 258c1e7175288c5bd85e2e9b18ef5c88 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. * Copyright 2012, Leo Franchi <lfranchi@kde.org>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef DATABASECOMMAND_LOADSOCIALACTIONS_H
  20. #define DATABASECOMMAND_LOADSOCIALACTIONS_H
  21. #include <QDateTime>
  22. #include <QList>
  23. #include "database/DatabaseCommand.h"
  24. #include "SourceList.h"
  25. #include "Typedefs.h"
  26. #include "Artist.h"
  27. #include "Track.h"
  28. #include "DllMacro.h"
  29. namespace Tomahawk
  30. {
  31. /**
  32. * \class DatabaseCommand_LoadSocialActions
  33. * \brief Database command used to load social actions from the database.
  34. *
  35. * This Database command allows Tomahawk to load social actions from
  36. * the local database. The loaded social actions can be used to create
  37. * dynamic playlists, generate statistics and provide data to share with
  38. * friends on tomahawk.
  39. *
  40. * \see DatabaseCommand_SocialAction
  41. */
  42. class DLLEXPORT DatabaseCommand_LoadSocialActions : public DatabaseCommand
  43. {
  44. Q_OBJECT
  45. public:
  46. typedef QMap<Tomahawk::track_ptr, Tomahawk::SocialAction> TrackActions;
  47. /**
  48. * \brief Default constructor for DatabaseCommand_LoadSocialActions.
  49. *
  50. * Constructs an empty database command for loading social actions.
  51. */
  52. explicit DatabaseCommand_LoadSocialActions( QObject* parent = 0 )
  53. : DatabaseCommand( parent )
  54. {}
  55. /**
  56. * \brief Overloaded constructor for DatabaseCommand_LoadSocialAction.
  57. * \param result A Tomahawk Query object.
  58. * \param parent Parent class.
  59. *
  60. * Constructor which creates a new database command for loading all social actions.
  61. */
  62. explicit DatabaseCommand_LoadSocialActions( const Tomahawk::trackdata_ptr& track, QObject* parent = 0 )
  63. : DatabaseCommand( parent ), m_track( track )
  64. {
  65. setSource( SourceList::instance()->getLocal() );
  66. }
  67. /**
  68. * Load all tracks with a specific social action
  69. */
  70. explicit DatabaseCommand_LoadSocialActions( const QString& action, const Tomahawk::source_ptr& source, QObject* parent = 0 )
  71. : DatabaseCommand( parent ), m_actionOnly( action )
  72. {
  73. setSource( source );
  74. qRegisterMetaType<TrackActions>( "DatabaseCommand_LoadSocialActions::TrackActions" );
  75. }
  76. /**
  77. * \brief Returns the name of this database command.
  78. * \return QString containing the database command name 'loadsocialaction'.
  79. */
  80. virtual QString commandname() const { return "loadsocialactions"; }
  81. /**
  82. * \brief Executes the database command.
  83. * \param dbi Database instance.
  84. *
  85. * This method prepares an sql query to load the social actions
  86. * from the database into a list of all social actions.
  87. *
  88. * \see Result::setAllSocialActions()
  89. */
  90. virtual void exec( DatabaseImpl* );
  91. virtual bool doesMutates() const { return false; }
  92. signals:
  93. /**
  94. * All loaded social actions for each track found, for queries that generate all tracks
  95. * with matching actions.
  96. */
  97. void done( DatabaseCommand_LoadSocialActions::TrackActions actionsForTracks );
  98. private:
  99. Tomahawk::trackdata_ptr m_track;
  100. QString m_actionOnly;
  101. };
  102. }
  103. //FIXME: Qt5: this fails with Qt5, is it needed at all? It compiles fine without in Qt4 as well
  104. // Q_DECLARE_METATYPE( DatabaseCommand_LoadSocialActions::TrackActions )
  105. #endif // DATABASECOMMAND_LOADSOCIALACTIONS_H