Skip to content

Commit b042db3

Browse files
committed
fix(ui): show waiting for card page by default
Signed-off-by: Mart Somermaa <[email protected]>
1 parent b05e23b commit b042db3

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/controller/controller.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ void Controller::run()
9999

100100
void Controller::startCommandExecution()
101101
{
102+
REQUIRE_NON_NULL(commandHandler)
103+
102104
// Reader monitor thread setup.
103105
WaitForCardThread* waitForCardThread = new WaitForCardThread(this);
104106
connect(waitForCardThread, &WaitForCardThread::statusUpdate, this,
@@ -108,7 +110,7 @@ void Controller::startCommandExecution()
108110
saveChildThreadPtrAndConnectFailureFinish(waitForCardThread);
109111

110112
// UI setup.
111-
window = WebEidUI::createAndShowDialog(CommandType::INSERT_CARD);
113+
window = WebEidUI::createAndShowDialog(commandHandler->commandType());
112114
connect(this, &Controller::statusUpdate, window.get(), &WebEidUI::onSmartCardStatusUpdate);
113115
connectOkCancelWaitingForPinPad();
114116

@@ -157,6 +159,7 @@ void Controller::onCardsAvailable(const std::vector<electronic_id::CardInfo::ptr
157159
{
158160
try {
159161
REQUIRE_NON_NULL(commandHandler)
162+
REQUIRE_NON_NULL(window)
160163
REQUIRE_NOT_EMPTY_CONTAINS_NON_NULL_PTRS(availableCards)
161164

162165
for (const auto& card : availableCards) {
@@ -165,12 +168,7 @@ void Controller::onCardsAvailable(const std::vector<electronic_id::CardInfo::ptr
165168
qInfo() << "Using smart card protocol" << protocol << "for card" << card->eid().name();
166169
}
167170

168-
if (!window) {
169-
window = WebEidUI::createAndShowDialog(commandHandler->commandType());
170-
connectOkCancelWaitingForPinPad();
171-
} else {
172-
window->showWaitingForCardPage(commandHandler->commandType());
173-
}
171+
window->showWaitingForCardPage(commandHandler->commandType());
174172

175173
commandHandler->connectSignals(window.get());
176174

src/controller/ui.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class WebEidUI : public QDialog
4646
static void showFatalError();
4747

4848
virtual void showWaitingForCardPage(const CommandType commandType) = 0;
49+
4950
// getPin() is called from background threads and must be thread-safe.
5051
virtual QString getPin() = 0;
5152

src/ui/webeiddialog.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ WebEidDialog::Page commandToPage(const CommandType command)
4949
using Page = WebEidDialog::Page;
5050
switch (command) {
5151
case CommandType::INSERT_CARD:
52-
return Page::MESSAGE;
52+
return Page::ALERT;
5353
case CommandType::GET_CERTIFICATE:
5454
return Page::SELECT_CERTIFICATE;
5555
case CommandType::AUTHENTICATE:
5656
case CommandType::SIGN:
57-
return Page::PININPUT;
57+
return Page::PIN_INPUT;
5858
default:
5959
THROW(ProgrammingError, "No page exists for command " + std::string(command));
6060
}
@@ -120,8 +120,7 @@ void WebEidDialog::showWaitingForCardPage(const CommandType commandType)
120120
// Don't show OK button while waiting for card operation or connect card.
121121
ui->okButton->hide();
122122

123-
ui->pageStack->setCurrentIndex(
124-
int(commandType == CommandType::INSERT_CARD ? Page::MESSAGE : Page::WAITING));
123+
ui->pageStack->setCurrentIndex(int(Page::WAITING));
125124
}
126125

127126
QString WebEidDialog::getPin()
@@ -133,6 +132,8 @@ QString WebEidDialog::getPin()
133132

134133
void WebEidDialog::onSmartCardStatusUpdate(const RetriableError status)
135134
{
135+
currentCommand = CommandType::INSERT_CARD;
136+
136137
const auto [errorText, title, icon] = retriableErrorToTextTitleAndIcon(status);
137138

138139
ui->connectCardLabel->setText(errorText);
@@ -143,7 +144,7 @@ void WebEidDialog::onSmartCardStatusUpdate(const RetriableError status)
143144
ui->helpButton->show();
144145
ui->cancelButton->show();
145146
ui->okButton->hide();
146-
ui->pageStack->setCurrentIndex(int(Page::MESSAGE));
147+
ui->pageStack->setCurrentIndex(int(Page::ALERT));
147148
}
148149

149150
/** This slot is used by the get certificate and authenticate commands in case there are multiple
@@ -201,7 +202,7 @@ void WebEidDialog::onSingleCertificateReady(const QUrl& origin,
201202
{
202203
try {
203204
const auto page = commandToPage(currentCommand);
204-
if (page == Page::MESSAGE) {
205+
if (page == Page::ALERT) {
205206
THROW(ProgrammingError, "Insert card commmand not allowed here");
206207
}
207208
switch (currentCommand) {
@@ -258,8 +259,8 @@ void WebEidDialog::onRetry(const RetriableError error)
258259

259260
void WebEidDialog::onCertificateNotFound(const QString& certificateSubject)
260261
{
261-
onRetryImpl(tr("No electronic ID card is inserted that has the signing certificate provided as "
262-
"argument. Please insert the electronic ID card that belongs to %1")
262+
onRetryImpl(tr("None of the inserted electronic ID cards has the requested signing "
263+
"certificate. Please insert the electronic ID card that belongs to %1.")
263264
.arg(certificateSubject));
264265
}
265266

@@ -357,7 +358,7 @@ void WebEidDialog::onRetryImpl(const QString& error)
357358
ui->messagePageTitleLabel->setText(tr("Error occurred"));
358359
ui->cardChipIcon->setPixmap(QStringLiteral(":/images/id-card.svg"));
359360
setupOK([this] { emit retry(); }, tr("Retry"), true);
360-
ui->pageStack->setCurrentIndex(int(Page::MESSAGE));
361+
ui->pageStack->setCurrentIndex(int(Page::ALERT));
361362
}
362363

363364
void WebEidDialog::setupPinPadProgressBarAndEmitWait(const CardCertificateAndPinInfo& certAndPin)

src/ui/webeiddialog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class WebEidDialog : public WebEidUI
4343
Q_OBJECT
4444

4545
public:
46-
enum class Page { WAITING, MESSAGE, SELECT_CERTIFICATE, PININPUT };
46+
enum class Page { WAITING, ALERT, SELECT_CERTIFICATE, PIN_INPUT };
4747

4848
explicit WebEidDialog(QWidget* parent = nullptr);
4949
~WebEidDialog() override;

tests/mock-ui/mock-ui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "ui.hpp"
2424
#include "mock-ui.hpp"
2525

26-
WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType /* command */)
26+
WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType)
2727
{
2828
return std::make_unique<MockUI>();
2929
}

0 commit comments

Comments
 (0)