~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/Playlist.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
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>
 
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 PLAYLIST_H
 
22
#define PLAYLIST_H
 
23
 
 
24
#include <QObject>
 
25
#include <QList>
 
26
#include <QVariant>
 
27
#include <QSharedPointer>
 
28
#include <QQueue>
 
29
 
 
30
#include "Typedefs.h"
 
31
#include "Result.h"
 
32
#include "PlaylistInterface.h"
 
33
#include "playlist/PlaylistUpdaterInterface.h"
 
34
#include "Query.h"
 
35
 
 
36
#include "DllMacro.h"
 
37
 
 
38
class SourceTreePopupDialog;
 
39
class DatabaseCommand_LoadAllPlaylists;
 
40
class DatabaseCommand_LoadAllSortedPlaylists;
 
41
class DatabaseCommand_SetPlaylistRevision;
 
42
class DatabaseCommand_CreatePlaylist;
 
43
class PlaylistModel;
 
44
 
 
45
namespace Tomahawk
 
46
{
 
47
 
 
48
class PlaylistUpdaterInterface;
 
49
 
 
50
class DLLEXPORT PlaylistEntry : public QObject
 
51
{
 
52
Q_OBJECT
 
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 )
 
58
 
 
59
public:
 
60
    PlaylistEntry();
 
61
    virtual ~PlaylistEntry();
 
62
 
 
63
    bool isValid() const { return !m_query.isNull(); }
 
64
 
 
65
    void setQuery( const Tomahawk::query_ptr& q );
 
66
    const Tomahawk::query_ptr& query() const;
 
67
 
 
68
    void setQueryVariant( const QVariant& v );
 
69
    QVariant queryVariant() const;
 
70
 
 
71
    QString guid() const { return m_guid; }
 
72
    void setGuid( const QString& s ) { m_guid = s; }
 
73
 
 
74
    QString annotation() const { return m_annotation; }
 
75
    void setAnnotation( const QString& s ) { m_annotation = s; }
 
76
 
 
77
    QString resultHint() const { return m_resulthint; }
 
78
    void setResultHint( const QString& s ) { m_resulthint= s; }
 
79
 
 
80
    unsigned int duration() const { return m_duration; }
 
81
    void setDuration( unsigned int i ) { m_duration = i; }
 
82
 
 
83
    unsigned int lastmodified() const { return m_lastmodified; }
 
84
    void setLastmodified( unsigned int i ) { m_lastmodified = i; }
 
85
 
 
86
    source_ptr lastSource() const;
 
87
    void setLastSource( source_ptr s );
 
88
 
 
89
private:
 
90
    QString m_guid;
 
91
    Tomahawk::query_ptr m_query;
 
92
    QString m_annotation;
 
93
    unsigned int m_duration;
 
94
    unsigned int m_lastmodified;
 
95
    source_ptr   m_lastsource;
 
96
    QString      m_resulthint;
 
97
};
 
98
 
 
99
 
 
100
struct PlaylistRevision
 
101
{
 
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
 
108
};
 
109
 
 
110
struct RevisionQueueItem
 
111
{
 
112
public:
 
113
    QString newRev;
 
114
    QString oldRev;
 
115
    QList< plentry_ptr > entries;
 
116
    bool applyToTip;
 
117
 
 
118
    RevisionQueueItem( const QString& nRev, const QString& oRev, const QList< plentry_ptr >& e, bool latest ) :
 
119
        newRev( nRev ), oldRev( oRev), entries( e ), applyToTip( latest ) {}
 
120
};
 
121
 
 
122
 
 
123
class DLLEXPORT Playlist : public QObject
 
124
{
 
125
    Q_OBJECT
 
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 )
 
133
 
 
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;
 
140
 
 
141
public:
 
142
    virtual ~Playlist();
 
143
 
 
144
    static Tomahawk::playlist_ptr load( const QString& guid );
 
145
 
 
146
    // one CTOR is private, only called by DatabaseCommand_LoadAllPlaylists
 
147
    static Tomahawk::playlist_ptr create( const source_ptr& author,
 
148
                                          const QString& guid,
 
149
                                          const QString& title,
 
150
                                          const QString& info,
 
151
                                          const QString& creator,
 
152
                                          bool shared,
 
153
                                          const QList<Tomahawk::query_ptr>& queries = QList<Tomahawk::query_ptr>() );
 
154
 
 
155
    static void remove( const playlist_ptr& playlist );
 
156
    void rename( const QString& title );
 
157
 
 
158
    virtual void loadRevision( const QString& rev = "" );
 
159
 
 
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; }
 
169
 
 
170
    bool busy() const { return m_busy; }
 
171
 
 
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 );
 
176
 
 
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 );
 
189
    // </IGNORE>
 
190
 
 
191
 
 
192
    QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst = false );
 
193
 
 
194
    void addUpdater( PlaylistUpdaterInterface* updater );
 
195
    void removeUpdater( PlaylistUpdaterInterface* updater );
 
196
    QList<PlaylistUpdaterInterface*> updaters() const { return m_updaters; }
 
197
 
 
198
    /**
 
199
     * Some updaters might have custom deleters in order to perform more actions that require
 
200
     * user prompting on delete.
 
201
     */
 
202
    bool hasCustomDeleter() const;
 
203
    /**
 
204
     * If this playlist has a custom deleter, let it do the deleting itself.
 
205
     *
 
206
     * If it needs user prompting, use the \param customDeleter as the right-most center point.
 
207
     */
 
208
    void customDelete( const QPoint& rightCenter );
 
209
 
 
210
    Tomahawk::playlistinterface_ptr playlistInterface();
 
211
 
 
212
signals:
 
213
    /// emitted when the playlist revision changes (whenever the playlist changes)
 
214
    void revisionLoaded( Tomahawk::PlaylistRevision );
 
215
 
 
216
    /// watch for this to see when newly created playlist is synced to DB (if you care)
 
217
    void created();
 
218
 
 
219
    /// renamed etc.
 
220
    void changed();
 
221
    void renamed( const QString& newTitle, const QString& oldTitle );
 
222
 
 
223
    /**
 
224
     *   delete command is scheduled but not completed. Do not call remove() again once this
 
225
     *   is emitted.
 
226
     */
 
227
    void aboutToBeDeleted( const Tomahawk::playlist_ptr& pl );
 
228
 
 
229
    /// was deleted, eh?
 
230
    void deleted( const Tomahawk::playlist_ptr& pl );
 
231
 
 
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 );
 
235
 
 
236
    /// Notification for tracks being removed from playlist
 
237
    void tracksRemoved( const QList< Tomahawk::query_ptr >& tracks );
 
238
 
 
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 );
 
242
 
 
243
public slots:
 
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 );
 
247
 
 
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 );
 
251
 
 
252
 
 
253
    void reportCreated( const Tomahawk::playlist_ptr& self );
 
254
    void reportDeleted( const Tomahawk::playlist_ptr& self );
 
255
 
 
256
    void setRevision( const QString& rev,
 
257
                      const QList<QString>& neworderedguids,
 
258
                      const QList<QString>& oldorderedguids,
 
259
                      bool is_newest_rev,
 
260
                      const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
 
261
                      bool applied );
 
262
 
 
263
    void resolve();
 
264
 
 
265
    void setWeakSelf( QWeakPointer< Playlist > self );
 
266
protected:
 
267
    // called from loadAllPlaylists DB cmd:
 
268
    explicit Playlist( const source_ptr& src,
 
269
                       const QString& currentrevision,
 
270
                       const QString& title,
 
271
                       const QString& info,
 
272
                       const QString& creator,
 
273
                       uint createdOn,
 
274
                       bool shared,
 
275
                       int lastmod,
 
276
                       const QString& guid = "" ); // populate db
 
277
 
 
278
    // called when creating new playlist
 
279
    explicit Playlist( const source_ptr& author,
 
280
                       const QString& guid,
 
281
                       const QString& title,
 
282
                       const QString& info,
 
283
                       const QString& creator,
 
284
                       bool shared,
 
285
                       const QList< Tomahawk::plentry_ptr >& entries = QList< Tomahawk::plentry_ptr >() );
 
286
 
 
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,
 
291
                                     bool is_newest_rev,
 
292
                                     const QMap< QString, Tomahawk::plentry_ptr >& addedmap );
 
293
 
 
294
 
 
295
private slots:
 
296
    void onResultsChanged();
 
297
    void onResolvingFinished();
 
298
 
 
299
    void onDeleteResult( SourceTreePopupDialog* );
 
300
private:
 
301
    Playlist();
 
302
    void init();
 
303
 
 
304
    void setBusy( bool b );
 
305
    void checkRevisionQueue();
 
306
 
 
307
    QWeakPointer< Playlist > m_weakSelf;
 
308
    source_ptr m_source;
 
309
    QString m_currentrevision;
 
310
    QString m_guid, m_title, m_info, m_creator;
 
311
    unsigned int m_lastmodified;
 
312
    unsigned int m_createdOn;
 
313
    bool m_shared;
 
314
 
 
315
    QList< plentry_ptr > m_initEntries;
 
316
    QList< plentry_ptr > m_entries;
 
317
 
 
318
    QQueue<RevisionQueueItem> m_revisionQueue;
 
319
    QQueue<RevisionQueueItem> m_updateQueue;
 
320
 
 
321
    QList<PlaylistUpdaterInterface*> m_updaters;
 
322
 
 
323
    bool m_locallyChanged;
 
324
    bool m_deleted;
 
325
    bool m_busy;
 
326
 
 
327
    Tomahawk::playlistinterface_ptr m_playlistInterface;
 
328
};
 
329
 
 
330
}
 
331
 
 
332
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > )
 
333
Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::PlaylistEntry > > )
 
334
 
 
335
#endif // PLAYLIST_H