Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34206669
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
26 KB
Subscribers
None
View Options
diff --git a/src/ui/keyrequester.cpp b/src/ui/keyrequester.cpp
index 164fac67..7cef1d45 100644
--- a/src/ui/keyrequester.cpp
+++ b/src/ui/keyrequester.cpp
@@ -1,515 +1,529 @@
/* -*- c++ -*-
keyrequester.cpp
This file is part of libkleopatra, the KDE keymanagement library
SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
Based on kpgpui.cpp
SPDX-FileCopyrightText: 2001, 2002 the KPGP authors
See file libkdenetwork/AUTHORS.kpgp for details
This file is part of KPGP, the KDE PGP/GnuPG support library.
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-libkleo.h>
#include "keyrequester.h"
#include "keyselectiondialog.h"
#include <libkleo/algorithm.h>
#include <libkleo/compliance.h>
#include <libkleo/formatting.h>
#include <libkleo/keyhelpers.h>
#include <KLocalizedString>
#include <KMessageBox>
#include <QGpgME/KeyListJob>
#include <QApplication>
#include <QDialog>
#include <QHBoxLayout>
#include <QPushButton>
#include <QString>
#include <gpgme++/key.h>
#include <gpgme++/keylistresult.h>
using namespace QGpgME;
using namespace Kleo;
-Kleo::KeyRequester::KeyRequester(unsigned int allowedKeys, bool multipleKeys, QWidget *parent)
- : QWidget(parent)
- , mOpenPGPBackend(nullptr)
- , mSMIMEBackend(nullptr)
- , mMulti(multipleKeys)
- , mKeyUsage(allowedKeys)
- , mJobs(0)
- , d(nullptr)
-{
- init();
-}
-
-Kleo::KeyRequester::KeyRequester(QWidget *parent)
- : QWidget(parent)
- , mOpenPGPBackend(nullptr)
- , mSMIMEBackend(nullptr)
- , mMulti(false)
- , mKeyUsage(0)
- , mJobs(0)
- , d(nullptr)
-{
- init();
-}
+class KeyRequester::Private
+{
+public:
+ Private(QWidget *q, unsigned int allowedKeys, bool multipleKeys)
+ : mMulti(multipleKeys)
+ , mKeyUsage(allowedKeys)
+ {
+ init(q);
+ }
-void Kleo::KeyRequester::init()
-{
- auto hlay = new QHBoxLayout(this);
+ void init(QWidget *q);
+
+ const QGpgME::Protocol *mOpenPGPBackend = nullptr;
+ const QGpgME::Protocol *mSMIMEBackend = nullptr;
+ QLabel *mComplianceIcon = nullptr;
+ QLabel *mLabel = nullptr;
+ QPushButton *mEraseButton = nullptr;
+ QPushButton *mDialogButton = nullptr;
+ QString mDialogCaption, mDialogMessage, mInitialQuery;
+ bool mMulti = false;
+ unsigned int mKeyUsage = 0;
+ int mJobs = 0;
+ std::vector<GpgME::Key> mKeys;
+ std::vector<GpgME::Key> mTmpKeys;
+};
+
+void KeyRequester::Private::init(QWidget *q)
+{
+ auto hlay = new QHBoxLayout(q);
hlay->setContentsMargins(0, 0, 0, 0);
if (DeVSCompliance::isCompliant()) {
- mComplianceIcon = new QLabel{this};
+ mComplianceIcon = new QLabel{q};
mComplianceIcon->setPixmap(Formatting::questionIcon().pixmap(22));
}
// the label where the key id is to be displayed:
- mLabel = new QLabel(this);
+ mLabel = new QLabel(q);
mLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
// the button to unset any key:
- mEraseButton = new QPushButton(this);
+ mEraseButton = new QPushButton(q);
mEraseButton->setAutoDefault(false);
mEraseButton->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
mEraseButton->setIcon(
QIcon::fromTheme(QApplication::isRightToLeft() ? QStringLiteral("edit-clear-locationbar-ltr") : QStringLiteral("edit-clear-locationbar-rtl")));
mEraseButton->setToolTip(i18nc("@info:tooltip", "Clear"));
// the button to call the KeySelectionDialog:
- mDialogButton = new QPushButton(i18nc("@action:button", "Change..."), this);
+ mDialogButton = new QPushButton(i18nc("@action:button", "Change..."), q);
mDialogButton->setAutoDefault(false);
if (mComplianceIcon) {
hlay->addWidget(mComplianceIcon);
}
hlay->addWidget(mLabel, 1);
hlay->addWidget(mEraseButton);
hlay->addWidget(mDialogButton);
+}
- connect(mEraseButton, &QPushButton::clicked, this, &SigningKeyRequester::slotEraseButtonClicked);
- connect(mDialogButton, &QPushButton::clicked, this, &SigningKeyRequester::slotDialogButtonClicked);
+Kleo::KeyRequester::KeyRequester(unsigned int allowedKeys, bool multipleKeys, QWidget *parent)
+ : QWidget(parent)
+ , d{std::make_unique<Private>(this, allowedKeys, multipleKeys)}
+{
+ connect(d->mEraseButton, &QPushButton::clicked, this, &SigningKeyRequester::slotEraseButtonClicked);
+ connect(d->mDialogButton, &QPushButton::clicked, this, &SigningKeyRequester::slotDialogButtonClicked);
setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
- setAllowedKeys(mKeyUsage);
+ setAllowedKeys(d->mKeyUsage);
}
-Kleo::KeyRequester::~KeyRequester()
+Kleo::KeyRequester::KeyRequester(QWidget *parent)
+ : KeyRequester{0, false, parent}
{
}
+Kleo::KeyRequester::~KeyRequester() = default;
+
const std::vector<GpgME::Key> &Kleo::KeyRequester::keys() const
{
- return mKeys;
+ return d->mKeys;
}
const GpgME::Key &Kleo::KeyRequester::key() const
{
static const GpgME::Key null = GpgME::Key::null;
- if (mKeys.empty()) {
+ if (d->mKeys.empty()) {
return null;
} else {
- return mKeys.front();
+ return d->mKeys.front();
}
}
void Kleo::KeyRequester::setKeys(const std::vector<GpgME::Key> &keys)
{
- mKeys.clear();
- for (auto it = keys.begin(); it != keys.end(); ++it) {
- if (!it->isNull()) {
- mKeys.push_back(*it);
+ d->mKeys.clear();
+ for (const auto &key : keys) {
+ if (!key.isNull()) {
+ d->mKeys.push_back(key);
}
}
updateKeys();
}
void Kleo::KeyRequester::setKey(const GpgME::Key &key)
{
- mKeys.clear();
+ d->mKeys.clear();
if (!key.isNull()) {
- mKeys.push_back(key);
+ d->mKeys.push_back(key);
}
updateKeys();
}
QString Kleo::KeyRequester::fingerprint() const
{
- if (mKeys.empty()) {
+ if (d->mKeys.empty()) {
return QString();
} else {
- return QLatin1StringView(mKeys.front().primaryFingerprint());
+ return QLatin1StringView(d->mKeys.front().primaryFingerprint());
}
}
QStringList Kleo::KeyRequester::fingerprints() const
{
QStringList result;
- for (auto it = mKeys.begin(); it != mKeys.end(); ++it) {
- if (!it->isNull()) {
- if (const char *fpr = it->primaryFingerprint()) {
+ for (const GpgME::Key &key : d->mKeys) {
+ if (!key.isNull()) {
+ if (const char *fpr = key.primaryFingerprint()) {
result.push_back(QLatin1StringView(fpr));
}
}
}
return result;
}
void Kleo::KeyRequester::setFingerprint(const QString &fingerprint)
{
startKeyListJob(QStringList(fingerprint));
}
void Kleo::KeyRequester::setFingerprints(const QStringList &fingerprints)
{
startKeyListJob(fingerprints);
}
void Kleo::KeyRequester::updateKeys()
{
- if (mKeys.empty()) {
- if (mComplianceIcon) {
- mComplianceIcon->setPixmap(Formatting::unavailableIcon().pixmap(22));
- mComplianceIcon->setToolTip(QString{});
+ if (d->mKeys.empty()) {
+ if (d->mComplianceIcon) {
+ d->mComplianceIcon->setPixmap(Formatting::unavailableIcon().pixmap(22));
+ d->mComplianceIcon->setToolTip(QString{});
}
- mLabel->clear();
+ d->mLabel->clear();
return;
}
- if (mKeys.size() > 1) {
+ if (d->mKeys.size() > 1) {
setMultipleKeysEnabled(true);
}
QStringList labelTexts;
QString toolTipText;
- for (std::vector<GpgME::Key>::const_iterator it = mKeys.begin(); it != mKeys.end(); ++it) {
- if (it->isNull()) {
+ for (const GpgME::Key &key : d->mKeys) {
+ if (key.isNull()) {
continue;
}
- const QString fpr = QLatin1StringView(it->primaryFingerprint());
- const QString keyID = QString::fromLatin1(it->keyID());
+ const QString fpr = QLatin1StringView(key.primaryFingerprint());
+ const QString keyID = QString::fromLatin1(key.keyID());
labelTexts.push_back(keyID);
toolTipText += keyID + QLatin1StringView(": ");
- if (const char *uid = it->userID(0).id()) {
- if (it->protocol() == GpgME::OpenPGP) {
+ if (const char *uid = key.userID(0).id()) {
+ if (key.protocol() == GpgME::OpenPGP) {
toolTipText += QString::fromUtf8(uid);
} else {
toolTipText += Formatting::prettyDN(uid);
}
} else {
toolTipText += xi18n("<placeholder>unknown</placeholder>");
}
toolTipText += QLatin1Char('\n');
}
- if (mComplianceIcon) {
- if (Kleo::all_of(mKeys, &Kleo::DeVSCompliance::keyIsCompliant)) {
- mComplianceIcon->setPixmap(Formatting::successIcon().pixmap(22));
- mComplianceIcon->setToolTip(DeVSCompliance::name(true));
+ if (d->mComplianceIcon) {
+ if (std::ranges::all_of(d->mKeys, &Kleo::DeVSCompliance::keyIsCompliant)) {
+ d->mComplianceIcon->setPixmap(Formatting::successIcon().pixmap(22));
+ d->mComplianceIcon->setToolTip(DeVSCompliance::name(true));
} else {
- mComplianceIcon->setPixmap(Formatting::warningIcon().pixmap(22));
- mComplianceIcon->setToolTip(DeVSCompliance::name(false));
+ d->mComplianceIcon->setPixmap(Formatting::warningIcon().pixmap(22));
+ d->mComplianceIcon->setToolTip(DeVSCompliance::name(false));
}
}
- mLabel->setText(labelTexts.join(QLatin1StringView(", ")));
- mLabel->setToolTip(toolTipText);
+ d->mLabel->setText(labelTexts.join(QLatin1StringView(", ")));
+ d->mLabel->setToolTip(toolTipText);
}
#ifndef __KLEO_UI_SHOW_KEY_LIST_ERROR_H__
#define __KLEO_UI_SHOW_KEY_LIST_ERROR_H__
static void showKeyListError(QWidget *parent, const GpgME::Error &err)
{
Q_ASSERT(err);
const QString msg = i18n(
"<qt><p>An error occurred while fetching "
"the keys from the backend:</p>"
"<p><b>%1</b></p></qt>",
Formatting::errorAsString(err));
KMessageBox::error(parent, msg, i18nc("@title:window", "Key Listing Failed"));
}
#endif // __KLEO_UI_SHOW_KEY_LIST_ERROR_H__
void Kleo::KeyRequester::startKeyListJob(const QStringList &fingerprints)
{
- if (!mSMIMEBackend && !mOpenPGPBackend) {
+ if (!d->mSMIMEBackend && !d->mOpenPGPBackend) {
return;
}
- mTmpKeys.clear();
- mJobs = 0;
+ d->mTmpKeys.clear();
+ d->mJobs = 0;
unsigned int count = 0;
for (QStringList::const_iterator it = fingerprints.begin(); it != fingerprints.end(); ++it) {
if (!(*it).trimmed().isEmpty()) {
++count;
}
}
if (!count) {
// don't fall into the trap that an empty pattern means
// "return all keys" :)
setKey(GpgME::Key::null);
return;
}
- if (mOpenPGPBackend) {
- KeyListJob *job = mOpenPGPBackend->keyListJob(false); // local, no sigs
+ if (d->mOpenPGPBackend) {
+ KeyListJob *job = d->mOpenPGPBackend->keyListJob(false); // local, no sigs
if (!job) {
KMessageBox::error(this,
i18n("The OpenPGP backend does not support listing keys. "
"Check your installation."),
i18nc("@title:window", "Key Listing Failed"));
} else {
connect(job, &KeyListJob::result, this, &SigningKeyRequester::slotKeyListResult);
connect(job, &KeyListJob::nextKey, this, &SigningKeyRequester::slotNextKey);
const GpgME::Error err =
- job->start(fingerprints, mKeyUsage & Kleo::KeySelectionDialog::SecretKeys && !(mKeyUsage & Kleo::KeySelectionDialog::PublicKeys));
+ job->start(fingerprints, d->mKeyUsage & Kleo::KeySelectionDialog::SecretKeys && !(d->mKeyUsage & Kleo::KeySelectionDialog::PublicKeys));
if (err) {
showKeyListError(this, err);
} else {
- ++mJobs;
+ d->mJobs += 1;
}
}
}
- if (mSMIMEBackend) {
- KeyListJob *job = mSMIMEBackend->keyListJob(false); // local, no sigs
+ if (d->mSMIMEBackend) {
+ KeyListJob *job = d->mSMIMEBackend->keyListJob(false); // local, no sigs
if (!job) {
KMessageBox::error(this,
i18n("The S/MIME backend does not support listing keys. "
"Check your installation."),
i18nc("@title:window", "Key Listing Failed"));
} else {
connect(job, &KeyListJob::result, this, &SigningKeyRequester::slotKeyListResult);
connect(job, &KeyListJob::nextKey, this, &SigningKeyRequester::slotNextKey);
const GpgME::Error err =
- job->start(fingerprints, mKeyUsage & Kleo::KeySelectionDialog::SecretKeys && !(mKeyUsage & Kleo::KeySelectionDialog::PublicKeys));
+ job->start(fingerprints, d->mKeyUsage & Kleo::KeySelectionDialog::SecretKeys && !(d->mKeyUsage & Kleo::KeySelectionDialog::PublicKeys));
if (err) {
showKeyListError(this, err);
} else {
- ++mJobs;
+ d->mJobs += 1;
}
}
}
- if (mJobs > 0) {
- mEraseButton->setEnabled(false);
- mDialogButton->setEnabled(false);
+ if (d->mJobs > 0) {
+ d->mEraseButton->setEnabled(false);
+ d->mDialogButton->setEnabled(false);
}
}
void Kleo::KeyRequester::slotNextKey(const GpgME::Key &key)
{
if (!key.isNull()) {
- mTmpKeys.push_back(key);
+ d->mTmpKeys.push_back(key);
}
}
void Kleo::KeyRequester::slotKeyListResult(const GpgME::KeyListResult &res)
{
if (res.error()) {
showKeyListError(this, res.error());
}
- if (--mJobs <= 0) {
- mEraseButton->setEnabled(true);
- mDialogButton->setEnabled(true);
+ d->mJobs -= 1;
+ if (d->mJobs <= 0) {
+ d->mEraseButton->setEnabled(true);
+ d->mDialogButton->setEnabled(true);
- setKeys(mTmpKeys);
- mTmpKeys.clear();
+ setKeys(d->mTmpKeys);
+ d->mTmpKeys.clear();
}
}
void Kleo::KeyRequester::slotDialogButtonClicked()
{
- KeySelectionDialog *dlg = mKeys.empty() ? new KeySelectionDialog(mDialogCaption, mDialogMessage, mInitialQuery, mKeyUsage, mMulti, false, this)
- : new KeySelectionDialog(mDialogCaption, mDialogCaption, mKeys, mKeyUsage, mMulti, false, this);
+ KeySelectionDialog *dlg = d->mKeys.empty()
+ ? new KeySelectionDialog(d->mDialogCaption, d->mDialogMessage, d->mInitialQuery, d->mKeyUsage, d->mMulti, false, this)
+ : new KeySelectionDialog(d->mDialogCaption, d->mDialogCaption, d->mKeys, d->mKeyUsage, d->mMulti, false, this);
if (dlg->exec() == QDialog::Accepted) {
- if (mMulti) {
+ if (d->mMulti) {
setKeys(dlg->selectedKeys());
} else {
setKey(dlg->selectedKey());
}
Q_EMIT changed();
}
delete dlg;
}
void Kleo::KeyRequester::slotEraseButtonClicked()
{
- if (!mKeys.empty()) {
+ if (!d->mKeys.empty()) {
Q_EMIT changed();
}
- mKeys.clear();
+ d->mKeys.clear();
updateKeys();
}
void Kleo::KeyRequester::setDialogCaption(const QString &caption)
{
- mDialogCaption = caption;
+ d->mDialogCaption = caption;
}
void Kleo::KeyRequester::setDialogMessage(const QString &msg)
{
- mDialogMessage = msg;
+ d->mDialogMessage = msg;
}
bool Kleo::KeyRequester::isMultipleKeysEnabled() const
{
- return mMulti;
+ return d->mMulti;
}
void Kleo::KeyRequester::setMultipleKeysEnabled(bool multi)
{
- if (multi == mMulti) {
+ if (multi == d->mMulti) {
return;
}
- if (!multi && !mKeys.empty()) {
- mKeys.erase(mKeys.begin() + 1, mKeys.end());
+ if (!multi && !d->mKeys.empty()) {
+ d->mKeys.erase(d->mKeys.begin() + 1, d->mKeys.end());
}
- mMulti = multi;
+ d->mMulti = multi;
updateKeys();
}
unsigned int Kleo::KeyRequester::allowedKeys() const
{
- return mKeyUsage;
+ return d->mKeyUsage;
}
void Kleo::KeyRequester::setAllowedKeys(unsigned int keyUsage)
{
- mKeyUsage = keyUsage;
- mOpenPGPBackend = nullptr;
- mSMIMEBackend = nullptr;
+ d->mKeyUsage = keyUsage;
+ d->mOpenPGPBackend = nullptr;
+ d->mSMIMEBackend = nullptr;
- if (mKeyUsage & KeySelectionDialog::OpenPGPKeys) {
- mOpenPGPBackend = openpgp();
+ if (d->mKeyUsage & KeySelectionDialog::OpenPGPKeys) {
+ d->mOpenPGPBackend = openpgp();
}
- if (mKeyUsage & KeySelectionDialog::SMIMEKeys) {
- mSMIMEBackend = smime();
+ if (d->mKeyUsage & KeySelectionDialog::SMIMEKeys) {
+ d->mSMIMEBackend = smime();
}
- if (mOpenPGPBackend && !mSMIMEBackend) {
- mDialogCaption = i18n("OpenPGP Key Selection");
- mDialogMessage = i18n("Please select an OpenPGP key to use.");
- } else if (!mOpenPGPBackend && mSMIMEBackend) {
- mDialogCaption = i18n("S/MIME Key Selection");
- mDialogMessage = i18n("Please select an S/MIME key to use.");
+ if (d->mOpenPGPBackend && !d->mSMIMEBackend) {
+ d->mDialogCaption = i18n("OpenPGP Key Selection");
+ d->mDialogMessage = i18n("Please select an OpenPGP key to use.");
+ } else if (!d->mOpenPGPBackend && d->mSMIMEBackend) {
+ d->mDialogCaption = i18n("S/MIME Key Selection");
+ d->mDialogMessage = i18n("Please select an S/MIME key to use.");
} else {
- mDialogCaption = i18n("Key Selection");
- mDialogMessage = i18n("Please select an (OpenPGP or S/MIME) key to use.");
+ d->mDialogCaption = i18n("Key Selection");
+ d->mDialogMessage = i18n("Please select an (OpenPGP or S/MIME) key to use.");
}
}
+void KeyRequester::setInitialQuery(const QString &s)
+{
+ d->mInitialQuery = s;
+}
+
+const QString &KeyRequester::initialQuery() const
+{
+ return d->mInitialQuery;
+}
+
QPushButton *Kleo::KeyRequester::dialogButton()
{
- return mDialogButton;
+ return d->mDialogButton;
}
QPushButton *Kleo::KeyRequester::eraseButton()
{
- return mEraseButton;
+ return d->mEraseButton;
}
static inline unsigned int foo(bool openpgp, bool smime, bool trusted, bool valid)
{
unsigned int result = 0;
if (openpgp) {
result |= Kleo::KeySelectionDialog::OpenPGPKeys;
}
if (smime) {
result |= Kleo::KeySelectionDialog::SMIMEKeys;
}
if (trusted) {
result |= Kleo::KeySelectionDialog::TrustedKeys;
}
if (valid) {
result |= Kleo::KeySelectionDialog::ValidKeys;
}
return result;
}
static inline unsigned int encryptionKeyUsage(bool openpgp, bool smime, bool trusted, bool valid)
{
return foo(openpgp, smime, trusted, valid) | Kleo::KeySelectionDialog::EncryptionKeys | Kleo::KeySelectionDialog::PublicKeys;
}
static inline unsigned int signingKeyUsage(bool openpgp, bool smime, bool trusted, bool valid)
{
return foo(openpgp, smime, trusted, valid) | Kleo::KeySelectionDialog::SigningKeys | Kleo::KeySelectionDialog::SecretKeys;
}
+class EncryptionKeyRequester::Private
+{
+};
+
Kleo::EncryptionKeyRequester::EncryptionKeyRequester(bool multi, unsigned int proto, QWidget *parent, bool onlyTrusted, bool onlyValid)
: KeyRequester(encryptionKeyUsage(proto & OpenPGP, proto & SMIME, onlyTrusted, onlyValid), multi, parent)
, d(nullptr)
{
}
Kleo::EncryptionKeyRequester::EncryptionKeyRequester(QWidget *parent)
: KeyRequester(0, false, parent)
, d(nullptr)
{
}
-Kleo::EncryptionKeyRequester::~EncryptionKeyRequester()
-{
-}
+Kleo::EncryptionKeyRequester::~EncryptionKeyRequester() = default;
void Kleo::EncryptionKeyRequester::setAllowedKeys(unsigned int proto, bool onlyTrusted, bool onlyValid)
{
KeyRequester::setAllowedKeys(encryptionKeyUsage(proto & OpenPGP, proto & SMIME, onlyTrusted, onlyValid));
}
+class SigningKeyRequester::Private
+{
+};
+
Kleo::SigningKeyRequester::SigningKeyRequester(bool multi, unsigned int proto, QWidget *parent, bool onlyTrusted, bool onlyValid)
: KeyRequester(signingKeyUsage(proto & OpenPGP, proto & SMIME, onlyTrusted, onlyValid), multi, parent)
, d(nullptr)
{
}
Kleo::SigningKeyRequester::SigningKeyRequester(QWidget *parent)
: KeyRequester(0, false, parent)
, d(nullptr)
{
}
-Kleo::SigningKeyRequester::~SigningKeyRequester()
-{
-}
+Kleo::SigningKeyRequester::~SigningKeyRequester() = default;
void Kleo::SigningKeyRequester::setAllowedKeys(unsigned int proto, bool onlyTrusted, bool onlyValid)
{
KeyRequester::setAllowedKeys(signingKeyUsage(proto & OpenPGP, proto & SMIME, onlyTrusted, onlyValid));
}
-void Kleo::KeyRequester::virtual_hook(int, void *)
-{
-}
-void Kleo::EncryptionKeyRequester::virtual_hook(int id, void *data)
-{
- KeyRequester::virtual_hook(id, data);
-}
-void Kleo::SigningKeyRequester::virtual_hook(int id, void *data)
-{
- KeyRequester::virtual_hook(id, data);
-}
-
#include "moc_keyrequester.cpp"
diff --git a/src/ui/keyrequester.h b/src/ui/keyrequester.h
index 3b26a3d1..0b84608e 100644
--- a/src/ui/keyrequester.h
+++ b/src/ui/keyrequester.h
@@ -1,204 +1,175 @@
/* -*- c++ -*-
keyrequester.h
This file is part of libkleopatra, the KDE keymanagement library
SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
Based on kpgpui.h
SPDX-FileCopyrightText: 2001, 2002 the KPGP authors
See file libkdenetwork/AUTHORS.kpgp for details
This file is part of KPGP, the KDE PGP/GnuPG support library.
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include "kleo_export.h"
#include <QGpgME/Protocol>
#include <QLabel>
#include <QStringList>
#include <QWidget>
#include <vector>
namespace GpgME
{
class Key;
class KeyListResult;
}
class QString;
class QPushButton;
namespace Kleo
{
/// Base class for SigningKeyRequester and EncryptionKeyRequester
class KLEO_EXPORT KeyRequester : public QWidget
{
Q_OBJECT
public:
explicit KeyRequester(unsigned int allowedKeys, bool multipleKeys = false, QWidget *parent = nullptr);
// Constructor for Qt Designer
explicit KeyRequester(QWidget *parent = nullptr);
~KeyRequester() override;
const GpgME::Key &key() const;
/** Preferred method to set a key for
non-multi-KeyRequesters. Doesn't start a backend
KeyListJob.
*/
void setKey(const GpgME::Key &key);
const std::vector<GpgME::Key> &keys() const;
/** Preferred method to set a key for multi-KeyRequesters. Doesn't
start a backend KeyListJob.
*/
void setKeys(const std::vector<GpgME::Key> &keys);
QString fingerprint() const;
/** Set the key by fingerprint. Starts a background KeyListJob to
retrieve the complete GpgME::Key object
*/
void setFingerprint(const QString &fingerprint);
QStringList fingerprints() const;
/** Set the keys by fingerprint. Starts a background KeyListJob to
retrieve the complete GpgME::Key objects
*/
void setFingerprints(const QStringList &fingerprints);
QPushButton *eraseButton();
QPushButton *dialogButton();
void setDialogCaption(const QString &caption);
void setDialogMessage(const QString &message);
bool isMultipleKeysEnabled() const;
void setMultipleKeysEnabled(bool enable);
unsigned int allowedKeys() const;
void setAllowedKeys(unsigned int allowed);
- void setInitialQuery(const QString &s)
- {
- mInitialQuery = s;
- }
- const QString &initialQuery() const
- {
- return mInitialQuery;
- }
+ void setInitialQuery(const QString &s);
+ const QString &initialQuery() const;
Q_SIGNALS:
void changed();
private:
void init();
void startKeyListJob(const QStringList &fingerprints);
void updateKeys();
private Q_SLOTS:
void slotNextKey(const GpgME::Key &key);
void slotKeyListResult(const GpgME::KeyListResult &result);
void slotDialogButtonClicked();
void slotEraseButtonClicked();
-private:
- const QGpgME::Protocol *mOpenPGPBackend = nullptr;
- const QGpgME::Protocol *mSMIMEBackend = nullptr;
- QLabel *mComplianceIcon = nullptr;
- QLabel *mLabel = nullptr;
- QPushButton *mEraseButton = nullptr;
- QPushButton *mDialogButton = nullptr;
- QString mDialogCaption, mDialogMessage, mInitialQuery;
- bool mMulti;
- unsigned int mKeyUsage;
- int mJobs;
- std::vector<GpgME::Key> mKeys;
- std::vector<GpgME::Key> mTmpKeys;
-
private:
class Private;
- Private *const d;
-
-protected:
- virtual void virtual_hook(int, void *);
+ std::unique_ptr<Private> const d;
};
class KLEO_EXPORT EncryptionKeyRequester : public KeyRequester
{
Q_OBJECT
public:
enum { OpenPGP = 1, SMIME = 2, AllProtocols = OpenPGP | SMIME };
/**
* Preferred constructor
*/
explicit EncryptionKeyRequester(bool multipleKeys = false,
unsigned int proto = AllProtocols,
QWidget *parent = nullptr,
bool onlyTrusted = true,
bool onlyValid = true);
/**
* Constructor for Qt designer
*/
explicit EncryptionKeyRequester(QWidget *parent);
~EncryptionKeyRequester() override;
void setAllowedKeys(unsigned int proto, bool onlyTrusted = true, bool onlyValid = true);
private:
class Private;
- Private *const d;
-
-protected:
- void virtual_hook(int, void *) override;
+ std::unique_ptr<Private> const d;
};
class KLEO_EXPORT SigningKeyRequester : public KeyRequester
{
Q_OBJECT
public:
enum { OpenPGP = 1, SMIME = 2, AllProtocols = OpenPGP | SMIME };
/**
* Preferred constructor
* @param multipleKeys whether multiple keys can be selected
*
* @param proto the allowed protocols, OpenPGP and/or SMIME
* @param parent the parent widget
* @param onlyTrusted only show trusted keys
* @param onlyValid only show valid keys
*/
explicit SigningKeyRequester(bool multipleKeys = false,
unsigned int proto = AllProtocols,
QWidget *parent = nullptr,
bool onlyTrusted = true,
bool onlyValid = true);
/**
* Constructor for Qt designer
*/
explicit SigningKeyRequester(QWidget *parent);
~SigningKeyRequester() override;
/*
* Those parameters affect the parameters given to the key selection dialog.
* @param proto the allowed protocols, OpenPGP and/or SMIME
* @param onlyTrusted only show trusted keys
* @param onlyValid only show valid keys
*/
void setAllowedKeys(unsigned int proto, bool onlyTrusted = true, bool onlyValid = true);
private:
class Private;
- Private *const d;
-
-protected:
- void virtual_hook(int, void *) override;
+ std::unique_ptr<Private> const d;
};
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Dec 18, 8:42 AM (2 h, 19 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fc/1b/8f803667705fe7949eff6c0cfd22
Attached To
rLIBKLEO Libkleo
Event Timeline
Log In to Comment