Skip to content

Commit

Permalink
Deduplicate code and block update dialog
Browse files Browse the repository at this point in the history
IB-7831

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Sep 29, 2023
1 parent f2493e2 commit 7207b88
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
46 changes: 26 additions & 20 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ Application::Application( int &argc, char **argv )
QTimer::singleShot(0, this, [this] {
auto lessThanVersion = [](QLatin1String key) {
return QVersionNumber::fromString(applicationVersion()) <
QVersionNumber::fromString(confValue(key).toString());
QVersionNumber::fromString(confValue(key).toString());
};
WarningDialog *dlg{};
if(lessThanVersion(QLatin1String("QDIGIDOC4-UNSUPPORTED")))
Expand All @@ -347,13 +347,13 @@ Application::Application( int &argc, char **argv )
"macOS users can download the latest ID-software version from the "
"<a href=\"https://itunes.apple.com/ee/developer/ria/id556524921?mt=12\">Mac App Store</a>."));
}
connect(d->conf, &Configuration::finished, this, [&](bool changed, const QString &){
connect(d->conf, &Configuration::finished, this, [lessThanVersion](bool changed, const QString &){
if(changed && lessThanVersion(QLatin1String("QDIGIDOC4-LATEST")))
dlg = WarningDialog::show(tr(
(new WarningDialog(tr(
"An ID-software update has been found. To download the update, go to the "
"<a href=\"https://www.id.ee/en/article/install-id-software/\">id.ee</a> website. "
"macOS users can download the update from the "
"<a href=\"https://itunes.apple.com/ee/developer/ria/id556524921?mt=12\">Mac App Store</a>."));
"<a href=\"https://itunes.apple.com/ee/developer/ria/id556524921?mt=12\">Mac App Store</a>."), mainWindow()))->exec();
});
#ifdef Q_OS_WIN
if(dlg)
Expand Down Expand Up @@ -420,22 +420,7 @@ Application::Application( int &argc, char **argv )
{
digidoc::Conf::init( new DigidocConf );
d->signer = new QSigner(this);
QString cache = confValue(TSLCache).toString();
QDir().mkpath( cache );
QDateTime tslTime = QDateTime::currentDateTimeUtc().addDays(-7);
for(const QString &file: QDir(QStringLiteral(":/TSL/")).entryList())
{
QFile tl(cache + "/" + file);
if(!tl.exists() ||
readTSLVersion(":/TSL/" + file) > readTSLVersion(tl.fileName()))
{
tl.remove();
QFile::copy(":/TSL/" + file, tl.fileName());
tl.setPermissions(QFile::Permissions(0x6444));
if(tl.open(QFile::Append))
tl.setFileTime(tslTime, QFileDevice::FileModificationTime);
}
}
updateTSLCache(QDateTime::currentDateTimeUtc().addDays(-7));

digidoc::initialize(applicationName().toUtf8().constData(), QStringLiteral("%1/%2 (%3)")
.arg(applicationName(), applicationVersion(), applicationOs()).toUtf8().constData(),
Expand Down Expand Up @@ -946,6 +931,27 @@ void Application::showWarning( const QString &msg, const digidoc::Exception &e )

QSigner* Application::signer() const { return d->signer; }

void Application::updateTSLCache(const QDateTime &tslTime)
{
QString cache = confValue(Application::TSLCache).toString();
QDir().mkpath(cache);
const QStringList tsllist = QDir(QStringLiteral(":/TSL/")).entryList();
for(const QString &file: tsllist)
{
if(QFile tl(cache + "/" + file);
Application::readTSLVersion(":/TSL/" + file) > Application::readTSLVersion(tl.fileName()))
{
const QStringList cleanup = QDir(cache, file + QStringLiteral("*")).entryList();
for(const QString &rm: cleanup)
QFile::remove(cache + "/" + rm);
QFile::copy(":/TSL/" + file, tl.fileName());
tl.setPermissions(QFile::Permissions(0x6444));
if(tslTime.isValid() && tl.open(QFile::Append))
tl.setFileTime(tslTime, QFileDevice::FileModificationTime);
}
}
}

void Application::waitForTSL( const QString &file )
{
if(!CONTAINER_EXT.contains(QFileInfo(file).suffix(), Qt::CaseInsensitive))
Expand Down
1 change: 1 addition & 0 deletions client/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Application final: public Common
static uint readTSLVersion(const QString &path);
static void setConfValue( ConfParameter parameter, const QVariant &value );
static void showClient(const QStringList &params = {}, bool crypto = false, bool sign = false, bool newWindow = false);
static void updateTSLCache(const QDateTime &tslTime);

private Q_SLOTS:
static void browse(const QUrl &url);
Expand Down
18 changes: 2 additions & 16 deletions client/dialogs/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)

connect(ui->btnCheckConnection, &QPushButton::clicked, this, &SettingsDialog::checkConnection);
connect(ui->btnFirstRun, &QPushButton::clicked, this, [this] {
FirstRun *dlg = new FirstRun(this);
auto *dlg = new FirstRun(this);
connect(dlg, &FirstRun::langChanged, this, [this](const QString &lang) {
retranslate(lang);
selectLanguage();
Expand All @@ -221,21 +221,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
#ifdef CONFIG_URL
qApp->conf()->update(true);
#endif
QString cache = Application::confValue(Application::TSLCache).toString();
const QStringList tsllist = QDir(QStringLiteral(":/TSL/")).entryList();
for(const QString &file: tsllist)
{
const QString target = cache + "/" + file;
if(!QFile::exists(target) ||
Application::readTSLVersion(":/TSL/" + file) > Application::readTSLVersion(target))
{
const QStringList cleanup = QDir(cache, file + QStringLiteral("*")).entryList();
for(const QString &rm: cleanup)
QFile::remove(cache + "/" + rm);
QFile::copy(":/TSL/" + file, target);
QFile::setPermissions(target, QFile::Permissions(0x6444));
}
}
Application::updateTSLCache({});
});
connect( ui->btnNavUseByDefault, &QPushButton::clicked, this, &SettingsDialog::useDefaultSettings );
connect( ui->btnNavSaveReport, &QPushButton::clicked, this, [=]{
Expand Down

0 comments on commit 7207b88

Please sign in to comment.