refactor: serverconfigdialog ui is no longer base for the class

This commit is contained in:
sithlord48 2024-10-18 19:52:32 -04:00 committed by Nick Bolton
parent 9167bf04f6
commit afff2eb6ac
3 changed files with 108 additions and 100 deletions

View file

@ -17,6 +17,7 @@
*/ */
#include "ServerConfigDialog.h" #include "ServerConfigDialog.h"
#include "ui_ServerConfigDialog.h"
#include "ActionDialog.h" #include "ActionDialog.h"
#include "HotkeyDialog.h" #include "HotkeyDialog.h"
@ -32,7 +33,7 @@ using enum ScreenConfig::SwitchCorner;
ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig) ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::ServerConfigDialogBase(), ui{std::make_unique<Ui::ServerConfigDialog>()},
m_OriginalServerConfig(config), m_OriginalServerConfig(config),
m_OriginalServerConfigIsExternal(config.useExternalConfig()), m_OriginalServerConfigIsExternal(config.useExternalConfig()),
m_OriginalServerConfigUsesExternalFile(config.configFile()), m_OriginalServerConfigUsesExternalFile(config.configFile()),
@ -41,42 +42,42 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, Ap
m_Message(""), m_Message(""),
m_appConfig(appConfig) m_appConfig(appConfig)
{ {
setupUi(this); ui->setupUi(this);
// force the first tab, since qt creator sets the active tab as the last one // force the first tab, since qt creator sets the active tab as the last one
// the developer was looking at, and it's easy to accidentally save that. // the developer was looking at, and it's easy to accidentally save that.
m_pTabWidget->setCurrentIndex(0); ui->m_pTabWidget->setCurrentIndex(0);
m_pEditConfigFile->setText(serverConfig().configFile()); ui->m_pEditConfigFile->setText(serverConfig().configFile());
m_pCheckBoxUseExternalConfig->setChecked(serverConfig().useExternalConfig()); ui->m_pCheckBoxUseExternalConfig->setChecked(serverConfig().useExternalConfig());
m_pCheckBoxHeartbeat->setChecked(serverConfig().hasHeartbeat()); ui->m_pCheckBoxHeartbeat->setChecked(serverConfig().hasHeartbeat());
m_pSpinBoxHeartbeat->setValue(serverConfig().heartbeat()); ui->m_pSpinBoxHeartbeat->setValue(serverConfig().heartbeat());
m_pCheckBoxRelativeMouseMoves->setChecked(serverConfig().relativeMouseMoves()); ui->m_pCheckBoxRelativeMouseMoves->setChecked(serverConfig().relativeMouseMoves());
m_pCheckBoxWin32KeepForeground->setChecked(serverConfig().win32KeepForeground()); ui->m_pCheckBoxWin32KeepForeground->setChecked(serverConfig().win32KeepForeground());
m_pCheckBoxSwitchDelay->setChecked(serverConfig().hasSwitchDelay()); ui->m_pCheckBoxSwitchDelay->setChecked(serverConfig().hasSwitchDelay());
m_pSpinBoxSwitchDelay->setValue(serverConfig().switchDelay()); ui->m_pSpinBoxSwitchDelay->setValue(serverConfig().switchDelay());
m_pCheckBoxSwitchDoubleTap->setChecked(serverConfig().hasSwitchDoubleTap()); ui->m_pCheckBoxSwitchDoubleTap->setChecked(serverConfig().hasSwitchDoubleTap());
m_pSpinBoxSwitchDoubleTap->setValue(serverConfig().switchDoubleTap()); ui->m_pSpinBoxSwitchDoubleTap->setValue(serverConfig().switchDoubleTap());
m_pCheckBoxCornerTopLeft->setChecked(serverConfig().switchCorner(static_cast<int>(TopLeft))); ui->m_pCheckBoxCornerTopLeft->setChecked(serverConfig().switchCorner(static_cast<int>(TopLeft)));
m_pCheckBoxCornerTopRight->setChecked(serverConfig().switchCorner(static_cast<int>(TopRight))); ui->m_pCheckBoxCornerTopRight->setChecked(serverConfig().switchCorner(static_cast<int>(TopRight)));
m_pCheckBoxCornerBottomLeft->setChecked(serverConfig().switchCorner(static_cast<int>(BottomLeft))); ui->m_pCheckBoxCornerBottomLeft->setChecked(serverConfig().switchCorner(static_cast<int>(BottomLeft)));
m_pCheckBoxCornerBottomRight->setChecked(serverConfig().switchCorner(static_cast<int>(BottomRight))); ui->m_pCheckBoxCornerBottomRight->setChecked(serverConfig().switchCorner(static_cast<int>(BottomRight)));
m_pSpinBoxSwitchCornerSize->setValue(serverConfig().switchCornerSize()); ui->m_pSpinBoxSwitchCornerSize->setValue(serverConfig().switchCornerSize());
m_pCheckBoxDisableLockToScreen->setChecked(serverConfig().disableLockToScreen()); ui->m_pCheckBoxDisableLockToScreen->setChecked(serverConfig().disableLockToScreen());
m_pCheckBoxEnableClipboard->setChecked(serverConfig().clipboardSharing()); ui->m_pCheckBoxEnableClipboard->setChecked(serverConfig().clipboardSharing());
int clipboardSharingSizeM = static_cast<int>(serverConfig().clipboardSharingSize() / 1024); int clipboardSharingSizeM = static_cast<int>(serverConfig().clipboardSharingSize() / 1024);
m_pSpinBoxClipboardSizeLimit->setValue(clipboardSharingSizeM); ui->m_pSpinBoxClipboardSizeLimit->setValue(clipboardSharingSizeM);
m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing()); ui->m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing());
foreach (const Hotkey &hotkey, serverConfig().hotkeys()) foreach (const Hotkey &hotkey, serverConfig().hotkeys())
m_pListHotkeys->addItem(hotkey.text()); ui->m_pListHotkeys->addItem(hotkey.text());
m_pScreenSetupView->setModel(&m_ScreenSetupModel); ui->m_pScreenSetupView->setModel(&m_ScreenSetupModel);
auto &screens = serverConfig().screens(); auto &screens = serverConfig().screens();
auto server = std::find_if(screens.begin(), screens.end(), [this](const Screen &screen) { auto server = std::find_if(screens.begin(), screens.end(), [this](const Screen &screen) {
@ -91,8 +92,8 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, Ap
server->markAsServer(); server->markAsServer();
} }
m_pButtonAddComputer->setEnabled(!model().isFull()); ui->m_pButtonAddComputer->setEnabled(!model().isFull());
connect(m_pTrashScreenWidget, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved); connect(ui->m_pTrashScreenWidget, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved);
onChange(); onChange();
@ -100,149 +101,151 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, Ap
connect(&m_ScreenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange); connect(&m_ScreenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange);
#if QT_VERSION <= QT_VERSION_CHECK(6, 7, 0) #if QT_VERSION <= QT_VERSION_CHECK(6, 7, 0)
// advanced // advanced
connect(m_pCheckBoxSwitchDelay, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxSwitchDelay, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().haveSwitchDelay(v); serverConfig().haveSwitchDelay(v);
onChange(); onChange();
}); });
connect(m_pCheckBoxSwitchDoubleTap, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxSwitchDoubleTap, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().haveSwitchDoubleTap(v); serverConfig().haveSwitchDoubleTap(v);
onChange(); onChange();
}); });
connect(m_pCheckBoxEnableClipboard, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxEnableClipboard, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setClipboardSharing(v); serverConfig().setClipboardSharing(v);
onChange(); onChange();
}); });
connect(m_pCheckBoxHeartbeat, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxHeartbeat, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().haveHeartbeat(v); serverConfig().haveHeartbeat(v);
onChange(); onChange();
}); });
connect(m_pCheckBoxRelativeMouseMoves, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxRelativeMouseMoves, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setRelativeMouseMoves(v); serverConfig().setRelativeMouseMoves(v);
onChange(); onChange();
}); });
connect(m_pCheckBoxWin32KeepForeground, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxWin32KeepForeground, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setWin32KeepForeground(v); serverConfig().setWin32KeepForeground(v);
onChange(); onChange();
}); });
connect(m_pCheckBoxDisableLockToScreen, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxDisableLockToScreen, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setDisableLockToScreen(v); serverConfig().setDisableLockToScreen(v);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerTopLeft, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxCornerTopLeft, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setSwitchCorner(static_cast<int>(TopLeft), v); serverConfig().setSwitchCorner(static_cast<int>(TopLeft), v);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerTopRight, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxCornerTopRight, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setSwitchCorner(static_cast<int>(TopRight), v); serverConfig().setSwitchCorner(static_cast<int>(TopRight), v);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerBottomLeft, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxCornerBottomLeft, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setSwitchCorner(static_cast<int>(BottomLeft), v); serverConfig().setSwitchCorner(static_cast<int>(BottomLeft), v);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerBottomRight, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxCornerBottomRight, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setSwitchCorner(static_cast<int>(BottomRight), v); serverConfig().setSwitchCorner(static_cast<int>(BottomRight), v);
onChange(); onChange();
}); });
// config // config
connect(m_pCheckBoxUseExternalConfig, &QCheckBox::stateChanged, this, [this](const int &v) { connect(ui->m_pCheckBoxUseExternalConfig, &QCheckBox::stateChanged, this, [this](const int &v) {
serverConfig().setUseExternalConfig(v); serverConfig().setUseExternalConfig(v);
onChange(); onChange();
}); });
#else #else
connect(m_pCheckBoxSwitchDelay, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxSwitchDelay, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().haveSwitchDelay(v == Qt::Checked); serverConfig().haveSwitchDelay(v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxSwitchDoubleTap, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxSwitchDoubleTap, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().haveSwitchDoubleTap(v == Qt::Checked); serverConfig().haveSwitchDoubleTap(v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxEnableClipboard, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxEnableClipboard, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setClipboardSharing(v == Qt::Checked); serverConfig().setClipboardSharing(v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxHeartbeat, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxHeartbeat, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().haveHeartbeat(v == Qt::Checked); serverConfig().haveHeartbeat(v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxRelativeMouseMoves, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxRelativeMouseMoves, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setRelativeMouseMoves(v == Qt::Checked); serverConfig().setRelativeMouseMoves(v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxWin32KeepForeground, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxWin32KeepForeground, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setWin32KeepForeground(v == Qt::Checked); serverConfig().setWin32KeepForeground(v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxDisableLockToScreen, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxDisableLockToScreen, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setDisableLockToScreen(v == Qt::Checked); serverConfig().setDisableLockToScreen(v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerTopLeft, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxCornerTopLeft, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setSwitchCorner(static_cast<int>(TopLeft), v == Qt::Checked); serverConfig().setSwitchCorner(static_cast<int>(TopLeft), v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerTopRight, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxCornerTopRight, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setSwitchCorner(static_cast<int>(TopRight), v == Qt::Checked); serverConfig().setSwitchCorner(static_cast<int>(TopRight), v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerBottomLeft, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxCornerBottomLeft, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setSwitchCorner(static_cast<int>(BottomLeft), v == Qt::Checked); serverConfig().setSwitchCorner(static_cast<int>(BottomLeft), v == Qt::Checked);
onChange(); onChange();
}); });
connect(m_pCheckBoxCornerBottomRight, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxCornerBottomRight, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setSwitchCorner(static_cast<int>(BottomRight), v == Qt::Checked); serverConfig().setSwitchCorner(static_cast<int>(BottomRight), v == Qt::Checked);
onChange(); onChange();
}); });
// config // config
connect(m_pCheckBoxUseExternalConfig, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) { connect(ui->m_pCheckBoxUseExternalConfig, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
serverConfig().setUseExternalConfig(v == Qt::Checked); serverConfig().setUseExternalConfig(v == Qt::Checked);
onChange(); onChange();
}); });
#endif #endif
connect( connect(
m_pSpinBoxSwitchDelay, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, ui->m_pSpinBoxSwitchDelay, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](const int &v) { [this](const int &v) {
serverConfig().setSwitchDelay(v); serverConfig().setSwitchDelay(v);
onChange(); onChange();
} }
); );
connect( connect(
m_pSpinBoxSwitchDoubleTap, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, ui->m_pSpinBoxSwitchDoubleTap, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](const int &v) { [this](const int &v) {
serverConfig().setSwitchDoubleTap(v); serverConfig().setSwitchDoubleTap(v);
onChange(); onChange();
} }
); );
connect( connect(
m_pSpinBoxClipboardSizeLimit, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, ui->m_pSpinBoxClipboardSizeLimit, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](const int &v) { [this](const int &v) {
serverConfig().setClipboardSharingSize(v * 1024); serverConfig().setClipboardSharingSize(v * 1024);
onChange(); onChange();
} }
); );
connect( connect(
m_pSpinBoxHeartbeat, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, ui->m_pSpinBoxHeartbeat, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](const int &v) { [this](const int &v) {
serverConfig().setHeartbeat(v); serverConfig().setHeartbeat(v);
onChange(); onChange();
} }
); );
connect( connect(
m_pSpinBoxSwitchCornerSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, ui->m_pSpinBoxSwitchCornerSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](const int &v) { [this](const int &v) {
serverConfig().setSwitchCornerSize(v); serverConfig().setSwitchCornerSize(v);
onChange(); onChange();
} }
); );
connect(m_pEditConfigFile, &QLineEdit::textChanged, this, [this]() { connect(ui->m_pEditConfigFile, &QLineEdit::textChanged, this, [this]() {
serverConfig().setConfigFile(m_pEditConfigFile->text()); serverConfig().setConfigFile(ui->m_pEditConfigFile->text());
onChange(); onChange();
}); });
} }
ServerConfigDialog::~ServerConfigDialog() = default;
bool ServerConfigDialog::addClient(const QString &clientName) bool ServerConfigDialog::addClient(const QString &clientName)
{ {
return addComputer(clientName, true); return addComputer(clientName, true);
@ -250,7 +253,7 @@ bool ServerConfigDialog::addClient(const QString &clientName)
void ServerConfigDialog::accept() void ServerConfigDialog::accept()
{ {
if (m_pCheckBoxUseExternalConfig->isChecked() && !QFile::exists(m_pEditConfigFile->text())) { if (ui->m_pCheckBoxUseExternalConfig->isChecked() && !QFile::exists(ui->m_pEditConfigFile->text())) {
auto selectedButton = QMessageBox::warning( auto selectedButton = QMessageBox::warning(
this, "Filename invalid", "Please select a valid configuration file.", QMessageBox::Ok | QMessageBox::Ignore this, "Filename invalid", "Please select a valid configuration file.", QMessageBox::Ok | QMessageBox::Ignore
@ -282,44 +285,44 @@ void ServerConfigDialog::on_m_pButtonNewHotkey_clicked()
HotkeyDialog dlg(this, hotkey); HotkeyDialog dlg(this, hotkey);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
serverConfig().hotkeys().append(hotkey); serverConfig().hotkeys().append(hotkey);
m_pListHotkeys->addItem(hotkey.text()); ui->m_pListHotkeys->addItem(hotkey.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonEditHotkey_clicked() void ServerConfigDialog::on_m_pButtonEditHotkey_clicked()
{ {
int idx = m_pListHotkeys->currentRow(); int idx = ui->m_pListHotkeys->currentRow();
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
Hotkey &hotkey = serverConfig().hotkeys()[idx]; Hotkey &hotkey = serverConfig().hotkeys()[idx];
HotkeyDialog dlg(this, hotkey); HotkeyDialog dlg(this, hotkey);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
m_pListHotkeys->currentItem()->setText(hotkey.text()); ui->m_pListHotkeys->currentItem()->setText(hotkey.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked() void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked()
{ {
int idx = m_pListHotkeys->currentRow(); int idx = ui->m_pListHotkeys->currentRow();
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
serverConfig().hotkeys().removeAt(idx); serverConfig().hotkeys().removeAt(idx);
m_pListActions->clear(); ui->m_pListActions->clear();
delete m_pListHotkeys->item(idx); delete ui->m_pListHotkeys->item(idx);
onChange(); onChange();
} }
void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged() void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged()
{ {
bool itemsSelected = !m_pListHotkeys->selectedItems().isEmpty(); bool itemsSelected = !ui->m_pListHotkeys->selectedItems().isEmpty();
m_pButtonEditHotkey->setEnabled(itemsSelected); ui->m_pButtonEditHotkey->setEnabled(itemsSelected);
m_pButtonRemoveHotkey->setEnabled(itemsSelected); ui->m_pButtonRemoveHotkey->setEnabled(itemsSelected);
m_pButtonNewAction->setEnabled(itemsSelected); ui->m_pButtonNewAction->setEnabled(itemsSelected);
if (itemsSelected && serverConfig().hotkeys().size() > 0) { if (itemsSelected && serverConfig().hotkeys().size() > 0) {
m_pListActions->clear(); ui->m_pListActions->clear();
int idx = m_pListHotkeys->row(m_pListHotkeys->selectedItems()[0]); int idx = ui->m_pListHotkeys->row(ui->m_pListHotkeys->selectedItems()[0]);
// There's a bug somewhere around here: We get idx == 1 right after we // There's a bug somewhere around here: We get idx == 1 right after we
// deleted the next to last item, so idx can only possibly be 0. GDB shows // deleted the next to last item, so idx can only possibly be 0. GDB shows
@ -334,13 +337,13 @@ void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged()
const Hotkey &hotkey = serverConfig().hotkeys()[idx]; const Hotkey &hotkey = serverConfig().hotkeys()[idx];
foreach (const Action &action, hotkey.actions()) foreach (const Action &action, hotkey.actions())
m_pListActions->addItem(action.text()); ui->m_pListActions->addItem(action.text());
} }
} }
void ServerConfigDialog::on_m_pButtonNewAction_clicked() void ServerConfigDialog::on_m_pButtonNewAction_clicked()
{ {
int idx = m_pListHotkeys->currentRow(); int idx = ui->m_pListHotkeys->currentRow();
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
Hotkey &hotkey = serverConfig().hotkeys()[idx]; Hotkey &hotkey = serverConfig().hotkeys()[idx];
@ -348,55 +351,55 @@ void ServerConfigDialog::on_m_pButtonNewAction_clicked()
ActionDialog dlg(this, serverConfig(), hotkey, action); ActionDialog dlg(this, serverConfig(), hotkey, action);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
hotkey.actions().append(action); hotkey.actions().append(action);
m_pListActions->addItem(action.text()); ui->m_pListActions->addItem(action.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonEditAction_clicked() void ServerConfigDialog::on_m_pButtonEditAction_clicked()
{ {
int idxHotkey = m_pListHotkeys->currentRow(); int idxHotkey = ui->m_pListHotkeys->currentRow();
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size()); Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey]; Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey];
int idxAction = m_pListActions->currentRow(); int idxAction = ui->m_pListActions->currentRow();
Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size());
Action &action = hotkey.actions()[idxAction]; Action &action = hotkey.actions()[idxAction];
ActionDialog dlg(this, serverConfig(), hotkey, action); ActionDialog dlg(this, serverConfig(), hotkey, action);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
m_pListActions->currentItem()->setText(action.text()); ui->m_pListActions->currentItem()->setText(action.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() void ServerConfigDialog::on_m_pButtonRemoveAction_clicked()
{ {
int idxHotkey = m_pListHotkeys->currentRow(); int idxHotkey = ui->m_pListHotkeys->currentRow();
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size()); Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey]; Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey];
int idxAction = m_pListActions->currentRow(); int idxAction = ui->m_pListActions->currentRow();
Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size());
hotkey.actions().removeAt(idxAction); hotkey.actions().removeAt(idxAction);
delete m_pListActions->currentItem(); delete ui->m_pListActions->currentItem();
onChange(); onChange();
} }
void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(int const state) void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(int const state)
{ {
m_pSpinBoxClipboardSizeLimit->setEnabled(state == Qt::Checked); ui->m_pSpinBoxClipboardSizeLimit->setEnabled(state == Qt::Checked);
if ((state == Qt::Checked) && (!m_pSpinBoxClipboardSizeLimit->value())) { if ((state == Qt::Checked) && (!ui->m_pSpinBoxClipboardSizeLimit->value())) {
int size = static_cast<int>((serverConfig().defaultClipboardSharingSize() + 512) / 1024); int size = static_cast<int>((serverConfig().defaultClipboardSharingSize() + 512) / 1024);
m_pSpinBoxClipboardSizeLimit->setValue(size ? size : 1); ui->m_pSpinBoxClipboardSizeLimit->setValue(size ? size : 1);
} }
} }
void ServerConfigDialog::on_m_pListActions_itemSelectionChanged() void ServerConfigDialog::on_m_pListActions_itemSelectionChanged()
{ {
m_pButtonEditAction->setEnabled(!m_pListActions->selectedItems().isEmpty()); ui->m_pButtonEditAction->setEnabled(!ui->m_pListActions->selectedItems().isEmpty());
m_pButtonRemoveAction->setEnabled(!m_pListActions->selectedItems().isEmpty()); ui->m_pButtonRemoveAction->setEnabled(!ui->m_pListActions->selectedItems().isEmpty());
} }
void ServerConfigDialog::on_m_pButtonAddComputer_clicked() void ServerConfigDialog::on_m_pButtonAddComputer_clicked()
@ -406,19 +409,19 @@ void ServerConfigDialog::on_m_pButtonAddComputer_clicked()
void ServerConfigDialog::onScreenRemoved() void ServerConfigDialog::onScreenRemoved()
{ {
m_pButtonAddComputer->setEnabled(true); ui->m_pButtonAddComputer->setEnabled(true);
onChange(); onChange();
} }
void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked) void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked)
{ {
m_pLabelConfigFile->setEnabled(checked); ui->m_pLabelConfigFile->setEnabled(checked);
m_pEditConfigFile->setEnabled(checked); ui->m_pEditConfigFile->setEnabled(checked);
m_pButtonBrowseConfigFile->setEnabled(checked); ui->m_pButtonBrowseConfigFile->setEnabled(checked);
m_pTabWidget->setTabEnabled(0, !checked); ui->m_pTabWidget->setTabEnabled(0, !checked);
m_pTabWidget->setTabEnabled(1, !checked); ui->m_pTabWidget->setTabEnabled(1, !checked);
m_pTabWidget->setTabEnabled(2, !checked); ui->m_pTabWidget->setTabEnabled(2, !checked);
} }
bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked() bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked()
@ -432,7 +435,7 @@ bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked()
QString fileName = QFileDialog::getOpenFileName(this, "Browse for a config file", "", deskflowConfigFilter); QString fileName = QFileDialog::getOpenFileName(this, "Browse for a config file", "", deskflowConfigFilter);
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
m_pEditConfigFile->setText(fileName); ui->m_pEditConfigFile->setText(fileName);
return true; return true;
} }
@ -450,7 +453,7 @@ bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent)
isAccepted = true; isAccepted = true;
} }
m_pButtonAddComputer->setEnabled(!model().isFull()); ui->m_pButtonAddComputer->setEnabled(!model().isFull());
return isAccepted; return isAccepted;
} }
@ -458,6 +461,6 @@ void ServerConfigDialog::onChange()
{ {
bool isAppConfigDataEqual = m_OriginalServerConfigIsExternal == serverConfig().useExternalConfig() && bool isAppConfigDataEqual = m_OriginalServerConfigIsExternal == serverConfig().useExternalConfig() &&
m_OriginalServerConfigUsesExternalFile == serverConfig().configFile(); m_OriginalServerConfigUsesExternalFile == serverConfig().configFile();
m_pButtonBox->button(QDialogButtonBox::Ok) ui->m_pButtonBox->button(QDialogButtonBox::Ok)
->setEnabled(!isAppConfigDataEqual || !(m_OriginalServerConfig == m_ServerConfig)); ->setEnabled(!isAppConfigDataEqual || !(m_OriginalServerConfig == m_ServerConfig));
} }

View file

@ -21,16 +21,20 @@
#include "ScreenSetupModel.h" #include "ScreenSetupModel.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "gui/config/AppConfig.h" #include "gui/config/AppConfig.h"
#include "ui_ServerConfigDialogBase.h"
#include <QDialog> #include <QDialog>
class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase namespace Ui {
class ServerConfigDialog;
}
class ServerConfigDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig); ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig);
~ServerConfigDialog();
bool addClient(const QString &clientName); bool addClient(const QString &clientName);
public slots: public slots:
@ -77,6 +81,7 @@ protected:
} }
private: private:
std::unique_ptr<Ui::ServerConfigDialog> ui;
ServerConfig &m_OriginalServerConfig; ServerConfig &m_OriginalServerConfig;
ServerConfig m_ServerConfig; ServerConfig m_ServerConfig;
bool m_OriginalServerConfigIsExternal; bool m_OriginalServerConfigIsExternal;

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>ServerConfigDialogBase</class> <class>ServerConfigDialog</class>
<widget class="QDialog" name="ServerConfigDialogBase"> <widget class="QDialog" name="ServerConfigDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -1181,7 +1181,7 @@ Enabling this setting will disable the server config GUI.</string>
<connection> <connection>
<sender>m_pButtonBox</sender> <sender>m_pButtonBox</sender>
<signal>accepted()</signal> <signal>accepted()</signal>
<receiver>ServerConfigDialogBase</receiver> <receiver>ServerConfigDialog</receiver>
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -1197,7 +1197,7 @@ Enabling this setting will disable the server config GUI.</string>
<connection> <connection>
<sender>m_pButtonBox</sender> <sender>m_pButtonBox</sender>
<signal>rejected()</signal> <signal>rejected()</signal>
<receiver>ServerConfigDialogBase</receiver> <receiver>ServerConfigDialog</receiver>
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">