1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
4
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
5
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
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.
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.
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/>.
27
#include <QSharedPointer>
32
#include "PlaylistInterface.h"
33
#include "playlist/PlaylistUpdaterInterface.h"
38
class SourceTreePopupDialog;
39
class DatabaseCommand_LoadAllPlaylists;
40
class DatabaseCommand_LoadAllSortedPlaylists;
41
class DatabaseCommand_SetPlaylistRevision;
42
class DatabaseCommand_CreatePlaylist;
48
class PlaylistUpdaterInterface;
50
class DLLEXPORT PlaylistEntry : public QObject
53
Q_PROPERTY( QString guid READ guid WRITE setGuid )
54
Q_PROPERTY( QString annotation READ annotation WRITE setAnnotation )
55
Q_PROPERTY( unsigned int duration READ duration WRITE setDuration )
56
Q_PROPERTY( unsigned int lastmodified READ lastmodified WRITE setLastmodified )
57
Q_PROPERTY( QVariant query READ queryVariant WRITE setQueryVariant )
61
virtual ~PlaylistEntry();
63
bool isValid() const { return !m_query.isNull(); }
65
void setQuery( const Tomahawk::query_ptr& q );
66
const Tomahawk::query_ptr& query() const;
68
void setQueryVariant( const QVariant& v );
69
QVariant queryVariant() const;
71
QString guid() const { return m_guid; }
72
void setGuid( const QString& s ) { m_guid = s; }
74
QString annotation() const { return m_annotation; }
75
void setAnnotation( const QString& s ) { m_annotation = s; }
77
QString resultHint() const { return m_resulthint; }
78
void setResultHint( const QString& s ) { m_resulthint= s; }
80
unsigned int duration() const { return m_duration; }
81
void setDuration( unsigned int i ) { m_duration = i; }
83
unsigned int lastmodified() const { return m_lastmodified; }
84
void setLastmodified( unsigned int i ) { m_lastmodified = i; }
86
source_ptr lastSource() const;
87
void setLastSource( source_ptr s );
91
Tomahawk::query_ptr m_query;
93
unsigned int m_duration;
94
unsigned int m_lastmodified;
95
source_ptr m_lastsource;
100
struct PlaylistRevision
102
QString revisionguid;
103
QString oldrevisionguid;
104
QList<plentry_ptr> newlist;
105
QList<plentry_ptr> added;
106
QList<plentry_ptr> removed;
107
bool applied; // false if conflict
110
struct RevisionQueueItem
115
QList< plentry_ptr > entries;
118
RevisionQueueItem( const QString& nRev, const QString& oRev, const QList< plentry_ptr >& e, bool latest ) :
119
newRev( nRev ), oldRev( oRev), entries( e ), applyToTip( latest ) {}
123
class DLLEXPORT Playlist : public QObject
126
Q_PROPERTY( QString guid READ guid WRITE setGuid )
127
Q_PROPERTY( QString currentrevision READ currentrevision WRITE setCurrentrevision )
128
Q_PROPERTY( QString title READ title WRITE setTitle )
129
Q_PROPERTY( QString info READ info WRITE setInfo )
130
Q_PROPERTY( QString creator READ creator WRITE setCreator )
131
Q_PROPERTY( unsigned int createdon READ createdOn WRITE setCreatedOn )
132
Q_PROPERTY( bool shared READ shared WRITE setShared )
134
friend class ::DatabaseCommand_LoadAllPlaylists;
135
friend class ::DatabaseCommand_LoadAllSortedPlaylists;
136
friend class ::DatabaseCommand_SetPlaylistRevision;
137
friend class ::DatabaseCommand_CreatePlaylist;
138
friend class DynamicPlaylist;
139
friend class ::PlaylistModel;
144
static Tomahawk::playlist_ptr load( const QString& guid );
146
// one CTOR is private, only called by DatabaseCommand_LoadAllPlaylists
147
static Tomahawk::playlist_ptr create( const source_ptr& author,
149
const QString& title,
151
const QString& creator,
153
const QList<Tomahawk::query_ptr>& queries = QList<Tomahawk::query_ptr>() );
155
static void remove( const playlist_ptr& playlist );
156
void rename( const QString& title );
158
virtual void loadRevision( const QString& rev = "" );
160
source_ptr author() const;
161
QString currentrevision() const { return m_currentrevision; }
162
QString title() const { return m_title; }
163
QString info() const { return m_info; }
164
QString creator() const { return m_creator; }
165
QString guid() const { return m_guid; }
166
bool shared() const { return m_shared; }
167
unsigned int lastmodified() const { return m_lastmodified; }
168
uint createdOn() const { return m_createdOn; }
170
bool busy() const { return m_busy; }
172
const QList< plentry_ptr >& entries() { return m_entries; }
173
virtual void addEntry( const Tomahawk::query_ptr& query, const QString& oldrev );
174
virtual void addEntries( const QList<Tomahawk::query_ptr>& queries, const QString& oldrev );
175
virtual void insertEntries( const QList<Tomahawk::query_ptr>& queries, const int position, const QString& oldrev );
177
// <IGNORE hack="true">
178
// these need to exist and be public for the json serialization stuff
179
// you SHOULD NOT call them. They are used for an alternate CTOR method from json.
180
// maybe friend QObjectHelper and make them private?
181
explicit Playlist( const source_ptr& author );
182
void setCurrentrevision( const QString& s ) { m_currentrevision = s; }
183
void setInfo( const QString& s ) { m_info = s; }
184
void setCreator( const QString& s ) { m_creator = s; }
185
void setGuid( const QString& s ) { m_guid = s; }
186
void setShared( bool b ) { m_shared = b; }
187
void setCreatedOn( uint createdOn ) { m_createdOn = createdOn; }
188
void setTitle( const QString& s );
192
QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst = false );
194
void addUpdater( PlaylistUpdaterInterface* updater );
195
void removeUpdater( PlaylistUpdaterInterface* updater );
196
QList<PlaylistUpdaterInterface*> updaters() const { return m_updaters; }
199
* Some updaters might have custom deleters in order to perform more actions that require
200
* user prompting on delete.
202
bool hasCustomDeleter() const;
204
* If this playlist has a custom deleter, let it do the deleting itself.
206
* If it needs user prompting, use the \param customDeleter as the right-most center point.
208
void customDelete( const QPoint& rightCenter );
210
Tomahawk::playlistinterface_ptr playlistInterface();
213
/// emitted when the playlist revision changes (whenever the playlist changes)
214
void revisionLoaded( Tomahawk::PlaylistRevision );
216
/// watch for this to see when newly created playlist is synced to DB (if you care)
221
void renamed( const QString& newTitle, const QString& oldTitle );
224
* delete command is scheduled but not completed. Do not call remove() again once this
227
void aboutToBeDeleted( const Tomahawk::playlist_ptr& pl );
230
void deleted( const Tomahawk::playlist_ptr& pl );
232
/// Notification for tracks being inserted at a specific point
233
/// Contiguous range from startPosition
234
void tracksInserted( const QList< Tomahawk::plentry_ptr >& tracks, int startPosition );
236
/// Notification for tracks being removed from playlist
237
void tracksRemoved( const QList< Tomahawk::query_ptr >& tracks );
239
/// Notification for tracks being moved in a playlist. List is of new tracks, and new position of first track
240
/// Contiguous range from startPosition
241
void tracksMoved( const QList< Tomahawk::plentry_ptr >& tracks, int startPosition );
244
// want to update the playlist from the model?
245
// generate a newrev using uuid() and call this:
246
void createNewRevision( const QString& newrev, const QString& oldrev, const QList< plentry_ptr >& entries );
248
// Want to update some metadata of a plentry_ptr? this gets you a new revision too.
249
// entries should be <= entries(), with changed metadata.
250
void updateEntries( const QString& newrev, const QString& oldrev, const QList< plentry_ptr >& entries );
253
void reportCreated( const Tomahawk::playlist_ptr& self );
254
void reportDeleted( const Tomahawk::playlist_ptr& self );
256
void setRevision( const QString& rev,
257
const QList<QString>& neworderedguids,
258
const QList<QString>& oldorderedguids,
260
const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
265
void setWeakSelf( QWeakPointer< Playlist > self );
267
// called from loadAllPlaylists DB cmd:
268
explicit Playlist( const source_ptr& src,
269
const QString& currentrevision,
270
const QString& title,
272
const QString& creator,
276
const QString& guid = "" ); // populate db
278
// called when creating new playlist
279
explicit Playlist( const source_ptr& author,
281
const QString& title,
283
const QString& creator,
285
const QList< Tomahawk::plentry_ptr >& entries = QList< Tomahawk::plentry_ptr >() );
287
QList< plentry_ptr > newEntries( const QList< plentry_ptr >& entries );
288
PlaylistRevision setNewRevision( const QString& rev,
289
const QList<QString>& neworderedguids,
290
const QList<QString>& oldorderedguids,
292
const QMap< QString, Tomahawk::plentry_ptr >& addedmap );
296
void onResultsChanged();
297
void onResolvingFinished();
299
void onDeleteResult( SourceTreePopupDialog* );
304
void setBusy( bool b );
305
void checkRevisionQueue();
307
QWeakPointer< Playlist > m_weakSelf;
309
QString m_currentrevision;
310
QString m_guid, m_title, m_info, m_creator;
311
unsigned int m_lastmodified;
312
unsigned int m_createdOn;
315
QList< plentry_ptr > m_initEntries;
316
QList< plentry_ptr > m_entries;
318
QQueue<RevisionQueueItem> m_revisionQueue;
319
QQueue<RevisionQueueItem> m_updateQueue;
321
QList<PlaylistUpdaterInterface*> m_updaters;
323
bool m_locallyChanged;
327
Tomahawk::playlistinterface_ptr m_playlistInterface;
332
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > )
333
Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::PlaylistEntry > > )