/[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 3465 by capela, Mon Feb 11 16:51:26 2019 UTC revision 4024 by capela, Sun Feb 6 10:50:27 2022 UTC
# Line 1  Line 1 
1  // qsampler.cpp  // qsampler.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2019, 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,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
# 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
# Line 37  Line 57 
57  #define CONFIG_PREFIX   "/usr/local"  #define CONFIG_PREFIX   "/usr/local"
58  #endif  #endif
59    
60    #ifndef CONFIG_BINDIR
61    #define CONFIG_BINDIR   CONFIG_PREFIX "/bin"
62    #endif
63    
64  #ifndef CONFIG_DATADIR  #ifndef CONFIG_DATADIR
65  #define CONFIG_DATADIR  CONFIG_PREFIX "/share"  #define CONFIG_DATADIR  CONFIG_PREFIX "/share"
66  #endif  #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)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
85  #define RELATIVE_LOCALE_DIR "/share/locale"  #define RELATIVE_LOCALE_DIR "/share/locale"
86  #elif defined(__APPLE__)  #elif defined(__APPLE__)
# Line 52  Line 92 
92  // Singleton application instance stuff (Qt/X11 only atm.)  // Singleton application instance stuff (Qt/X11 only atm.)
93  //  //
94    
95  #if QT_VERSION < 0x050000  #ifdef CONFIG_XUNIQUE
 #if defined(Q_WS_X11)  
 #define CONFIG_X11  
 #endif  
 #else  
 #if defined(QT_X11EXTRAS_LIB)  
 #define CONFIG_X11  
 #endif  
 #endif  
96    
97    #define QSAMPLER_XUNIQUE "qsamplerApplication"
98    
99    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
100  #ifdef CONFIG_X11  #ifdef CONFIG_X11
 #ifdef CONFIG_XUNIQUE  
101    
102  #include <QX11Info>  #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 "qsamplerApplication"  #endif  // CONFIG_X11
108    #else
109  #if QT_VERSION >= 0x050100  #include <QSharedMemory>
110    #include <QLocalServer>
111  #include <xcb/xcb.h>  #include <QLocalSocket>
112  #include <xcb/xproto.h>  #include <QHostInfo>
   
 #include <QAbstractNativeEventFilter>  
   
 class qsamplerApplication;  
   
 class qsamplerXcbEventFilter : public QAbstractNativeEventFilter  
 {  
 public:  
   
         // Constructor.  
         qsamplerXcbEventFilter(qsamplerApplication *pApp)  
                 : QAbstractNativeEventFilter(), m_pApp(pApp) {}  
   
         // XCB event filter (virtual processor).  
         bool nativeEventFilter(const QByteArray& eventType, void *message, long *);  
   
 private:  
   
         // Instance variable.  
         qsamplerApplication *m_pApp;  
 };  
   
113  #endif  #endif
114    
115  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
 #endif  // CONFIG_X11  
116    
117    
118  class qsamplerApplication : public QApplication  // Constructor.
119    qsamplerApplication::qsamplerApplication ( int& argc, char **argv )
120            : QApplication(argc, argv),
121                    m_pQtTranslator(nullptr), m_pMyTranslator(nullptr), m_pWidget(nullptr)
122  {  {
123  public:  #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
124            QApplication::setApplicationName(QSAMPLER_TITLE);
125          // Constructor.          QApplication::setApplicationDisplayName(QSAMPLER_TITLE);
126          qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv),          //      QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE));
127                  m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)          QString sVersion(CONFIG_BUILD_VERSION);
128          {          sVersion += '\n';
129                  // Load translation support.          sVersion += QString("Qt: %1").arg(qVersion());
130                  QLocale loc;  #if defined(QT_STATIC)
131                  if (loc.language() != QLocale::C) {          sVersion += "-static";
132                          // Try own Qt translation...  #endif
133                          m_pQtTranslator = new QTranslator(this);          sVersion += '\n';
134                          QString sLocName = "qt_" + loc.name();  #ifdef CONFIG_LIBGIG
135                          QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);          sVersion += QString("%1: %2")
136                    .arg(gig::libraryName().c_str())
137                    .arg(gig::libraryVersion().c_str());
138            sVersion += '\n';
139    #endif
140            sVersion += QString("%1: %2")
141                    .arg(::lscp_client_package())
142                    .arg(::lscp_client_version());
143            QApplication::setApplicationVersion(sVersion);
144    #endif
145            // Load translation support.
146            QLocale loc;
147            if (loc.language() != QLocale::C) {
148                    // Try own Qt translation...
149                    m_pQtTranslator = new QTranslator(this);
150                    QString sLocName = "qt_" + loc.name();
151            #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
152                    QString sLocPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
153            #else
154                    QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
155            #endif
156                    if (m_pQtTranslator->load(sLocName, sLocPath)) {
157                            QApplication::installTranslator(m_pQtTranslator);
158                    } else {
159                            sLocPath = QApplication::applicationDirPath();
160                    #ifdef RELATIVE_LOCALE_DIR
161                            sLocPath.append(RELATIVE_LOCALE_DIR);
162                    #else
163                            sLocPath.remove(CONFIG_BINDIR);
164                            sLocPath.append(CONFIG_DATADIR "/qsampler/translations");
165                    #endif
166                          if (m_pQtTranslator->load(sLocName, sLocPath)) {                          if (m_pQtTranslator->load(sLocName, sLocPath)) {
167                                  QApplication::installTranslator(m_pQtTranslator);                                  QApplication::installTranslator(m_pQtTranslator);
168                          } else {                          } else {
                         #ifdef RELATIVE_LOCALE_DIR  
                                 sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;  
                                 if (m_pQtTranslator->load(sLocName, sLocPath)) {  
                                         QApplication::installTranslator(m_pQtTranslator);  
                                 } else {  
                         #endif  
169                                  delete m_pQtTranslator;                                  delete m_pQtTranslator;
170                                  m_pQtTranslator = 0;                                  m_pQtTranslator = nullptr;
171                          #ifdef CONFIG_DEBUG                          #ifdef CONFIG_DEBUG
172                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
173                                          loc.name().toUtf8().constData(),                                          loc.name().toUtf8().constData(),
174                                          sLocPath.toUtf8().constData(),                                          sLocPath.toUtf8().constData(),
175                                          sLocName.toUtf8().constData());                                          sLocName.toUtf8().constData());
176                          #endif                          #endif
                         #ifdef RELATIVE_LOCALE_DIR  
                                 }  
                         #endif  
177                          }                          }
178                          // Try own application translation...                  }
179                          m_pMyTranslator = new QTranslator(this);                  // Try own application translation...
180                          sLocName = "qsampler_" + loc.name();                  m_pMyTranslator = new QTranslator(this);
181                    sLocName = "qsampler_" + loc.name();
182                    if (m_pMyTranslator->load(sLocName, sLocPath)) {
183                            QApplication::installTranslator(m_pMyTranslator);
184                    } else {
185                    #ifdef RELATIVE_LOCALE_DIR
186                            sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;
187                    #else
188                            sLocPath = CONFIG_DATADIR "/qsampler/translations";
189                    #endif
190                          if (m_pMyTranslator->load(sLocName, sLocPath)) {                          if (m_pMyTranslator->load(sLocName, sLocPath)) {
191                                  QApplication::installTranslator(m_pMyTranslator);                                  QApplication::installTranslator(m_pMyTranslator);
192                          } else {                          } else {
193                          #ifdef RELATIVE_LOCALE_DIR                                  delete m_pMyTranslator;
194                                  sLocPath = QApplication::applicationDirPath() + RELATIVE_LOCALE_DIR;                                  m_pMyTranslator = nullptr;
195                          #else                          #ifdef CONFIG_DEBUG
196                                  sLocPath = CONFIG_DATADIR "/qsampler/translations";                                  qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
197                                            loc.name().toUtf8().constData(),
198                                            sLocPath.toUtf8().constData(),
199                                            sLocName.toUtf8().constData());
200                          #endif                          #endif
                                 if (m_pMyTranslator->load(sLocName, sLocPath)) {  
                                         QApplication::installTranslator(m_pMyTranslator);  
                                 } else {  
                                         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  
                                 }  
201                          }                          }
202                  }                  }
         #ifdef CONFIG_X11  
         #ifdef CONFIG_XUNIQUE  
                 m_pDisplay = NULL;  
                 m_aUnique = 0;  
                 m_wOwner = 0;  
         #if QT_VERSION >= 0x050100  
                 m_pXcbEventFilter = new qsamplerXcbEventFilter(this);  
                 installNativeEventFilter(m_pXcbEventFilter);  
                 if (QX11Info::isPlatformX11()) {  
         #endif  
                         // Instance uniqueness initialization...  
                         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);  
         #if QT_VERSION >= 0x050100  
                 }  
         #endif  
         #endif  // CONFIG_XUNIQUE  
         #endif  // CONFIG_X11  
203          }          }
204    #ifdef CONFIG_XUNIQUE
205    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
206    #ifdef CONFIG_X11
207            m_pDisplay = nullptr;
208            m_aUnique = 0;
209            m_wOwner = 0;
210    #endif  // CONFIG_X11
211    #else
212            m_pMemory = nullptr;
213            m_pServer = nullptr;
214    #endif
215    #endif  // CONFIG_XUNIQUE
216    }
217    
         // Destructor.  
         ~qsamplerApplication()  
         {  
         #ifdef CONFIG_X11  
         #ifdef CONFIG_XUNIQUE  
         #if QT_VERSION >= 0x050100  
                 removeNativeEventFilter(m_pXcbEventFilter);  
                 delete m_pXcbEventFilter;  
         #endif  
         #endif  // CONFIG_XUNIQUE  
         #endif  // CONFIG_X11  
                 if (m_pMyTranslator) delete m_pMyTranslator;  
                 if (m_pQtTranslator) delete m_pQtTranslator;  
         }  
218    
219          // Main application widget accessors.  // Destructor.
220          void setMainWidget(QWidget *pWidget)  qsamplerApplication::~qsamplerApplication (void)
221          {  {
222                  m_pWidget = pWidget;  #ifdef CONFIG_XUNIQUE
223          #ifdef CONFIG_X11  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
224          #ifdef CONFIG_XUNIQUE          if (m_pServer) {
225                  m_wOwner = m_pWidget->winId();                  m_pServer->close();
226                  if (m_pDisplay && m_wOwner) {                  delete m_pServer;
227                          XGrabServer(m_pDisplay);                  m_pServer = nullptr;
228                          XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);          }
229                          XUngrabServer(m_pDisplay);          if (m_pMemory) {
230                  }                  delete m_pMemory;
231          #endif  // CONFIG_XUNIQUE                  m_pMemory = nullptr;
232          #endif  // CONFIG_X11  }
233    #endif
234    #endif  // CONFIG_XUNIQUE
235            if (m_pMyTranslator) delete m_pMyTranslator;
236            if (m_pQtTranslator) delete m_pQtTranslator;
237    }
238    
239    
240    // Main application widget accessors.
241    void qsamplerApplication::setMainWidget ( QWidget *pWidget )
242    {
243            m_pWidget = pWidget;
244    #ifdef CONFIG_XUNIQUE
245    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
246    #ifdef CONFIG_X11
247            m_wOwner = m_pWidget->winId();
248            if (m_pDisplay && m_wOwner) {
249                    XGrabServer(m_pDisplay);
250                    XSetSelectionOwner(m_pDisplay, m_aUnique, m_wOwner, CurrentTime);
251                    XUngrabServer(m_pDisplay);
252          }          }
253    #endif  // CONFIG_X11
254    #endif
255    #endif  // CONFIG_XUNIQUE
256    }
257    
         QWidget *mainWidget() const { return m_pWidget; }  
258    
259          // Check if another instance is running,  // Check if another instance is running,
260      // and raise its proper main widget...  // and raise its proper main widget...
261          bool setup()  bool qsamplerApplication::setup (void)
262          {  {
263          #ifdef CONFIG_X11  #ifdef CONFIG_XUNIQUE
264          #ifdef CONFIG_XUNIQUE  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
265                  if (m_pDisplay && m_wOwner != None) {  #ifdef CONFIG_X11
266            m_pDisplay = QX11Info::display();
267            if (m_pDisplay) {
268                    QString sUnique = QSAMPLER_XUNIQUE;
269                    char szHostName[255];
270                    if (::gethostname(szHostName, sizeof(szHostName)) == 0) {
271                            sUnique += '@';
272                            sUnique += szHostName;
273                    }
274                    m_aUnique = XInternAtom(m_pDisplay, sUnique.toUtf8().constData(), false);
275                    XGrabServer(m_pDisplay);
276                    m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);
277                    XUngrabServer(m_pDisplay);
278                    if (m_wOwner != None) {
279                          // First, notify any freedesktop.org WM                          // First, notify any freedesktop.org WM
280                          // that we're about to show the main widget...                          // that we're about to show the main widget...
281                          Screen *pScreen = XDefaultScreenOfDisplay(m_pDisplay);                          Screen *pScreen = XDefaultScreenOfDisplay(m_pDisplay);
# Line 264  public: Line 311  public:
311                          // Done.                          // Done.
312                          return true;                          return true;
313                  }                  }
         #endif  // CONFIG_XUNIQUE  
         #endif  // CONFIG_X11  
                 return false;  
314          }          }
315    #endif  // CONFIG_X11
316  #ifdef CONFIG_X11          return false;
317  #ifdef CONFIG_XUNIQUE  #else
318          void x11PropertyNotify(Window w)          m_sUnique = QCoreApplication::applicationName();
319          {          m_sUnique += '@';
320                  if (m_pDisplay && m_pWidget && m_wOwner == w) {          m_sUnique += QHostInfo::localHostName();
321                          // Always check whether our property-flag is still around...  #ifdef Q_OS_UNIX
322                          Atom aType;          m_pMemory = new QSharedMemory(m_sUnique);
323                          int iFormat = 0;          m_pMemory->attach();
324                          unsigned long iItems = 0;          delete m_pMemory;
325                          unsigned long iAfter = 0;  #endif
326                          unsigned char *pData = 0;          m_pMemory = new QSharedMemory(m_sUnique);
327                          if (XGetWindowProperty(          bool bServer = false;
328                                          m_pDisplay,          const qint64 pid = QCoreApplication::applicationPid();
329                                          m_wOwner,          struct Data { qint64 pid; };
330                                          m_aUnique,          if (m_pMemory->create(sizeof(Data))) {
331                                          0, 1024,                  m_pMemory->lock();
332                                          false,                  Data *pData = static_cast<Data *> (m_pMemory->data());
333                                          m_aUnique,                  if (pData) {
334                                          &aType,                          pData->pid = pid;
335                                          &iFormat,                          bServer = true;
                                         &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);  
336                  }                  }
337                    m_pMemory->unlock();
338          }          }
339  #if QT_VERSION < 0x050000          else
340          bool x11EventFilter(XEvent *pEv)          if (m_pMemory->attach()) {
341          {                  m_pMemory->lock(); // maybe not necessary?
342                  if (pEv->type == PropertyNotify                  Data *pData = static_cast<Data *> (m_pMemory->data());
343                          && pEv->xproperty.state == PropertyNewValue)                  if (pData)
344                          x11PropertyNotify(pEv->xproperty.window);                          bServer = (pData->pid == pid);
345                  return QApplication::x11EventFilter(pEv);                  m_pMemory->unlock();
346            }
347            if (bServer) {
348                    QLocalServer::removeServer(m_sUnique);
349                    m_pServer = new QLocalServer();
350                    m_pServer->setSocketOptions(QLocalServer::UserAccessOption);
351                    m_pServer->listen(m_sUnique);
352                    QObject::connect(m_pServer,
353                            SIGNAL(newConnection()),
354                            SLOT(newConnectionSlot()));
355            } else {
356                    QLocalSocket socket;
357                    socket.connectToServer(m_sUnique);
358                    if (socket.state() == QLocalSocket::ConnectingState)
359                            socket.waitForConnected(200);
360                    if (socket.state() == QLocalSocket::ConnectedState) {
361                            socket.write(QCoreApplication::arguments().join(' ').toUtf8());
362                            socket.flush();
363                            socket.waitForBytesWritten(200);
364                    }
365          }          }
366            return !bServer;
367  #endif  #endif
368  #endif  // CONFIG_XUNIQUE  #else
369  #endif  // CONFIG_X11          return false;
370            #endif  // !CONFIG_XUNIQUE
371  private:  }
   
         // Translation support.  
         QTranslator *m_pQtTranslator;  
         QTranslator *m_pMyTranslator;  
372    
         // Instance variables.  
         QWidget *m_pWidget;  
373    
 #ifdef CONFIG_X11  
374  #ifdef CONFIG_XUNIQUE  #ifdef CONFIG_XUNIQUE
375          Display *m_pDisplay;  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
376          Atom     m_aUnique;  #ifdef CONFIG_X11
377          Window   m_wOwner;  
378  #if QT_VERSION >= 0x050100  void qsamplerApplication::x11PropertyNotify ( Window w )
379          qsamplerXcbEventFilter *m_pXcbEventFilter;  {
380  #endif          if (m_pDisplay && m_pWidget && m_wOwner == w) {
381  #endif  // CONFIG_XUNIQUE                  // Always check whether our property-flag is still around...
382                    Atom aType;
383                    int iFormat = 0;
384                    unsigned long iItems = 0;
385                    unsigned long iAfter = 0;
386                    unsigned char *pData = 0;
387                    if (XGetWindowProperty(
388                                    m_pDisplay,
389                                    m_wOwner,
390                                    m_aUnique,
391                                    0, 1024,
392                                    false,
393                                    m_aUnique,
394                                    &aType,
395                                    &iFormat,
396                                    &iItems,
397                                    &iAfter,
398                                    &pData) == Success
399                            && aType == m_aUnique && iItems > 0 && iAfter == 0) {
400                            // Avoid repeating it-self...
401                            XDeleteProperty(m_pDisplay, m_wOwner, m_aUnique);
402                            // Just make it always shows up fine...
403                            m_pWidget->show();
404                            m_pWidget->raise();
405                            m_pWidget->activateWindow();
406                    }
407                    // Free any left-overs...
408                    if (iItems > 0 && pData)
409                            XFree(pData);
410            }
411    }
412    
413    
414    bool qsamplerApplication::x11EventFilter ( XEvent *pEv )
415    {
416            if (pEv->type == PropertyNotify
417                    && pEv->xproperty.state == PropertyNewValue)
418                    x11PropertyNotify(pEv->xproperty.window);
419            return QApplication::x11EventFilter(pEv);
420    }
421    
422  #endif  // CONFIG_X11  #endif  // CONFIG_X11
423  };  #else
424    
425    // Local server conection slot.
426    void qsamplerApplication::newConnectionSlot (void)
427    {
428            QLocalSocket *pSocket = m_pServer->nextPendingConnection();
429            QObject::connect(pSocket,
430                    SIGNAL(readyRead()),
431                    SLOT(readyReadSlot()));
432    }
433    
434  #ifdef CONFIG_X11  // Local server data-ready slot.
435  #ifdef CONFIG_XUNIQUE  void qsamplerApplication::readyReadSlot (void)
 #if QT_VERSION >= 0x050100  
 // XCB Event filter (virtual processor).  
 bool qsamplerXcbEventFilter::nativeEventFilter (  
         const QByteArray& eventType, void *message, long * )  
436  {  {
437          if (eventType == "xcb_generic_event_t") {          QLocalSocket *pSocket = qobject_cast<QLocalSocket *> (sender());
438                  xcb_property_notify_event_t *pEv          if (pSocket) {
439                          = static_cast<xcb_property_notify_event_t *> (message);                  const qint64 nread = pSocket->bytesAvailable();
440                  if ((pEv->response_type & ~0x80) == XCB_PROPERTY_NOTIFY                  if (nread > 0) {
441                          && pEv->state == XCB_PROPERTY_NEW_VALUE)                          const QByteArray data = pSocket->read(nread);
442                          m_pApp->x11PropertyNotify(pEv->window);                          // Just make it always shows up fine...
443                            m_pWidget->hide();
444                            m_pWidget->show();
445                            m_pWidget->raise();
446                            m_pWidget->activateWindow();
447                    }
448          }          }
         return false;  
449  }  }
450    
451  #endif  #endif
452  #endif  // CONFIG_XUNIQUE  #endif  // CONFIG_XUNIQUE
 #endif  // CONFIG_X11  
453    
454    
455  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 381  void stacktrace ( int signo ) Line 473  void stacktrace ( int signo )
473          char cmd[80];          char cmd[80];
474    
475          // Reinstall default handler; prevent race conditions...          // Reinstall default handler; prevent race conditions...
476          signal(signo, SIG_DFL);          ::signal(signo, SIG_DFL);
477    
478          static const char *shell  = "/bin/sh";          static const char *shell  = "/bin/sh";
479          static const char *format = "gdb -q --batch --pid=%d"          static const char *format = "gdb -q --batch --pid=%d"
# Line 397  void stacktrace ( int signo ) Line 489  void stacktrace ( int signo )
489    
490          // Fork child...          // Fork child...
491          if (pid == 0) {          if (pid == 0) {
492                  execl(shell, shell, "-c", cmd, NULL);                  execl(shell, shell, "-c", cmd, nullptr);
493                  _exit(1);                  _exit(1);
494                  return;                  return;
495          }          }
# Line 427  int main ( int argc, char **argv ) Line 519  int main ( int argc, char **argv )
519          Q_INIT_RESOURCE(qsampler);          Q_INIT_RESOURCE(qsampler);
520  #ifdef CONFIG_STACKTRACE  #ifdef CONFIG_STACKTRACE
521  #if defined(__GNUC__) && defined(Q_OS_LINUX)  #if defined(__GNUC__) && defined(Q_OS_LINUX)
522          signal(SIGILL,  stacktrace);          ::signal(SIGILL,  stacktrace);
523          signal(SIGFPE,  stacktrace);          ::signal(SIGFPE,  stacktrace);
524          signal(SIGSEGV, stacktrace);          ::signal(SIGSEGV, stacktrace);
525          signal(SIGABRT, stacktrace);          ::signal(SIGABRT, stacktrace);
526          signal(SIGBUS,  stacktrace);          ::signal(SIGBUS,  stacktrace);
527  #endif  #endif
528  #endif  #endif
529          qsamplerApplication app(argc, argv);  #if defined(Q_OS_LINUX)
530  #if QT_VERSION >= 0x050600          ::setenv("QT_QPA_PLATFORM", "xcb", 0);
531          app.setAttribute(Qt::AA_EnableHighDpiScaling);  #endif
532    #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
533    #if QT_VERSION <  QT_VERSION_CHECK(6, 0, 0)
534            QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
535    #endif
536  #endif  #endif
537            qsamplerApplication app(argc, argv);
538    
539          #if defined(__APPLE__)  //  Toshi Nagata 20080105          #if defined(__APPLE__)  //  Toshi Nagata 20080105
540          {          {
541                  //  Set the plugin path to @exetutable_path/../plugins                  //  Set the plugin path to @exetutable_path/../plugins
# Line 467  int main ( int argc, char **argv ) Line 565  int main ( int argc, char **argv )
565                  return 2;                  return 2;
566          }          }
567    
568          // Dark themes grayed/disabled color group fix...          // Special custom styles...
569            if (QDir(CONFIG_PLUGINSDIR).exists())
570                    app.addLibraryPath(CONFIG_PLUGINSDIR);
571            if (!options.sCustomStyleTheme.isEmpty())
572                    app.setStyle(QStyleFactory::create(options.sCustomStyleTheme));
573    
574            // Custom color theme (eg. "KXStudio")...
575          QPalette pal(app.palette());          QPalette pal(app.palette());
576          if (pal.base().color().value() < 0x7f) {          if (QSampler::PaletteForm::namedPalette(
577          #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());  
578                  app.setPalette(pal);                  app.setPalette(pal);
         }  
579    
580          // Set default base font...          // Set default base font...
581          if (options.iBaseFontSize > 0)          if (options.iBaseFontSize > 0)

Legend:
Removed from v.3465  
changed lines
  Added in v.4024

  ViewVC Help
Powered by ViewVC