Commit 73cb87f0 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add possibility to specify allowed key actions

GnuPG-bug-id: 4876
parent 75c25653
......@@ -61,7 +61,8 @@ public:
explicit Private(OpenPGPKeyCardWidget *q);
~Private() = default;
void update(const Card *card);
void setAllowedActions(Actions actions);
void update(const Card *card = nullptr);
private:
void updateCachedValues(const std::string &openPGPKeyRef, const std::string &cardKeyRef, const Card *card);
......@@ -69,6 +70,7 @@ private:
private:
OpenPGPKeyCardWidget *const q;
Actions mAllowedActions = AllActions;
std::map<std::string, KeyWidgets> mKeyWidgets;
};
......@@ -97,6 +99,12 @@ OpenPGPKeyCardWidget::Private::Private(OpenPGPKeyCardWidget *q)
grid->setColumnStretch(grid->columnCount(), 1);
}
void OpenPGPKeyCardWidget::Private::setAllowedActions(Actions actions)
{
mAllowedActions = actions;
update();
}
void OpenPGPKeyCardWidget::Private::update(const Card *card)
{
if (card) {
......@@ -125,7 +133,7 @@ void OpenPGPKeyCardWidget::Private::updateKeyWidgets(const std::string &openPGPK
widgets.keyTitleLabel->setVisible(cardSupportsKey);
widgets.keyInfoLabel->setVisible(cardSupportsKey);
if (widgets.createCSRButton) {
widgets.createCSRButton->setVisible(cardSupportsKey);
widgets.createCSRButton->setVisible(cardSupportsKey && (mAllowedActions & Action::CreateCSR));
}
if (!cardSupportsKey) {
return;
......@@ -188,6 +196,11 @@ OpenPGPKeyCardWidget::OpenPGPKeyCardWidget(QWidget *parent)
OpenPGPKeyCardWidget::~OpenPGPKeyCardWidget() = default;
void OpenPGPKeyCardWidget::setAllowedActions(Actions actions)
{
d->setAllowedActions(actions);
}
void OpenPGPKeyCardWidget::update(const Card *card)
{
d->update(card);
......
......@@ -8,6 +8,7 @@
*/
#pragma once
#include <QFlags>
#include <QWidget>
#include <memory>
......@@ -24,9 +25,18 @@ class OpenPGPKeyCardWidget: public QWidget
{
Q_OBJECT
public:
enum Action {
NoAction = 0x00,
CreateCSR = 0x01,
AllActions = CreateCSR,
};
Q_DECLARE_FLAGS(Actions, Action)
explicit OpenPGPKeyCardWidget(QWidget *parent = nullptr);
~OpenPGPKeyCardWidget() override;
void setAllowedActions(Actions actions);
public Q_SLOTS:
void update(const SmartCard::Card *card);
......@@ -38,4 +48,6 @@ private:
std::unique_ptr<Private> d;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(OpenPGPKeyCardWidget::Actions)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment