Skip to content

Commit

Permalink
fix(ui): show waiting for card page by default
Browse files Browse the repository at this point in the history
Signed-off-by: Mart Somermaa <[email protected]>
  • Loading branch information
mrts committed May 28, 2021
1 parent b05e23b commit b042db3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
12 changes: 5 additions & 7 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void Controller::run()

void Controller::startCommandExecution()
{
REQUIRE_NON_NULL(commandHandler)

// Reader monitor thread setup.
WaitForCardThread* waitForCardThread = new WaitForCardThread(this);
connect(waitForCardThread, &WaitForCardThread::statusUpdate, this,
Expand All @@ -108,7 +110,7 @@ void Controller::startCommandExecution()
saveChildThreadPtrAndConnectFailureFinish(waitForCardThread);

// UI setup.
window = WebEidUI::createAndShowDialog(CommandType::INSERT_CARD);
window = WebEidUI::createAndShowDialog(commandHandler->commandType());
connect(this, &Controller::statusUpdate, window.get(), &WebEidUI::onSmartCardStatusUpdate);
connectOkCancelWaitingForPinPad();

Expand Down Expand Up @@ -157,6 +159,7 @@ void Controller::onCardsAvailable(const std::vector<electronic_id::CardInfo::ptr
{
try {
REQUIRE_NON_NULL(commandHandler)
REQUIRE_NON_NULL(window)
REQUIRE_NOT_EMPTY_CONTAINS_NON_NULL_PTRS(availableCards)

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

if (!window) {
window = WebEidUI::createAndShowDialog(commandHandler->commandType());
connectOkCancelWaitingForPinPad();
} else {
window->showWaitingForCardPage(commandHandler->commandType());
}
window->showWaitingForCardPage(commandHandler->commandType());

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

Expand Down
1 change: 1 addition & 0 deletions src/controller/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class WebEidUI : public QDialog
static void showFatalError();

virtual void showWaitingForCardPage(const CommandType commandType) = 0;

// getPin() is called from background threads and must be thread-safe.
virtual QString getPin() = 0;

Expand Down
19 changes: 10 additions & 9 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ WebEidDialog::Page commandToPage(const CommandType command)
using Page = WebEidDialog::Page;
switch (command) {
case CommandType::INSERT_CARD:
return Page::MESSAGE;
return Page::ALERT;
case CommandType::GET_CERTIFICATE:
return Page::SELECT_CERTIFICATE;
case CommandType::AUTHENTICATE:
case CommandType::SIGN:
return Page::PININPUT;
return Page::PIN_INPUT;
default:
THROW(ProgrammingError, "No page exists for command " + std::string(command));
}
Expand Down Expand Up @@ -120,8 +120,7 @@ void WebEidDialog::showWaitingForCardPage(const CommandType commandType)
// Don't show OK button while waiting for card operation or connect card.
ui->okButton->hide();

ui->pageStack->setCurrentIndex(
int(commandType == CommandType::INSERT_CARD ? Page::MESSAGE : Page::WAITING));
ui->pageStack->setCurrentIndex(int(Page::WAITING));
}

QString WebEidDialog::getPin()
Expand All @@ -133,6 +132,8 @@ QString WebEidDialog::getPin()

void WebEidDialog::onSmartCardStatusUpdate(const RetriableError status)
{
currentCommand = CommandType::INSERT_CARD;

const auto [errorText, title, icon] = retriableErrorToTextTitleAndIcon(status);

ui->connectCardLabel->setText(errorText);
Expand All @@ -143,7 +144,7 @@ void WebEidDialog::onSmartCardStatusUpdate(const RetriableError status)
ui->helpButton->show();
ui->cancelButton->show();
ui->okButton->hide();
ui->pageStack->setCurrentIndex(int(Page::MESSAGE));
ui->pageStack->setCurrentIndex(int(Page::ALERT));
}

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

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

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

void WebEidDialog::setupPinPadProgressBarAndEmitWait(const CardCertificateAndPinInfo& certAndPin)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/webeiddialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WebEidDialog : public WebEidUI
Q_OBJECT

public:
enum class Page { WAITING, MESSAGE, SELECT_CERTIFICATE, PININPUT };
enum class Page { WAITING, ALERT, SELECT_CERTIFICATE, PIN_INPUT };

explicit WebEidDialog(QWidget* parent = nullptr);
~WebEidDialog() override;
Expand Down
2 changes: 1 addition & 1 deletion tests/mock-ui/mock-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "ui.hpp"
#include "mock-ui.hpp"

WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType /* command */)
WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType)
{
return std::make_unique<MockUI>();
}
Expand Down

0 comments on commit b042db3

Please sign in to comment.