Add importpaperkeycommand to subkeyswidget

Adding it to the context menu of subkeys makes sense to me
as this is technically the right place and it extends
the current menu.
This should be sufficiently hidden for a very rarely used
option that is mostly disaster recovery.
parent 6c157f24
......@@ -21,6 +21,7 @@
#include "smartcard/readerstatus.h"
#include "commands/keytocardcommand.h"
#include "commands/importpaperkeycommand.h"
#include <gpgme++/key.h>
......@@ -58,42 +59,57 @@ private:
void SubKeysWidget::Private::tableContextMenuRequested(const QPoint &p)
{
if (!Kleo::Commands::KeyToCardCommand::supported()) {
return;
}
auto item = ui.subkeysTree->itemAt(p);
if (!item) {
return;
}
const auto subkey = item->data(0, Qt::UserRole).value<GpgME::Subkey>();
QMenu *menu = new QMenu(q);
connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
bool hasActions = false;
if (!subkey.isSecret()) {
return;
hasActions = true;
menu->addAction(QIcon::fromTheme(QStringLiteral("view-certificate-import")),
i18n("Restore printed backup"),
q, [this, subkey] () {
auto cmd = new Kleo::Commands::ImportPaperKeyCommand(subkey.parent());
ui.subkeysTree->setEnabled(false);
connect(cmd, &Kleo::Commands::ImportPaperKeyCommand::finished,
q, [this]() { ui.subkeysTree->setEnabled(true); });
cmd->setParentWidget(q);
cmd->start();
});
}
const auto cards = SmartCard::ReaderStatus::instance()->getCards();
if (!cards.size() || cards[0]->appType() != SmartCard::Card::OpenPGPApplication) {
return;
if (Kleo::Commands::KeyToCardCommand::supported()) {
const auto cards = SmartCard::ReaderStatus::instance()->getCards();
if (cards.size() && cards[0]->appType() == SmartCard::Card::OpenPGPApplication) {
const auto card = cards[0];
if (!subkey.cardSerialNumber() || card->serialNumber() != subkey.cardSerialNumber()) {
hasActions = true;
menu->addAction(QIcon::fromTheme(QStringLiteral("send-to-symbolic")),
i18n("Transfer to smartcard"),
q, [this, subkey, card]() {
auto cmd = new Kleo::Commands::KeyToCardCommand(subkey, card->serialNumber());
ui.subkeysTree->setEnabled(false);
connect(cmd, &Kleo::Commands::KeyToCardCommand::finished,
q, [this]() { ui.subkeysTree->setEnabled(true); });
cmd->setParentWidget(q);
cmd->start();
});
}
}
}
const auto card = cards[0];
if (subkey.cardSerialNumber() && card->serialNumber() == subkey.cardSerialNumber()) {
return;
if (hasActions) {
menu->popup(ui.subkeysTree->viewport()->mapToGlobal(p));
} else {
delete menu;
}
QMenu *menu = new QMenu(q);
menu->addAction(QIcon::fromTheme(QStringLiteral("send-to-symbolic")),
i18n("Transfer to smartcard"),
q, [this, subkey, card]() {
auto cmd = new Kleo::Commands::KeyToCardCommand(subkey, card->serialNumber());
ui.subkeysTree->setEnabled(false);
connect(cmd, &Kleo::Commands::KeyToCardCommand::finished,
q, [this]() { ui.subkeysTree->setEnabled(true); });
cmd->setParentWidget(q);
cmd->start();
});
connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
menu->popup(ui.subkeysTree->viewport()->mapToGlobal(p));
}
SubKeysWidget::SubKeysWidget(QWidget *parent)
......
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