Skip to content

Commit e58503e

Browse files
committed
Update Warning dialogs
IB-7962 Signed-off-by: Raul Metsma <[email protected]>
1 parent e6f0558 commit e58503e

28 files changed

+817
-601
lines changed

client/Application.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,12 @@ class DigidocConf final: public digidoc::XmlConfCurrent
197197
if(static std::atomic_bool isShown(false); !isShown.exchange(true))
198198
{
199199
dispatchToMain([] {
200-
WarningDialog::show(Application::tr(
200+
WarningDialog::create()->withText(Application::tr(
201201
"The renewal of Trust Service status List, used for digital signature validation, has failed. "
202202
"Please check your internet connection and make sure you have the latest ID-software version "
203203
"installed. An expired Trust Service List (TSL) will be used for signature validation. "
204-
"<a href=\"https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/\">Additional information</a>"), QString());
204+
"<a href=\"https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/\">Additional information</a>"))
205+
->open();
205206
});
206207
}
207208
return true;
@@ -354,7 +355,7 @@ Application::Application( int &argc, char **argv )
354355
WarningDialog *dlg{};
355356
if(lessThanVersion(QLatin1String("QDIGIDOC4-UNSUPPORTED")))
356357
{
357-
dlg = WarningDialog::show(tr(
358+
dlg = WarningDialog::create()->withText(tr(
358359
"This version of ID-software on your computer is unsupported. "
359360
"DigiDoc4 Client cannot be used until you update ID-software. "
360361
"Install new ID-software from <a href=\"https://www.id.ee/en/article/install-id-software/\">www.id.ee</a>. "
@@ -364,7 +365,7 @@ Application::Application( int &argc, char **argv )
364365
}
365366
else if(lessThanVersion(QLatin1String("QDIGIDOC4-SUPPORTED")))
366367
{
367-
dlg = WarningDialog::show(tr(
368+
dlg = WarningDialog::create()->withText(tr(
368369
"Your ID-software has expired. To download the latest software version, go to the "
369370
"<a href=\"https://www.id.ee/en/article/install-id-software/\">id.ee</a> website. "
370371
"macOS users can download the latest ID-software version from the "
@@ -373,26 +374,25 @@ Application::Application( int &argc, char **argv )
373374
connect(d->conf, &Configuration::finished, this, [lessThanVersion](bool changed, const QString &){
374375
if(changed && lessThanVersion(QLatin1String("QDIGIDOC4-LATEST")))
375376
{
376-
auto *dlg = new WarningDialog(tr(
377+
auto *dlg = WarningDialog::create(activeWindow())->withText(tr(
377378
"An ID-software update has been found. To download the update, go to the "
378379
"<a href=\"https://www.id.ee/en/article/install-id-software/\">id.ee</a> website. "
379380
"macOS users can download the update from the "
380-
"<a href=\"https://itunes.apple.com/ee/developer/ria/id556524921?mt=12\">Mac App Store</a>."), activeWindow());
381+
"<a href=\"https://itunes.apple.com/ee/developer/ria/id556524921?mt=12\">Mac App Store</a>."));
381382
new Overlay(dlg, activeWindow());
382383
dlg->exec();
383384
}
384385
});
385386
#ifdef Q_OS_WIN
386387
if(dlg)
387388
{
388-
dlg->addButton(tr("Start downloading"), 2);
389-
connect(dlg, &WarningDialog::finished, this, [](int result) {
390-
if(result != 2)
391-
return;
389+
dlg->addButton(tr("Start downloading"), QMessageBox::Ok);
390+
connect(dlg, &WarningDialog::accepted, this, [] {
392391
QString path = QApplication::applicationDirPath() + QLatin1String("/id-updater.exe");
393392
if (QFile::exists(path))
394393
QProcess::startDetached(path, {});
395394
});
395+
dlg->open();
396396
}
397397
#endif
398398
}, Qt::QueuedConnection);
@@ -470,8 +470,8 @@ Application::Application( int &argc, char **argv )
470470
#ifdef Q_OS_MAC
471471
if(!Settings::PLUGINS.isSet())
472472
{
473-
auto *dlg = new WarningDialog(tr(
474-
"In order to authenticate and sign in e-services with an ID-card you need to install the web browser components."), mainWindow());
473+
auto *dlg = WarningDialog::create()
474+
->withText(tr("In order to authenticate and sign in e-services with an ID-card you need to install the web browser components."));
475475
dlg->setCancelText(tr("Ignore forever"));
476476
dlg->addButton(tr("Remind later"), QMessageBox::Ignore);
477477
dlg->addButton(tr("Install"), QMessageBox::Open);
@@ -809,11 +809,15 @@ bool Application::notify(QObject *object, QEvent *event)
809809
}
810810
catch(const std::bad_alloc &e)
811811
{
812-
WarningDialog::show(tr("Added file(s) exceeds the maximum size limit of the container(120MB)."), QString::fromLocal8Bit(e.what()));
812+
WarningDialog::create()
813+
->withTitle(DocumentModel::tr("Failed to add file"))
814+
->withText(tr("Added file(s) exceeds the maximum size limit of the container(120MB)."))
815+
->withDetails(QString::fromLocal8Bit(e.what()))
816+
->open();
813817
}
814818
catch(...)
815819
{
816-
WarningDialog::show(tr("Caught exception!"));
820+
WarningDialog::create()->withTitle(tr("Caught exception!"))->open();
817821
}
818822

819823
return false;
@@ -944,11 +948,11 @@ void Application::showClient(QStringList files, bool crypto, bool sign, bool new
944948
});
945949
}
946950

947-
void Application::showWarning( const QString &msg, const digidoc::Exception &e )
951+
void Application::showWarning(const QString &title, const digidoc::Exception &e)
948952
{
949953
digidoc::Exception::ExceptionCode code = digidoc::Exception::General;
950954
QStringList causes = DigiDoc::parseException(e, code);
951-
WarningDialog::show(msg, causes.join('\n'));
955+
WarningDialog::create()->withTitle(title)->withDetails(causes.join('\n'))->open();
952956
}
953957

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

client/Application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private Q_SLOTS:
9292
static void msgHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &msg);
9393
static void parseArgs(const QString &msg = {});
9494
static void parseArgs(QStringList args);
95-
static void showWarning(const QString &msg, const digidoc::Exception &e);
95+
static void showWarning(const QString &title, const digidoc::Exception &e);
9696
#if defined(Q_OS_MAC)
9797
static void initMacEvents();
9898
static void deinitMacEvents();

client/CDoc1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#include "QCryptoBackend.h"
2525
#include "QSigner.h"
2626
#include "Utils.h"
27-
#include "dialogs/FileDialog.h"
2827

2928
#include <QtCore/QBuffer>
3029
#include <QtCore/QDebug>
30+
#include <QtCore/QDir>
3131
#include <QtCore/QTemporaryFile>
3232
#include <QtCore/QXmlStreamWriter>
3333
#include <QtNetwork/QSslKey>
@@ -195,7 +195,7 @@ bool CDoc1::decryptPayload(const QByteArray &key)
195195
return setLastError(CryptoDoc::tr("Error parsing document"));
196196
data = Crypto::cipher(ENC_MTH[method], key, data, false);
197197
if(data.isEmpty())
198-
return setLastError(CryptoDoc::tr("Failed to decrypt document"));
198+
return setLastError(QCoreApplication::translate("QSigner", "Failed to decrypt document"));
199199

200200
// remove ANSIX923 padding
201201
if(data.size() > 0 && method == AES128CBC_MTH)

client/CryptoDoc.cpp

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CryptoDoc::Private final: public QThread
4949
{
5050
Q_OBJECT
5151
public:
52-
bool isEncryptedWarning() const;
52+
bool isEncryptedWarning(const QString &title) const;
5353
void run() final;
5454
inline void waitForFinished()
5555
{
@@ -67,12 +67,12 @@ class CryptoDoc::Private final: public QThread
6767
QStringList tempFiles;
6868
};
6969

70-
bool CryptoDoc::Private::isEncryptedWarning() const
70+
bool CryptoDoc::Private::isEncryptedWarning(const QString &title) const
7171
{
7272
if( fileName.isEmpty() )
73-
WarningDialog::show(CryptoDoc::tr("Container is not open"));
73+
WarningDialog::create()->withTitle(title)->withText(CryptoDoc::tr("Container is not open"))->open();
7474
if(isEncrypted)
75-
WarningDialog::show(CryptoDoc::tr("Container is encrypted"));
75+
WarningDialog::create()->withTitle(title)->withText(CryptoDoc::tr("Container is encrypted"))->open();
7676
return fileName.isEmpty() || isEncrypted;
7777
}
7878

@@ -96,7 +96,7 @@ CDocumentModel::CDocumentModel(CryptoDoc::Private *doc)
9696

9797
bool CDocumentModel::addFile(const QString &file, const QString &mime)
9898
{
99-
if( d->isEncryptedWarning() )
99+
if(d->isEncryptedWarning(DocumentModel::tr("Failed to add file")))
100100
return false;
101101

102102
QFileInfo info(file);
@@ -105,8 +105,11 @@ bool CDocumentModel::addFile(const QString &file, const QString &mime)
105105

106106
if(d->cdoc->version() == 1 && info.size() > 120*1024*1024)
107107
{
108-
WarningDialog::show(tr("Added file(s) exceeds the maximum size limit of the container (∼120MB). "
109-
"<a href='https://www.id.ee/en/article/encrypting-large-120-mb-files/'>Read more about it</a>"));
108+
WarningDialog::create()
109+
->withTitle(DocumentModel::tr("Failed to add file"))
110+
->withText(tr("Added file(s) exceeds the maximum size limit of the container (∼120MB). "
111+
"<a href='https://www.id.ee/en/article/encrypting-large-120-mb-files/'>Read more about it</a>"))
112+
->open();
110113
return false;
111114
}
112115

@@ -137,7 +140,10 @@ QString CDocumentModel::copy(int row, const QString &dst) const
137140
file.data->seek(0);
138141
if(QFile f(dst); f.open(QFile::WriteOnly) && copyIODevice(file.data.get(), &f) == file.size)
139142
return dst;
140-
WarningDialog::show(tr("Failed to save file '%1'").arg(dst));
143+
WarningDialog::create()
144+
->withTitle(FileDialog::tr("Failed to save file"))
145+
->withText(dst)
146+
->open();
141147
return {};
142148
}
143149

@@ -175,12 +181,15 @@ void CDocumentModel::open(int row)
175181

176182
bool CDocumentModel::removeRow(int row)
177183
{
178-
if(d->isEncryptedWarning())
184+
if(d->isEncryptedWarning(DocumentModel::tr("Failed remove document from container")))
179185
return false;
180186

181187
if(d->cdoc->files.empty() || row >= d->cdoc->files.size())
182188
{
183-
WarningDialog::show(DocumentModel::tr("Internal error"));
189+
WarningDialog::create()
190+
->withTitle(DocumentModel::tr("Failed remove document from container"))
191+
->withText(DocumentModel::tr("Internal error"))
192+
->open();
184193
return false;
185194
}
186195

@@ -307,11 +316,14 @@ CryptoDoc::~CryptoDoc() { clear(); delete d; }
307316

308317
bool CryptoDoc::addKey( const CKey &key )
309318
{
310-
if(d->isEncryptedWarning())
319+
if(d->isEncryptedWarning(tr("Failed to add key")))
311320
return false;
312321
if(d->cdoc->keys.contains(key))
313322
{
314-
WarningDialog::show(tr("Key already exists"));
323+
WarningDialog::create()
324+
->withTitle(tr("Failed to add key"))
325+
->withText(tr("Key already exists"))
326+
->open();
315327
return false;
316328
}
317329
d->cdoc->keys.append(key);
@@ -349,7 +361,10 @@ bool CryptoDoc::decrypt()
349361
{
350362
if( d->fileName.isEmpty() )
351363
{
352-
WarningDialog::show(tr("Container is not open"));
364+
WarningDialog::create()
365+
->withTitle(QSigner::tr("Failed to decrypt document"))
366+
->withText(tr("Container is not open"))
367+
->open();
353368
return false;
354369
}
355370
if(!d->isEncrypted)
@@ -358,15 +373,20 @@ bool CryptoDoc::decrypt()
358373
CKey key = d->cdoc->canDecrypt(qApp->signer()->tokenauth().cert());
359374
if(key.key.isEmpty())
360375
{
361-
WarningDialog::show(tr("You do not have the key to decrypt this document"));
376+
WarningDialog::create()
377+
->withTitle(QSigner::tr("Failed to decrypt document"))
378+
->withText(tr("You do not have the key to decrypt this document"))
379+
->open();
362380
return false;
363381
}
364382

365383
if(d->cdoc->version() == 2 && !key.transaction_id.isEmpty() && !Settings::CDOC2_NOTIFICATION.isSet())
366384
{
367-
auto *dlg = new WarningDialog(tr("You must enter your PIN code twice in order to decrypt the CDOC2 container. "
368-
"The first PIN entry is required for authentication to the key server referenced in the CDOC2 container. "
369-
"Second PIN entry is required to decrypt the CDOC2 container."), Application::mainWindow());
385+
auto *dlg = WarningDialog::create()
386+
->withTitle(QSigner::tr("Failed to decrypt document"))
387+
->withText(tr("You must enter your PIN code twice in order to decrypt the CDOC2 container. "
388+
"The first PIN entry is required for authentication to the key server referenced in the CDOC2 container. "
389+
"Second PIN entry is required to decrypt the CDOC2 container."));
370390
dlg->setCancelText(WarningDialog::Cancel);
371391
dlg->addButton(WarningDialog::OK, QMessageBox::Ok);
372392
dlg->addButton(tr("Don't show again"), QMessageBox::Ignore);
@@ -386,15 +406,25 @@ bool CryptoDoc::decrypt()
386406
#endif
387407
if(d->key.isEmpty())
388408
{
389-
WarningDialog::show(tr("Failed to decrypt document. Please check your internet connection and network settings."), d->cdoc->lastError);
409+
WarningDialog::create()
410+
->withTitle(QSigner::tr("Failed to decrypt document"))
411+
->withText(tr("Please check your internet connection and network settings."))
412+
->withDetails(d->cdoc->lastError)
413+
->open();
390414
return false;
391415
}
392416

393417
d->waitForFinished();
394418
if(d->isEncrypted)
395-
WarningDialog::show(tr("Error parsing document"));
419+
WarningDialog::create()
420+
->withTitle(QSigner::tr("Failed to decrypt document"))
421+
->withText(tr("Error parsing document"))
422+
->open();
396423
if(!d->cdoc->lastError.isEmpty())
397-
WarningDialog::show(d->cdoc->lastError);
424+
WarningDialog::create()
425+
->withTitle(QSigner::tr("Failed to decrypt document"))
426+
->withDetails(d->cdoc->lastError)
427+
->open();
398428

399429
return !d->isEncrypted;
400430
}
@@ -407,22 +437,32 @@ bool CryptoDoc::encrypt( const QString &filename )
407437
d->fileName = filename;
408438
if( d->fileName.isEmpty() )
409439
{
410-
WarningDialog::show(tr("Container is not open"));
440+
WarningDialog::create()
441+
->withTitle(tr("Failed to encrypt document"))
442+
->withText(tr("Container is not open"))
443+
->open();
411444
return false;
412445
}
413446
if(d->isEncrypted)
414447
return true;
415448
if(d->cdoc->keys.isEmpty())
416449
{
417-
WarningDialog::show(tr("No keys specified"));
450+
WarningDialog::create()
451+
->withTitle(tr("Failed to encrypt document"))
452+
->withText(tr("No keys specified"))
453+
->open();
418454
return false;
419455
}
420456

421457
d->waitForFinished();
422458
if(d->isEncrypted)
423459
open(d->fileName);
424460
else
425-
WarningDialog::show(tr("Failed to encrypt document. Please check your internet connection and network settings."), d->cdoc->lastError);
461+
WarningDialog::create()
462+
->withTitle(tr("Failed to encrypt document"))
463+
->withText(tr("Please check your internet connection and network settings."))
464+
->withDetails(d->cdoc->lastError)
465+
->open();
426466
return d->isEncrypted;
427467
}
428468

@@ -450,7 +490,10 @@ bool CryptoDoc::open( const QString &file )
450490
d->isEncrypted = bool(d->cdoc);
451491
if(!d->isEncrypted || d->cdoc->keys.isEmpty())
452492
{
453-
WarningDialog::show(tr("Failed to open document"), d->cdoc->lastError);
493+
WarningDialog::create()
494+
->withTitle(tr("Failed to open document"))
495+
->withDetails(d->cdoc->lastError)
496+
->open();
454497
return false;
455498
}
456499
Application::addRecent( file );
@@ -459,7 +502,7 @@ bool CryptoDoc::open( const QString &file )
459502

460503
void CryptoDoc::removeKey( int id )
461504
{
462-
if(!d->isEncryptedWarning())
505+
if(!d->isEncryptedWarning(tr("Failed to remove key")))
463506
d->cdoc->keys.removeAt(id);
464507
}
465508

0 commit comments

Comments
 (0)