Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,8 @@ Application::Application( int &argc, char **argv )
loadTranslation(Settings::LANGUAGE);

// Clear obsolete registriy settings
Settings::SETTINGS_MIGRATED.clear();
#ifdef Q_OS_DARWIN
Settings::TSL_ONLINE_DIGEST.clear();
#ifndef Q_OS_DARWIN
Settings::DEFAULT_DIR.clear();
#endif

// Actions
Expand Down
5 changes: 2 additions & 3 deletions client/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Application.h"

#include <QtCore/QJsonValue>
#include <QtCore/QStandardPaths>

template<class T, class D = T>
using Option = Settings::Option<T, D>;
Expand Down Expand Up @@ -97,9 +98,8 @@ const Option<QString, QString (*)()> Settings::LANGUAGE { QStringLiteral("Langua
if(languages.first().contains(QLatin1String("ru"), Qt::CaseInsensitive)) return QStringLiteral("ru");
return QStringLiteral("en");
}};
const Option<QString> Settings::LAST_PATH { QStringLiteral("lastPath") };
const Option<QString> Settings::LAST_PATH { QStringLiteral("lastPath"), QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) };
Option<bool> Settings::LIBDIGIDOCPP_DEBUG { QStringLiteral("LibdigidocppDebug"), false };
const Option<bool> Settings::SETTINGS_MIGRATED { QStringLiteral("SettingsMigrated"), false };
const Option<bool> Settings::SHOW_INTRO { QStringLiteral("showIntro"), true };
const Option<bool> Settings::SHOW_PRINT_SUMMARY { QStringLiteral("ShowPrintSummary"), false };
const Option<bool> Settings::SHOW_ROLE_ADDRESS_INFO { QStringLiteral("RoleAddressInfo"), false };
Expand All @@ -111,5 +111,4 @@ const Option<QString> Settings::PROXY_USER { QStringLiteral("ProxyUser") };
const Option<QString> Settings::PROXY_PASS { QStringLiteral("ProxyPass") };
#ifdef Q_OS_MAC
const Option<QString> Settings::PLUGINS { QStringLiteral("plugins") };
const Option<bool> Settings::TSL_ONLINE_DIGEST { QStringLiteral("TSLOnlineDigest"), true };
#endif
43 changes: 11 additions & 32 deletions client/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,33 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QSettings>

template<typename T>
using if_QString = std::enable_if_t<std::is_same_v<T,QString>, bool>;

struct Settings
{
template<class T, class D = T>
struct Option
{
operator QVariant() const {
return settings().value(KEY, defaultValue());
if(QSettings s(isLocked() ? QSettings::SystemScope : QSettings::UserScope); s.contains(KEY))
return s.value(KEY);
return defaultValue();
}
operator T() const {
return operator QVariant().template value<T>();
}
template <typename P = T, typename = if_QString<P>>
operator std::string() const {
operator std::string() const requires(std::is_same_v<T,QString>) {
return operator T().toStdString();
}
void operator =(const QVariant &value) const {
setValue(value, defaultValue());
}
void operator =(const T &value) const {
operator =(QVariant(value));
if(value == defaultValue())
clear();
else
QSettings().setValue(KEY, value);
if(f)
f(operator T());
}
void operator() (const T &value) const {
operator =(QVariant(value));
}
template <typename P = T, typename = if_QString<P>>
void operator =(const std::string &value) const {
operator =(QString::fromStdString(value));
}
void clear() const {
QSettings().remove(KEY);
}
Expand All @@ -62,18 +58,6 @@ struct Settings
bool isSet() const {
return QSettings().contains(KEY);
}
T value(const QVariant &def) const {
return settings().value(KEY, def).template value<T>();
}
void setValue(const QVariant &value, const QVariant &def = {}) const {
if(bool valueIsNullOrEmpty = value.typeId() == QMetaType::QString ? value.toString().isEmpty() : value.isNull();
value == def || (def.isNull() && valueIsNullOrEmpty))
clear();
else
QSettings().setValue(KEY, value);
if(f)
f(operator T());
}
T defaultValue() const {
if constexpr (std::is_invocable_v<D>)
return DEFAULT();
Expand All @@ -85,9 +69,6 @@ struct Settings
{
f = functor;
}
QSettings settings() const {
return QSettings(isLocked() ? QSettings::SystemScope : QSettings::UserScope);
}
const QString KEY;
const D DEFAULT {};
std::function<void (const T &value)> f {};
Expand Down Expand Up @@ -134,12 +115,11 @@ struct Settings
static const Option<QString, QString (*)()> LANGUAGE;
static const Option<QString> LAST_PATH;
static Option<bool> LIBDIGIDOCPP_DEBUG;
static const Option<bool> SETTINGS_MIGRATED;
static const Option<bool> SHOW_INTRO;
static const Option<bool> SHOW_PRINT_SUMMARY;
static const Option<bool> SHOW_ROLE_ADDRESS_INFO;

enum ProxyConfig {
enum ProxyConfig: quint8 {
ProxyNone,
ProxySystem,
ProxyManual,
Expand All @@ -151,6 +131,5 @@ struct Settings
static const Option<QString> PROXY_PASS;
#ifdef Q_OS_MAC
static const Option<QString> PLUGINS;
static const Option<bool> TSL_ONLINE_DIGEST;
#endif
};
8 changes: 2 additions & 6 deletions client/dialogs/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <QtCore/QCoreApplication>
#include <QtCore/QRegularExpression>
#include <QtCore/QStandardPaths>
#include <QtCore/QTemporaryFile>
#include <QtWidgets/QMessageBox>

Expand Down Expand Up @@ -58,10 +57,8 @@ QString FileDialog::createNewFileName(const QString &file, bool signature, QWidg
Settings::CDOC2_DEFAULT ? QStringLiteral(".cdoc2") : QStringLiteral(".cdoc");
const QString type = signature ? tr("signature container") : tr("crypto container");
QString capitalized = type[0].toUpper() + type.mid(1);
const QString defaultDir = Settings::DEFAULT_DIR;
const QFileInfo f(normalized(file));
QString dir = defaultDir.isEmpty() ? f.absolutePath() : defaultDir;
QString fileName = QDir::toNativeSeparators(dir + QDir::separator() + f.completeBaseName() + extension);
QString fileName = QDir::toNativeSeparators(f.absolutePath() + QDir::separator() + f.completeBaseName() + extension);
#ifndef Q_OS_MACOS
// macOS App Sandbox restricts the rights of the application to write to the filesystem outside of
// app sandbox; user must explicitly give permission to write data to the specific folders.
Expand Down Expand Up @@ -162,8 +159,7 @@ QString FileDialog::getDir( const QString &dir )
path.replace('~', QDir::homePath());
return path;
#else
return !dir.isEmpty() ? dir : Settings::LAST_PATH.value(
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
return !dir.isEmpty() ? dir : Settings::LAST_PATH;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/MobileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MobileDialog::MobileDialog(QWidget *parent)
ui->idCode->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->errorCode->hide();
ui->phoneNo->setValidator(new NumberValidator(ui->phoneNo));
ui->phoneNo->setText(Settings::MOBILEID_NUMBER.value(countryCodes[0]));
ui->phoneNo->setText(Settings::MOBILEID_NUMBER);
ui->phoneNo->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->phoneNo->setFocus();
ui->errorPhone->hide();
Expand Down
34 changes: 2 additions & 32 deletions client/dialogs/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,43 +91,14 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
ui->chkRoleAddressInfo->setChecked(Settings::SHOW_ROLE_ADDRESS_INFO);
connect(ui->chkRoleAddressInfo, &QCheckBox::toggled, this, Settings::SHOW_ROLE_ADDRESS_INFO);

#ifdef Q_OS_MACOS
ui->lblDefaultDirectory->hide();
ui->rdGeneralSameDirectory->hide();
ui->txtGeneralDirectory->hide();
ui->btGeneralChooseDirectory->hide();
ui->rdGeneralSpecifyDirectory->hide();
#else
connect(ui->btGeneralChooseDirectory, &QPushButton::clicked, this, [this]{
QString dir = FileDialog::getExistingDirectory(this, tr("Select folder"), Settings::DEFAULT_DIR);
if(!dir.isEmpty())
{
ui->rdGeneralSpecifyDirectory->setChecked(true);
Settings::DEFAULT_DIR = dir;
ui->txtGeneralDirectory->setText(dir);
}
});
connect(ui->rdGeneralSpecifyDirectory, &QRadioButton::toggled, this, [this](bool enable) {
ui->btGeneralChooseDirectory->setVisible(enable);
ui->txtGeneralDirectory->setVisible(enable);
if(!enable)
ui->txtGeneralDirectory->clear();
});
ui->txtGeneralDirectory->setText(Settings::DEFAULT_DIR);
if(ui->txtGeneralDirectory->text().isEmpty())
ui->rdGeneralSameDirectory->setChecked(true);
connect(ui->txtGeneralDirectory, &QLineEdit::textChanged, this, Settings::DEFAULT_DIR);
#endif

// 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->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() : std::move(TSA_URL));
ui->txtTimeStamp->setText(Settings::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) {
Expand Down Expand Up @@ -183,8 +154,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
ui->txtSiVa->setReadOnly(Settings::SIVA_URL.isLocked());
ui->txtSiVa->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() : std::move(SIVA_URL));
ui->txtSiVa->setText(Settings::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) {
Expand Down
53 changes: 1 addition & 52 deletions client/dialogs/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ max-height: 22px;
}</string>
</property>
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<widget class="QWidget" name="pageGeneral">
<layout class="QVBoxLayout" name="pageGeneralLayout">
Expand Down Expand Up @@ -568,56 +568,6 @@ max-height: 22px;
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblDefaultDirectory">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="text">
<string>Container default location</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="locationBoxLayout">
<property name="spacing">
<number>15</number>
</property>
<item row="0" column="0">
<widget class="QRadioButton" name="rdGeneralSameDirectory">
<property name="text">
<string>Same folder</string>
</property>
<attribute name="buttonGroup">
<string notr="true">pathGroup</string>
</attribute>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rdGeneralSpecifyDirectory">
<property name="text">
<string>Select the default directory</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">pathGroup</string>
</attribute>
</widget>
</item>
<item row="0" column="1" rowspan="2">
<widget class="QPushButton" name="btGeneralChooseDirectory">
<property name="text">
<string notr="true">...</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<widget class="QLineEdit" name="txtGeneralDirectory"/>
</item>
</layout>
</item>
<item>
<spacer name="pageGeneralSpacer">
<property name="orientation">
Expand Down Expand Up @@ -1798,7 +1748,6 @@ p, li { white-space: pre-wrap; margin-top:12px; margin-bottom:12px; margin-left:
</resources>
<connections/>
<buttongroups>
<buttongroup name="pathGroup"/>
<buttongroup name="pageGroup"/>
<buttongroup name="rdSiVa"/>
<buttongroup name="langGroup"/>
Expand Down
16 changes: 0 additions & 16 deletions client/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2174,18 +2174,6 @@ ID-Card</translation>
<source>Language</source>
<translation>Language</translation>
</message>
<message>
<source>Container default location</source>
<translation>Container default location</translation>
</message>
<message>
<source>Same folder</source>
<translation>Same folder</translation>
</message>
<message>
<source>Select the default directory</source>
<translation>Select the default directory</translation>
</message>
<message>
<source>Show print summary</source>
<translation>Show print summary</translation>
Expand Down Expand Up @@ -2258,10 +2246,6 @@ Additional licenses and components</source>
In case of questions please contact our support via &lt;a href=&quot;https://www.id.ee/en/id-help/&quot;&gt;id.ee&lt;/a&gt;.&lt;/p&gt;
Additional licenses and components</translation>
</message>
<message>
<source>Select folder</source>
<translation>Select folder</translation>
</message>
<message>
<source>Save as</source>
<translation>Save as</translation>
Expand Down
16 changes: 0 additions & 16 deletions client/translations/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2174,18 +2174,6 @@ ID-kaardiga</translation>
<source>Language</source>
<translation>Keel</translation>
</message>
<message>
<source>Container default location</source>
<translation>Ümbriku loomise vaikekataloog</translation>
</message>
<message>
<source>Same folder</source>
<translation>Samasse kataloogi</translation>
</message>
<message>
<source>Select the default directory</source>
<translation>Vali vaikimisi kataloog</translation>
</message>
<message>
<source>Show print summary</source>
<translation>Näita kinnituslehte</translation>
Expand Down Expand Up @@ -2258,10 +2246,6 @@ Additional licenses and components</source>
Küsimuste korral võta ühendust &lt;a href=&quot;https://www.id.ee/id-abikeskus/&quot;&gt;ID-abikeskusega/a&gt;.&lt;/p&gt;
Täiendavad litsentsid ja komponendid</translation>
</message>
<message>
<source>Select folder</source>
<translation>Vali kataloog</translation>
</message>
<message>
<source>Save as</source>
<translation>Salvesta</translation>
Expand Down
16 changes: 0 additions & 16 deletions client/translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2175,18 +2175,6 @@ ID-картой</translation>
<source>Language</source>
<translation>Язык</translation>
</message>
<message>
<source>Container default location</source>
<translation>Расположение контейнера по умолчанию</translation>
</message>
<message>
<source>Same folder</source>
<translation>Та же папка</translation>
</message>
<message>
<source>Select the default directory</source>
<translation>Выберите каталог</translation>
</message>
<message>
<source>Show print summary</source>
<translation>Показать подтверждающий лист</translation>
Expand Down Expand Up @@ -2259,10 +2247,6 @@ Additional licenses and components</source>
Если у вас возникнут вопросы, пожалуйста, обратитесь на &lt;a href=&quot;https://www.id.ee/ru/id-pomoshh/&quot;&gt;id.ee&lt;/a&gt;.&lt;/p&gt;
Дополнительные лицензии и компоненты</translation>
</message>
<message>
<source>Select folder</source>
<translation>Выбрать каталог</translation>
</message>
<message>
<source>Save as</source>
<translation>Cохранить</translation>
Expand Down
Loading