summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-04-28 14:17:01 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-08-02 09:56:51 (GMT)
commit1c351b7a75833b73ddf5931058b727c2f27ec86a (patch)
tree4ab4b0ecc66160c3524b46aa22dcf68870d7d04f
parentac2487e944d99626f6fe8209240490b0717f8b01 (diff)
Add recipient support to signencryptwidget
-rw-r--r--src/crypto/gui/signencryptwidget.cpp128
-rw-r--r--src/crypto/gui/signencryptwidget.h12
2 files changed, 124 insertions, 16 deletions
diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
index d1fdac5..36aa5c1 100644
--- a/src/crypto/gui/signencryptwidget.cpp
+++ b/src/crypto/gui/signencryptwidget.cpp
@@ -1,4 +1,4 @@
-/* crypto/signencryptwidget.cpp
+/* crypto/gui/signencryptwidget.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2016 Intevation GmbH
@@ -38,6 +38,8 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGroupBox>
+#include <QCheckBox>
+#include <QScrollArea>
#include <Libkleo/KeyRequester>
@@ -53,25 +55,95 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
{
QVBoxLayout *lay = new QVBoxLayout;
- QVBoxLayout *sigLay = new QVBoxLayout;
- QGroupBox *sigBox = new QGroupBox(i18nc("@label", "Protect Authenticity (Sign):"));
- sigBox->setCheckable(true);
- sigBox->setChecked(true);
+ /* The signature selection */
+ QHBoxLayout *sigLay = new QHBoxLayout;
+ QCheckBox *sigChk = new QCheckBox(i18nc("@action", "Sign"));
+ sigChk->setChecked(true);
mSigSelect = new CertificateSelectionWidget(this,
CertificateSelectionDialog::SignOnly |
CertificateSelectionDialog::SecretKeys |
CertificateSelectionDialog::AnyFormat,
false);
+ sigLay->addWidget(sigChk);
sigLay->addWidget(mSigSelect);
- sigBox->setLayout(sigLay);
- lay->addWidget(sigBox);
+ lay->addLayout(sigLay);
- connect(sigBox, &QGroupBox::toggled, mSigSelect, &QWidget::setEnabled);
- connect(sigBox, &QGroupBox::toggled, this, &SignEncryptWidget::updateOp);
+ connect(sigChk, &QCheckBox::toggled, mSigSelect, &QWidget::setEnabled);
+ connect(sigChk, &QCheckBox::toggled, this, &SignEncryptWidget::updateOp);
connect(mSigSelect, &CertificateSelectionWidget::keyChanged,
this, &SignEncryptWidget::updateOp);
+ /* Recipient selection */
+ mRecpLayout = new QVBoxLayout;
+ mRecpLayout->setAlignment(Qt::AlignTop);
+ mRecpLayout->addStretch(1);
+ QGroupBox *encBox = new QGroupBox(i18nc("@action", "Encrypt"));
+ encBox->setCheckable(true);
+ encBox->setChecked(true);
+ encBox->setAlignment(Qt::AlignLeft);
+ QVBoxLayout *encBoxLay = new QVBoxLayout;
+ encBox->setLayout(encBoxLay);
+ QWidget *recipientWidget = new QWidget;
+ QScrollArea *recipientScroll = new QScrollArea;
+ recipientWidget->setLayout(mRecpLayout);
+ recipientScroll->setWidget(recipientWidget);
+ recipientScroll->setWidgetResizable(true);
+ recipientScroll->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
+ encBoxLay->addWidget(recipientScroll, 1);
+ connect(encBox, &QGroupBox::toggled, recipientWidget, &QWidget::setEnabled);
+ connect(encBox, &QGroupBox::toggled, this, &SignEncryptWidget::updateOp);
+
+ /* Self certificate */
+ QHBoxLayout *encSelfLay = new QHBoxLayout;
+ QCheckBox *encSelfChk = new QCheckBox(i18nc("@label", "Own certificate:"));
+ encSelfChk->setChecked(true);
+ mSelfSelect = new CertificateSelectionWidget(this,
+ CertificateSelectionDialog::EncryptOnly |
+ CertificateSelectionDialog::SecretKeys |
+ CertificateSelectionDialog::AnyFormat,
+ false);
+ encSelfLay->addWidget(encSelfChk);
+ encSelfLay->addWidget(mSelfSelect);
+
+ encBoxLay->addLayout(encSelfLay);
+
+ connect(encSelfChk, &QCheckBox::toggled, mSelfSelect, &QWidget::setEnabled);
+ connect(encSelfChk, &QCheckBox::toggled, this, &SignEncryptWidget::updateOp);
+ connect(mSelfSelect, &CertificateSelectionWidget::keyChanged,
+ this, &SignEncryptWidget::updateOp);
+
+ lay->addWidget(encBox);
+
setLayout(lay);
+ addRecipient();
+ updateOp();
+}
+
+void SignEncryptWidget::addRecipient()
+{
+ CertificateSelectionWidget *certSel = new CertificateSelectionWidget(this,
+ CertificateSelectionDialog::EncryptOnly |
+ CertificateSelectionDialog::AnyFormat,
+ true);
+ mRecpWidgets << certSel;
+ mRecpLayout->insertWidget(mRecpLayout->count() - 1, certSel);
+ qCDebug(KLEOPATRA_LOG) << "Adding recipient widget.";
+ connect(certSel, &CertificateSelectionWidget::keyChanged,
+ this, &SignEncryptWidget::recipientsChanged);
+}
+
+void SignEncryptWidget::recipientsChanged()
+{
+ bool oneEmpty = false;
+ Q_FOREACH (const CertificateSelectionWidget *w, mRecpWidgets) {
+ if (w->key().isNull()) {
+ oneEmpty = true;
+ break;
+ }
+ }
+ if (!oneEmpty) {
+ addRecipient();
+ }
}
Key SignEncryptWidget::signKey() const
@@ -84,22 +156,50 @@ Key SignEncryptWidget::signKey() const
Key SignEncryptWidget::selfKey() const
{
+ if (mSelfSelect->isEnabled()) {
+ return mSelfSelect->key();
+ }
return Key();
}
QVector <Key> SignEncryptWidget::recipients() const
{
- return QVector<Key>();
+ QVector<Key> ret;
+ Q_FOREACH (const CertificateSelectionWidget *w, mRecpWidgets) {
+ if (!w->isEnabled()) {
+ // If one is disabled, all are disabled.
+ break;
+ }
+ const Key k = w->key();
+ if (!k.isNull()) {
+ ret << k;
+ }
+ }
+ const Key k = selfKey();
+ if (!k.isNull()) {
+ ret << k;
+ }
+ return ret;
}
void SignEncryptWidget::updateOp()
{
- if (!signKey().isNull()) {
- mOp = i18nc("@action", "Sign");
+ const Key sigKey = signKey();
+ const QVector<Key> recp = recipients();
+ QString newOp;
+ if (!sigKey.isNull() && !recp.isEmpty()) {
+ newOp = i18nc("@action", "Sign / Encrypt");
+ } else if (!recp.isEmpty()) {
+ newOp = i18nc("@action", "Encrypt");
+ } else if (!sigKey.isNull()) {
+ newOp = i18nc("@action", "Sign");
} else {
- mOp = QString();
+ newOp = QString();
+ }
+ if (newOp != mOp) {
+ mOp = newOp;
+ Q_EMIT operationChanged(mOp);
}
- Q_EMIT operationChanged(mOp);
}
QString SignEncryptWidget::currentOp() const
diff --git a/src/crypto/gui/signencryptwidget.h b/src/crypto/gui/signencryptwidget.h
index 3793ad9..487a280 100644
--- a/src/crypto/gui/signencryptwidget.h
+++ b/src/crypto/gui/signencryptwidget.h
@@ -1,4 +1,4 @@
-/* crypto/signencryptwidget.h
+/* crypto/gui/signencryptwidget.h
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2016 Intevation GmbH
@@ -35,6 +35,8 @@
#include <QVector>
#include <gpgme++/key.h>
+class QVBoxLayout;
+
namespace Kleo
{
class CertificateSelectionWidget;
@@ -63,6 +65,10 @@ public:
protected Q_SLOTS:
void updateOp();
+ void recipientsChanged();
+
+protected:
+ void addRecipient();
Q_SIGNALS:
/* Emitted when the certificate selection changed the operation
@@ -72,7 +78,9 @@ Q_SIGNALS:
private:
CertificateSelectionWidget *mSigSelect,
- *mEncSelect;
+ *mSelfSelect;
+ QVector<CertificateSelectionWidget *> mRecpWidgets;
+ QVBoxLayout *mRecpLayout;
QString mOp;
};
} // namespace Kleo