Skip to content

Commit

Permalink
Hide default action when token is not present (#821)
Browse files Browse the repository at this point in the history
IB-6616

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma authored Sep 17, 2020
1 parent a993202 commit 5fbb738
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
19 changes: 8 additions & 11 deletions client/widgets/ContainerPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,19 @@ void ContainerPage::showMainAction(const QList<Actions> &actions)
mainAction.reset(new MainAction(this));
connect(mainAction.get(), &MainAction::action, this, &ContainerPage::forward);
}
mainAction->update(actions);
bool isSign =
actions.contains(SignatureAdd) || actions.contains(SignatureToken) ||
actions.contains(SignatureMobile) || actions.contains(SignatureSmartID);
bool isEncrypt =
actions.contains(EncryptContainer) && !ui->rightPane->findChildren<AddressItem*>().isEmpty();
bool isDecrypt =
actions.contains(DecryptContainer) || actions.contains(DecryptToken);
mainAction->setButtonEnabled(isEncrypt || (!isBlocked && ((isSign && !isExpired) || isDecrypt)));
mainAction->showActions(actions);
bool isSign = actions.contains(SignatureAdd) || actions.contains(SignatureToken);
bool isSignMobile = !isSign && (actions.contains(SignatureMobile) || actions.contains(SignatureSmartID));
bool isEncrypt = actions.contains(EncryptContainer) && !ui->rightPane->findChildren<AddressItem*>().isEmpty();
bool isDecrypt = actions.contains(DecryptContainer) || actions.contains(DecryptToken);
mainAction->setButtonEnabled(isEncrypt || isSignMobile || (!isBlocked && ((isSign && !isExpired) || isDecrypt)));
ui->mainActionSpacer->changeSize( 198, 20, QSizePolicy::Fixed );
ui->navigationArea->layout()->invalidate();
}

void ContainerPage::showSigningButton()
{
if(cardInReader.isNull())
if(cardInReader.isEmpty())
showMainAction({ SignatureMobile, SignatureSmartID });
else if(isSeal)
showMainAction({ SignatureToken, SignatureMobile, SignatureSmartID });
Expand Down Expand Up @@ -403,7 +400,7 @@ void ContainerPage::update(bool canDecrypt, CryptoDoc* container)

void ContainerPage::updateDecryptionButton()
{
if(!canDecrypt || cardInReader.isNull())
if(!canDecrypt || cardInReader.isEmpty())
hideMainAction();
else if(isSeal)
showMainAction({ DecryptToken });
Expand Down
1 change: 0 additions & 1 deletion client/widgets/ContainerPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public slots:
void hideMainAction();
void hideRightPane();
void initContainer( const QString &file, const QString &suffix );
void showDropdown();
void showMainAction(const QList<ria::qdigidoc4::Actions> &actions);
void showRightPane(ria::qdigidoc4::ItemType itemType, const QString &header);
void showSigningButton();
Expand Down
41 changes: 23 additions & 18 deletions client/widgets/MainAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ MainAction::~MainAction()
void MainAction::changeEvent(QEvent* event)
{
if(event->type() == QEvent::LanguageChange)
update(ui->actions);
update();
QWidget::changeEvent(event);
}

Expand Down Expand Up @@ -113,6 +113,23 @@ void MainAction::setButtonEnabled(bool enabled)
ui->mainAction->setEnabled(enabled);
}

void MainAction::showActions(const QList<Actions> &actions)
{
QList<Actions> order = actions;
if(order.size() == 2 &&
std::all_of(order.cbegin(), order.cend(), [] (Actions action) {
return action == SignatureMobile || action == SignatureSmartID;
}) &&
!QSettings().value("MIDOrder", true).toBool())
{
std::reverse(order.begin(), order.end());
}
ui->actions = order;
update();
ui->otherCards->setVisible(ui->actions.size() > 1);
show();
}

void MainAction::showDropdown()
{
if(ui->actions.size() > 1 && ui->list.isEmpty())
Expand All @@ -121,13 +138,13 @@ void MainAction::showDropdown()
{
QPushButton *other = new QPushButton(label(*i), parentWidget());
other->setAccessibleName(label(*i).toLower());
other->setCursor(QCursor(Qt::PointingHandCursor));
other->setCursor(ui->mainAction->cursor());
other->setFont(ui->mainAction->font());
other->resize(size());
other->move(pos() + QPoint(0, (-height() - 1) * (ui->list.size() + 1)));
other->show();
other->setStyleSheet(ui->mainAction->styleSheet() +
QStringLiteral("\nborder-top-left-radius: 2px; border-top-right-radius: 2px;"));
other->setFont(ui->mainAction->font());
if (*i == Actions::SignatureMobile)
connect(other, &QPushButton::clicked, this, []{ SettingsDialog::setValueEx("MIDOrder", true, true); });
if (*i == Actions::SignatureSmartID)
Expand All @@ -142,21 +159,9 @@ void MainAction::showDropdown()
hideDropdown();
}

void MainAction::update(const QList<Actions> &actions)
void MainAction::update()
{
QList<Actions> order = actions;
hideDropdown();
if(order.size() == 2 &&
std::all_of(order.cbegin(), order.cend(), [] (Actions action) {
return action == SignatureMobile || action == SignatureSmartID;
}) &&
!QSettings().value("MIDOrder", true).toBool())
{
std::reverse(order.begin(), order.end());
}
ui->actions = order;
ui->mainAction->setText(label(order[0]));
ui->mainAction->setAccessibleName(label(order[0]).toLower());
ui->otherCards->setVisible(order.size() > 1);
show();
ui->mainAction->setText(label(ui->actions[0]));
ui->mainAction->setAccessibleName(label(ui->actions[0]).toLower());
}
7 changes: 4 additions & 3 deletions client/widgets/MainAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <QWidget>

class MainAction : public QWidget
class MainAction final : public QWidget
{
Q_OBJECT

Expand All @@ -33,8 +33,7 @@ class MainAction : public QWidget

void hideDropdown();
void setButtonEnabled(bool enabled);
void showDropdown();
void update(const QList<ria::qdigidoc4::Actions> &actions);
void showActions(const QList<ria::qdigidoc4::Actions> &actions);

signals:
void action(ria::qdigidoc4::Actions action);
Expand All @@ -43,6 +42,8 @@ class MainAction : public QWidget
void changeEvent(QEvent* event) override;
bool eventFilter(QObject *o, QEvent *e) override;
QString label(ria::qdigidoc4::Actions action) const;
void showDropdown();
void update();

class Private;
Private *ui;
Expand Down

0 comments on commit 5fbb738

Please sign in to comment.