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

Allow selection of groups of keys for encryption

This adds the possibility to select groups of keys in the selection
dialog that can be opened when selecting recipients for encryption.

GnuPG-bug-id: 5175, 5241
parent 9e5aebf7
......@@ -219,16 +219,11 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent, bool sigEncExclusive)
loadKeys();
setProtocol(GpgME::UnknownProtocol);
addRecipient(Key());
addRecipientWidget();
updateOp();
}
void SignEncryptWidget::addRecipient()
{
addRecipient(Key());
}
void SignEncryptWidget::addRecipient(const Key &key)
CertificateLineEdit *SignEncryptWidget::addRecipientWidget()
{
CertificateLineEdit *certSel = new CertificateLineEdit(mModel, this,
new EncryptCertificateFilter(mCurrentProto));
......@@ -247,16 +242,31 @@ void SignEncryptWidget::addRecipient(const Key &key)
connect(certSel, &CertificateLineEdit::wantsRemoval,
this, &SignEncryptWidget::recpRemovalRequested);
connect(certSel, &CertificateLineEdit::editingStarted,
this, static_cast<void (SignEncryptWidget::*)()>(&SignEncryptWidget::addRecipient));
this, [this] () { addRecipientWidget(); });
connect(certSel, &CertificateLineEdit::dialogRequested,
this, [this, certSel] () { dialogRequested(certSel); });
return certSel;
}
void SignEncryptWidget::addRecipient(const Key &key)
{
CertificateLineEdit *certSel = addRecipientWidget();
if (!key.isNull()) {
certSel->setKey(key);
mAddedKeys << key;
}
}
void SignEncryptWidget::addRecipient(const KeyGroup &group)
{
CertificateLineEdit *certSel = addRecipientWidget();
if (!group.isNull()) {
certSel->setGroup(group);
mAddedGroups << group;
}
}
void SignEncryptWidget::dialogRequested(CertificateLineEdit *certificateLineEdit)
{
if (!certificateLineEdit->key().isNull()) {
......@@ -268,17 +278,33 @@ void SignEncryptWidget::dialogRequested(CertificateLineEdit *certificateLineEdit
CertificateSelectionDialog *const dlg = new CertificateSelectionDialog(this);
dlg->setKeyFilter(std::make_shared<EncryptCertificateFilter>(mCurrentProto));
#ifdef GROUP_SUPPORT
dlg->setOptions(dlg->options() | CertificateSelectionDialog::MultiSelection | CertificateSelectionDialog::IncludeGroups);
#else
dlg->setOptions(dlg->options() | CertificateSelectionDialog::MultiSelection);
#endif
if (dlg->exec()) {
const std::vector<Key> keys = dlg->selectedCertificates();
if (!keys.size()) {
const std::vector<KeyGroup> groups = dlg->selectedGroups();
if (keys.size() == 0 && groups.size() == 0) {
return;
}
for (unsigned int i = 0; i < keys.size(); i++) {
if (!i) {
certificateLineEdit->setKey(keys[i]);
bool isFirstItem = true;
for (const Key &key : keys) {
if (isFirstItem) {
certificateLineEdit->setKey(key);
isFirstItem = false;
} else {
addRecipient(keys[i]);
addRecipient(key);
}
}
for (const KeyGroup &group : groups) {
if (isFirstItem) {
certificateLineEdit->setGroup(group);
isFirstItem = false;
} else {
addRecipient(group);
}
}
}
......@@ -296,6 +322,10 @@ void SignEncryptWidget::clearAddedRecipients()
for (auto &key: qAsConst(mAddedKeys)) {
removeRecipient(key);
}
for (auto &group: qAsConst(mAddedGroups)) {
removeRecipient(group);
}
}
void SignEncryptWidget::addUnknownRecipient(const char *keyID)
......@@ -346,7 +376,7 @@ void SignEncryptWidget::recipientsChanged()
}
}
if (!oneEmpty) {
addRecipient();
addRecipientWidget();
}
updateOp();
}
......@@ -487,6 +517,21 @@ void SignEncryptWidget::removeRecipient(const GpgME::Key &key)
}
}
void SignEncryptWidget::removeRecipient(const KeyGroup &group)
{
for (CertificateLineEdit *edit: qAsConst(mRecpWidgets)) {
const auto editGroup = edit->group();
if (group.isNull() && editGroup.isNull()) {
recpRemovalRequested(edit);
return;
}
if (editGroup.name() == group.name()) {
recpRemovalRequested(edit);
return;
}
}
}
bool SignEncryptWidget::encryptSymmetric() const
{
return mSymmetric->isChecked();
......
......@@ -19,6 +19,7 @@ class QCheckBox;
namespace Kleo
{
class CertificateLineEdit;
class KeyGroup;
class KeySelectionCombo;
class AbstractKeyListModel;
class UnknownRecipientWidget;
......@@ -71,6 +72,9 @@ public:
/** Add a recipient with the key key */
void addRecipient(const GpgME::Key &key);
/** Add a group of recipients */
void addRecipient(const Kleo::KeyGroup &group);
/** Add a placehoder for an unknown key */
void addUnknownRecipient(const char *keyId);
......@@ -80,6 +84,9 @@ public:
/** Remove a Recipient key */
void removeRecipient(const GpgME::Key &key);
/** Remove a recipient group */
void removeRecipient(const Kleo::KeyGroup &group);
/** Validate that each line edit with content has a key. */
bool validate();
......@@ -87,7 +94,6 @@ protected Q_SLOTS:
void updateOp();
void recipientsChanged();
void recpRemovalRequested(CertificateLineEdit *w);
void addRecipient();
void dialogRequested(CertificateLineEdit *w);
protected:
......@@ -102,12 +108,16 @@ Q_SIGNALS:
/* Emitted when the certificate selection might be changed. */
void keysChanged();
private:
CertificateLineEdit* addRecipientWidget();
private:
KeySelectionCombo *mSigSelect = nullptr;
KeySelectionCombo *mSelfSelect = nullptr;
QVector<CertificateLineEdit *> mRecpWidgets;
QVector<UnknownRecipientWidget *> mUnknownWidgets;
QVector<GpgME::Key> mAddedKeys;
QVector<KeyGroup> mAddedGroups;
QGridLayout *mRecpLayout = nullptr;
QString mOp;
AbstractKeyListModel *mModel = nullptr;
......
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