SYNERGY-786 The system does not update server name in Server configuration (#6953)

* SYNERGY-786 The system does not update server name in Server configuration

* SYNERGY-768 Remove unused header

* SYNERGY-786 Update ChangeLog and version

* SYNERGY-786 Fix code smells

* SYNERGY-786 Save screen name after update
This commit is contained in:
SerhiiGadzhilov
2021-02-22 14:33:18 +03:00
committed by GitHub
parent 450c741cd6
commit 22c77b4e8b
15 changed files with 139 additions and 44 deletions

View File

@ -1,3 +1,9 @@
v1.13.2-snapshot
===========
Bug fixes:
- #6953 The system does not update server name in Server configuration
===========
v1.13.1-snapshot
===========
Bug fixes:

View File

@ -6,7 +6,7 @@ cmake_minimum_required (VERSION 3.4)
set (SYNERGY_VERSION_MAJOR 1)
set (SYNERGY_VERSION_MINOR 13)
set (SYNERGY_VERSION_PATCH 1)
set (SYNERGY_VERSION_PATCH 2)
set (SYNERGY_VERSION_BUILD 1)
set (SYNERGY_VERSION_STAGE "snapshot")

View File

@ -200,6 +200,10 @@ QString AppConfig::autoConfigServer() const { return m_AutoConfigServer; }
void AppConfig::loadSettings()
{
m_ScreenName = loadSetting(kScreenName, QHostInfo::localHostName()).toString();
if (m_ScreenName.isEmpty()) {
m_ScreenName = QHostInfo::localHostName();
}
m_Port = loadSetting(kPort, 24800).toInt();
m_Interface = loadSetting(kInterfaceSetting).toString();
m_LogLevel = loadSetting(kLogLevel, 0).toInt();

View File

@ -49,6 +49,7 @@ const int kWizardVersion = 8;
class QSettings;
class SettingsDialog;
class ServerConfig;
enum ProcessMode {
Service,
@ -62,6 +63,7 @@ class AppConfig: public QObject, public GUI::Config::ConfigBase
friend class SettingsDialog;
friend class MainWindow;
friend class SetupWizard;
friend class ServerConfig;
public:
AppConfig();

View File

@ -111,7 +111,7 @@ MainWindow::MainWindow (AppConfig& appConfig,
m_AppConfig(&appConfig),
m_pSynergy(NULL),
m_SynergyState(synergyDisconnected),
m_ServerConfig(5, 3, m_AppConfig->screenName(), this),
m_ServerConfig(5, 3, m_AppConfig, this),
m_AlreadyHidden(false),
m_pMenuBar(NULL),
m_pMenuFile(NULL),
@ -135,7 +135,7 @@ MainWindow::MainWindow (AppConfig& appConfig,
m_pWidgetUpdate->hide();
m_VersionChecker.setApp(appPath(appConfig.synergycName()));
m_pLabelScreenName->setText(getScreenName());
m_pLabelScreenName->setText(appConfig.screenName());
connect(m_AppConfig, SIGNAL(screenNameChanged()), this, SLOT(updateScreenName()));
m_pLabelIpAddresses->setText(getIPAddresses());
@ -617,7 +617,7 @@ void MainWindow::startSynergy()
args << "-f" << "--no-tray" << "--debug" << appConfig().logLevelText();
args << "--name" << getScreenName();
args << "--name" << appConfig().screenName();
if (desktopMode)
{
@ -1074,16 +1074,6 @@ QString MainWindow::getIPAddresses()
return result;
}
QString MainWindow::getScreenName()
{
if (appConfig().screenName() == "") {
return QHostInfo::localHostName();
}
else {
return appConfig().screenName();
}
}
void MainWindow::changeEvent(QEvent* event)
{
if (event != 0)
@ -1301,7 +1291,7 @@ void MainWindow::autoAddScreen(const QString name)
void MainWindow::showConfigureServer(const QString& message)
{
ServerConfigDialog dlg(this, serverConfig(), appConfig().screenName());
ServerConfigDialog dlg(this, serverConfig());
dlg.message(message);
dlg.exec();
}
@ -1391,7 +1381,8 @@ void MainWindow::windowStateChanged()
hide();
}
void MainWindow::updateScreenName()
void MainWindow::updateScreenName()
{
m_pLabelScreenName->setText(getScreenName());
m_pLabelScreenName->setText(appConfig().screenName());
serverConfig().updateServerName();
}

View File

@ -114,7 +114,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void open();
void clearLog();
VersionChecker& versionChecker() { return m_VersionChecker; }
QString getScreenName();
ServerConfig& serverConfig() { return m_ServerConfig; }
void showConfigureServer(const QString& message);
void showConfigureServer() { showConfigureServer(""); }

View File

@ -66,6 +66,8 @@ class Screen : public BaseConfig
bool swapped() const { return m_Swapped; }
QString& name() { return m_Name; }
void setName(const QString& name) { m_Name = name; }
bool isServer() const { return m_isServer;}
void markAsServer() { m_isServer = true; }
protected:
void init();
@ -94,6 +96,7 @@ class Screen : public BaseConfig
QList<bool> m_Fixes;
bool m_Swapped;
bool m_isServer = false;
};
typedef QList<Screen> ScreenList;

View File

@ -0,0 +1,24 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 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 "ScreenNameValidator.h"
ScreenNameValidator::ScreenNameValidator(QObject *parent) :
QRegExpValidator(QRegExp("[a-z0-9\\._-]{,255}", Qt::CaseInsensitive), parent)
{
}

View File

@ -0,0 +1,29 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 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 SCREENNAMEVALIDATOR_H
#define SCREENNAMEVALIDATOR_H
#include <qvalidator.h>
class ScreenNameValidator : public QRegExpValidator
{
public:
explicit ScreenNameValidator(QObject *parent = nullptr);
};
#endif // SCREENNAMEVALIDATOR_H

View File

@ -22,6 +22,7 @@
#include <QtCore>
#include <QtGui>
#include <QMessageBox>
#include <ScreenNameValidator.h>
ScreenSettingsDialog::ScreenSettingsDialog(QWidget* parent, Screen* pScreen) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
@ -30,13 +31,11 @@ ScreenSettingsDialog::ScreenSettingsDialog(QWidget* parent, Screen* pScreen) :
{
setupUi(this);
QRegExp validScreenName("[a-z0-9\\._-]{,255}", Qt::CaseInsensitive);
m_pLineEditName->setText(m_pScreen->name());
m_pLineEditName->setValidator(new QRegExpValidator(validScreenName, m_pLineEditName));
m_pLineEditName->setValidator(new ScreenNameValidator(m_pLineEditName));
m_pLineEditName->selectAll();
m_pLineEditAlias->setValidator(new QRegExpValidator(validScreenName, m_pLineEditName));
m_pLineEditAlias->setValidator(new ScreenNameValidator(m_pLineEditName));
for (int i = 0; i < m_pScreen->aliases().count(); i++)
new QListWidgetItem(m_pScreen->aliases()[i], m_pListAliases);

View File

@ -42,13 +42,12 @@ static const struct
const int serverDefaultIndex = 7;
ServerConfig::ServerConfig(int numColumns, int numRows ,
QString serverName, MainWindow* mainWindow) :
ServerConfig::ServerConfig(int numColumns, int numRows, AppConfig* appConfig, MainWindow* mainWindow) :
m_Screens(),
m_NumColumns(numColumns),
m_NumRows(numRows),
m_ServerName(serverName),
m_pAppConfig(appConfig),
m_IgnoreAutoConfigClient(false),
m_EnableDragAndDrop(false),
m_DisableLockToScreen(false),
@ -119,8 +118,8 @@ void ServerConfig::saveSettings()
settings().setValue("ignoreAutoConfigClient", ignoreAutoConfigClient());
settings().setValue("disableLockToScreen", disableLockToScreen());
settings().setValue("enableDragAndDrop", enableDragAndDrop());
settings().setValue("clipboardSharing", clipboardSharing());
settings().setValue("clipboardSharingSize", QVariant::fromValue(clipboardSharingSize()));
settings().setValue("clipboardSharing", clipboardSharing());
settings().setValue("clipboardSharingSize", QVariant::fromValue(clipboardSharingSize()));
writeSettings(settings(), switchCorners(), "switchCorner");
@ -128,7 +127,11 @@ void ServerConfig::saveSettings()
for (int i = 0; i < screens().size(); i++)
{
settings().setArrayIndex(i);
screens()[i].saveSettings(settings());
auto& screen = screens()[i];
screen.saveSettings(settings());
if (screen.isServer() && m_pAppConfig->screenName() != screen.name()){
m_pAppConfig->setScreenName(screen.name());
}
}
settings().endArray();
@ -181,6 +184,9 @@ void ServerConfig::loadSettings()
{
settings().setArrayIndex(i);
screens()[i].loadSettings(settings());
if (getServerName() == screens()[i].name()) {
screens()[i].markAsServer();
}
}
settings().endArray();
@ -299,11 +305,12 @@ int ServerConfig::autoAddScreen(const QString name)
{
int serverIndex = -1;
int targetIndex = -1;
if (!findScreenName(m_ServerName, serverIndex)) {
if (!fixNoServer(m_ServerName, serverIndex)) {
return kAutoAddScreenManualServer;
}
if (!findScreenName(m_pAppConfig->screenName(), serverIndex) &&
!fixNoServer(m_pAppConfig->screenName(), serverIndex))
{
return kAutoAddScreenManualServer;
}
if (findScreenName(name, targetIndex)) {
m_pMainWindow->appendLogDebug(QString("ignoring screen already in config: %1").arg(name));
return kAutoAddScreenIgnore;
@ -362,6 +369,22 @@ int ServerConfig::autoAddScreen(const QString name)
return kAutoAddScreenOk;
}
const QString& ServerConfig::getServerName() const
{
return m_pAppConfig->screenName();
}
void ServerConfig::updateServerName()
{
for (auto& screen : screens()) {
if (screen.isServer()) {
screen.setName(m_pAppConfig->screenName());
screen.saveSettings(settings());
break;
}
}
}
bool ServerConfig::findScreenName(const QString& name, int& index)
{
bool found = false;

View File

@ -41,8 +41,7 @@ class ServerConfig : public BaseConfig, public GUI::Config::ConfigBase
friend QTextStream& operator<<(QTextStream& outStream, const ServerConfig& config);
public:
ServerConfig(int numColumns, int numRows,
QString serverName, MainWindow* mainWindow);
ServerConfig(int numColumns, int numRows, AppConfig* appConfig, MainWindow* mainWindow);
ServerConfig(const ServerConfig &src) =default;
ServerConfig(ServerConfig &&) =default;
@ -80,6 +79,8 @@ class ServerConfig : public BaseConfig, public GUI::Config::ConfigBase
void save(QFile& file) const;
int numScreens() const;
int autoAddScreen(const QString name);
const QString& getServerName() const;
void updateServerName();
protected:
QSettings& settings();
@ -132,7 +133,7 @@ class ServerConfig : public BaseConfig, public GUI::Config::ConfigBase
int m_SwitchCornerSize;
QList<bool> m_SwitchCorners;
HotkeyList m_Hotkeys;
QString m_ServerName;
AppConfig* m_pAppConfig;
bool m_IgnoreAutoConfigClient;
bool m_EnableDragAndDrop;
bool m_DisableLockToScreen;

View File

@ -25,7 +25,7 @@
#include <QtGui>
#include <QMessageBox>
ServerConfigDialog::ServerConfigDialog(QWidget* parent, ServerConfig& config, const QString& defaultScreenName) :
ServerConfigDialog::ServerConfigDialog(QWidget* parent, ServerConfig& config) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::ServerConfigDialogBase(),
m_OrigServerConfig(config),
@ -66,8 +66,19 @@ ServerConfigDialog::ServerConfigDialog(QWidget* parent, ServerConfig& config, co
m_pScreenSetupView->setModel(&m_ScreenSetupModel);
if (serverConfig().numScreens() == 0)
model().screen(serverConfig().numColumns() / 2, serverConfig().numRows() / 2) = Screen(defaultScreenName);
if (serverConfig().numScreens() == 0) {
Screen serverScreen(serverConfig().getServerName());
serverScreen.markAsServer();
model().screen(serverConfig().numColumns() / 2, serverConfig().numRows() / 2) = serverScreen;
}
else {
for (auto& screen : serverConfig().screens()) {
if (screen.name() == serverConfig().getServerName()) {
screen.markAsServer();
break;
}
}
}
}
void ServerConfigDialog::showEvent(QShowEvent* event)
@ -103,8 +114,8 @@ void ServerConfigDialog::accept()
serverConfig().setIgnoreAutoConfigClient(m_pCheckBoxIgnoreAutoConfigClient->isChecked());
serverConfig().setDisableLockToScreen(m_pCheckBoxDisableLockToScreen->isChecked());
serverConfig().setClipboardSharingSize(m_pSpinBoxClipboardSizeLimit->value() * 1024);
serverConfig().setClipboardSharing(m_pCheckBoxEnableClipboard->isChecked()
&& m_pSpinBoxClipboardSizeLimit->value());
serverConfig().setClipboardSharing(m_pCheckBoxEnableClipboard->isChecked()
&& m_pSpinBoxClipboardSizeLimit->value());
// now that the dialog has been accepted, copy the new server config to the original one,
// which is a reference to the one in MainWindow.

View File

@ -32,7 +32,7 @@ class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase
Q_OBJECT
public:
ServerConfigDialog(QWidget* parent, ServerConfig& config, const QString& defaultScreenName);
ServerConfigDialog(QWidget* parent, ServerConfig& config);
public slots:
void accept();
@ -50,7 +50,7 @@ class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase
void on_m_pButtonEditAction_clicked();
void on_m_pButtonRemoveAction_clicked();
void on_m_pCheckBoxEnableClipboard_stateChanged(int state);
void on_m_pCheckBoxEnableClipboard_stateChanged(int state);
protected:
ServerConfig& serverConfig() { return m_ServerConfig; }

View File

@ -26,6 +26,7 @@
#include "MainWindow.h"
#include "BonjourWindows.h"
#include "Zeroconf.h"
#include "ScreenNameValidator.h"
#include <QtCore>
#include <QtGui>
@ -50,6 +51,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
m_isSystemAtStart = appConfig().isSystemScoped();
buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
enableControls(appConfig().isWritable());
m_pLineEditScreenName->setValidator(new ScreenNameValidator(m_pLineEditScreenName));
connect(m_pLineEditLogFilename, SIGNAL(textChanged(const QString&)), this, SLOT(onChange()));
connect(m_pComboLogLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(onChange()));
@ -305,8 +307,8 @@ void SettingsDialog::updateKeyLengthOnFile(const QString &path) {
bool SettingsDialog::isModified()
{
return (
appConfig().screenName() != m_pLineEditScreenName->text()
return (!m_pLineEditScreenName->text().isEmpty() &&
(appConfig().screenName() != m_pLineEditScreenName->text()
|| appConfig().port() != m_pSpinBoxPort->value()
|| appConfig().networkInterface() != m_pLineEditInterface->text()
|| appConfig().logLevel() != m_pComboLogLevel->currentIndex()
@ -320,6 +322,7 @@ bool SettingsDialog::isModified()
|| appConfig().getTLSCertPath() != m_pLineEditCertificatePath->text()
|| appConfig().getTLSKeyLength() != m_pComboBoxKeyLength->currentText()
|| appConfig().getCryptoEnabled() != m_pCheckBoxEnableCrypto->isChecked()
|| appConfig().isSystemScoped() != m_isSystemAtStart)
);
}