Commit 5de2f7ac authored by Ingo Klöcker's avatar Ingo Klöcker Committed by Ingo Klöcker
Browse files

Always include the default key in the list of keys to chose from

Add custom subclass of KeyListSortFilterProxyModel that allows specifying
a key that is always accepted by the filtering. Use this subclass
to make sure that the default key is not filtered out.

This fixes the problem that KMail didn't show keys not matching
the email address of an identity in the identity configuration dialog
and that KMail cleared the keys silently if one saved such an identity
after opening the Cryptography tab.

Funded by: Intevation GmbH

BUG: 437091
FIXED-IN: 5.18.0
parent 703a3873
Pipeline #61968 passed with stage
in 7 minutes
......@@ -30,6 +30,40 @@ Q_DECLARE_METATYPE(GpgME::Key)
class SortFilterProxyModel : public KeyListSortFilterProxyModel
using KeyListSortFilterProxyModel::KeyListSortFilterProxyModel;
void setAlwaysAcceptedKey(const QString &fingerprint)
if (fingerprint == mFingerprint) {
mFingerprint = fingerprint;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
if (!mFingerprint.isEmpty()) {
const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
const auto fingerprint = sourceModel()->data(index, KeyList::FingerprintRole).toString();
if (fingerprint == mFingerprint) {
return true;
return KeyListSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
QString mFingerprint;
class ProxyModel : public QSortFilterProxyModel
......@@ -313,7 +347,7 @@ public:
/* Updates the current key with the default key if the key matches
* the current key filter. */
void updateWithDefaultKey() const {
void updateWithDefaultKey() {
GpgME::Protocol filterProto = GpgME::UnknownProtocol;
const auto filter = dynamic_cast<const DefaultKeyFilter*> (sortFilterProxy->keyFilter().get());
......@@ -328,11 +362,13 @@ public:
// Fallback to unknown protocol
defaultKey = defaultKeys.value (GpgME::UnknownProtocol);
// make sure that the default key is not filtered out
Kleo::AbstractKeyListModel *model = nullptr;
Kleo::KeyListSortFilterProxyModel *sortFilterProxy = nullptr;
SortFilterProxyModel *sortFilterProxy = nullptr;
ProxyModel *proxyModel = nullptr;
std::shared_ptr<Kleo::KeyCache> cache;
QMap<GpgME::Protocol, QString> defaultKeys;
......@@ -360,7 +396,7 @@ KeySelectionCombo::KeySelectionCombo(bool secretOnly, QWidget* parent)
d->model = Kleo::AbstractKeyListModel::createFlatKeyListModel(this);
d->secretOnly = secretOnly;
d->sortFilterProxy = new Kleo::KeyListSortFilterProxyModel(this);
d->sortFilterProxy = new SortFilterProxyModel(this);
d->proxyModel = new ProxyModel(this);
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