File indexing completed on 2024-04-21 05:50:40

0001 /*
0002     SPDX-FileCopyrightText: 2008 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 SELECTKEYPROXYMODEL_H
0007 #define SELECTKEYPROXYMODEL_H
0008 
0009 #include <QSortFilterProxyModel>
0010 
0011 class KGpgNode;
0012 class KGpgItemModel;
0013 
0014 /**
0015  * @brief filter model to select a public key for encryption
0016  */
0017 class SelectKeyProxyModel: public QSortFilterProxyModel
0018 {
0019     Q_PROPERTY(bool showUntrusted read showUntrusted write setShowUntrusted)
0020 
0021 public:
0022     explicit SelectKeyProxyModel(QObject * parent);
0023 
0024     void setKeyModel(KGpgItemModel *);
0025 
0026     KGpgNode *nodeForIndex(const QModelIndex &index) const;
0027 
0028     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0029 
0030     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0031     bool hasChildren(const QModelIndex &parent) const override;
0032     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0033 
0034     bool showUntrusted() const;
0035     void setShowUntrusted(const bool b);
0036 
0037 protected:
0038     bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
0039     int columnCount(const QModelIndex &) const override;
0040 
0041     KGpgItemModel *m_model;
0042 
0043 private:
0044     bool m_showUntrusted;
0045 };
0046 
0047 class SelectSecretKeyProxyModel: public SelectKeyProxyModel
0048 {
0049 public:
0050     explicit SelectSecretKeyProxyModel(QObject *parent);
0051 
0052     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0053 
0054     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0055     bool hasChildren(const QModelIndex &parent) const override;
0056     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0057 
0058 protected:
0059     bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
0060     int columnCount(const QModelIndex &) const override;
0061 };
0062 
0063 #endif