Skip to content

Commit

Permalink
UI feedback fixes
Browse files Browse the repository at this point in the history
IB-8249

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Nov 27, 2024
1 parent 000ed65 commit fb0ef98
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
24 changes: 12 additions & 12 deletions client/QPCSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Q_LOGGING_CATEGORY(SCard,"QPCSC.SCard")

static quint16 toUInt16(const QByteArray &data, int size)
{
return size >= 2 ? quint16((quint16(data[size - 2]) << 8) | quint16(data[size - 1])) : 0;
return size >= 2 ? quint16((quint16(data[size - 2]) << 8) | quint8(data[size - 1])) : 0;
}

static QStringList stateToString(DWORD state)
Expand All @@ -58,31 +58,31 @@ static QStringList stateToString(DWORD state)
return result;
}

template<typename Func, typename... Args>
static auto SCCall(const char *file, int line, const char *function, Func func, Args... args)
template<auto Func, typename... Args>
static auto SCCall(const char *file, int line, const char *function, Args... args)
{
auto err = func(args...);
auto err = Func(args...);
if(SCard().isDebugEnabled())
QMessageLogger(file, line, function, SCard().categoryName()).debug()
<< function << Qt::hex << (unsigned long)err;
return err;
}
#define SC(API, ...) SCCall(__FILE__, __LINE__, "SCard"#API, SCard##API, __VA_ARGS__)
#define SC(API, ...) SCCall<SCard##API>(__FILE__, __LINE__, "SCard"#API, __VA_ARGS__)

QHash<DRIVER_FEATURES,quint32> QPCSCReader::Private::features()
{
if(!featuresList.isEmpty())
return featuresList;
DWORD size = 0;
std::array<BYTE,256> feature{};
if(SC(Control, card, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0U, feature.data(), DWORD(feature.size()), &size))
std::array<PCSC_TLV_STRUCTURE,FEATURE_CCID_ESC_COMMAND> feature{};
if(SC(Control, card, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0U, feature.data(), DWORD(feature.size() * sizeof(PCSC_TLV_STRUCTURE)), &size))
return featuresList;
for(auto p = feature.cbegin(); std::distance(feature.cbegin(), p) < size; )
if(size % sizeof(PCSC_TLV_STRUCTURE))
return featuresList;
for(const auto &f: feature)
{
unsigned int tag = *p++, len = *p++, value = 0;
for(unsigned int i = 0; i < len; ++i)
value |= *p++ << 8 * i;
featuresList[DRIVER_FEATURES(tag)] = qFromBigEndian<quint32>(value);
if(f.tag)
featuresList[DRIVER_FEATURES(f.tag)] = qFromBigEndian<quint32>(f.value);
}
return featuresList;
}
Expand Down
4 changes: 2 additions & 2 deletions client/QSmartCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ QSmartCard::ErrorType QSmartCard::pinChange(QSmartCardData::PinType type, QWidge
else
{
SslCertificate cert = d->t.authCert();
title = cert.toString(cert.showCN() ? QStringLiteral("<b>CN,</b> serialNumber") : QStringLiteral("<b>GN SN,</b> serialNumber"));
title = cert.toString(cert.showCN() ? QStringLiteral("CN, serialNumber") : QStringLiteral("GN SN, serialNumber"));
textBody = tr("To change %1 on a PinPad reader the old %1 code has to be entered first and then the new %1 code twice.").arg(QSmartCardData::typeString(type));
}
return change(type, parent, newPin, oldPin, title, textBody);
Expand All @@ -407,7 +407,7 @@ QSmartCard::ErrorType QSmartCard::pinUnblock(QSmartCardData::PinType type, bool
else
{
SslCertificate cert = d->t.authCert();
title = cert.toString(cert.showCN() ? QStringLiteral("<b>CN,</b> serialNumber") : QStringLiteral("<b>GN SN,</b> serialNumber"));
title = cert.toString(cert.showCN() ? QStringLiteral("CN, serialNumber") : QStringLiteral("GN SN, serialNumber"));
textBody = isForgotPin ?
tr("To change %1 code with the PUK code on a PinPad reader the PUK code has to be entered first and then the %1 code twice.").arg(QSmartCardData::typeString(type)) :
tr("To unblock the %1 code on a PinPad reader the PUK code has to be entered first and then the %1 code twice.").arg(QSmartCardData::typeString(type));
Expand Down
1 change: 1 addition & 0 deletions client/dialogs/MobileProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ MobileProgress::MobileProgress(QWidget *parent)
d->setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint);
d->setupUi(d);
d->code->setBuddy(d->signProgressBar);
d->code->clear();
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
const auto styleSheet = R"(QProgressBar {
background-color: #d3d3d3;
Expand Down
25 changes: 12 additions & 13 deletions client/dialogs/PinUnblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
new Overlay(this);

auto pattern = [](QSmartCardData::PinType type) {
return QStringLiteral("^\\d{%1,12}$").arg(QSmartCardData::minPinLen(type));
return QRegularExpression(QStringLiteral("^\\d{%1,12}$").arg(QSmartCardData::minPinLen(type)));
};

QRegularExpression regexpValidateCode;
QRegularExpression regexpNewCode;
regexpNewCode.setPattern(pattern(type));
QRegularExpression regexpNewCode = pattern(type);
switch(mode)
{
case PinUnblock::UnBlockPinWithPuk:
ui->label->setText(tr("%1 unblocking").arg(QSmartCardData::typeString(type)));
ui->change->setText(tr("Unblock"));
regexpValidateCode.setPattern(pattern(QSmartCardData::PukType));
regexpValidateCode = pattern(QSmartCardData::PukType);
ui->line1_text->setText(tr("To unblock the certificate you have to enter the PUK code."));
ui->line2_text->setText(tr("You can find your PUK code inside the ID-card codes envelope."));
ui->line3_text->setText(tr("If you have forgotten the PUK code for your ID card, please visit "
Expand All @@ -65,7 +64,7 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
break;
case PinUnblock::ChangePinWithPuk:
ui->label->setText(tr("%1 code change").arg(QSmartCardData::typeString(type)));
regexpValidateCode.setPattern(pattern(QSmartCardData::PukType));
regexpValidateCode = pattern(QSmartCardData::PukType);
ui->line1_text->setText(type == QSmartCardData::Pin2Type
? tr("PIN2 code is used to digitally sign documents.")
: tr("PIN1 code is used for confirming the identity of a person."));
Expand All @@ -75,7 +74,7 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
case PinUnblock::PinChange:
ui->label->setText(tr("%1 code change").arg(QSmartCardData::typeString(type)));
ui->labelPuk->setText(tr("Valid %1 code").arg(QSmartCardData::typeString(type)));
regexpValidateCode.setPattern(pattern(type));
regexpValidateCode = pattern(type);
if(type == QSmartCardData::PukType)
{
ui->line1_text->setText(tr("PUK code is used for unblocking the certificates, when PIN1 or PIN2 has been entered 3 times incorrectly."));
Expand All @@ -100,8 +99,14 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
ui->repeat->setValidator(new QRegularExpressionValidator(regexpNewCode, ui->repeat));
ui->puk->setValidator(new QRegularExpressionValidator(regexpValidateCode, ui->puk));

auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) {
input->setStyleSheet(msg.isEmpty() ? QString() : QStringLiteral("border-color: #BE7884"));
error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus);
error->setText(msg);
error->setHidden(msg.isEmpty());
};
if(leftAttempts < 3)
ui->errorPuk->setText(mode == PinUnblock::PinChange ?
setError(ui->puk, ui->errorPuk, mode == PinUnblock::PinChange ?
tr("Remaining attempts: %1").arg(leftAttempts) :
tr("PUK remaining attempts: %1").arg(leftAttempts));

Expand All @@ -113,12 +118,6 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
if(auto *bullet = findChild<QLabel*>(QStringLiteral("line%1_bullet").arg(i)))
bullet->setHidden(isHidden);
}
auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) {
input->setStyleSheet(msg.isEmpty() ? QString() : QStringLiteral("border-color: #BE7884"));
error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus);
error->setText(msg);
error->setHidden(msg.isEmpty());
};
connect(ui->cancel, &QPushButton::clicked, this, &PinUnblock::reject);
connect(this, &PinUnblock::finished, this, &PinUnblock::close);
connect(ui->pin, &QLineEdit::returnPressed, ui->change, &QPushButton::click);
Expand Down
1 change: 1 addition & 0 deletions client/dialogs/SmartIDProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ SmartIDProgress::SmartIDProgress(QWidget *parent)
d->setupUi(d);
d->signProgressBar->setMaximum(100);
d->code->setBuddy(d->signProgressBar);
d->code->clear();
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
const auto styleSheet = R"(QProgressBar {
background-color: #d3d3d3;;
Expand Down

0 comments on commit fb0ef98

Please sign in to comment.