-
Notifications
You must be signed in to change notification settings - Fork 33
/
playlist.h
119 lines (97 loc) · 2.78 KB
/
playlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef PLAYLIST_H
#define PLAYLIST_H
// A set of classes suitable for creating and storing playlists.
#include <QString>
#include <QUuid>
#include <QUrl>
#include <QObject>
#include <functional>
#include <QList>
#include <QHash>
#include <QStringList>
#include <QVariantMap>
class Item {
public:
Item(QUrl url = QUrl());
QUuid uuid() const;
void setUuid(QUuid uuid);
QUrl url() const;
void setUrl(QUrl url);
QVariantMap metadata() const;
void setMetadata(const QVariantMap &qvm);
int queuePosition() const;
void setQueuePosition(int num);
void decQueuePosition();
QString toDisplayString() const;
QString toString() const;
void fromString(QString input);
QVariantMap toVMap() const;
void fromVMap(const QVariantMap &qvm);
private:
QUuid uuid_;
QUrl url_;
QVariantMap metadata_;
int queuePosition_;
};
class Playlist : public QObject {
Q_OBJECT
public:
Playlist(QString title = QString());
~Playlist();
Item *addItem(QUrl url = QUrl());
Item *addItem(QUuid uuid, QUrl url);
Item *itemAt(int row);
Item *itemOf(QUuid uuid);
Item *itemAfter(QUuid uuid);
Item *itemBefore(QUuid uuid);
int indexOf(QUuid uuid);
int count() const;
void iterateItems(std::function<void(Item *)> callback);
void moveItems(int sourceRow, int destRow, int count);
void addItems(int where, QList<Item*> itemsToAdd);
void removeItems(int where, int count);
void removeItem(QUuid uuid);
QList<Item*> takeItems(int where, int count);
void clear();
QUuid queueFirst();
QUuid queueTakeFirst();
void queueToggle(QUuid uuid);
void queueRemove(QUuid uuid);
QString title() const;
void setTitle(const QString title);
QUuid uuid() const;
void setUuid(const QUuid uuid);
QStringList toStringList() const;
void fromStringList(QStringList sl);
QVariantMap toVMap() const;
void fromVMap(const QVariantMap &qvm);
private:
QList<Item*> items;
QHash<QUuid, Item*> itemsByUuid;
QList<QUuid> queue;
QString title_;
QUuid uuid_;
};
class PlaylistCollection : public QObject {
Q_OBJECT
private:
PlaylistCollection();
~PlaylistCollection();
static PlaylistCollection* collection;
public:
static PlaylistCollection *getSingleton();
static void freeSingleton();
Playlist *nowPlaying();
Playlist *newPlaylist(QString title = 0);
Playlist *clonePlaylist(QUuid uuid);
void removePlaylist(QUuid uuid);
void removePlaylist(Playlist *p);
Playlist *playlistAt(int col);
Playlist *playlistOf(QUuid uuid);
void addPlaylist(Playlist *playlist);
private:
QList<Playlist*> playlists;
QHash<QUuid, Playlist*> playlistsByUuid;
Playlist *doNewPlaylist(QString title, QUuid uuid);
};
#endif // PLAYLIST_H