diff --git a/ChangeLog b/ChangeLog index 712d0c208..7bd5edc96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ Enhancements: - #6973 Update synergy UI. Main window - #6977 Update synergy UI. Configure server - #6978 Update synergy UI. Settings window +- #6981 Update synergy UI. Setup client configuration - #6962 | #6965 Add macOS 10.13 builder =========== diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 682869ac0..423ae2114 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -112,7 +112,8 @@ MainWindow::MainWindow (AppConfig& appConfig, m_pMenuHelp(NULL), m_pCancelButton(NULL), m_ExpectedRunningState(kStopped), - m_SecureSocket(false) + m_SecureSocket(false), + m_serverConnection(*this) { #if !defined(SYNERGY_ENTERPRISE) && defined(SYNERGY_AUTOCONFIG) m_pZeroconf = new Zeroconf(this); @@ -450,6 +451,7 @@ void MainWindow::checkConnected(const QString& line) // TODO: implement ipc connection state messages to replace this hack. if (m_pRadioGroupServer->isChecked()) { + m_serverConnection.update(line); m_pLabelServerState->updateServerState(line); } else diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 55397f0b7..18e11416f 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -28,6 +28,7 @@ #include "ui_MainWindowBase.h" #include "ServerConfig.h" +#include "ServerConnection.h" #include "AppConfig.h" #include "VersionChecker.h" #include "IpcClient.h" @@ -67,6 +68,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase friend class SetupWizard; friend class ActivationDialog; friend class SettingsDialog; + friend class ServerConnection; public: enum qSynergyState @@ -238,6 +240,7 @@ public slots: QMutex m_StopDesktopMutex; bool m_SecureSocket; // brief Is the program running a secure socket protocol (SSL/TLS) QString m_SecureSocketVersion; // brief Contains the version of the Secure Socket currently active + ServerConnection m_serverConnection; void updateAutoConfigWidgets(); diff --git a/src/gui/src/ServerConfig.cpp b/src/gui/src/ServerConfig.cpp index f2b805df7..2425b23d7 100644 --- a/src/gui/src/ServerConfig.cpp +++ b/src/gui/src/ServerConfig.cpp @@ -396,6 +396,22 @@ bool ServerConfig::getUseExternalConfig() const return m_pAppConfig->getUseExternalConfig(); } +bool ServerConfig::isFull() const +{ + bool isFull = true; + + for (const auto& screen : screens()) + { + if (screen.isNull()) + { + isFull = false; + break; + } + } + + return isFull; +} + void ServerConfig::setConfigFile(const QString& configFile) { m_pAppConfig->setConfigFile(configFile); diff --git a/src/gui/src/ServerConfig.h b/src/gui/src/ServerConfig.h index d0f4e8463..e6294ad85 100644 --- a/src/gui/src/ServerConfig.h +++ b/src/gui/src/ServerConfig.h @@ -38,6 +38,7 @@ class AppConfig; class ServerConfig : public BaseConfig, public GUI::Config::ConfigBase { friend class ServerConfigDialog; + friend class ServerConnection; friend QTextStream& operator<<(QTextStream& outStream, const ServerConfig& config); public: @@ -83,6 +84,7 @@ class ServerConfig : public BaseConfig, public GUI::Config::ConfigBase void updateServerName(); const QString& getConfigFile() const; bool getUseExternalConfig() const; + bool isFull() const; protected: QSettings& settings(); diff --git a/src/gui/src/ServerConnection.cpp b/src/gui/src/ServerConnection.cpp new file mode 100644 index 000000000..03a2a9d0b --- /dev/null +++ b/src/gui/src/ServerConnection.cpp @@ -0,0 +1,86 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2012-2021 Symless Ltd. + * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ServerConnection.h" + +#include "MainWindow.h" +#include "ServerConfigDialog.h" +#include "ServerMessage.h" + +#include + + +ServerConnection::ServerConnection(MainWindow& parent) : + m_parent(parent) +{ + +} + +void ServerConnection::update(const QString& line) +{ + ServerMessage message(line); + + if (!m_parent.appConfig().getUseExternalConfig() && + message.isNewClientMessage() && + !m_ignoredClients.contains(message.getClientName())) + { + addClient(message.getClientName()); + } +} + +bool ServerConnection::checkMainWindow() +{ + if (m_parent.isMinimized() || m_parent.isHidden()) + { + m_parent.showNormal(); + m_parent.activateWindow(); + } + + return m_parent.isActiveWindow(); +} + +void ServerConnection::addClient(const QString& clientName) +{ + if (!m_parent.serverConfig().isFull() && checkMainWindow()) + { + QMessageBox message(&m_parent); + message.addButton(QObject::tr("Ignore"), QMessageBox::RejectRole); + message.addButton(QObject::tr("Accept and configure"), QMessageBox::AcceptRole); + message.setText(QObject::tr("%1 client has made a connection request").arg(clientName)); + + if (message.exec() == QMessageBox::Accepted) + { + configureClient(clientName); + } + else + { + m_ignoredClients.append(clientName); + } + } +} + +void ServerConnection::configureClient(const QString& clientName) +{ + auto& config = m_parent.serverConfig(); + config.addToFirstEmptyGrid(clientName); + + ServerConfigDialog dlg(&m_parent, config); + dlg.exec(); + + m_parent.restartSynergy(); +} diff --git a/src/gui/src/ServerConnection.h b/src/gui/src/ServerConnection.h new file mode 100644 index 000000000..9a8731730 --- /dev/null +++ b/src/gui/src/ServerConnection.h @@ -0,0 +1,42 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2012-2021 Symless Ltd. + * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef SERVERCONNECTION_H +#define SERVERCONNECTION_H + +#include +#include + +class MainWindow; + +class ServerConnection +{ + MainWindow& m_parent; + QStringList m_ignoredClients; + +public: + explicit ServerConnection(MainWindow& parent); + void update(const QString& line); + +private: + void addClient(const QString& clientName); + void configureClient(const QString& clientName); + bool checkMainWindow(); +}; + +#endif // SERVERCONNECTION_H diff --git a/src/gui/src/ServerMessage.cpp b/src/gui/src/ServerMessage.cpp new file mode 100644 index 000000000..d1fa625ac --- /dev/null +++ b/src/gui/src/ServerMessage.cpp @@ -0,0 +1,64 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2012-2021 Symless Ltd. + * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "ServerMessage.h" + +ServerMessage::ServerMessage(const QString& message) : + m_message(message), + m_clienName(parseClientName(message)) +{ + +} + +bool ServerMessage::isNewClientMessage() const +{ + return m_message.contains("unrecognised client name"); +} + +bool ServerMessage::isExitMessage() const +{ + return m_message.contains("process exited"); +} + +bool ServerMessage::isConnectedMessage() const +{ + return m_message.contains("has connected"); +} + +bool ServerMessage::isDisconnectedMessage() const +{ + return m_message.contains("has disconnected"); +} + +const QString& ServerMessage::getClientName() const +{ + return m_clienName; +} + +QString ServerMessage::parseClientName(const QString& line) const +{ + QString clientName("Unknown"); + auto nameStart = line.indexOf('"') + 1; + auto nameEnd = line.indexOf('"', nameStart); + + if (nameEnd > nameStart) + { + clientName = line.mid(nameStart, nameEnd - nameStart); + } + + return clientName; +} diff --git a/src/gui/src/ServerMessage.h b/src/gui/src/ServerMessage.h new file mode 100644 index 000000000..4efd02375 --- /dev/null +++ b/src/gui/src/ServerMessage.h @@ -0,0 +1,44 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2012-2021 Symless Ltd. + * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef SERVERMESSAGE_H +#define SERVERMESSAGE_H + +#include + +class ServerMessage +{ + QString m_message; + QString m_clienName; + +public: + explicit ServerMessage(const QString& message); + + bool isNewClientMessage() const; + bool isExitMessage() const; + bool isConnectedMessage() const; + bool isDisconnectedMessage() const; + + const QString& getClientName() const; + +private: + QString parseClientName(const QString& line) const; + +}; + +#endif // SERVERMESSAGE_H diff --git a/src/gui/src/widgets/ServerStateLabel.cpp b/src/gui/src/widgets/ServerStateLabel.cpp index 26f39929d..80f14770d 100644 --- a/src/gui/src/widgets/ServerStateLabel.cpp +++ b/src/gui/src/widgets/ServerStateLabel.cpp @@ -18,6 +18,8 @@ #include "ServerStateLabel.h" +#include "ServerMessage.h" + namespace synergy_widgets { @@ -28,17 +30,19 @@ ServerStateLabel::ServerStateLabel(QWidget* parent) : void ServerStateLabel::updateServerState(const QString& line) { - if (line.contains("process exited")) + ServerMessage message(line); + + if (message.isExitMessage()) { - m_clientsCounter = 0; + m_clients.clear(); } - else if (line.contains("has connected")) + else if (message.isConnectedMessage()) { - ++m_clientsCounter; + m_clients.append(message.getClientName()); } - else if (line.contains("has disconnected") && m_clientsCounter) + else if (message.isDisconnectedMessage()) { - --m_clientsCounter; + m_clients.removeAll(message.getClientName()); } updateState(); @@ -46,13 +50,13 @@ void ServerStateLabel::updateServerState(const QString& line) void ServerStateLabel::updateState() { - if (m_clientsCounter) + if (m_clients.isEmpty()) { - hide(); + show(); } else { - show(); + hide(); } } diff --git a/src/gui/src/widgets/ServerStateLabel.h b/src/gui/src/widgets/ServerStateLabel.h index 49ce40c4d..288b64b4f 100644 --- a/src/gui/src/widgets/ServerStateLabel.h +++ b/src/gui/src/widgets/ServerStateLabel.h @@ -20,6 +20,7 @@ #define SERVERSTATELABEL_H #include +#include namespace synergy_widgets { @@ -31,7 +32,7 @@ public: void updateServerState(const QString& line); private: - unsigned int m_clientsCounter = 0; + QStringList m_clients; void updateState(); };