/* Copyright 2008,2009,2012 Rolf Eike Beer * * 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 . */ #include "KGpgNode.h" #include "KGpgGroupMemberNode.h" #include "KGpgGroupNode.h" #include "KGpgOrphanNode.h" #include "KGpgRootNode.h" #include "KGpgSubkeyNode.h" #include "KGpgUatNode.h" #include "KGpgUidNode.h" #include "model/kgpgitemmodel.h" #include KGpgNode::KGpgNode(KGpgExpandableNode *parent) : QObject(), m_parent(parent) { if (parent == NULL) m_model = NULL; else m_model = parent->m_model; } KGpgNode::~KGpgNode() { Q_ASSERT(m_model); m_model->invalidateIndexes(this); if (m_parent != NULL) m_parent->deleteChild(this); } QString KGpgNode::getNameComment() const { if (getComment().isEmpty()) return getName(); else return i18nc("Name of uid (comment)", "%1 (%2)", getName(), getComment()); } KGpgExpandableNode * KGpgNode::toExpandableNode() { Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && !(getType() & KgpgCore::ITYPE_PAIR)) || (getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT))); return qobject_cast(this); } const KGpgExpandableNode * KGpgNode::toExpandableNode() const { Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && !(getType() & KgpgCore::ITYPE_PAIR)) || (getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT))); return qobject_cast(this); } KGpgSignableNode * KGpgNode::toSignableNode() { Q_ASSERT(getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT)); return qobject_cast(this); } const KGpgSignableNode * KGpgNode::toSignableNode() const { Q_ASSERT(getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT)); return qobject_cast(this); } KGpgKeyNode * KGpgNode::toKeyNode() { Q_ASSERT(getType() & KgpgCore::ITYPE_PAIR); Q_ASSERT(!(getType() & KgpgCore::ITYPE_GROUP)); return qobject_cast(this); } const KGpgKeyNode * KGpgNode::toKeyNode() const { Q_ASSERT(getType() & KgpgCore::ITYPE_PAIR); Q_ASSERT(!(getType() & KgpgCore::ITYPE_GROUP)); return qobject_cast(this); } KGpgRootNode * KGpgNode::toRootNode() { Q_ASSERT((m_parent == NULL) && (getType() == 0)); return static_cast(this)->asRootNode(); } const KGpgRootNode * KGpgNode::toRootNode() const { Q_ASSERT((m_parent == NULL) && (getType() == 0)); return static_cast(this)->asRootNode(); } KGpgUidNode * KGpgNode::toUidNode() { Q_ASSERT(getType() == KgpgCore::ITYPE_UID); return static_cast(this); } const KGpgUidNode * KGpgNode::toUidNode() const { Q_ASSERT(getType() == KgpgCore::ITYPE_UID); return static_cast(this); } KGpgSubkeyNode * KGpgNode::toSubkeyNode() { Q_ASSERT(getType() == KgpgCore::ITYPE_SUB); return static_cast(this); } const KGpgSubkeyNode * KGpgNode::toSubkeyNode() const { Q_ASSERT(getType() == KgpgCore::ITYPE_SUB); return static_cast(this); } KGpgUatNode * KGpgNode::toUatNode() { Q_ASSERT(getType() == KgpgCore::ITYPE_UAT); return static_cast(this); } const KGpgUatNode * KGpgNode::toUatNode() const { Q_ASSERT(getType() == KgpgCore::ITYPE_UAT); return static_cast(this); } KGpgGroupNode * KGpgNode::toGroupNode() { Q_ASSERT(getType() == KgpgCore::ITYPE_GROUP); return static_cast(this); } const KGpgGroupNode * KGpgNode::toGroupNode() const { Q_ASSERT(getType() == KgpgCore::ITYPE_GROUP); return static_cast(this); } KGpgRefNode * KGpgNode::toRefNode() { Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)) || (getType() & KgpgCore::ITYPE_SIGN)); return qobject_cast(this); } const KGpgRefNode * KGpgNode::toRefNode() const { Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)) || (getType() & KgpgCore::ITYPE_SIGN)); return qobject_cast(this); } KGpgGroupMemberNode * KGpgNode::toGroupMemberNode() { Q_ASSERT((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)); return static_cast(this); } const KGpgGroupMemberNode * KGpgNode::toGroupMemberNode() const { Q_ASSERT((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)); return static_cast(this); } KGpgSignNode * KGpgNode::toSignNode() { Q_ASSERT(getType() == KgpgCore::ITYPE_SIGN); return static_cast(this); } const KGpgSignNode * KGpgNode::toSignNode() const { Q_ASSERT(getType() == KgpgCore::ITYPE_SIGN); return static_cast(this); } KGpgOrphanNode * KGpgNode::toOrphanNode() { Q_ASSERT(getType() == KgpgCore::ITYPE_SECRET); return static_cast(this); } const KGpgOrphanNode * KGpgNode::toOrphanNode() const { Q_ASSERT(getType() == KgpgCore::ITYPE_SECRET); return static_cast(this); } bool KGpgNode::hasChildren() const { return false; } int KGpgNode::getChildCount() { return 0; } KGpgNode * KGpgNode::getChild(const int index) const { Q_UNUSED(index); return NULL; } int KGpgNode::getChildIndex(KGpgNode *node) const { Q_UNUSED(node); return 0; } KgpgCore::KgpgKeyTrust KGpgNode::getTrust() const { return TRUST_NOKEY; } QString KGpgNode::getSize() const { return QString(); } QString KGpgNode::getName() const { return QString(); } QString KGpgNode::getEmail() const { return QString(); } QDateTime KGpgNode::getExpiration() const { return QDateTime(); } QDateTime KGpgNode::getCreation() const { return QDateTime(); } QString KGpgNode::getId() const { return QString(); } QString KGpgNode::getComment() const { return QString(); } KGpgExpandableNode * KGpgNode::getParentKeyNode() const { return m_parent; } #include "moc_KGpgNode.cpp"