14#include <config-libkleo.h>
16#include "keyapprovaldialog.h"
18#include "keyrequester.h"
20#include <KLocalizedString>
23#include <QGpgME/Protocol>
26#include <QDialogButtonBox>
35#include <gpgme++/key.h>
37static Kleo::EncryptionPreference cb2pref(
int i)
42 return Kleo::UnknownPreference;
44 return Kleo::NeverEncrypt;
46 return Kleo::AlwaysEncrypt;
48 return Kleo::AlwaysEncryptIfPossible;
50 return Kleo::AlwaysAskForEncryption;
52 return Kleo::AskWheneverPossible;
56static int pref2cb(Kleo::EncryptionPreference p)
61 case Kleo::NeverEncrypt:
63 case Kleo::AlwaysEncrypt:
65 case Kleo::AlwaysEncryptIfPossible:
67 case Kleo::AlwaysAskForEncryption:
69 case Kleo::AskWheneverPossible:
77 <<
i18n(
"Never Encrypt with This Key")
78 <<
i18n(
"Always Encrypt with This Key")
79 <<
i18n(
"Encrypt Whenever Encryption is Possible")
81 <<
i18n(
"Ask Whenever Encryption is Possible");
84class Q_DECL_HIDDEN Kleo::KeyApprovalDialog::KeyApprovalDialogPrivate
87 KeyApprovalDialogPrivate()
93 std::vector<Kleo::KeyRequester *> requesters;
95 bool prefsChanged =
false;
98Kleo::KeyApprovalDialog::KeyApprovalDialog(
const std::vector<Item> &recipients,
const std::vector<GpgME::Key> &sender,
QWidget *parent)
100 , d(new KeyApprovalDialogPrivate())
102 setWindowTitle(
i18nc(
"@title:window",
"Encryption Key Approval"));
110 Q_ASSERT(!recipients.empty());
113 mainLayout->addWidget(page);
114 mainLayout->addWidget(buttonBox);
116 vlay->setContentsMargins(0, 0, 0, 0);
118 vlay->addWidget(
new QLabel(
i18nc(
"@label:textbox",
"The following keys will be used for encryption:"), page));
121 sv->setWidgetResizable(
true);
127 glay->setColumnStretch(1, 1);
132 if (!sender.empty()) {
134 glay->addWidget(
new QLabel(
i18nc(
"@label:textbox",
"Your keys:"), view), row, 0);
135 d->selfRequester =
new EncryptionKeyRequester(
true, EncryptionKeyRequester::AllProtocols, view);
136 d->selfRequester->setKeys(sender);
137 glay->addWidget(d->selfRequester, row, 1);
144 for (
auto it = recipients.begin(); it != recipients.end(); ++it) {
146 glay->addWidget(
new QLabel(
i18nc(
"@label:textbox",
"Recipient:"), view), row, 0);
147 glay->addWidget(
new QLabel(it->address, view), row, 1);
148 d->addresses.push_back(it->address);
151 glay->addWidget(
new QLabel(
i18nc(
"@label:textbox",
"Encryption keys:"), view), row, 0);
152 KeyRequester *req =
new EncryptionKeyRequester(
true, EncryptionKeyRequester::AllProtocols, view);
153 req->setKeys(it->keys);
154 glay->addWidget(req, row, 1);
155 d->requesters.push_back(req);
158 glay->addWidget(
new QLabel(
i18nc(
"@label:textbox",
"Encryption preference:"), view), row, 0);
160 cb->setEditable(
false);
162 glay->addWidget(cb, row, 1);
163 cb->setCurrentIndex(pref2cb(it->pref));
165 d->preferences.push_back(cb);
168 QSize size = sizeHint();
171 const QSize desk = screen()->size();
175Kleo::KeyApprovalDialog::~KeyApprovalDialog() =
default;
177std::vector<GpgME::Key> Kleo::KeyApprovalDialog::senderKeys()
const
179 return d->selfRequester ? d->selfRequester->keys() : std::vector<GpgME::Key>();
182std::vector<Kleo::KeyApprovalDialog::Item> Kleo::KeyApprovalDialog::items()
const
184 Q_ASSERT(d->requesters.size() ==
static_cast<unsigned int>(d->addresses.size()));
185 Q_ASSERT(d->requesters.size() == d->preferences.size());
187 std::vector<Item> result;
188 result.reserve(d->requesters.size());
190 auto rit = d->requesters.begin();
191 auto cit = d->preferences.begin();
192 while (ait != d->addresses.constEnd()) {
193 result.push_back(
Item(*ait++, (*rit++)->keys(), cb2pref((*cit++)->currentIndex())));
198bool Kleo::KeyApprovalDialog::preferencesChanged()
const
200 return d->prefsChanged;
203void Kleo::KeyApprovalDialog::slotPrefsChanged()
205 d->prefsChanged =
true;
208#include "moc_keyapprovaldialog.cpp"
Base class for SigningKeyRequester and EncryptionKeyRequester.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString xi18n(const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QAction * preferences(const QObject *recvr, const char *slot, QObject *parent)
void activated(int index)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)