/src/libtomahawk/playlist/dynamic/DynamicPlaylist.h

http://github.com/tomahawk-player/tomahawk · C Header · 198 lines · 122 code · 33 blank · 43 comment · 0 complexity · c25a7ec63b037d1df6bb5cfdb439f295 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4. * Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5. * Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef DYNAMIC_PLAYLIST_H
  21. #define DYNAMIC_PLAYLIST_H
  22. #include "playlist/dynamic/DynamicControl.h"
  23. #include "playlist/dynamic/DynamicPlaylistRevision.h"
  24. #include "DllMacro.h"
  25. #include "Playlist.h"
  26. #include "Typedefs.h"
  27. #include <QObject>
  28. #include <QList>
  29. #include <QSharedPointer>
  30. namespace Tomahawk
  31. {
  32. class DatabaseCollection;
  33. class DatabaseCommand_LoadAllDynamicPlaylists;
  34. class DatabaseCommand_SetDynamicPlaylistRevision;
  35. class DatabaseCommand_CreateDynamicPlaylist;
  36. class DatabaseCommand_LoadAllSortedPlaylists;
  37. class DatabaseCommand_LoadDynamicPlaylist;
  38. class DynamicPlaylistPrivate;
  39. class DLLEXPORT DynamicPlaylist : public Tomahawk::Playlist
  40. {
  41. Q_OBJECT
  42. // :-( int becuase qjson chokes on my enums
  43. Q_PROPERTY( int mode WRITE setMode READ mode )
  44. Q_PROPERTY( QString type WRITE setType READ type )
  45. Q_PROPERTY( bool autoLoad READ autoLoad )
  46. friend class DatabaseCommand_SetDynamicPlaylistRevision;
  47. friend class DatabaseCommand_CreateDynamicPlaylist;
  48. friend class Tomahawk::DatabaseCommand_LoadDynamicPlaylist;
  49. friend class DatabaseCommand_LoadAllSortedPlaylists;
  50. friend class DatabaseCollection; /// :-(
  51. public:
  52. virtual ~DynamicPlaylist();
  53. static Tomahawk::dynplaylist_ptr get( const QString& guid );
  54. /// Generate an empty dynamic playlist with default generator
  55. static Tomahawk::dynplaylist_ptr create( const source_ptr& author,
  56. const QString& guid,
  57. const QString& title,
  58. const QString& info,
  59. const QString& creator,
  60. GeneratorMode mode,
  61. bool shared,
  62. const QString& type = QString(),
  63. bool autoLoad = true
  64. );
  65. static void remove( const dynplaylist_ptr& playlist );
  66. virtual void loadRevision( const QString& rev = "" );
  67. // :-( int becuase qjson chokes on my enums
  68. int mode() const;
  69. QString type() const;
  70. geninterface_ptr generator() const;
  71. bool autoLoad() const;
  72. // Creates a new revision from the playlist in memory. Use this is you change the controls or
  73. // mode of a playlist and want to save it to db/others.
  74. void createNewRevision( const QString& uuid = QString() );
  75. virtual void addEntries( const QList< query_ptr >& queries );
  76. virtual void addEntry( const Tomahawk::query_ptr& query );
  77. // <IGNORE hack="true">
  78. // these need to exist and be public for the json serialization stuff
  79. // you SHOULD NOT call them. They are used for an alternate CTOR method from json.
  80. // maybe friend QObjectHelper and make them private?
  81. explicit DynamicPlaylist( const source_ptr& author, const QString& type );
  82. void setMode( int mode );
  83. void setType( const QString& /*type*/ ) { /** TODO */; }
  84. void setGenerator( const geninterface_ptr& gen_ptr );
  85. // </IGNORE>
  86. signals:
  87. /// emitted when the playlist revision changes (whenever the playlist changes)
  88. void dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision );
  89. void aboutToBeDeleted( const Tomahawk::dynplaylist_ptr& pl );
  90. void deleted( const Tomahawk::dynplaylist_ptr& pl );
  91. public slots:
  92. // want to update the playlist from the model?
  93. // generate a newrev using uuid() and call this:
  94. // if this is a static playlist, pass it a new list of entries. implicitly sets mode to static
  95. void createNewRevision( const QString& newrev, const QString& oldrev, const QString& type, const QList< dyncontrol_ptr>& controls, const QList< plentry_ptr >& entries );
  96. // if it is ondemand, no entries are needed implicitly sets mode to ondemand
  97. void createNewRevision( const QString& newrev, const QString& oldrev, const QString& type, const QList< dyncontrol_ptr>& controls );
  98. void reportCreated( const Tomahawk::dynplaylist_ptr& self );
  99. void reportDeleted( const Tomahawk::dynplaylist_ptr& self );
  100. // called from setdynamicplaylistrevision db cmd
  101. // 4 options, because dbcmds can't create qwidgets:
  102. // static version, qvariant controls
  103. // static version, dyncontrol_ptr controls
  104. // ondemand version, qvariant controls
  105. // ondemand version, dyncontrol_ptr controls
  106. void setRevision( const QString& rev,
  107. const QList<QString>& neworderedguids,
  108. const QList<QString>& oldorderedguids,
  109. const QString& type,
  110. const QList< QVariantMap >& controls,
  111. bool is_newest_rev,
  112. const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
  113. bool applied );
  114. void setRevision( const QString& rev,
  115. const QList<QString>& neworderedguids,
  116. const QList<QString>& oldorderedguids,
  117. const QString& type,
  118. const QList< Tomahawk::dyncontrol_ptr >& controls,
  119. bool is_newest_rev,
  120. const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
  121. bool applied );
  122. // ondemand version
  123. void setRevision( const QString& rev,
  124. bool is_newest_rev,
  125. const QString& type,
  126. const QList< QVariantMap>& controls,
  127. bool applied );
  128. void setRevision( const QString& rev,
  129. bool is_newest_rev,
  130. const QString& type,
  131. const QList< Tomahawk::dyncontrol_ptr>& controls,
  132. bool applied );
  133. void setWeakSelf( QWeakPointer< DynamicPlaylist > self );
  134. protected:
  135. virtual void removeFromDatabase();
  136. private:
  137. // called from loadAllPlaylists DB cmd via databasecollection (in GUI thread)
  138. explicit DynamicPlaylist( const source_ptr& src,
  139. const QString& currentrevision,
  140. const QString& title,
  141. const QString& info,
  142. const QString& creator,
  143. uint createdOn,
  144. const QString& type,
  145. GeneratorMode mode,
  146. bool shared,
  147. int lastmod,
  148. const QString& guid = "" ); // populate db
  149. // called when creating new playlist
  150. explicit DynamicPlaylist( const source_ptr& author,
  151. const QString& guid,
  152. const QString& title,
  153. const QString& info,
  154. const QString& creator,
  155. const QString& type,
  156. GeneratorMode mode,
  157. bool shared,
  158. bool autoLoad = true );
  159. void checkRevisionQueue();
  160. QList< dyncontrol_ptr > variantsToControl( const QList< QVariantMap >& controlsV );
  161. Q_DECLARE_PRIVATE( DynamicPlaylist )
  162. };
  163. } // namespace
  164. Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::DynamicPlaylist > )
  165. #endif