Page MenuHome GnuPG

No OneTemporary

diff --git a/src/commands/addadskcommand.cpp b/src/commands/addadskcommand.cpp
index c1b739201..dbb79fe13 100644
--- a/src/commands/addadskcommand.cpp
+++ b/src/commands/addadskcommand.cpp
@@ -1,188 +1,187 @@
/*
SPDX-FileCopyrightText: 2024 g10 Code GmbH
SPDX-FileContributor: Tobias Fella <tobias.fella@gnupg.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "addadskcommand.h"
#include "command_p.h"
#include "dialogs/addadskdialog.h"
#include <Libkleo/Formatting>
#include <KLocalizedString>
#include <QGpgME/Protocol>
#include <QGpgME/QuickJob>
#include <gpgme++/key.h>
#include <gpgme.h>
using namespace Kleo;
using namespace Kleo::Commands;
using namespace Kleo::Dialogs;
using namespace GpgME;
using namespace QGpgME;
class AddADSKCommand::Private : public Command::Private
{
AddADSKCommand *q_func() const
{
return static_cast<AddADSKCommand *>(q);
}
public:
- explicit Private(AddADSKCommand *qq, KeyListController *c);
+ explicit Private(AddADSKCommand *qq);
~Private() override;
void slotDialogAccepted();
void slotDialogRejected();
void slotResult(const Error &err);
void ensureDialogCreated();
void createJob();
void showErrorDialog(const Error &error);
void showSuccessDialog();
QPointer<AddADSKDialog> dialog;
QPointer<QuickJob> job;
};
AddADSKCommand::Private *AddADSKCommand::d_func()
{
return static_cast<Private *>(d.get());
}
const AddADSKCommand::Private *AddADSKCommand::d_func() const
{
return static_cast<const Private *>(d.get());
}
#define d d_func()
#define q q_func()
AddADSKCommand::Private::Private(AddADSKCommand *qq, KeyListController *c)
: Command::Private{qq, c}
{
}
AddADSKCommand::Private::~Private() = default;
void AddADSKCommand::Private::slotDialogAccepted()
{
Q_ASSERT(dialog);
createJob();
for (const auto &subkey : dialog->adsk().subkeys()) {
if (subkey.canEncrypt() && !subkey.isBad()) {
#if GPGME_VERSION_NUMBER >= 0x011800 // 1.24.0
job->startAddAdsk(key(), subkey.fingerprint());
#endif
break;
}
}
}
void AddADSKCommand::Private::slotDialogRejected()
{
- Q_EMIT q->canceled();
- finished();
+ canceled();
}
void AddADSKCommand::Private::slotResult(const Error &err)
{
if (err.isCanceled()) {
- finished();
+ canceled();
return;
}
if (err) {
showErrorDialog(err);
} else {
showSuccessDialog();
}
finished();
}
void AddADSKCommand::Private::ensureDialogCreated()
{
if (dialog) {
return;
}
dialog = new AddADSKDialog{key()};
applyWindowID(dialog);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, &QDialog::accepted, q, [this]() {
slotDialogAccepted();
});
connect(dialog, &QDialog::rejected, q, [this]() {
slotDialogRejected();
});
}
void AddADSKCommand::Private::createJob()
{
Q_ASSERT(!job);
const auto backend = QGpgME::openpgp();
if (!backend) {
return;
}
const auto j = backend->quickJob();
if (!j) {
return;
}
connect(j, &QGpgME::Job::jobProgress, q, &Command::progress);
connect(j, &QuickJob::result, q, [this](const auto &err) {
slotResult(err);
});
job = j;
}
void AddADSKCommand::Private::showErrorDialog(const Error &err)
{
error(i18nc("'ADSK' means 'Additional Decryption Subkey'; Don't try translating it, though.",
"<p>An error occurred while trying to add "
"a new ADSK to <b>%1</b>:</p><p>%2</p>",
Formatting::formatForComboBox(key()),
Formatting::errorAsString(err)));
}
void AddADSKCommand::Private::showSuccessDialog()
{
success(i18nc("'ADSK' means 'Additional Decryption Subkey'; Don't try translating it, though.", "ADSK added successfully."));
}
AddADSKCommand::AddADSKCommand(const GpgME::Key &key)
: Command{key, new Private{this, nullptr}}
{
}
AddADSKCommand::~AddADSKCommand() = default;
void AddADSKCommand::doStart()
{
d->ensureDialogCreated();
Q_ASSERT(d->dialog);
d->dialog->show();
}
void AddADSKCommand::doCancel()
{
if (d->job) {
d->job->slotCancel();
}
}
#undef d
#undef q
#include "moc_addadskcommand.cpp"
diff --git a/src/dialogs/addadskdialog.cpp b/src/dialogs/addadskdialog.cpp
index d1402c802..a10cbec82 100644
--- a/src/dialogs/addadskdialog.cpp
+++ b/src/dialogs/addadskdialog.cpp
@@ -1,147 +1,146 @@
/* -*- mode: c++; c-basic-offset:4 -*-
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2024 g10 Code GmbH
SPDX-FileContributor: Tobias Fella <tobias.fella@gnupg.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "addadskdialog.h"
#include "crypto/gui/certificatelineedit.h"
#include "dialogs/certificateselectiondialog.h"
#include <Libkleo/DefaultKeyFilter>
#include <Libkleo/KeyListModel>
#include <KLocalizedString>
#include <QDialogButtonBox>
#include <QLabel>
#include <QPushButton>
#include <QScreen>
#include <QVBoxLayout>
using namespace Kleo;
using namespace Kleo::Dialogs;
using namespace GpgME;
class EncryptCertificateFilter : public DefaultKeyFilter
{
public:
EncryptCertificateFilter(const Key &key)
: DefaultKeyFilter()
, m_key(key)
{
- setRevoked(DefaultKeyFilter::NotSet);
- setExpired(DefaultKeyFilter::NotSet);
+ setIsBad(DefaultKeyFilter::NotSet);
setCanEncrypt(DefaultKeyFilter::Set);
setValidIfSMIME(DefaultKeyFilter::NotSet);
}
bool matches(const Key &key, MatchContexts ctx) const override
{
if (m_key.primaryFingerprint() == key.primaryFingerprint()) {
return false;
}
return DefaultKeyFilter::matches(key, ctx);
}
Key m_key;
};
class AddADSKDialog::Private
{
public:
Private(AddADSKDialog *qq, const Key &key)
: ui{qq, key}
{
}
struct UI {
CertificateLineEdit *adsk = nullptr;
QDialogButtonBox *buttonBox = nullptr;
UI(QDialog *parent, const Key &key)
{
const auto mainLayout = new QVBoxLayout{parent};
{
const auto &model = AbstractKeyListModel::createFlatKeyListModel(parent);
model->useKeyCache(true, KeyList::AllKeys);
auto filter = new EncryptCertificateFilter(key);
auto infoLabel = new QLabel(i18nc("@info",
"By adding an additional encryption subkey to your certificate, you allow it to decrypt all messages that "
"were encrypted for your certificate."));
mainLayout->addWidget(infoLabel);
auto layout = new QHBoxLayout;
layout->addWidget(new QLabel(i18n("ADSK:")));
adsk = new CertificateLineEdit(model, KeyUsage::Encrypt, filter, parent);
layout->addWidget(adsk);
mainLayout->addLayout(layout);
}
buttonBox = new QDialogButtonBox{parent};
buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
mainLayout->addWidget(buttonBox);
}
} ui;
};
AddADSKDialog::AddADSKDialog(const Key &parent, QWidget *p)
: QDialog{p}
, d{new Private{this, parent}}
{
setWindowTitle(i18nc("@title:window", "Add ADSK"));
const auto size = sizeHint();
const auto desk = screen()->size();
resize(QSize(desk.width() / 3, qMin(size.height(), desk.height() / 2)));
connect(d->ui.buttonBox, &QDialogButtonBox::accepted, this, &AddADSKDialog::accept);
connect(d->ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(d->ui.adsk, &CertificateLineEdit::certificateSelectionRequested, this, [this, parent]() {
CertificateSelectionDialog dlg{this};
dlg.setOptions(CertificateSelectionDialog::Options( //
CertificateSelectionDialog::SingleSelection | //
CertificateSelectionDialog::EncryptOnly | //
CertificateSelectionDialog::optionsFromProtocol(OpenPGP)));
dlg.setKeyFilter(std::shared_ptr<EncryptCertificateFilter>(new EncryptCertificateFilter(parent)));
if (!d->ui.adsk->key().isNull()) {
const auto key = d->ui.adsk->key();
const auto name = QString::fromUtf8(key.userID(0).name());
const auto email = QString::fromUtf8(key.userID(0).email());
dlg.setStringFilter(!name.isEmpty() ? name : email);
} else {
dlg.setStringFilter(d->ui.adsk->text());
}
if (dlg.exec()) {
const std::vector<Key> keys = dlg.selectedCertificates();
if (keys.size() == 0) {
return;
}
CertificateLineEdit *certWidget = d->ui.adsk;
for (const Key &key : keys) {
certWidget->setKey(key);
}
}
});
connect(d->ui.adsk, &CertificateLineEdit::keyChanged, this, [this]() {
d->ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!d->ui.adsk->userID().parent().isNull());
});
}
Key AddADSKDialog::adsk() const
{
return d->ui.adsk->userID().parent();
}
AddADSKDialog::~AddADSKDialog() = default;
#include "moc_addadskdialog.cpp"

File Metadata

Mime Type
text/x-diff
Expires
Sat, Feb 1, 9:08 AM (1 d, 2 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8d/e9/0e0796ff1368dcadd86d792c3025

Event Timeline