Commit 1c351b7a authored by Andre Heinecke's avatar Andre Heinecke
Browse files

Add recipient support to signencryptwidget

parent ac2487e9
/* 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
......
/* 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
......
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