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

Use the key cache instead of running our own keylist job

Running our own keylist job causes unnecessary load. Moreover, we miss
later updates of the key list. Using the key cache to look for uncertified
OpenPGP keys fixes both issues. In particular, the button is hidden/shown
automagically when the last uncertified key is certified or when the
certification of a certified key is revoked.

GnuPG-bug-id: 5850
parent 6ef300c6
......@@ -3,6 +3,8 @@
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -11,6 +13,8 @@
#include "searchbar.h"
#include <Libkleo/Algorithm>
#include <Libkleo/KeyCache>
#include <Libkleo/KeyFilter>
#include <Libkleo/KeyFilterManager>
......@@ -23,9 +27,6 @@
#include <QSortFilterProxyModel>
#include <Libkleo/GnuPG>
#include <qgpgme/keylistjob.h>
#include <qgpgme/protocol.h>
#include <gpgme++/keylistresult.h>
using namespace Kleo;
......@@ -94,23 +95,20 @@ private:
/* List all OpenPGP keys and see if we find one with a UID that is
* not at least fully valid. If we find one, show the certify
* button. */
/* XXX: It would be nice to do this every time the user certifies
* a key. */
void showOrHideCertifyButton() const
{
QGpgME::KeyListJob *job = QGpgME::openpgp()->keyListJob();
connect(job, &QGpgME::KeyListJob::result, job,
[this](const GpgME::KeyListResult&, const std::vector<GpgME::Key> &keys, const QString&, const GpgME::Error&)
{
for (const auto &key: keys) {
if (Kleo::keyValidity(key) < GpgME::UserID::Validity::Full) {
certifyButton->show();
return;
}
}
certifyButton->hide();
});
job->start(QStringList());
if (!KeyCache::instance()->initialized()) {
return;
}
if (Kleo::any_of(KeyCache::instance()->keys(),
[](const auto &key) {
return (key.protocol() == GpgME::OpenPGP)
&& (Kleo::keyValidity(key) < GpgME::UserID::Validity::Full);
})) {
certifyButton->show();
return;
}
certifyButton->hide();
}
private:
......@@ -145,7 +143,6 @@ SearchBar::Private::Private(SearchBar *qq)
"actually belong to the identity they claim to belong to."));
certifyButton->hide();
layout->addWidget(certifyButton);
showOrHideCertifyButton();
proxyModel = new ProxyModel{q};
proxyModel->setSourceModel(KeyFilterManager::instance()->model());
......@@ -160,6 +157,10 @@ SearchBar::Private::Private(SearchBar *qq)
connect(lineEdit, &QLineEdit::textChanged, q, &SearchBar::stringFilterChanged);
connect(combo, SIGNAL(currentIndexChanged(int)), q, SLOT(slotKeyFilterChanged(int)));
connect(certifyButton, SIGNAL(clicked()), q, SLOT(listNotCertifiedKeys()));
connect(KeyCache::instance().get(), &KeyCache::keyListingDone,
q, [this]() { showOrHideCertifyButton(); });
showOrHideCertifyButton();
}
SearchBar::Private::~Private() {}
......
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