From ec45ae54e08937508ca22d7b227e1b8cbe9add6a Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Sat, 29 May 2021 13:43:21 +0300 Subject: [PATCH] Show fatal error in same style WE2-439 Signed-off-by: Raul Metsma --- src/controller/controller.cpp | 5 +---- src/controller/ui.hpp | 3 +-- src/ui/dialog.ui | 41 ++++++++++++++++++++++++++++++++--- src/ui/images/fatal.svg | 7 ++++++ src/ui/ui.cpp | 9 -------- src/ui/web-eid-resources.qrc | 1 + src/ui/webeiddialog.cpp | 19 ++++++++++++---- src/ui/webeiddialog.hpp | 1 + tests/mock-ui/mock-ui.cpp | 2 -- 9 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 src/ui/images/fatal.svg diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index c039eccc..7267c75c 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -333,10 +333,7 @@ void Controller::onCriticalFailure(const QString& error) << "fatal error:" << error; writeResponseToStdOut(isInStdinMode, makeErrorObject(RESP_TECH_ERROR, error), commandType()); - // Dispose the UI. - window.reset(); - - WebEidUI::showFatalError(); + WebEidUI::createAndShowDialog(CommandType(CommandType::INSERT_CARD))->showFatalError(); exit(); } diff --git a/src/controller/ui.hpp b/src/controller/ui.hpp index 6af29618..96732a33 100644 --- a/src/controller/ui.hpp +++ b/src/controller/ui.hpp @@ -43,8 +43,7 @@ class WebEidUI : public QDialog // Factory function that creates and shows the dialog that implements this interface. static ptr createAndShowDialog(const CommandType command); - static void showFatalError(); - + virtual void showFatalError() {} virtual void showWaitingForCardPage(const CommandType commandType) = 0; // getPin() is called from background threads and must be thread-safe. diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui index dc90de90..1ae1aca6 100644 --- a/src/ui/dialog.ui +++ b/src/ui/dialog.ui @@ -100,11 +100,11 @@ max-height: 20px; #pinErrorLabel { color: #F04E23; } -#smartCardErrorLabel { +#smartCardError { border: 1px solid rgba(240,78,35,0.1); border-radius: 3px; -padding: 10px; color: #F04E23; +min-height: 56px; } #helpButton { color: #003168; @@ -238,7 +238,7 @@ color: #003168; Qt::TabFocus - Insert an ID card + Insert an ID card @@ -281,6 +281,41 @@ color: #003168; + + + + + 8 + + + 10 + + + 10 + + + 10 + + + 10 + + + + + :/images/fatal.svg + + + + + + + A fatal error occurred, check the logs for more details + + + + + + diff --git a/src/ui/images/fatal.svg b/src/ui/images/fatal.svg new file mode 100644 index 00000000..a7c1d1a1 --- /dev/null +++ b/src/ui/images/fatal.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index fdb8d590..291c5ecd 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -20,11 +20,8 @@ * SOFTWARE. */ -#include "ui.hpp" #include "webeiddialog.hpp" -#include - WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType command) { auto dialog = std::make_unique(); @@ -35,9 +32,3 @@ WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType command) return dialog; } - -void WebEidUI::showFatalError() -{ - QMessageBox::critical(nullptr, tr("Web eID: fatal error"), - tr("A fatal error occurred, check the logs for more details")); -} diff --git a/src/ui/web-eid-resources.qrc b/src/ui/web-eid-resources.qrc index dcf2bcd4..7cb47da1 100644 --- a/src/ui/web-eid-resources.qrc +++ b/src/ui/web-eid-resources.qrc @@ -2,6 +2,7 @@ images/arrow.svg images/cardreader.svg + images/fatal.svg images/help.svg images/id-card.svg images/origin.svg diff --git a/src/ui/webeiddialog.cpp b/src/ui/webeiddialog.cpp index 58fac660..0502a969 100644 --- a/src/ui/webeiddialog.cpp +++ b/src/ui/webeiddialog.cpp @@ -81,11 +81,12 @@ WebEidDialog::WebEidDialog(QWidget* parent) : WebEidUI(parent), ui(new Private) ui->pinInput->setAttribute(Qt::WA_MacShowFocusRect, false); ui->waitingSpinner->load(QStringLiteral(":/images/wait.svg")); ui->selectionGroup = new QButtonGroup(this); + ui->smartCardError->hide(); connect(ui->pageStack, &QStackedWidget::currentChanged, this, &WebEidDialog::resizeHeight); connect(ui->selectionGroup, qOverload(&QButtonGroup::buttonClicked), this, [this] { ui->okButton->setEnabled(true); }); - connect(ui->cancelButton, &QPushButton::clicked, this, &WebEidDialog::rejected); + connect(ui->cancelButton, &QPushButton::clicked, this, &WebEidDialog::reject); connect(ui->helpButton, &QPushButton::clicked, this, [] { QDesktopServices::openUrl(tr("https://www.id.ee/en/")); }); @@ -114,6 +115,19 @@ WebEidDialog::~WebEidDialog() delete ui; } +void WebEidDialog::showFatalError() +{ + ui->messagePageTitleLabel->setText(tr("Fatal error")); + ui->smartCardError->show(); + ui->connectCardLabel->hide(); + ui->cardChipIcon->hide(); + ui->helpButton->show(); + ui->cancelButton->show(); + ui->okButton->hide(); + ui->pageStack->setCurrentIndex(int(Page::ALERT)); + exec(); +} + void WebEidDialog::showWaitingForCardPage(const CommandType commandType) { currentCommand = commandType; @@ -442,9 +456,6 @@ void WebEidDialog::displayPinRetriesRemaining(PinInfo::PinRetriesCount pinRetrie ui->pinErrorLabel->setText(tr("%n retries left", nullptr, int(pinRetriesCount.first))); ui->pinErrorLabel->show(); } - if (!ui->pinEntryTimeoutProgressBar->isVisible()) { - ui->pinInput->setFocus(); - } } void WebEidDialog::displayPinBlockedError() diff --git a/src/ui/webeiddialog.hpp b/src/ui/webeiddialog.hpp index 6b943b66..7c6b227a 100644 --- a/src/ui/webeiddialog.hpp +++ b/src/ui/webeiddialog.hpp @@ -48,6 +48,7 @@ class WebEidDialog : public WebEidUI explicit WebEidDialog(QWidget* parent = nullptr); ~WebEidDialog() override; + void showFatalError() override; void showWaitingForCardPage(const CommandType commandType) override; QString getPin() override; diff --git a/tests/mock-ui/mock-ui.cpp b/tests/mock-ui/mock-ui.cpp index 9b0a1dab..d97332ac 100644 --- a/tests/mock-ui/mock-ui.cpp +++ b/tests/mock-ui/mock-ui.cpp @@ -27,5 +27,3 @@ WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType) { return std::make_unique(); } - -void WebEidUI::showFatalError() {}