Page MenuHome GnuPG

No OneTemporary

diff --git a/src/dialogs/addadskdialog.cpp b/src/dialogs/addadskdialog.cpp
index f22acc392..490f7ee05 100644
--- a/src/dialogs/addadskdialog.cpp
+++ b/src/dialogs/addadskdialog.cpp
@@ -1,144 +1,145 @@
/* -*- 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 <Libkleo/Predicates>
#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)
{
setIsBad(DefaultKeyFilter::NotSet);
setCanEncrypt(DefaultKeyFilter::Set);
setIsOpenPGP(DefaultKeyFilter::Set);
}
bool matches(const Key &key, MatchContexts ctx) const override
{
if (_detail::ByFingerprint<std::equal_to>()(m_key, 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);
+ mainLayout->addSpacing(16);
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()) {
auto keys = dlg.selectedCertificates();
if (keys.size() == 0) {
return;
}
d->ui.adsk->setKey(keys.front());
}
});
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:04 AM (1 d, 4 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7a/83/896f9b19ef3bda6fd44d516d340d

Event Timeline