refactor: settingsdialog, remove autoconnect slots
This commit is contained in:
parent
2d04e0be4d
commit
63744ddbd6
2 changed files with 50 additions and 65 deletions
|
|
@ -36,9 +36,6 @@ SettingsDialog::SettingsDialog(
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
|
|
||||||
|
|
||||||
ui->m_pComboBoxTlsKeyLength->setItemIcon(0, QIcon::fromTheme(QIcon::ThemeIcon::SecurityLow));
|
ui->m_pComboBoxTlsKeyLength->setItemIcon(0, QIcon::fromTheme(QIcon::ThemeIcon::SecurityLow));
|
||||||
ui->m_pComboBoxTlsKeyLength->setItemIcon(1, QIcon::fromTheme(QStringLiteral("security-medium")));
|
ui->m_pComboBoxTlsKeyLength->setItemIcon(1, QIcon::fromTheme(QStringLiteral("security-medium")));
|
||||||
ui->m_pComboBoxTlsKeyLength->setItemIcon(2, QIcon::fromTheme(QIcon::ThemeIcon::SecurityHigh));
|
ui->m_pComboBoxTlsKeyLength->setItemIcon(2, QIcon::fromTheme(QIcon::ThemeIcon::SecurityHigh));
|
||||||
|
|
@ -59,66 +56,40 @@ SettingsDialog::SettingsDialog(
|
||||||
m_wasOriginallySystemScope = m_appConfig.isActiveScopeSystem();
|
m_wasOriginallySystemScope = m_appConfig.isActiveScopeSystem();
|
||||||
updateControls();
|
updateControls();
|
||||||
|
|
||||||
connect(ui->m_pCheckBoxEnableTls, &QCheckBox::toggled, this, &SettingsDialog::updateTlsControlsEnabled);
|
|
||||||
|
|
||||||
connect(
|
|
||||||
this, &SettingsDialog::shown, this,
|
|
||||||
[this] {
|
|
||||||
if (!m_appConfig.isActiveScopeWritable()) {
|
|
||||||
showReadOnlyMessage();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Qt::QueuedConnection
|
|
||||||
);
|
|
||||||
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
setFixedHeight(height());
|
setFixedHeight(height());
|
||||||
setWindowFlags((windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMinMaxButtonsHint);
|
setWindowFlags((windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMinMaxButtonsHint);
|
||||||
|
|
||||||
|
initConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
void SettingsDialog::initConnections()
|
||||||
// Auto-connect slots
|
|
||||||
//
|
|
||||||
|
|
||||||
void SettingsDialog::on_m_pCheckBoxLogToFile_stateChanged(int i)
|
|
||||||
{
|
{
|
||||||
bool checked = i == 2;
|
connect(this, &SettingsDialog::shown, this, &SettingsDialog::showReadOnlyMessage, Qt::QueuedConnection);
|
||||||
|
|
||||||
ui->m_pLabelLogPath->setEnabled(checked);
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
|
||||||
ui->m_pLineEditLogFilename->setEnabled(checked);
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
|
||||||
ui->m_pButtonBrowseLog->setEnabled(checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::on_m_pButtonBrowseLog_clicked()
|
connect(ui->m_pCheckBoxEnableTls, &QCheckBox::toggled, this, &SettingsDialog::updateTlsControlsEnabled);
|
||||||
{
|
connect(ui->m_pCheckBoxServiceEnabled, &QCheckBox::toggled, this, &SettingsDialog::updateControls);
|
||||||
QString fileName = QFileDialog::getSaveFileName(
|
connect(ui->m_pPushButtonTlsRegenCert, &QPushButton::clicked, this, &SettingsDialog::regenCertificates);
|
||||||
this, tr("Save log file to..."), ui->m_pLineEditLogFilename->text(), "Logs (*.log *.txt)"
|
connect(ui->m_pPushButtonTlsCertPath, &QPushButton::clicked, this, &SettingsDialog::browseCertificatePath);
|
||||||
);
|
connect(ui->m_pButtonBrowseLog, &QPushButton::clicked, this, &SettingsDialog::browseLogPath);
|
||||||
|
connect(ui->m_pCheckBoxLogToFile, &QCheckBox::toggled, this, &SettingsDialog::setLogToFile);
|
||||||
|
|
||||||
if (!fileName.isEmpty()) {
|
|
||||||
ui->m_pLineEditLogFilename->setText(fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::on_m_pCheckBoxEnableTls_clicked(bool)
|
|
||||||
{
|
|
||||||
updateTlsControlsEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::on_m_pRadioSystemScope_toggled(bool checked)
|
|
||||||
{
|
|
||||||
// We only need to test the System scoped Radio as they are connected
|
// We only need to test the System scoped Radio as they are connected
|
||||||
m_appConfig.setLoadFromSystemScope(checked);
|
connect(ui->m_pRadioSystemScope, &QRadioButton::toggled, this, &SettingsDialog::setSystemScope);
|
||||||
loadFromConfig();
|
}
|
||||||
updateControls();
|
|
||||||
|
|
||||||
if (isVisible() && !m_appConfig.isActiveScopeWritable()) {
|
void SettingsDialog::regenCertificates()
|
||||||
showReadOnlyMessage();
|
{
|
||||||
|
if (m_tlsUtility.generateCertificate()) {
|
||||||
|
QMessageBox::information(this, tr("TLS Certificate Regenerated"), tr("TLS certificate regenerated successfully."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::on_m_pPushButtonTlsCertPath_clicked()
|
void SettingsDialog::browseCertificatePath()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getSaveFileName(
|
QString fileName = QFileDialog::getSaveFileName(
|
||||||
this, tr("Select a TLS certificate to use..."), ui->m_pLineEditTlsCertPath->text(), "Cert (*.pem)", nullptr,
|
this, tr("Select a TLS certificate to use..."), ui->m_pLineEditTlsCertPath->text(), "Cert (*.pem)", nullptr,
|
||||||
|
|
@ -136,21 +107,34 @@ void SettingsDialog::on_m_pPushButtonTlsCertPath_clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::on_m_pPushButtonTlsRegenCert_clicked()
|
void SettingsDialog::browseLogPath()
|
||||||
{
|
{
|
||||||
if (m_tlsUtility.generateCertificate()) {
|
QString fileName = QFileDialog::getSaveFileName(
|
||||||
QMessageBox::information(this, tr("TLS Certificate Regenerated"), tr("TLS certificate regenerated successfully."));
|
this, tr("Save log file to..."), ui->m_pLineEditLogFilename->text(), "Logs (*.log *.txt)"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!fileName.isEmpty()) {
|
||||||
|
ui->m_pLineEditLogFilename->setText(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::on_m_pCheckBoxServiceEnabled_toggled(bool)
|
void SettingsDialog::setLogToFile(bool logToFile)
|
||||||
{
|
{
|
||||||
updateControls();
|
ui->m_pLabelLogPath->setEnabled(logToFile);
|
||||||
|
ui->m_pLineEditLogFilename->setEnabled(logToFile);
|
||||||
|
ui->m_pButtonBrowseLog->setEnabled(logToFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
void SettingsDialog::setSystemScope(bool systemScope)
|
||||||
// End of auto-connect slots
|
{
|
||||||
//
|
m_appConfig.setLoadFromSystemScope(systemScope);
|
||||||
|
loadFromConfig();
|
||||||
|
updateControls();
|
||||||
|
|
||||||
|
if (isVisible() && !m_appConfig.isActiveScopeWritable()) {
|
||||||
|
showReadOnlyMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsDialog::showEvent(QShowEvent *event)
|
void SettingsDialog::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
|
|
@ -160,6 +144,8 @@ void SettingsDialog::showEvent(QShowEvent *event)
|
||||||
|
|
||||||
void SettingsDialog::showReadOnlyMessage()
|
void SettingsDialog::showReadOnlyMessage()
|
||||||
{
|
{
|
||||||
|
if (m_appConfig.isActiveScopeWritable())
|
||||||
|
return;
|
||||||
const auto activeScopeFilename = m_appConfig.scopes().activeFilePath();
|
const auto activeScopeFilename = m_appConfig.scopes().activeFilePath();
|
||||||
messages::showReadOnlySettings(this, activeScopeFilename);
|
messages::showReadOnlySettings(this, activeScopeFilename);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,16 +36,15 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void shown();
|
void shown();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void on_m_pCheckBoxEnableTls_clicked(bool checked);
|
|
||||||
void on_m_pCheckBoxLogToFile_stateChanged(int);
|
|
||||||
void on_m_pButtonBrowseLog_clicked();
|
|
||||||
void on_m_pRadioSystemScope_toggled(bool checked);
|
|
||||||
void on_m_pPushButtonTlsCertPath_clicked();
|
|
||||||
void on_m_pPushButtonTlsRegenCert_clicked();
|
|
||||||
void on_m_pCheckBoxServiceEnabled_toggled(bool checked);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initConnections();
|
||||||
|
|
||||||
|
void regenCertificates();
|
||||||
|
void browseCertificatePath();
|
||||||
|
void browseLogPath();
|
||||||
|
void setLogToFile(bool logToFile);
|
||||||
|
void setSystemScope(bool systemScope);
|
||||||
|
|
||||||
void accept() override;
|
void accept() override;
|
||||||
void reject() override;
|
void reject() override;
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue