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

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

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

revision 3668 by schoenebeck, Sun Dec 22 13:47:40 2019 UTC revision 3761 by capela, Tue Mar 31 11:06:16 2020 UTC
# Line 1  Line 1 
1  // qsamplerMainForm.cpp  // qsamplerMainForm.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-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 35  Line 35 
35  #include "qsamplerOptionsForm.h"  #include "qsamplerOptionsForm.h"
36  #include "qsamplerDeviceStatusForm.h"  #include "qsamplerDeviceStatusForm.h"
37    
38    #include "qsamplerPaletteForm.h"
39    
40    #include <QStyleFactory>
41    
42  #include <QMdiArea>  #include <QMdiArea>
43  #include <QMdiSubWindow>  #include <QMdiSubWindow>
44    
# Line 58  Line 62 
62  #include <QTimer>  #include <QTimer>
63  #include <QDateTime>  #include <QDateTime>
64    
65    #include <QElapsedTimer>
66    
67  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
68  #include <QMimeData>  #include <QMimeData>
69  #endif  #endif
# Line 68  const WindowFlags WindowCloseButtonHint Line 74  const WindowFlags WindowCloseButtonHint
74  }  }
75  #endif  #endif
76    
77    // Deprecated QTextStreamFunctions/Qt namespaces workaround.
78    #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
79    #define endl    Qt::endl
80    #endif
81    
82    
83  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
84  #include <gig.h>  #include <gig.h>
85  #endif  #endif
# Line 1866  void MainForm::viewOptions (void) Line 1878  void MainForm::viewOptions (void)
1878                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1879                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1880                  // To track down deferred or immediate changes.                  // To track down deferred or immediate changes.
1881                  const QString sOldServerHost      = m_pOptions->sServerHost;                  const QString sOldServerHost       = m_pOptions->sServerHost;
1882                  const int     iOldServerPort      = m_pOptions->iServerPort;                  const int     iOldServerPort       = m_pOptions->iServerPort;
1883                  const int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  const int     iOldServerTimeout    = m_pOptions->iServerTimeout;
1884                  const bool    bOldServerStart     = m_pOptions->bServerStart;                  const bool    bOldServerStart      = m_pOptions->bServerStart;
1885                  const QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  const QString sOldServerCmdLine    = m_pOptions->sServerCmdLine;
1886                  const bool    bOldMessagesLog     = m_pOptions->bMessagesLog;                  const bool    bOldMessagesLog      = m_pOptions->bMessagesLog;
1887                  const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;                  const QString sOldMessagesLogPath  = m_pOptions->sMessagesLogPath;
1888                  const QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  const QString sOldDisplayFont      = m_pOptions->sDisplayFont;
1889                  const bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  const bool    bOldDisplayEffect    = m_pOptions->bDisplayEffect;
1890                  const int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  const int     iOldMaxVolume        = m_pOptions->iMaxVolume;
1891                  const QString sOldMessagesFont    = m_pOptions->sMessagesFont;                  const QString sOldMessagesFont     = m_pOptions->sMessagesFont;
1892                  const bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;                  const bool    bOldKeepOnTop        = m_pOptions->bKeepOnTop;
1893                  const bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;                  const bool    bOldStdoutCapture    = m_pOptions->bStdoutCapture;
1894                  const int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;                  const int     bOldMessagesLimit    = m_pOptions->bMessagesLimit;
1895                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1896                  const bool    bOldCompletePath    = m_pOptions->bCompletePath;                  const bool    bOldCompletePath     = m_pOptions->bCompletePath;
1897                  const bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  const bool    bOldInstrumentNames  = m_pOptions->bInstrumentNames;
1898                  const int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  const int     iOldMaxRecentFiles   = m_pOptions->iMaxRecentFiles;
1899                  const int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;                  const int     iOldBaseFontSize     = m_pOptions->iBaseFontSize;
1900                    const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme;
1901                    const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme;
1902                  // Load the current setup settings.                  // Load the current setup settings.
1903                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1904                  // Show the setup dialog...                  // Show the setup dialog...
1905                  if (pOptionsForm->exec()) {                  if (pOptionsForm->exec()) {
1906                          // Warn if something will be only effective on next run.                          // Warn if something will be only effective on next run.
1907                            int iNeedRestart = 0;
1908                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1909                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {
1910                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  updateMessagesCapture();
1911                                    ++iNeedRestart;
1912                            }
1913                            if (( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1914                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1915                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1916                                  QMessageBox::information(this,                                  ++iNeedRestart;
1917                                          tr("Information"),                          }
1918                                          tr("Some settings may be only effective\n"                          // Check whether restart is needed or whether
1919                                          "next time you start this program."));                          // custom options maybe set up immediately...
1920                                  updateMessagesCapture();                          if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) {
1921                                    if (m_pOptions->sCustomStyleTheme.isEmpty()) {
1922                                            ++iNeedRestart;
1923                                    } else {
1924                                            QApplication::setStyle(
1925                                                    QStyleFactory::create(m_pOptions->sCustomStyleTheme));
1926                                    }
1927                            }
1928                            if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) {
1929                                    if (m_pOptions->sCustomColorTheme.isEmpty()) {
1930                                            ++iNeedRestart;
1931                                    } else {
1932                                            QPalette pal;
1933                                            if (PaletteForm::namedPalette(
1934                                                            &m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal))
1935                                                    QApplication::setPalette(pal);
1936                                    }
1937                          }                          }
1938                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1939                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
# Line 1927  void MainForm::viewOptions (void) Line 1961  void MainForm::viewOptions (void)
1961                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||
1962                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))
1963                                  updateMessagesLimit();                                  updateMessagesLimit();
1964                            // Show restart needed message...
1965                            if (iNeedRestart > 0) {
1966                                    QMessageBox::information(this,
1967                                            tr("Information"),
1968                                            tr("Some settings may be only effective\n"
1969                                            "next time you start this program."));
1970                            }
1971                          // And now the main thing, whether we'll do client/server recycling?                          // And now the main thing, whether we'll do client/server recycling?
1972                          if ((sOldServerHost != m_pOptions->sServerHost) ||                          if ((sOldServerHost != m_pOptions->sServerHost) ||
1973                                  (iOldServerPort != m_pOptions->iServerPort) ||                                  (iOldServerPort != m_pOptions->iServerPort) ||
# Line 2793  void MainForm::timerSlot (void) Line 2834  void MainForm::timerSlot (void)
2834                          }                          }
2835                  }                  }
2836    
2837  #if CONFIG_LSCP_CLIENT_CONNECTION_LOST          #if CONFIG_LSCP_CLIENT_CONNECTION_LOST
2838                  // If we lost connection to server: Try to automatically reconnect if we                  // If we lost connection to server: Try to automatically reconnect if we
2839                  // did not start the server.                  // did not start the server.
2840                  //                  //
# Line 2802  void MainForm::timerSlot (void) Line 2843  void MainForm::timerSlot (void)
2843                  // restart the server.                  // restart the server.
2844                  if (lscp_client_connection_lost(m_pClient) && !m_pServer)                  if (lscp_client_connection_lost(m_pClient) && !m_pServer)
2845                          startAutoReconnectClient();                          startAutoReconnectClient();
2846  #endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST          #endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST
2847          }          }
2848    
2849          // Register the next timer slot.          // Register the next timer slot.
# Line 2929  void MainForm::stopServer ( bool bIntera Line 2970  void MainForm::stopServer ( bool bIntera
2970    
2971          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2972          if (bGraceWait) {          if (bGraceWait) {
2973                  QTime t;                  QElapsedTimer timer;
2974                  t.start();                  timer.start();
2975                  while (t.elapsed() < QSAMPLER_TIMER_MSECS)                  while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
2976                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2977          }          }
2978  }  }
# Line 2961  void MainForm::processServerExit (void) Line 3002  void MainForm::processServerExit (void)
3002                          // Force final server shutdown...                          // Force final server shutdown...
3003                          m_pServer->kill();                          m_pServer->kill();
3004                          // Give it some time to terminate gracefully and stabilize...                          // Give it some time to terminate gracefully and stabilize...
3005                          QTime t;                          QElapsedTimer timer;
3006                          t.start();                          timer.start();
3007                          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                          while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
3008                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
3009                  }                  }
3010                  // Force final server shutdown...                  // Force final server shutdown...
# Line 3024  bool MainForm::startClient (bool bReconn Line 3065  bool MainForm::startClient (bool bReconn
3065                  if ((m_pServer && m_pServer->state() == QProcess::Running)                  if ((m_pServer && m_pServer->state() == QProcess::Running)
3066                          || !m_pOptions->bServerStart || bReconnectOnly)                          || !m_pOptions->bServerStart || bReconnectOnly)
3067                  {                  {
3068                          // if this method is called from doAutoReconnect() then don't bother                          // if this method is called from autoReconnectClient()
3069                          // user with an error message                          // then don't bother user with an error message...
3070                          if (!bReconnectOnly) {                          if (!bReconnectOnly) {
3071                                  appendMessagesError(                                  appendMessagesError(
3072                                          tr("Could not connect to server as client.\n\nSorry.")                                          tr("Could not connect to server as client.\n\nSorry.")
# Line 3158  void MainForm::stopClient (void) Line 3199  void MainForm::stopClient (void)
3199          stabilizeForm();          stabilizeForm();
3200  }  }
3201    
3202  void MainForm::startAutoReconnectClient() {  
3203    void MainForm::startAutoReconnectClient (void)
3204    {
3205          stopClient();          stopClient();
3206          appendMessages("Trying to reconnect.");          appendMessages(tr("Trying to reconnect..."));
3207          QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(doAutoReconnectClient()));          QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3208  }  }
3209    
3210  void MainForm::doAutoReconnectClient() {  
3211          bool success = startClient(true);  void MainForm::autoReconnectClient (void)
3212          if (!success)  {
3213                  QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(doAutoReconnectClient()));          const bool bSuccess = startClient(true);
3214            if (!bSuccess)
3215                    QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3216  }  }
3217    
3218    

Legend:
Removed from v.3668  
changed lines
  Added in v.3761

  ViewVC Help
Powered by ViewVC