@@ -49,7 +49,7 @@ class CryptoDoc::Private final: public QThread
4949{
5050 Q_OBJECT
5151public:
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
9797bool 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
176182bool 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
308317bool 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
460503void 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