Unverified Commit d3614e8a authored by Andre Heinecke's avatar Andre Heinecke
Browse files

p15: Add learn card keys button when neccessary

This is a simple solution to make it possible to call gpgsm --learn
for p15cards. A better solution will be to unify this somehow
with the netkeywidget and add the additional actions and
keytreeview from there.
parent 20177db4
Pipeline #169062 passed with stage
in 4 minutes and 9 seconds
......@@ -18,11 +18,14 @@
#include "smartcard/openpgpcard.h"
#include "smartcard/readerstatus.h"
#include "commands/learncardkeyscommand.h"
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QScrollArea>
#include <QStringList>
#include <QPushButton>
#include <KLocalizedString>
#include <KSeparator>
......@@ -43,6 +46,7 @@
using namespace Kleo;
using namespace Kleo::SmartCard;
using namespace Kleo::Commands;
P15CardWidget::P15CardWidget(QWidget *parent)
: QWidget{parent}
......@@ -50,6 +54,7 @@ P15CardWidget::P15CardWidget(QWidget *parent)
, mSerialNumber{new QLabel{this}}
, mStatusLabel{new QLabel{this}}
, mOpenPGPKeysSection{new QWidget{this}}
, mCMSKeysSection{new QWidget{this}}
, mOpenPGPKeysWidget{new OpenPGPKeyCardWidget{this}}
{
// Set up the scroll area
......@@ -94,8 +99,41 @@ P15CardWidget::P15CardWidget(QWidget *parent)
l->addWidget(mOpenPGPKeysWidget);
l->addWidget(new KSeparator(Qt::Horizontal));
}
{
auto l = new QVBoxLayout{mCMSKeysSection};
/* For an improvement we need to make a hybrid of
* the NetKeyWidget with the treeview and all the
* CMS Related actions here, too. For now it
* is just a button that is shown when we can
* learn additional CMS keys from the smartcard. */
auto hl = new QHBoxLayout;
auto learnBtn = new QPushButton(i18n("Load additional certificates"));
learnBtn->setToolTip(i18n("Search for additional certificates on the card and add them to the list. "
"The certificates might be usable for S/MIME."));
auto learnLbl = new QLabel();
learnLbl->setVisible(false);
hl->addWidget(learnBtn);
hl->addStretch(1);
l->addLayout(hl);
l->addWidget(learnLbl);
connect(learnBtn, &QPushButton::clicked, this, [this, learnBtn, learnLbl] () {
learnBtn->setEnabled(false);
auto cmd = new LearnCardKeysCommand(GpgME::CMS);
cmd->setParentWidget(this);
cmd->start();
learnLbl->setVisible(true);
learnLbl->setText(i18n("Loading certificates..."));
connect(cmd, &Command::finished, this, [learnBtn, learnLbl] () {
learnLbl->setText(i18n("Certificates added to the certificate list."));
});
});
l->addWidget(new KSeparator(Qt::Horizontal));
}
mOpenPGPKeysSection->setVisible(false);
mCMSKeysSection->setVisible(false);
areaVLay->addWidget(mOpenPGPKeysSection);
areaVLay->addWidget(mCMSKeysSection);
areaVLay->addStretch(1);
}
......@@ -168,4 +206,14 @@ void P15CardWidget::setCard(const P15Card *card)
if (cardHasOpenPGPKeys) {
mOpenPGPKeysWidget->update(card);
}
/* Check if additional keys could be available */
for (const auto &info: card->keyInfos()) {
const auto key = KeyCache::instance()->findSubkeyByKeyGrip(info.grip);
if (key.isNull()) {
mCMSKeysSection->setVisible(true);
break;
}
}
}
......@@ -41,6 +41,7 @@ private:
QLabel *mSerialNumber = nullptr;
QLabel *mStatusLabel = nullptr;
QWidget *mOpenPGPKeysSection = nullptr;
QWidget *mCMSKeysSection = nullptr;
OpenPGPKeyCardWidget *mOpenPGPKeysWidget = nullptr;
};
......
Supports Markdown
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