1 /* 2 SPDX-FileCopyrightText: 2008, 2009, 2012 Rolf Eike Beer <kde@opensource.sf-tec.de> 3 4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 5 */ 6 #include "KGpgNode.h" 7 8 #include "KGpgGroupMemberNode.h" 9 #include "KGpgGroupNode.h" 10 #include "KGpgOrphanNode.h" 11 #include "KGpgRootNode.h" 12 #include "KGpgSubkeyNode.h" 13 #include "KGpgUatNode.h" 14 #include "KGpgUidNode.h" 15 #include "model/kgpgitemmodel.h" 16 17 #include <KLocalizedString> 18 KGpgNode(KGpgExpandableNode * parent)19KGpgNode::KGpgNode(KGpgExpandableNode *parent) 20 : QObject(), m_parent(parent) 21 { 22 if (parent == nullptr) 23 m_model = nullptr; 24 else 25 m_model = parent->m_model; 26 } 27 ~KGpgNode()28KGpgNode::~KGpgNode() 29 { 30 Q_ASSERT(m_model); 31 m_model->invalidateIndexes(this); 32 33 if (m_parent != nullptr) 34 m_parent->deleteChild(this); 35 } 36 37 QString getNameComment() const38KGpgNode::getNameComment() const 39 { 40 if (getComment().isEmpty()) 41 return getName(); 42 else 43 return i18nc("Name of uid (comment)", "%1 (%2)", getName(), getComment()); 44 } 45 46 KGpgExpandableNode * toExpandableNode()47KGpgNode::toExpandableNode() 48 { 49 Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && !(getType() & KgpgCore::ITYPE_PAIR)) || 50 (getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT))); 51 52 return qobject_cast<KGpgExpandableNode *>(this); 53 } 54 55 const KGpgExpandableNode * toExpandableNode() const56KGpgNode::toExpandableNode() const 57 { 58 Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && !(getType() & KgpgCore::ITYPE_PAIR)) || 59 (getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT))); 60 61 return qobject_cast<const KGpgExpandableNode *>(this); 62 } 63 64 KGpgSignableNode * toSignableNode()65KGpgNode::toSignableNode() 66 { 67 Q_ASSERT(getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT)); 68 69 return qobject_cast<KGpgSignableNode *>(this); 70 } 71 72 const KGpgSignableNode * toSignableNode() const73KGpgNode::toSignableNode() const 74 { 75 Q_ASSERT(getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT)); 76 77 return qobject_cast<const KGpgSignableNode *>(this); 78 } 79 80 KGpgKeyNode * toKeyNode()81KGpgNode::toKeyNode() 82 { 83 Q_ASSERT(getType() & KgpgCore::ITYPE_PAIR); 84 Q_ASSERT(!(getType() & KgpgCore::ITYPE_GROUP)); 85 86 return qobject_cast<KGpgKeyNode *>(this); 87 } 88 89 const KGpgKeyNode * toKeyNode() const90KGpgNode::toKeyNode() const 91 { 92 Q_ASSERT(getType() & KgpgCore::ITYPE_PAIR); 93 Q_ASSERT(!(getType() & KgpgCore::ITYPE_GROUP)); 94 95 return qobject_cast<const KGpgKeyNode *>(this); 96 } 97 98 KGpgRootNode * toRootNode()99KGpgNode::toRootNode() 100 { 101 Q_ASSERT((m_parent == nullptr) && (getType() == 0)); 102 103 return static_cast<KGpgRootNode *>(this); 104 } 105 106 const KGpgRootNode * toRootNode() const107KGpgNode::toRootNode() const 108 { 109 Q_ASSERT((m_parent == nullptr) && (getType() == 0)); 110 111 return static_cast<const KGpgRootNode *>(this); 112 } 113 114 KGpgUidNode * toUidNode()115KGpgNode::toUidNode() 116 { 117 Q_ASSERT(getType() == KgpgCore::ITYPE_UID); 118 119 return static_cast<KGpgUidNode *>(this); 120 } 121 122 const KGpgUidNode * toUidNode() const123KGpgNode::toUidNode() const 124 { 125 Q_ASSERT(getType() == KgpgCore::ITYPE_UID); 126 127 return static_cast<const KGpgUidNode *>(this); 128 } 129 130 KGpgSubkeyNode * toSubkeyNode()131KGpgNode::toSubkeyNode() 132 { 133 Q_ASSERT(getType() == KgpgCore::ITYPE_SUB); 134 135 return static_cast<KGpgSubkeyNode *>(this); 136 } 137 138 const KGpgSubkeyNode * toSubkeyNode() const139KGpgNode::toSubkeyNode() const 140 { 141 Q_ASSERT(getType() == KgpgCore::ITYPE_SUB); 142 143 return static_cast<const KGpgSubkeyNode *>(this); 144 } 145 146 KGpgUatNode * toUatNode()147KGpgNode::toUatNode() 148 { 149 Q_ASSERT(getType() == KgpgCore::ITYPE_UAT); 150 151 return static_cast<KGpgUatNode *>(this); 152 } 153 154 const KGpgUatNode * toUatNode() const155KGpgNode::toUatNode() const 156 { 157 Q_ASSERT(getType() == KgpgCore::ITYPE_UAT); 158 159 return static_cast<const KGpgUatNode *>(this); 160 } 161 162 KGpgGroupNode * toGroupNode()163KGpgNode::toGroupNode() 164 { 165 Q_ASSERT(getType() == KgpgCore::ITYPE_GROUP); 166 167 return static_cast<KGpgGroupNode *>(this); 168 } 169 170 const KGpgGroupNode * toGroupNode() const171KGpgNode::toGroupNode() const 172 { 173 Q_ASSERT(getType() == KgpgCore::ITYPE_GROUP); 174 175 return static_cast<const KGpgGroupNode *>(this); 176 } 177 178 KGpgRefNode * toRefNode()179KGpgNode::toRefNode() 180 { 181 Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)) || (getType() & KgpgCore::ITYPE_SIGN)); 182 183 return qobject_cast<KGpgRefNode *>(this); 184 } 185 186 const KGpgRefNode * toRefNode() const187KGpgNode::toRefNode() const 188 { 189 Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)) || (getType() & KgpgCore::ITYPE_SIGN)); 190 191 return qobject_cast<const KGpgRefNode *>(this); 192 } 193 194 KGpgGroupMemberNode * toGroupMemberNode()195KGpgNode::toGroupMemberNode() 196 { 197 Q_ASSERT((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)); 198 199 return static_cast<KGpgGroupMemberNode *>(this); 200 } 201 202 const KGpgGroupMemberNode * toGroupMemberNode() const203KGpgNode::toGroupMemberNode() const 204 { 205 Q_ASSERT((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)); 206 207 return static_cast<const KGpgGroupMemberNode *>(this); 208 } 209 210 KGpgSignNode * toSignNode()211KGpgNode::toSignNode() 212 { 213 Q_ASSERT(getType() == KgpgCore::ITYPE_SIGN); 214 215 return static_cast<KGpgSignNode *>(this); 216 } 217 218 const KGpgSignNode * toSignNode() const219KGpgNode::toSignNode() const 220 { 221 Q_ASSERT(getType() == KgpgCore::ITYPE_SIGN); 222 223 return static_cast<const KGpgSignNode *>(this); 224 } 225 226 KGpgOrphanNode * toOrphanNode()227KGpgNode::toOrphanNode() 228 { 229 Q_ASSERT(getType() == KgpgCore::ITYPE_SECRET); 230 231 return static_cast<KGpgOrphanNode *>(this); 232 } 233 234 const KGpgOrphanNode * toOrphanNode() const235KGpgNode::toOrphanNode() const 236 { 237 Q_ASSERT(getType() == KgpgCore::ITYPE_SECRET); 238 239 return static_cast<const KGpgOrphanNode *>(this); 240 } 241 242 bool hasChildren() const243KGpgNode::hasChildren() const 244 { 245 return false; 246 } 247 248 int getChildCount()249KGpgNode::getChildCount() 250 { 251 return 0; 252 } 253 254 KGpgNode * getChild(const int index) const255KGpgNode::getChild(const int index) const 256 { 257 Q_UNUSED(index); 258 return nullptr; 259 } 260 261 int getChildIndex(KGpgNode * node) const262KGpgNode::getChildIndex(KGpgNode *node) const 263 { 264 Q_UNUSED(node); 265 return 0; 266 } 267 268 KgpgCore::KgpgKeyTrust getTrust() const269KGpgNode::getTrust() const 270 { 271 return TRUST_NOKEY; 272 } 273 274 QString getSize() const275KGpgNode::getSize() const 276 { 277 return QString(); 278 } 279 280 QString getName() const281KGpgNode::getName() const 282 { 283 return QString(); 284 } 285 286 QString getEmail() const287KGpgNode::getEmail() const 288 { 289 return QString(); 290 } 291 292 QDateTime getExpiration() const293KGpgNode::getExpiration() const 294 { 295 return QDateTime(); 296 } 297 298 QDateTime getCreation() const299KGpgNode::getCreation() const 300 { 301 return QDateTime(); 302 } 303 304 QString getId() const305KGpgNode::getId() const 306 { 307 return QString(); 308 } 309 310 QString getComment() const311KGpgNode::getComment() const 312 { 313 return QString(); 314 } 315 316 KGpgExpandableNode * getParentKeyNode() const317KGpgNode::getParentKeyNode() const 318 { 319 return m_parent; 320 } 321