-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.h
executable file
·364 lines (321 loc) · 10.4 KB
/
app.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
/****************************************************************************}
{ app.h - application core }
{ }
{ Copyright (c) 2012 Alexey Parfenov <[email protected]> }
{ }
{ This file is part of Meson Player. }
{ }
{ Meson Player is free software: you can redistribute it and/or modify it }
{ under the terms of the GNU General Public License as published by }
{ the Free Software Foundation, either version 3 of the License, }
{ or (at your option) any later version. }
{ }
{ Meson Player is distributed in the hope that it will be useful, }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU }
{ General Public License for more details: https://gnu.org/licenses/gpl.html }
{****************************************************************************/
#pragma once
#include "coreapp.h"
#include "mse/types.h"
#include "mse/engine.h"
#include "mse/utils/lastfm.h"
#include "mse/utils/mixer.h"
#ifdef MSE_MODULE_MPRIS
#include "mse/utils/mpris.h"
#endif
#include "notificationpopup.h"
#include <QActionGroup>
#include <QTextBrowser>
#ifdef Q_OS_WIN
#include <windows.h>
#ifndef VK_MEDIA_NEXT_TRACK
#define VK_MEDIA_NEXT_TRACK 0xB0
#endif
#ifndef VK_MEDIA_PREV_TRACK
#define VK_MEDIA_PREV_TRACK 0xB1
#endif
#ifndef VK_MEDIA_PLAY_PAUSE
#define VK_MEDIA_PLAY_PAUSE 0xB3
#endif
#endif
#ifdef Q_OS_LINUX
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <X11/keysym.h>
#include <X11/XF86keysym.h>
#include "eventqueue.h"
#endif
#ifdef Q_OS_OSX
#include <Carbon/Carbon.h>
#endif
typedef struct {
bool autoNumlock = true;
bool subdirs = true;
bool autoResume = false;
quint8 volumeStep = 5;
bool unlimitedPlaylists = true;
bool balloons = true;
quint16 typeTimeout = 1000;
bool shortCaptions = false;
quint32 frequency = 44100;
bool use8Bits = false;
MSE_SoundSampleType sampleType = mse_sstFloat32;
int nChannels = 2;
int device = -1;
bool useDefaultDevice = true;
bool useSoftware = false;
bool playlistsAutoload = false;
MSE_SoundSampleInterpolation sampleInterpolation = mse_ssiSinc;
MSE_SoundSampleRamping sampleRamping = mse_ssrSensitive;
MSE_SoundSurroundMode surroundMode = mse_ssmNone;
MSE_SoundTrackerEmulation trackerEmulation = mse_steNone;
MSE_PlaylistFormatType playlistsType = mse_pftM3U;
bool shoutcastPlaylists = true;
bool logErrors = false;
int minFolderLength = 5;
int volume = -1;
int index = -1;
MSE_PlaylistPlaybackMode playbackMode = mse_ppmAllLoop;
bool setPlaybackMode = false;
bool closeOnStop = true;
bool trayIcon = true;
Qt::KeyboardModifiers modsCmd = Qt::NoModifier;
Qt::KeyboardModifiers modsLoad = Qt::ControlModifier;
Qt::KeyboardModifiers modsSave = Qt::AltModifier;
Qt::KeyboardModifiers modsMM = Qt::NoModifier;
Qt::KeyboardModifiers modsMM2 = Qt::ControlModifier;
bool systemPlaylists = true;
float mvolStep = 5;
QString proxy = "system";
bool loadOnly = false;
int popupDuration = 5;
int updatePeriod = 100;
int bufferLength = 500;
double position = -1;
bool mpris = true;
} Settings;
typedef struct {
MSE_SourceLoadFlags loadFlags;
QString source;
} PlaylistSource;
typedef struct {
int id;
int nKey;
int nMod;
#ifdef Q_OS_OSX
EventHotKeyRef ref;
#endif
bool isRegistered;
bool isDisabled;
} HotKeyInfo;
typedef QList<HotKeyInfo> HotKeysInfo;
class App : public CoreApp
{
Q_OBJECT
public:
enum class Err {
registerHotKey,
unregisterHotKey,
iconFileNotFound,
keyModifiersOverlap,
shiftModNotSupported,
systemProxyDisabled,
invalidProxyUrl,
invalidProxyScheme,
invalidProxyPort,
trayInaccessible,
createDir
};
Q_ENUM(Err)
protected:
virtual int main();
virtual void onQuit();
bool loadSettings();
void loadConfig(const QString& filename);
void parseCommandLine();
void outputCmdResult(const QString &cmd, const QString &prefix = QString());
void onNewInstanceArgs();
bool createSoundObject();
void tryCreateTray();
bool createTray();
void updateModeGroup(MSE_PlaylistPlaybackMode playbackMode);
void updateLfmMenu();
bool registerHotKey(HotKeyInfo& info);
bool unregisterHotKey(HotKeyInfo& info);
bool registerHotKeys(HotKeysInfo& infos);
bool unregisterHotKeys(HotKeysInfo& infos);
bool registerControlHotKeys();
bool unregisterControlHotKeys();
bool registerAppCommandHotKeys();
bool unregisterAppCommandHotKeys();
QString hotkeyToString(const HotKeyInfo &info);
void updateTray(bool showBalloon = true, bool showTime = false);
void showTrayMessage(const QString& msg);
void showMasterVolumeInfo();
void updateVolumeLabel();
void loadState();
void setPlaybackMode(MSE_PlaylistPlaybackMode mode);
void initSound();
int getNativeKey(Qt::Key key);
int getNativeKeyMod(Qt::KeyboardModifiers mod);
void getHotKeyInfo(HotKeyInfo& info, int id, Qt::Key key, Qt::KeyboardModifiers mod = Qt::NoModifier);
void addHotKeyInfo(HotKeysInfo& infos, int id, Qt::Key key, Qt::KeyboardModifiers mod = Qt::NoModifier);
void addHotKeysInfo();
void setNumLock();
Qt::KeyboardModifiers stringToModifiers(const QString& str) const;
#ifdef Q_OS_LINUX
int searchHotKey(const HotKeysInfo& infos, int nKey, uint16_t nMod);
#endif
void correctPath(QString& s);
QString getPlaylistFilename();
void loadPlaylist();
void savePlaylist();
void startPrefixTimer();
void killPrefixTimer();
void startTrayTimer();
void killTrayTimer();
void startSaveTimer();
void killSaveTimer();
void execAppCommand(const QString& cmd);
void timerEvent(QTimerEvent* event);
static QString errorCodeToString(Err code);
static QString errorDataToString(Err errorCode, const void *data);
QString getCmd(const QString& arg);
void cmdTogglePlayStop();
void cmdTogglePlayPause();
void cmdPlay();
void cmdStop(bool forceClose = false);
void cmdPause();
void cmdNextTrack(bool autoPlay);
void cmdPrevTrack(bool autoPlay);
void cmdSeekForward();
void cmdSeekBack();
void cmdNextDir();
void cmdPrevDir();
void cmdVolUp();
void cmdVolDown();
void cmdMVolUp();
void cmdMVolDown();
QString secsToTimeFormat(int secs);
void setSoundPosition(double secs);
void setSoundVolume(float val, bool snapToGrid);
#ifdef MSE_MODULE_MPRIS
MSE_Mpris* mpris;
void mprisInit();
#endif
HotKeysInfo hotKeysNum, hotKeysMedia, hotKeysAppMain, hotKeysApp;
QIcon* curTrayIco;
bool exitNow;
QString settingsDir;
Settings settings;
QList<PlaylistSource> cmdPlaylist;
QString appDir;
QSystemTrayIcon* tray;
NotificationPopup* trayPopup;
QMenu* trayMenu;
QActionGroup* modeGroup;
MSE_Engine* player;
MSE_Sound* sound;
MSE_Mixer* mixer;
MSE_Playlist* playlist;
MSE_Lastfm* lfm;
bool showLfmLoginNotification;
bool doPlay;
QString lastFilename;
QStringList statePlaylist;
bool hasInputFiles;
bool hotkeysOn;
bool appCommandHotkeysOn;
bool appCommandInput;
float mvolStepReal;
float volStepReal;
bool ignoreContState;
QIcon* icoApp;
QIcon* icoPlay;
QIcon* icoPause;
QIcon* icoStop;
QAction* actionShuffle;
QAction* actionPlaylists;
QAction* actionHotkeys;
QAction* actionCurrentFile;
QAction* actionCloseFile;
QMenu* menuServiceLfm;
QAction* actionLfmLoginWeb;
QAction* actionLfmLoginForm;
QAction* actionLfmUser;
QAction* actionLfmLogout;
QAction* actionExit;
QList<QAction*> *modeActions;
QAction *addModeAction(
QMenu *menuModes,
QActionGroup *group,
const QString& title,
MSE_PlaylistPlaybackMode mode);
QString playlistPrefix;
bool doSaveList;
int prefixTimer;
int trayTimer;
int trayTimerTriesLeft;
int saveTimer;
QString playlistsExt;
struct {
QString formattedTitle;
QString title;
QString artist;
QString filename;
QString fullFilename;
double duration;
double fullDuration;
} lastTrackData;
void updateLastTrackData();
void clearLastTrackData();
bool hotkeysDisabled;
QString curDir;
QString curVol;
#ifdef Q_OS_LINUX
xcb_connection_t* xconn;
xcb_screen_t* xscreen;
xcb_window_t xwin;
xcb_key_symbols_t* xkeysyms;
int keyHookTimer;
EventQueue* eventQueue;
#endif
#ifdef Q_OS_OSX
EventHandlerRef keyHooks;
int keyRepeatTimer;
int keyRepeatCounter;
int keyRepeatKeyId;
#endif
QDialog* aboutDialog;
QTextBrowser* aboutText;
public:
explicit App(int &argc, char **argv);
~App();
void onHotKey(int id, bool isPressed);
#ifdef Q_OS_LINUX
bool handleXKeyPress(const xcb_key_press_event_t *event, bool isPressed);
bool xcb_ok(xcb_void_cookie_t cookie);
#endif
#ifdef Q_OS_OSX
void startKeyRepeatTimer(int keyId);
void stopKeyRepeatTimer();
#endif
void loadCmdPlaylist();
void moveCurFileToTrash();
public slots:
void saveState();
void saveStateList();
void onLfmChangeState();
protected slots:
void onInfoChange();
void updateTrayIcon();
void onActionPlaylists();
void onActionHotkeys(bool checked);
void onActionCurrentFile();
void onActionCloseFile();
void onActionExit();
void onActionMode(bool checked);
void onSaveData();
virtual void onNativeEvent(void* event, bool& stopPropagation);
};