refactor(ServerConfigDialog): use SettingsDialogButtonBox and enable control lock for general setting controled items

This commit is contained in:
sithlord48 2026-08-13 06:14:31 -04:00 committed by Nick Bolton
parent 727191e9eb
commit fc95339477
3 changed files with 35 additions and 16 deletions

View file

@ -16,6 +16,7 @@
#include "dialogs/ActionDialog.h" #include "dialogs/ActionDialog.h"
#include "dialogs/HotkeyDialog.h" #include "dialogs/HotkeyDialog.h"
#include "dialogs/ScreenSettingsDialog.h" #include "dialogs/ScreenSettingsDialog.h"
#include "gui/widgets/SettingsDialogButtonBox.h"
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
@ -31,10 +32,15 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config)
m_originalServerConfigIsExternal(config.useExternalConfig()), m_originalServerConfigIsExternal(config.useExternalConfig()),
m_originalServerConfigUsesExternalFile(config.configFile()), m_originalServerConfigUsesExternalFile(config.configFile()),
m_serverConfig(config), m_serverConfig(config),
m_screenSetupModel(m_serverConfig.screens(), m_columns, m_rows) m_screenSetupModel(m_serverConfig.screens(), m_columns, m_rows),
m_buttonBox{new SettingsDialogButtonBox(this)}
{ {
ui->setupUi(this); ui->setupUi(this);
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
layout()->addWidget(m_buttonBox);
m_buttonBox->enableReset(false);
m_buttonBox->enableRestoreDefaults(false);
loadFromConfig(); loadFromConfig();
@ -448,12 +454,13 @@ void ServerConfigDialog::loadFromConfig()
} else { } else {
server->markAsServer(); server->markAsServer();
} }
updateControls();
} }
void ServerConfigDialog::initConnections() const void ServerConfigDialog::initConnections() const
{ {
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ServerConfigDialog::save); connect(m_buttonBox, &SettingsDialogButtonBox::accepted, this, &ServerConfigDialog::save);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ServerConfigDialog::cancel); connect(m_buttonBox, &SettingsDialogButtonBox::rejected, this, &ServerConfigDialog::cancel);
connect(ui->lblRemoveScreen, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved); connect(ui->lblRemoveScreen, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved);
connect(ui->btnNewHotkey, &QPushButton::clicked, this, &ServerConfigDialog::addHotkey); connect(ui->btnNewHotkey, &QPushButton::clicked, this, &ServerConfigDialog::addHotkey);
connect(ui->btnEditHotkey, &QPushButton::clicked, this, &ServerConfigDialog::editHotkey); connect(ui->btnEditHotkey, &QPushButton::clicked, this, &ServerConfigDialog::editHotkey);
@ -498,6 +505,26 @@ void ServerConfigDialog::initConnections() const
); );
connect(ui->cbDisableLockToComputer, &QCheckBox::toggled, this, &ServerConfigDialog::toggleLockToComputer); connect(ui->cbDisableLockToComputer, &QCheckBox::toggled, this, &ServerConfigDialog::toggleLockToComputer);
connect(&m_screenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange); connect(&m_screenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange);
connect(Settings::instance(), &Settings::settingsWritableChanged, this, &ServerConfigDialog::updateControls);
}
void ServerConfigDialog::updateControls() const
{
const bool writable = Settings::isWritable();
ui->cbDefaultLockToComputerState->setEnabled(writable);
ui->cbDisableLockToComputer->setEnabled(writable);
ui->cbEnableClipboard->setEnabled(writable);
ui->sbClipboardSizeLimit->setEnabled(writable);
ui->rbProtocolBarrier->setEnabled(writable);
ui->rbProtocolSynergy->setEnabled(writable);
ui->cbHeartbeat->setEnabled(writable);
ui->cbRelativeMouseMoves->setEnabled(writable);
ui->cbSwitchDelay->setEnabled(writable);
ui->cbWin32KeepForeground->setEnabled(writable);
ui->cbSwitchDoubleTap->setEnabled(writable);
ui->sbSwitchDoubleTap->setEnabled(writable && ui->cbSwitchDoubleTap->isChecked());
ui->sbSwitchDelay->setEnabled(writable && ui->cbSwitchDelay->isChecked());
ui->groupExternalConfig->setEnabled(writable);
} }
bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent) bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent)
@ -532,6 +559,5 @@ void ServerConfigDialog::onChange()
m_win32keepForeground == Settings::value(Settings::Server::Win32KeepForeground).toBool() && m_win32keepForeground == Settings::value(Settings::Server::Win32KeepForeground).toBool() &&
m_disableLockToComputer == Settings::value(Settings::Server::DisableLockToComputer).toBool() && m_disableLockToComputer == Settings::value(Settings::Server::DisableLockToComputer).toBool() &&
m_defaultLockToComputerState == Settings::value(Settings::Server::DefaultLockToComputerState).toBool(); m_defaultLockToComputerState == Settings::value(Settings::Server::DefaultLockToComputerState).toBool();
ui->buttonBox->button(QDialogButtonBox::Ok) m_buttonBox->enableSave(!isAppConfigDataEqual || !(m_originalServerConfig == m_serverConfig));
->setEnabled(!isAppConfigDataEqual || !(m_originalServerConfig == m_serverConfig));
} }

View file

@ -14,6 +14,7 @@
#include <QDialog> #include <QDialog>
class SettingsDialogButtonBox;
class QItemSelection; class QItemSelection;
namespace Ui { namespace Ui {
@ -88,6 +89,7 @@ private:
void cancel(); void cancel();
void loadFromConfig(); void loadFromConfig();
void initConnections() const; void initConnections() const;
void updateControls() const;
void onChange(); void onChange();
std::unique_ptr<Ui::ServerConfigDialog> ui; std::unique_ptr<Ui::ServerConfigDialog> ui;
QString m_message = ""; QString m_message = "";
@ -111,4 +113,5 @@ private:
QString m_originalServerConfigUsesExternalFile; QString m_originalServerConfigUsesExternalFile;
ServerConfig m_serverConfig; ServerConfig m_serverConfig;
ScreenSetupModel m_screenSetupModel; ScreenSetupModel m_screenSetupModel;
SettingsDialogButtonBox *m_buttonBox = nullptr;
}; };

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>724</width> <width>724</width>
<height>586</height> <height>609</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
@ -881,16 +881,6 @@ Enabling this setting will disable the server config GUI.</string>
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>