Skip to content

Commit

Permalink
Use async WarningDialog (open-eid#1182)
Browse files Browse the repository at this point in the history
IB-7665

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Apr 27, 2023
1 parent e512bee commit 7686eab
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 150 deletions.
11 changes: 3 additions & 8 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,11 @@ bool Application::notify(QObject *object, QEvent *event)
}
catch(const std::bad_alloc &e)
{
showWarning(tr("Added file(s) exceeds the maximum size limit of the container(120MB)."), QString::fromLocal8Bit(e.what()));
WarningDialog::show(tr("Added file(s) exceeds the maximum size limit of the container(120MB)."), QString::fromLocal8Bit(e.what()));
}
catch(...)
{
showWarning( tr("Caught exception!") );
WarningDialog::show(tr("Caught exception!"));
}

return false;
Expand Down Expand Up @@ -939,12 +939,7 @@ void Application::showWarning( const QString &msg, const digidoc::Exception &e )
{
digidoc::Exception::ExceptionCode code = digidoc::Exception::General;
QStringList causes = DigiDoc::parseException(e, code);
WarningDialog::show(mainWindow(), msg, causes.join('\n'));
}

void Application::showWarning( const QString &msg, const QString &details )
{
WarningDialog(msg, details, mainWindow()).exec();
WarningDialog::show(msg, causes.join('\n'));
}

QSigner* Application::signer() const { return d->signer; }
Expand Down
1 change: 0 additions & 1 deletion client/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class Application final: public Common

public Q_SLOTS:
void showClient(const QStringList &params = {}, bool crypto = false, bool sign = false, bool newWindow = false);
static void showWarning(const QString &msg, const QString &details = {});

private Q_SLOTS:
void parseArgs(const QString &msg = {});
Expand Down
2 changes: 1 addition & 1 deletion client/CryptoDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CryptoDoc::Private final: public QThread
void run() final;
static void showError(const QString &err, const QString &details = {})
{
WarningDialog::show(Application::mainWindow(), err, details);
WarningDialog::show(err, details);
}
static QString size(const QString &size)
{
Expand Down
50 changes: 25 additions & 25 deletions client/DigiDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,20 @@ bool SDocumentModel::addFile(const QString &file, const QString &mime)
QFileInfo info(file);
if(info.size() == 0)
{
WarningDialog::show(qApp->mainWindow(), DocumentModel::tr("Cannot add empty file to the container."));
WarningDialog::show(DocumentModel::tr("Cannot add empty file to the container."));
return false;
}
QString fileName(info.fileName());
if(fileName == QStringLiteral("mimetype"))
{
WarningDialog::show(qApp->mainWindow(), DocumentModel::tr("Cannot add file with name 'mimetype' to the envelope."));
WarningDialog::show(DocumentModel::tr("Cannot add file with name 'mimetype' to the envelope."));
return false;
}
for(int row = 0; row < rowCount(); row++)
{
if(fileName == from(doc->b->dataFiles().at(size_t(row))->fileName()))
{
WarningDialog::show(qApp->mainWindow(), DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.")
WarningDialog::show(DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.")
.arg(FileDialog::normalized(fileName)));
return false;
}
Expand Down Expand Up @@ -455,9 +455,9 @@ QString DigiDoc::fileName() const { return m_fileName; }
bool DigiDoc::isError(bool failure, const QString &msg) const
{
if(!b)
qApp->showWarning(tr("Container is not open"));
WarningDialog::show(tr("Container is not open"));
else if(failure)
qApp->showWarning(msg);
WarningDialog::show(msg);
return !b || failure;
}

Expand Down Expand Up @@ -496,16 +496,16 @@ bool DigiDoc::open( const QString &file )
{
QWidget *parent = qobject_cast<QWidget *>(QObject::parent());
if(parent == nullptr)
parent = qApp->activeWindow();
parent = Application::activeWindow();
qApp->waitForTSL( file );
clear();
auto serviceConfirmation = [parent] {
WarningDialog dlg(tr("Signed document in PDF and DDOC format will be transmitted to the Digital Signature Validation Service SiVa to verify the validity of the digital signature. "
auto *dlg = new WarningDialog(tr("Signed document in PDF and DDOC format will be transmitted to the Digital Signature Validation Service SiVa to verify the validity of the digital signature. "
"Read more information about transmitted data to Digital Signature Validation service from <a href=\"https://www.id.ee/en/article/data-protection-conditions-for-the-id-software-of-the-national-information-system-authority/\">here</a>.<br />"
"Do you want to continue?"), parent);
dlg.setCancelText(tr("CANCEL"));
dlg.addButton(tr("YES"), ContainerSave);
return dlg.exec() == ContainerSave;
dlg->setCancelText(tr("CANCEL"));
dlg->addButton(tr("YES"), ContainerSave);
return dlg->exec() == ContainerSave;
};
if((file.endsWith(QStringLiteral(".pdf"), Qt::CaseInsensitive) ||
file.endsWith(QStringLiteral(".ddoc"), Qt::CaseInsensitive)) && !serviceConfirmation())
Expand Down Expand Up @@ -543,7 +543,7 @@ bool DigiDoc::open( const QString &file )
for(const Signature *signature: parentContainer->signatures())
m_timestamps.append(DigiDocSignature(signature, this));
}
qApp->addRecent(file);
Application::addRecent(file);
m_fileName = file;
containerState = signatures().isEmpty() ? ContainerState::UnsignedSavedContainer : ContainerState::SignedContainer;
return true;
Expand Down Expand Up @@ -614,7 +614,7 @@ bool DigiDoc::save( const QString &filename )
m_fileName = filename;
if(!saveAs(m_fileName))
return false;
qApp->addRecent(m_fileName);
Application::addRecent(m_fileName);
modified = false;
containerState = signatures().isEmpty() ? ContainerState::UnsignedSavedContainer : ContainerState::SignedContainer;
return true;
Expand Down Expand Up @@ -644,33 +644,33 @@ void DigiDoc::setLastError( const QString &msg, const Exception &e )
switch( code )
{
case Exception::CertificateRevoked:
qApp->showWarning(tr("Certificate status revoked"), causes.join('\n')); break;
WarningDialog::show(tr("Certificate status revoked"), causes.join('\n')); break;
case Exception::CertificateUnknown:
qApp->showWarning(tr("Certificate status unknown"), causes.join('\n')); break;
WarningDialog::show(tr("Certificate status unknown"), causes.join('\n')); break;
case Exception::OCSPTimeSlot:
qApp->showWarning(tr("Please check your computer time. <a href='https://www.id.ee/en/article/digidoc4-client-error-please-check-your-computer-time-2/'>Additional information</a>"), causes.join('\n')); break;
WarningDialog::show(tr("Please check your computer time. <a href='https://www.id.ee/en/article/digidoc4-client-error-please-check-your-computer-time-2/'>Additional information</a>"), causes.join('\n')); break;
case Exception::OCSPRequestUnauthorized:
qApp->showWarning(tr("You have not granted IP-based access. "
WarningDialog::show(tr("You have not granted IP-based access. "
"Check your validity confirmation service access settings."), causes.join('\n')); break;
case Exception::TSForbidden:
qApp->showWarning(tr("Failed to sign container. "
WarningDialog::show(tr("Failed to sign container. "
"Check your Time-Stamping service access settings."), causes.join('\n')); break;
case Exception::TSTooManyRequests:
qApp->showWarning(tr("The limit for digital signatures per month has been reached for this IP address. "
WarningDialog::show(tr("The limit for digital signatures per month has been reached for this IP address. "
"<a href=\"https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/\">Additional information</a>"), causes.join('\n')); break;
case Exception::PINCanceled:
break;
case Exception::PINFailed:
qApp->showWarning(tr("PIN Login failed"), causes.join('\n')); break;
WarningDialog::show(tr("PIN Login failed"), causes.join('\n')); break;
case Exception::PINIncorrect:
qApp->showWarning(tr("PIN Incorrect"), causes.join('\n')); break;
WarningDialog::show(tr("PIN Incorrect"), causes.join('\n')); break;
case Exception::PINLocked:
qApp->showWarning(tr("PIN Locked. Unblock to reuse PIN."), causes.join('\n')); break;
WarningDialog::show(tr("PIN Locked. Unblock to reuse PIN."), causes.join('\n')); break;
case Exception::NetworkError: // use passed message for these thre exceptions
case Exception::HostNotFound:
case Exception::InvalidUrl:
default:
qApp->showWarning(msg, causes.join('\n')); break;
WarningDialog::show(msg, causes.join('\n')); break;
}
}

Expand Down Expand Up @@ -702,13 +702,13 @@ bool DigiDoc::sign(const QString &city, const QString &state, const QString &zip
switch(code)
{
case Exception::PINIncorrect:
qApp->showWarning(tr("PIN Incorrect"));
(new WarningDialog(tr("PIN Incorrect"), Application::mainWindow()))->exec();
return sign(city, state, zip, country, role, signer);
case Exception::NetworkError:
case Exception::HostNotFound:
qApp->showWarning(tr("Failed to sign container. Please check the access to signing services and network settings."), causes.join('\n')); break;
WarningDialog::show(tr("Failed to sign container. Please check the access to signing services and network settings."), causes.join('\n')); break;
case Exception::InvalidUrl:
qApp->showWarning(tr("Failed to sign container. Signing service URL is incorrect."), causes.join('\n')); break;
WarningDialog::show(tr("Failed to sign container. Signing service URL is incorrect."), causes.join('\n')); break;
default:
setLastError(tr("Failed to sign container."), e); break;
}
Expand Down
7 changes: 2 additions & 5 deletions client/DocumentModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ bool DocumentModel::verifyFile(const QString &f)
QStringLiteral("pps"), QStringLiteral("ppt"), QStringLiteral("pptx"), QStringLiteral("png"), QStringLiteral("jpg"), QStringLiteral("jpeg"), QStringLiteral("bmp"), QStringLiteral("ai"),
QStringLiteral("gif"), QStringLiteral("ico"), QStringLiteral("ps"), QStringLiteral("psd"), QStringLiteral("tif"), QStringLiteral("tiff"), QStringLiteral("csv")};

QJsonArray allowedExts = qApp->confValue(QLatin1String("ALLOWED-EXTENSIONS")).toArray(defaultArray);
QJsonArray allowedExts = Application::confValue(QLatin1String("ALLOWED-EXTENSIONS")).toArray(defaultArray);
if(!allowedExts.contains(QJsonValue(QFileInfo(f).suffix().toLower()))){
auto *dlg = new WarningDialog(tr("A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it."), qApp->activeWindow());
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setCancelText(tr("OK"));
dlg->open();
WarningDialog::show(tr("A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it."))->setCancelText(tr("OK"));
return false;
}

Expand Down
62 changes: 28 additions & 34 deletions client/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ bool MainWindow::encrypt()
return false;

if(!FileDialog::fileIsWritable(cryptoDoc->fileName())) {
WarningDialog dlg(tr("Cannot alter container %1. Save different location?")
auto *dlg = new WarningDialog(tr("Cannot alter container %1. Save different location?")
.arg(FileDialog::normalized(cryptoDoc->fileName())), this);
dlg.addButton(tr("YES").toUpper(), QMessageBox::Yes);
if(dlg.exec() == QMessageBox::Yes) {
dlg->addButton(tr("YES").toUpper(), QMessageBox::Yes);
if(dlg->exec() == QMessageBox::Yes) {
moveCryptoContainer();
return encrypt();
}
Expand Down Expand Up @@ -572,9 +572,9 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString
break;
if( !FileDialog::fileIsWritable(target))
{
WarningDialog dlg(tr("Cannot alter container %1. Save different location?").arg(target), this);
dlg.addButton(tr("YES").toUpper(), QMessageBox::Yes);
if(dlg.exec() == QMessageBox::Yes) {
auto *dlg = new WarningDialog(tr("Cannot alter container %1. Save different location?").arg(target), this);
dlg->addButton(tr("YES").toUpper(), QMessageBox::Yes);
if(dlg->exec() == QMessageBox::Yes) {
QString file = selectFile(tr("Save file"), target, true);
if(!file.isEmpty())
cryptoDoc->saveCopy(file);
Expand Down Expand Up @@ -741,10 +741,10 @@ void MainWindow::resetDigiDoc(DigiDoc *doc, bool warnOnChange)
saveTxt = tr("SAVE");
}

WarningDialog dlg(warning, this);
dlg.setCancelText(cancelTxt);
dlg.addButton(saveTxt, ContainerSave);
if(dlg.exec() == ContainerSave)
auto *dlg = new WarningDialog(warning, this);
dlg->setCancelText(cancelTxt);
dlg->addButton(saveTxt, ContainerSave);
if(dlg->exec() == ContainerSave)
save();
}

Expand Down Expand Up @@ -775,9 +775,9 @@ bool MainWindow::save(bool saveAs)

if(!FileDialog::fileIsWritable(target))
{
WarningDialog dlg(tr("Cannot alter container %1. Save different location?").arg(target), this);
dlg.addButton(tr("YES").toUpper(), QMessageBox::Yes);
if(dlg.exec() == QMessageBox::Yes) {
auto *dlg = new WarningDialog(tr("Cannot alter container %1. Save different location?").arg(target), this);
dlg->addButton(tr("YES").toUpper(), QMessageBox::Yes);
if(dlg->exec() == QMessageBox::Yes) {
QString file = selectFile(tr("Save file"), target, true);
if(!file.isEmpty())
return saveAs ? digiDoc->saveAs(file) : digiDoc->save(file);
Expand Down Expand Up @@ -960,11 +960,11 @@ bool MainWindow::removeFile(DocumentModel *model, int index)
}
else
{
WarningDialog dlg(tr("You are about to delete the last file in the container, it is removed along with the container."), this);
dlg.setCancelText(tr("CANCEL"));
dlg.resetCancelStyle();
dlg.addButton(tr("REMOVE"), ContainerSave, true);
if (dlg.exec() == ContainerSave) {
auto *dlg = new WarningDialog(tr("You are about to delete the last file in the container, it is removed along with the container."), this);
dlg->setCancelText(tr("CANCEL"));
dlg->resetCancelStyle();
dlg->addButton(tr("REMOVE"), ContainerSave, true);
if (dlg->exec() == ContainerSave) {
window()->setWindowFilePath({});
window()->setWindowTitle(tr("DigiDoc4 Client"));
return true;
Expand Down Expand Up @@ -1025,18 +1025,12 @@ bool MainWindow::validateFiles(const QString &container, const QStringList &file
{
// Check that container is not dropped into itself
QFileInfo containerInfo(container);
for(const auto &file: files)
{
if(containerInfo == QFileInfo(file))
{
WarningDialog dlg(tr("Cannot add container to same container\n%1").arg(FileDialog::normalized(container)), this);
dlg.setCancelText(tr("CANCEL"));
dlg.exec();
return false;
}
}

return true;
if(std::none_of(files.cbegin(), files.cend(),
[containerInfo] (const QString &file) { return containerInfo == QFileInfo(file); }))
return true;
WarningDialog::show(this, tr("Cannot add container to same container\n%1")
.arg(FileDialog::normalized(container)))->setCancelText(tr("CANCEL"));
return false;
}

void MainWindow::warningClicked(const QString &link)
Expand Down Expand Up @@ -1078,10 +1072,10 @@ bool MainWindow::wrapContainer(bool signing)
QString msg = signing ?
tr("Files can not be added to the signed container. The system will create a new container which shall contain the signed document and the files you wish to add.") :
tr("Files can not be added to the cryptocontainer. The system will create a new container which shall contain the cypto-document and the files you wish to add.");
WarningDialog dlg(msg, this);
dlg.setCancelText(tr("CANCEL"));
dlg.addButton(tr("CONTINUE"), ContainerSave);
return dlg.exec() == ContainerSave;
auto *dlg = new WarningDialog(msg, this);
dlg->setCancelText(tr("CANCEL"));
dlg->addButton(tr("CONTINUE"), ContainerSave);
return dlg->exec() == ContainerSave;
}

void MainWindow::updateSelector()
Expand Down
11 changes: 6 additions & 5 deletions client/QSigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "QPKCS11.h"
#include "SslCertificate.h"
#include "Utils.h"
#include "dialogs/WarningDialog.h"

#include <digidocpp/Conf.h>
#include <digidocpp/crypto/X509Cert.h>
Expand Down Expand Up @@ -90,8 +91,8 @@ QSigner::QSigner(QObject *parent)
EC_KEY_METHOD_set_sign(d->ecmethod, sign, sign_setup, Private::ecdsa_do_sign);

d->smartcard = new QSmartCard(parent);
connect(this, &QSigner::error, qApp, [](const QString &msg) {
qApp->showWarning(msg);
connect(this, &QSigner::error, this, [](const QString &msg) {
WarningDialog::show(msg);
});
connect(this, &QSigner::signDataChanged, this, [this](const TokenData &token) {
std::string method = (CONF(signatureDigestUri));
Expand Down Expand Up @@ -199,7 +200,7 @@ QByteArray QSigner::decrypt(std::function<QByteArray (QCryptoBackend *)> &&func)
QCardLock::instance().exclusiveUnlock();
return {};
case QCryptoBackend::PinIncorrect:
qApp->showWarning(QCryptoBackend::errorString(status));
(new WarningDialog(QCryptoBackend::errorString(status), Application::mainWindow()))->exec();
continue;
case QCryptoBackend::PinLocked:
QCardLock::instance().exclusiveUnlock();
Expand Down Expand Up @@ -240,7 +241,7 @@ QSslKey QSigner::key() const
{
case QCryptoBackend::PinOK: break;
case QCryptoBackend::PinIncorrect:
qApp->showWarning(QCryptoBackend::errorString(status));
(new WarningDialog(QCryptoBackend::errorString(status), Application::mainWindow()))->exec();
continue;
case QCryptoBackend::PinLocked:
default:
Expand Down Expand Up @@ -408,7 +409,7 @@ std::vector<unsigned char> QSigner::sign(const std::string &method, const std::v
d->smartcard->reload(); // QSmartCard should also know that PIN2 info is updated
throwException((tr("Failed to login token") + " " + QCryptoBackend::errorString(status)), Exception::PINCanceled)
case QCryptoBackend::PinIncorrect:
qApp->showWarning(QCryptoBackend::errorString(status));
(new WarningDialog(QCryptoBackend::errorString(status), Application::mainWindow()))->exec();
continue;
case QCryptoBackend::PinLocked:
QCardLock::instance().exclusiveUnlock();
Expand Down
20 changes: 10 additions & 10 deletions client/dialogs/AddRecipients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,22 @@ bool AddRecipients::addRecipientToRightPane(const CKey &key, bool update)
auto expiryDate = key.cert.expiryDate();
if(expiryDate <= QDateTime::currentDateTime())
{
WarningDialog dlg(tr("Are you sure that you want use certificate for encrypting, which expired on %1?<br />"
"When decrypter has updated certificates then decrypting is impossible.")
.arg(expiryDate.toString(QStringLiteral("dd.MM.yyyy hh:mm:ss"))), this);
dlg.setCancelText(tr("NO"));
dlg.addButton(tr("YES"), QMessageBox::Yes);
if(dlg.exec() != QMessageBox::Yes)
auto *dlg = new WarningDialog(tr("Are you sure that you want use certificate for encrypting, which expired on %1?<br />"
"When decrypter has updated certificates then decrypting is impossible.")
.arg(expiryDate.toString(QStringLiteral("dd.MM.yyyy hh:mm:ss"))), this);
dlg->setCancelText(tr("NO"));
dlg->addButton(tr("YES"), QMessageBox::Yes);
if(dlg->exec() != QMessageBox::Yes)
return false;
}
QList<QSslError> errors = QSslCertificate::verify({ key.cert });
errors.removeAll(QSslError(QSslError::CertificateExpired, key.cert));
if(!errors.isEmpty())
{
WarningDialog dlg(tr("Recipient’s certification chain contains certificates that are not trusted. Continue with encryption?"), this);
dlg.setCancelText(tr("NO"));
dlg.addButton(tr("YES"), QMessageBox::Yes);
if(dlg.exec() != QMessageBox::Yes)
auto *dlg = new WarningDialog(tr("Recipient’s certification chain contains certificates that are not trusted. Continue with encryption?"), this);
dlg->setCancelText(tr("NO"));
dlg->addButton(tr("YES"), QMessageBox::Yes);
if(dlg->exec() != QMessageBox::Yes)
return false;
}
}
Expand Down
Loading

0 comments on commit 7686eab

Please sign in to comment.