Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmake/Version.cmake
Expand Up @@ -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")

Expand Down
4 changes: 4 additions & 0 deletions src/gui/src/AppConfig.cpp
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/src/AppConfig.h
Expand Up @@ -49,6 +49,7 @@ const int kWizardVersion = 8;

class QSettings;
class SettingsDialog;
class ServerConfig;

enum ProcessMode {
Service,
Expand All @@ -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();
Expand Down
23 changes: 7 additions & 16 deletions src/gui/src/MainWindow.cpp
Expand Up @@ -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),
Expand All @@ -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());

Expand Down Expand Up @@ -617,7 +617,7 @@ void MainWindow::startSynergy()
args << "-f" << "--no-tray" << "--debug" << appConfig().logLevelText();


args << "--name" << getScreenName();
args << "--name" << appConfig().screenName();

if (desktopMode)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion src/gui/src/MainWindow.h
Expand Up @@ -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(""); }
Expand Down
3 changes: 3 additions & 0 deletions src/gui/src/Screen.h
Expand Up @@ -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();
Expand Down Expand Up @@ -94,6 +96,7 @@ class Screen : public BaseConfig
QList<bool> m_Fixes;

bool m_Swapped;
bool m_isServer = false;
};

typedef QList<Screen> ScreenList;
Expand Down
24 changes: 24 additions & 0 deletions src/gui/src/ScreenNameValidator.cpp
@@ -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)
{

}
29 changes: 29 additions & 0 deletions src/gui/src/ScreenNameValidator.h
@@ -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
7 changes: 3 additions & 4 deletions src/gui/src/ScreenSettingsDialog.cpp
Expand Up @@ -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),
Expand All @@ -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);
Expand Down
43 changes: 33 additions & 10 deletions src/gui/src/ServerConfig.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -119,16 +118,20 @@ 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");

settings().beginWriteArray("screens");
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();

Expand Down Expand Up @@ -181,6 +184,9 @@ void ServerConfig::loadSettings()
{
settings().setArrayIndex(i);
screens()[i].loadSettings(settings());
if (getServerName() == screens()[i].name()) {
screens()[i].markAsServer();
}
}
settings().endArray();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/gui/src/ServerConfig.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 16 additions & 5 deletions src/gui/src/ServerConfigDialog.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/gui/src/ServerConfigDialog.h
Expand Up @@ -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();
Expand All @@ -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; }
Expand Down