Skip to content

Commit 55773df

Browse files
authored
Add option to lock parameters system scope (#1174)
IB-7376 Signed-off-by: Raul Metsma <[email protected]>
1 parent d65d264 commit 55773df

File tree

4 files changed

+56
-22
lines changed

4 files changed

+56
-22
lines changed

client/Settings.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ const Option<bool> Settings::MOBILEID_ORDER { QStringLiteral("MIDOrder"), true }
5555
const Option<QString> Settings::SID_UUID { QStringLiteral("SIDUUID") };
5656
const Option<QString> Settings::SID_NAME { QStringLiteral("SIDNAME"), QStringLiteral("RIA DigiDoc") };
5757
const Option<QString, QString (*)()> Settings::SID_PROXY_URL { QStringLiteral("SID-PROXY-URL"), []{
58-
return Application::confValue(QLatin1String("SIDV2-PROXY-URL")).toString(Application::confValue(QLatin1String("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL)));
58+
return Application::confValue(QLatin1String("SIDV2-PROXY-URL"))
59+
.toString(Application::confValue(QLatin1String("SID-PROXY-URL"))
60+
.toString(QStringLiteral(SMARTID_URL)));
5961
}};
6062
const Option<QString, QString (*)()> Settings::SID_SK_URL { QStringLiteral("SID-SK-URL"), []{
61-
return Application::confValue(QLatin1String("SIDV2-SK-URL")).toString(Application::confValue(QLatin1String("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL)));
63+
return Application::confValue(QLatin1String("SIDV2-SK-URL"))
64+
.toString(Application::confValue(QLatin1String("SID-SK-URL"))
65+
.toString(QStringLiteral(SMARTID_URL)));
6266
}};
6367
const Option<bool, bool (*)()> Settings::SID_UUID_CUSTOM
6468
{ QStringLiteral("SIDUUID-CUSTOM"), [] { return Settings::SID_UUID.isSet(); } };

client/Settings.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#pragma once
2121

22+
#include <QtCore/QCoreApplication>
2223
#include <QtCore/QSettings>
2324

2425
template<typename T>
@@ -30,7 +31,7 @@ struct Settings
3031
struct Option
3132
{
3233
operator QVariant() const {
33-
return QSettings().value(KEY, defaultValue());
34+
return settings().value(KEY, defaultValue());
3435
}
3536
operator T() const {
3637
return operator QVariant().template value<T>();
@@ -52,11 +53,14 @@ struct Settings
5253
void clear() const {
5354
QSettings().remove(KEY);
5455
}
56+
bool isLocked() const {
57+
return settings(QSettings::SystemScope).value(KEY + QLatin1String("_LOCK"), false).toBool();
58+
}
5559
bool isSet() const {
5660
return QSettings().contains(KEY);
5761
}
5862
T value(const QVariant &def) const {
59-
return QSettings().value(KEY, def).template value<T>();
63+
return settings().value(KEY, def).template value<T>();
6064
}
6165
void setValue(const QVariant &value, const QVariant &def = {}) const {
6266
if(bool valueIsNullOrEmpty = value.type() == QVariant::String ? value.toString().isEmpty() : value.isNull();
@@ -78,6 +82,16 @@ struct Settings
7882
{
7983
f = functor;
8084
}
85+
QSettings settings() const {
86+
return settings(isLocked() ? QSettings::SystemScope : QSettings::UserScope);
87+
}
88+
static QSettings settings(QSettings::Scope scope) {
89+
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
90+
return QSettings(scope);
91+
#else
92+
return QSettings(scope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
93+
#endif
94+
}
8195
const QString KEY;
8296
const D DEFAULT {};
8397
std::function<void (const T &value)> f;

client/dialogs/SettingsDialog.cpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
241241
// remove certificates (having %ESTEID% text) from browsing history of Internet Explorer and/or Google Chrome, and do it for all users.
242242
QList<TokenData> cache = qApp->signer()->cache();
243243
CertStore s;
244-
const QList<QSslCertificate> certificates = s.list();
245-
for(const QSslCertificate &c: certificates)
244+
for(const QSslCertificate &c: s.list())
246245
{
247246
if(std::any_of(cache.cbegin(), cache.cend(), [&](const TokenData &token) { return token.cert() == c; }))
248247
continue;
@@ -418,16 +417,21 @@ void SettingsDialog::initFunctionality()
418417
updateProxy();
419418

420419
// pageServices - TimeStamp
420+
ui->rdTimeStampDefault->setDisabled(Settings::TSA_URL_CUSTOM.isLocked());
421+
ui->rdTimeStampCustom->setEnabled(ui->rdTimeStampDefault->isEnabled());
422+
ui->rdTimeStampCustom->setChecked(Settings::TSA_URL_CUSTOM);
423+
ui->txtTimeStamp->setReadOnly(Settings::TSA_URL.isLocked());
424+
ui->txtTimeStamp->setEnabled(ui->rdTimeStampCustom->isChecked());
425+
ui->txtTimeStamp->setPlaceholderText(Application::confValue(Settings::TSA_URL.KEY).toString());
426+
QString TSA_URL = Settings::TSA_URL.value(Application::confValue(Application::TSAUrl));
427+
ui->txtTimeStamp->setText(ui->txtTimeStamp->placeholderText() == TSA_URL ? QString() : TSA_URL);
428+
ui->wgtTSACert->setDisabled(Settings::TSA_CERT.isLocked());
429+
ui->wgtTSACert->setVisible(ui->rdTimeStampCustom->isChecked());
421430
connect(ui->rdTimeStampCustom, &QRadioButton::toggled, ui->txtTimeStamp, [this](bool checked) {
422431
ui->txtTimeStamp->setEnabled(checked);
423432
ui->wgtTSACert->setVisible(checked);
424433
Settings::TSA_URL_CUSTOM = checked;
425434
});
426-
ui->rdTimeStampCustom->setChecked(Settings::TSA_URL_CUSTOM);
427-
ui->wgtTSACert->setVisible(ui->rdTimeStampCustom->isChecked());
428-
ui->txtTimeStamp->setPlaceholderText(Application::confValue(Settings::TSA_URL.KEY).toString());
429-
QString TSA_URL = Settings::TSA_URL.value(Application::confValue(Application::TSAUrl));
430-
ui->txtTimeStamp->setText(ui->txtTimeStamp->placeholderText() == TSA_URL ? QString() : TSA_URL);
431435
connect(ui->txtTimeStamp, &QLineEdit::textChanged, this, [this](const QString &url) {
432436
Application::setConfValue(Application::TSAUrl, url);
433437
if(url.isEmpty())
@@ -450,13 +454,17 @@ void SettingsDialog::initFunctionality()
450454
updateTSACert(QSslCertificate(QByteArray::fromBase64(Settings::TSA_CERT), QSsl::Der));
451455

452456
// pageServices - MID
457+
ui->rdMIDUUIDDefault->setDisabled(Settings::MID_UUID_CUSTOM.isLocked());
458+
ui->rdMIDUUIDCustom->setEnabled(ui->rdMIDUUIDDefault->isEnabled());
459+
ui->rdMIDUUIDCustom->setChecked(Settings::MID_UUID_CUSTOM);
460+
ui->txtMIDUUID->setReadOnly(Settings::MID_UUID.isLocked());
461+
ui->txtMIDUUID->setEnabled(ui->rdMIDUUIDCustom->isChecked());
462+
ui->txtMIDUUID->setText(Settings::MID_UUID);
453463
connect(ui->rdMIDUUIDCustom, &QRadioButton::toggled, ui->txtMIDUUID, [=](bool checked) {
454464
ui->txtMIDUUID->setEnabled(checked);
455465
Settings::MID_UUID_CUSTOM = checked;
456466
Settings::SID_UUID_CUSTOM = checked;
457467
});
458-
ui->rdMIDUUIDCustom->setChecked(Settings::MID_UUID_CUSTOM);
459-
ui->txtMIDUUID->setText(Settings::MID_UUID);
460468
connect(ui->txtMIDUUID, &QLineEdit::textChanged, this, [](const QString &text) {
461469
Settings::MID_UUID = text;
462470
Settings::SID_UUID = text;
@@ -466,16 +474,21 @@ void SettingsDialog::initFunctionality()
466474
});
467475

468476
// pageValidation - SiVa
477+
ui->rdSiVaDefault->setDisabled(Settings::SIVA_URL_CUSTOM.isLocked());
478+
ui->rdSiVaCustom->setEnabled(ui->rdSiVaDefault->isEnabled());
479+
ui->rdSiVaCustom->setChecked(Settings::SIVA_URL_CUSTOM);
480+
ui->txtSiVa->setReadOnly(Settings::SIVA_URL.isLocked());
481+
ui->txtSiVa->setEnabled(ui->rdSiVaCustom->isChecked());
482+
ui->txtSiVa->setPlaceholderText(Application::confValue(Settings::SIVA_URL.KEY).toString());
483+
QString SIVA_URL = Settings::SIVA_URL.value(Application::confValue(Application::SiVaUrl));
484+
ui->txtSiVa->setText(ui->txtSiVa->placeholderText() == SIVA_URL ? QString() : SIVA_URL);
485+
ui->wgtSiVaCert->setDisabled(Settings::SIVA_CERT.isLocked());
486+
ui->wgtSiVaCert->setVisible(ui->rdSiVaCustom->isChecked());
469487
connect(ui->rdSiVaCustom, &QRadioButton::toggled, ui->txtSiVa, [this](bool checked) {
470488
ui->txtSiVa->setEnabled(checked);
471489
ui->wgtSiVaCert->setVisible(checked);
472490
Settings::SIVA_URL_CUSTOM = checked;
473491
});
474-
ui->rdSiVaCustom->setChecked(Settings::SIVA_URL_CUSTOM);
475-
ui->wgtSiVaCert->setVisible(ui->rdSiVaCustom->isChecked());
476-
ui->txtSiVa->setPlaceholderText(Application::confValue(Settings::SIVA_URL.KEY).toString());
477-
QString SIVA_URL = Settings::SIVA_URL.value(Application::confValue(Application::SiVaUrl));
478-
ui->txtSiVa->setText(ui->txtSiVa->placeholderText() == SIVA_URL ? QString() : SIVA_URL);
479492
connect(ui->txtSiVa, &QLineEdit::textChanged, this, [this](const QString &url) {
480493
Application::setConfValue(Application::SiVaUrl, url);
481494
if(url.isEmpty())
@@ -689,9 +702,12 @@ void SettingsDialog::saveFile(const QString &name, const QString &path)
689702

690703
void SettingsDialog::saveFile(const QString &name, const QByteArray &content)
691704
{
692-
QString filename = FileDialog::getSaveFileName(this, tr("Save as"), QStringLiteral( "%1/%2_%3_%4")
693-
.arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), QApplication::applicationName(), QApplication::applicationVersion(), name),
694-
tr("Text files (*.txt)") );
705+
QString filename = FileDialog::getSaveFileName(this, tr("Save as"), QStringLiteral( "%1/%2_%3_%4").arg(
706+
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
707+
QApplication::applicationName(),
708+
QApplication::applicationVersion(),
709+
name),
710+
tr("Text files (*.txt)"));
695711
if( filename.isEmpty() )
696712
return;
697713
if(QFile f(filename); !f.open(QIODevice::WriteOnly|QIODevice::Text) || !f.write(content))

client/dialogs/SettingsDialog.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ QCheckBox, QRadioButton {
262262
min-height: 31px;
263263
spacing: 5px;
264264
}
265-
QCheckBox:disabled {
265+
QCheckBox:disabled, QRadioButton:disabled {
266266
color: #727679;
267267
}
268268
QCheckBox::indicator, QRadioButton::indicator {

0 commit comments

Comments
 (0)