Libkleo

keyfiltermanager.h
1/*
2 keyfiltermanager.h
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "kleo_export.h"
13
14#include <Libkleo/KeyFilter>
15
16#include <QObject>
17#include <QSortFilterProxyModel>
18
19#include <gpgme++/global.h>
20
21#include <memory>
22#include <vector>
23
24namespace GpgME
25{
26class Key;
27class UserID;
28}
29
30class QModelIndex;
31class QFont;
32class QColor;
33class QIcon;
34
35namespace Kleo
36{
37
38class KLEO_EXPORT KeyFilterManager : public QObject
39{
40 Q_OBJECT
41public:
42 enum ModelRoles {
43 FilterIdRole = Qt::UserRole,
44 FilterMatchContextsRole,
45 FilterRole,
46 };
47
48protected:
49 explicit KeyFilterManager(QObject *parent = nullptr);
50 ~KeyFilterManager() override;
51
52public:
53 static KeyFilterManager *instance();
54
55 /**
56 * Adds the rule that keys must match @p protocol to all filters.
57 */
58 void alwaysFilterByProtocol(GpgME::Protocol protocol);
59 GpgME::Protocol protocol() const;
60
61 const std::shared_ptr<KeyFilter> &filterMatching(const GpgME::Key &key, KeyFilter::MatchContexts contexts) const;
62 std::vector<std::shared_ptr<KeyFilter>> filtersMatching(const GpgME::Key &key, KeyFilter::MatchContexts contexts) const;
63
64 QAbstractItemModel *model() const;
65
66 const std::shared_ptr<KeyFilter> &keyFilterByID(const QString &id) const;
67 const std::shared_ptr<KeyFilter> &fromModelIndex(const QModelIndex &mi) const;
68 QModelIndex toModelIndex(const std::shared_ptr<KeyFilter> &kf) const;
69
70 void reload();
71
72 QFont font(const GpgME::Key &key, const QFont &baseFont) const;
73 QColor bgColor(const GpgME::Key &key) const;
74 QColor bgColor(const GpgME::UserID &userID) const;
75 QColor fgColor(const GpgME::Key &key) const;
76 QColor fgColor(const GpgME::UserID &userID) const;
77 QIcon icon(const GpgME::Key &key) const;
78
79 class Private;
80
81Q_SIGNALS:
82 void alwaysFilterByProtocolChanged(GpgME::Protocol protocol);
83
84private:
85 std::unique_ptr<Private> d;
86 static KeyFilterManager *mSelf;
87};
88
89class KLEO_EXPORT KeyFilterModel : public QSortFilterProxyModel
90{
91 Q_OBJECT
92
93public:
94 KeyFilterModel(QObject *parent = nullptr);
95 bool isCustomFilter(int row) const;
96 void prependCustomFilter(const std::shared_ptr<KeyFilter> &filter);
97
98 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
99 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
100
101 QModelIndex mapToSource(const QModelIndex &index) const override;
102 QModelIndex mapFromSource(const QModelIndex &source_index) const override;
103
104 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
105 Qt::ItemFlags flags(const QModelIndex &index) const override;
106 QModelIndex parent(const QModelIndex &) const override;
107 QVariant data(const QModelIndex &index, int role) const override;
108
109private:
110 class Private;
111 const std::unique_ptr<Private> d;
112};
113}
const QList< QKeySequence > & reload()
UserRole
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.