Skip to content

Commit

Permalink
Show fatal error in same style
Browse files Browse the repository at this point in the history
WE2-439

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored and mrts committed Jun 11, 2021
1 parent da9815b commit ec45ae5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 24 deletions.
5 changes: 1 addition & 4 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 1 addition & 2 deletions src/controller/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
41 changes: 38 additions & 3 deletions src/ui/dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -238,7 +238,7 @@ color: #003168;
<enum>Qt::TabFocus</enum>
</property>
<property name="text">
<string>Insert an ID card</string>
<string notr="true">Insert an ID card</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -281,6 +281,41 @@ color: #003168;
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="smartCardError" native="true">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
<property name="spacing">
<number>8</number>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="smartCardErrorIcon">
<property name="pixmap">
<pixmap resource="web-eid-resources.qrc">:/images/fatal.svg</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="smartCardErrorLabel">
<property name="text">
<string>A fatal error occurred, check the logs for more details</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="messagePageSpacer">
<property name="orientation">
Expand Down
7 changes: 7 additions & 0 deletions src/ui/images/fatal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions src/ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
* SOFTWARE.
*/

#include "ui.hpp"
#include "webeiddialog.hpp"

#include <QMessageBox>

WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType command)
{
auto dialog = std::make_unique<WebEidDialog>();
Expand All @@ -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"));
}
1 change: 1 addition & 0 deletions src/ui/web-eid-resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource prefix="/">
<file>images/arrow.svg</file>
<file>images/cardreader.svg</file>
<file>images/fatal.svg</file>
<file>images/help.svg</file>
<file>images/id-card.svg</file>
<file>images/origin.svg</file>
Expand Down
19 changes: 15 additions & 4 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QAbstractButton*>(&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/")); });

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/ui/webeiddialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions tests/mock-ui/mock-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,3 @@ WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType)
{
return std::make_unique<MockUI>();
}

void WebEidUI::showFatalError() {}

0 comments on commit ec45ae5

Please sign in to comment.