Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate code and block update dialog #1220

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
51 changes: 31 additions & 20 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MacMenuBar {};
#include "dialogs/SettingsDialog.h"
#include "dialogs/WaitDialog.h"
#include "dialogs/WarningDialog.h"
#include "effects/Overlay.h"

#include <common/Configuration.h>

Expand Down Expand Up @@ -336,7 +337,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 @@ -357,13 +358,17 @@ 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(
{
auto dlg = 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>."), activeWindow());
new Overlay(dlg, activeWindow());
dlg->exec();
}
});
#ifdef Q_OS_WIN
if(dlg)
Expand Down Expand Up @@ -430,22 +435,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 @@ -956,6 +946,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
2 changes: 1 addition & 1 deletion client/dialogs/AddRecipients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ AddRecipients::AddRecipients(ItemList* itemList, QWidget *parent)
ui->actionLayout->setDirection(QBoxLayout::RightToLeft);
#endif
setWindowFlags( Qt::Dialog | Qt::CustomizeWindowHint );
new Overlay(this, parent);
new Overlay(this);

ui->leftPane->init(ria::qdigidoc4::ToAddAdresses, QT_TRANSLATE_NOOP("ItemList", "Add recipients"));
ui->leftPane->setFont(Styles::font(Styles::Regular, 20));
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/CertificateDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CertificateDetails::CertificateDetails(const SslCertificate &cert, QWidget *pare
#else
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
#endif
new Overlay(this, parent);
new Overlay(this);

QFont headerFont = Styles::font( Styles::Regular, 18 );
QFont regularFont = Styles::font( Styles::Regular, 14 );
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/KeyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ KeyDialog::KeyDialog( const CKey &k, QWidget *parent )
#endif
setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint);
setAttribute(Qt::WA_DeleteOnClose);
new Overlay(this, parent);
new Overlay(this);

QFont condensed = Styles::font(Styles::Condensed, 12);
QFont regular = Styles::font(Styles::Regular, 14);
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/MobileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MobileDialog::MobileDialog(QWidget *parent) :
ui(new Ui::MobileDialog)
{
static const QStringList countryCodes {QStringLiteral("372"), QStringLiteral("370")};
new Overlay(this, parent);
new Overlay(this);
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
setFixedSize(size());
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/PinPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidg
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
for(QLineEdit *w: findChildren<QLineEdit*>())
w->setAttribute(Qt::WA_MacShowFocusRect, false);
new Overlay(this, parent);
new Overlay(this);

ui->labelNameId->setFont(Styles::font(Styles::Regular, 20, QFont::DemiBold));
ui->label->setFont(Styles::font(Styles::Regular, 14));
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/PinUnblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
list.first()->setFocus();
for(QLineEdit *w: list)
w->setAttribute(Qt::WA_MacShowFocusRect, false);
new Overlay(this, parent);
new Overlay(this);

QFont condensed14 = Styles::font(Styles::Condensed, 14);
QFont condensed12 = Styles::font(Styles::Condensed, 12);
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/RoleAddressDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int RoleAddressDialog::get(QString &city, QString &country, QString &state, QStr
{
if(!Settings::SHOW_ROLE_ADDRESS_INFO)
return QDialog::Accepted;
new Overlay(this, parentWidget());
new Overlay(this);
int result = QDialog::exec();
if(result == QDialog::Rejected)
return result;
Expand Down
23 changes: 5 additions & 18 deletions client/dialogs/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
: QDialog(parent)
, ui(new Ui::SettingsDialog)
{
new Overlay(this, parent);
new Overlay(this);

ui->setupUi(this);
setWindowFlag(Qt::FramelessWindowHint);
Expand Down Expand Up @@ -196,7 +196,8 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
WarningDialog::show(this, tr("Checking updates has failed.") + "<br />" + tr("Please try again."), error);
return;
}
WarningDialog::show(this, tr("DigiDoc4 Client configuration update was successful."));
auto dlg = WarningDialog::show(this, tr("DigiDoc4 Client configuration update was successful."));
new Overlay(dlg);
#ifdef Q_OS_WIN
QString path = QApplication::applicationDirPath() + QLatin1String("/id-updater.exe");
if (QFile::exists(path))
Expand All @@ -210,7 +211,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 +222,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)
{
if(const QString target = cache + "/" + file;
!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
2 changes: 1 addition & 1 deletion client/dialogs/SignatureDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SignatureDialog::SignatureDialog(const DigiDocSignature &signature, QWidget *par
connect(d->showRole, &AccordionTitle::opened, d->showErrors, &AccordionTitle::openSection);
connect(d->showRole, &AccordionTitle::closed, this, [this] { d->showErrors->setSectionOpen(); });

new Overlay(this, parent);
new Overlay(this);

SslCertificate c = signature.cert();
QString style = QStringLiteral("<font color=\"green\">");
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/SmartIDDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SmartIDDialog::SmartIDDialog(QWidget *parent)
, ui(new Ui::SmartIDDialog)
{
static const QString &EE = Settings::SMARTID_COUNTRY_LIST.first();
new Overlay(this, parent);
new Overlay(this);

ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/WaitDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ WaitDialog::WaitDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::WaitDialog)
{
new Overlay(this, parent);
new Overlay(this);
setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);
ui->setupUi(this);
ui->movie->load(QStringLiteral(":/images/wait.svg"));
Expand Down
4 changes: 4 additions & 0 deletions client/effects/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <QGraphicsBlurEffect>
#include <QPainter>

Overlay::Overlay(QWidget *runner)
: Overlay(runner, runner->parentWidget())
{}

Overlay::Overlay(QWidget *runner, QWidget *parent)
: QWidget(parent->topLevelWidget())
{
Expand Down
1 change: 1 addition & 0 deletions client/effects/Overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Overlay final : public QWidget
{
Q_OBJECT
public:
Overlay(QWidget *runner);
Overlay(QWidget *runner, QWidget *parent);
~Overlay() final;

Expand Down