SYNERGY-694 Setup client configuration (#6981)

* SYNERGY-694 Setup client configuration

* SYNERGY-694 Add copyrights

* SYNERGY-694 Fix code smell

* Update ChangeLog

* SYNERGY-694 Show setup if the window is closed or minimized
This commit is contained in:
SerhiiGadzhilov 2021-04-22 10:29:46 +03:00 committed by GitHub
parent 426055a44a
commit 749736581c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 276 additions and 11 deletions

View file

@ -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
===========

View file

@ -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

View file

@ -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();

View file

@ -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);

View file

@ -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();

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "ServerConnection.h"
#include "MainWindow.h"
#include "ServerConfigDialog.h"
#include "ServerMessage.h"
#include <QMessageBox>
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();
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef SERVERCONNECTION_H
#define SERVERCONNECTION_H
#include <QString>
#include <QStringList>
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

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef SERVERMESSAGE_H
#define SERVERMESSAGE_H
#include <QString>
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

View file

@ -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();
}
}

View file

@ -20,6 +20,7 @@
#define SERVERSTATELABEL_H
#include <QLabel>
#include <QStringList>
namespace synergy_widgets
{
@ -31,7 +32,7 @@ public:
void updateServerState(const QString& line);
private:
unsigned int m_clientsCounter = 0;
QStringList m_clients;
void updateState();
};