Skip to content

Commit cf4b145

Browse files
metsmamrts
authored andcommitted
Quit application after closing fatal error page
WE2-573 Signed-off-by: Raul Metsma <[email protected]>
1 parent 0ae8e4f commit cf4b145

File tree

3 files changed

+31
-41
lines changed

3 files changed

+31
-41
lines changed

src/ui/ui.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ void WebEidUI::showAboutPage()
4343

4444
void WebEidUI::showFatalError()
4545
{
46-
auto dialog = WebEidDialog {};
47-
dialog.showFatalErrorPage();
46+
WebEidDialog::showFatalErrorPage();
4847
}

src/ui/webeiddialog.cpp

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@
3535
#include <QUrl>
3636
#include <application.hpp>
3737

38-
#define CATCH_AND_EMIT_FAILURE_AND_RETURN() \
39-
catch (std::exception & e) \
40-
{ \
41-
emit failure(e.what()); \
42-
return; \
43-
}
44-
4538
using namespace electronic_id;
4639

4740
class WebEidDialog::Private : public Ui::WebEidDialog
@@ -133,16 +126,20 @@ void WebEidDialog::showAboutPage()
133126

134127
void WebEidDialog::showFatalErrorPage()
135128
{
136-
ui->messagePageTitleLabel->setText(tr("Operation failed"));
137-
ui->fatalError->show();
138-
ui->fatalHelp->show();
139-
ui->connectCardLabel->hide();
140-
ui->cardChipIcon->hide();
141-
ui->helpButton->show();
142-
ui->cancelButton->show();
143-
ui->okButton->hide();
144-
ui->pageStack->setCurrentIndex(int(Page::ALERT));
145-
exec();
129+
WebEidDialog* d = new WebEidDialog();
130+
d->setAttribute(Qt::WA_DeleteOnClose);
131+
d->ui->messagePageTitleLabel->setText(tr("Operation failed"));
132+
d->ui->fatalError->show();
133+
d->ui->fatalHelp->show();
134+
d->ui->connectCardLabel->hide();
135+
d->ui->cardChipIcon->hide();
136+
d->ui->helpButton->show();
137+
d->ui->cancelButton->show();
138+
d->ui->okButton->hide();
139+
d->ui->pageStack->setCurrentIndex(int(Page::ALERT));
140+
d->adjustSize();
141+
d->open();
142+
connect(d, &WebEidDialog::finished, qApp, &QApplication::quit);
146143
}
147144

148145
void WebEidDialog::showWaitingForCardPage(const CommandType commandType)
@@ -193,29 +190,21 @@ void WebEidDialog::onMultipleCertificatesReady(
193190

194191
if (CertificateButton* button =
195192
qobject_cast<CertificateButton*>(ui->selectionGroup->checkedButton())) {
196-
try {
197-
switch (currentCommand) {
198-
case CommandType::GET_SIGNING_CERTIFICATE:
199-
setupOK([this, button] { emit accepted(button->certificateInfo()); });
200-
break;
201-
case CommandType::AUTHENTICATE:
202-
// Authenticate continues with the selected certificate to
203-
// onSingleCertificateReady().
204-
setupOK([this, origin, button] {
205-
try {
206-
onSingleCertificateReady(origin, button->certificateInfo());
207-
}
208-
CATCH_AND_EMIT_FAILURE_AND_RETURN()
209-
});
210-
break;
211-
default:
212-
THROW(ProgrammingError,
213-
"Command " + std::string(currentCommand) + " not allowed here");
214-
}
215193

194+
switch (currentCommand) {
195+
case CommandType::GET_SIGNING_CERTIFICATE:
196+
setupOK([this, button] { emit accepted(button->certificateInfo()); });
216197
ui->pageStack->setCurrentIndex(int(Page::SELECT_CERTIFICATE));
198+
break;
199+
case CommandType::AUTHENTICATE:
200+
// Authenticate continues with the selected certificate to onSingleCertificateReady().
201+
onSingleCertificateReady(origin, button->certificateInfo());
202+
break;
203+
default:
204+
emit failure(QStringLiteral("Command %1 not allowed here")
205+
.arg(std::string(currentCommand).c_str()));
206+
return;
217207
}
218-
CATCH_AND_EMIT_FAILURE_AND_RETURN()
219208
} else {
220209
emit failure(QStringLiteral("CertificateButton not found"));
221210
}
@@ -279,8 +268,10 @@ void WebEidDialog::onSingleCertificateReady(const QUrl& origin,
279268
}
280269

281270
ui->pageStack->setCurrentIndex(int(WebEidDialog::Page::PIN_INPUT));
271+
} catch (std::exception& e) {
272+
emit failure(e.what());
273+
return;
282274
}
283-
CATCH_AND_EMIT_FAILURE_AND_RETURN()
284275
}
285276

286277
void WebEidDialog::onRetry(const RetriableError error)

src/ui/webeiddialog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class WebEidDialog : public WebEidUI
5252
QString getPin() override;
5353

5454
static void showAboutPage();
55-
void showFatalErrorPage();
55+
static void showFatalErrorPage();
5656

5757
public: // slots
5858
void onSmartCardStatusUpdate(const RetriableError status) override;

0 commit comments

Comments
 (0)