1 |
// qsampler.cpp |
// qsampler.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, 2008 Christian Schoenebeck |
Copyright (C) 2007,2008,2015,2019 Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
#include "qsamplerAbout.h" |
#include "qsampler.h" |
24 |
|
|
25 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
|
|
28 |
#include <QApplication> |
#include "qsamplerPaletteForm.h" |
29 |
|
|
30 |
|
#include <QDir> |
31 |
|
|
32 |
|
#include <QStyleFactory> |
33 |
|
|
34 |
#include <QLibraryInfo> |
#include <QLibraryInfo> |
35 |
#include <QTranslator> |
#include <QTranslator> |
36 |
#include <QLocale> |
#include <QLocale> |
37 |
|
|
38 |
#if defined(__APPLE__) // Toshi Nagata 20080105 |
#if defined(__APPLE__) // Toshi Nagata 20080105 |
39 |
#include <QDir> |
#include <QDir> |
40 |
#endif |
#endif |
41 |
|
|
42 |
#if QT_VERSION < 0x040300 |
#ifndef CONFIG_PREFIX |
43 |
#define lighter(x) light(x) |
#define CONFIG_PREFIX "/usr/local" |
44 |
#define darker(x) dark(x) |
#endif |
45 |
|
|
46 |
|
#ifndef CONFIG_DATADIR |
47 |
|
#define CONFIG_DATADIR CONFIG_PREFIX "/share" |
48 |
|
#endif |
49 |
|
|
50 |
|
#ifndef CONFIG_LIBDIR |
51 |
|
#if defined(__x86_64__) |
52 |
|
#define CONFIG_LIBDIR CONFIG_PREFIX "/lib64" |
53 |
|
#else |
54 |
|
#define CONFIG_LIBDIR CONFIG_PREFIX "/lib" |
55 |
|
#endif |
56 |
|
#endif |
57 |
|
|
58 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
59 |
|
#define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt4/plugins" |
60 |
|
#else |
61 |
|
#define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt5/plugins" |
62 |
|
#endif |
63 |
|
|
64 |
|
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) |
65 |
|
#define RELATIVE_LOCALE_DIR "/share/locale" |
66 |
|
#elif defined(__APPLE__) |
67 |
|
#define RELATIVE_LOCALE_DIR "/../Resources" |
68 |
#endif |
#endif |
69 |
|
|
70 |
|
|
72 |
// Singleton application instance stuff (Qt/X11 only atm.) |
// Singleton application instance stuff (Qt/X11 only atm.) |
73 |
// |
// |
74 |
|
|
75 |
#if defined(Q_WS_X11) |
#ifdef CONFIG_XUNIQUE |
76 |
|
|
77 |
|
#define QSAMPLER_XUNIQUE "qsamplerApplication" |
78 |
|
|
79 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
80 |
|
#ifdef CONFIG_X11 |
81 |
|
|
82 |
#include <QX11Info> |
#include <unistd.h> /* for gethostname() */ |
83 |
|
|
84 |
#include <X11/Xatom.h> |
#include <X11/Xatom.h> |
85 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
86 |
|
|
87 |
#define QSAMPLER_XUNIQUE "qsamplerMainForm_xunique" |
#endif // CONFIG_X11 |
88 |
|
#else |
89 |
|
#include <QSharedMemory> |
90 |
|
#include <QLocalServer> |
91 |
|
#include <QLocalSocket> |
92 |
|
#include <QHostInfo> |
93 |
#endif |
#endif |
94 |
|
|
95 |
class qsamplerApplication : public QApplication |
#endif // CONFIG_XUNIQUE |
|
{ |
|
|
public: |
|
96 |
|
|
97 |
// Constructor. |
|
98 |
qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv), |
// Constructor. |
99 |
m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0) |
qsamplerApplication::qsamplerApplication ( int& argc, char **argv ) |
100 |
{ |
: QApplication(argc, argv), |
101 |
// Load translation support. |
m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr) |
102 |
QLocale loc; |
{ |
103 |
if (loc.language() != QLocale::C) { |
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) |
104 |
// Try own Qt translation... |
QApplication::setApplicationName(QSAMPLER_TITLE); |
105 |
m_pQtTranslator = new QTranslator(this); |
QApplication::setApplicationDisplayName(QSAMPLER_TITLE); |
106 |
QString sLocName = "qt_" + loc.name(); |
// QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE)); |
107 |
QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); |
#endif |
108 |
|
// Load translation support. |
109 |
|
QLocale loc; |
110 |
|
if (loc.language() != QLocale::C) { |
111 |
|
// Try own Qt translation... |
112 |
|
m_pQtTranslator = new QTranslator(this); |
113 |
|
QString sLocName = "qt_" + loc.name(); |
114 |
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
115 |
|
QString sLocPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath); |
116 |
|
#else |
117 |
|
QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); |
118 |
|
#endif |
119 |
|
if (m_pQtTranslator->load(sLocName, sLocPath)) { |
120 |
|
QApplication::installTranslator(m_pQtTranslator); |
121 |
|
} else { |
122 |
|
#ifdef RELATIVE_LOCALE_DIR |
123 |
|
sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR; |
124 |
if (m_pQtTranslator->load(sLocName, sLocPath)) { |
if (m_pQtTranslator->load(sLocName, sLocPath)) { |
125 |
QApplication::installTranslator(m_pQtTranslator); |
QApplication::installTranslator(m_pQtTranslator); |
126 |
} else { |
} else { |
|
#if WIN32 |
|
|
sLocPath = QApplication::applicationDirPath() + "/share/locale"; |
|
|
if (m_pQtTranslator->load(sLocName, sLocPath)) { |
|
|
QApplication::installTranslator(m_pQtTranslator); |
|
|
} else { |
|
127 |
#endif |
#endif |
128 |
delete m_pQtTranslator; |
delete m_pQtTranslator; |
129 |
m_pQtTranslator = 0; |
m_pQtTranslator = 0; |
130 |
#ifdef CONFIG_DEBUG |
#ifdef CONFIG_DEBUG |
131 |
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm", |
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm", |
132 |
loc.name().toUtf8().constData(), |
loc.name().toUtf8().constData(), |
133 |
sLocPath.toUtf8().constData(), |
sLocPath.toUtf8().constData(), |
134 |
sLocName.toUtf8().constData()); |
sLocName.toUtf8().constData()); |
|
#endif |
|
|
#if WIN32 |
|
|
} |
|
135 |
#endif |
#endif |
136 |
|
#ifdef RELATIVE_LOCALE_DIR |
137 |
} |
} |
138 |
// Try own application translation... |
#endif |
139 |
m_pMyTranslator = new QTranslator(this); |
} |
140 |
sLocName = "qsampler_" + loc.name(); |
// Try own application translation... |
141 |
|
m_pMyTranslator = new QTranslator(this); |
142 |
|
sLocName = "qsampler_" + loc.name(); |
143 |
|
if (m_pMyTranslator->load(sLocName, sLocPath)) { |
144 |
|
QApplication::installTranslator(m_pMyTranslator); |
145 |
|
} else { |
146 |
|
#ifdef RELATIVE_LOCALE_DIR |
147 |
|
sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR; |
148 |
|
#else |
149 |
|
sLocPath = CONFIG_DATADIR "/qsampler/translations"; |
150 |
|
#endif |
151 |
if (m_pMyTranslator->load(sLocName, sLocPath)) { |
if (m_pMyTranslator->load(sLocName, sLocPath)) { |
152 |
QApplication::installTranslator(m_pMyTranslator); |
QApplication::installTranslator(m_pMyTranslator); |
153 |
} else { |
} else { |
154 |
#if WIN32 |
delete m_pMyTranslator; |
155 |
sLocPath = QApplication::applicationDirPath() + "/share/locale"; |
m_pMyTranslator = 0; |
156 |
#else |
#ifdef CONFIG_DEBUG |
157 |
sLocPath = CONFIG_PREFIX "/share/locale"; |
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm", |
158 |
#endif |
loc.name().toUtf8().constData(), |
159 |
if (m_pMyTranslator->load(sLocName, sLocPath)) { |
sLocPath.toUtf8().constData(), |
160 |
QApplication::installTranslator(m_pMyTranslator); |
sLocName.toUtf8().constData()); |
161 |
} else { |
#endif |
|
delete m_pMyTranslator; |
|
|
m_pMyTranslator = 0; |
|
|
#ifdef CONFIG_DEBUG |
|
|
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm", |
|
|
loc.name().toUtf8().constData(), |
|
|
sLocPath.toUtf8().constData(), |
|
|
sLocName.toUtf8().constData()); |
|
|
#endif |
|
|
} |
|
162 |
} |
} |
163 |
} |
} |
|
#if defined(Q_WS_X11) |
|
|
m_pDisplay = QX11Info::display(); |
|
|
m_aUnique = XInternAtom(m_pDisplay, QSAMPLER_XUNIQUE, false); |
|
|
XGrabServer(m_pDisplay); |
|
|
m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique); |
|
|
XUngrabServer(m_pDisplay); |
|
|
#endif |
|
164 |
} |
} |
165 |
|
#ifdef CONFIG_XUNIQUE |
166 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
167 |
|
#ifdef CONFIG_X11 |
168 |
|
m_pDisplay = nullptr; |
169 |
|
m_aUnique = 0; |
170 |
|
m_wOwner = 0; |
171 |
|
#endif // CONFIG_X11 |
172 |
|
#else |
173 |
|
m_pMemory = nullptr; |
174 |
|
m_pServer = nullptr; |
175 |
|
#endif |
176 |
|
#endif // CONFIG_XUNIQUE |
177 |
|
} |
178 |
|
|
179 |
// Destructor. |
|
180 |
~qsamplerApplication() |
// Destructor. |
181 |
{ |
qsamplerApplication::~qsamplerApplication (void) |
182 |
if (m_pMyTranslator) delete m_pMyTranslator; |
{ |
183 |
if (m_pQtTranslator) delete m_pQtTranslator; |
#ifdef CONFIG_XUNIQUE |
184 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
185 |
|
if (m_pServer) { |
186 |
|
m_pServer->close(); |
187 |
|
delete m_pServer; |
188 |
|
m_pServer = nullptr; |
189 |
} |
} |
190 |
|
if (m_pMemory) { |
191 |
|
delete m_pMemory; |
192 |
|
m_pMemory = nullptr; |
193 |
|
} |
194 |
|
#endif |
195 |
|
#endif // CONFIG_XUNIQUE |
196 |
|
if (m_pMyTranslator) delete m_pMyTranslator; |
197 |
|
if (m_pQtTranslator) delete m_pQtTranslator; |
198 |
|
} |
199 |
|
|
200 |
// Main application widget accessors. |
|
201 |
void setMainWidget(QWidget *pWidget) |
// Main application widget accessors. |
202 |
{ |
void qsamplerApplication::setMainWidget ( QWidget *pWidget ) |
203 |
m_pWidget = pWidget; |
{ |
204 |
#if defined(Q_WS_X11) |
m_pWidget = pWidget; |
205 |
|
#ifdef CONFIG_XUNIQUE |
206 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
207 |
|
#ifdef CONFIG_X11 |
208 |
|
m_wOwner = m_pWidget->winId(); |
209 |
|
if (m_pDisplay && m_wOwner) { |
210 |
XGrabServer(m_pDisplay); |
XGrabServer(m_pDisplay); |
|
m_wOwner = m_pWidget->winId(); |
|
211 |
XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime); |
XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime); |
212 |
XUngrabServer(m_pDisplay); |
XUngrabServer(m_pDisplay); |
|
#endif |
|
213 |
} |
} |
214 |
|
#endif // CONFIG_X11 |
215 |
|
#endif |
216 |
|
#endif // CONFIG_XUNIQUE |
217 |
|
} |
218 |
|
|
|
QWidget *mainWidget() const { return m_pWidget; } |
|
219 |
|
|
220 |
// Check if another instance is running, |
// Check if another instance is running, |
221 |
// and raise its proper main widget... |
// and raise its proper main widget... |
222 |
bool setup() |
bool qsamplerApplication::setup (void) |
223 |
{ |
{ |
224 |
#if defined(Q_WS_X11) |
#ifdef CONFIG_XUNIQUE |
225 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
226 |
|
#ifdef CONFIG_X11 |
227 |
|
m_pDisplay = QX11Info::display(); |
228 |
|
if (m_pDisplay) { |
229 |
|
QString sUnique = QSAMPLER_XUNIQUE; |
230 |
|
char szHostName[255]; |
231 |
|
if (::gethostname(szHostName, sizeof(szHostName)) == 0) { |
232 |
|
sUnique += '@'; |
233 |
|
sUnique += szHostName; |
234 |
|
} |
235 |
|
m_aUnique = XInternAtom(m_pDisplay, sUnique.toUtf8().constData(), false); |
236 |
|
XGrabServer(m_pDisplay); |
237 |
|
m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique); |
238 |
|
XUngrabServer(m_pDisplay); |
239 |
if (m_wOwner != None) { |
if (m_wOwner != None) { |
240 |
// First, notify any freedesktop.org WM |
// First, notify any freedesktop.org WM |
241 |
// that we're about to show the main widget... |
// that we're about to show the main widget... |
259 |
XSync(m_pDisplay, false); |
XSync(m_pDisplay, false); |
260 |
XRaiseWindow(m_pDisplay, m_wOwner); |
XRaiseWindow(m_pDisplay, m_wOwner); |
261 |
// And then, let it get caught on destination |
// And then, let it get caught on destination |
262 |
// by QApplication::x11EventFilter... |
// by QApplication::native/x11EventFilter... |
263 |
QByteArray value = QSAMPLER_XUNIQUE; |
const QByteArray value = QSAMPLER_XUNIQUE; |
264 |
XChangeProperty( |
XChangeProperty( |
265 |
m_pDisplay, |
m_pDisplay, |
266 |
m_wOwner, |
m_wOwner, |
272 |
// Done. |
// Done. |
273 |
return true; |
return true; |
274 |
} |
} |
|
#endif |
|
|
return false; |
|
275 |
} |
} |
276 |
|
#endif // CONFIG_X11 |
277 |
#if defined(Q_WS_X11) |
return false; |
278 |
bool x11EventFilter(XEvent *pEv) |
#else |
279 |
{ |
m_sUnique = QCoreApplication::applicationName(); |
280 |
if (m_pWidget && m_wOwner != None |
m_sUnique += '@'; |
281 |
&& pEv->type == PropertyNotify |
m_sUnique += QHostInfo::localHostName(); |
282 |
&& pEv->xproperty.window == m_wOwner |
#ifdef Q_OS_UNIX |
283 |
&& pEv->xproperty.state == PropertyNewValue) { |
m_pMemory = new QSharedMemory(m_sUnique); |
284 |
// Always check whether our property-flag is still around... |
m_pMemory->attach(); |
285 |
Atom aType; |
delete m_pMemory; |
286 |
int iFormat = 0; |
#endif |
287 |
unsigned long iItems = 0; |
m_pMemory = new QSharedMemory(m_sUnique); |
288 |
unsigned long iAfter = 0; |
bool bServer = false; |
289 |
unsigned char *pData = 0; |
const qint64 pid = QCoreApplication::applicationPid(); |
290 |
if (XGetWindowProperty( |
struct Data { qint64 pid; }; |
291 |
m_pDisplay, |
if (m_pMemory->create(sizeof(Data))) { |
292 |
m_wOwner, |
m_pMemory->lock(); |
293 |
m_aUnique, |
Data *pData = static_cast<Data *> (m_pMemory->data()); |
294 |
0, 1024, |
if (pData) { |
295 |
false, |
pData->pid = pid; |
296 |
m_aUnique, |
bServer = true; |
|
&aType, |
|
|
&iFormat, |
|
|
&iItems, |
|
|
&iAfter, |
|
|
&pData) == Success |
|
|
&& aType == m_aUnique && iItems > 0 && iAfter == 0) { |
|
|
// Avoid repeating it-self... |
|
|
XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique); |
|
|
// Just make it always shows up fine... |
|
|
m_pWidget->show(); |
|
|
m_pWidget->raise(); |
|
|
m_pWidget->activateWindow(); |
|
|
} |
|
|
// Free any left-overs... |
|
|
if (iItems > 0 && pData) |
|
|
XFree(pData); |
|
297 |
} |
} |
298 |
return QApplication::x11EventFilter(pEv); |
m_pMemory->unlock(); |
299 |
} |
} |
300 |
|
else |
301 |
|
if (m_pMemory->attach()) { |
302 |
|
m_pMemory->lock(); // maybe not necessary? |
303 |
|
Data *pData = static_cast<Data *> (m_pMemory->data()); |
304 |
|
if (pData) |
305 |
|
bServer = (pData->pid == pid); |
306 |
|
m_pMemory->unlock(); |
307 |
|
} |
308 |
|
if (bServer) { |
309 |
|
QLocalServer::removeServer(m_sUnique); |
310 |
|
m_pServer = new QLocalServer(); |
311 |
|
m_pServer->setSocketOptions(QLocalServer::UserAccessOption); |
312 |
|
m_pServer->listen(m_sUnique); |
313 |
|
QObject::connect(m_pServer, |
314 |
|
SIGNAL(newConnection()), |
315 |
|
SLOT(newConnectionSlot())); |
316 |
|
} else { |
317 |
|
QLocalSocket socket; |
318 |
|
socket.connectToServer(m_sUnique); |
319 |
|
if (socket.state() == QLocalSocket::ConnectingState) |
320 |
|
socket.waitForConnected(200); |
321 |
|
if (socket.state() == QLocalSocket::ConnectedState) { |
322 |
|
socket.write(QCoreApplication::arguments().join(' ').toUtf8()); |
323 |
|
socket.flush(); |
324 |
|
socket.waitForBytesWritten(200); |
325 |
|
} |
326 |
|
} |
327 |
|
return !bServer; |
328 |
#endif |
#endif |
329 |
|
#else |
330 |
private: |
return false; |
331 |
|
#endif // !CONFIG_XUNIQUE |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
#ifdef CONFIG_XUNIQUE |
336 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
337 |
|
#ifdef CONFIG_X11 |
338 |
|
|
339 |
// Translation support. |
void qsamplerApplication::x11PropertyNotify ( Window w ) |
340 |
QTranslator *m_pQtTranslator; |
{ |
341 |
QTranslator *m_pMyTranslator; |
if (m_pDisplay && m_pWidget && m_wOwner == w) { |
342 |
|
// Always check whether our property-flag is still around... |
343 |
|
Atom aType; |
344 |
|
int iFormat = 0; |
345 |
|
unsigned long iItems = 0; |
346 |
|
unsigned long iAfter = 0; |
347 |
|
unsigned char *pData = 0; |
348 |
|
if (XGetWindowProperty( |
349 |
|
m_pDisplay, |
350 |
|
m_wOwner, |
351 |
|
m_aUnique, |
352 |
|
0, 1024, |
353 |
|
false, |
354 |
|
m_aUnique, |
355 |
|
&aType, |
356 |
|
&iFormat, |
357 |
|
&iItems, |
358 |
|
&iAfter, |
359 |
|
&pData) == Success |
360 |
|
&& aType == m_aUnique && iItems > 0 && iAfter == 0) { |
361 |
|
// Avoid repeating it-self... |
362 |
|
XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique); |
363 |
|
// Just make it always shows up fine... |
364 |
|
m_pWidget->show(); |
365 |
|
m_pWidget->raise(); |
366 |
|
m_pWidget->activateWindow(); |
367 |
|
} |
368 |
|
// Free any left-overs... |
369 |
|
if (iItems > 0 && pData) |
370 |
|
XFree(pData); |
371 |
|
} |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
|
bool qsamplerApplication::x11EventFilter ( XEvent *pEv ) |
376 |
|
{ |
377 |
|
if (pEv->type == PropertyNotify |
378 |
|
&& pEv->xproperty.state == PropertyNewValue) |
379 |
|
x11PropertyNotify(pEv->xproperty.window); |
380 |
|
return QApplication::x11EventFilter(pEv); |
381 |
|
} |
382 |
|
|
383 |
// Instance variables. |
#endif // CONFIG_X11 |
384 |
QWidget *m_pWidget; |
#else |
385 |
|
|
386 |
|
// Local server conection slot. |
387 |
|
void qsamplerApplication::newConnectionSlot (void) |
388 |
|
{ |
389 |
|
QLocalSocket *pSocket = m_pServer->nextPendingConnection(); |
390 |
|
QObject::connect(pSocket, |
391 |
|
SIGNAL(readyRead()), |
392 |
|
SLOT(readyReadSlot())); |
393 |
|
} |
394 |
|
|
395 |
|
// Local server data-ready slot. |
396 |
|
void qsamplerApplication::readyReadSlot (void) |
397 |
|
{ |
398 |
|
QLocalSocket *pSocket = qobject_cast<QLocalSocket *> (sender()); |
399 |
|
if (pSocket) { |
400 |
|
const qint64 nread = pSocket->bytesAvailable(); |
401 |
|
if (nread > 0) { |
402 |
|
const QByteArray data = pSocket->read(nread); |
403 |
|
// Just make it always shows up fine... |
404 |
|
m_pWidget->hide(); |
405 |
|
m_pWidget->show(); |
406 |
|
m_pWidget->raise(); |
407 |
|
m_pWidget->activateWindow(); |
408 |
|
} |
409 |
|
} |
410 |
|
} |
411 |
|
|
|
#if defined(Q_WS_X11) |
|
|
Display *m_pDisplay; |
|
|
Atom m_aUnique; |
|
|
Window m_wOwner; |
|
412 |
#endif |
#endif |
413 |
}; |
#endif // CONFIG_XUNIQUE |
414 |
|
|
415 |
|
|
416 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
423 |
#include <stdio.h> |
#include <stdio.h> |
424 |
#include <errno.h> |
#include <errno.h> |
425 |
#include <signal.h> |
#include <signal.h> |
426 |
|
#include <unistd.h> |
427 |
#include <sys/wait.h> |
#include <sys/wait.h> |
428 |
|
|
429 |
void stacktrace ( int signo ) |
void stacktrace ( int signo ) |
434 |
char cmd[80]; |
char cmd[80]; |
435 |
|
|
436 |
// Reinstall default handler; prevent race conditions... |
// Reinstall default handler; prevent race conditions... |
437 |
signal(signo, SIG_DFL); |
::signal(signo, SIG_DFL); |
438 |
|
|
439 |
static const char *shell = "/bin/sh"; |
static const char *shell = "/bin/sh"; |
440 |
static const char *format = "gdb -q --batch --pid=%d --eval-command=bt"; |
static const char *format = "gdb -q --batch --pid=%d" |
441 |
|
" --eval-command='thread apply all bt'"; |
442 |
|
|
443 |
snprintf(cmd, sizeof(cmd), format, (int) getpid()); |
snprintf(cmd, sizeof(cmd), format, (int) getpid()); |
444 |
|
|
450 |
|
|
451 |
// Fork child... |
// Fork child... |
452 |
if (pid == 0) { |
if (pid == 0) { |
453 |
execl(shell, shell, "-c", cmd, NULL); |
execl(shell, shell, "-c", cmd, nullptr); |
454 |
_exit(1); |
_exit(1); |
455 |
return; |
return; |
456 |
} |
} |
480 |
Q_INIT_RESOURCE(qsampler); |
Q_INIT_RESOURCE(qsampler); |
481 |
#ifdef CONFIG_STACKTRACE |
#ifdef CONFIG_STACKTRACE |
482 |
#if defined(__GNUC__) && defined(Q_OS_LINUX) |
#if defined(__GNUC__) && defined(Q_OS_LINUX) |
483 |
signal(SIGILL, stacktrace); |
::signal(SIGILL, stacktrace); |
484 |
signal(SIGFPE, stacktrace); |
::signal(SIGFPE, stacktrace); |
485 |
signal(SIGSEGV, stacktrace); |
::signal(SIGSEGV, stacktrace); |
486 |
signal(SIGABRT, stacktrace); |
::signal(SIGABRT, stacktrace); |
487 |
signal(SIGBUS, stacktrace); |
::signal(SIGBUS, stacktrace); |
488 |
|
#endif |
489 |
|
#endif |
490 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) |
491 |
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
492 |
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
493 |
#endif |
#endif |
494 |
#endif |
#endif |
495 |
qsamplerApplication app(argc, argv); |
qsamplerApplication app(argc, argv); |
523 |
return 2; |
return 2; |
524 |
} |
} |
525 |
|
|
526 |
// Dark themes grayed/disabled color group fix... |
// Special custom styles... |
527 |
|
if (QDir(CONFIG_PLUGINSDIR).exists()) |
528 |
|
app.addLibraryPath(CONFIG_PLUGINSDIR); |
529 |
|
if (!options.sCustomStyleTheme.isEmpty()) |
530 |
|
app.setStyle(QStyleFactory::create(options.sCustomStyleTheme)); |
531 |
|
|
532 |
|
// Custom color theme (eg. "KXStudio")... |
533 |
QPalette pal(app.palette()); |
QPalette pal(app.palette()); |
534 |
if (pal.base().color().value() < 0x7f) { |
if (QSampler::PaletteForm::namedPalette( |
535 |
pal.setColorGroup(QPalette::Disabled, |
&options.settings(), options.sCustomColorTheme, pal)) |
|
pal.windowText().color().darker(), |
|
|
pal.button(), |
|
|
pal.light(), |
|
|
pal.dark(), |
|
|
pal.mid(), |
|
|
pal.text().color().darker(), |
|
|
pal.text().color().lighter(), |
|
|
pal.base(), |
|
|
pal.window()); |
|
536 |
app.setPalette(pal); |
app.setPalette(pal); |
|
} |
|
537 |
|
|
538 |
// Set default base font... |
// Set default base font... |
|
int iBaseFontSize = app.font().pointSize(); |
|
539 |
if (options.iBaseFontSize > 0) |
if (options.iBaseFontSize > 0) |
540 |
iBaseFontSize = options.iBaseFontSize; |
app.setFont(QFont(app.font().family(), options.iBaseFontSize)); |
|
app.setFont(QFont(app.font().family(), iBaseFontSize)); |
|
541 |
|
|
542 |
// Construct, setup and show the main form. |
// Construct, setup and show the main form. |
543 |
QSampler::MainForm w; |
QSampler::MainForm w; |
555 |
|
|
556 |
|
|
557 |
// end of qsampler.cpp |
// end of qsampler.cpp |
558 |
|
|