Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI feedback fixes #1307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 12 additions & 5 deletions client/dialogs/MobileDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<class>MobileDialog</class>
<widget class="QDialog" name="MobileDialog">
<property name="windowModality">
<enum>Qt::WindowModality::WindowModal</enum>
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
Expand Down Expand Up @@ -41,6 +41,7 @@ padding: 10px 14px;
border: 1px solid #C4CBD8;
border-radius: 4px;
color: #07142A;
background-color: white;
placeholder-text-color: #607496;
font-size: 16px;
}
Expand Down Expand Up @@ -107,7 +108,7 @@ background-color: #2F70B6;
<number>40</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetFixedSize</enum>
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>40</number>
Expand All @@ -130,13 +131,13 @@ background-color: #2F70B6;
</size>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::TabFocus</enum>
<enum>Qt::TabFocus</enum>
</property>
<property name="text">
<string>Enter your phone number to sign with mobile-ID</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down Expand Up @@ -184,6 +185,9 @@ background-color: #2F70B6;
<height>20</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -224,6 +228,9 @@ background-color: #2F70B6;
<height>20</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -264,7 +271,7 @@ background-color: #2F70B6;
<item>
<spacer name="buttonSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
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
15 changes: 8 additions & 7 deletions client/dialogs/MobileProgress.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<class>MobileProgress</class>
<widget class="QDialog" name="MobileProgress">
<property name="windowModality">
<enum>Qt::WindowModality::WindowModal</enum>
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
Expand Down Expand Up @@ -35,6 +35,7 @@ padding: 10px 14px;
border: 1px solid #C4CBD8;
border-radius: 4px;
color: #07142A;
background-color: white;
placeholder-text-color: #607496;
font-size: 16px;
}
Expand Down Expand Up @@ -168,20 +169,20 @@ background-color: #2F70B6;
<string>Control code:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="code">
<property name="focusPolicy">
<enum>Qt::FocusPolicy::TabFocus</enum>
<enum>Qt::TabFocus</enum>
</property>
<property name="text">
<string notr="true">1234</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
Expand All @@ -191,7 +192,7 @@ background-color: #2F70B6;
<string notr="true">Make sure control code matches with one in phone screen and enter mobile-ID PIN2-code.</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand All @@ -218,7 +219,7 @@ background-color: #2F70B6;
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
<set>Qt::AlignCenter</set>
</property>
<property name="textVisible">
<bool>false</bool>
Expand All @@ -232,7 +233,7 @@ background-color: #2F70B6;
</item>
</layout>
</item>
<item alignment="Qt::AlignmentFlag::AlignHCenter">
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="cancel">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
Expand Down
20 changes: 12 additions & 8 deletions client/dialogs/PinPopup.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<class>PinPopup</class>
<widget class="QDialog" name="PinPopup">
<property name="windowModality">
<enum>Qt::WindowModality::WindowModal</enum>
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
Expand Down Expand Up @@ -38,6 +38,7 @@ padding: 10px 14px;
border: 1px solid #C4CBD8;
border-radius: 4px;
color: #07142A;
background-color: white;
placeholder-text-color: #607496;
font-size: 16px;
}
Expand Down Expand Up @@ -74,7 +75,7 @@ background-color: #2F70B6;
<number>40</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetFixedSize</enum>
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>40</number>
Expand All @@ -97,13 +98,13 @@ background-color: #2F70B6;
</size>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::TabFocus</enum>
<enum>Qt::TabFocus</enum>
</property>
<property name="text">
<string notr="true">&lt;b&gt;Mari Maasikas,&lt;/b&gt; 48405050123</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand All @@ -118,13 +119,13 @@ background-color: #2F70B6;
<item>
<widget class="QLabel" name="text">
<property name="focusPolicy">
<enum>Qt::FocusPolicy::TabFocus</enum>
<enum>Qt::TabFocus</enum>
</property>
<property name="text">
<string>You need to use a personal identification certificate for the selected activity.</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand All @@ -149,7 +150,7 @@ background-color: #2F70B6;
<item>
<widget class="QLineEdit" name="pin">
<property name="echoMode">
<enum>QLineEdit::EchoMode::Password</enum>
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
Expand All @@ -161,6 +162,9 @@ background-color: #2F70B6;
<height>20</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -194,7 +198,7 @@ background-color: #2F70B6;
<item>
<spacer name="buttonSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
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
Loading
Loading