-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentities.h
378 lines (356 loc) · 9.36 KB
/
entities.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#pragma once
#include <QObject>
#include <QImage>
#include <QUrl>
#include <QMediaPlayer>
#include <QMediaMetaData>
#include <QAudioOutput>
#include <QPropertyAnimation>
#include <QFile>
#include <QJsonObject>
#include <memory>
#include "settings.h"
#include "security.h"
enum class CommandType
{
BLANK,
NATIVE,
VIDEO,
AUDIO,
PULSAR
};
namespace File
{
class List
{
public:
List() : currentIndex(0) { }
List(const QString &path,const QStringList &filter={});
List(const QStringList &files);
const QString File(const int index) const;
const QString First();
const QString Random();
const QString Unique();
int RandomIndex();
const QStringList& operator()() const;
protected:
QStringList files;
int currentIndex;
void Shuffle();
void Reshuffle();
};
}
class Command
{
public:
using Lookup=std::unordered_map<QString,Command>;
Command() : Command({},{},CommandType::BLANK,false,true,{},{},{},{}) { }
Command(const QString &name,const QString &description,const CommandType &type,bool protect=false) : Command(name,description,type,false,true,{},{},{},{},protect) { }
Command(const QString &name,const QString &description,const CommandType &type,bool random,bool duplicates,const QString &path,const QStringList &filters,const QString &message,const QStringList &viewers,bool protect=false) : name(name), description(description), type(type), random(random), duplicates(duplicates), protect(protect), path(path), files(std::make_shared<File::List>(path,filters)), message(message), viewers(viewers), parent(nullptr) { }
Command(const QString &name,Command* const parent);
Command(const Command &command,const QString &message) : name(command.name), description(command.description), type(command.type), random(command.random), duplicates(command.duplicates), protect(command.protect), path(command.path), files(command.files), message(message), viewers(command.viewers), parent(nullptr) { }
Command(const Command &other) : name(other.name), description(other.description), type(other.type), random(other.random), duplicates(other.duplicates), protect(other.protect), path(other.path), files(other.files), message(other.message), viewers(other.viewers), parent(nullptr) { }
const QString& Name() const { return name; }
const QString& Description() const { return description; }
CommandType Type() const { return type; }
bool Random() const { return random; }
bool Duplicates() const { return duplicates; }
bool Protected() const { return protect; }
const QString& Path() const { return path; }
const QString File();
const QString& Message() const { return message; }
const QStringList& Viewers() const { return viewers; }
const Command* Parent() const { return parent; }
const std::vector<Command*>& Children() const { return children; }
static QStringList FileListFilters(const CommandType type);
protected:
QString name;
QString description;
CommandType type;
bool random;
bool duplicates;
bool protect;
QString path;
std::shared_ptr<File::List> files;
QString message;
QStringList viewers; //! the names of the viewers needed in chat to trigger the command
Command *parent;
std::vector<Command*> children;
};
namespace Music
{
struct Metadata
{
QString title;
QString album;
QString artist;
QImage cover;
bool valid=false;
};
class Player : public QObject
{
Q_OBJECT
public:
Player(bool loop,int initialVolume,QObject *parent=nullptr);
void DuckVolume(bool duck);
void Volume(int targetVolume,std::chrono::seconds duration);
bool Playing() const;
struct Metadata Metadata() const;
QString Filename() const;
void Sources(const File::List &sources);
const File::List& Sources();
ApplicationSetting& SuppressedVolume();
protected:
QMediaPlayer player;
QAudioOutput output;
File::List sources;
QMetaObject::Connection autoPlay;
bool loop;
ApplicationSetting settingSuppressedVolume;
QPropertyAnimation volumeAdjustment;
static const char *ERROR_LOADING;
static const char *OPERATION_LOADING;
bool Next(QUrl source={});
int TranslateVolume(qreal volume);
qreal TranslateVolume(int volume);
bool Empty();
signals:
void Print(const QString &message,const QString operation=QString(),const QString subsystem=QString("music player")) const;
void PlaylistLoaded();
public slots:
void Start();
void Start(QUrl source);
void Stop();
void Volume(int volume);
protected slots:
void StateChanged(QMediaPlayer::PlaybackState state);
void MediaStatusChanged(QMediaPlayer::MediaStatus status);
void MediaError(QMediaPlayer::Error error,const QString &errorString);
void VolumeMuted();
};
namespace ID3
{
quint32 SyncSafe(const char *value);
class Header
{
public:
Header(QFile &file);
quint32 Size() const;
protected:
QFile &file;
unsigned short versionMajor;
unsigned short versionMinor;
bool unsynchronization;
bool extendedHeader;
quint32 size;
void ParseIdentifier();
void ParseVersion();
void ParseFlags();
void ParseSize();
};
namespace Frame
{
enum class Frame
{
APIC,
TIT2,
TALB,
TPE1
};
enum class PictureType
{
OTHER=0,
FILE_ICON,
OTHER_FILE_ICON,
COVER_FRONT,
COVER_BACK,
LEAFLET_PAGE,
CD_LABEL,
LEAD_ARTIST,
ARTIST,
CONDUCTOR,
BAND,
COMPOSER,
LYRICIST,
RECORDING_LOCATION,
DURING_RECORDING,
DURING_PERFORMANCE,
VIDEO_SCREEN_CAPTURE,
A_BRIGHT_COLORED_FISH,
ILLUSTRATION,
BAND_LOGO,
STUDIO_LOGO
};
enum class Encoding
{
ISO_8859_1=0,
UTF_16,
UTF_16BE,
UTF_8
};
class Header
{
public:
Header(QFile &file);
QByteArray ID() const;
quint32 Size() const;
protected:
QFile &file;
QByteArray id;
quint32 size;
void ParseID();
void ParseSize();
};
class APIC
{
public:
APIC(QFile &file,quint32 size);
const QImage& Picture() const;
protected:
QFile &file;
quint32 size;
Encoding encoding;
QByteArray MIMEType;
PictureType pictureType;
QByteArray description;
QImage picture;
void ParseEncoding();
void ParseMIMEType();
void ParsePictureType();
void ParseDescription();
void ParsePictureData();
quint32 DataSize();
};
class TIT2
{
public:
TIT2(QFile &file,quint32 size);
const QString& Title() const;
protected:
QFile &file;
quint32 size;
Encoding encoding;
QString title;
void ParseEncoding();
void ParseTitle();
};
using TALB=TIT2;
using TPE1=TIT2;
}
class Tag
{
template<typename T> using Candidate=std::optional<std::reference_wrapper<T>>;
public:
Tag(const QString &filename);
~Tag();
Candidate<const QImage> AlbumCoverFront() const;
Candidate<const QString> Title() const;
Candidate<const QString> AlbumTitle() const;
Candidate<const QString> Artist() const;
protected:
QFile file;
std::unique_ptr<Frame::APIC> APIC;
std::unique_ptr<Frame::TIT2> TIT2;
std::unique_ptr<Frame::TALB> TALB;
std::unique_ptr<Frame::TPE1> TPE1;
void Destroy();
};
}
}
namespace Viewer
{
namespace ProfileImage
{
class Remote : public QObject
{
Q_OBJECT
public:
Remote(const QUrl &profileImageURL);
operator QImage() const;
protected:
QImage image;
signals:
void Print(const QString &message,const QString operation=QString(),const QString subsystem=QString("profile image retrieval"));
void Retrieved(std::shared_ptr<QImage> image);
};
}
class Local
{
public:
Local(const QString &name,const QString &id,const QString &displayName,QUrl profileImageURL,const QString &description) : name(name), id(id), displayName(displayName), profileImageURL(profileImageURL), description(description) { }
const QString& Name() const;
const QString& ID() const;
const QString& DisplayName() const;
ProfileImage::Remote* ProfileImage() const;
const QString& Description() const;
protected:
QString name;
QString id;
QString displayName;
QUrl profileImageURL;
QString description;
};
class Remote : public QObject
{
Q_OBJECT
public:
Remote(Security &security,const QString &username);
protected:
QString name;
void DownloadProfileImage(const QString &url);
signals:
void Print(const QString &message,const QString operation=QString(),const QString subsystem=QString("viewer retrieval"));
void Recognized(const Viewer::Local &viewer);
void Unrecognized();
};
struct Attributes
{
bool commands { true };
bool welcomed { false };
bool bot { false };
bool limited { false };
bool subscribed { false };
std::chrono::time_point<std::chrono::system_clock> commandTimestamp;
};
}
namespace Chat
{
struct Emote
{
QString name {};
QString id {};
QString path {};
int start { 0 };
int end { 0 };
bool operator<(const Emote &other) const { return start < other.start; }
};
using EmoteList=std::vector<Emote>;
struct Message
{
QString id {};
QString displayName {};
QString text {};
QColor color {};
QStringList badges {};
std::vector<Chat::Emote> emotes {};
bool action { false };
bool broadcaster { false };
bool moderator { false };
bool html { false };
bool Privileged() const { return broadcaster || moderator; }
};
}
namespace JSON
{
class SignalPayload : public QObject
{
Q_OBJECT
public:
SignalPayload(const QJsonObject &payload) : QObject(nullptr), payload(payload) { }
void Dispatch();
QJsonObject payload;
QVariant context;
signals:
void Deliver(const QJsonObject &payload);
};
}