-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQtGui.cpp
199 lines (167 loc) · 6.38 KB
/
QtGui.cpp
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
/*
ddb_gui_qt5 - Qt user interface
Copyright (C) 2010 Anton Novikov <[email protected]>
Copyright (C) 2011 Semen Minyushov <[email protected]>
Copyright (C) 2013 Karjavin Roman <[email protected]>
Copyright (C) 2019-2020 Jakub Wasylków <[email protected]>
This program 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 2
of the License, or (at your option) any later version.
This program 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "QtGui.h"
#include <unistd.h>
#include <QApplication>
#include "DBApi.h"
#include "MainWindow.h"
#include "QtGuiSettings.h"
#include <QStyleFactory>
#include <QLocale>
#include <QQuickWindow>
#include "PluginLoader.h"
#include "DeadbeefTranslator.h"
#undef DBAPI
#define DBAPI deadbeef_internal
static int pluginStart();
static int pluginStop();
static int pluginConnect();
DB_functions_t *deadbeef_internal;
DB_qtgui_t qt_plugin;
DB_gui_t &plugin = qt_plugin.gui;
// TODO make casual plugin list
DB_artwork_plugin_t *coverart_plugin;
DBApi *api = nullptr;
PluginLoader *pl = nullptr;
MainWindow *w = nullptr;
DeadbeefTranslator *tr = nullptr;
QApplication *app = nullptr;
static int pluginMessage_wrapper(uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
return api->pluginMessage(id, ctx, p1, p2);
}
static int initializeApi() {
if (!api) {
while (!deadbeef_internal) {
usleep(10000);
}
// provide dummy args for QApplication
static char argv0[] = "a.out";
static char *argv[] = {argv0, nullptr};
static int argc = sizeof(argv) / sizeof(char*) - 1;
app = new QApplication(argc, argv);
QApplication::setOrganizationName("deadbeef");
QApplication::setApplicationName("DeaDBeeF");
dbtr = new DeadbeefTranslator(app);
app->installTranslator(dbtr);
//QApplication::setStyle(QStyleFactory::create("breeze"));
#ifdef __MINGW32__
QStringList theme_search_paths = QIcon::themeSearchPaths();
theme_search_paths.append("./share/icons");
QIcon::setThemeSearchPaths(theme_search_paths);
qDebug() << QIcon::themeSearchPaths();
//QIcon::setThemeName("Windows-10-Icons");
QIcon::setThemeName("Adwaita");
// Set opengl api for qt quick (qt 6 and higher)
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
#endif
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
//QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
#endif
// setup settings
QString file = QString("%1/%2") .arg(deadbeef_internal->get_system_dir(DDB_SYS_DIR_CONFIG), "qt5");
QtGuiSettings::setDefaultFormat(QSettings::IniFormat);
QtGuiSettings::setPath(QSettings::IniFormat, QSettings::UserScope, file);
if (!pl) {
pl = new PluginLoader();
}
api = new DBApi(app, deadbeef_internal);
// initialize window
w = new MainWindow(nullptr, api);
plugin.plugin.message = pluginMessage_wrapper;
}
return 0;
}
static int initializePluginLoader() {
if (!pl) {
pl = new PluginLoader();
}
if (!api) {
initializeApi();
}
return 0;
}
static int pluginStop() {
QApplication::instance()->quit();
qDebug() << "QtGui_stop completed";
return 0;
}
static int pluginConnect() {
return 0;
}
static int registerWidget (DBWidgetInfo *info) {
initializeApi();
pl->widgetLibraryAppend(info);
return 0;
}
static int pluginStart() {
initializeApi();
w->loadConfig();
w->show();
app->exec();
// shutdown
//delete w;
delete api;
delete pl;
delete app;
DBAPI->sendmessage(DB_EV_TERMINATE, 0, 0, 0);
return 0;
}
extern "C" {
DB_plugin_t *ddb_gui_qt5_load(DB_functions_t *dbapi) {
deadbeef_internal = dbapi;
plugin.plugin.api_vmajor = 1;
plugin.plugin.api_vminor = 9;
plugin.plugin.version_major = 1;
plugin.plugin.version_minor = 9;
plugin.plugin.type = DB_PLUGIN_GUI;
plugin.plugin.id = "qt5";
plugin.plugin.name = "Qt user interface";
plugin.plugin.descr = "Qt user interface";
plugin.plugin.copyright =
"ddb_gui_qt5 - Qt user interface\n"
"Copyright (C) 2010 Anton Novikov <[email protected]>\n"
"Copyright (C) 2011 Semen Minyushov <[email protected]>\n"
"Copyright (C) 2013 Karjavin Roman <[email protected]>\n"
"Copyright (C) 2019-2021 Jakub Wasylków <[email protected]>\n"
"\n"
"This program is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU General Public License\n"
"as published by the Free Software Foundation; either version 2\n"
"of the License, or (at your option) any later version.\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n";
plugin.plugin.website = "https://github.com/kuba160/ddb_gui_qt5";
plugin.plugin.start = pluginStart;
plugin.plugin.stop = pluginStop;
plugin.plugin.connect = pluginConnect;
plugin.plugin.message = nullptr;
qt_plugin.register_widget = registerWidget;
return DB_PLUGIN(&plugin);
}
}