aboutsummaryrefslogtreecommitdiffstats
path: root/kgpg/KGpgRootNode.h
blob: 97c597cbb36097df37b57f4dea307bc12180455c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef KGPGROOTNODE_H
#define KGPGROOTNODE_H

#include "KGpgExpandableNode.h"
#include "KGpgKeyNode.h"

class KGpgGroupNode;
class QString;
class QStringList;

/**
 * @brief The parent of all key data objects
 *
 * This object is invisible to the user but acts as the internal base object for
 * everything in the keyring. It is anchestor of all other KGpgNode objects and
 * the only one that will ever return NULL when calling getParentKeyNode() on it.
 *
 * There is only one object of this type around at any time.
 */
class KGpgRootNode : public KGpgExpandableNode
{
	Q_OBJECT

	friend class KGpgGroupNode;

private:
	int m_groups;
	int m_deleting;

protected:
	virtual void readChildren();

public:
	explicit KGpgRootNode(KGpgItemModel *model);
	virtual ~KGpgRootNode();

	virtual KgpgCore::KgpgItemType getType() const;

	/**
	 * Create new group nodes
	 * @param groups list of group names to create
	 */
	void addGroups(const QStringList &groups);
	void addKeys(const QStringList &ids = QStringList());
	void refreshKeys(KGpgKeyNode::List nodes);
	/**
	 * Find a key node with the given id
	 *
	 * This scans the list of primary keys for a key with the given id
	 * and returns the corresponding key node.
	 *
	 * The key id will be matched against the characters given in keyId.
	 * If you give only 8 or 16 byte you will still find the key if it
	 * exists. To be really sure to find the correct node you should pass
	 * the complete fingerprint whenever possible.
	 *
	 * @param keyId the key id to find, any length is permitted
	 * @return pointer to key node or %NULL if no such key
	 */
	KGpgKeyNode *findKey(const QString &keyId);
	/**
	 * Return the child number of the key with the given id
	 *
	 * This scans the list of direct children for a key with the given
	 * key id. It returns the number in the internal list of children
	 * which is identical to the row number in the item model. Since
	 * proxy models may sort the items you should only call this function
	 * from the primary model (i.e. KGpgItemModel).
	 *
	 * The key id will be matched against the characters given in keyId.
	 * If you give only 8 or 16 byte you will still find the key if it
	 * exists. To be really sure to find the correct node you should pass
	 * the complete fingerprint whenever possible.
	 *
	 * @param keyId the key id to find, any length is permitted
	 * @return the child number or -1 if there is no such key
	 */
	int findKeyRow(const QString &keyId);

	/**
	 * Return the child number of the given key
	 * @param key the key to search for
	 *
	 * @overload
	 */
	int findKeyRow(const KGpgKeyNode *key);

	/**
	 * Return the group count
	 * @return the number of group nodes
	 */
	int groupChildren() const;

	/**
	 * Return a pointer to this object or NULL
	 *
	 * This returns a pointer to this object if the object will persist,
	 * i.e. is not currently in destruction. If the object is already
	 * cleaning up NULL is returned.
	 */
	KGpgRootNode *asRootNode();
	/**
	 * @overload
	 */
	const KGpgRootNode *asRootNode() const;

Q_SIGNALS:
	void newKeyNode(KGpgKeyNode *);
};

#endif /* KGPGROOTNODE_H */