File indexing completed on 2024-12-08 08:16:19
0001 /* 0002 SPDX-FileCopyrightText: 2008, 2013 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 #ifndef KEYLISTPROXYMODEL_H 0007 #define KEYLISTPROXYMODEL_H 0008 0009 #include <QSortFilterProxyModel> 0010 #include "core/kgpgkey.h" 0011 0012 class KGpgNode; 0013 class KGpgItemModel; 0014 class KeyListProxyModelPrivate; 0015 0016 class KeyListProxyModel: public QSortFilterProxyModel 0017 { 0018 Q_OBJECT 0019 0020 Q_PROPERTY(int idLength READ idLength WRITE setIdLength) 0021 Q_DECLARE_PRIVATE(KeyListProxyModel) 0022 0023 KeyListProxyModelPrivate * const d_ptr; 0024 0025 public: 0026 enum DisplayMode { 0027 MultiColumn = 0, 0028 SingleColumnIdFirst = 1, 0029 SingleColumnIdLast = 2 0030 }; 0031 0032 explicit KeyListProxyModel(QObject * parent = nullptr, const DisplayMode mode = MultiColumn); 0033 ~KeyListProxyModel() override; 0034 0035 bool hasChildren(const QModelIndex &idx) const override; 0036 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0037 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0038 Qt::ItemFlags flags(const QModelIndex &index) const override; 0039 void setKeyModel(KGpgItemModel *); 0040 /** 0041 * @brief set the minimum trust level to be shown 0042 * @param t trust level 0043 * 0044 * This enables filtering by key trust. All keys that have a lower trust than 0045 * the given value will be hidden. 0046 */ 0047 void setTrustFilter(const KgpgCore::KgpgKeyTrustFlag t); 0048 0049 /** 0050 * @brief show only keys capable of encryption 0051 */ 0052 void setEncryptionKeyFilter(bool b); 0053 0054 KGpgNode *nodeForIndex(const QModelIndex &index) const; 0055 QModelIndex nodeIndex(KGpgNode *node); 0056 void setPreviewSize(const int pixel); 0057 KGpgItemModel *getModel() const; 0058 int idLength() const; 0059 void setIdLength(const int length); 0060 0061 public Q_SLOTS: 0062 /** 0063 * @brief set if only secret keys should be shown 0064 * @param b new value 0065 */ 0066 void setOnlySecret(const bool b); 0067 0068 /** 0069 * @brief call this when the settings have changed 0070 */ 0071 void settingsChanged(); 0072 0073 protected: 0074 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 0075 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0076 }; 0077 0078 #endif