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 |
58 |
#include <QTimer> |
#include <QTimer> |
59 |
#include <QDateTime> |
#include <QDateTime> |
60 |
|
|
61 |
|
#include <QElapsedTimer> |
62 |
|
|
63 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
64 |
#include <QMimeData> |
#include <QMimeData> |
65 |
#endif |
#endif |
2794 |
} |
} |
2795 |
} |
} |
2796 |
} |
} |
2797 |
|
|
2798 |
|
#if CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2799 |
|
// If we lost connection to server: Try to automatically reconnect if we |
2800 |
|
// did not start the server. |
2801 |
|
// |
2802 |
|
// TODO: If we started the server, then we might inform the user that |
2803 |
|
// the server probably crashed and asking user ONCE whether we should |
2804 |
|
// restart the server. |
2805 |
|
if (lscp_client_connection_lost(m_pClient) && !m_pServer) |
2806 |
|
startAutoReconnectClient(); |
2807 |
|
#endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST |
2808 |
} |
} |
2809 |
|
|
2810 |
// Register the next timer slot. |
// Register the next timer slot. |
2931 |
|
|
2932 |
// Give it some time to terminate gracefully and stabilize... |
// Give it some time to terminate gracefully and stabilize... |
2933 |
if (bGraceWait) { |
if (bGraceWait) { |
2934 |
QTime t; |
QElapsedTimer timer; |
2935 |
t.start(); |
timer.start(); |
2936 |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
while (timer.elapsed() < QSAMPLER_TIMER_MSECS) |
2937 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
2938 |
} |
} |
2939 |
} |
} |
2963 |
// Force final server shutdown... |
// Force final server shutdown... |
2964 |
m_pServer->kill(); |
m_pServer->kill(); |
2965 |
// Give it some time to terminate gracefully and stabilize... |
// Give it some time to terminate gracefully and stabilize... |
2966 |
QTime t; |
QElapsedTimer timer; |
2967 |
t.start(); |
timer.start(); |
2968 |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
while (timer.elapsed() < QSAMPLER_TIMER_MSECS) |
2969 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
2970 |
} |
} |
2971 |
// Force final server shutdown... |
// Force final server shutdown... |
3003 |
|
|
3004 |
|
|
3005 |
// Start our almighty client... |
// Start our almighty client... |
3006 |
bool MainForm::startClient (void) |
bool MainForm::startClient (bool bReconnectOnly) |
3007 |
{ |
{ |
3008 |
// Have it a setup? |
// Have it a setup? |
3009 |
if (m_pOptions == nullptr) |
if (m_pOptions == nullptr) |
3024 |
// Is this the first try? |
// Is this the first try? |
3025 |
// maybe we need to start a local server... |
// maybe we need to start a local server... |
3026 |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
if ((m_pServer && m_pServer->state() == QProcess::Running) |
3027 |
|| !m_pOptions->bServerStart) { |
|| !m_pOptions->bServerStart || bReconnectOnly) |
3028 |
appendMessagesError( |
{ |
3029 |
tr("Could not connect to server as client.\n\nSorry.")); |
// if this method is called from autoReconnectClient() |
3030 |
|
// then don't bother user with an error message... |
3031 |
|
if (!bReconnectOnly) { |
3032 |
|
appendMessagesError( |
3033 |
|
tr("Could not connect to server as client.\n\nSorry.") |
3034 |
|
); |
3035 |
|
} |
3036 |
} else { |
} else { |
3037 |
startServer(); |
startServer(); |
3038 |
} |
} |
3161 |
} |
} |
3162 |
|
|
3163 |
|
|
3164 |
|
void MainForm::startAutoReconnectClient (void) |
3165 |
|
{ |
3166 |
|
stopClient(); |
3167 |
|
appendMessages(tr("Trying to reconnect...")); |
3168 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3169 |
|
} |
3170 |
|
|
3171 |
|
|
3172 |
|
void MainForm::autoReconnectClient (void) |
3173 |
|
{ |
3174 |
|
const bool bSuccess = startClient(true); |
3175 |
|
if (!bSuccess) |
3176 |
|
QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient())); |
3177 |
|
} |
3178 |
|
|
3179 |
|
|
3180 |
// Channel strip activation/selection. |
// Channel strip activation/selection. |
3181 |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow ) |
3182 |
{ |
{ |