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

0001 /*
0002     SPDX-FileCopyrightText: 2008, 2009 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 
0007 #ifndef KGPGROOTNODE_H
0008 #define KGPGROOTNODE_H
0009 
0010 #include "KGpgExpandableNode.h"
0011 #include "KGpgKeyNode.h"
0012 
0013 #include <QStringList>
0014 
0015 class KGpgGroupNode;
0016 class QString;
0017 
0018 /**
0019  * @brief The parent of all key data objects
0020  *
0021  * This object is invisible to the user but acts as the internal base object for
0022  * everything in the keyring. It is anchestor of all other KGpgNode objects and
0023  * the only one that will ever return nullptr when calling getParentKeyNode() on it.
0024  *
0025  * There is only one object of this type around at any time.
0026  */
0027 class KGpgRootNode : public KGpgExpandableNode
0028 {
0029     Q_OBJECT
0030 
0031     friend class KGpgGroupNode;
0032 
0033 private:
0034     int m_groups;
0035 
0036 protected:
0037     void readChildren() override;
0038 
0039 public:
0040     explicit KGpgRootNode(KGpgItemModel *model);
0041     ~KGpgRootNode() override;
0042 
0043     KgpgCore::KgpgItemType getType() const override;
0044 
0045     /**
0046      * Create new group nodes
0047      * @param groups list of group names and keys to create
0048      *
0049      * The format of each entry of groups is name:keys, where keys is
0050      * a list of key ids separated by semicolons. This is the format
0051      * that is output by "gpg --list-config --with-colons".
0052      */
0053     void addGroups(const QStringList &groups);
0054     void addKeys(const QStringList &ids = QStringList());
0055     void refreshKeys(KGpgKeyNode::List nodes);
0056     /**
0057      * Find a key node with the given id
0058      *
0059      * This scans the list of primary keys for a key with the given id
0060      * and returns the corresponding key node.
0061      *
0062      * The key id will be matched against the characters given in keyId.
0063      * If you give only 8 or 16 byte you will still find the key if it
0064      * exists. To be really sure to find the correct node you should pass
0065      * the complete fingerprint whenever possible.
0066      *
0067      * @param keyId the key id to find, any length is permitted
0068      * @return pointer to key node or %nullptr if no such key
0069      */
0070     KGpgKeyNode *findKey(const QString &keyId);
0071     /**
0072      * Return the child number of the key with the given id
0073      *
0074      * This scans the list of direct children for a key with the given
0075      * key id. It returns the number in the internal list of children
0076      * which is identical to the row number in the item model. Since
0077      * proxy models may sort the items you should only call this function
0078      * from the primary model (i.e. KGpgItemModel).
0079      *
0080      * The key id will be matched against the characters given in keyId.
0081      * If you give only 8 or 16 byte you will still find the key if it
0082      * exists. To be really sure to find the correct node you should pass
0083      * the complete fingerprint whenever possible.
0084      *
0085      * @param keyId the key id to find, any length is permitted
0086      * @return the child number or -1 if there is no such key
0087      */
0088     int findKeyRow(const QString &keyId);
0089 
0090     /**
0091      * Return the child number of the given key
0092      * @param key the key to search for
0093      *
0094      * @overload
0095      */
0096     int findKeyRow(const KGpgKeyNode *key);
0097 
0098     /**
0099      * Return the group count
0100      * @return the number of group nodes
0101      */
0102     int groupChildren() const;
0103 
0104 Q_SIGNALS:
0105     void newKeyNode(KGpgKeyNode *);
0106 };
0107 
0108 #endif /* KGPGROOTNODE_H */