From 7fa08c51e3d19d55ea8407373516d844a4192f41 Mon Sep 17 00:00:00 2001 From: Serhii Hadzhilov Date: Wed, 28 Apr 2021 15:34:04 +0300 Subject: [PATCH] SYNERGY-694 Issues with clients messages --- src/gui/src/ClientConnection.cpp | 34 ++++++++++++++++++++++++-------- src/gui/src/ClientConnection.h | 3 +++ src/gui/src/MainWindow.cpp | 12 +++++++++-- src/gui/src/MainWindow.h | 1 + 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/gui/src/ClientConnection.cpp b/src/gui/src/ClientConnection.cpp index 71207a5c4..e7e487760 100644 --- a/src/gui/src/ClientConnection.cpp +++ b/src/gui/src/ClientConnection.cpp @@ -30,15 +30,20 @@ ClientConnection::ClientConnection(MainWindow& parent) : void ClientConnection::update(const QString& line) { - if (line.contains("failed to connect to server") && - checkMainWindow()) + if (m_checkConnection && checkMainWindow()) { - m_parent.stopSynergy(); - - QMessageBox message(&m_parent); - message.addButton(QObject::tr("Close"), QMessageBox::RejectRole); - message.setText(getMessage()); - message.exec(); + if (line.contains("failed to connect to server")) + { + m_checkConnection = false; + if (!line.contains("server refused client with our name")) + { + showMessage(); + } + } + else if (line.contains("connected to server")) + { + m_checkConnection = false; + } } } @@ -69,3 +74,16 @@ QString ClientConnection::getMessage() const return message; } + +void ClientConnection::showMessage() +{ + QMessageBox message(&m_parent); + message.addButton(QObject::tr("Close"), QMessageBox::RejectRole); + message.setText(getMessage()); + message.exec(); +} + +void ClientConnection::setCheckConnection(bool checkConnection) +{ + m_checkConnection = checkConnection; +} diff --git a/src/gui/src/ClientConnection.h b/src/gui/src/ClientConnection.h index 0d52e95a7..1a2ec6252 100644 --- a/src/gui/src/ClientConnection.h +++ b/src/gui/src/ClientConnection.h @@ -26,14 +26,17 @@ class MainWindow; class ClientConnection { MainWindow& m_parent; + bool m_checkConnection = false; public: explicit ClientConnection(MainWindow& parent); void update(const QString& line); + void setCheckConnection(bool checkConnection); private: QString getMessage() const; bool checkMainWindow(); + void showMessage(); }; #endif // CLIENTCONNECTION_H diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 29568f159..33caf646e 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -310,7 +310,7 @@ void MainWindow::initConnections() { connect(m_pActionMinimize, SIGNAL(triggered()), this, SLOT(hide())); connect(m_pActionRestore, SIGNAL(triggered()), this, SLOT(showNormal())); - connect(m_pActionStartSynergy, SIGNAL(triggered()), this, SLOT(startSynergy())); + connect(m_pActionStartSynergy, SIGNAL(triggered()), this, SLOT(actionStart())); connect(m_pActionStopSynergy, SIGNAL(triggered()), this, SLOT(stopSynergy())); connect(m_pActionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); connect(&m_VersionChecker, SIGNAL(updateFound(const QString&)), this, SLOT(updateFound(const QString&))); @@ -714,6 +714,12 @@ void MainWindow::startSynergy() } } +void MainWindow::actionStart() +{ + m_clientConnection.setCheckConnection(true); + startSynergy(); +} + void MainWindow::retryStart() { //This function is only called after a failed start @@ -1284,6 +1290,7 @@ void MainWindow::on_m_pActivate_triggered() void MainWindow::on_m_pButtonApply_clicked() { + m_clientConnection.setCheckConnection(true); restartSynergy(); } @@ -1425,6 +1432,7 @@ void MainWindow::on_m_pRadioGroupClient_clicked(bool) void MainWindow::on_m_pButtonConnect_clicked() { - restartSynergy(); + m_clientConnection.setCheckConnection(true); + restartSynergy(); } diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index d3a444eec..7c59a4aeb 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -143,6 +143,7 @@ public slots: void appendLogError(const QString& text); void startSynergy(); void retryStart(); // If the connection failed this will retry a startSynergy + void actionStart(); protected slots: void updateLocalFingerprint();