Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Add option to filter signencryptwidget by protocol

For some actions (e.g. encrypting text) we don't want
to allow mixed protocols.
parent 98c86cfa
......@@ -267,4 +267,10 @@ bool CertificateLineEdit::isEmpty() const
return text().isEmpty();
}
void CertificateLineEdit::setKeyFilter(const std::shared_ptr<KeyFilter> &filter)
{
mFilter = filter;
mFilterModel->setKeyFilter(filter);
}
#include "certificatelineedit.moc"
......@@ -82,6 +82,9 @@ public:
/** Set the preselected Key for this widget. */
void setKey(const GpgME::Key &key);
/** Set the used keyfilter. */
void setKeyFilter(const std::shared_ptr<KeyFilter> &filter);
Q_SIGNALS:
/** Emitted when the selected key changed. */
void keyChanged();
......@@ -106,6 +109,7 @@ private:
QLabel *mStatusLabel,
*mStatusIcon;
GpgME::Key mKey;
GpgME::Protocol mCurrentProto;
std::shared_ptr<KeyFilter> mFilter;
bool mEditStarted,
mEditFinished;
......
......@@ -63,28 +63,40 @@ namespace {
class SignCertificateFilter: public DefaultKeyFilter
{
public:
SignCertificateFilter() : DefaultKeyFilter()
SignCertificateFilter(GpgME::Protocol proto) : DefaultKeyFilter()
{
setRevoked(DefaultKeyFilter::NotSet);
setExpired(DefaultKeyFilter::NotSet);
setHasSecret(DefaultKeyFilter::Set);
setCanSign(DefaultKeyFilter::Set);
if (proto == GpgME::OpenPGP) {
setIsOpenPGP(DefaultKeyFilter::Set);
} else if (proto == GpgME::CMS) {
setIsOpenPGP(DefaultKeyFilter::NotSet);
}
}
};
class EncryptCertificateFilter: public DefaultKeyFilter
{
public:
EncryptCertificateFilter(): DefaultKeyFilter()
EncryptCertificateFilter(GpgME::Protocol proto): DefaultKeyFilter()
{
setRevoked(DefaultKeyFilter::NotSet);
setExpired(DefaultKeyFilter::NotSet);
setCanEncrypt(DefaultKeyFilter::Set);
if (proto == GpgME::OpenPGP) {
setIsOpenPGP(DefaultKeyFilter::Set);
} else if (proto == GpgME::CMS) {
setIsOpenPGP(DefaultKeyFilter::NotSet);
}
}
};
class EncryptSelfCertificateFilter: public EncryptCertificateFilter
{
public:
EncryptSelfCertificateFilter(): EncryptCertificateFilter()
EncryptSelfCertificateFilter(GpgME::Protocol proto): EncryptCertificateFilter(proto)
{
setRevoked(DefaultKeyFilter::NotSet);
setExpired(DefaultKeyFilter::NotSet);
......@@ -111,7 +123,6 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
mSigChk->setChecked(true);
mSigSelect = new KeySelectionCombo();
mSigSelect->setKeyFilter(std::shared_ptr<KeyFilter>(new SignCertificateFilter()));
sigLay->addWidget(mSigChk);
sigLay->addWidget(mSigSelect, 1);
......@@ -133,7 +144,6 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
// Own key
mSelfSelect = new KeySelectionCombo();
mSelfSelect->setKeyFilter(std::shared_ptr<KeyFilter>(new EncryptSelfCertificateFilter()));
mEncSelfChk = new QCheckBox(i18n("Encrypt for me:"));
mEncSelfChk->setChecked(true);
mRecpLayout->addWidget(mEncSelfChk, 0, 0);
......@@ -191,6 +201,7 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
lay->addWidget(encBox);
loadKeys();
setProtocol(GpgME::UnknownProtocol);
addRecipient(Key());
updateOp();
}
......@@ -203,7 +214,7 @@ void SignEncryptWidget::addRecipient()
void SignEncryptWidget::addRecipient(const Key &key)
{
CertificateLineEdit *certSel = new CertificateLineEdit(mModel, this,
new EncryptCertificateFilter());
new EncryptCertificateFilter(mCurrentProto));
mRecpWidgets << certSel;
if (!mRecpLayout->itemAtPosition(mRecpRowCount - 1, 1)) {
......@@ -394,3 +405,17 @@ void SignEncryptWidget::setEncryptionChecked(bool value)
mEncSelfChk->setChecked(value);
mEncOtherChk->setChecked(value);
}
void SignEncryptWidget::setProtocol(GpgME::Protocol proto)
{
if (mCurrentProto == proto) {
return;
}
mCurrentProto = proto;
mSigSelect->setKeyFilter(std::shared_ptr<KeyFilter>(new SignCertificateFilter(proto)));
mSelfSelect->setKeyFilter(std::shared_ptr<KeyFilter>(new EncryptSelfCertificateFilter(proto)));
const auto encFilter = std::shared_ptr<KeyFilter>(new EncryptCertificateFilter(proto));
Q_FOREACH (CertificateLineEdit *edit, mRecpWidgets) {
edit->setKeyFilter(encFilter);
}
}
......@@ -84,6 +84,10 @@ public:
/** Set wether or not encryption group should be checked */
void setEncryptionChecked(bool value);
/** Filter for a specific protocol. Use UnknownProtocol for both
* S/MIME and OpenPGP */
void setProtocol(GpgME::Protocol protocol);
protected Q_SLOTS:
void updateOp();
void recipientsChanged();
......@@ -115,6 +119,7 @@ private:
*mEncOtherChk,
*mEncSelfChk;
int mRecpRowCount;
GpgME::Protocol mCurrentProto;
};
} // namespace Kleo
#endif // CRYPTO_GUI_SIGNENCRYPTWIDGET_H
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