Skip to content

Commit

Permalink
Show Download button (#1209)
Browse files Browse the repository at this point in the history
IB-7776

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Aug 15, 2023
1 parent 551a4f5 commit caae2ce
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
30 changes: 22 additions & 8 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class MacMenuBar {};
#endif
#include "TokenData.h"
#include "Utils.h"
#include "dialogs/FirstRun.h"
#include "dialogs/SettingsDialog.h"
#include "dialogs/WaitDialog.h"
Expand Down Expand Up @@ -327,9 +328,10 @@ Application::Application( int &argc, char **argv )
return QVersionNumber::fromString(applicationVersion()) <
QVersionNumber::fromString(confValue(key).toString());
};
WarningDialog *dlg{};
if(lessThanVersion(QLatin1String("QDIGIDOC4-UNSUPPORTED")))
{
auto *dlg = WarningDialog::show(activeWindow(), tr(
dlg = WarningDialog::show(tr(
"This version of ID-software on your computer is unsupported. "
"DigiDoc4 Client cannot be used until you update ID-software. "
"Install new ID-software from <a href=\"https://www.id.ee/en/article/install-id-software/\">www.id.ee</a>. "
Expand All @@ -339,20 +341,33 @@ Application::Application( int &argc, char **argv )
}
else if(lessThanVersion(QLatin1String("QDIGIDOC4-SUPPORTED")))
{
WarningDialog::show(activeWindow(), tr(
dlg = WarningDialog::show(tr(
"Your ID-software has expired. To download the latest software version, go to the "
"<a href=\"https://www.id.ee/en/article/install-id-software/\">id.ee</a> website. "
"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, [&](bool changed, const QString &){
if(changed && lessThanVersion(QLatin1String("QDIGIDOC4-LATEST")))
WarningDialog::show(activeWindow(), tr(
dlg = WarningDialog::show(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>."));
});
#ifdef Q_OS_WIN
if(dlg)
{
dlg->addButton(tr("Start downloading"), 2);
connect(dlg, &WarningDialog::finished, this, [](int result) {
if(result != 2)
return;
QString path = QApplication::applicationDirPath() + QLatin1String("/id-updater.exe");
if (QFile::exists(path))
QProcess::startDetached(path, {});
});
}
#endif
});
#endif

Expand Down Expand Up @@ -429,10 +444,9 @@ Application::Application( int &argc, char **argv )
Q_EMIT qApp->TSLLoadingFinished();
qApp->d->ready = true;
if(ex) {
digidoc::Exception::ExceptionCode code = digidoc::Exception::General;
QStringList causes = DigiDoc::parseException(*ex, code);
QMetaObject::invokeMethod( qApp, "showWarning",
Q_ARG(QString,tr("Failed to initalize.")), Q_ARG(QString,causes.join('\n')) );
dispatchToMain([ex] {
showWarning(tr("Failed to initalize."), *ex);
});
}
}
);
Expand Down
28 changes: 19 additions & 9 deletions client/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,29 @@ namespace {

template <typename F, class... Args>
inline auto dispatchToMain(F&& function, Args&& ...args) {
std::invoke_result_t<F,Args...> result{};
QEventLoop l;
QTimer *timer = new QTimer();
timer->moveToThread(qApp->thread());
timer->setSingleShot(true);
QObject::connect(timer, &QTimer::timeout, timer, [&, function = std::forward<F>(function)] {
result = std::invoke(function, args...);
l.exit();
timer->deleteLater();
});
QMetaObject::invokeMethod(timer, [timer] { timer->start(0); }, Qt::QueuedConnection);
l.exec();
return result;
if constexpr (std::is_void_v<std::invoke_result_t<F,Args...>>) {
QObject::connect(timer, &QTimer::timeout, timer, [&, function = std::forward<F>(function)] {
std::invoke(function, args...);
l.exit();
timer->deleteLater();
});
QMetaObject::invokeMethod(timer, [timer] { timer->start(0); }, Qt::QueuedConnection);
l.exec();
} else {
std::invoke_result_t<F,Args...> result{};
QObject::connect(timer, &QTimer::timeout, timer, [&, function = std::forward<F>(function)] {
result = std::invoke(function, args...);
l.exit();
timer->deleteLater();
});
QMetaObject::invokeMethod(timer, [timer] { timer->start(0); }, Qt::QueuedConnection);
l.exec();
return result;
}
}

inline QString escapeUnicode(const QString &str) {
Expand Down
4 changes: 4 additions & 0 deletions client/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
<source>An ID-software update has been found. To download the update, go to the &lt;a href=&quot;https://www.id.ee/en/article/install-id-software/&quot;&gt;id.ee&lt;/a&gt; website. macOS users can download the update from the &lt;a href=&quot;https://itunes.apple.com/ee/developer/ria/id556524921?mt=12&quot;&gt;Mac App Store&lt;/a&gt;.</source>
<translation>An ID-software update has been found. To download the update, go to the &lt;a href=&quot;https://www.id.ee/en/article/install-id-software/&quot;&gt;id.ee&lt;/a&gt; website. macOS users can download the update from the &lt;a href=&quot;https://itunes.apple.com/ee/developer/ria/id556524921?mt=12&quot;&gt;Mac App Store&lt;/a&gt;.</translation>
</message>
<message>
<source>Start downloading</source>
<translation>Start downloading</translation>
</message>
</context>
<context>
<name>CDoc2</name>
Expand Down
4 changes: 4 additions & 0 deletions client/translations/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
<source>An ID-software update has been found. To download the update, go to the &lt;a href=&quot;https://www.id.ee/en/article/install-id-software/&quot;&gt;id.ee&lt;/a&gt; website. macOS users can download the update from the &lt;a href=&quot;https://itunes.apple.com/ee/developer/ria/id556524921?mt=12&quot;&gt;Mac App Store&lt;/a&gt;.</source>
<translation>Saadaval on ID-tarkvara uuendus, mille saad paigaldada veebilehelt &lt;a href=&quot;https://www.id.ee/artikkel/paigalda-id-tarkvara/&quot;&gt;id.ee&lt;/a&gt;, macOS kasutajad saavad uuenduse alla laadida &lt;a href=&quot;https://itunes.apple.com/ee/developer/ria/id556524921?mt=12&quot;&gt;Mac App Store&lt;/a&gt;&apos;ist.</translation>
</message>
<message>
<source>Start downloading</source>
<translation>Alusta paigaldust</translation>
</message>
</context>
<context>
<name>CDoc2</name>
Expand Down
4 changes: 4 additions & 0 deletions client/translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
<source>An ID-software update has been found. To download the update, go to the &lt;a href=&quot;https://www.id.ee/en/article/install-id-software/&quot;&gt;id.ee&lt;/a&gt; website. macOS users can download the update from the &lt;a href=&quot;https://itunes.apple.com/ee/developer/ria/id556524921?mt=12&quot;&gt;Mac App Store&lt;/a&gt;.</source>
<translation>Выпущено обновление для программного обеспечения ID-карты. Чтобы скачать обновление, перейдите на сайт &lt;a href=&quot;https://www.id.ee/ru/artikkel/ustanovite-id-programmu/&quot;&gt;id.ee&lt;/a&gt;. Пользователи macOS могут скачать обновление в магазине &lt;a href=&quot;https://itunes.apple.com/ee/developer/ria/id556524921?mt=12&quot;&gt;Mac App Store&lt;/a&gt;.</translation>
</message>
<message>
<source>Start downloading</source>
<translation>Начать установку</translation>
</message>
</context>
<context>
<name>CDoc2</name>
Expand Down

0 comments on commit caae2ce

Please sign in to comment.