PageRenderTime 174ms CodeModel.GetById 81ms app.highlight 15ms RepoModel.GetById 75ms app.codeStats 1ms

/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
 21#ifndef DYNAMIC_PLAYLIST_H
 22#define DYNAMIC_PLAYLIST_H
 23
 24#include "playlist/dynamic/DynamicControl.h"
 25#include "playlist/dynamic/DynamicPlaylistRevision.h"
 26
 27#include "DllMacro.h"
 28#include "Playlist.h"
 29#include "Typedefs.h"
 30
 31#include <QObject>
 32#include <QList>
 33#include <QSharedPointer>
 34
 35namespace Tomahawk
 36{
 37
 38class DatabaseCollection;
 39class DatabaseCommand_LoadAllDynamicPlaylists;
 40class DatabaseCommand_SetDynamicPlaylistRevision;
 41class DatabaseCommand_CreateDynamicPlaylist;
 42class DatabaseCommand_LoadAllSortedPlaylists;
 43
 44class DatabaseCommand_LoadDynamicPlaylist;
 45class DynamicPlaylistPrivate;
 46
 47class DLLEXPORT DynamicPlaylist : public Tomahawk::Playlist
 48{
 49    Q_OBJECT
 50
 51    // :-( int becuase qjson chokes on my enums
 52    Q_PROPERTY( int     mode                  WRITE setMode   READ mode )
 53    Q_PROPERTY( QString type                  WRITE setType   READ type )
 54    Q_PROPERTY( bool    autoLoad                              READ autoLoad )
 55
 56    friend class DatabaseCommand_SetDynamicPlaylistRevision;
 57    friend class DatabaseCommand_CreateDynamicPlaylist;
 58    friend class Tomahawk::DatabaseCommand_LoadDynamicPlaylist;
 59    friend class DatabaseCommand_LoadAllSortedPlaylists;
 60    friend class DatabaseCollection; /// :-(
 61
 62public:
 63    virtual ~DynamicPlaylist();
 64
 65    static Tomahawk::dynplaylist_ptr get( const QString& guid );
 66
 67    /// Generate an empty dynamic playlist with default generator
 68    static Tomahawk::dynplaylist_ptr create( const source_ptr& author,
 69                                             const QString& guid,
 70                                             const QString& title,
 71                                             const QString& info,
 72                                             const QString& creator,
 73                                             GeneratorMode mode,
 74                                             bool shared,
 75                                             const QString& type = QString(),
 76                                             bool autoLoad = true
 77                                           );
 78
 79    static void remove( const dynplaylist_ptr& playlist );
 80    virtual void loadRevision( const QString& rev = "" );
 81
 82    // :-( int becuase qjson chokes on my enums
 83    int mode() const;
 84    QString type() const;
 85    geninterface_ptr generator() const;
 86    bool autoLoad() const;
 87
 88    // Creates a new revision from the playlist in memory. Use this is you change the controls or
 89    // mode of a playlist and want to save it to db/others.
 90    void createNewRevision( const QString& uuid = QString() );
 91
 92    virtual void addEntries( const QList< query_ptr >& queries );
 93    virtual void addEntry( const Tomahawk::query_ptr& query );
 94
 95    // <IGNORE hack="true">
 96    // these need to exist and be public for the json serialization stuff
 97    // you SHOULD NOT call them.  They are used for an alternate CTOR method from json.
 98    // maybe friend QObjectHelper and make them private?
 99    explicit DynamicPlaylist( const source_ptr& author, const QString& type );
100    void setMode( int mode );
101    void setType( const QString& /*type*/ ) { /** TODO */; }
102    void setGenerator( const geninterface_ptr& gen_ptr );
103    // </IGNORE>
104
105signals:
106    /// emitted when the playlist revision changes (whenever the playlist changes)
107    void dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision );
108
109    void aboutToBeDeleted( const Tomahawk::dynplaylist_ptr& pl );
110    void deleted( const Tomahawk::dynplaylist_ptr& pl );
111
112public slots:
113    // want to update the playlist from the model?
114    // generate a newrev using uuid() and call this:
115    // if this is a static playlist, pass it a new list of entries. implicitly sets mode to static
116    void createNewRevision( const QString& newrev, const QString& oldrev, const QString& type, const QList< dyncontrol_ptr>& controls, const QList< plentry_ptr >& entries );
117    // if it is ondemand, no entries are needed implicitly sets mode to ondemand
118    void createNewRevision( const QString& newrev, const QString& oldrev, const QString& type, const QList< dyncontrol_ptr>& controls );
119
120    void reportCreated( const Tomahawk::dynplaylist_ptr& self );
121    void reportDeleted( const Tomahawk::dynplaylist_ptr& self );
122
123    // called from setdynamicplaylistrevision db cmd
124    // 4 options, because dbcmds can't create qwidgets:
125    // static version,   qvariant controls
126    // static version,   dyncontrol_ptr controls
127    // ondemand version, qvariant controls
128    // ondemand version, dyncontrol_ptr controls
129    void setRevision( const QString& rev,
130                      const QList<QString>& neworderedguids,
131                      const QList<QString>& oldorderedguids,
132                      const QString& type,
133                      const QList< QVariantMap >& controls,
134                      bool is_newest_rev,
135                      const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
136                      bool applied );
137    void setRevision( const QString& rev,
138                      const QList<QString>& neworderedguids,
139                      const QList<QString>& oldorderedguids,
140                      const QString& type,
141                      const QList< Tomahawk::dyncontrol_ptr >& controls,
142                      bool is_newest_rev,
143                      const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
144                      bool applied );
145    // ondemand version
146    void setRevision( const QString& rev,
147                      bool is_newest_rev,
148                      const QString& type,
149                      const QList< QVariantMap>& controls,
150                      bool applied );
151    void setRevision( const QString& rev,
152                      bool is_newest_rev,
153                      const QString& type,
154                      const QList< Tomahawk::dyncontrol_ptr>& controls,
155                      bool applied );
156
157    void setWeakSelf( QWeakPointer< DynamicPlaylist > self );
158
159protected:
160    virtual void removeFromDatabase();
161
162private:
163    // called from loadAllPlaylists DB cmd via databasecollection (in GUI thread)
164    explicit DynamicPlaylist( const source_ptr& src,
165                              const QString& currentrevision,
166                              const QString& title,
167                              const QString& info,
168                              const QString& creator,
169                              uint createdOn,
170                              const QString& type,
171                              GeneratorMode mode,
172                              bool shared,
173                              int lastmod,
174                              const QString& guid = "" ); // populate db
175
176    // called when creating new playlist
177    explicit DynamicPlaylist( const source_ptr& author,
178                              const QString& guid,
179                              const QString& title,
180                              const QString& info,
181                              const QString& creator,
182                              const QString& type,
183                              GeneratorMode mode,
184                              bool shared,
185                              bool autoLoad = true );
186
187    void checkRevisionQueue();
188
189    QList< dyncontrol_ptr > variantsToControl( const QList< QVariantMap >& controlsV );
190
191    Q_DECLARE_PRIVATE( DynamicPlaylist )
192};
193
194} // namespace
195
196Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::DynamicPlaylist > )
197
198#endif