Skip to content

Commit

Permalink
Fix Coverity warnings (open-eid#1070)
Browse files Browse the repository at this point in the history
* Fix Coverity warnings

IB-7145

Signed-off-by: Raul Metsma <[email protected]>

* Fix Coverity warnings

IB-7145

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored May 20, 2022
1 parent 0c48246 commit 94adb1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 44 deletions.
79 changes: 37 additions & 42 deletions client/dialogs/PinUnblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,67 +35,51 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
, birthDate(birthDate)
, personalCode(std::move(personalCode))
{
new Overlay(this, parent->topLevelWidget());
init( mode, type, leftAttempts );
QSizePolicy sp_retain = ui->labelPinValidation->sizePolicy();
sp_retain.setRetainSizeWhenHidden(true);
ui->labelPinValidation->setSizePolicy(sp_retain);
ui->labelNameId->setFont(Styles::font(Styles::Regular, 20, QFont::DemiBold));
adjustSize();
setFixedSize( size() );
}

PinUnblock::~PinUnblock()
{
delete ui;
}

void PinUnblock::init( WorkMode mode, QSmartCardData::PinType type, short leftAttempts )
{
ui->setupUi( this );
ui->setupUi(this);
#if defined (Q_OS_WIN)
ui->horizontalLayout->setDirection(QBoxLayout::RightToLeft);
#endif
setWindowFlags( Qt::Dialog | Qt::FramelessWindowHint );
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
for(QLineEdit *w: findChildren<QLineEdit*>())
w->setAttribute(Qt::WA_MacShowFocusRect, false);
new Overlay(this, parent->topLevelWidget());

ui->unblock->setEnabled( false );
connect( ui->unblock, &QPushButton::clicked, this, &PinUnblock::accept );
connect( ui->cancel, &QPushButton::clicked, this, &PinUnblock::reject );
connect( this, &PinUnblock::finished, this, &PinUnblock::close );
ui->unblock->setEnabled(false);
connect(ui->unblock, &QPushButton::clicked, this, &PinUnblock::accept);
connect(ui->cancel, &QPushButton::clicked, this, &PinUnblock::reject);
connect(this, &PinUnblock::finished, this, &PinUnblock::close);

QFont condensed12 = Styles::font(Styles::Condensed, 12);
ui->labelPuk->setFont(condensed12);
ui->labelPin->setFont(condensed12);
ui->labelRepeat->setFont(condensed12);

if( mode == PinUnblock::ChangePinWithPuk )
if(mode == PinUnblock::ChangePinWithPuk)
{
ui->labelNameId->setText( tr("%1 code change").arg( QSmartCardData::typeString( type ) ) );
ui->labelNameId->setText(tr("%1 code change").arg(QSmartCardData::typeString(type)));
regexpFirstCode.setPattern(QStringLiteral("^\\d{8,12}$"));
regexpNewCode.setPattern((type == QSmartCardData::Pin1Type) ? QStringLiteral("^\\d{4,12}$") : QStringLiteral("^\\d{5,12}$"));
ui->unblock->setText( tr("CHANGE") );
ui->unblock->setText(tr("CHANGE"));
}
if( mode == PinUnblock::UnBlockPinWithPuk )
if(mode == PinUnblock::UnBlockPinWithPuk)
{
ui->labelNameId->setText( tr("%1 unblocking").arg( QSmartCardData::typeString( type ) ) );
ui->labelNameId->setText(tr("%1 unblocking").arg(QSmartCardData::typeString(type)));
regexpFirstCode.setPattern(QStringLiteral("^\\d{8,12}$"));
regexpNewCode.setPattern((type == QSmartCardData::Pin1Type) ? QStringLiteral("^\\d{4,12}$") : QStringLiteral("^\\d{5,12}$"));
}
else if( mode == PinUnblock::PinChange )
else if(mode == PinUnblock::PinChange)
{
ui->labelNameId->setText( tr("%1 code change").arg( QSmartCardData::typeString( type ) ) );
ui->labelPuk->setText( tr( "VALID %1 CODE").arg( QSmartCardData::typeString( type ) ) );
ui->labelNameId->setText(tr("%1 code change").arg(QSmartCardData::typeString(type)));
ui->labelPuk->setText(tr("VALID %1 CODE").arg(QSmartCardData::typeString(type)));
regexpFirstCode.setPattern((type == QSmartCardData::Pin1Type) ? QStringLiteral("^\\d{4,12}$") :
(type == QSmartCardData::Pin2Type) ? QStringLiteral("^\\d{5,12}$") : QStringLiteral("^\\d{8,12}$"));
regexpNewCode.setPattern((type == QSmartCardData::Pin1Type) ? QStringLiteral("^\\d{4,12}$") :
(type == QSmartCardData::Pin2Type) ? QStringLiteral("^\\d{5,12}$") : QStringLiteral("^\\d{8,12}$"));
ui->unblock->setText( tr("CHANGE") );
ui->unblock->setText(tr("CHANGE"));
}
setWindowTitle(ui->labelNameId->text());
ui->labelPin->setText( tr( "NEW %1 CODE").arg( QSmartCardData::typeString( type ) ) );
ui->labelRepeat->setText( tr( "NEW %1 CODE AGAIN").arg( QSmartCardData::typeString( type ) ) );
ui->labelPin->setText(tr("NEW %1 CODE").arg(QSmartCardData::typeString(type)));
ui->labelRepeat->setText(tr("NEW %1 CODE AGAIN").arg(QSmartCardData::typeString(type)));
ui->pin->setAccessibleName(ui->labelPin->text().toLower());
ui->repeat->setAccessibleName(ui->labelRepeat->text().toLower());
ui->puk->setAccessibleName(ui->labelPuk->text().toLower());
Expand All @@ -108,18 +92,18 @@ void PinUnblock::init( WorkMode mode, QSmartCardData::PinType type, short leftAt
QFont condensed14(Styles::font(Styles::Condensed, 14));
QFont headerFont(Styles::font(Styles::Regular, 18));
QFont regular13(Styles::font(Styles::Regular, 13));
headerFont.setWeight( QFont::Bold );
ui->labelNameId->setFont( headerFont );
ui->cancel->setFont( condensed14 );
ui->unblock->setFont( condensed14 );
headerFont.setWeight(QFont::Bold);
ui->labelNameId->setFont(headerFont);
ui->cancel->setFont(condensed14);
ui->unblock->setFont(condensed14);
ui->labelAttemptsLeft->setFont(regular13);
ui->labelPinValidation->setFont(regular13);
ui->labelPinValidation->hide();
if( mode == PinUnblock::ChangePinWithPuk || mode == PinUnblock::UnBlockPinWithPuk )
ui->labelAttemptsLeft->setText( tr("PUK remaining attempts: %1").arg( leftAttempts ) );
if(mode == PinUnblock::ChangePinWithPuk || mode == PinUnblock::UnBlockPinWithPuk)
ui->labelAttemptsLeft->setText(tr("PUK remaining attempts: %1").arg(leftAttempts));
else
ui->labelAttemptsLeft->setText( tr("Remaining attempts: %1").arg( leftAttempts ) );
ui->labelAttemptsLeft->setVisible( leftAttempts < 3 );
ui->labelAttemptsLeft->setText(tr("Remaining attempts: %1").arg(leftAttempts));
ui->labelAttemptsLeft->setVisible(leftAttempts < 3);

initIntro(mode, type);

Expand All @@ -137,6 +121,17 @@ void PinUnblock::init( WorkMode mode, QSmartCardData::PinType type, short leftAt
isRepeatCodeOk = !ui->pin->text().isEmpty() && ui->pin->text() == ui->repeat->text();
setUnblockEnabled();
});
QSizePolicy sp_retain = ui->labelPinValidation->sizePolicy();
sp_retain.setRetainSizeWhenHidden(true);
ui->labelPinValidation->setSizePolicy(sp_retain);
ui->labelNameId->setFont(Styles::font(Styles::Regular, 20, QFont::DemiBold));
adjustSize();
setFixedSize(size());
}

PinUnblock::~PinUnblock()
{
delete ui;
}

void PinUnblock::initIntro(WorkMode mode, QSmartCardData::PinType type)
Expand Down
1 change: 0 additions & 1 deletion client/dialogs/PinUnblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class PinUnblock final : public QDialog
QString newCodeText() const;

private:
void init( WorkMode mode, QSmartCardData::PinType type, short leftAttempts );
void initIntro(WorkMode mode, QSmartCardData::PinType type);
void setUnblockEnabled();
bool validatePin(const QString& pin, QSmartCardData::PinType type, WorkMode mode);
Expand Down
2 changes: 2 additions & 0 deletions client/widgets/ContainerPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ void ContainerPage::transition(CryptoDoc *container, const QSslCertificate &cert
{
clear();
isSupported = container && (container->state() & UnencryptedContainer || container->canDecrypt(cert));
if(!container)
return;
setHeader(container->fileName());
for(const CKey &key: container->keys())
ui->rightPane->addWidget(new AddressItem(key, ui->rightPane, true));
Expand Down
2 changes: 1 addition & 1 deletion client/widgets/SignatureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ SignatureItem::SignatureItem(DigiDocSignature s, ContainerState /*state*/, QWidg
ui->remove->setIcons(QStringLiteral("/images/icon_remove.svg"), QStringLiteral("/images/icon_remove_hover.svg"),
QStringLiteral("/images/icon_remove_pressed.svg"), 17, 17);
ui->remove->init(LabelButton::White, {}, 0);
ui->remove->setVisible(s.parent()->isSupported());
ui->remove->setVisible(ui->signature.parent()->isSupported());
connect(ui->remove, &LabelButton::clicked, this, &SignatureItem::removeSignature);
init();
}
Expand Down

0 comments on commit 94adb1c

Please sign in to comment.