Synergy 1161 when clicking on save preferences on configure server window, automatically apply all the new settings (#7074)

* SYNERGY-1161 When clicking on "Save" preferences on "Configure server" window, automatically apply all the new settings
*Added comparison for all classes which used in server config

* SYNERGY-1161 When clicking on Save preferences on Configure server window, automatically apply all the new settings
*Added server config changes checking logic

* SYNERGY-1161 When clicking on Save preferences on Configure server window, automatically apply all the new settings
* Update ChangeLog

* SYNERGY-1161 When clicking on Save preferences on Configure server window, automatically apply all the new settings
*Fix code style

* SYNERGY-1161 When clicking on Save preferences on Configure server window, automatically apply all the new settings
* Fix Linux build

* SYNERGY-1161 When clicking on Save preferences on Configure server window, automatically apply all the new settings
*Fix Sonar code smells

Co-authored-by: Andrii Batyiev <andrii-external@symless.com>
This commit is contained in:
Andrey Batyiev 2021-08-20 15:22:07 +03:00 committed by GitHub
parent a703280d38
commit 861f6ec279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 185 additions and 31 deletions

View File

@ -6,6 +6,7 @@ Bug fixes:
Enhancements:
- #7068 Add Synergy restart when settings changed
- #7072 Ability to run synergy as a pre-login agent
- #7074 Add Synergy restart when server settings changed
===========
v1.14.1-rc

View File

@ -143,6 +143,19 @@ void Action::saveSettings(QSettings& settings) const
settings.setValue("restartServer", restartServer());
}
bool Action::operator==(const Action& a) const
{
return m_KeySequence == a.m_KeySequence &&
m_Type == a.m_Type &&
m_TypeScreenNames == a.m_TypeScreenNames &&
m_SwitchScreenName == a.m_SwitchScreenName &&
m_SwitchDirection == a.m_SwitchDirection &&
m_LockCursorMode == a.m_LockCursorMode &&
m_ActiveOnRelease == a.m_ActiveOnRelease &&
m_HasScreens == a.m_HasScreens &&
m_restartServer == a.m_restartServer;
}
QTextStream& operator<<(QTextStream& outStream, const Action& action)
{
if (action.activeOnRelease())

View File

@ -77,6 +77,8 @@ class Action
bool haveScreens() const { return m_HasScreens; }
bool restartServer() const { return m_restartServer; }
bool operator==(const Action& a) const;
protected:
KeySequence& keySequence() { return m_KeySequence; }
void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; }

View File

@ -66,6 +66,11 @@ void Hotkey::saveSettings(QSettings& settings) const
settings.endArray();
}
bool Hotkey::operator==(const Hotkey& hk) const
{
return m_KeySequence == hk.m_KeySequence && m_Actions == hk.m_Actions;
}
QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey)
{
for (int i = 0; i < hotkey.actions().size(); i++)

View File

@ -48,6 +48,8 @@ class Hotkey
void loadSettings(QSettings& settings);
void saveSettings(QSettings& settings) const;
bool operator==(const Hotkey& hk) const;
protected:
KeySequence& keySequence() { return m_KeySequence; }
void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; }

View File

@ -235,3 +235,10 @@ QString KeySequence::keyToString(int key)
// give up, synergy probably won't handle this
return "";
}
bool KeySequence::operator==(const KeySequence& ks) const
{
return m_Sequence == ks.m_Sequence &&
m_Modifiers == ks.m_Modifiers &&
m_IsValid == ks.m_IsValid;
}

View File

@ -41,6 +41,8 @@ class KeySequence
void loadSettings(QSettings& settings);
const QList<int>& sequence() const { return m_Sequence; }
bool operator==(const KeySequence& ks) const;
private:
void setValid(bool b) { m_IsValid = b; }
void setModifiers(int i) { m_Modifiers = i; }

View File

@ -1355,7 +1355,14 @@ void MainWindow::showConfigureServer(const QString& message)
{
ServerConfigDialog dlg(this, serverConfig());
dlg.message(message);
dlg.exec();
auto result = dlg.exec();
if(result == QDialog::Accepted) {
auto state = synergyState();
if ((state == synergyConnected) || (state == synergyConnecting) || (state == synergyListening)) {
restartSynergy();
}
}
}
void MainWindow::on_m_pButtonConfigureServer_clicked()

View File

@ -122,6 +122,19 @@ QTextStream& Screen::writeAliasesSection(QTextStream& outStream) const
return outStream;
}
bool Screen::operator==(const Screen& screen) const
{
return m_Pixmap == screen.m_Pixmap &&
m_Name == screen.m_Name &&
m_Aliases == screen.m_Aliases &&
m_Modifiers == screen.m_Modifiers &&
m_SwitchCorners == screen.m_SwitchCorners &&
m_SwitchCornerSize == screen.m_SwitchCornerSize &&
m_Fixes == screen.m_Fixes &&
m_Swapped == screen.m_Swapped &&
m_isServer == screen.m_isServer;
}
QDataStream& operator<<(QDataStream& outStream, const Screen& screen)
{
return outStream

View File

@ -69,6 +69,8 @@ class Screen : public BaseConfig
bool isServer() const { return m_isServer;}
void markAsServer() { m_isServer = true; }
bool operator==(const Screen& screen) const;
protected:
void init();
QPixmap* pixmap() { return &m_Pixmap; }

View File

@ -125,3 +125,8 @@ void ScreenList::addScreenToFirstEmpty(const Screen& newScreen)
}
}
bool ScreenList::operator==(const ScreenList& sc) const
{
return m_width == sc.m_width && QList::operator==(sc);
}

View File

@ -47,6 +47,12 @@ public:
* @param newScreen
*/
void addScreenToFirstEmpty(const Screen& newScreen);
/**
* @brief Returns true if screens are equal
* @param sc
*/
bool operator==(const ScreenList& sc) const;
};
#endif // SCREENLIST_H

View File

@ -138,12 +138,15 @@ bool ScreenSetupModel::dropMimeData(const QMimeData* data, Qt::DropAction action
screen(parent.column(), parent.row()) = droppedScreen;
emit screensChanged();
return true;
}
void ScreenSetupModel::addScreen(const Screen& newScreen)
{
m_Screens.addScreenByPriority(newScreen);
emit screensChanged();
}
bool ScreenSetupModel::isFull() const

View File

@ -53,6 +53,10 @@ class ScreenSetupModel : public QAbstractTableModel
QMimeData* mimeData(const QModelIndexList& indexes) const;
bool isFull() const;
signals:
void screensChanged();
protected:
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
const Screen& screen(const QModelIndex& index) const { return screen(index.column(), index.row()); }

View File

@ -76,6 +76,7 @@ void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent* event)
{
ScreenSettingsDialog dlg(this, &model()->screen(col, row), &model()->m_Screens);
dlg.exec();
emit model()->screensChanged();
}
}
else
@ -147,6 +148,8 @@ void ScreenSetupView::startDrag(Qt::DropActions)
model()->screen(indexes[0]) = Screen();
else
model()->screen(indexes[0]).setSwapped(false);
emit model()->screensChanged();
}
}

View File

@ -76,6 +76,31 @@ bool ServerConfig::save(const QString& fileName) const
return true;
}
bool ServerConfig::operator==(const ServerConfig& sc) const
{
return m_Screens == sc.m_Screens &&
m_NumColumns == sc.m_NumColumns &&
m_NumRows == sc.m_NumRows &&
m_HasHeartbeat == sc.m_HasHeartbeat &&
m_Heartbeat == sc.m_Heartbeat &&
m_RelativeMouseMoves == sc.m_RelativeMouseMoves &&
m_Win32KeepForeground == sc.m_Win32KeepForeground &&
m_HasSwitchDelay == sc.m_HasSwitchDelay &&
m_SwitchDelay == sc.m_SwitchDelay &&
m_HasSwitchDoubleTap == sc.m_HasSwitchDoubleTap &&
m_SwitchDoubleTap == sc.m_SwitchDoubleTap &&
m_SwitchCornerSize == sc.m_SwitchCornerSize &&
m_SwitchCorners == sc.m_SwitchCorners &&
m_Hotkeys == sc.m_Hotkeys &&
m_pAppConfig == sc.m_pAppConfig &&
m_IgnoreAutoConfigClient == sc.m_IgnoreAutoConfigClient &&
m_EnableDragAndDrop == sc.m_EnableDragAndDrop &&
m_DisableLockToScreen == sc.m_DisableLockToScreen &&
m_ClipboardSharing == sc.m_ClipboardSharing &&
m_ClipboardSharingSize == sc.m_ClipboardSharingSize &&
m_pMainWindow == sc.m_pMainWindow;
}
void ServerConfig::save(QFile& file) const
{
QTextStream outStream(&file);

View File

@ -50,6 +50,8 @@ class ServerConfig : public BaseConfig, public GUI::Config::ConfigBase
ServerConfig& operator=(const ServerConfig &src) =default;
ServerConfig& operator=(ServerConfig &&) =delete;
bool operator==(const ServerConfig& sc) const;
public:
const ScreenList& screens() const { return m_Screens; }
int numColumns() const { return m_NumColumns; }

View File

@ -31,6 +31,8 @@ ServerConfigDialog::ServerConfigDialog(QWidget* parent, ServerConfig& config) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::ServerConfigDialogBase(),
m_OrigServerConfig(config),
m_OrigServerAppConfigUseExternalConfig(config.getUseExternalConfig()),
m_OrigServerAppConfigExternalConfigFile(config.getConfigFile()),
m_ServerConfig(config),
m_ScreenSetupModel(serverConfig().screens(), serverConfig().numColumns(), serverConfig().numRows()),
m_Message("")
@ -84,6 +86,53 @@ ServerConfigDialog::ServerConfigDialog(QWidget* parent, ServerConfig& config) :
m_pButtonAddComputer->setEnabled(!model().isFull());
connect(m_pTrashScreenWidget, SIGNAL(screenRemoved()), this, SLOT(onScreenRemoved()));
onChange();
//computers
connect(&m_ScreenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange);
//advanced
connect(m_pCheckBoxSwitchDelay, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().haveSwitchDelay(v); onChange();});
connect(m_pSpinBoxSwitchDelay, QOverload<int>::of(&QSpinBox::valueChanged),
this, [this]( const auto& v ) { serverConfig().setSwitchDelay(v); onChange();});
connect(m_pCheckBoxSwitchDoubleTap, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().haveSwitchDoubleTap(v); onChange();});
connect(m_pSpinBoxSwitchDoubleTap, QOverload<int>::of(&QSpinBox::valueChanged),
this, [this]( const auto& v ) { serverConfig().setSwitchDoubleTap(v); onChange();});
connect(m_pCheckBoxEnableClipboard, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setClipboardSharing(v); onChange();});
connect(m_pSpinBoxClipboardSizeLimit, QOverload<int>::of(&QSpinBox::valueChanged),
this, [this]( const auto& v ) { serverConfig().setClipboardSharingSize(v * 1024); onChange();});
connect(m_pCheckBoxHeartbeat, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().haveHeartbeat(v); onChange();});
connect(m_pSpinBoxHeartbeat, QOverload<int>::of(&QSpinBox::valueChanged),
this, [this]( const auto& v ) { serverConfig().setHeartbeat(v); onChange();});
connect(m_pCheckBoxRelativeMouseMoves, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setRelativeMouseMoves(v); onChange();});
connect(m_pCheckBoxWin32KeepForeground, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setWin32KeepForeground(v); onChange();});
connect(m_pCheckBoxIgnoreAutoConfigClient, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setIgnoreAutoConfigClient(v); onChange();});
connect(m_pCheckBoxDisableLockToScreen, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setDisableLockToScreen(v); onChange();});
connect(m_pCheckBoxCornerTopLeft, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setSwitchCorner(BaseConfig::TopLeft, v); onChange();});
connect(m_pCheckBoxCornerTopRight, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setSwitchCorner(BaseConfig::TopRight, v); onChange();});
connect(m_pCheckBoxCornerBottomLeft, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setSwitchCorner(BaseConfig::BottomLeft, v); onChange();});
connect(m_pCheckBoxCornerBottomRight, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setSwitchCorner(BaseConfig::BottomRight, v); onChange();});
connect(m_pSpinBoxSwitchCornerSize, QOverload<int>::of(&QSpinBox::valueChanged),
this, [this]( const auto& v ) { serverConfig().setSwitchCornerSize(v); onChange();});
//config
connect(m_pCheckBoxUseExternalConfig, &QCheckBox::stateChanged,
this, [this]( const auto& v ) { serverConfig().setUseExternalConfig(v); onChange();});
connect(m_pEditConfigFile, &QLineEdit::textChanged,
this, [this]() { serverConfig().setConfigFile(m_pEditConfigFile->text()); onChange();});
}
void ServerConfigDialog::showEvent(QShowEvent* event)
@ -115,32 +164,6 @@ void ServerConfigDialog::accept()
}
}
serverConfig().setConfigFile(m_pEditConfigFile->text());
serverConfig().setUseExternalConfig(m_pCheckBoxUseExternalConfig->isChecked());
serverConfig().haveHeartbeat(m_pCheckBoxHeartbeat->isChecked());
serverConfig().setHeartbeat(m_pSpinBoxHeartbeat->value());
serverConfig().setRelativeMouseMoves(m_pCheckBoxRelativeMouseMoves->isChecked());
serverConfig().setWin32KeepForeground(m_pCheckBoxWin32KeepForeground->isChecked());
serverConfig().haveSwitchDelay(m_pCheckBoxSwitchDelay->isChecked());
serverConfig().setSwitchDelay(m_pSpinBoxSwitchDelay->value());
serverConfig().haveSwitchDoubleTap(m_pCheckBoxSwitchDoubleTap->isChecked());
serverConfig().setSwitchDoubleTap(m_pSpinBoxSwitchDoubleTap->value());
serverConfig().setSwitchCorner(BaseConfig::TopLeft, m_pCheckBoxCornerTopLeft->isChecked());
serverConfig().setSwitchCorner(BaseConfig::TopRight, m_pCheckBoxCornerTopRight->isChecked());
serverConfig().setSwitchCorner(BaseConfig::BottomLeft, m_pCheckBoxCornerBottomLeft->isChecked());
serverConfig().setSwitchCorner(BaseConfig::BottomRight, m_pCheckBoxCornerBottomRight->isChecked());
serverConfig().setSwitchCornerSize(m_pSpinBoxSwitchCornerSize->value());
serverConfig().setIgnoreAutoConfigClient(m_pCheckBoxIgnoreAutoConfigClient->isChecked());
serverConfig().setDisableLockToScreen(m_pCheckBoxDisableLockToScreen->isChecked());
serverConfig().setClipboardSharingSize(m_pSpinBoxClipboardSizeLimit->value() * 1024);
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.
setOrigServerConfig(serverConfig());
@ -148,14 +171,22 @@ void ServerConfigDialog::accept()
QDialog::accept();
}
void ServerConfigDialog::reject()
{
serverConfig().setUseExternalConfig(m_OrigServerAppConfigUseExternalConfig);
serverConfig().setConfigFile(m_OrigServerAppConfigExternalConfigFile);
QDialog::reject();
}
void ServerConfigDialog::on_m_pButtonNewHotkey_clicked()
{
Hotkey hotkey;
HotkeyDialog dlg(this, hotkey);
if (dlg.exec() == QDialog::Accepted)
{
if (dlg.exec() == QDialog::Accepted) {
serverConfig().hotkeys().append(hotkey);
m_pListHotkeys->addItem(hotkey.text());
onChange();
}
}
@ -165,8 +196,10 @@ void ServerConfigDialog::on_m_pButtonEditHotkey_clicked()
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
Hotkey& hotkey = serverConfig().hotkeys()[idx];
HotkeyDialog dlg(this, hotkey);
if (dlg.exec() == QDialog::Accepted)
if (dlg.exec() == QDialog::Accepted) {
m_pListHotkeys->currentItem()->setText(hotkey.text());
onChange();
}
}
void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked()
@ -176,6 +209,7 @@ void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked()
serverConfig().hotkeys().removeAt(idx);
m_pListActions->clear();
delete m_pListHotkeys->item(idx);
onChange();
}
void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged()
@ -218,6 +252,7 @@ void ServerConfigDialog::on_m_pButtonNewAction_clicked()
{
hotkey.actions().append(action);
m_pListActions->addItem(action.text());
onChange();
}
}
@ -232,8 +267,10 @@ void ServerConfigDialog::on_m_pButtonEditAction_clicked()
Action& action = hotkey.actions()[idxAction];
ActionDialog dlg(this, serverConfig(), hotkey, action);
if (dlg.exec() == QDialog::Accepted)
if (dlg.exec() == QDialog::Accepted) {
m_pListActions->currentItem()->setText(action.text());
onChange();
}
}
void ServerConfigDialog::on_m_pButtonRemoveAction_clicked()
@ -247,6 +284,7 @@ void ServerConfigDialog::on_m_pButtonRemoveAction_clicked()
hotkey.actions().removeAt(idxAction);
delete m_pListActions->currentItem();
onChange();
}
void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(int const state)
@ -280,6 +318,7 @@ void ServerConfigDialog::on_m_pButtonAddComputer_clicked()
void ServerConfigDialog::onScreenRemoved()
{
m_pButtonAddComputer->setEnabled(true);
onChange();
}
void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked)
@ -311,3 +350,10 @@ bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked()
return false;
}
void ServerConfigDialog::onChange()
{
bool isAppConfigDataEqual = m_OrigServerAppConfigUseExternalConfig == serverConfig().getUseExternalConfig() &&
m_OrigServerAppConfigExternalConfigFile == serverConfig().getConfigFile();
m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!isAppConfigDataEqual || !(m_OrigServerConfig == m_ServerConfig));
}

View File

@ -36,6 +36,7 @@ class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase
public slots:
void accept();
void reject() override;
void showEvent(QShowEvent* event);
void message(const QString& message) { m_Message = message; }
@ -62,9 +63,14 @@ class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase
private:
ServerConfig& m_OrigServerConfig;
bool m_OrigServerAppConfigUseExternalConfig;
QString m_OrigServerAppConfigExternalConfigFile;
ServerConfig m_ServerConfig;
ScreenSetupModel m_ScreenSetupModel;
QString m_Message;
private slots:
void onChange();
};
#endif