Commit 7a5b3bdd authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Use std::set for protocols

... instead of a mix of std::vector and QVector.

Also avoid some difficult to translate word puzzles at the cost of
spelling out the display names of the CMS and OpenPGP protocols.
parent 80904450
Pipeline #51461 passed with stage
in 17 minutes and 37 seconds
......@@ -55,7 +55,7 @@ SignerResolveValidator::SignerResolveValidator(SignerResolvePage *page)
void SignerResolveValidator::update() const
{
const bool haveSelected = !m_page->selectedProtocols().empty();
const std::vector<Protocol> missing = m_page->selectedProtocolsWithoutSigningCertificate();
const std::set<Protocol> missing = m_page->selectedProtocolsWithoutSigningCertificate();
complete = haveSelected && missing.empty();
expl.clear();
......@@ -69,9 +69,13 @@ void SignerResolveValidator::update() const
Q_ASSERT(missing.size() <= 2);
if (missing.size() == 1) {
expl = i18n("You need to select an %1 signing certificate to proceed.", Formatting::displayName(missing[0]));
if (missing.find(OpenPGP) != missing.end()) {
expl = i18n("You need to select an OpenPGP signing certificate to proceed.");
} else {
expl = i18n("You need to select an S/MIME signing certificate to proceed.");
}
} else {
expl = i18n("You need to select %1 and %2 signing certificates to proceed.", Formatting::displayName(missing[0]), Formatting::displayName(missing[1]));
expl = i18n("You need to select an OpenPGP signing certificate and an S/MIME signing certificate to proceed.");
}
}
......
......@@ -102,12 +102,12 @@ bool ReadOnlyProtocolSelectionWidget::isProtocolChecked(Protocol protocol) const
return l->isVisible();
}
std::vector<Protocol> ReadOnlyProtocolSelectionWidget::checkedProtocols() const
std::set<Protocol> ReadOnlyProtocolSelectionWidget::checkedProtocols() const
{
std::vector<Protocol> res;
std::set<Protocol> res;
Q_FOREACH (const Protocol i, supportedProtocols()) //krazy:exclude=foreach
if (isProtocolChecked(i)) {
res.push_back(i);
res.insert(i);
}
return res;
......@@ -152,14 +152,14 @@ bool SigningProtocolSelectionWidget::isProtocolChecked(Protocol p) const
return b->isChecked();
}
std::vector<Protocol> SigningProtocolSelectionWidget::checkedProtocols() const
std::set<Protocol> SigningProtocolSelectionWidget::checkedProtocols() const
{
std::vector<Protocol> res;
std::set<Protocol> res;
for (std::map<Protocol, QCheckBox *>::const_iterator it = m_buttons.begin(), end = m_buttons.end();
it != end;
++it)
if (it->second->isChecked()) {
res.push_back(it->first);
res.insert(it->first);
}
return res;
}
......@@ -444,7 +444,7 @@ void SignerResolvePage::Private::updateModeSelectionWidgets()
void SignerResolvePage::Private::selectCertificates()
{
QPointer<SigningCertificateSelectionDialog> dlg = new SigningCertificateSelectionDialog(q);
dlg->setAllowedProtocols(QVector<Protocol>::fromStdVector(signingProtocolSelectionWidget->checkedProtocols()));
dlg->setAllowedProtocols(signingProtocolSelectionWidget->checkedProtocols());
if (dlg->exec() == QDialog::Accepted && dlg) {
const QMap<Protocol, Key> certs = dlg->selectedCertificates();
setCertificates(certs);
......@@ -550,7 +550,7 @@ void SignerResolvePage::setPresetProtocols(const std::vector<Protocol> &protocol
d->updateModeSelectionWidgets();
}
std::vector<Protocol> SignerResolvePage::selectedProtocols() const
std::set<Protocol> SignerResolvePage::selectedProtocols() const
{
return d->signingProtocolSelectionWidget->checkedProtocols();
}
......@@ -627,12 +627,12 @@ void SignerResolvePage::setSigningUserMutable(bool ismutable)
d->updateModeSelectionWidgets();
}
std::vector<Protocol> SignerResolvePage::selectedProtocolsWithoutSigningCertificate() const
std::set<Protocol> SignerResolvePage::selectedProtocolsWithoutSigningCertificate() const
{
std::vector<Protocol> res;
std::set<Protocol> res;
Q_FOREACH (const Protocol i, selectedProtocols()) //krazy:exclude=foreach
if (signingCertificates(i).empty()) {
res.push_back(i);
res.insert(i);
}
return res;
}
......
......@@ -18,6 +18,7 @@
#include <kmime/kmime_header_parsing.h>
#include <memory>
#include <set>
#include <vector>
namespace GpgME
......@@ -67,9 +68,9 @@ public:
void setPresetProtocol(GpgME::Protocol protocol);
void setPresetProtocols(const std::vector<GpgME::Protocol> &protocols);
std::vector<GpgME::Protocol> selectedProtocols() const;
std::set<GpgME::Protocol> selectedProtocols() const;
std::vector<GpgME::Protocol> selectedProtocolsWithoutSigningCertificate() const;
std::set<GpgME::Protocol> selectedProtocolsWithoutSigningCertificate() const;
void setMultipleProtocolsAllowed(bool allowed);
bool multipleProtocolsAllowed() const;
......
......@@ -18,6 +18,7 @@ class QLabel;
#include <vector>
#include <map>
#include <set>
namespace Kleo
{
......@@ -33,7 +34,7 @@ public:
explicit AbstractSigningProtocolSelectionWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = {});
virtual void setProtocolChecked(GpgME::Protocol protocol, bool checked) = 0;
virtual bool isProtocolChecked(GpgME::Protocol protocol) const = 0;
virtual std::vector<GpgME::Protocol> checkedProtocols() const = 0;
virtual std::set<GpgME::Protocol> checkedProtocols() const = 0;
virtual void setCertificate(GpgME::Protocol protocol, const GpgME::Key &key) = 0;
Q_SIGNALS:
......@@ -47,7 +48,7 @@ public:
explicit SigningProtocolSelectionWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = {});
void setProtocolChecked(GpgME::Protocol protocol, bool checked) override;
bool isProtocolChecked(GpgME::Protocol protocol) const override;
std::vector<GpgME::Protocol> checkedProtocols() const override;
std::set<GpgME::Protocol> checkedProtocols() const override;
void setCertificate(GpgME::Protocol protocol, const GpgME::Key &key) override;
void setExclusive(bool exclusive);
......@@ -66,7 +67,7 @@ public:
explicit ReadOnlyProtocolSelectionWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = {});
void setProtocolChecked(GpgME::Protocol protocol, bool checked) override;
bool isProtocolChecked(GpgME::Protocol protocol) const override;
std::vector<GpgME::Protocol> checkedProtocols() const override;
std::set<GpgME::Protocol> checkedProtocols() const override;
void setCertificate(GpgME::Protocol protocol, const GpgME::Key &key) override;
private:
......
......@@ -55,7 +55,7 @@ bool SigningCertificateSelectionDialog::rememberAsDefault() const
return widget->rememberAsDefault();
}
void SigningCertificateSelectionDialog::setAllowedProtocols(const QVector<GpgME::Protocol> &allowedProtocols)
void SigningCertificateSelectionDialog::setAllowedProtocols(const std::set<GpgME::Protocol> &allowedProtocols)
{
widget->setAllowedProtocols(allowedProtocols);
}
......
......@@ -15,6 +15,8 @@
#include <utils/pimpl_ptr.h>
#include <set>
template <typename K, typename U> class QMap;
namespace Kleo
......@@ -33,7 +35,7 @@ public:
explicit SigningCertificateSelectionDialog(QWidget *parent = nullptr);
~SigningCertificateSelectionDialog();
void setAllowedProtocols(const QVector<GpgME::Protocol> &allowedProtocols);
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;
......
......@@ -128,10 +128,10 @@ bool SigningCertificateSelectionWidget::rememberAsDefault() const
return d->ui.rememberCO->isChecked();
}
void SigningCertificateSelectionWidget::setAllowedProtocols(const QVector<GpgME::Protocol> &allowedProtocols)
void SigningCertificateSelectionWidget::setAllowedProtocols(const std::set<GpgME::Protocol> &allowedProtocols)
{
setAllowedProtocols(allowedProtocols.contains(GpgME::OpenPGP),
allowedProtocols.contains(GpgME::CMS));
setAllowedProtocols(allowedProtocols.find(GpgME::OpenPGP) != allowedProtocols.end(),
allowedProtocols.find(GpgME::CMS) != allowedProtocols.end());
}
void SigningCertificateSelectionWidget::setAllowedProtocols(bool pgp, bool cms)
......
......@@ -15,6 +15,8 @@
#include <utils/pimpl_ptr.h>
#include <set>
template <typename K, typename U> class QMap;
namespace GpgME
......@@ -36,7 +38,7 @@ public:
explicit SigningCertificateSelectionWidget(QWidget *parent = nullptr, Qt::WindowFlags f = {});
~SigningCertificateSelectionWidget();
void setAllowedProtocols(const QVector<GpgME::Protocol> &allowedProtocols);
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 GpgME::Key &pgp, const GpgME::Key &cms);
......
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