refactor(ServerConfigDialog): add new init connections method to centeralize all connections

This commit is contained in:
sithlord48 2026-06-10 21:08:52 -04:00 committed by Nick Bolton
parent 493e2f374c
commit c66c356665
2 changed files with 60 additions and 77 deletions

View file

@ -37,94 +37,19 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config)
loadFromConfig();
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ServerConfigDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ServerConfigDialog::reject);
ui->lblRemoveScreen->setPixmap(QIcon::fromTheme("user-trash").pixmap(QSize(64, 64)));
connect(ui->lblRemoveScreen, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved);
ui->lblNewScreen->setEnabled(!model().isFull());
ui->lblNewScreen->setPixmap(QIcon::fromTheme("video-display").pixmap(QSize(64, 64)));
connect(ui->btnNewHotkey, &QPushButton::clicked, this, &ServerConfigDialog::addHotkey);
connect(ui->btnEditHotkey, &QPushButton::clicked, this, &ServerConfigDialog::editHotkey);
connect(ui->btnRemoveHotkey, &QPushButton::clicked, this, &ServerConfigDialog::removeHotkey);
connect(ui->listHotkeys, &QListView::doubleClicked, this, &ServerConfigDialog::editHotkey);
connect(
ui->listHotkeys->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ServerConfigDialog::listHotkeysSelectionChanged
);
connect(ui->btnNewAction, &QPushButton::clicked, this, &ServerConfigDialog::addAction);
connect(ui->btnEditAction, &QPushButton::clicked, this, &ServerConfigDialog::editAction);
connect(ui->btnRemoveAction, &QPushButton::clicked, this, &ServerConfigDialog::removeAction);
connect(ui->listActions, &QListView::doubleClicked, this, &ServerConfigDialog::editAction);
connect(
ui->listActions->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ServerConfigDialog::listActionsSelectionChanged
);
ui->btnBrowseConfigFile->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen));
// 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.
ui->tabWidget->setCurrentIndex(0);
ui->btnBrowseConfigFile->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen));
connect(ui->rbProtocolBarrier, &QRadioButton::toggled, this, &ServerConfigDialog::toggleProtocol);
connect(ui->cbHeartbeat, &QCheckBox::toggled, this, &ServerConfigDialog::toggleHeartbeat);
connect(ui->sbHeartbeat, QOverload<int>::of(&QSpinBox::valueChanged), this, &ServerConfigDialog::setHeartbeat);
if (!deskflow::platform::isWindows())
ui->cbWin32KeepForeground->setVisible(false);
connect(ui->cbWin32KeepForeground, &QCheckBox::toggled, this, &ServerConfigDialog::toggleWin32Foreground);
connect(ui->cbSwitchDelay, &QCheckBox::toggled, this, &ServerConfigDialog::toggleSwitchDelay);
connect(ui->sbSwitchDelay, QOverload<int>::of(&QSpinBox::valueChanged), this, &ServerConfigDialog::setSwitchDelay);
connect(ui->cbSwitchDoubleTap, &QCheckBox::toggled, this, &ServerConfigDialog::toggleSwitchDoubleTap);
connect(
ui->sbSwitchDoubleTap, QOverload<int>::of(&QSpinBox::valueChanged), this, &ServerConfigDialog::setSwitchDoubleTap
);
connect(ui->cbRelativeMouseMoves, &QCheckBox::toggled, this, &ServerConfigDialog::toggleRelativeMouseMoves);
connect(ui->cbEnableClipboard, &QCheckBox::toggled, this, &ServerConfigDialog::toggleClipboard);
connect(ui->btnBrowseConfigFile, &QPushButton::clicked, this, &ServerConfigDialog::browseConfigFile);
connect(ui->groupExternalConfig, &QGroupBox::toggled, this, &ServerConfigDialog::toggleExternalConfig);
connect(
ui->sbSwitchCornerSize, QOverload<int>::of(&QSpinBox::valueChanged), this,
&ServerConfigDialog::setSwitchCornerSize
);
connect(
ui->sbClipboardSizeLimit, QOverload<int>::of(&QSpinBox::valueChanged), this,
&ServerConfigDialog::setClipboardLimit
);
connect(ui->cbCornerTopLeft, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerTopLeft);
connect(ui->cbCornerTopRight, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerTopRight);
connect(ui->cbCornerBottomLeft, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerBottomLeft);
connect(ui->cbCornerBottomRight, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerBottomRight);
connect(
ui->cbDefaultLockToScreenState, &QCheckBox::toggled, this, &ServerConfigDialog::toggleDefaultLockToScreenState
);
connect(ui->cbDisableLockToScreen, &QCheckBox::toggled, this, &ServerConfigDialog::toggleLockToScreen);
initConnections();
onChange();
// computers
connect(&m_screenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange);
}
ServerConfigDialog::~ServerConfigDialog() = default;
@ -503,6 +428,63 @@ void ServerConfigDialog::loadFromConfig()
}
}
void ServerConfigDialog::initConnections()
{
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ServerConfigDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ServerConfigDialog::reject);
connect(ui->lblRemoveScreen, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved);
connect(ui->btnNewHotkey, &QPushButton::clicked, this, &ServerConfigDialog::addHotkey);
connect(ui->btnEditHotkey, &QPushButton::clicked, this, &ServerConfigDialog::editHotkey);
connect(ui->btnRemoveHotkey, &QPushButton::clicked, this, &ServerConfigDialog::removeHotkey);
connect(ui->listHotkeys, &QListView::doubleClicked, this, &ServerConfigDialog::editHotkey);
connect(
ui->listHotkeys->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ServerConfigDialog::listHotkeysSelectionChanged
);
connect(ui->btnNewAction, &QPushButton::clicked, this, &ServerConfigDialog::addAction);
connect(ui->btnEditAction, &QPushButton::clicked, this, &ServerConfigDialog::editAction);
connect(ui->btnRemoveAction, &QPushButton::clicked, this, &ServerConfigDialog::removeAction);
connect(ui->listActions, &QListView::doubleClicked, this, &ServerConfigDialog::editAction);
connect(
ui->listActions->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ServerConfigDialog::listActionsSelectionChanged
);
connect(ui->rbProtocolBarrier, &QRadioButton::toggled, this, &ServerConfigDialog::toggleProtocol);
connect(ui->cbHeartbeat, &QCheckBox::toggled, this, &ServerConfigDialog::toggleHeartbeat);
connect(ui->sbHeartbeat, QOverload<int>::of(&QSpinBox::valueChanged), this, &ServerConfigDialog::setHeartbeat);
connect(ui->cbWin32KeepForeground, &QCheckBox::toggled, this, &ServerConfigDialog::toggleWin32Foreground);
connect(ui->cbSwitchDelay, &QCheckBox::toggled, this, &ServerConfigDialog::toggleSwitchDelay);
connect(ui->sbSwitchDelay, QOverload<int>::of(&QSpinBox::valueChanged), this, &ServerConfigDialog::setSwitchDelay);
connect(ui->cbSwitchDoubleTap, &QCheckBox::toggled, this, &ServerConfigDialog::toggleSwitchDoubleTap);
connect(
ui->sbSwitchDoubleTap, QOverload<int>::of(&QSpinBox::valueChanged), this, &ServerConfigDialog::setSwitchDoubleTap
);
connect(ui->cbRelativeMouseMoves, &QCheckBox::toggled, this, &ServerConfigDialog::toggleRelativeMouseMoves);
connect(ui->cbEnableClipboard, &QCheckBox::toggled, this, &ServerConfigDialog::toggleClipboard);
connect(ui->btnBrowseConfigFile, &QPushButton::clicked, this, &ServerConfigDialog::browseConfigFile);
connect(ui->groupExternalConfig, &QGroupBox::toggled, this, &ServerConfigDialog::toggleExternalConfig);
connect(
ui->sbSwitchCornerSize, QOverload<int>::of(&QSpinBox::valueChanged), this,
&ServerConfigDialog::setSwitchCornerSize
);
connect(
ui->sbClipboardSizeLimit, QOverload<int>::of(&QSpinBox::valueChanged), this,
&ServerConfigDialog::setClipboardLimit
);
connect(ui->cbCornerTopLeft, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerTopLeft);
connect(ui->cbCornerTopRight, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerTopRight);
connect(ui->cbCornerBottomLeft, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerBottomLeft);
connect(ui->cbCornerBottomRight, &QCheckBox::toggled, this, &ServerConfigDialog::toggleCornerBottomRight);
connect(
ui->cbDefaultLockToScreenState, &QCheckBox::toggled, this, &ServerConfigDialog::toggleDefaultLockToScreenState
);
connect(ui->cbDisableLockToScreen, &QCheckBox::toggled, this, &ServerConfigDialog::toggleLockToScreen);
connect(&m_screenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange);
}
bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent)
{
bool isAccepted = false;

View file

@ -97,6 +97,7 @@ protected:
private:
void loadFromConfig();
void initConnections();
std::unique_ptr<Ui::ServerConfigDialog> ui;
QString m_message = "";
int m_columns;