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

0001 /*
0002     SPDX-FileCopyrightText: 2008, 2009, 2010, 2011, 2012 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 KGPGITEMMODEL_H
0007 #define KGPGITEMMODEL_H
0008 
0009 #include "core/kgpgkey.h"
0010 #include "core/KGpgKeyNode.h"
0011 #include "core/KGpgNode.h"
0012 
0013 #include <QAbstractItemModel>
0014 #include <QString>
0015 #include <QStringList>
0016 
0017 #define KEYCOLUMN_NAME  0
0018 #define KEYCOLUMN_EMAIL 1
0019 #define KEYCOLUMN_TRUST 2
0020 #define KEYCOLUMN_EXPIR 3
0021 #define KEYCOLUMN_SIZE  4
0022 #define KEYCOLUMN_CREAT 5
0023 #define KEYCOLUMN_ID    6
0024 
0025 class KGpgExpandableNode;
0026 class KGpgGroupNode;
0027 class KGpgGroupMemberNode;
0028 class KGpgRootNode;
0029 class QColor;
0030 
0031 class KGpgItemModel : public QAbstractItemModel
0032 {
0033     Q_OBJECT
0034 
0035 private:
0036     KGpgRootNode *m_root;
0037     QString m_default;
0038 
0039 public:
0040 
0041     explicit KGpgItemModel(QObject *parent = nullptr);
0042     ~KGpgItemModel() override;
0043 
0044     QModelIndex index(int row, int column,
0045                 const QModelIndex &parent = QModelIndex()) const override;
0046     QModelIndex parent(const QModelIndex &child) const override;
0047 
0048     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0049     int columnCount(const QModelIndex & /*parent = QModelIndex()*/ ) const override
0050             { return 7; }
0051 
0052     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0053     bool hasChildren(const QModelIndex &parent) const override;
0054     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0055 
0056     KGpgNode *nodeForIndex(const QModelIndex &index) const;
0057     KGpgKeyNode *findKeyNode(const QString &id) const;
0058 
0059     KGpgRootNode *getRootNode() const;
0060     QString statusCountMessage() const;
0061     static QString statusCountMessageString(const unsigned int keys, const unsigned int groups);
0062     bool isDefaultKey(const KGpgNode *node) const;
0063 
0064 public Q_SLOTS:
0065     KGpgGroupNode *addGroup(const QString &name, const KGpgKeyNode::List &keys);
0066     void delNode(KGpgNode *node);
0067     void changeGroup(KGpgGroupNode *node, const KGpgNode::List &keys);
0068     void deleteFromGroup(KGpgGroupNode *group, KGpgGroupMemberNode *member);
0069     void setDefaultKey(KGpgKeyNode *def);
0070     QModelIndex nodeIndex(KGpgNode *node, const int column = 0);
0071     inline void refreshKey(const QString &id)
0072     { refreshKeys(QStringList(id)); }
0073     inline void refreshKey(KGpgKeyNode *nd)
0074     { refreshKeys(KGpgKeyNode::List() << nd); }
0075     void refreshKeys(const QStringList &ids);
0076     void refreshKeys(KGpgKeyNode::List keys);
0077     void refreshAllKeys();
0078     void refreshGroups();
0079     void invalidateIndexes(KGpgNode *nd);
0080     void refreshTrust(const KgpgCore::KgpgKeyTrust trust, const QColor &color);
0081 
0082 protected:
0083     int rowForNode(KGpgNode *node) const;
0084     void updateNodeTrustColor(KGpgExpandableNode *node, const KgpgCore::KgpgKeyTrust trust, const QColor &color);
0085 };
0086 
0087 #endif