From 55773df02192d93af2b8b57459f3d8a8ca930e2c Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Wed, 25 Oct 2023 10:34:36 +0300 Subject: [PATCH] Add option to lock parameters system scope (#1174) IB-7376 Signed-off-by: Raul Metsma --- client/Settings.cpp | 8 +++-- client/Settings.h | 18 +++++++++-- client/dialogs/SettingsDialog.cpp | 50 ++++++++++++++++++++----------- client/dialogs/SettingsDialog.ui | 2 +- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/client/Settings.cpp b/client/Settings.cpp index d6c778ab9..1423d0fc8 100644 --- a/client/Settings.cpp +++ b/client/Settings.cpp @@ -55,10 +55,14 @@ const Option Settings::MOBILEID_ORDER { QStringLiteral("MIDOrder"), true } const Option Settings::SID_UUID { QStringLiteral("SIDUUID") }; const Option Settings::SID_NAME { QStringLiteral("SIDNAME"), QStringLiteral("RIA DigiDoc") }; const Option Settings::SID_PROXY_URL { QStringLiteral("SID-PROXY-URL"), []{ - return Application::confValue(QLatin1String("SIDV2-PROXY-URL")).toString(Application::confValue(QLatin1String("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL))); + return Application::confValue(QLatin1String("SIDV2-PROXY-URL")) + .toString(Application::confValue(QLatin1String("SID-PROXY-URL")) + .toString(QStringLiteral(SMARTID_URL))); }}; const Option Settings::SID_SK_URL { QStringLiteral("SID-SK-URL"), []{ - return Application::confValue(QLatin1String("SIDV2-SK-URL")).toString(Application::confValue(QLatin1String("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL))); + return Application::confValue(QLatin1String("SIDV2-SK-URL")) + .toString(Application::confValue(QLatin1String("SID-SK-URL")) + .toString(QStringLiteral(SMARTID_URL))); }}; const Option Settings::SID_UUID_CUSTOM { QStringLiteral("SIDUUID-CUSTOM"), [] { return Settings::SID_UUID.isSet(); } }; diff --git a/client/Settings.h b/client/Settings.h index c6f66330d..c0a40327f 100644 --- a/client/Settings.h +++ b/client/Settings.h @@ -19,6 +19,7 @@ #pragma once +#include #include template @@ -30,7 +31,7 @@ struct Settings struct Option { operator QVariant() const { - return QSettings().value(KEY, defaultValue()); + return settings().value(KEY, defaultValue()); } operator T() const { return operator QVariant().template value(); @@ -52,11 +53,14 @@ struct Settings void clear() const { QSettings().remove(KEY); } + bool isLocked() const { + return settings(QSettings::SystemScope).value(KEY + QLatin1String("_LOCK"), false).toBool(); + } bool isSet() const { return QSettings().contains(KEY); } T value(const QVariant &def) const { - return QSettings().value(KEY, def).template value(); + return settings().value(KEY, def).template value(); } void setValue(const QVariant &value, const QVariant &def = {}) const { if(bool valueIsNullOrEmpty = value.type() == QVariant::String ? value.toString().isEmpty() : value.isNull(); @@ -78,6 +82,16 @@ struct Settings { f = functor; } + QSettings settings() const { + return settings(isLocked() ? QSettings::SystemScope : QSettings::UserScope); + } + static QSettings settings(QSettings::Scope scope) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) + return QSettings(scope); +#else + return QSettings(scope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); +#endif + } const QString KEY; const D DEFAULT {}; std::function f; diff --git a/client/dialogs/SettingsDialog.cpp b/client/dialogs/SettingsDialog.cpp index 17ef5262d..b07b9a0c5 100644 --- a/client/dialogs/SettingsDialog.cpp +++ b/client/dialogs/SettingsDialog.cpp @@ -241,8 +241,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent) // remove certificates (having %ESTEID% text) from browsing history of Internet Explorer and/or Google Chrome, and do it for all users. QList cache = qApp->signer()->cache(); CertStore s; - const QList certificates = s.list(); - for(const QSslCertificate &c: certificates) + for(const QSslCertificate &c: s.list()) { if(std::any_of(cache.cbegin(), cache.cend(), [&](const TokenData &token) { return token.cert() == c; })) continue; @@ -418,16 +417,21 @@ void SettingsDialog::initFunctionality() updateProxy(); // pageServices - TimeStamp + ui->rdTimeStampDefault->setDisabled(Settings::TSA_URL_CUSTOM.isLocked()); + ui->rdTimeStampCustom->setEnabled(ui->rdTimeStampDefault->isEnabled()); + ui->rdTimeStampCustom->setChecked(Settings::TSA_URL_CUSTOM); + ui->txtTimeStamp->setReadOnly(Settings::TSA_URL.isLocked()); + ui->txtTimeStamp->setEnabled(ui->rdTimeStampCustom->isChecked()); + ui->txtTimeStamp->setPlaceholderText(Application::confValue(Settings::TSA_URL.KEY).toString()); + QString TSA_URL = Settings::TSA_URL.value(Application::confValue(Application::TSAUrl)); + ui->txtTimeStamp->setText(ui->txtTimeStamp->placeholderText() == TSA_URL ? QString() : TSA_URL); + ui->wgtTSACert->setDisabled(Settings::TSA_CERT.isLocked()); + ui->wgtTSACert->setVisible(ui->rdTimeStampCustom->isChecked()); connect(ui->rdTimeStampCustom, &QRadioButton::toggled, ui->txtTimeStamp, [this](bool checked) { ui->txtTimeStamp->setEnabled(checked); ui->wgtTSACert->setVisible(checked); Settings::TSA_URL_CUSTOM = checked; }); - ui->rdTimeStampCustom->setChecked(Settings::TSA_URL_CUSTOM); - ui->wgtTSACert->setVisible(ui->rdTimeStampCustom->isChecked()); - ui->txtTimeStamp->setPlaceholderText(Application::confValue(Settings::TSA_URL.KEY).toString()); - QString TSA_URL = Settings::TSA_URL.value(Application::confValue(Application::TSAUrl)); - ui->txtTimeStamp->setText(ui->txtTimeStamp->placeholderText() == TSA_URL ? QString() : TSA_URL); connect(ui->txtTimeStamp, &QLineEdit::textChanged, this, [this](const QString &url) { Application::setConfValue(Application::TSAUrl, url); if(url.isEmpty()) @@ -450,13 +454,17 @@ void SettingsDialog::initFunctionality() updateTSACert(QSslCertificate(QByteArray::fromBase64(Settings::TSA_CERT), QSsl::Der)); // pageServices - MID + ui->rdMIDUUIDDefault->setDisabled(Settings::MID_UUID_CUSTOM.isLocked()); + ui->rdMIDUUIDCustom->setEnabled(ui->rdMIDUUIDDefault->isEnabled()); + ui->rdMIDUUIDCustom->setChecked(Settings::MID_UUID_CUSTOM); + ui->txtMIDUUID->setReadOnly(Settings::MID_UUID.isLocked()); + ui->txtMIDUUID->setEnabled(ui->rdMIDUUIDCustom->isChecked()); + ui->txtMIDUUID->setText(Settings::MID_UUID); connect(ui->rdMIDUUIDCustom, &QRadioButton::toggled, ui->txtMIDUUID, [=](bool checked) { ui->txtMIDUUID->setEnabled(checked); Settings::MID_UUID_CUSTOM = checked; Settings::SID_UUID_CUSTOM = checked; }); - ui->rdMIDUUIDCustom->setChecked(Settings::MID_UUID_CUSTOM); - ui->txtMIDUUID->setText(Settings::MID_UUID); connect(ui->txtMIDUUID, &QLineEdit::textChanged, this, [](const QString &text) { Settings::MID_UUID = text; Settings::SID_UUID = text; @@ -466,16 +474,21 @@ void SettingsDialog::initFunctionality() }); // pageValidation - SiVa + ui->rdSiVaDefault->setDisabled(Settings::SIVA_URL_CUSTOM.isLocked()); + ui->rdSiVaCustom->setEnabled(ui->rdSiVaDefault->isEnabled()); + ui->rdSiVaCustom->setChecked(Settings::SIVA_URL_CUSTOM); + ui->txtSiVa->setReadOnly(Settings::SIVA_URL.isLocked()); + ui->txtSiVa->setEnabled(ui->rdSiVaCustom->isChecked()); + ui->txtSiVa->setPlaceholderText(Application::confValue(Settings::SIVA_URL.KEY).toString()); + QString SIVA_URL = Settings::SIVA_URL.value(Application::confValue(Application::SiVaUrl)); + ui->txtSiVa->setText(ui->txtSiVa->placeholderText() == SIVA_URL ? QString() : SIVA_URL); + ui->wgtSiVaCert->setDisabled(Settings::SIVA_CERT.isLocked()); + ui->wgtSiVaCert->setVisible(ui->rdSiVaCustom->isChecked()); connect(ui->rdSiVaCustom, &QRadioButton::toggled, ui->txtSiVa, [this](bool checked) { ui->txtSiVa->setEnabled(checked); ui->wgtSiVaCert->setVisible(checked); Settings::SIVA_URL_CUSTOM = checked; }); - ui->rdSiVaCustom->setChecked(Settings::SIVA_URL_CUSTOM); - ui->wgtSiVaCert->setVisible(ui->rdSiVaCustom->isChecked()); - ui->txtSiVa->setPlaceholderText(Application::confValue(Settings::SIVA_URL.KEY).toString()); - QString SIVA_URL = Settings::SIVA_URL.value(Application::confValue(Application::SiVaUrl)); - ui->txtSiVa->setText(ui->txtSiVa->placeholderText() == SIVA_URL ? QString() : SIVA_URL); connect(ui->txtSiVa, &QLineEdit::textChanged, this, [this](const QString &url) { Application::setConfValue(Application::SiVaUrl, url); if(url.isEmpty()) @@ -689,9 +702,12 @@ void SettingsDialog::saveFile(const QString &name, const QString &path) void SettingsDialog::saveFile(const QString &name, const QByteArray &content) { - QString filename = FileDialog::getSaveFileName(this, tr("Save as"), QStringLiteral( "%1/%2_%3_%4") - .arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), QApplication::applicationName(), QApplication::applicationVersion(), name), - tr("Text files (*.txt)") ); + QString filename = FileDialog::getSaveFileName(this, tr("Save as"), QStringLiteral( "%1/%2_%3_%4").arg( + QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), + QApplication::applicationName(), + QApplication::applicationVersion(), + name), + tr("Text files (*.txt)")); if( filename.isEmpty() ) return; if(QFile f(filename); !f.open(QIODevice::WriteOnly|QIODevice::Text) || !f.write(content)) diff --git a/client/dialogs/SettingsDialog.ui b/client/dialogs/SettingsDialog.ui index 042b20326..2c16c0215 100644 --- a/client/dialogs/SettingsDialog.ui +++ b/client/dialogs/SettingsDialog.ui @@ -262,7 +262,7 @@ QCheckBox, QRadioButton { min-height: 31px; spacing: 5px; } -QCheckBox:disabled { +QCheckBox:disabled, QRadioButton:disabled { color: #727679; } QCheckBox::indicator, QRadioButton::indicator {