1 |
// qsampler.cpp |
// qsampler.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2019, 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,2015 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 |
25 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
|
|
28 |
|
#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> |
47 |
#define CONFIG_DATADIR CONFIG_PREFIX "/share" |
#define CONFIG_DATADIR CONFIG_PREFIX "/share" |
48 |
#endif |
#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) |
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) |
65 |
#define RELATIVE_LOCALE_DIR "/share/locale" |
#define RELATIVE_LOCALE_DIR "/share/locale" |
66 |
#elif defined(__APPLE__) |
#elif defined(__APPLE__) |
76 |
|
|
77 |
#define QSAMPLER_XUNIQUE "qsamplerApplication" |
#define QSAMPLER_XUNIQUE "qsamplerApplication" |
78 |
|
|
79 |
#if QT_VERSION < 0x050000 |
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
80 |
#ifdef CONFIG_X11 |
#ifdef CONFIG_X11 |
81 |
|
|
82 |
#include <unistd.h> /* for gethostname() */ |
#include <unistd.h> /* for gethostname() */ |
98 |
// Constructor. |
// Constructor. |
99 |
qsamplerApplication::qsamplerApplication ( int& argc, char **argv ) |
qsamplerApplication::qsamplerApplication ( int& argc, char **argv ) |
100 |
: QApplication(argc, argv), |
: QApplication(argc, argv), |
101 |
m_pQtTranslator(NULL), m_pMyTranslator(NULL), m_pWidget(NULL) |
m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr) |
102 |
{ |
{ |
103 |
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) |
104 |
|
QApplication::setApplicationName(QSAMPLER_TITLE); |
105 |
|
QApplication::setApplicationDisplayName(QSAMPLER_TITLE); |
106 |
|
// QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE)); |
107 |
|
#endif |
108 |
// Load translation support. |
// Load translation support. |
109 |
QLocale loc; |
QLocale loc; |
110 |
if (loc.language() != QLocale::C) { |
if (loc.language() != QLocale::C) { |
111 |
// Try own Qt translation... |
// Try own Qt translation... |
112 |
m_pQtTranslator = new QTranslator(this); |
m_pQtTranslator = new QTranslator(this); |
113 |
QString sLocName = "qt_" + loc.name(); |
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); |
QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); |
118 |
|
#endif |
119 |
if (m_pQtTranslator->load(sLocName, sLocPath)) { |
if (m_pQtTranslator->load(sLocName, sLocPath)) { |
120 |
QApplication::installTranslator(m_pQtTranslator); |
QApplication::installTranslator(m_pQtTranslator); |
121 |
} else { |
} else { |
126 |
} else { |
} else { |
127 |
#endif |
#endif |
128 |
delete m_pQtTranslator; |
delete m_pQtTranslator; |
129 |
m_pQtTranslator = 0; |
m_pQtTranslator = nullptr; |
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(), |
152 |
QApplication::installTranslator(m_pMyTranslator); |
QApplication::installTranslator(m_pMyTranslator); |
153 |
} else { |
} else { |
154 |
delete m_pMyTranslator; |
delete m_pMyTranslator; |
155 |
m_pMyTranslator = 0; |
m_pMyTranslator = nullptr; |
156 |
#ifdef CONFIG_DEBUG |
#ifdef CONFIG_DEBUG |
157 |
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm", |
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm", |
158 |
loc.name().toUtf8().constData(), |
loc.name().toUtf8().constData(), |
163 |
} |
} |
164 |
} |
} |
165 |
#ifdef CONFIG_XUNIQUE |
#ifdef CONFIG_XUNIQUE |
166 |
#if QT_VERSION < 0x050000 |
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
167 |
#ifdef CONFIG_X11 |
#ifdef CONFIG_X11 |
168 |
m_pDisplay = NULL; |
m_pDisplay = nullptr; |
169 |
m_aUnique = 0; |
m_aUnique = 0; |
170 |
m_wOwner = 0; |
m_wOwner = 0; |
171 |
#endif // CONFIG_X11 |
#endif // CONFIG_X11 |
172 |
#else |
#else |
173 |
m_pMemory = NULL; |
m_pMemory = nullptr; |
174 |
m_pServer = NULL; |
m_pServer = nullptr; |
175 |
#endif |
#endif |
176 |
#endif // CONFIG_XUNIQUE |
#endif // CONFIG_XUNIQUE |
177 |
} |
} |
181 |
qsamplerApplication::~qsamplerApplication (void) |
qsamplerApplication::~qsamplerApplication (void) |
182 |
{ |
{ |
183 |
#ifdef CONFIG_XUNIQUE |
#ifdef CONFIG_XUNIQUE |
184 |
#if QT_VERSION >= 0x050000 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
185 |
if (m_pServer) { |
if (m_pServer) { |
186 |
m_pServer->close(); |
m_pServer->close(); |
187 |
delete m_pServer; |
delete m_pServer; |
188 |
m_pServer = NULL; |
m_pServer = nullptr; |
189 |
} |
} |
190 |
if (m_pMemory) { |
if (m_pMemory) { |
191 |
delete m_pMemory; |
delete m_pMemory; |
192 |
m_pMemory = NULL; |
m_pMemory = nullptr; |
193 |
} |
} |
194 |
#endif |
#endif |
195 |
#endif // CONFIG_XUNIQUE |
#endif // CONFIG_XUNIQUE |
203 |
{ |
{ |
204 |
m_pWidget = pWidget; |
m_pWidget = pWidget; |
205 |
#ifdef CONFIG_XUNIQUE |
#ifdef CONFIG_XUNIQUE |
206 |
#if QT_VERSION < 0x050000 |
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
207 |
#ifdef CONFIG_X11 |
#ifdef CONFIG_X11 |
208 |
m_wOwner = m_pWidget->winId(); |
m_wOwner = m_pWidget->winId(); |
209 |
if (m_pDisplay && m_wOwner) { |
if (m_pDisplay && m_wOwner) { |
222 |
bool qsamplerApplication::setup (void) |
bool qsamplerApplication::setup (void) |
223 |
{ |
{ |
224 |
#ifdef CONFIG_XUNIQUE |
#ifdef CONFIG_XUNIQUE |
225 |
#if QT_VERSION < 0x050000 |
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
226 |
#ifdef CONFIG_X11 |
#ifdef CONFIG_X11 |
227 |
m_pDisplay = QX11Info::display(); |
m_pDisplay = QX11Info::display(); |
228 |
if (m_pDisplay) { |
if (m_pDisplay) { |
333 |
|
|
334 |
|
|
335 |
#ifdef CONFIG_XUNIQUE |
#ifdef CONFIG_XUNIQUE |
336 |
#if QT_VERSION < 0x050000 |
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
337 |
#ifdef CONFIG_X11 |
#ifdef CONFIG_X11 |
338 |
|
|
339 |
void qsamplerApplication::x11PropertyNotify ( Window w ) |
void qsamplerApplication::x11PropertyNotify ( Window w ) |
399 |
if (pSocket) { |
if (pSocket) { |
400 |
const qint64 nread = pSocket->bytesAvailable(); |
const qint64 nread = pSocket->bytesAvailable(); |
401 |
if (nread > 0) { |
if (nread > 0) { |
402 |
QByteArray data = pSocket->read(nread); |
const QByteArray data = pSocket->read(nread); |
403 |
// Just make it always shows up fine... |
// Just make it always shows up fine... |
404 |
m_pWidget->hide(); |
m_pWidget->hide(); |
405 |
m_pWidget->show(); |
m_pWidget->show(); |
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" |
static const char *format = "gdb -q --batch --pid=%d" |
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 |
#endif |
489 |
#endif |
#endif |
490 |
qsamplerApplication app(argc, argv); |
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) |
491 |
#if QT_VERSION >= 0x050600 |
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
492 |
app.setAttribute(Qt::AA_EnableHighDpiScaling); |
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
493 |
#endif |
#endif |
494 |
|
#endif |
495 |
|
qsamplerApplication app(argc, argv); |
496 |
|
|
497 |
#if defined(__APPLE__) // Toshi Nagata 20080105 |
#if defined(__APPLE__) // Toshi Nagata 20080105 |
498 |
{ |
{ |
499 |
// Set the plugin path to @exetutable_path/../plugins |
// Set the plugin path to @exetutable_path/../plugins |
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 |
#if QT_VERSION >= 0x050000 |
&options.settings(), options.sCustomColorTheme, pal)) |
|
const QColor& color = pal.window().color(); |
|
|
const int iGroups = int(QPalette::Active | QPalette::Inactive) + 1; |
|
|
for (int i = 0; i < iGroups; ++i) { |
|
|
const QPalette::ColorGroup group = QPalette::ColorGroup(i); |
|
|
pal.setBrush(group, QPalette::Light, color.lighter(150)); |
|
|
pal.setBrush(group, QPalette::Midlight, color.lighter(120)); |
|
|
pal.setBrush(group, QPalette::Dark, color.darker(150)); |
|
|
pal.setBrush(group, QPalette::Mid, color.darker(120)); |
|
|
pal.setBrush(group, QPalette::Shadow, color.darker(200)); |
|
|
} |
|
|
// pal.setColor(QPalette::Disabled, QPalette::ButtonText, pal.mid().color()); |
|
|
#endif |
|
|
pal.setColorGroup(QPalette::Disabled, |
|
|
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... |
539 |
if (options.iBaseFontSize > 0) |
if (options.iBaseFontSize > 0) |