Skip to content

Commit

Permalink
Show background Overlay and cleanup code (open-eid#1210)
Browse files Browse the repository at this point in the history
IB-7706

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Aug 15, 2023
1 parent 4e3015e commit b0766bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions client/dialogs/PinPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ui_PinPopup.h"
#include "Styles.h"
#include "SslCertificate.h"
#include "effects/Overlay.h"

#include <QtCore/QTimeLine>
#include <QtGui/QRegularExpressionValidator>
Expand All @@ -41,14 +42,15 @@ PinPopup::PinPopup(PinFlags flags, const SslCertificate &c, TokenFlags count, QW
}
}

PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidget *parent, const QString &bodyText)
PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidget *parent, QString text)
: QDialog(parent)
, ui(new Ui::PinPopup)
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
for(QLineEdit *w: findChildren<QLineEdit*>())
w->setAttribute(Qt::WA_MacShowFocusRect, false);
new Overlay(this, parent);

ui->labelNameId->setFont(Styles::font(Styles::Regular, 20, QFont::DemiBold));
ui->label->setFont(Styles::font(Styles::Regular, 14));
Expand All @@ -60,13 +62,7 @@ PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidg
connect( this, &PinPopup::finished, this, &PinPopup::close );
connect(ui->pin, &QLineEdit::returnPressed, ui->ok, &QPushButton::click);

QString text;

if(!bodyText.isEmpty())
{
text = bodyText;
}
else
if(text.isEmpty())
{
if(count & PinFinalTry)
text += QStringLiteral("<font color='red'><b>%1</b></font><br />").arg(tr("PIN will be locked next failed attempt"));
Expand All @@ -78,15 +74,15 @@ PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidg
QString t = flags & PinpadFlag ?
tr("For using sign certificate enter PIN2 at the reader") :
tr("For using sign certificate enter PIN2");
text += tr("Selected action requires sign certificate.") + QStringLiteral("<br />") + t;
text += tr("Selected action requires sign certificate.") + QLatin1String("<br />") + t;
setPinLen(5);
}
else
{
QString t = flags & PinpadFlag ?
tr("For using authentication certificate enter PIN1 at the reader") :
tr("For using authentication certificate enter PIN1");
text += tr("Selected action requires authentication certificate.") + QStringLiteral("<br />") + t;
text += tr("Selected action requires authentication certificate.") + QLatin1String("<br />") + t;
setPinLen(4);
}
}
Expand All @@ -102,7 +98,7 @@ PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidg
ui->pin->hide();
ui->ok->hide();
ui->cancel->hide();
QSvgWidget *movie = new QSvgWidget(QStringLiteral(":/images/wait.svg"), this);
auto *movie = new QSvgWidget(QStringLiteral(":/images/wait.svg"), this);
movie->setFixedSize(ui->pin->size().height(), ui->pin->size().height());
movie->show();
ui->PinPopupLayout->addWidget(movie, 0, Qt::AlignCenter);
Expand All @@ -112,14 +108,14 @@ PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidg
ui->pin->hide();
ui->ok->hide();
ui->cancel->hide();
QProgressBar *progress = new QProgressBar( this );
auto *progress = new QProgressBar(this);
progress->setRange( 0, 30 );
progress->setValue( progress->maximum() );
progress->setTextVisible( false );
progress->resize( 200, 30 );
progress->move( 153, 122 );
ui->PinPopupLayout->addWidget(progress);
QTimeLine *statusTimer = new QTimeLine( progress->maximum() * 1000, this );
auto *statusTimer = new QTimeLine(progress->maximum() * 1000, this);
statusTimer->setEasingCurve(QEasingCurve::Linear);
statusTimer->setFrameRange( progress->maximum(), progress->minimum() );
connect( statusTimer, &QTimeLine::frameChanged, progress, &QProgressBar::setValue );
Expand All @@ -146,7 +142,7 @@ PinPopup::~PinPopup()

void PinPopup::setPinLen(unsigned long minLen, unsigned long maxLen)
{
QString charPattern = regexp.pattern().startsWith(QStringLiteral("^.")) ? QStringLiteral(".") : QStringLiteral("\\d");
QString charPattern = regexp.pattern().startsWith(QLatin1String("^.")) ? QStringLiteral(".") : QStringLiteral("\\d");
regexp.setPattern(QStringLiteral("^%1{%2,%3}$").arg(charPattern).arg(minLen).arg(maxLen));
}

Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/PinPopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PinPopup final : public QDialog
Q_DECLARE_FLAGS(TokenFlags, TokenFlag)

PinPopup(PinFlags flags, const SslCertificate &cert, TokenFlags count, QWidget *parent = {});
PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidget *parent = {}, const QString &bodyText = {});
PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidget *parent = {}, QString text = {});
~PinPopup() final;

void setPinLen(unsigned long minLen, unsigned long maxLen = 12);
Expand Down

0 comments on commit b0766bf

Please sign in to comment.