summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-05-12 10:48:16 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-07-22 09:10:27 (GMT)
commit1ca721ca8d983726aeeb58f07347f5ef59737dd1 (patch)
tree6f2a7d32cfdd202a68de74117238b545d64960c8
parent1e20795fc16b18ee0da2abc6b05e0793b49d0884 (diff)
Add function to get model based on keycache
-rw-r--r--src/models/keylistmodel.cpp25
-rw-r--r--src/models/keylistmodel.h2
2 files changed, 26 insertions, 1 deletions
diff --git a/src/models/keylistmodel.cpp b/src/models/keylistmodel.cpp
index 4239856..35512f7 100644
--- a/src/models/keylistmodel.cpp
+++ b/src/models/keylistmodel.cpp
@@ -33,6 +33,7 @@
#include <config-kleopatra.h>
#include "keylistmodel.h"
+#include "keycache.h"
#include "Libkleo/Predicates"
#ifdef KLEO_MODEL_TEST
@@ -151,9 +152,14 @@ static inline uint qHash(const char *data)
class AbstractKeyListModel::Private
{
public:
- Private() : m_toolTipOptions(Formatting::Validity) {}
+ Private() :
+ m_toolTipOptions(Formatting::Validity),
+ m_useKeyCache(false),
+ m_secretOnly(false) {}
int m_toolTipOptions;
mutable QHash<const char *, QVariant> prettyEMailCache;
+ bool m_useKeyCache;
+ bool m_secretOnly;
};
AbstractKeyListModel::AbstractKeyListModel(QObject *p)
: QAbstractItemModel(p), KeyListModelInterface(), d(new Private)
@@ -955,6 +961,23 @@ void HierarchicalKeyListModel::doRemoveKey(const Key &key)
endRemoveRows();
}
+void AbstractKeyListModel::useKeyCache(bool value, bool secretOnly)
+{
+ d->m_secretOnly = secretOnly;
+ d->m_useKeyCache = value;
+ if (value) {
+ setKeys(d->m_secretOnly ? KeyCache::instance()->secretKeys() : KeyCache::instance()->keys());
+ } else {
+ setKeys(std::vector<Key>());
+ }
+ connect(KeyCache::instance().get(), &KeyCache::keysMayHaveChanged,
+ this, [this] {
+ if (d->m_useKeyCache) {
+ setKeys(d->m_secretOnly ? KeyCache::instance()->secretKeys() : KeyCache::instance()->keys());
+ }
+ });
+}
+
// static
AbstractKeyListModel *AbstractKeyListModel::createFlatKeyListModel(QObject *p)
{
diff --git a/src/models/keylistmodel.h b/src/models/keylistmodel.h
index 7ae9c1b..28f930d 100644
--- a/src/models/keylistmodel.h
+++ b/src/models/keylistmodel.h
@@ -75,6 +75,8 @@ Q_SIGNALS:
public Q_SLOTS:
void setKeys(const std::vector<GpgME::Key> &keys);
+ /* Set this to set all or only secret keys from the keycache. */
+ void useKeyCache(bool value, bool secretOnly);
QModelIndex addKey(const GpgME::Key &key);
QList<QModelIndex> addKeys(const std::vector<GpgME::Key> &keys);
void removeKey(const GpgME::Key &key);