Commit 25e4425b authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Use simple struct with two Keys instead of a QMap

parent 8ee85555
Pipeline #181492 passed with stage
in 3 minutes and 3 seconds
......@@ -14,7 +14,8 @@
#include "signingcertificateselectiondialog.h"
#include <crypto/certificateresolver.h>
#include "crypto/certificateresolver.h"
#include "utils/keys.h"
#include <Libkleo/KeyCache>
#include <Libkleo/Formatting>
......@@ -231,7 +232,7 @@ public:
void setOperation(Operation operation);
void operationButtonClicked(int operation);
void selectCertificates();
void setCertificates(const QMap<GpgME::Protocol, GpgME::Key> &certs);
void setCertificates(const CertificatePair &certs);
void updateModeSelectionWidgets();
void updateUi();
bool protocolSelected(Protocol p) const;
......@@ -257,7 +258,7 @@ private:
bool encryptionSelected;
bool multipleProtocolsAllowed;
bool protocolSelectionUserMutable;
QMap<GpgME::Protocol, GpgME::Key> certificates;
CertificatePair certificates;
std::shared_ptr<SignerResolvePage::Validator> validator;
std::shared_ptr<SigningPreferences> signingPreferences;
};
......@@ -357,15 +358,13 @@ bool SignerResolvePage::Private::protocolSelected(Protocol p) const
return signingProtocolSelectionWidget->isProtocolChecked(p);
}
void SignerResolvePage::Private::setCertificates(const QMap<GpgME::Protocol, GpgME::Key> &certs)
void SignerResolvePage::Private::setCertificates(const CertificatePair &certs)
{
certificates = certs;
for (auto it = certs.cbegin(), endIt = certs.cend(); it != endIt; ++it) {
const Protocol proto = it.key();
const Key &key = it.value();
readOnlyProtocolSelectionWidget->setCertificate(proto, key);
signingProtocolSelectionWidget->setCertificate(proto, key);
}
readOnlyProtocolSelectionWidget->setCertificate(GpgME::OpenPGP, certs.openpgp);
signingProtocolSelectionWidget->setCertificate(GpgME::OpenPGP, certs.openpgp);
readOnlyProtocolSelectionWidget->setCertificate(GpgME::CMS, certs.cms);
signingProtocolSelectionWidget->setCertificate(GpgME::CMS, certs.cms);
updateUi();
}
......@@ -443,11 +442,11 @@ void SignerResolvePage::Private::selectCertificates()
QPointer<SigningCertificateSelectionDialog> dlg = new SigningCertificateSelectionDialog(q);
dlg->setAllowedProtocols(signingProtocolSelectionWidget->checkedProtocols());
if (dlg->exec() == QDialog::Accepted && dlg) {
const QMap<Protocol, Key> certs = dlg->selectedCertificates();
const auto certs = dlg->selectedCertificates();
setCertificates(certs);
if (signingPreferences && dlg->rememberAsDefault()) {
signingPreferences->setPreferredCertificate(OpenPGP, certs.value(OpenPGP));
signingPreferences->setPreferredCertificate(CMS, certs.value(CMS));
signingPreferences->setPreferredCertificate(OpenPGP, certs.openpgp);
signingPreferences->setPreferredCertificate(CMS, certs.cms);
}
}
......@@ -495,7 +494,7 @@ SignerResolvePage::SignerResolvePage(QWidget *parent, Qt::WindowFlags f)
setTitle(i18n("<b>Choose Operation to be Performed</b>"));
// setSubTitle( i18n( "TODO" ) );
setPresetProtocol(UnknownProtocol);
d->setCertificates(QMap<GpgME::Protocol, GpgME::Key>());
d->setCertificates({});
d->updateModeSelectionWidgets();
d->operationButtonClicked(EncryptOnly);
}
......@@ -555,11 +554,11 @@ std::set<Protocol> SignerResolvePage::selectedProtocols() const
std::vector<Key> SignerResolvePage::signingCertificates(Protocol protocol) const
{
std::vector<Key> result;
if (protocol != CMS && d->signingProtocolSelectionWidget->isProtocolChecked(OpenPGP) && !d->certificates[OpenPGP].isNull()) {
result.push_back(d->certificates[OpenPGP]);
if (protocol != CMS && d->signingProtocolSelectionWidget->isProtocolChecked(OpenPGP) && !d->certificates.openpgp.isNull()) {
result.push_back(d->certificates.openpgp);
}
if (protocol != OpenPGP && d->signingProtocolSelectionWidget->isProtocolChecked(CMS) && !d->certificates[CMS].isNull()) {
result.push_back(d->certificates[CMS]);
if (protocol != OpenPGP && d->signingProtocolSelectionWidget->isProtocolChecked(CMS) && !d->certificates.cms.isNull()) {
result.push_back(d->certificates.cms);
}
return result;
}
......@@ -648,10 +647,11 @@ void SignerResolvePage::setAsciiArmorEnabled(bool enabled)
void SignerResolvePage::setSigningPreferences(const std::shared_ptr<SigningPreferences> &prefs)
{
d->signingPreferences = prefs;
QMap<Protocol, Key> map;
map[OpenPGP] = prefs ? prefs->preferredCertificate(OpenPGP) : Key();
map[CMS] = prefs ? prefs->preferredCertificate(CMS) : Key();
d->setCertificates(map);
const CertificatePair certs = {
prefs ? prefs->preferredCertificate(OpenPGP) : Key(),
prefs ? prefs->preferredCertificate(CMS) : Key()
};
d->setCertificates(certs);
}
std::shared_ptr<SigningPreferences> SignerResolvePage::signingPreferences() const
......
......@@ -10,8 +10,11 @@
#include <config-kleopatra.h>
#include "signingcertificateselectiondialog.h"
#include "signingcertificateselectionwidget.h"
#include "utils/keys.h"
#include <KLocalizedString>
#include <QMap>
......@@ -40,12 +43,12 @@ SigningCertificateSelectionDialog::SigningCertificateSelectionDialog(QWidget *pa
SigningCertificateSelectionDialog::~SigningCertificateSelectionDialog() {}
void SigningCertificateSelectionDialog::setSelectedCertificates(const QMap<GpgME::Protocol, GpgME::Key> &certificates)
void SigningCertificateSelectionDialog::setSelectedCertificates(const CertificatePair &certificates)
{
widget->setSelectedCertificates(certificates);
}
QMap<GpgME::Protocol, GpgME::Key> SigningCertificateSelectionDialog::selectedCertificates() const
CertificatePair SigningCertificateSelectionDialog::selectedCertificates() const
{
return widget->selectedCertificates();
}
......
......@@ -20,6 +20,8 @@ template <typename K, typename U> class QMap;
namespace Kleo
{
class CertificatePair;
namespace Crypto
{
namespace Gui
......@@ -35,8 +37,8 @@ public:
~SigningCertificateSelectionDialog() override;
void setAllowedProtocols(const std::set<GpgME::Protocol> &allowedProtocols);
void setSelectedCertificates(const QMap<GpgME::Protocol, GpgME::Key> &certificates);
Q_REQUIRED_RESULT QMap<GpgME::Protocol, GpgME::Key> selectedCertificates() const;
void setSelectedCertificates(const CertificatePair &certificates);
Q_REQUIRED_RESULT CertificatePair selectedCertificates() const;
Q_REQUIRED_RESULT bool rememberAsDefault() const;
......
......@@ -13,6 +13,8 @@
#include "ui_signingcertificateselectionwidget.h"
#include "utils/keys.h"
#include <Libkleo/KeyCache>
#include <Libkleo/Formatting>
#include <Libkleo/Stl_Util>
......@@ -78,9 +80,9 @@ SigningCertificateSelectionWidget::SigningCertificateSelectionWidget(QWidget *pa
SigningCertificateSelectionWidget::~SigningCertificateSelectionWidget() {}
void SigningCertificateSelectionWidget::setSelectedCertificates(const QMap<GpgME::Protocol, GpgME::Key> &certificates)
void SigningCertificateSelectionWidget::setSelectedCertificates(const CertificatePair &certificates)
{
setSelectedCertificates(certificates[GpgME::OpenPGP], certificates[GpgME::CMS]);
setSelectedCertificates(certificates.openpgp, certificates.cms);
}
void SigningCertificateSelectionWidget::setSelectedCertificates(const GpgME::Key &pgp, const GpgME::Key &cms)
......@@ -113,14 +115,12 @@ void SigningCertificateSelectionWidget::Private::addCandidates(GpgME::Protocol p
}
}
QMap<GpgME::Protocol, GpgME::Key> SigningCertificateSelectionWidget::selectedCertificates() const
CertificatePair SigningCertificateSelectionWidget::selectedCertificates() const
{
QMap<GpgME::Protocol, GpgME::Key> res;
res.insert(GpgME::OpenPGP, current_cert(*d->ui.pgpCombo));
res.insert(GpgME::CMS, current_cert(*d->ui.cmsCombo));
return res;
return {
current_cert(*d->ui.pgpCombo),
current_cert(*d->ui.cmsCombo),
};
}
bool SigningCertificateSelectionWidget::rememberAsDefault() const
......
......@@ -25,6 +25,8 @@ class Key;
namespace Kleo
{
class CertificatePair;
namespace Crypto
{
namespace Gui
......@@ -39,9 +41,9 @@ public:
void setAllowedProtocols(const std::set<GpgME::Protocol> &allowedProtocols);
void setAllowedProtocols(bool pgp, bool cms);
void setSelectedCertificates(const QMap<GpgME::Protocol, GpgME::Key> &certificates);
void setSelectedCertificates(const CertificatePair &certificates);
void setSelectedCertificates(const GpgME::Key &pgp, const GpgME::Key &cms);
QMap<GpgME::Protocol, GpgME::Key> selectedCertificates() const;
CertificatePair selectedCertificates() const;
bool rememberAsDefault() const;
......
......@@ -14,6 +14,12 @@
namespace Kleo
{
struct CertificatePair {
GpgME::Key openpgp;
GpgME::Key cms;
};
/** Returns true if \p signature is a self-signature. */
bool isSelfSignature(const GpgME::UserID::Signature &signature);
......@@ -32,4 +38,5 @@ bool isRevokedOrExpired(const GpgME::UserID &userId);
* offline key, is available in the keyring.
*/
bool canCreateCertifications(const GpgME::Key &key);
}
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