• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
  • core
KGpgRootNode.cpp
Go to the documentation of this file.
1 /* Copyright 2008,2009,2010,2012,2013 Rolf Eike Beer <kde@opensource.sf-tec.de>
2  *
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License as
5  * published by the Free Software Foundation; either version 2 of
6  * the License or (at your option) version 3 or any later version
7  * accepted by the membership of KDE e.V. (or its successor approved
8  * by the membership of KDE e.V.), which shall act as a proxy
9  * defined in Section 14 of version 3 of the license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "KGpgRootNode.h"
20 
21 #include "KGpgGroupNode.h"
22 #include "kgpginterface.h"
23 #include "KGpgOrphanNode.h"
24 #include "kgpgsettings.h"
25 
26 #include <QString>
27 #include <QStringList>
28 
29 KGpgRootNode::KGpgRootNode(KGpgItemModel *model)
30  : KGpgExpandableNode(NULL),
31  m_groups(0),
32  m_deleting(false)
33 {
34  m_model = model;
35 }
36 
37 KGpgRootNode::~KGpgRootNode()
38 {
39  m_deleting = true;
40 }
41 
42 void
43 KGpgRootNode::readChildren()
44 {
45 }
46 
47 KgpgCore::KgpgItemType
48 KGpgRootNode::getType() const
49 {
50  return 0;
51 }
52 
53 void
54 KGpgRootNode::addGroups(const QStringList &groups)
55 {
56  foreach (const QString &group, groups) {
57  QStringList members = group.split(QLatin1Char(' '));
58  const QString groupName = members.takeFirst();
59  new KGpgGroupNode(this, groupName, members);
60  }
61 }
62 
63 void
64 KGpgRootNode::addKeys(const QStringList &ids)
65 {
66  KgpgCore::KgpgKeyList publiclist = KgpgInterface::readPublicKeys(ids);
67  KgpgCore::KgpgKeyList secretlist = KgpgInterface::readSecretKeys();
68 
69  QStringList issec = secretlist;
70 
71  foreach (KgpgCore::KgpgKey key, publiclist) { // krazy:exclude=foreach
72  int index = issec.indexOf(key.fullId());
73 
74  if (index >= 0) {
75  key.setSecret(true);
76  issec.removeAt(index);
77  secretlist.removeAt(index);
78  }
79 
80  KGpgKeyNode *nd = new KGpgKeyNode(this, key);
81  emit newKeyNode(nd);
82  }
83 
84  foreach (const KgpgCore::KgpgKey &key, secretlist)
85  new KGpgOrphanNode(this, key);
86 }
87 
88 void
89 KGpgRootNode::refreshKeys(KGpgKeyNode::List nodes)
90 {
91  QStringList ids;
92 
93  foreach (const KGpgNode *nd, nodes)
94  ids << nd->getId();
95 
96  KgpgCore::KgpgKeyList publiclist = KgpgInterface::readPublicKeys(ids);
97  QStringList issec = KgpgInterface::readSecretKeys(ids);
98 
99  foreach (KgpgCore::KgpgKey key, publiclist) { // krazy:exclude=foreach
100  int index = issec.indexOf(key.fullId());
101  if (index != -1) {
102  key.setSecret(true);
103  issec.removeAt(index);
104  }
105 
106  for (int j = 0; j < nodes.count(); j++) {
107  KGpgKeyNode *nd = nodes.at(j);
108  if (nd->getId() == key.fullId()) {
109  nodes.removeAt(j);
110  nd->setKey(key);
111  break;
112  }
113  }
114  }
115 }
116 
117 KGpgKeyNode *
118 KGpgRootNode::findKey(const QString &keyId)
119 {
120  int i = findKeyRow(keyId);
121  if (i >= 0) {
122  return children[i]->toKeyNode();
123  }
124 
125  return NULL;
126 }
127 
128 int
129 KGpgRootNode::findKeyRow(const QString &keyId)
130 {
131  int i = 0;
132 
133  foreach (const KGpgNode *node, children) {
134  if ((node->getType() & ITYPE_PAIR) == 0) {
135  ++i;
136  continue;
137  }
138 
139  const KGpgKeyNode *key = node->toKeyNode();
140 
141  if (key->compareId(keyId))
142  return i;
143  ++i;
144  }
145 
146  return -1;
147 }
148 
149 int
150 KGpgRootNode::groupChildren() const
151 {
152  return m_groups;
153 }
154 
155 int
156 KGpgRootNode::findKeyRow(const KGpgKeyNode *key)
157 {
158  for (int i = 0; i < children.count(); i++) {
159  if (children[i] == key)
160  return i;
161  }
162  return -1;
163 }
164 
165 KGpgRootNode *
166 KGpgRootNode::asRootNode()
167 {
168  if (m_deleting)
169  return NULL;
170 
171  return this;
172 }
173 
174 const KGpgRootNode *
175 KGpgRootNode::asRootNode() const
176 {
177  if (m_deleting)
178  return NULL;
179 
180  return this;
181 }
182 
183 #include "KGpgRootNode.moc"
KGpgItemModel
Definition: kgpgitemmodel.h:44
KGpgKeyNode::getId
virtual QString getId() const
Definition: KGpgKeyNode.cpp:113
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KGpgRootNode::refreshKeys
void refreshKeys(KGpgKeyNode::List nodes)
Definition: KGpgRootNode.cpp:89
KGpgRootNode::KGpgRootNode
KGpgRootNode(KGpgItemModel *model)
Definition: KGpgRootNode.cpp:29
KGpgRootNode::KGpgGroupNode
friend class KGpgGroupNode
Definition: KGpgRootNode.h:42
QList::at
const T & at(int i) const
QObject::children
const QObjectList & children() const
QList::removeAt
void removeAt(int i)
KgpgCore::KgpgKey
Definition: kgpgkey.h:236
KgpgCore::KgpgKey::fullId
QString fullId() const
Definition: kgpgkey.cpp:238
KGpgRootNode.h
KGpgKeyNode
A public key with or without corresponding secret key.
Definition: KGpgKeyNode.h:33
KGpgNode::getType
virtual KgpgCore::KgpgItemType getType() const =0
Returns the item type of this object.
QList::count
int count(const T &value) const
KGpgRootNode
The parent of all key data objects.
Definition: KGpgRootNode.h:38
KGpgOrphanNode.h
KGpgRootNode::~KGpgRootNode
virtual ~KGpgRootNode()
Definition: KGpgRootNode.cpp:37
KgpgInterface::readPublicKeys
KgpgCore::KgpgKeyList readPublicKeys(const QStringList &ids=QStringList())
Definition: kgpginterface.cpp:288
KGpgOrphanNode
A lone secret key without public key.
Definition: KGpgOrphanNode.h:33
kgpginterface.h
QString
QList
QStringList
KGpgRootNode::addGroups
void addGroups(const QStringList &groups)
Create new group nodes.
Definition: KGpgRootNode.cpp:54
KgpgCore::KgpgKeyList
Definition: kgpgkey.h:293
KGpgNode
The abstract base class for all classes representing keyring data.
Definition: KGpgNode.h:42
KgpgCore::ITYPE_PAIR
key pair
Definition: kgpgkey.h:94
QLatin1Char
KgpgCore::Images::group
QPixmap group()
Definition: images.cpp:48
KGpgRootNode::findKey
KGpgKeyNode * findKey(const QString &keyId)
Find a key node with the given id.
Definition: KGpgRootNode.cpp:118
KGpgRootNode::addKeys
void addKeys(const QStringList &ids=QStringList())
Definition: KGpgRootNode.cpp:64
kgpgsettings.h
KGpgExpandableNode
The abstract base class for all classes that may have child objects.
Definition: KGpgExpandableNode.h:34
KgpgInterface::readSecretKeys
KgpgCore::KgpgKeyList readSecretKeys(const QStringList &ids=QStringList())
Definition: kgpginterface.cpp:402
KGpgNode::toKeyNode
KGpgKeyNode * toKeyNode()
Definition: KGpgNode.cpp:94
KGpgRootNode::asRootNode
KGpgRootNode * asRootNode()
Return a pointer to this object or NULL.
Definition: KGpgRootNode.cpp:166
QList::takeFirst
T takeFirst()
KGpgRootNode::findKeyRow
int findKeyRow(const QString &keyId)
Return the child number of the key with the given id.
Definition: KGpgRootNode.cpp:129
KGpgNode::getId
virtual QString getId() const
Definition: KGpgNode.cpp:318
KGpgRootNode::getType
virtual KgpgCore::KgpgItemType getType() const
Returns the item type of this object.
Definition: KGpgRootNode.cpp:48
KGpgRootNode::groupChildren
int groupChildren() const
Return the group count.
Definition: KGpgRootNode.cpp:150
KGpgGroupNode.h
QStringList::indexOf
int indexOf(const QRegExp &rx, int from) const
KGpgRootNode::newKeyNode
void newKeyNode(KGpgKeyNode *)
KGpgKeyNode::compareId
bool compareId(const QString &other) const
compare the id of this node to the given other node
Definition: KGpgKeyNode.cpp:339
KGpgKeyNode::setKey
void setKey(const KgpgCore::KgpgKey &key)
Replaces the current key information with the new one.
Definition: KGpgKeyNode.cpp:180
KgpgCore::KgpgKey::setSecret
void setSecret(const bool secret)
Definition: kgpgkey.cpp:183
KGpgRootNode::readChildren
virtual void readChildren()
reimplemented in every base class to read in the child data
Definition: KGpgRootNode.cpp:43
KGpgNode::m_model
KGpgItemModel * m_model
Definition: KGpgNode.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal