forked from mpc-qt/mpc-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.h
238 lines (201 loc) · 7.31 KB
/
helpers.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
// generic helper module for general-use static functions
#ifndef HELPERS_H
#define HELPERS_H
#include <QObject>
#include <QCoreApplication>
#include <QWidget>
#include <QSet>
#include <QList>
#include <QUrl>
#include <QUuid>
#include <QOpenGLWidget>
#include <QDate>
#include <QTime>
#include <QDir>
extern const char autoIcons[];
extern const char blackIconsPath[];
extern const char whiteIconsPath[];
class QPushButton;
class QFileDialog;
class QLocalServer;
class QLocalSocket;
class QOpenGLTexture;
namespace Helpers {
enum DisabledTrack { NothingDisabled, DisabledAudio, DisabledVideo };
enum Subtitles { NoSubtitles, SubtitlesPresent, SubtitlesDisabled, };
enum FileType { AudioFile, VideoFile };
enum ScreenshotRender { VideoRender, SubsRender, WindowRender };
enum TitlePrefix { PrefixFullPath, PrefixFileName, NoPrefix };
enum MpvWidgetType { NullWidget, EmbedWidget, GlCbWidget, VulkanCbWidget,
CustomWidget };
enum ControlHiding { NeverShown, ShowWhenMoving, ShowWhenHovering,
AlwaysShow };
enum AfterPlayback { DoNothingAfter, RepeatAfter, PlayNextAfter,
ExitAfter, StandByAfter, HibernateAfter,
ShutdownAfter, LogOffAfter, LockAfter };
enum TimeFormat { LongFormat, ShortFormat,
LongHourFormat, ShortHourFormat };
extern QSet<QString> audioVideoFileExtensions;
extern QSet<QString> imagesFileExtensions;
extern QSet<QString> archivesFileExtensions;
extern QSet<QString> othersFileExtensions;
extern QSet<QString> allMediaExtensions;
extern QSet<QString> subsExtensions;
QString fileSizeToString(int64_t bytes);
QString fileSizeToStringShort(int64_t bytes);
QString toDateFormat(double time);
QString toDateFormatWithZero(double time);
QString toDateFormatFixed(double time, TimeFormat format);
QDate dateFromCFormat(const char date[]);
QTime timeFromCFormat(const char time[]);
double fromDateFormat(QString date);
QString parseFormat(QString fmt, QString fileName, DisabledTrack disabled,
Subtitles subtitles, double timeNav, double timeBegin,
double timeEnd);
QString parseFormatEx(QString fmt, QUrl sourceUrl, QString filePath,
QString fileExt, DisabledTrack disabled,
Subtitles subtitles, double timeNav,
double timeBegin, double timeEnd);
QString fileOpenFilter();
QString subsOpenFilter();
bool urlSurvivesFilter(const QUrl &url, bool onlyAudioVideo);
QList<QUrl> filterUrls(const QList<QUrl> &urls);
QRect vmapToRect(const QVariantMap &m);
QVariantMap rectToVmap(const QRect &r);
bool sizeFromString(QSize &size, const QString &text);
bool pointFromString(QPoint &point, const QString &text);
QRect availableGeometryFromPoint(const QPoint &point);
QScreen *findScreenByName(QString s);
QString screenToVisualName(QScreen *s);
}
class IconThemer : public QObject {
Q_OBJECT
public:
class IconData {
public:
QPushButton *button; QString iconNormal; QString iconChecked;
};
enum FolderMode { FallbackFolder, CustomFolder, SystemFolder };
explicit IconThemer(QObject *parent = nullptr);
void addIconData(const IconData &data);
QIcon fetchIcon(const QString &name);
void updateButton(const IconData &data);
public slots:
void setIconFolders(IconThemer::FolderMode folderMode, const QString &fallbackFolder, const QString &customFolder);
private:
QList<IconData> iconDataList;
FolderMode folderMode_;
QString fallbackFolder_;
QString customFolder_;
};
class DisplayNode;
class DisplayParser {
public:
DisplayParser();
~DisplayParser();
void takeFormatString(QString fmt);
QString parseMetadata(QVariantMap metaData, QString displayString,
Helpers::FileType fileType);
private:
DisplayNode *node = nullptr;
};
class TrackInfo {
public:
TrackInfo() {}
TrackInfo(const QUrl &url, const QUuid &list, const QUuid &item, QString text, double length,
double position, int64_t videoTrack, int64_t audioTrack, int64_t subtitleTrack);
QUrl url;
QUuid list;
QUuid item;
QString text;
double length;
double position;
int64_t videoTrack;
int64_t audioTrack;
int64_t subtitleTrack;
QVariantMap toVMap() const;
void fromVMap(const QVariantMap &map);
bool operator ==(const TrackInfo &track) const;
static QVariantList tracksToVList(const QList<TrackInfo> &list);
static QList<TrackInfo> tracksFromVList(const QVariantList &list);
};
class MouseState {
Q_DECLARE_TR_FUNCTIONS(MouseState)
public:
enum MouseButtons { None, Wheel, Left, Right, Middle, Back,
Forward, Task, XButton4, XButton5, XButton6, XButton7,
XButton8, XButton9, XButton10, XButton11, XButton12,
XButton13, XButton14, XButton15, XButton16, XButton17,
XButton18, XButton19,XButton20, XButton21, XButton22,
XButton23, XButton24 };
enum MousePress { MouseDown, MouseUp, PressTwice };
MouseState();
MouseState(const MouseState &m);
MouseState(int button, int mod, MousePress press);
MouseState operator =(const MouseState &other);
// Components
int button;
int mod;
MousePress press;
// to Qt notation functions
Qt::MouseButtons mouseButtons() const;
Qt::KeyboardModifiers keyModifiers() const;
bool isPress();
bool isTwice();
bool isWheel();
// I/O functions
QString toString() const;
QVariantMap toVMap() const;
void fromVMap(const QVariantMap &map);
// Hashing-related functions
uint mouseHash() const;
bool operator ==(const MouseState &other) const;
bool operator !() const; // le saef bull eyediom faec
// Conversion functions
static MouseState fromWheelEvent(QWheelEvent *event);
static MouseState fromMouseEvent(QMouseEvent *event, MousePress press);
// Display mapping vars
static QString buttonToText(int index);
static int buttonToTextCount();
static QString modToText(int index);
static int modToTextCount();
static QString multiModToText(int index);
static int multiModToTextCount();
static QString pressToText(int index);
static int pressToTextCount();
};
inline uint qHash(const MouseState &m, uint seed) {
Q_UNUSED(seed)
return m.mouseHash();
}
typedef QHash<MouseState, QAction*> MouseStateMap;
class Command {
public:
Command();
Command(QAction *a, MouseState mf, MouseState mw);
// Components
QAction *action = nullptr;
QKeySequence keys; // taken from the QAction in constructor
MouseState mouseFullscreen;
MouseState mouseWindowed;
// I/O functions
QString toString() const;
QVariantMap toVMap() const;
void fromVMap(const QVariantMap &map);
// Conversion functions
void fromAction(QAction *a);
};
class AudioDevice {
public:
AudioDevice();
AudioDevice(const QVariantMap &m);
void setFromVMap(const QVariantMap &m);
bool operator ==(const AudioDevice &other) const;
QString displayString() const;
QString deviceName() const;
static QList<AudioDevice> listFromVList(const QVariantList &list);
private:
QString displayString_;
QString deviceName_;
};
#endif // HELPERS_H