/[svn]/qsampler/trunk/src/qsampler.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2144 by persson, Wed Oct 6 18:49:54 2010 UTC revision 4040 by capela, Sun Jul 10 09:22:44 2022 UTC
# Line 1  Line 1 
1  // qsampler.cpp  // qsampler.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2022, 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
# Line 20  Line 20 
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 QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
39    #include <lscp/client.h>
40    #ifdef CONFIG_LIBGIG
41    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
42    #pragma GCC diagnostic push
43    #pragma GCC diagnostic ignored "-Wunused-parameter"
44    #endif
45    #include <gig.h>
46    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
47    #pragma GCC diagnostic pop
48    #endif
49    #endif
50    #endif
51    
52  #if defined(__APPLE__)  // Toshi Nagata 20080105  #if defined(__APPLE__)  // Toshi Nagata 20080105
53  #include <QDir>  #include <QDir>
54  #endif  #endif
55    
56  #if QT_VERSION < 0x040300  #ifndef CONFIG_PREFIX
57  #define lighter(x)      light(x)  #define CONFIG_PREFIX   "/usr/local"
58  #define darker(x)       dark(x)  #endif
59    
60    #ifndef CONFIG_BINDIR
61    #define CONFIG_BINDIR   CONFIG_PREFIX "/bin"
62    #endif
63    
64    #ifndef CONFIG_DATADIR
65    #define CONFIG_DATADIR  CONFIG_PREFIX "/share"
66    #endif
67    
68    #ifndef CONFIG_LIBDIR
69    #if defined(__x86_64__)
70    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib64"
71    #else
72    #define CONFIG_LIBDIR  CONFIG_PREFIX "/lib"
73    #endif
74    #endif
75    
76    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
77    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt4/plugins"
78    #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
79    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt5/plugins"
80    #else
81    #define CONFIG_PLUGINSDIR CONFIG_LIBDIR "/qt6/plugins"
82    #endif
83    
84    #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
85    #define RELATIVE_LOCALE_DIR "/share/locale"
86    #elif defined(__APPLE__)
87    #define RELATIVE_LOCALE_DIR "/../Resources"
88  #endif  #endif
89    
90    
# Line 42  Line 92 
92  // Singleton application instance stuff (Qt/X11 only atm.)  // Singleton application instance stuff (Qt/X11 only atm.)
93  //  //
94    
95  #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
96    
97    #define QSAMPLER_XUNIQUE "qsamplerApplication"
98    
99  #include <QX11Info>  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
100    #ifdef CONFIG_X11
101    
102    #include <unistd.h> /* for gethostname() */
103    
104  #include <X11/Xatom.h>  #include <X11/Xatom.h>
105  #include <X11/Xlib.h>  #include <X11/Xlib.h>
106    
107  #define QSAMPLER_XUNIQUE "qsamplerMainForm_xunique"  #endif  // CONFIG_X11
108    #else
109    #include <QSharedMemory>
110    #include <QLocalServer>
111    #include <QLocalSocket>
112    #include <QHostInfo>
113  #endif  #endif
114    
115  class qsamplerApplication : public QApplication  #endif  // CONFIG_XUNIQUE
 {  
 public:  
116    
117          // Constructor.  
118          qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv),  // Constructor.
119                  m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)      qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
120          {          : QApplication(argc, argv),
121                  // Load translation support.                  m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
122                  QLocale loc;  {
123                  if (loc.language() != QLocale::C) {  #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
124                          // Try own Qt translation...          QApplication::setApplicationName(QSAMPLER_TITLE);
125                          m_pQtTranslator = new QTranslator(this);          QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
126                          QString sLocName = "qt_" + loc.name();          //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
127                          QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);  #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
128            QApplication::setDesktopFileName(
129                    QString("org.rncbc.%1").arg(PACKAGE_TARNAME));
130    #endif
131            QString sVersion(CONFIG_BUILD_VERSION);
132            sVersion += '\n';
133            sVersion += QString("Qt: %1").arg(qVersion());
134    #if defined(QT_STATIC)
135            sVersion += "-static";
136    #endif
137            sVersion += '\n';
138    #ifdef CONFIG_LIBGIG
139            sVersion += QString("%1: %2")
140                    .arg(gig::libraryName().c_str())
141                    .arg(gig::libraryVersion().c_str());
142            sVersion += '\n';
143    #endif
144            sVersion += QString("%1: %2")
145                    .arg(::lscp_client_package())
146                    .arg(::lscp_client_version());
147            QApplication::setApplicationVersion(sVersion);
148    #endif
149            // Load translation support.
150            QLocale loc;
151            if (loc.language() != QLocale::C) {
152                    // Try own Qt translation...
153                    m_pQtTranslator = new QTranslator(this);
154                    QString sLocName = "qt_" + loc.name();
155            #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
156                    QString sLocPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
157            #else
158                    QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
159            #endif
160                    if (m_pQtTranslator->load(sLocName, sLocPath)) {
161                            QApplication::installTranslator(m_pQtTranslator);
162                    } else {
163                            sLocPath = QApplication::applicationDirPath();
164                    #ifdef RELATIVE_LOCALE_DIR
165                            sLocPath.append(RELATIVE_LOCALE_DIR);
166                    #else
167                            sLocPath.remove(CONFIG_BINDIR);
168                            sLocPath.append(CONFIG_DATADIR "/qsampler/translations");
169                    #endif
170                          if (m_pQtTranslator->load(sLocName, sLocPath)) {                          if (m_pQtTranslator->load(sLocName, sLocPath)) {
171                                  QApplication::installTranslator(m_pQtTranslator);                                  QApplication::installTranslator(m_pQtTranslator);
172                          } else {                          } else {
                 #if WIN32  
                                 sLocPath = QApplication::applicationDirPath() + "/share/locale";  
                                 if (m_pQtTranslator->load(sLocName, sLocPath)) {  
                                         QApplication::installTranslator(m_pQtTranslator);  
                                 } else {  
                 #endif  
173                                  delete m_pQtTranslator;                                  delete m_pQtTranslator;
174                                  m_pQtTranslator = 0;                                  m_pQtTranslator = nullptr;
175                  #ifdef CONFIG_DEBUG                          #ifdef CONFIG_DEBUG
176                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
177                                          loc.name().toUtf8().constData(),                                          loc.name().toUtf8().constData(),
178                                          sLocPath.toUtf8().constData(),                                          sLocPath.toUtf8().constData(),
179                                          sLocName.toUtf8().constData());                                          sLocName.toUtf8().constData());
180                  #endif                          #endif
                 #if WIN32  
                                 }  
                 #endif  
181                          }                          }
182                          // Try own application translation...                  }
183                          m_pMyTranslator = new QTranslator(this);                  // Try own application translation...
184                          sLocName = "qsampler_" + loc.name();                  m_pMyTranslator = new QTranslator(this);
185                    sLocName = "qsampler_" + loc.name();
186                    if (m_pMyTranslator->load(sLocName, sLocPath)) {
187                            QApplication::installTranslator(m_pMyTranslator);
188                    } else {
189                    #ifdef RELATIVE_LOCALE_DIR
190                            sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
191                    #else
192                            sLocPath = CONFIG_DATADIR "/qsampler/translations";
193                    #endif
194                          if (m_pMyTranslator->load(sLocName, sLocPath)) {                          if (m_pMyTranslator->load(sLocName, sLocPath)) {
195                                  QApplication::installTranslator(m_pMyTranslator);                                  QApplication::installTranslator(m_pMyTranslator);
196                          } else {                          } else {
197                  #if WIN32                                  delete m_pMyTranslator;
198                                  sLocPath = QApplication::applicationDirPath() + "/share/locale";                                  m_pMyTranslator = nullptr;
199                  #else                          #ifdef CONFIG_DEBUG
200                                  sLocPath = CONFIG_PREFIX "/share/locale";                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
201                  #endif                                          loc.name().toUtf8().constData(),
202                                  if (m_pMyTranslator->load(sLocName, sLocPath)) {                                          sLocPath.toUtf8().constData(),
203                                          QApplication::installTranslator(m_pMyTranslator);                                          sLocName.toUtf8().constData());
204                                  } 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  
                                 }  
205                          }                          }
206                  }                  }
         #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  
207          }          }
208    #ifdef CONFIG_XUNIQUE
209    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
210    #ifdef CONFIG_X11
211            m_pDisplay = nullptr;
212            m_aUnique = 0;
213            m_wOwner = 0;
214    #endif  // CONFIG_X11
215    #else
216            m_pMemory = nullptr;
217            m_pServer = nullptr;
218    #endif
219    #endif  // CONFIG_XUNIQUE
220    }
221    
222          // Destructor.  
223          ~qsamplerApplication()  // Destructor.
224          {  qsamplerApplication::~qsamplerApplication (void)
225                  if (m_pMyTranslator) delete m_pMyTranslator;  {
226                  if (m_pQtTranslator) delete m_pQtTranslator;  #ifdef CONFIG_XUNIQUE
227    #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
228            if (m_pServer) {
229                    m_pServer->close();
230                    delete m_pServer;
231                    m_pServer = nullptr;
232          }          }
233            if (m_pMemory) {
234                    delete m_pMemory;
235                    m_pMemory = nullptr;
236    }
237    #endif
238    #endif  // CONFIG_XUNIQUE
239            if (m_pMyTranslator) delete m_pMyTranslator;
240            if (m_pQtTranslator) delete m_pQtTranslator;
241    }
242    
243          // Main application widget accessors.  
244          void setMainWidget(QWidget *pWidget)  // Main application widget accessors.
245          {  void qsamplerApplication::setMainWidget ( QWidget *pWidget )
246                  m_pWidget = pWidget;  {
247          #if defined(Q_WS_X11)          m_pWidget = pWidget;
248    #ifdef CONFIG_XUNIQUE
249    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
250    #ifdef CONFIG_X11
251            m_wOwner = m_pWidget->winId();
252            if (m_pDisplay && m_wOwner) {
253                  XGrabServer(m_pDisplay);                  XGrabServer(m_pDisplay);
                 m_wOwner = m_pWidget->winId();  
254                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);                  XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);
255                  XUngrabServer(m_pDisplay);                  XUngrabServer(m_pDisplay);
         #endif  
256          }          }
257    #endif  // CONFIG_X11
258    #endif
259    #endif  // CONFIG_XUNIQUE
260    }
261    
         QWidget *mainWidget() const { return m_pWidget; }  
262    
263          // Check if another instance is running,  // Check if another instance is running,
264      // and raise its proper main widget...  // and raise its proper main widget...
265          bool setup()  bool qsamplerApplication::setup (void)
266          {  {
267          #if defined(Q_WS_X11)  #ifdef CONFIG_XUNIQUE
268    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
269    #ifdef CONFIG_X11
270            m_pDisplay = QX11Info::display();
271            if (m_pDisplay) {
272                    QString sUnique = QSAMPLER_XUNIQUE;
273                    QString sUserName = QString::fromUtf8(::getenv("USER"));
274                    if (sUserName.isEmpty())
275                            sUserName = QString::fromUtf8(::getenv("USERNAME"));
276                    if (!sUserName.isEmpty()) {
277                            sUnique += ':';
278                            sUnique += sUserName;
279                    }
280                    char szHostName[255];
281                    if (::gethostname(szHostName, sizeof(szHostName)) == 0) {
282                            sUnique += '@';
283                            sUnique += QString::fromUtf8(szHostName);
284                    }
285                    m_aUnique = XInternAtom(m_pDisplay, sUnique.toUtf8().constData(), false);
286                    XGrabServer(m_pDisplay);
287                    m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);
288                    XUngrabServer(m_pDisplay);
289                  if (m_wOwner != None) {                  if (m_wOwner != None) {
290                          // First, notify any freedesktop.org WM                          // First, notify any freedesktop.org WM
291                          // that we're about to show the main widget...                          // that we're about to show the main widget...
# Line 172  public: Line 309  public:
309                          XSync(m_pDisplay, false);                          XSync(m_pDisplay, false);
310                          XRaiseWindow(m_pDisplay, m_wOwner);                          XRaiseWindow(m_pDisplay, m_wOwner);
311                          // And then, let it get caught on destination                          // And then, let it get caught on destination
312                          // by QApplication::x11EventFilter...                          // by QApplication::native/x11EventFilter...
313                          QByteArray value = QSAMPLER_XUNIQUE;                          const QByteArray value = QSAMPLER_XUNIQUE;
314                          XChangeProperty(                          XChangeProperty(
315                                  m_pDisplay,                                  m_pDisplay,
316                                  m_wOwner,                                  m_wOwner,
# Line 185  public: Line 322  public:
322                          // Done.                          // Done.
323                          return true;                          return true;
324                  }                  }
         #endif  
                 return false;  
325          }          }
326    #endif  // CONFIG_X11
327  #if defined(Q_WS_X11)          return false;
328          bool x11EventFilter(XEvent *pEv)  #else
329          {          m_sUnique = QCoreApplication::applicationName();
330                  if (m_pWidget && m_wOwner != None          QString sUserName = QString::fromUtf8(::getenv("USER"));
331                          && pEv->type == PropertyNotify          if (sUserName.isEmpty())
332                          && pEv->xproperty.window == m_wOwner                  sUserName = QString::fromUtf8(::getenv("USERNAME"));
333                          && pEv->xproperty.state == PropertyNewValue) {          if (!sUserName.isEmpty()) {
334                          // Always check whether our property-flag is still around...                  m_sUnique += ':';
335                          Atom aType;                  m_sUnique += sUserName;
336                          int iFormat = 0;          }
337                          unsigned long iItems = 0;          m_sUnique += '@';
338                          unsigned long iAfter = 0;          m_sUnique += QHostInfo::localHostName();
339                          unsigned char *pData = 0;  #ifdef Q_OS_UNIX
340                          if (XGetWindowProperty(          m_pMemory = new QSharedMemory(m_sUnique);
341                                          m_pDisplay,          m_pMemory->attach();
342                                          m_wOwner,          delete m_pMemory;
343                                          m_aUnique,  #endif
344                                          0, 1024,          m_pMemory = new QSharedMemory(m_sUnique);
345                                          false,          bool bServer = false;
346                                          m_aUnique,          const qint64 pid = QCoreApplication::applicationPid();
347                                          &aType,          struct Data { qint64 pid; };
348                                          &iFormat,          if (m_pMemory->create(sizeof(Data))) {
349                                          &iItems,                  m_pMemory->lock();
350                                          &iAfter,                  Data *pData = static_cast<Data *> (m_pMemory->data());
351                                          &pData) == Success                  if (pData) {
352                                  && aType == m_aUnique && iItems > 0 && iAfter == 0) {                          pData->pid = pid;
353                                  // Avoid repeating it-self...                          bServer = true;
                                 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);  
354                  }                  }
355                  return QApplication::x11EventFilter(pEv);                  m_pMemory->unlock();
356            }
357            else
358            if (m_pMemory->attach()) {
359                    m_pMemory->lock(); // maybe not necessary?
360                    Data *pData = static_cast<Data *> (m_pMemory->data());
361                    if (pData)
362                            bServer = (pData->pid == pid);
363                    m_pMemory->unlock();
364          }          }
365            if (bServer) {
366                    QLocalServer::removeServer(m_sUnique);
367                    m_pServer = new QLocalServer();
368                    m_pServer->setSocketOptions(QLocalServer::UserAccessOption);
369                    m_pServer->listen(m_sUnique);
370                    QObject::connect(m_pServer,
371                            SIGNAL(newConnection()),
372                            SLOT(newConnectionSlot()));
373            } else {
374                    QLocalSocket socket;
375                    socket.connectToServer(m_sUnique);
376                    if (socket.state() == QLocalSocket::ConnectingState)
377                            socket.waitForConnected(200);
378                    if (socket.state() == QLocalSocket::ConnectedState) {
379                            socket.write(QCoreApplication::arguments().join(' ').toUtf8());
380                            socket.flush();
381                            socket.waitForBytesWritten(200);
382                    }
383            }
384            return !bServer;
385  #endif  #endif
386            #else
387  private:          return false;
388    #endif  // !CONFIG_XUNIQUE
389    }
390    
         // Translation support.  
         QTranslator *m_pQtTranslator;  
         QTranslator *m_pMyTranslator;  
391    
392          // Instance variables.  #ifdef CONFIG_XUNIQUE
393          QWidget *m_pWidget;  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
394    #ifdef CONFIG_X11
395    
396    void qsamplerApplication::x11PropertyNotify ( Window w )
397    {
398            if (m_pDisplay && m_pWidget && m_wOwner == w) {
399                    // Always check whether our property-flag is still around...
400                    Atom aType;
401                    int iFormat = 0;
402                    unsigned long iItems = 0;
403                    unsigned long iAfter = 0;
404                    unsigned char *pData = 0;
405                    if (XGetWindowProperty(
406                                    m_pDisplay,
407                                    m_wOwner,
408                                    m_aUnique,
409                                    0, 1024,
410                                    false,
411                                    m_aUnique,
412                                    &aType,
413                                    &iFormat,
414                                    &iItems,
415                                    &iAfter,
416                                    &pData) == Success
417                            && aType == m_aUnique && iItems > 0 && iAfter == 0) {
418                            // Avoid repeating it-self...
419                            XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);
420                            // Just make it always shows up fine...
421                            m_pWidget->show();
422                            m_pWidget->raise();
423                            m_pWidget->activateWindow();
424                    }
425                    // Free any left-overs...
426                    if (iItems > 0 && pData)
427                            XFree(pData);
428            }
429    }
430    
431    
432    bool qsamplerApplication::x11EventFilter ( XEvent *pEv )
433    {
434            if (pEv->type == PropertyNotify
435                    && pEv->xproperty.state == PropertyNewValue)
436                    x11PropertyNotify(pEv->xproperty.window);
437            return QApplication::x11EventFilter(pEv);
438    }
439    
440    #endif  // CONFIG_X11
441    #else
442    
443    // Local server conection slot.
444    void qsamplerApplication::newConnectionSlot (void)
445    {
446            QLocalSocket *pSocket = m_pServer->nextPendingConnection();
447            QObject::connect(pSocket,
448                    SIGNAL(readyRead()),
449                    SLOT(readyReadSlot()));
450    }
451    
452    // Local server data-ready slot.
453    void qsamplerApplication::readyReadSlot (void)
454    {
455            QLocalSocket *pSocket = qobject_cast<QLocalSocket *> (sender());
456            if (pSocket) {
457                    const qint64 nread = pSocket->bytesAvailable();
458                    if (nread > 0) {
459                            const QByteArray data = pSocket->read(nread);
460                            // Just make it always shows up fine...
461                            m_pWidget->hide();
462                            m_pWidget->show();
463                            m_pWidget->raise();
464                            m_pWidget->activateWindow();
465                    }
466            }
467    }
468    
 #if defined(Q_WS_X11)  
         Display *m_pDisplay;  
         Atom     m_aUnique;  
         Window   m_wOwner;  
469  #endif  #endif
470  };  #endif  // CONFIG_XUNIQUE
471    
472    
473  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 257  private: Line 480  private:
480  #include <stdio.h>  #include <stdio.h>
481  #include <errno.h>  #include <errno.h>
482  #include <signal.h>  #include <signal.h>
483    #include <unistd.h>
484  #include <sys/wait.h>  #include <sys/wait.h>
485    
486  void stacktrace ( int signo )  void stacktrace ( int signo )
# Line 267  void stacktrace ( int signo ) Line 491  void stacktrace ( int signo )
491          char cmd[80];          char cmd[80];
492    
493          // Reinstall default handler; prevent race conditions...          // Reinstall default handler; prevent race conditions...
494          signal(signo, SIG_DFL);          ::signal(signo, SIG_DFL);
495    
496          static const char *shell  = "/bin/sh";          static const char *shell  = "/bin/sh";
497          static const char *format = "gdb -q --batch --pid=%d --eval-command=bt";          static const char *format = "gdb -q --batch --pid=%d"
498                    " --eval-command='thread apply all bt'";
499    
500          snprintf(cmd, sizeof(cmd), format, (int) getpid());          snprintf(cmd, sizeof(cmd), format, (int) getpid());
501    
# Line 282  void stacktrace ( int signo ) Line 507  void stacktrace ( int signo )
507    
508          // Fork child...          // Fork child...
509          if (pid == 0) {          if (pid == 0) {
510                  execl(shell, shell, "-c", cmd, NULL);                  execl(shell, shell, "-c", cmd, nullptr);
511                  _exit(1);                  _exit(1);
512                  return;                  return;
513          }          }
# Line 312  int main ( int argc, char **argv ) Line 537  int main ( int argc, char **argv )
537          Q_INIT_RESOURCE(qsampler);          Q_INIT_RESOURCE(qsampler);
538  #ifdef CONFIG_STACKTRACE  #ifdef CONFIG_STACKTRACE
539  #if defined(__GNUC__) && defined(Q_OS_LINUX)  #if defined(__GNUC__) && defined(Q_OS_LINUX)
540          signal(SIGILL,  stacktrace);          ::signal(SIGILL,  stacktrace);
541          signal(SIGFPE,  stacktrace);          ::signal(SIGFPE,  stacktrace);
542          signal(SIGSEGV, stacktrace);          ::signal(SIGSEGV, stacktrace);
543          signal(SIGABRT, stacktrace);          ::signal(SIGABRT, stacktrace);
544          signal(SIGBUS,  stacktrace);          ::signal(SIGBUS,  stacktrace);
545    #endif
546    #endif
547    #if defined(Q_OS_LINUX) && !defined(CONFIG_WAYLAND)
548            ::setenv("QT_QPA_PLATFORM", "xcb", 0);
549    #endif
550    #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
551    #if QT_VERSION <  QT_VERSION_CHECK(6, 0, 0)
552            QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
553  #endif  #endif
554  #endif  #endif
555          qsamplerApplication app(argc, argv);          qsamplerApplication app(argc, argv);
# Line 350  int main ( int argc, char **argv ) Line 583  int main ( int argc, char **argv )
583                  return 2;                  return 2;
584          }          }
585    
586          // Dark themes grayed/disabled color group fix...          // Special custom styles...
587            if (QDir(CONFIG_PLUGINSDIR).exists())
588                    app.addLibraryPath(CONFIG_PLUGINSDIR);
589            if (!options.sCustomStyleTheme.isEmpty())
590                    app.setStyle(QStyleFactory::create(options.sCustomStyleTheme));
591    
592            // Custom color theme (eg. "KXStudio")...
593          QPalette pal(app.palette());          QPalette pal(app.palette());
594          if (pal.base().color().value() < 0x7f) {          if (QSampler::PaletteForm::namedPalette(
595                  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());  
596                  app.setPalette(pal);                  app.setPalette(pal);
         }  
597    
598          // Set default base font...          // Set default base font...
         int iBaseFontSize = app.font().pointSize();  
599          if (options.iBaseFontSize > 0)          if (options.iBaseFontSize > 0)
600                  iBaseFontSize = options.iBaseFontSize;                  app.setFont(QFont(app.font().family(), options.iBaseFontSize));
         app.setFont(QFont(app.font().family(), iBaseFontSize));  
601    
602          // Construct, setup and show the main form.          // Construct, setup and show the main form.
603          QSampler::MainForm w;          QSampler::MainForm w;
# Line 388  int main ( int argc, char **argv ) Line 615  int main ( int argc, char **argv )
615    
616    
617  // end of qsampler.cpp  // end of qsampler.cpp
618    

Legend:
Removed from v.2144  
changed lines
  Added in v.4040

  ViewVC Help
Powered by ViewVC