From f9143c0d39e2a2127eeedabdbb115e4072ee4ad9 Mon Sep 17 00:00:00 2001 From: ubbo Date: Fri, 3 Aug 2012 09:44:12 +0000 Subject: reorganize kgpg source tree git-svn-id: http://cpunk.de/svn/src/gpg4usb/branches/0.3.2-mac@931 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- gpg4usb.pro | 64 +++---- gpgcontext.cpp | 15 +- gpgcontext.h | 2 +- keydetailsdialog.h | 2 +- kgpg/KGpgExpandableNode.cpp | 88 ---------- kgpg/KGpgExpandableNode.h | 85 --------- kgpg/KGpgGroupMemberNode.cpp | 100 ----------- kgpg/KGpgGroupMemberNode.h | 61 ------- kgpg/KGpgGroupNode.cpp | 279 ----------------------------- kgpg/KGpgGroupNode.h | 84 --------- kgpg/KGpgKeyNode.cpp | 358 -------------------------------------- kgpg/KGpgKeyNode.h | 191 -------------------- kgpg/KGpgNode.cpp | 337 ----------------------------------- kgpg/KGpgNode.h | 156 ----------------- kgpg/KGpgOrphanNode.cpp | 84 --------- kgpg/KGpgOrphanNode.h | 53 ------ kgpg/KGpgRefNode.cpp | 151 ---------------- kgpg/KGpgRefNode.h | 98 ----------- kgpg/KGpgRootNode.cpp | 189 -------------------- kgpg/KGpgRootNode.h | 129 -------------- kgpg/KGpgSignNode.cpp | 95 ---------- kgpg/KGpgSignNode.h | 54 ------ kgpg/KGpgSignableNode.cpp | 99 ----------- kgpg/KGpgSignableNode.h | 62 ------- kgpg/KGpgSubkeyNode.cpp | 100 ----------- kgpg/KGpgSubkeyNode.h | 55 ------ kgpg/KGpgUatNode.cpp | 174 ------------------ kgpg/KGpgUatNode.h | 61 ------- kgpg/KGpgUidNode.cpp | 146 ---------------- kgpg/KGpgUidNode.h | 57 ------ kgpg/convert.cpp | 183 ------------------- kgpg/convert.h | 53 ------ kgpg/core/KGpgExpandableNode.cpp | 88 ++++++++++ kgpg/core/KGpgExpandableNode.h | 85 +++++++++ kgpg/core/KGpgGroupMemberNode.cpp | 100 +++++++++++ kgpg/core/KGpgGroupMemberNode.h | 61 +++++++ kgpg/core/KGpgGroupNode.cpp | 279 +++++++++++++++++++++++++++++ kgpg/core/KGpgGroupNode.h | 84 +++++++++ kgpg/core/KGpgKeyNode.cpp | 358 ++++++++++++++++++++++++++++++++++++++ kgpg/core/KGpgKeyNode.h | 191 ++++++++++++++++++++ kgpg/core/KGpgNode.cpp | 337 +++++++++++++++++++++++++++++++++++ kgpg/core/KGpgNode.h | 156 +++++++++++++++++ kgpg/core/KGpgOrphanNode.cpp | 84 +++++++++ kgpg/core/KGpgOrphanNode.h | 53 ++++++ kgpg/core/KGpgRefNode.cpp | 151 ++++++++++++++++ kgpg/core/KGpgRefNode.h | 98 +++++++++++ kgpg/core/KGpgRootNode.cpp | 189 ++++++++++++++++++++ kgpg/core/KGpgRootNode.h | 129 ++++++++++++++ kgpg/core/KGpgSignNode.cpp | 95 ++++++++++ kgpg/core/KGpgSignNode.h | 54 ++++++ kgpg/core/KGpgSignableNode.cpp | 99 +++++++++++ kgpg/core/KGpgSignableNode.h | 62 +++++++ kgpg/core/KGpgSubkeyNode.cpp | 100 +++++++++++ kgpg/core/KGpgSubkeyNode.h | 55 ++++++ kgpg/core/KGpgUatNode.cpp | 174 ++++++++++++++++++ kgpg/core/KGpgUatNode.h | 61 +++++++ kgpg/core/KGpgUidNode.cpp | 146 ++++++++++++++++ kgpg/core/KGpgUidNode.h | 57 ++++++ kgpg/core/convert.cpp | 183 +++++++++++++++++++ kgpg/core/convert.h | 53 ++++++ kgpg/core/images.cpp | 100 +++++++++++ kgpg/core/images.h | 47 +++++ kgpg/core/kgpgkey.cpp | 354 +++++++++++++++++++++++++++++++++++++ kgpg/core/kgpgkey.h | 327 ++++++++++++++++++++++++++++++++++ kgpg/images.cpp | 100 ----------- kgpg/images.h | 47 ----- kgpg/kgpg.pro | 12 -- kgpg/kgpginterface.cpp | 12 +- kgpg/kgpginterface.h | 2 +- kgpg/kgpgkey.cpp | 354 ------------------------------------- kgpg/kgpgkey.h | 327 ---------------------------------- mainwindow.h | 2 +- 72 files changed, 4453 insertions(+), 4478 deletions(-) delete mode 100644 kgpg/KGpgExpandableNode.cpp delete mode 100644 kgpg/KGpgExpandableNode.h delete mode 100644 kgpg/KGpgGroupMemberNode.cpp delete mode 100644 kgpg/KGpgGroupMemberNode.h delete mode 100644 kgpg/KGpgGroupNode.cpp delete mode 100644 kgpg/KGpgGroupNode.h delete mode 100644 kgpg/KGpgKeyNode.cpp delete mode 100644 kgpg/KGpgKeyNode.h delete mode 100644 kgpg/KGpgNode.cpp delete mode 100644 kgpg/KGpgNode.h delete mode 100644 kgpg/KGpgOrphanNode.cpp delete mode 100644 kgpg/KGpgOrphanNode.h delete mode 100644 kgpg/KGpgRefNode.cpp delete mode 100644 kgpg/KGpgRefNode.h delete mode 100644 kgpg/KGpgRootNode.cpp delete mode 100644 kgpg/KGpgRootNode.h delete mode 100644 kgpg/KGpgSignNode.cpp delete mode 100644 kgpg/KGpgSignNode.h delete mode 100644 kgpg/KGpgSignableNode.cpp delete mode 100644 kgpg/KGpgSignableNode.h delete mode 100644 kgpg/KGpgSubkeyNode.cpp delete mode 100644 kgpg/KGpgSubkeyNode.h delete mode 100644 kgpg/KGpgUatNode.cpp delete mode 100644 kgpg/KGpgUatNode.h delete mode 100644 kgpg/KGpgUidNode.cpp delete mode 100644 kgpg/KGpgUidNode.h delete mode 100644 kgpg/convert.cpp delete mode 100644 kgpg/convert.h create mode 100644 kgpg/core/KGpgExpandableNode.cpp create mode 100644 kgpg/core/KGpgExpandableNode.h create mode 100644 kgpg/core/KGpgGroupMemberNode.cpp create mode 100644 kgpg/core/KGpgGroupMemberNode.h create mode 100644 kgpg/core/KGpgGroupNode.cpp create mode 100644 kgpg/core/KGpgGroupNode.h create mode 100644 kgpg/core/KGpgKeyNode.cpp create mode 100644 kgpg/core/KGpgKeyNode.h create mode 100644 kgpg/core/KGpgNode.cpp create mode 100644 kgpg/core/KGpgNode.h create mode 100644 kgpg/core/KGpgOrphanNode.cpp create mode 100644 kgpg/core/KGpgOrphanNode.h create mode 100644 kgpg/core/KGpgRefNode.cpp create mode 100644 kgpg/core/KGpgRefNode.h create mode 100644 kgpg/core/KGpgRootNode.cpp create mode 100644 kgpg/core/KGpgRootNode.h create mode 100644 kgpg/core/KGpgSignNode.cpp create mode 100644 kgpg/core/KGpgSignNode.h create mode 100644 kgpg/core/KGpgSignableNode.cpp create mode 100644 kgpg/core/KGpgSignableNode.h create mode 100644 kgpg/core/KGpgSubkeyNode.cpp create mode 100644 kgpg/core/KGpgSubkeyNode.h create mode 100644 kgpg/core/KGpgUatNode.cpp create mode 100644 kgpg/core/KGpgUatNode.h create mode 100644 kgpg/core/KGpgUidNode.cpp create mode 100644 kgpg/core/KGpgUidNode.h create mode 100644 kgpg/core/convert.cpp create mode 100644 kgpg/core/convert.h create mode 100644 kgpg/core/images.cpp create mode 100644 kgpg/core/images.h create mode 100644 kgpg/core/kgpgkey.cpp create mode 100644 kgpg/core/kgpgkey.h delete mode 100644 kgpg/images.cpp delete mode 100644 kgpg/images.h delete mode 100644 kgpg/kgpg.pro delete mode 100644 kgpg/kgpgkey.cpp delete mode 100644 kgpg/kgpgkey.h diff --git a/gpg4usb.pro b/gpg4usb.pro index f82b9d9..84bc18c 100644 --- a/gpg4usb.pro +++ b/gpg4usb.pro @@ -46,22 +46,22 @@ HEADERS += attachments.h \ kgpg/kprocess.h \ kgpg/kprocess_p.h \ kgpg/kgpginterface.h \ - kgpg/kgpgkey.h \ - kgpg/KGpgSignableNode.h \ - kgpg/KGpgExpandableNode.h \ - kgpg/KGpgSignNode.h \ - kgpg/KGpgUidNode.h \ - kgpg/KGpgUatNode.h \ - kgpg/KGpgKeyNode.h \ - kgpg/KGpgSubKeyNode.h \ - kgpg/KGpgNode.h \ - kgpg/KGpgRefNode.h \ - kgpg/KGpgRootNode.h \ - kgpg/KGpgGroupNode.h \ - kgpg/KGpgGroupMemberNode.h \ - kgpg/KGpgOrphanNode.h \ - kgpg/convert.h \ - kgpg/images.h \ + kgpg/core/kgpgkey.h \ + kgpg/core/KGpgSignableNode.h \ + kgpg/core/KGpgExpandableNode.h \ + kgpg/core/KGpgSignNode.h \ + kgpg/core/KGpgUidNode.h \ + kgpg/core/KGpgUatNode.h \ + kgpg/core/KGpgKeyNode.h \ + kgpg/core/KGpgSubKeyNode.h \ + kgpg/core/KGpgNode.h \ + kgpg/core/KGpgRefNode.h \ + kgpg/core/KGpgRootNode.h \ + kgpg/core/KGpgGroupNode.h \ + kgpg/core/KGpgGroupMemberNode.h \ + kgpg/core/KGpgOrphanNode.h \ + kgpg/core/convert.h \ + kgpg/core/images.h \ gpgconstants.h SOURCES += attachments.cpp \ @@ -91,22 +91,22 @@ SOURCES += attachments.cpp \ kgpg/klinebufferedprocess.cpp \ kgpg/kprocess.cpp \ kgpg/kgpginterface.cpp \ - kgpg/kgpgkey.cpp \ - kgpg/KGpgSignableNode.cpp \ - kgpg/KGpgExpandableNode.cpp \ - kgpg/KGpgSignNode.cpp \ - kgpg/KGpgUidNode.cpp \ - kgpg/KGpgUatNode.cpp \ - kgpg/KGpgKeyNode.cpp \ - kgpg/KGpgSubKeyNode.cpp \ - kgpg/KGpgNode.cpp \ - kgpg/KGpgRefNode.cpp \ - kgpg/KGpgRootNode.cpp \ - kgpg/KGpgGroupNode.cpp \ - kgpg/KGpgGroupMemberNode.cpp \ - kgpg/KGpgOrphanNode.cpp \ - kgpg/convert.cpp \ - kgpg/images.cpp \ + kgpg/core/kgpgkey.cpp \ + kgpg/core/KGpgSignableNode.cpp \ + kgpg/core/KGpgExpandableNode.cpp \ + kgpg/core/KGpgSignNode.cpp \ + kgpg/core/KGpgUidNode.cpp \ + kgpg/core/KGpgUatNode.cpp \ + kgpg/core/KGpgKeyNode.cpp \ + kgpg/core/KGpgSubKeyNode.cpp \ + kgpg/core/KGpgNode.cpp \ + kgpg/core/KGpgRefNode.cpp \ + kgpg/core/KGpgRootNode.cpp \ + kgpg/core/KGpgGroupNode.cpp \ + kgpg/core/KGpgGroupMemberNode.cpp \ + kgpg/core/KGpgOrphanNode.cpp \ + kgpg/core/convert.cpp \ + kgpg/core/images.cpp \ gpgconstants.cpp RC_FILE = gpg4usb.rc diff --git a/gpgcontext.cpp b/gpgcontext.cpp index aa2c3da..f87ed11 100644 --- a/gpgcontext.cpp +++ b/gpgcontext.cpp @@ -23,7 +23,7 @@ #include "kgpg/gpgproc.h" #include "kgpg/kgpginterface.h" #include "kgpg/klinebufferedprocess.h" -#include "kgpg/kgpgkey.h" +#include "kgpg/core/kgpgkey.h" #ifdef _WIN32 #include #include /* contains read/write */ @@ -194,19 +194,6 @@ bool GpgContext::exportKeys(QStringList *uidList, QByteArray *outBuffer) return true; } -/*gpgme_key_t GpgContext::getKeyDetails(QString uid) -{ - gpgme_key_t key; - - // try secret - gpgme_get_key(mCtx, uid.toAscii().constData(), &key, 1); - // ok, its a public key - if (!key) { - gpgme_get_key(mCtx, uid.toAscii().constData(), &key, 0); - } - return key; -}*/ - KgpgCore::KgpgKey GpgContext::getKeyDetails(QString uid) { //KgpgCore::KgpgKey key; diff --git a/gpgcontext.h b/gpgcontext.h index 7bb9a4b..ba4cf67 100644 --- a/gpgcontext.h +++ b/gpgcontext.h @@ -28,7 +28,7 @@ #include #include #include -#include "kgpg/kgpgkey.h" +#include "kgpg/core/kgpgkey.h" QT_BEGIN_NAMESPACE class QMessageBox; diff --git a/keydetailsdialog.h b/keydetailsdialog.h index a13257e..e0893c2 100644 --- a/keydetailsdialog.h +++ b/keydetailsdialog.h @@ -23,7 +23,7 @@ #define __KEYDETAILSDIALOG_H__ #include "gpgcontext.h" -#include "kgpg/kgpgkey.h" +#include "kgpg/core/kgpgkey.h" #include QT_BEGIN_NAMESPACE diff --git a/kgpg/KGpgExpandableNode.cpp b/kgpg/KGpgExpandableNode.cpp deleted file mode 100644 index 4cf9607..0000000 --- a/kgpg/KGpgExpandableNode.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* 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 "KGpgExpandableNode.h" - -//#include "kgpgsettings.h" -#include "convert.h" -//#include "model/kgpgitemmodel.h" - -//#include - -KGpgExpandableNode::KGpgExpandableNode(KGpgExpandableNode *parent) - : KGpgNode(parent) -{ - if (parent != NULL) - parent->children.append(this); -} - -KGpgExpandableNode::~KGpgExpandableNode() -{ - for (int i = children.count() - 1; i >= 0; i--) - delete children[i]; -} - -KGpgNode * -KGpgExpandableNode::getChild(const int index) const -{ - if ((index < 0) || (index > children.count())) - return NULL; - return children.at(index); -} - -int -KGpgExpandableNode::getChildCount() -{ - if (children.count() == 0) - readChildren(); - - return children.count(); -} - -bool -KGpgExpandableNode::hasChildren() const -{ - return (children.count() != 0); -} - -bool -KGpgExpandableNode::wasExpanded() const -{ - return (children.count() != 0); -} - -const -KGpgNode::List & -KGpgExpandableNode::getChildren() const -{ - return children; -} - -int -KGpgExpandableNode::getChildIndex(KGpgNode *node) const -{ - return children.indexOf(node); -} - -void -KGpgExpandableNode::deleteChild(KGpgNode *child) -{ - children.removeAll(child); -} - -//#include "KGpgExpandableNode.moc" diff --git a/kgpg/KGpgExpandableNode.h b/kgpg/KGpgExpandableNode.h deleted file mode 100644 index 39f351d..0000000 --- a/kgpg/KGpgExpandableNode.h +++ /dev/null @@ -1,85 +0,0 @@ -/* 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 . - */ -#ifndef KGPGEXPANDABLENODE_H -#define KGPGEXPANDABLENODE_H - -#include "KGpgNode.h" - -class KGpgSubkeyNode; -class KGpgRefNode; - -/** - * @brief The abstract base class for all classes that may have child objects - * - * Every class that represents something in the keyring that may have - * child objects inherits from this class. That does not mean that every - * child object always has children, but every child \em may have children. - */ -class KGpgExpandableNode : public KGpgNode -{ - Q_OBJECT - - friend class KGpgRefNode; - friend class KGpgSubkeyNode; -protected: - KGpgNode::List children; - - /** - * reimplemented in every base class to read in the child data - * - * This allows the child objects to delay the loading of the - * child objects until they are really needed to avoid time - * consuming operations for data never used. - */ - virtual void readChildren() = 0; - - explicit KGpgExpandableNode(KGpgExpandableNode *parent = NULL); -public: - virtual ~KGpgExpandableNode(); - - /** - * check if there are any child nodes - * - * The default implementation returns true if any child nodes were loaded. - * This may be reimplemented by child classes so they can indicate that - * there are child nodes before actually loading them. - * - * This method indicates if there are children if this node is expanded. - * In contrast wasExpanded() will only return true if the child nodes - * are actually present in memory. - */ - virtual bool hasChildren() const; - /** - * check if there are any child nodes present in memory - * - * Returns true if any child nodes were loaded. - * - * This method indicates if the children of this node are already loaded - * into memory. In contrast hasChildren() may return true even if the child - * objects are not present in memory. - */ - virtual bool wasExpanded() const; - virtual int getChildCount(); - virtual const KGpgNode::List &getChildren() const; - virtual KGpgNode *getChild(const int index) const; - virtual int getChildIndex(KGpgNode *node) const; - virtual void deleteChild(KGpgNode *child); -}; - -#endif /* KGPGEXPANDABLENODE_H */ diff --git a/kgpg/KGpgGroupMemberNode.cpp b/kgpg/KGpgGroupMemberNode.cpp deleted file mode 100644 index e7a9f97..0000000 --- a/kgpg/KGpgGroupMemberNode.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright 2008,2009 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 "KGpgGroupMemberNode.h" - -#include - -#include "KGpgGroupNode.h" -#include "KGpgKeyNode.h" - -KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, const QString &k) - : KGpgRefNode(parent, k) -{ -} - -KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, KGpgKeyNode *k) - : KGpgRefNode(parent, k) -{ -} - -KGpgGroupMemberNode::~KGpgGroupMemberNode() -{ -} - -KgpgKeyTrust -KGpgGroupMemberNode::getTrust() const -{ - if (m_keynode != NULL) - return m_keynode->getTrust(); - return KgpgCore::TRUST_NOKEY; -} - -KgpgItemType -KGpgGroupMemberNode::getType() const -{ - if (m_keynode != NULL) - return m_keynode->getType() | KgpgCore::ITYPE_GROUP; - return KgpgCore::ITYPE_PUBLIC | KgpgCore::ITYPE_GROUP; -} - -QString -KGpgGroupMemberNode::getSize() const -{ - if (m_keynode != NULL) - return m_keynode->getSize(); - return QString(); -} - -QDateTime -KGpgGroupMemberNode::getExpiration() const -{ - if (m_keynode != NULL) - return m_keynode->getExpiration(); - return QDateTime(); -} - -QDateTime -KGpgGroupMemberNode::getCreation() const -{ - if (m_keynode != NULL) - return m_keynode->getCreation(); - return QDateTime(); -} - -unsigned int -KGpgGroupMemberNode::getSignKeySize() const -{ - if (m_keynode != NULL) - return m_keynode->getSignKeySize(); - return 0; -} - -unsigned int -KGpgGroupMemberNode::getEncryptionKeySize() const -{ - if (m_keynode != NULL) - return m_keynode->getEncryptionKeySize(); - return 0; -} - -KGpgGroupNode * -KGpgGroupMemberNode::getParentKeyNode() const -{ - return m_parent->toGroupNode(); -} diff --git a/kgpg/KGpgGroupMemberNode.h b/kgpg/KGpgGroupMemberNode.h deleted file mode 100644 index 2a456ef..0000000 --- a/kgpg/KGpgGroupMemberNode.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2008,2009 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 . - */ -#ifndef KGPGGROUPMEMBERNODE_H -#define KGPGGROUPMEMBERNODE_H - -#include "KGpgRefNode.h" - -#include -#include "kgpgkey.h" - -using namespace KgpgCore; - -class KGpgKeyNode; -class KGpgGroupNode; - -/** - * @brief A member of a GnuPG group - */ -class KGpgGroupMemberNode : public KGpgRefNode -{ -public: - explicit KGpgGroupMemberNode(KGpgGroupNode *parent, const QString &k); - explicit KGpgGroupMemberNode(KGpgGroupNode *parent, KGpgKeyNode *k); - virtual ~KGpgGroupMemberNode(); - - virtual KgpgCore::KgpgKeyTrust getTrust() const; - virtual KgpgCore::KgpgItemType getType() const; - virtual QString getSize() const; - virtual QDateTime getExpiration() const; - virtual QDateTime getCreation() const; - virtual KGpgGroupNode *getParentKeyNode() const; - - /** - * Returns the size of the signing key. - * @return signing key size in bits - */ - virtual unsigned int getSignKeySize() const; - /** - * Returns the size of the first encryption subkey. - * @return encryption key size in bits - */ - virtual unsigned int getEncryptionKeySize() const; -}; - -#endif /* KGPGGROUPMEMBERNODE_H */ diff --git a/kgpg/KGpgGroupNode.cpp b/kgpg/KGpgGroupNode.cpp deleted file mode 100644 index 3475303..0000000 --- a/kgpg/KGpgGroupNode.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* Copyright 2008,2009,2010,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 "KGpgGroupNode.h" - -#include "KGpgGroupMemberNode.h" -#include "KGpgRootNode.h" -//#include "kgpgsettings.h" - -#include -//#include -#include -#include -#include - -class KGpgGroupNodePrivate { -public: - KGpgGroupNodePrivate(const QString &name); - - QString m_name; - - /** - * @brief find the line that defines this group in the configuration - * @param conffile file object (will be initialized) - * @param stream text stream (will be initialized and connected to conffile) - * @param lines the lines found in conffile (will be filled) - * @return the index in lines of the entry defining this group - * @retval -1 no entry defining this group was found - * - * stream will be positioned at the beginning. - */ - int findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines); - - static const QRegExp &groupPattern(); - static const QString &groupTag(); -}; - -KGpgGroupNodePrivate::KGpgGroupNodePrivate(const QString &name) - : m_name(name) -{ -} - -int -KGpgGroupNodePrivate::findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines) -{ - //conffile.setFileName(KGpgSettings::gpgConfigPath()); - conffile.setFileName(""); - - if (!conffile.exists()) - return -1; - - if (!conffile.open(QIODevice::ReadWrite)) - return -1; - - stream.setDevice(&conffile); - int index = -1; - int i = -1; - - while (!stream.atEnd()) { - const QString rawLine = stream.readLine(); - i++; - QString parsedLine = rawLine.simplified().section(QLatin1Char('#'), 0, 0); - - if (groupPattern().exactMatch(parsedLine)) { - // remove "group " - parsedLine = parsedLine.remove(0, 6); - if (parsedLine.startsWith(m_name)) { - if (parsedLine.mid(m_name.length()).simplified().startsWith(QLatin1Char('='))) { - if (index >= 0) { - // multiple definitions of the same group, drop the second one - continue; - } else { - index = i; - } - } - } - } - - lines << rawLine; - } - - stream.seek(0); - - return index; -} - -const QRegExp & -KGpgGroupNodePrivate::groupPattern() -{ - static const QRegExp groupre(QLatin1String("^group [^ ]+ ?= ?([0-9a-fA-F]{8,} ?)*$")); - - return groupre; -} - -const QString & -KGpgGroupNodePrivate::groupTag() -{ - static const QString grouptag(QLatin1String("group ")); - - return grouptag; -} - -KGpgGroupNode::KGpgGroupNode(KGpgRootNode *parent, const QString &name, const QStringList &members) - : KGpgExpandableNode(parent), - d_ptr(new KGpgGroupNodePrivate(name)) -{ - foreach (const QString &id, members) - new KGpgGroupMemberNode(this, id); - - parent->m_groups++; -} - -KGpgGroupNode::KGpgGroupNode(KGpgRootNode *parent, const QString &name, const KGpgKeyNode::List &members) - : KGpgExpandableNode(parent), - d_ptr(new KGpgGroupNodePrivate(name)) -{ - Q_ASSERT(members.count() > 0); - - foreach (KGpgKeyNode *nd, members) - new KGpgGroupMemberNode(this, nd); - - parent->m_groups++; -} - -KGpgGroupNode::~KGpgGroupNode() -{ - KGpgRootNode *root = m_parent->toRootNode(); - - if (root != NULL) - root->m_groups--; -} - -KgpgCore::KgpgItemType -KGpgGroupNode::getType() const -{ - return ITYPE_GROUP; -} - -QString -KGpgGroupNode::getName() const -{ - const Q_D(KGpgGroupNode); - - return d->m_name; -} - -QString -KGpgGroupNode::getSize() const -{ - return tr("1 key", "%1 keys").arg(children.count()); -} - -void -KGpgGroupNode::readChildren() -{ -} - -void -KGpgGroupNode::rename(const QString &newName) -{ - Q_D(KGpgGroupNode); - - QFile conffile; - QTextStream t; - QStringList lines; - int index = d->findGroupEntry(conffile, t, lines); - - // check if file opening failed - if (!t.device()) - return; - - if (index < 0) { - qDebug() << "Group " << d->m_name << " not renamed, group does not exist"; - return; - } - - // 6 = groupTag().length() - const QString values = lines[index].simplified().mid(6 + d->m_name.length()); - lines[index] = d->groupTag() + newName + QLatin1Char(' ') + values; - - conffile.resize(0); - t << lines.join(QLatin1String("\n")) + QLatin1Char('\n'); - - d->m_name = newName; -} - -void -KGpgGroupNode::saveMembers() -{ - Q_D(KGpgGroupNode); - - QFile conffile; - QTextStream t; - QStringList lines; - int index = d->findGroupEntry(conffile, t, lines); - - // check if file opening failed - if (!t.device()) - return; - - QStringList memberIds; - - for (int j = getChildCount() - 1; j >= 0; j--) - memberIds << getChild(j)->toGroupMemberNode()->getId(); - - const QString groupEntry = d->groupTag() + d->m_name + QLatin1String(" = ") + - memberIds.join(QLatin1String(" ")); - - if (index >= 0) - lines[index] = groupEntry; - else - lines << groupEntry; - - conffile.resize(0); - t << lines.join(QLatin1String("\n")) + QLatin1Char('\n'); -} - -void -KGpgGroupNode::remove() -{ - Q_D(KGpgGroupNode); - - QFile conffile; - QTextStream t; - QStringList lines; - int index = d->findGroupEntry(conffile, t, lines); - - // check if file opening failed - if (!t.device()) - return; - - if (index < 0) - return; - - lines.removeAt(index); - conffile.resize(0); - t << lines.join(QLatin1String("\n")) + QLatin1Char('\n'); -} - -QStringList -KGpgGroupNode::readGroups() -{ - QStringList groups; - //QFile qfile(KGpgSettings::gpgConfigPath()); - QFile qfile(""); - - if (!qfile.exists() || !qfile.open(QIODevice::ReadOnly)) - return groups; - - QTextStream t(&qfile); - - while (!t.atEnd()) { - QString line = t.readLine().simplified().section(QLatin1Char('#'), 0, 0); - if (!KGpgGroupNodePrivate::groupPattern().exactMatch(line)) - continue; - - // remove the "group " at the start - line.remove(0, 6); - // transform it in a simple space separated list - groups.append(line.replace(QLatin1Char('='), QLatin1Char(' ')).simplified()); - } - - return groups; -} diff --git a/kgpg/KGpgGroupNode.h b/kgpg/KGpgGroupNode.h deleted file mode 100644 index 5aca837..0000000 --- a/kgpg/KGpgGroupNode.h +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright 2008,2009,2010,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 . - */ -#ifndef KGPGGROUPNODE_H -#define KGPGGROUPNODE_H - -#include "KGpgExpandableNode.h" -#include "KGpgKeyNode.h" - -class QString; -class QStringList; - -class KGpgGroupNodePrivate; - -/** - * @brief A GnuPG group of public keys - */ -class KGpgGroupNode : public KGpgExpandableNode -{ -private: - KGpgGroupNodePrivate * const d_ptr; - Q_DECLARE_PRIVATE(KGpgGroupNode) - Q_DISABLE_COPY(KGpgGroupNode) - -protected: - virtual void readChildren(); - -public: - KGpgGroupNode(KGpgRootNode *parent, const QString &name, const QStringList &members); - KGpgGroupNode(KGpgRootNode *parent, const QString &name, const KGpgKeyNode::List &members); - virtual ~KGpgGroupNode(); - - virtual KgpgCore::KgpgItemType getType() const; - /** - * Return size of group - * - * @return the number of keys in this group - */ - virtual QString getSize() const; - virtual QString getName() const; - - /** - * Rename this group node - * - * @param newName new name of the group - */ - void rename(const QString &newName); - - /** - * Write the current members to GnuPG config file - */ - void saveMembers(); - - /** - * Remove this group from the GnuPG config file - */ - void remove(); - - /** - * @brief get all groups from GnuPG config file - * @return list of groups names and their keys - * - * The strings are themself space separated list. The first entry is the - * group name, the others are the keys inside - */ - static QStringList readGroups(); -}; - -#endif /* KGPGGROUPNODE_H */ diff --git a/kgpg/KGpgKeyNode.cpp b/kgpg/KGpgKeyNode.cpp deleted file mode 100644 index 285c8f1..0000000 --- a/kgpg/KGpgKeyNode.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/* Copyright 2008,2009,2010,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 "KGpgKeyNode.h" - -#include "KGpgGroupMemberNode.h" -#include "KGpgRootNode.h" -#include "KGpgSubkeyNode.h" -#include "KGpgUatNode.h" -#include "KGpgUidNode.h" -#include "convert.h" -#include "kgpginterface.h" -//#include "kgpgsettings.h" -//#include "model/kgpgitemmodel.h" - -//#include - -KGpgKeyNode::KGpgKeyNode(KGpgRootNode *parent, const KgpgCore::KgpgKey &k) - : KGpgSignableNode(parent), - m_key(new KgpgCore::KgpgKey(k)), - m_signs(0) -{ -} - -KGpgKeyNode::~KGpgKeyNode() -{ - foreach (KGpgRefNode *nd, m_refs) { - nd->unRef(m_parent->toRootNode()); - } -} - -KgpgCore::KgpgItemType -KGpgKeyNode::getType() const -{ - return getType(m_key); -} - -bool -KGpgKeyNode::hasChildren() const -{ - return true; -} - -KgpgCore::KgpgItemType -KGpgKeyNode::getType(const KgpgCore::KgpgKey *k) -{ - if (k->secret()) - return KgpgCore::ITYPE_PAIR; - - return KgpgCore::ITYPE_PUBLIC; -} - -KgpgCore::KgpgKeyTrust -KGpgKeyNode::getTrust() const -{ - return m_key->trust(); -} - -const QString & -KGpgKeyNode::getFingerprint() const -{ - return m_key->fingerprint(); -} - -QString -KGpgKeyNode::getSize() const -{ - return "size of signing key / size of encryption key", - "%1 / %2", QString::number(getSignKeySize()), - QString::number(getEncryptionKeySize()); -} - -QString -KGpgKeyNode::getName() const -{ - return m_key->name(); -} - -QString -KGpgKeyNode::getEmail() const -{ - return m_key->email(); -} - -QDateTime -KGpgKeyNode::getExpiration() const -{ - return m_key->expirationDate(); -} - -QDateTime -KGpgKeyNode::getCreation() const -{ - return m_key->creationDate(); -} - -QString -KGpgKeyNode::getId() const -{ - return m_key->fullId(); -} - -KGpgKeyNode * -KGpgKeyNode::getKeyNode(void) -{ - return this; -} - -bool -KGpgKeyNode::isSecret() const -{ - return m_key->secret(); -} - -const KGpgKeyNode * -KGpgKeyNode::getKeyNode(void) const -{ - return this; -} - -QString -KGpgKeyNode::getBeautifiedFingerprint() const -{ - return m_key->fingerprintBeautified(); -} - -QString -KGpgKeyNode::getComment() const -{ - return m_key->comment(); -} - -void -KGpgKeyNode::readChildren() -{ - KgpgInterface::readSignatures(this); - - m_signs = 0; - foreach(KGpgNode *n, children) - if (n->getType() == ITYPE_SIGN) - m_signs++; -} - -QString -KGpgKeyNode::getSignCount() const -{ - if (!wasExpanded()) - return QString(); - //return i18np("1 signature", "%1 signatures", m_signs); - return "TODO"; -} - -KgpgKey * -KGpgKeyNode::copyKey() const -{ - return new KgpgKey(*m_key); -} - -void -KGpgKeyNode::setKey(const KgpgKey &key) -{ - Q_ASSERT(m_key->fingerprint() == key.fingerprint()); - delete m_key; - - for (int i = 0; i < children.count(); i++) - delete children.at(i); - children.clear(); - - m_key = new KgpgKey(key); -} - -const KgpgKey * -KGpgKeyNode::getKey() const -{ - return m_key; -} - -unsigned int -KGpgKeyNode::getSignKeySize() const -{ - return m_key->size(); -} - -unsigned int -KGpgKeyNode::getEncryptionKeySize() const -{ - return m_key->encryptionSize(); -} - -void -KGpgKeyNode::addRef(KGpgRefNode *node) -{ - Q_ASSERT(m_refs.indexOf(node) == -1); - m_refs.append(node); -} - -void -KGpgKeyNode::delRef(KGpgRefNode *node) -{ - Q_ASSERT(m_refs.indexOf(node) != -1); - m_refs.removeOne(node); - Q_ASSERT(m_refs.indexOf(node) == -1); -} - -QList -KGpgKeyNode::getGroups(void) const -{ - QList ret; - - foreach (KGpgGroupMemberNode *gnd, getGroupRefs()) - ret.append(gnd->getParentKeyNode()); - - return ret; -} - -QList -KGpgKeyNode::getRefsOfType(const KgpgItemType &type) const -{ - QList ret; - - foreach (KGpgRefNode *nd, m_refs) { - if (nd->getType() & type) - ret.append(nd); - } - - return ret; -} - -QList -KGpgKeyNode::getGroupRefs(void) const -{ - QList ret; - - foreach (KGpgRefNode *rn, getRefsOfType(KgpgCore::ITYPE_GROUP)) - ret.append(rn->toGroupMemberNode()); - - return ret; -} - -KGpgSignNode::List -KGpgKeyNode::getSignRefs(void) const -{ - KGpgSignNode::List ret; - - QList refs = getRefsOfType(KgpgCore::ITYPE_SIGN); - - foreach (KGpgRefNode *rn, refs) - ret.append(rn->toSignNode()); - - return ret; -} - -KGpgSignNode::List -KGpgKeyNode::getSignatures(const bool subkeys) const -{ - KGpgSignNode::List ret = KGpgSignableNode::getSignatures(); - - if (!subkeys) - return ret; - - foreach (KGpgNode *child, children) { - KGpgSignNode::List tmp; - - switch (child->getType()) { - case KgpgCore::ITYPE_UID: - case KgpgCore::ITYPE_UAT: - tmp = child->toSignableNode()->getSignatures(); - break; - default: - continue; - } - - foreach (KGpgSignNode *sn, tmp) { - bool found = false; - const QString snid(sn->getId()); - - foreach (const KGpgSignNode *retsn, ret) { - found = (retsn->getId() == snid); - if (found) - break; - } - - if (!found) - ret << sn; - } - } - - return ret; -} - -const KGpgSignableNode * -KGpgKeyNode::getUid(const unsigned int index) const -{ - Q_ASSERT(index > 0); - - if (index == 1) - return this; - - const QString idxstr(QString::number(index)); - - foreach (const KGpgNode *child, children) { - KGpgSignNode::List tmp; - - switch (child->getType()) { - case KgpgCore::ITYPE_UID: - case KgpgCore::ITYPE_UAT: - if (child->getId() == idxstr) - return child->toSignableNode(); - break; - default: - continue; - } - } - - return NULL; -} - -bool -KGpgKeyNode::compareId(const QString &other) const -{ - if (other.length() == m_key->fullId().length()) - return (other.compare(m_key->fullId(), Qt::CaseInsensitive) == 0); - - if (other.length() == m_key->fingerprint().length()) - return (other.compare(m_key->fingerprint(), Qt::CaseInsensitive) == 0); - - const QString comId = m_key->fullId().isEmpty() ? m_key->fingerprint() : m_key->fullId(); - - return (other.right(comId.length()).compare( - comId.right(other.length()), - Qt::CaseInsensitive) == 0); -} - -void -KGpgKeyNode::expand() -{ - if (!wasExpanded()) - readChildren(); - - emit expanded(); -} - -//#include "KGpgKeyNode.moc" diff --git a/kgpg/KGpgKeyNode.h b/kgpg/KGpgKeyNode.h deleted file mode 100644 index caf0ba4..0000000 --- a/kgpg/KGpgKeyNode.h +++ /dev/null @@ -1,191 +0,0 @@ -/* Copyright 2008,2009,2010,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 . - */ -#ifndef KGPGKEYNODE_H -#define KGPGKEYNODE_H - -#include "KGpgSignableNode.h" -#include "KGpgSignNode.h" - -#include "kgpgkey.h" - -class KGpgExpandableNode; -class KGpgRefNode; - -/** - * @brief A public key with or without corresponding secret key - */ -class KGpgKeyNode : public KGpgSignableNode -{ - Q_OBJECT - - friend class KGpgGroupMemberNode; - -private: - KgpgCore::KgpgKey *m_key; - int m_signs; - -protected: - virtual void readChildren(); - - QList m_refs; - QList getRefsOfType(const KgpgCore::KgpgItemType &type) const; - -public: - typedef QList List; - typedef QList ConstList; - - explicit KGpgKeyNode(KGpgRootNode *parent, const KgpgCore::KgpgKey &k); - virtual ~KGpgKeyNode(); - - virtual bool hasChildren() const; - - static KgpgCore::KgpgItemType getType(const KgpgCore::KgpgKey *k); - - virtual KgpgCore::KgpgItemType getType() const; - virtual KgpgCore::KgpgKeyTrust getTrust() const; - const QString &getFingerprint() const; - virtual QString getSize() const; - virtual QString getName() const; - virtual QString getEmail() const; - virtual QDateTime getExpiration() const; - virtual QDateTime getCreation() const; - virtual QString getId() const; - virtual KGpgKeyNode *getKeyNode(void); - virtual const KGpgKeyNode *getKeyNode(void) const; - /** - * @brief Return if this key has a private key - */ - bool isSecret() const; - /** - * @brief Print the full key fingerprint with spaces inserted - * - * For display purposes you normally don't want to print the full - * fingerprint as is because it's too many hex characters at once. - * This function returns the fingerprint in the format usually used - * for printing this out, i.e. with a space after each fourth hex - * character. - * - * @return the full fingerprint with spaces inserted - */ - QString getBeautifiedFingerprint() const; - virtual QString getComment() const; - /** - * @brief Return the number of signatures of the primary user id - * - * This is different from the number of children of this node as there - * is usually at least one subkey and there may also be additional - * user ids or attributes. This does not count the signatures to those - * slave objects, only the ones that are direct children of this node. - * - * @return the number of signatures to the primary user id - */ - virtual QString getSignCount() const; - /** - * @brief Creates a copy of the KgpgKey that belongs to this class - */ - virtual KgpgCore::KgpgKey *copyKey() const; - /** - * @brief Replaces the current key information with the new one. - * All sub-items (i.e. signatures, user ids ...) will be deleted. This must - * only be used when the id of both new and old key is the same. - */ - void setKey(const KgpgCore::KgpgKey &key); - /** - * @brief Returns a reference to the key used in this object. - * This allows direct access to the values of the key e.g. for KgpgKeyInfo. - */ - const KgpgCore::KgpgKey *getKey() const; - - /** - * @brief Returns the size of the signing key. - * @return signing key size in bits - */ - virtual unsigned int getSignKeySize() const; - /** - * @brief Returns the size of the first encryption subkey. - * @return encryption key size in bits - */ - virtual unsigned int getEncryptionKeySize() const; - /** - * @brief Notify this key that a KGpgRefNode now references this key. - * @param node object that takes the reference - */ - void addRef(KGpgRefNode *node); - /** - * @brief Remove a reference to this object - * @param node node that no longer has the reference - * - * Note that this must not be called as reply when this object - * emits updated(NULL) - */ - void delRef(KGpgRefNode *node); - /** - * @brief returns a list of all groups this key is member of - */ - QList getGroups(void) const; - /** - * @brief returns a list of all group member nodes that reference this key - */ - QList getGroupRefs(void) const; - /** - * @brief returns a list of all sign nodes that reference this key - */ - KGpgSignNode::List getSignRefs(void) const; - /** - * @brief returns a list of signatures to this key - * @param subkeys if signatures on subkeys should be included - */ - KGpgSignNode::List getSignatures(const bool subkeys) const; - /** - * @brief get the user id or user attribute with the given number - * @param index the index of the user id to return - * @return the requested subitem or NULL if that is not present - * - * User ids indexes are 1-based, so 0 is not a valid index. Passing - * 1 as index will return the object itself, representing the primary - * user id. - */ - const KGpgSignableNode *getUid(const unsigned int index) const; - - /** - * @brief compare the id of this node to the given other node - * @param other key id to compare to - * @return if ids are identical - * - * This handles different length of the id string. - */ - bool compareId(const QString &other) const; -Q_SIGNALS: - void expanded(); - -public slots: - /** - * @brief read all subitems - * - * This will read in all subitems (e.g. subkeys, signatures). When - * this is done the expanded() signal is emitted. The signal is emitted - * immediately if the key has been expanded before. - * - * This will not update the child items in case they are already present. - * Use KGpgItemModel::refreshKey() instead. - */ - void expand(); -}; - -#endif /* KGPGKEYNODE_H */ diff --git a/kgpg/KGpgNode.cpp b/kgpg/KGpgNode.cpp deleted file mode 100644 index 18645f8..0000000 --- a/kgpg/KGpgNode.cpp +++ /dev/null @@ -1,337 +0,0 @@ -/* 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 tr("Name of uid (comment) %1 (%2)").arg(getName()).arg(getComment()); - //return QString("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 "KGpgNode.moc" diff --git a/kgpg/KGpgNode.h b/kgpg/KGpgNode.h deleted file mode 100644 index 1d89875..0000000 --- a/kgpg/KGpgNode.h +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright 2008,2009 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 . - */ -#ifndef KGPGNODE_H -#define KGPGNODE_H - -#include -#include "kgpgkey.h" - -class KGpgExpandableNode; -class KGpgKeyNode; -class KGpgRootNode; -class KGpgUidNode; -class KGpgSignableNode; -class KGpgSubkeyNode; -class KGpgUatNode; -class KGpgGroupNode; -class KGpgRefNode; -class KGpgGroupMemberNode; -class KGpgSignNode; -class KGpgOrphanNode; -class KGpgItemModel; - -/** - * @brief The abstract base class for all classes representing keyring data - */ -class KGpgNode : public QObject -{ - Q_OBJECT - - friend class KGpgItemModel; - - KGpgNode(); // = delete C++0x -protected: - KGpgExpandableNode *m_parent; - KGpgItemModel *m_model; - - /** - * constructor - * @param parent the parent node in item hierarchy - */ - explicit KGpgNode(KGpgExpandableNode *parent); - -public: - typedef QList List; - - /** - * destructor - */ - virtual ~KGpgNode(); - - /** - * Returns if this node has child nodes - * - * This may be reimplemented by child classes so they can indicate that - * there are child nodes before actually loading them. - */ - virtual bool hasChildren() const; - /** - * Return how many child nodes exist - * - * When the child nodes do not already exist this will create them. - * This is the reason why this method is not const. - */ - virtual int getChildCount(); - /** - * Returns the child node at the given index - * @param index child index - * - * index may be in range 0 to getChildCount() - 1. - */ - virtual KGpgNode *getChild(const int index) const; - /** - * Returns the index for a given child node - * @return -1 if the given node is not a child of this object - */ - virtual int getChildIndex(KGpgNode *node) const; - - /** - * Returns the item type of this object - * - * Since every subclass returns a distinct value you can use the - * result of this function to decide which cast to take. Note that - * there are subclasses (KGpgKeyNode, KGpgGroupMemberNode) that - * can return two different values. - */ - virtual KgpgCore::KgpgItemType getType() const = 0; - virtual KgpgCore::KgpgKeyTrust getTrust() const; - /** - * Returns a string describing the size of this object - * - * Subclasses may return a value that makes sense for whatever - * object they represent. - * - * The default implementation returns an empty string. - */ - virtual QString getSize() const; - virtual QString getName() const; - virtual QString getEmail() const; - virtual QDateTime getExpiration() const; - virtual QDateTime getCreation() const; - virtual QString getId() const; - virtual QString getComment() const; - virtual QString getNameComment() const; - /** - * Returns the parent node in the key hierarchy - * - * For all "primary" items like keys and key groups this will - * return the (invisible) root node. Calling this function for - * the root node will return %NULL. No other node but the root - * node has a %NULL parent. - */ - KGpgExpandableNode *getParentKeyNode() const; - - KGpgExpandableNode *toExpandableNode(); - const KGpgExpandableNode *toExpandableNode() const; - KGpgSignableNode *toSignableNode(); - const KGpgSignableNode *toSignableNode() const; - KGpgKeyNode *toKeyNode(); - const KGpgKeyNode *toKeyNode() const; - KGpgRootNode *toRootNode(); - const KGpgRootNode *toRootNode() const; - KGpgUidNode *toUidNode(); - const KGpgUidNode *toUidNode() const; - KGpgSubkeyNode *toSubkeyNode(); - const KGpgSubkeyNode *toSubkeyNode() const; - KGpgUatNode *toUatNode(); - const KGpgUatNode *toUatNode() const; - KGpgGroupNode *toGroupNode(); - const KGpgGroupNode *toGroupNode() const; - KGpgRefNode *toRefNode(); - const KGpgRefNode *toRefNode() const; - KGpgGroupMemberNode *toGroupMemberNode(); - const KGpgGroupMemberNode *toGroupMemberNode() const; - KGpgSignNode *toSignNode(); - const KGpgSignNode *toSignNode() const; - KGpgOrphanNode *toOrphanNode(); - const KGpgOrphanNode *toOrphanNode() const; -}; - -#endif /* KGPGNODE_H */ diff --git a/kgpg/KGpgOrphanNode.cpp b/kgpg/KGpgOrphanNode.cpp deleted file mode 100644 index f245121..0000000 --- a/kgpg/KGpgOrphanNode.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright 2008,2009,2010,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 "KGpgOrphanNode.h" - -KGpgOrphanNode::KGpgOrphanNode(KGpgExpandableNode *parent, const KgpgKey &k) - : KGpgNode(parent), - m_key(new KgpgKey(k)) -{ -} - -KGpgOrphanNode::~KGpgOrphanNode() -{ - delete m_key; -} - -KgpgItemType -KGpgOrphanNode::getType() const -{ - return ITYPE_SECRET; -} - -QString -KGpgOrphanNode::getName() const -{ - return m_key->name(); -} - -QString -KGpgOrphanNode::getEmail() const -{ - return m_key->email(); -} - -QString -KGpgOrphanNode::getSize() const -{ - return QString::number(m_key->size()); -} - -QDateTime -KGpgOrphanNode::getExpiration() const -{ - return m_key->expirationDate(); -} - -QDateTime -KGpgOrphanNode::getCreation() const -{ - return m_key->creationDate(); -} - -QString -KGpgOrphanNode::getId() const -{ - return m_key->fullId(); -} - -KgpgCore::KgpgKeyTrust -KGpgOrphanNode::getTrust() const -{ - return m_key->trust(); -} - -const QString & -KGpgOrphanNode::getFingerprint() const -{ - return m_key->fingerprint(); -} diff --git a/kgpg/KGpgOrphanNode.h b/kgpg/KGpgOrphanNode.h deleted file mode 100644 index e3b6132..0000000 --- a/kgpg/KGpgOrphanNode.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright 2008,2009,2010,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 . - */ -#ifndef KGPGORPHANNODE_H -#define KGPGORPHANNODE_H - -#include "KGpgNode.h" - -#include "kgpgkey.h" - -using namespace KgpgCore; - -class KGpgExpandableNode; - -/** - * @brief A lone secret key without public key - */ -class KGpgOrphanNode : public KGpgNode -{ -private: - KgpgCore::KgpgKey *m_key; - -public: - explicit KGpgOrphanNode(KGpgExpandableNode *parent, const KgpgKey &k); - virtual ~KGpgOrphanNode(); - - virtual KgpgCore::KgpgItemType getType() const; - virtual KgpgCore::KgpgKeyTrust getTrust() const; - const QString &getFingerprint() const; - virtual QString getSize() const; - virtual QString getName() const; - virtual QString getEmail() const; - virtual QDateTime getExpiration() const; - virtual QDateTime getCreation() const; - virtual QString getId() const; -}; - -#endif /* KGPGORPHANNODE_H */ diff --git a/kgpg/KGpgRefNode.cpp b/kgpg/KGpgRefNode.cpp deleted file mode 100644 index a67d6b5..0000000 --- a/kgpg/KGpgRefNode.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright 2008,2009 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 "KGpgRefNode.h" - -//#include - -#include "KGpgExpandableNode.h" -#include "KGpgRootNode.h" - -KGpgRefNode::KGpgRefNode(KGpgExpandableNode *parent, const QString &keyid) - : KGpgNode(parent), - m_id(keyid) -{ - Q_ASSERT(!keyid.isEmpty()); - - KGpgRootNode *root = getRootNode(); - KGpgExpandableNode *pnd = parent; - - do { - m_selfsig = (pnd->getId().right(keyid.length()) == keyid); - if (m_selfsig) - m_keynode = pnd->toKeyNode(); - else - pnd = pnd->getParentKeyNode(); - } while (!m_selfsig && (pnd != root)); - - // Self signatures do net need to get notified by their key: if the key is changed - // the key node is deleted, then those refnode would be deleted anyway. This avoids - // crashes when they would try to find the root node by iterating over their parent - // when the parents destructor is already called (see bug 208659). - if (!m_selfsig) { - m_keynode = root->findKey(keyid); - - if (m_keynode != NULL) { - m_keynode->addRef(this); - } else { - connect(root, SIGNAL(newKeyNode(KGpgKeyNode*)), this, SLOT(keyUpdated(KGpgKeyNode*))); - } - } - - parent->children.append(this); -} - -KGpgRefNode::KGpgRefNode(KGpgExpandableNode *parent, KGpgKeyNode *key) - : KGpgNode(parent), - m_id(key->getId()), - m_keynode(key) -{ - Q_ASSERT(key != NULL); - Q_ASSERT(parent != NULL); - m_keynode->addRef(this); - - parent->children.append(this); -} - -KGpgRefNode::~KGpgRefNode() -{ - if (m_keynode && !m_selfsig) - m_keynode->delRef(this); -} - -KGpgRootNode * -KGpgRefNode::getRootNode() const -{ - KGpgExpandableNode *root; - KGpgExpandableNode *pt = m_parent; - - do { - root = pt; - pt = pt->getParentKeyNode(); - } while (pt != NULL); - - return root->toRootNode(); -} - -void -KGpgRefNode::keyUpdated(KGpgKeyNode *nkey) -{ - Q_ASSERT(m_keynode == NULL); - Q_ASSERT(nkey != NULL); - - if (nkey->getId().right(m_id.length()) == m_id) { - disconnect(sender(), NULL, this, SLOT(keyUpdated(KGpgKeyNode*))); - m_keynode = nkey; - m_keynode->addRef(this); - } -} - -void -KGpgRefNode::unRef(KGpgRootNode *root) -{ - if (root != NULL) - connect(root, SIGNAL(newKeyNode(KGpgKeyNode*)), this, SLOT(keyUpdated(KGpgKeyNode*))); - - m_keynode = NULL; -} - -QString -KGpgRefNode::getId() const -{ - if (m_keynode != NULL) - return m_keynode->getId(); - else - return m_id; -} - -QString -KGpgRefNode::getName() const -{ - if (m_keynode != NULL) - return m_keynode->getName(); - return tr("[No user id found]"); -} - -QString -KGpgRefNode::getEmail() const -{ - if (m_keynode != NULL) - return m_keynode->getEmail(); - return QString(); -} - -bool -KGpgRefNode::isUnknown() const -{ - return (m_keynode == NULL); -} - -KGpgKeyNode * -KGpgRefNode::getRefNode() const -{ - return m_keynode; -} - -//#include "KGpgRefNode.moc" diff --git a/kgpg/KGpgRefNode.h b/kgpg/KGpgRefNode.h deleted file mode 100644 index f977567..0000000 --- a/kgpg/KGpgRefNode.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright 2008,2009 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 . - */ -#ifndef KGPGREFNODE_H -#define KGPGREFNODE_H - -#include "KGpgNode.h" - -class KGpgKeyNode; -class KGpgRootNode; - -/** - * @brief Class for child objects that are only a reference to a primary key - * - * This is the base class for all type of objects that match these criteria: - * -they can not have child objects - * -they are only a reference to a primary key (which needs not to be in the - * key ring) - * - * Do not create instances from this class. Use KGpgGroupMemberNode and - * KGpgSignNode as those represent the existing objects. This class exists - * only to get the hierarchy right. - */ -class KGpgRefNode : public KGpgNode -{ - Q_OBJECT - -private: - const QString m_id; - bool m_selfsig; ///< if this is a reference to it's own parent - -protected: - KGpgKeyNode *m_keynode; - - explicit KGpgRefNode(KGpgExpandableNode *parent, KGpgKeyNode *key); - explicit KGpgRefNode(KGpgExpandableNode *parent, const QString &keyid); - - KGpgRootNode *getRootNode() const; - -public: - virtual ~KGpgRefNode(); - - virtual QString getId() const; - virtual QString getName() const; - virtual QString getEmail() const; - /** - * Get the node of the primary key this node references to - * - * This will return the key node of the primary key this node - * references. This may be %NULL if the primary key is not in the key - * ring, e.g. if this is a signature of an unknown key. - * - * @return the node of the primary key or %NULL - */ - virtual KGpgKeyNode *getRefNode() const; - - /** - * Check if the referenced key exists - * - * @return if getRefNode() will return %NULL or not - */ - bool isUnknown() const; - - /** - * Break the current reference - * @param root root node - * - * This is called when the referenced node is going away. - * - * The root node is passed for two reasons: - * @li it doesn't need to be searched again for every ref node which - * can be many in case of an important key node get's deleted - * @li the ref node may be a child of the deleted node, then we can - * not call the parents functions to find the root anymore. This helps - * simplifying the code - */ - void unRef(KGpgRootNode *root); - -private Q_SLOTS: - void keyUpdated(KGpgKeyNode *); -}; - -#endif /* KGPGREFNODE_H */ diff --git a/kgpg/KGpgRootNode.cpp b/kgpg/KGpgRootNode.cpp deleted file mode 100644 index 416aa0a..0000000 --- a/kgpg/KGpgRootNode.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright 2008,2009,2010,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 "KGpgRootNode.h" - -#include "KGpgGroupNode.h" -#include "kgpginterface.h" -#include "KGpgOrphanNode.h" -//#include "kgpgsettings.h" - -#include -#include - -KGpgRootNode::KGpgRootNode(KGpgItemModel *model) - : KGpgExpandableNode(NULL), - m_groups(0), - m_deleting(false) -{ - m_model = model; -} - -KGpgRootNode::~KGpgRootNode() -{ - m_deleting = true; -} - -void -KGpgRootNode::readChildren() -{ -} - -KgpgCore::KgpgItemType -KGpgRootNode::getType() const -{ - return 0; -} - -void -KGpgRootNode::addGroups(const QStringList &groups) -{ - foreach (const QString &group, groups) { - QStringList members = group.split(QLatin1Char(' ')); - const QString groupName = members.takeFirst(); - new KGpgGroupNode(this, groupName, members); - } -} - -void -KGpgRootNode::addKeys(const QStringList &ids) -{ - KgpgCore::KgpgKeyList publiclist = KgpgInterface::readPublicKeys(ids); - KgpgCore::KgpgKeyList secretlist = KgpgInterface::readSecretKeys(); - - QStringList issec = secretlist; - - for (int i = 0; i < publiclist.size(); ++i) { - KgpgCore::KgpgKey key = publiclist.at(i); - - int index = issec.indexOf(key.fullId()); - if (index != -1) { - key.setSecret(true); - issec.removeAt(index); - secretlist.removeAt(index); - } - - KGpgKeyNode *nd = new KGpgKeyNode(this, key); - emit newKeyNode(nd); - } - - for (int i = 0; i < secretlist.count(); ++i) { - KgpgCore::KgpgKey key = secretlist.at(i); - - new KGpgOrphanNode(this, key); - } -} - -void -KGpgRootNode::refreshKeys(KGpgKeyNode::List nodes) -{ - QStringList ids; - - foreach (const KGpgNode *nd, nodes) - ids << nd->getId(); - - KgpgCore::KgpgKeyList publiclist = KgpgInterface::readPublicKeys(ids); - QStringList issec = KgpgInterface::readSecretKeys(ids); - - for (int i = 0; i < publiclist.size(); ++i) { - KgpgCore::KgpgKey key = publiclist.at(i); - - int index = issec.indexOf(key.fullId()); - if (index != -1) { - key.setSecret(true); - issec.removeAt(index); - } - - for (int j = 0; j < nodes.count(); j++) { - KGpgKeyNode *nd = nodes.at(j); - - if (nd->getId() == key.fingerprint()) { - nodes.removeAt(j); - nd->setKey(key); - break; - } - } - } -} - -KGpgKeyNode * -KGpgRootNode::findKey(const QString &keyId) -{ - int i = findKeyRow(keyId); - if (i >= 0) { - return children[i]->toKeyNode(); - } - - return NULL; -} - -int -KGpgRootNode::findKeyRow(const QString &keyId) -{ - int i = 0; - - foreach (const KGpgNode *node, children) { - if ((node->getType() & ITYPE_PAIR) == 0) { - ++i; - continue; - } - - const KGpgKeyNode *key = node->toKeyNode(); - - if (key->compareId(keyId)) - return i; - ++i; - } - return -1; -} - -int -KGpgRootNode::groupChildren() const -{ - return m_groups; -} - -int -KGpgRootNode::findKeyRow(const KGpgKeyNode *key) -{ - for (int i = 0; i < children.count(); i++) { - if (children[i] == key) - return i; - } - return -1; -} - -KGpgRootNode * -KGpgRootNode::asRootNode() -{ - if (m_deleting) - return NULL; - - return this; -} - -const KGpgRootNode * -KGpgRootNode::asRootNode() const -{ - if (m_deleting) - return NULL; - - return this; -} - -//#include "KGpgRootNode.moc" diff --git a/kgpg/KGpgRootNode.h b/kgpg/KGpgRootNode.h deleted file mode 100644 index 97c597c..0000000 --- a/kgpg/KGpgRootNode.h +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright 2008,2009 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 . - */ -#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 */ diff --git a/kgpg/KGpgSignNode.cpp b/kgpg/KGpgSignNode.cpp deleted file mode 100644 index f35bd9a..0000000 --- a/kgpg/KGpgSignNode.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright 2008,2009,2010 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 "KGpgSignNode.h" - -#include "KGpgSignableNode.h" - -//#include -#include - -class KGpgSignNodePrivate { -public: - KGpgSignNodePrivate(const QStringList &sl); - - QDateTime m_creation; - QDateTime m_expiration; - bool m_local; - bool m_revocation; -}; - -KGpgSignNodePrivate::KGpgSignNodePrivate(const QStringList &sl) -{ - m_revocation = (sl.at(0) == QLatin1String("rev")); - if (sl.count() < 6) - return; - m_creation = QDateTime::fromTime_t(sl.at(5).toUInt()); - if (sl.count() < 7) - return; - if (!sl.at(6).isEmpty()) - m_expiration = QDateTime::fromTime_t(sl.at(6).toUInt()); - if (sl.count() < 11) - return; - m_local = sl.at(10).endsWith(QLatin1Char( 'l' )); -} - -KGpgSignNode::KGpgSignNode(KGpgSignableNode *parent, const QStringList &s) - : KGpgRefNode(parent, s.at(4)), - d_ptr(new KGpgSignNodePrivate(s)) -{ -} - -KGpgSignNode::~KGpgSignNode() -{ - delete d_ptr; -} - -QDateTime -KGpgSignNode::getExpiration() const -{ - const Q_D(KGpgSignNode); - - return d->m_expiration; -} - -QDateTime -KGpgSignNode::getCreation() const -{ - const Q_D(KGpgSignNode); - - return d->m_creation; -} - -QString -KGpgSignNode::getName() const -{ - const Q_D(KGpgSignNode); - const QString name = KGpgRefNode::getName(); - - if (!d->m_local) - return name; - - //return tr("%1 [local signature]", &name.constData()->toAscii()); - return "fixme"; -} - -KgpgCore::KgpgItemType -KGpgSignNode::getType() const -{ - return KgpgCore::ITYPE_SIGN; -} diff --git a/kgpg/KGpgSignNode.h b/kgpg/KGpgSignNode.h deleted file mode 100644 index 398ee57..0000000 --- a/kgpg/KGpgSignNode.h +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2008,2009,2010 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 . - */ -#ifndef KGPGSIGNNODE_H -#define KGPGSIGNNODE_H - -#include "KGpgRefNode.h" - -class KGpgSignableNode; - -class KGpgSignNodePrivate; - -/** - * @brief A signature to another key object - */ -class KGpgSignNode : public KGpgRefNode -{ -private: - KGpgSignNodePrivate * const d_ptr; - Q_DECLARE_PRIVATE(KGpgSignNode) - -public: - typedef QList List; - - /** - * @brief constructor for KGpgSignNode - * @param parent the signed node - * @param s GnuPG line describing this signature - */ - explicit KGpgSignNode(KGpgSignableNode *parent, const QStringList &s); - virtual ~KGpgSignNode(); - - virtual KgpgCore::KgpgItemType getType() const; - virtual QDateTime getExpiration() const; - virtual QString getName() const; - virtual QDateTime getCreation() const; -}; - -#endif /* KGPGSIGNNODE_H */ diff --git a/kgpg/KGpgSignableNode.cpp b/kgpg/KGpgSignableNode.cpp deleted file mode 100644 index e3782c1..0000000 --- a/kgpg/KGpgSignableNode.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright 2008,2009 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 "KGpgSignableNode.h" - -//#include - -KGpgSignableNode::KGpgSignableNode(KGpgExpandableNode *parent) - : KGpgExpandableNode(parent) -{ -} - -KGpgSignableNode::~KGpgSignableNode() -{ -} - -KGpgSignNode::List -KGpgSignableNode::getSignatures(void) const -{ - KGpgSignNode::List ret; - - foreach (KGpgNode *kn, children) { - if (kn->getType() == KgpgCore::ITYPE_SIGN) - ret << kn->toSignNode(); - } - - return ret; -} - -QString -KGpgSignableNode::getSignCount() const -{ - //return i18np("1 signature", "%1 signatures", children.count()); - return tr("1 signature", "%1 signatures", children.count()); -} - -bool -KGpgSignableNode::operator<(const KGpgSignableNode &other) const -{ - return operator<(&other); -} - -bool -KGpgSignableNode::operator<(const KGpgSignableNode *other) const -{ - switch (getType()) { - case KgpgCore::ITYPE_PUBLIC: - case KgpgCore::ITYPE_PAIR: { - const QString myid(getId()); - - switch (other->getType()) { - case KgpgCore::ITYPE_PUBLIC: - case KgpgCore::ITYPE_PAIR: - return (myid < other->getId()); - default: { - const QString otherid(other->getParentKeyNode()->getId()); - - if (myid == otherid) - return true; - return (myid < otherid); - } - } - } - default: { - const QString myp(getParentKeyNode()->getId()); - - switch (other->getType()) { - case KgpgCore::ITYPE_PAIR: - case KgpgCore::ITYPE_PUBLIC: - return (myp < other->getId()); - default: { - const QString otherp(other->getParentKeyNode()->getId()); - - if (otherp == myp) - return (getId().toInt() < other->getId().toInt()); - - return (myp < otherp); - } - } - } - } -} - -//#include "KGpgSignableNode.moc" diff --git a/kgpg/KGpgSignableNode.h b/kgpg/KGpgSignableNode.h deleted file mode 100644 index fddae25..0000000 --- a/kgpg/KGpgSignableNode.h +++ /dev/null @@ -1,62 +0,0 @@ -/* 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 . - */ -#ifndef KGPGSIGNABLENODE_H -#define KGPGSIGNABLENODE_H - -#include "KGpgExpandableNode.h" -#include "KGpgSignNode.h" - -/** - * @brief An object that may have KGpgSignNode children - * - * This class represents an object that may be signed, i.e. key nodes, - * user ids, user attributes, and subkeys. - */ -class KGpgSignableNode : public KGpgExpandableNode -{ - Q_OBJECT - -public: - typedef QList List; - typedef QList const_List; - - KGpgSignableNode(KGpgExpandableNode *parent = NULL); - virtual ~KGpgSignableNode(); - - KGpgSignNode::List getSignatures(void) const; - /** - * @brief count signatures - * @return the number of signatures to this object - * - * This does not include the number of signatures to child objects. - */ - virtual QString getSignCount() const; - - bool operator<(const KGpgSignableNode &other) const; - bool operator<(const KGpgSignableNode *other) const; - - /** - * @brief returns the key node this node belongs to - * @returns this node if the node itself is a key or it's parent otherwise - */ - virtual KGpgKeyNode *getKeyNode(void) = 0; - virtual const KGpgKeyNode *getKeyNode(void) const = 0; -}; - -#endif /* KGPGSIGNABLENODE_H */ diff --git a/kgpg/KGpgSubkeyNode.cpp b/kgpg/KGpgSubkeyNode.cpp deleted file mode 100644 index 571ca35..0000000 --- a/kgpg/KGpgSubkeyNode.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright 2008,2009 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 "KGpgSubkeyNode.h" - -//#include - -#include "convert.h" -#include "KGpgKeyNode.h" - -KGpgSubkeyNode::KGpgSubkeyNode(KGpgKeyNode *parent, const KgpgKeySub &k) - : KGpgSignableNode(parent), - m_skey(k) -{ - Q_ASSERT(parent != NULL); -} -KGpgSubkeyNode::~KGpgSubkeyNode() -{ -} - -void -KGpgSubkeyNode::readChildren() -{ -} - -KgpgCore::KgpgItemType -KGpgSubkeyNode::getType() const -{ - return ITYPE_SUB; -} - -KgpgCore::KgpgKeyTrust -KGpgSubkeyNode::getTrust() const -{ - return m_skey.trust(); -} - -QDateTime -KGpgSubkeyNode::getExpiration() const -{ - return m_skey.expirationDate(); -} - -QDateTime -KGpgSubkeyNode::getCreation() const -{ - return m_skey.creationDate(); -} - -QString -KGpgSubkeyNode::getId() const -{ - return m_skey.id(); -} - -KGpgKeyNode * -KGpgSubkeyNode::getKeyNode(void) -{ - return getParentKeyNode()->toKeyNode(); -} - -const KGpgKeyNode * -KGpgSubkeyNode::getKeyNode(void) const -{ - return getParentKeyNode()->toKeyNode(); -} - -QString -KGpgSubkeyNode::getName() const -{ - //return i18n("%1 subkey", Convert::toString(m_skey.algorithm())); - return "TODO"; -} - -QString -KGpgSubkeyNode::getSize() const -{ - return QString::number(m_skey.size()); -} - -KGpgKeyNode * -KGpgSubkeyNode::getParentKeyNode() const -{ - return m_parent->toKeyNode(); -} diff --git a/kgpg/KGpgSubkeyNode.h b/kgpg/KGpgSubkeyNode.h deleted file mode 100644 index bbe5ab8..0000000 --- a/kgpg/KGpgSubkeyNode.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright 2008,2009 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 . - */ -#ifndef KGPGSUBKEYNODE_H -#define KGPGSUBKEYNODE_H - -#include "KGpgSignableNode.h" - -#include "kgpgkey.h" - -using namespace KgpgCore; - -/** - * @brief a subkey of a public key or key pair - */ -class KGpgSubkeyNode : public KGpgSignableNode -{ -private: - KgpgCore::KgpgKeySub m_skey; - -protected: - virtual void readChildren(); - -public: - explicit KGpgSubkeyNode(KGpgKeyNode *parent, const KgpgCore::KgpgKeySub &k); - virtual ~KGpgSubkeyNode(); - - virtual KgpgCore::KgpgItemType getType() const; - virtual KgpgCore::KgpgKeyTrust getTrust() const; - virtual QString getSize() const; - virtual QString getName() const; - virtual QDateTime getExpiration() const; - virtual QDateTime getCreation() const; - virtual QString getId() const; - virtual KGpgKeyNode *getKeyNode(void); - virtual const KGpgKeyNode *getKeyNode(void) const; - virtual KGpgKeyNode *getParentKeyNode() const; -}; - -#endif /* KGPGSUBKEYNODE_H */ diff --git a/kgpg/KGpgUatNode.cpp b/kgpg/KGpgUatNode.cpp deleted file mode 100644 index 3457e82..0000000 --- a/kgpg/KGpgUatNode.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* Copyright 2008,2009,2010,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 "KGpgUatNode.h" - -#include "gpgproc.h" -#include "KGpgKeyNode.h" - -//#include -//#include - -#include -#include -#include -#include -#include - -class KGpgUatNodePrivate { -public: - KGpgUatNodePrivate(const KGpgKeyNode *parent, const unsigned int index, const QStringList &sl); - - const QString m_idx; - const QPixmap m_pixmap; - QDateTime m_creation; - -private: - static QPixmap loadImage(const KGpgKeyNode *parent, const QString &index); -}; - -KGpgUatNodePrivate::KGpgUatNodePrivate(const KGpgKeyNode *parent, const unsigned int index, const QStringList &sl) - : m_idx(QString::number(index)), - m_pixmap(loadImage(parent, m_idx)) -{ - if (sl.count() < 6) - return; - m_creation = QDateTime::fromTime_t(sl.at(5).toUInt()); -} - -QPixmap -KGpgUatNodePrivate::loadImage(const KGpgKeyNode *parent, const QString &index) -{ - QPixmap pixmap; -#ifdef Q_OS_WIN32 //krazy:exclude=cpp - const QString pgpgoutput = QLatin1String("cmd /C \"echo %I\""); -#else - const QString pgpgoutput = QLatin1String("echo %I"); -#endif - - GPGProc workProcess; - workProcess << - QLatin1String("--no-greeting") << - QLatin1String("--status-fd=2") << - QLatin1String("--photo-viewer") << pgpgoutput << - QLatin1String("--edit-key") << parent->getFingerprint() << - QLatin1String( "uid" ) << index << - QLatin1String( "showphoto" ) << - QLatin1String( "quit" ); - - workProcess.start(); - workProcess.waitForFinished(); - if (workProcess.exitCode() != 0) - return pixmap; - - QString tmpfile; - if (workProcess.readln(tmpfile) < 0) - return pixmap; - - QUrl url(tmpfile); - pixmap.load(url.path()); - QFile::remove(url.path()); - QDir dir; - //dir.rmdir(url.directory()); - - return pixmap; -} - -KGpgUatNode::KGpgUatNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl) - : KGpgSignableNode(parent), - d_ptr(new KGpgUatNodePrivate(parent, index, sl)) -{ -} - -KGpgUatNode::~KGpgUatNode() -{ - delete d_ptr; -} - -QString -KGpgUatNode::getName() const -{ - return tr("Photo id"); -} - -QString -KGpgUatNode::getSize() const -{ - const Q_D(KGpgUatNode); - - return QString::number(d->m_pixmap.width()) + QLatin1Char( 'x' ) + QString::number(d->m_pixmap.height()); -} - -QDateTime -KGpgUatNode::getCreation() const -{ - const Q_D(KGpgUatNode); - - return d->m_creation; -} - -KGpgKeyNode * -KGpgUatNode::getParentKeyNode() const -{ - return m_parent->toKeyNode(); -} - -void -KGpgUatNode::readChildren() -{ -} - -KgpgCore::KgpgItemType -KGpgUatNode::getType() const -{ - return KgpgCore::ITYPE_UAT; -} - -KgpgCore::KgpgKeyTrust -KGpgUatNode::getTrust() const -{ - return KgpgCore::TRUST_NOKEY; -} - -const QPixmap & -KGpgUatNode::getPixmap() const -{ - const Q_D(KGpgUatNode); - - return d->m_pixmap; -} - -QString -KGpgUatNode::getId() const -{ - const Q_D(KGpgUatNode); - - return d->m_idx; -} - -KGpgKeyNode * -KGpgUatNode::getKeyNode(void) -{ - return getParentKeyNode()->toKeyNode(); -} - -const KGpgKeyNode * -KGpgUatNode::getKeyNode(void) const -{ - return getParentKeyNode()->toKeyNode(); -} diff --git a/kgpg/KGpgUatNode.h b/kgpg/KGpgUatNode.h deleted file mode 100644 index b4c6775..0000000 --- a/kgpg/KGpgUatNode.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2008,2009,2010 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 . - */ -#ifndef KGPGUATNODE_H -#define KGPGUATNODE_H - -#include "KGpgSignableNode.h" - -#include -#include - -class KGpgExpandableNode; -class KGpgKeyNode; -class QPixmap; - -class KGpgUatNodePrivate; - -/** - * @brief A user attribute (i.e. photo id) of a public key or key pair - */ -class KGpgUatNode : public KGpgSignableNode -{ -private: - KGpgUatNodePrivate * const d_ptr; - Q_DECLARE_PRIVATE(KGpgUatNode) - -protected: - virtual void readChildren(); - -public: - explicit KGpgUatNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl); - virtual ~KGpgUatNode(); - - virtual KgpgCore::KgpgItemType getType() const; - virtual KgpgCore::KgpgKeyTrust getTrust() const; - const QPixmap &getPixmap() const; - virtual QString getId() const; - virtual QString getSize() const; - virtual QString getName() const; - virtual QDateTime getCreation() const; - virtual KGpgKeyNode *getParentKeyNode() const; - virtual KGpgKeyNode *getKeyNode(void); - virtual const KGpgKeyNode *getKeyNode(void) const; -}; - -#endif /* KGPGUATNODE_H */ diff --git a/kgpg/KGpgUidNode.cpp b/kgpg/KGpgUidNode.cpp deleted file mode 100644 index 0be6c10..0000000 --- a/kgpg/KGpgUidNode.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* Copyright 2008,2009,2010 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 "KGpgUidNode.h" - -#include "KGpgKeyNode.h" -#include "convert.h" - -class KGpgUidNodePrivate { -public: - KGpgUidNodePrivate(const unsigned int index, const QStringList &sl); - - const QString m_index; - QString m_email; - QString m_name; - QString m_comment; - KgpgCore::KgpgKeyTrust m_trust; - bool m_valid; -}; - -KGpgUidNodePrivate::KGpgUidNodePrivate(const unsigned int index, const QStringList &sl) - : m_index(QString::number(index)) -{ - QString fullname(sl.at(9)); - if (fullname.contains(QLatin1Char( '<' )) ) { - m_email = fullname; - - if (fullname.contains(QLatin1Char( ')' )) ) - m_email = m_email.section(QLatin1Char( ')' ), 1); - - m_email = m_email.section(QLatin1Char( '<' ), 1); - m_email.truncate(m_email.length() - 1); - - if (m_email.contains(QLatin1Char( '<' ))) { - // several email addresses in the same key - m_email = m_email.replace(QLatin1Char( '>' ), QLatin1Char( ';' )); - m_email.remove(QLatin1Char( '<' )); - } - } - - m_name = fullname.section(QLatin1String( " <" ), 0, 0); - if (fullname.contains(QLatin1Char( '(' )) ) { - m_name = m_name.section(QLatin1String( " (" ), 0, 0); - m_comment = fullname.section(QLatin1Char( '(' ), 1, 1); - m_comment = m_comment.section(QLatin1Char( ')' ), 0, 0); - } - - m_trust = KgpgCore::Convert::toTrust(sl.at(1)); - m_valid = ((sl.count() <= 11) || !sl.at(11).contains(QLatin1Char( 'D' ))); -} - - -KGpgUidNode::KGpgUidNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl) - : KGpgSignableNode(parent), - d_ptr(new KGpgUidNodePrivate(index, sl)) -{ -} - -KGpgUidNode::~KGpgUidNode() -{ - delete d_ptr; -} - -QString -KGpgUidNode::getName() const -{ - const Q_D(KGpgUidNode); - - return d->m_name; -} - -QString -KGpgUidNode::getEmail() const -{ - const Q_D(KGpgUidNode); - - return d->m_email; -} - -QString -KGpgUidNode::getId() const -{ - const Q_D(KGpgUidNode); - - return d->m_index; -} - -KGpgKeyNode * -KGpgUidNode::getKeyNode(void) -{ - return getParentKeyNode()->toKeyNode(); -} - -const KGpgKeyNode * -KGpgUidNode::getKeyNode(void) const -{ - return getParentKeyNode()->toKeyNode(); -} - -KGpgKeyNode * -KGpgUidNode::getParentKeyNode() const -{ - return m_parent->toKeyNode(); -} - -void -KGpgUidNode::readChildren() -{ -} - -KgpgCore::KgpgItemType -KGpgUidNode::getType() const -{ - return KgpgCore::ITYPE_UID; -} - -KgpgCore::KgpgKeyTrust -KGpgUidNode::getTrust() const -{ - const Q_D(KGpgUidNode); - - return d->m_trust; -} - -QString -KGpgUidNode::getComment() const -{ - const Q_D(KGpgUidNode); - - return d->m_comment; -} diff --git a/kgpg/KGpgUidNode.h b/kgpg/KGpgUidNode.h deleted file mode 100644 index cd1b563..0000000 --- a/kgpg/KGpgUidNode.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright 2008,2009,2010 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 . - */ -#ifndef KGPGUIDNODE_H -#define KGPGUIDNODE_H - -#include "KGpgSignableNode.h" - -#include "kgpgkey.h" - -class KGpgKeyNode; - -class KGpgUidNodePrivate; - -/** - * @brief A user id of a public key or key pair - */ -class KGpgUidNode : public KGpgSignableNode -{ -private: - KGpgUidNodePrivate * const d_ptr; - Q_DECLARE_PRIVATE(KGpgUidNode) - -protected: - virtual void readChildren(); - -public: - explicit KGpgUidNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl); - virtual ~KGpgUidNode(); - - virtual KgpgCore::KgpgItemType getType() const; - virtual KgpgCore::KgpgKeyTrust getTrust() const; - virtual QString getName() const; - virtual QString getEmail() const; - virtual QString getId() const; - virtual KGpgKeyNode *getKeyNode(void); - virtual const KGpgKeyNode *getKeyNode(void) const; - virtual KGpgKeyNode *getParentKeyNode() const; - virtual QString getComment() const; -}; - -#endif /* KGPGUIDNODE_H */ diff --git a/kgpg/convert.cpp b/kgpg/convert.cpp deleted file mode 100644 index 934ec02..0000000 --- a/kgpg/convert.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2006 Jimmy Gilles - * Copyright (C) 2010 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) any later version. * - * * - * 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, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "convert.h" - -//#include -//#include -#include -//#include "kgpgsettings.h" -#include "images.h" - -namespace KgpgCore -{ - -QString Convert::toString(const KgpgKeyAlgo algorithm) -{ - switch (algorithm) - { - case ALGO_RSA: return QObject::tr("Encryption algorithm", "RSA"); - case ALGO_DSA: return QObject::tr("Encryption algorithm", "DSA"); - case ALGO_ELGAMAL: return QObject::tr("Encryption algorithm", "ElGamal"); - case ALGO_DSA_ELGAMAL: return QObject::tr("Encryption algorithm", "DSA & ElGamal"); - case ALGO_RSA_RSA: return QObject::tr("Encryption algorithm RSA, Signing algorithm RSA", "RSA & RSA"); - case ALGO_UNKNOWN: - default: return QObject::tr("Unknown algorithm", "Unknown"); - } -} - -QString Convert::toString(const KgpgKeyOwnerTrust ownertrust) -{ - switch (ownertrust) - { - case OWTRUST_UNDEFINED: return QObject::tr("Do not Know"); - case OWTRUST_NONE: return QObject::tr("Do NOT Trust"); - case OWTRUST_MARGINAL: return QObject::tr("Marginally"); - case OWTRUST_FULL: return QObject::tr("Fully"); - case OWTRUST_ULTIMATE: return QObject::tr("Ultimately"); - case OWTRUST_UNKNOWN: - default: return QObject::tr("Unknown trust in key owner", "Unknown"); - } -} - -QString Convert::toString(const KgpgKeyTrust trust) -{ - switch (trust) - { - case TRUST_INVALID: return QObject::tr("Invalid key", "Invalid"); - case TRUST_DISABLED: return QObject::tr("Disabled key", "Disabled"); - case TRUST_REVOKED: return QObject::tr("Revoked"); - case TRUST_EXPIRED: return QObject::tr("Expired key", "Expired"); - case TRUST_UNDEFINED: return QObject::tr("Undefined key trust", "Undefined"); - case TRUST_NONE: return QObject::tr("No trust in key", "None"); - case TRUST_MARGINAL: return QObject::tr("Marginal trust in key", "Marginal"); - case TRUST_FULL: return QObject::tr("Full trust in key", "Full"); - case TRUST_ULTIMATE: return QObject::tr("Ultimate trust in key", "Ultimate"); - case TRUST_UNKNOWN: - default: return QObject::tr("Unknown trust in key", "Unknown"); - } -} - -QColor Convert::toColor(const KgpgKeyTrust trust) -{ - switch (trust) - { - case TRUST_INVALID: - /*case TRUST_DISABLED: return KGpgSettings::colorBad(); - case TRUST_EXPIRED: return KGpgSettings::colorExpired(); - case TRUST_MARGINAL: return KGpgSettings::colorMarginal(); - case TRUST_REVOKED: return KGpgSettings::colorRev(); - case TRUST_UNDEFINED: - case TRUST_NONE: return KGpgSettings::colorUnknown(); - case TRUST_FULL: return KGpgSettings::colorGood(); - case TRUST_ULTIMATE: return KGpgSettings::colorUltimate();*/ - case TRUST_UNKNOWN: - default: return QColor(0,0,0); - //return KGpgSettings::colorUnknown(); - } -} - -QString Convert::toString(const QDate &date) -{ - //return KGlobal::locale()->formatDate(date, KLocale::ShortDate); -} - -KgpgKeyAlgo Convert::toAlgo(const uint v) -{ - switch (v) - { - case 1: return ALGO_RSA; - case 16: - case 20: return ALGO_ELGAMAL; - case 17: return ALGO_DSA; - default: return ALGO_UNKNOWN; - } -} - -KgpgKeyAlgo Convert::toAlgo(const QString &s) -{ - bool b; - unsigned int u = s.toUInt(&b); - return b ? toAlgo(u) : ALGO_UNKNOWN; -} - -KgpgKeyTrust Convert::toTrust(const QChar &c) -{ - switch (c.toAscii()) - { - case 'o': return TRUST_UNKNOWN; - case 'i': return TRUST_INVALID; - case 'd': return TRUST_DISABLED; - case 'r': return TRUST_REVOKED; - case 'e': return TRUST_EXPIRED; - case 'q': return TRUST_UNDEFINED; - case 'n': return TRUST_NONE; - case 'm': return TRUST_MARGINAL; - case 'f': return TRUST_FULL; - case 'u': return TRUST_ULTIMATE; - default: return TRUST_UNKNOWN; - } -} - -KgpgKeyTrust Convert::toTrust(const QString &s) -{ - return s.isEmpty() ? TRUST_UNKNOWN : toTrust(s[0]); -} - -KgpgKeyOwnerTrust Convert::toOwnerTrust(const QChar &c) -{ - switch (c.toAscii()) - { - case 'n': return OWTRUST_NONE; - case 'm': return OWTRUST_MARGINAL; - case 'u': return OWTRUST_ULTIMATE; - case 'f': return OWTRUST_FULL; - default: return OWTRUST_UNDEFINED; - } -} - -KgpgKeyOwnerTrust Convert::toOwnerTrust(const QString &s) -{ - return s.isEmpty() ? OWTRUST_UNDEFINED : toOwnerTrust(s[0]); -} - -QPixmap Convert::toPixmap(const KgpgItemType t) -{ - switch (t) - { - case ITYPE_GROUP: return Images::group(); - case ITYPE_GSECRET: - case ITYPE_SECRET: return Images::orphan(); - case ITYPE_GPUBLIC: - case ITYPE_SUB: - case ITYPE_PUBLIC: return Images::single(); - case ITYPE_GPAIR: - case ITYPE_PAIR: return Images::pair(); - case ITYPE_UID: return Images::userId(); - case ITYPE_UAT: return Images::photo(); - case ITYPE_REVSIGN: return Images::revoke(); - case ITYPE_SIGN: return Images::signature(); - default: Q_ASSERT(1); - return NULL; - } -} - -} // namespace KgpgCore diff --git a/kgpg/convert.h b/kgpg/convert.h deleted file mode 100644 index 96043a8..0000000 --- a/kgpg/convert.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2006 Jimmy Gilles - * Copyright (C) 2010 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) any later version. * - * * - * 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, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef CONVERT_H -#define CONVERT_H - -#include "kgpgkey.h" - -class QColor; -class QString; -class QPixmap; - -namespace KgpgCore -{ - -class Convert -{ -public: - static QString toString(const KgpgCore::KgpgKeyAlgo algorithm); - static QString toString(const KgpgCore::KgpgKeyOwnerTrust ownertrust); - static QString toString(const KgpgCore::KgpgKeyTrust trust); - static QString toString(const QDate &date); - static QColor toColor(const KgpgCore::KgpgKeyTrust trust); - static KgpgKeyAlgo toAlgo(const uint v); - static KgpgKeyAlgo toAlgo(const QString &s); - static KgpgKeyTrust toTrust(const QChar &c); - static KgpgKeyTrust toTrust(const QString &s); - static KgpgKeyOwnerTrust toOwnerTrust(const QChar &c); - static KgpgKeyOwnerTrust toOwnerTrust(const QString &s); - static QPixmap toPixmap(const KgpgCore::KgpgItemType t); -}; - -} // namespace KgpgCore - -#endif // CONVERT_H diff --git a/kgpg/core/KGpgExpandableNode.cpp b/kgpg/core/KGpgExpandableNode.cpp new file mode 100644 index 0000000..4cf9607 --- /dev/null +++ b/kgpg/core/KGpgExpandableNode.cpp @@ -0,0 +1,88 @@ +/* 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 "KGpgExpandableNode.h" + +//#include "kgpgsettings.h" +#include "convert.h" +//#include "model/kgpgitemmodel.h" + +//#include + +KGpgExpandableNode::KGpgExpandableNode(KGpgExpandableNode *parent) + : KGpgNode(parent) +{ + if (parent != NULL) + parent->children.append(this); +} + +KGpgExpandableNode::~KGpgExpandableNode() +{ + for (int i = children.count() - 1; i >= 0; i--) + delete children[i]; +} + +KGpgNode * +KGpgExpandableNode::getChild(const int index) const +{ + if ((index < 0) || (index > children.count())) + return NULL; + return children.at(index); +} + +int +KGpgExpandableNode::getChildCount() +{ + if (children.count() == 0) + readChildren(); + + return children.count(); +} + +bool +KGpgExpandableNode::hasChildren() const +{ + return (children.count() != 0); +} + +bool +KGpgExpandableNode::wasExpanded() const +{ + return (children.count() != 0); +} + +const +KGpgNode::List & +KGpgExpandableNode::getChildren() const +{ + return children; +} + +int +KGpgExpandableNode::getChildIndex(KGpgNode *node) const +{ + return children.indexOf(node); +} + +void +KGpgExpandableNode::deleteChild(KGpgNode *child) +{ + children.removeAll(child); +} + +//#include "KGpgExpandableNode.moc" diff --git a/kgpg/core/KGpgExpandableNode.h b/kgpg/core/KGpgExpandableNode.h new file mode 100644 index 0000000..39f351d --- /dev/null +++ b/kgpg/core/KGpgExpandableNode.h @@ -0,0 +1,85 @@ +/* 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 . + */ +#ifndef KGPGEXPANDABLENODE_H +#define KGPGEXPANDABLENODE_H + +#include "KGpgNode.h" + +class KGpgSubkeyNode; +class KGpgRefNode; + +/** + * @brief The abstract base class for all classes that may have child objects + * + * Every class that represents something in the keyring that may have + * child objects inherits from this class. That does not mean that every + * child object always has children, but every child \em may have children. + */ +class KGpgExpandableNode : public KGpgNode +{ + Q_OBJECT + + friend class KGpgRefNode; + friend class KGpgSubkeyNode; +protected: + KGpgNode::List children; + + /** + * reimplemented in every base class to read in the child data + * + * This allows the child objects to delay the loading of the + * child objects until they are really needed to avoid time + * consuming operations for data never used. + */ + virtual void readChildren() = 0; + + explicit KGpgExpandableNode(KGpgExpandableNode *parent = NULL); +public: + virtual ~KGpgExpandableNode(); + + /** + * check if there are any child nodes + * + * The default implementation returns true if any child nodes were loaded. + * This may be reimplemented by child classes so they can indicate that + * there are child nodes before actually loading them. + * + * This method indicates if there are children if this node is expanded. + * In contrast wasExpanded() will only return true if the child nodes + * are actually present in memory. + */ + virtual bool hasChildren() const; + /** + * check if there are any child nodes present in memory + * + * Returns true if any child nodes were loaded. + * + * This method indicates if the children of this node are already loaded + * into memory. In contrast hasChildren() may return true even if the child + * objects are not present in memory. + */ + virtual bool wasExpanded() const; + virtual int getChildCount(); + virtual const KGpgNode::List &getChildren() const; + virtual KGpgNode *getChild(const int index) const; + virtual int getChildIndex(KGpgNode *node) const; + virtual void deleteChild(KGpgNode *child); +}; + +#endif /* KGPGEXPANDABLENODE_H */ diff --git a/kgpg/core/KGpgGroupMemberNode.cpp b/kgpg/core/KGpgGroupMemberNode.cpp new file mode 100644 index 0000000..e7a9f97 --- /dev/null +++ b/kgpg/core/KGpgGroupMemberNode.cpp @@ -0,0 +1,100 @@ +/* Copyright 2008,2009 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 "KGpgGroupMemberNode.h" + +#include + +#include "KGpgGroupNode.h" +#include "KGpgKeyNode.h" + +KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, const QString &k) + : KGpgRefNode(parent, k) +{ +} + +KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, KGpgKeyNode *k) + : KGpgRefNode(parent, k) +{ +} + +KGpgGroupMemberNode::~KGpgGroupMemberNode() +{ +} + +KgpgKeyTrust +KGpgGroupMemberNode::getTrust() const +{ + if (m_keynode != NULL) + return m_keynode->getTrust(); + return KgpgCore::TRUST_NOKEY; +} + +KgpgItemType +KGpgGroupMemberNode::getType() const +{ + if (m_keynode != NULL) + return m_keynode->getType() | KgpgCore::ITYPE_GROUP; + return KgpgCore::ITYPE_PUBLIC | KgpgCore::ITYPE_GROUP; +} + +QString +KGpgGroupMemberNode::getSize() const +{ + if (m_keynode != NULL) + return m_keynode->getSize(); + return QString(); +} + +QDateTime +KGpgGroupMemberNode::getExpiration() const +{ + if (m_keynode != NULL) + return m_keynode->getExpiration(); + return QDateTime(); +} + +QDateTime +KGpgGroupMemberNode::getCreation() const +{ + if (m_keynode != NULL) + return m_keynode->getCreation(); + return QDateTime(); +} + +unsigned int +KGpgGroupMemberNode::getSignKeySize() const +{ + if (m_keynode != NULL) + return m_keynode->getSignKeySize(); + return 0; +} + +unsigned int +KGpgGroupMemberNode::getEncryptionKeySize() const +{ + if (m_keynode != NULL) + return m_keynode->getEncryptionKeySize(); + return 0; +} + +KGpgGroupNode * +KGpgGroupMemberNode::getParentKeyNode() const +{ + return m_parent->toGroupNode(); +} diff --git a/kgpg/core/KGpgGroupMemberNode.h b/kgpg/core/KGpgGroupMemberNode.h new file mode 100644 index 0000000..2a456ef --- /dev/null +++ b/kgpg/core/KGpgGroupMemberNode.h @@ -0,0 +1,61 @@ +/* Copyright 2008,2009 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 . + */ +#ifndef KGPGGROUPMEMBERNODE_H +#define KGPGGROUPMEMBERNODE_H + +#include "KGpgRefNode.h" + +#include +#include "kgpgkey.h" + +using namespace KgpgCore; + +class KGpgKeyNode; +class KGpgGroupNode; + +/** + * @brief A member of a GnuPG group + */ +class KGpgGroupMemberNode : public KGpgRefNode +{ +public: + explicit KGpgGroupMemberNode(KGpgGroupNode *parent, const QString &k); + explicit KGpgGroupMemberNode(KGpgGroupNode *parent, KGpgKeyNode *k); + virtual ~KGpgGroupMemberNode(); + + virtual KgpgCore::KgpgKeyTrust getTrust() const; + virtual KgpgCore::KgpgItemType getType() const; + virtual QString getSize() const; + virtual QDateTime getExpiration() const; + virtual QDateTime getCreation() const; + virtual KGpgGroupNode *getParentKeyNode() const; + + /** + * Returns the size of the signing key. + * @return signing key size in bits + */ + virtual unsigned int getSignKeySize() const; + /** + * Returns the size of the first encryption subkey. + * @return encryption key size in bits + */ + virtual unsigned int getEncryptionKeySize() const; +}; + +#endif /* KGPGGROUPMEMBERNODE_H */ diff --git a/kgpg/core/KGpgGroupNode.cpp b/kgpg/core/KGpgGroupNode.cpp new file mode 100644 index 0000000..3475303 --- /dev/null +++ b/kgpg/core/KGpgGroupNode.cpp @@ -0,0 +1,279 @@ +/* Copyright 2008,2009,2010,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 "KGpgGroupNode.h" + +#include "KGpgGroupMemberNode.h" +#include "KGpgRootNode.h" +//#include "kgpgsettings.h" + +#include +//#include +#include +#include +#include + +class KGpgGroupNodePrivate { +public: + KGpgGroupNodePrivate(const QString &name); + + QString m_name; + + /** + * @brief find the line that defines this group in the configuration + * @param conffile file object (will be initialized) + * @param stream text stream (will be initialized and connected to conffile) + * @param lines the lines found in conffile (will be filled) + * @return the index in lines of the entry defining this group + * @retval -1 no entry defining this group was found + * + * stream will be positioned at the beginning. + */ + int findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines); + + static const QRegExp &groupPattern(); + static const QString &groupTag(); +}; + +KGpgGroupNodePrivate::KGpgGroupNodePrivate(const QString &name) + : m_name(name) +{ +} + +int +KGpgGroupNodePrivate::findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines) +{ + //conffile.setFileName(KGpgSettings::gpgConfigPath()); + conffile.setFileName(""); + + if (!conffile.exists()) + return -1; + + if (!conffile.open(QIODevice::ReadWrite)) + return -1; + + stream.setDevice(&conffile); + int index = -1; + int i = -1; + + while (!stream.atEnd()) { + const QString rawLine = stream.readLine(); + i++; + QString parsedLine = rawLine.simplified().section(QLatin1Char('#'), 0, 0); + + if (groupPattern().exactMatch(parsedLine)) { + // remove "group " + parsedLine = parsedLine.remove(0, 6); + if (parsedLine.startsWith(m_name)) { + if (parsedLine.mid(m_name.length()).simplified().startsWith(QLatin1Char('='))) { + if (index >= 0) { + // multiple definitions of the same group, drop the second one + continue; + } else { + index = i; + } + } + } + } + + lines << rawLine; + } + + stream.seek(0); + + return index; +} + +const QRegExp & +KGpgGroupNodePrivate::groupPattern() +{ + static const QRegExp groupre(QLatin1String("^group [^ ]+ ?= ?([0-9a-fA-F]{8,} ?)*$")); + + return groupre; +} + +const QString & +KGpgGroupNodePrivate::groupTag() +{ + static const QString grouptag(QLatin1String("group ")); + + return grouptag; +} + +KGpgGroupNode::KGpgGroupNode(KGpgRootNode *parent, const QString &name, const QStringList &members) + : KGpgExpandableNode(parent), + d_ptr(new KGpgGroupNodePrivate(name)) +{ + foreach (const QString &id, members) + new KGpgGroupMemberNode(this, id); + + parent->m_groups++; +} + +KGpgGroupNode::KGpgGroupNode(KGpgRootNode *parent, const QString &name, const KGpgKeyNode::List &members) + : KGpgExpandableNode(parent), + d_ptr(new KGpgGroupNodePrivate(name)) +{ + Q_ASSERT(members.count() > 0); + + foreach (KGpgKeyNode *nd, members) + new KGpgGroupMemberNode(this, nd); + + parent->m_groups++; +} + +KGpgGroupNode::~KGpgGroupNode() +{ + KGpgRootNode *root = m_parent->toRootNode(); + + if (root != NULL) + root->m_groups--; +} + +KgpgCore::KgpgItemType +KGpgGroupNode::getType() const +{ + return ITYPE_GROUP; +} + +QString +KGpgGroupNode::getName() const +{ + const Q_D(KGpgGroupNode); + + return d->m_name; +} + +QString +KGpgGroupNode::getSize() const +{ + return tr("1 key", "%1 keys").arg(children.count()); +} + +void +KGpgGroupNode::readChildren() +{ +} + +void +KGpgGroupNode::rename(const QString &newName) +{ + Q_D(KGpgGroupNode); + + QFile conffile; + QTextStream t; + QStringList lines; + int index = d->findGroupEntry(conffile, t, lines); + + // check if file opening failed + if (!t.device()) + return; + + if (index < 0) { + qDebug() << "Group " << d->m_name << " not renamed, group does not exist"; + return; + } + + // 6 = groupTag().length() + const QString values = lines[index].simplified().mid(6 + d->m_name.length()); + lines[index] = d->groupTag() + newName + QLatin1Char(' ') + values; + + conffile.resize(0); + t << lines.join(QLatin1String("\n")) + QLatin1Char('\n'); + + d->m_name = newName; +} + +void +KGpgGroupNode::saveMembers() +{ + Q_D(KGpgGroupNode); + + QFile conffile; + QTextStream t; + QStringList lines; + int index = d->findGroupEntry(conffile, t, lines); + + // check if file opening failed + if (!t.device()) + return; + + QStringList memberIds; + + for (int j = getChildCount() - 1; j >= 0; j--) + memberIds << getChild(j)->toGroupMemberNode()->getId(); + + const QString groupEntry = d->groupTag() + d->m_name + QLatin1String(" = ") + + memberIds.join(QLatin1String(" ")); + + if (index >= 0) + lines[index] = groupEntry; + else + lines << groupEntry; + + conffile.resize(0); + t << lines.join(QLatin1String("\n")) + QLatin1Char('\n'); +} + +void +KGpgGroupNode::remove() +{ + Q_D(KGpgGroupNode); + + QFile conffile; + QTextStream t; + QStringList lines; + int index = d->findGroupEntry(conffile, t, lines); + + // check if file opening failed + if (!t.device()) + return; + + if (index < 0) + return; + + lines.removeAt(index); + conffile.resize(0); + t << lines.join(QLatin1String("\n")) + QLatin1Char('\n'); +} + +QStringList +KGpgGroupNode::readGroups() +{ + QStringList groups; + //QFile qfile(KGpgSettings::gpgConfigPath()); + QFile qfile(""); + + if (!qfile.exists() || !qfile.open(QIODevice::ReadOnly)) + return groups; + + QTextStream t(&qfile); + + while (!t.atEnd()) { + QString line = t.readLine().simplified().section(QLatin1Char('#'), 0, 0); + if (!KGpgGroupNodePrivate::groupPattern().exactMatch(line)) + continue; + + // remove the "group " at the start + line.remove(0, 6); + // transform it in a simple space separated list + groups.append(line.replace(QLatin1Char('='), QLatin1Char(' ')).simplified()); + } + + return groups; +} diff --git a/kgpg/core/KGpgGroupNode.h b/kgpg/core/KGpgGroupNode.h new file mode 100644 index 0000000..5aca837 --- /dev/null +++ b/kgpg/core/KGpgGroupNode.h @@ -0,0 +1,84 @@ +/* Copyright 2008,2009,2010,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 . + */ +#ifndef KGPGGROUPNODE_H +#define KGPGGROUPNODE_H + +#include "KGpgExpandableNode.h" +#include "KGpgKeyNode.h" + +class QString; +class QStringList; + +class KGpgGroupNodePrivate; + +/** + * @brief A GnuPG group of public keys + */ +class KGpgGroupNode : public KGpgExpandableNode +{ +private: + KGpgGroupNodePrivate * const d_ptr; + Q_DECLARE_PRIVATE(KGpgGroupNode) + Q_DISABLE_COPY(KGpgGroupNode) + +protected: + virtual void readChildren(); + +public: + KGpgGroupNode(KGpgRootNode *parent, const QString &name, const QStringList &members); + KGpgGroupNode(KGpgRootNode *parent, const QString &name, const KGpgKeyNode::List &members); + virtual ~KGpgGroupNode(); + + virtual KgpgCore::KgpgItemType getType() const; + /** + * Return size of group + * + * @return the number of keys in this group + */ + virtual QString getSize() const; + virtual QString getName() const; + + /** + * Rename this group node + * + * @param newName new name of the group + */ + void rename(const QString &newName); + + /** + * Write the current members to GnuPG config file + */ + void saveMembers(); + + /** + * Remove this group from the GnuPG config file + */ + void remove(); + + /** + * @brief get all groups from GnuPG config file + * @return list of groups names and their keys + * + * The strings are themself space separated list. The first entry is the + * group name, the others are the keys inside + */ + static QStringList readGroups(); +}; + +#endif /* KGPGGROUPNODE_H */ diff --git a/kgpg/core/KGpgKeyNode.cpp b/kgpg/core/KGpgKeyNode.cpp new file mode 100644 index 0000000..4e5fb55 --- /dev/null +++ b/kgpg/core/KGpgKeyNode.cpp @@ -0,0 +1,358 @@ +/* Copyright 2008,2009,2010,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 "KGpgKeyNode.h" + +#include "KGpgGroupMemberNode.h" +#include "KGpgRootNode.h" +#include "KGpgSubkeyNode.h" +#include "KGpgUatNode.h" +#include "KGpgUidNode.h" +#include "convert.h" +#include "../kgpginterface.h" +//#include "kgpgsettings.h" +//#include "model/kgpgitemmodel.h" + +//#include + +KGpgKeyNode::KGpgKeyNode(KGpgRootNode *parent, const KgpgCore::KgpgKey &k) + : KGpgSignableNode(parent), + m_key(new KgpgCore::KgpgKey(k)), + m_signs(0) +{ +} + +KGpgKeyNode::~KGpgKeyNode() +{ + foreach (KGpgRefNode *nd, m_refs) { + nd->unRef(m_parent->toRootNode()); + } +} + +KgpgCore::KgpgItemType +KGpgKeyNode::getType() const +{ + return getType(m_key); +} + +bool +KGpgKeyNode::hasChildren() const +{ + return true; +} + +KgpgCore::KgpgItemType +KGpgKeyNode::getType(const KgpgCore::KgpgKey *k) +{ + if (k->secret()) + return KgpgCore::ITYPE_PAIR; + + return KgpgCore::ITYPE_PUBLIC; +} + +KgpgCore::KgpgKeyTrust +KGpgKeyNode::getTrust() const +{ + return m_key->trust(); +} + +const QString & +KGpgKeyNode::getFingerprint() const +{ + return m_key->fingerprint(); +} + +QString +KGpgKeyNode::getSize() const +{ + return "size of signing key / size of encryption key", + "%1 / %2", QString::number(getSignKeySize()), + QString::number(getEncryptionKeySize()); +} + +QString +KGpgKeyNode::getName() const +{ + return m_key->name(); +} + +QString +KGpgKeyNode::getEmail() const +{ + return m_key->email(); +} + +QDateTime +KGpgKeyNode::getExpiration() const +{ + return m_key->expirationDate(); +} + +QDateTime +KGpgKeyNode::getCreation() const +{ + return m_key->creationDate(); +} + +QString +KGpgKeyNode::getId() const +{ + return m_key->fullId(); +} + +KGpgKeyNode * +KGpgKeyNode::getKeyNode(void) +{ + return this; +} + +bool +KGpgKeyNode::isSecret() const +{ + return m_key->secret(); +} + +const KGpgKeyNode * +KGpgKeyNode::getKeyNode(void) const +{ + return this; +} + +QString +KGpgKeyNode::getBeautifiedFingerprint() const +{ + return m_key->fingerprintBeautified(); +} + +QString +KGpgKeyNode::getComment() const +{ + return m_key->comment(); +} + +void +KGpgKeyNode::readChildren() +{ + KgpgInterface::readSignatures(this); + + m_signs = 0; + foreach(KGpgNode *n, children) + if (n->getType() == ITYPE_SIGN) + m_signs++; +} + +QString +KGpgKeyNode::getSignCount() const +{ + if (!wasExpanded()) + return QString(); + //return i18np("1 signature", "%1 signatures", m_signs); + return "TODO"; +} + +KgpgKey * +KGpgKeyNode::copyKey() const +{ + return new KgpgKey(*m_key); +} + +void +KGpgKeyNode::setKey(const KgpgKey &key) +{ + Q_ASSERT(m_key->fingerprint() == key.fingerprint()); + delete m_key; + + for (int i = 0; i < children.count(); i++) + delete children.at(i); + children.clear(); + + m_key = new KgpgKey(key); +} + +const KgpgKey * +KGpgKeyNode::getKey() const +{ + return m_key; +} + +unsigned int +KGpgKeyNode::getSignKeySize() const +{ + return m_key->size(); +} + +unsigned int +KGpgKeyNode::getEncryptionKeySize() const +{ + return m_key->encryptionSize(); +} + +void +KGpgKeyNode::addRef(KGpgRefNode *node) +{ + Q_ASSERT(m_refs.indexOf(node) == -1); + m_refs.append(node); +} + +void +KGpgKeyNode::delRef(KGpgRefNode *node) +{ + Q_ASSERT(m_refs.indexOf(node) != -1); + m_refs.removeOne(node); + Q_ASSERT(m_refs.indexOf(node) == -1); +} + +QList +KGpgKeyNode::getGroups(void) const +{ + QList ret; + + foreach (KGpgGroupMemberNode *gnd, getGroupRefs()) + ret.append(gnd->getParentKeyNode()); + + return ret; +} + +QList +KGpgKeyNode::getRefsOfType(const KgpgItemType &type) const +{ + QList ret; + + foreach (KGpgRefNode *nd, m_refs) { + if (nd->getType() & type) + ret.append(nd); + } + + return ret; +} + +QList +KGpgKeyNode::getGroupRefs(void) const +{ + QList ret; + + foreach (KGpgRefNode *rn, getRefsOfType(KgpgCore::ITYPE_GROUP)) + ret.append(rn->toGroupMemberNode()); + + return ret; +} + +KGpgSignNode::List +KGpgKeyNode::getSignRefs(void) const +{ + KGpgSignNode::List ret; + + QList refs = getRefsOfType(KgpgCore::ITYPE_SIGN); + + foreach (KGpgRefNode *rn, refs) + ret.append(rn->toSignNode()); + + return ret; +} + +KGpgSignNode::List +KGpgKeyNode::getSignatures(const bool subkeys) const +{ + KGpgSignNode::List ret = KGpgSignableNode::getSignatures(); + + if (!subkeys) + return ret; + + foreach (KGpgNode *child, children) { + KGpgSignNode::List tmp; + + switch (child->getType()) { + case KgpgCore::ITYPE_UID: + case KgpgCore::ITYPE_UAT: + tmp = child->toSignableNode()->getSignatures(); + break; + default: + continue; + } + + foreach (KGpgSignNode *sn, tmp) { + bool found = false; + const QString snid(sn->getId()); + + foreach (const KGpgSignNode *retsn, ret) { + found = (retsn->getId() == snid); + if (found) + break; + } + + if (!found) + ret << sn; + } + } + + return ret; +} + +const KGpgSignableNode * +KGpgKeyNode::getUid(const unsigned int index) const +{ + Q_ASSERT(index > 0); + + if (index == 1) + return this; + + const QString idxstr(QString::number(index)); + + foreach (const KGpgNode *child, children) { + KGpgSignNode::List tmp; + + switch (child->getType()) { + case KgpgCore::ITYPE_UID: + case KgpgCore::ITYPE_UAT: + if (child->getId() == idxstr) + return child->toSignableNode(); + break; + default: + continue; + } + } + + return NULL; +} + +bool +KGpgKeyNode::compareId(const QString &other) const +{ + if (other.length() == m_key->fullId().length()) + return (other.compare(m_key->fullId(), Qt::CaseInsensitive) == 0); + + if (other.length() == m_key->fingerprint().length()) + return (other.compare(m_key->fingerprint(), Qt::CaseInsensitive) == 0); + + const QString comId = m_key->fullId().isEmpty() ? m_key->fingerprint() : m_key->fullId(); + + return (other.right(comId.length()).compare( + comId.right(other.length()), + Qt::CaseInsensitive) == 0); +} + +void +KGpgKeyNode::expand() +{ + if (!wasExpanded()) + readChildren(); + + emit expanded(); +} + +//#include "KGpgKeyNode.moc" diff --git a/kgpg/core/KGpgKeyNode.h b/kgpg/core/KGpgKeyNode.h new file mode 100644 index 0000000..caf0ba4 --- /dev/null +++ b/kgpg/core/KGpgKeyNode.h @@ -0,0 +1,191 @@ +/* Copyright 2008,2009,2010,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 . + */ +#ifndef KGPGKEYNODE_H +#define KGPGKEYNODE_H + +#include "KGpgSignableNode.h" +#include "KGpgSignNode.h" + +#include "kgpgkey.h" + +class KGpgExpandableNode; +class KGpgRefNode; + +/** + * @brief A public key with or without corresponding secret key + */ +class KGpgKeyNode : public KGpgSignableNode +{ + Q_OBJECT + + friend class KGpgGroupMemberNode; + +private: + KgpgCore::KgpgKey *m_key; + int m_signs; + +protected: + virtual void readChildren(); + + QList m_refs; + QList getRefsOfType(const KgpgCore::KgpgItemType &type) const; + +public: + typedef QList List; + typedef QList ConstList; + + explicit KGpgKeyNode(KGpgRootNode *parent, const KgpgCore::KgpgKey &k); + virtual ~KGpgKeyNode(); + + virtual bool hasChildren() const; + + static KgpgCore::KgpgItemType getType(const KgpgCore::KgpgKey *k); + + virtual KgpgCore::KgpgItemType getType() const; + virtual KgpgCore::KgpgKeyTrust getTrust() const; + const QString &getFingerprint() const; + virtual QString getSize() const; + virtual QString getName() const; + virtual QString getEmail() const; + virtual QDateTime getExpiration() const; + virtual QDateTime getCreation() const; + virtual QString getId() const; + virtual KGpgKeyNode *getKeyNode(void); + virtual const KGpgKeyNode *getKeyNode(void) const; + /** + * @brief Return if this key has a private key + */ + bool isSecret() const; + /** + * @brief Print the full key fingerprint with spaces inserted + * + * For display purposes you normally don't want to print the full + * fingerprint as is because it's too many hex characters at once. + * This function returns the fingerprint in the format usually used + * for printing this out, i.e. with a space after each fourth hex + * character. + * + * @return the full fingerprint with spaces inserted + */ + QString getBeautifiedFingerprint() const; + virtual QString getComment() const; + /** + * @brief Return the number of signatures of the primary user id + * + * This is different from the number of children of this node as there + * is usually at least one subkey and there may also be additional + * user ids or attributes. This does not count the signatures to those + * slave objects, only the ones that are direct children of this node. + * + * @return the number of signatures to the primary user id + */ + virtual QString getSignCount() const; + /** + * @brief Creates a copy of the KgpgKey that belongs to this class + */ + virtual KgpgCore::KgpgKey *copyKey() const; + /** + * @brief Replaces the current key information with the new one. + * All sub-items (i.e. signatures, user ids ...) will be deleted. This must + * only be used when the id of both new and old key is the same. + */ + void setKey(const KgpgCore::KgpgKey &key); + /** + * @brief Returns a reference to the key used in this object. + * This allows direct access to the values of the key e.g. for KgpgKeyInfo. + */ + const KgpgCore::KgpgKey *getKey() const; + + /** + * @brief Returns the size of the signing key. + * @return signing key size in bits + */ + virtual unsigned int getSignKeySize() const; + /** + * @brief Returns the size of the first encryption subkey. + * @return encryption key size in bits + */ + virtual unsigned int getEncryptionKeySize() const; + /** + * @brief Notify this key that a KGpgRefNode now references this key. + * @param node object that takes the reference + */ + void addRef(KGpgRefNode *node); + /** + * @brief Remove a reference to this object + * @param node node that no longer has the reference + * + * Note that this must not be called as reply when this object + * emits updated(NULL) + */ + void delRef(KGpgRefNode *node); + /** + * @brief returns a list of all groups this key is member of + */ + QList getGroups(void) const; + /** + * @brief returns a list of all group member nodes that reference this key + */ + QList getGroupRefs(void) const; + /** + * @brief returns a list of all sign nodes that reference this key + */ + KGpgSignNode::List getSignRefs(void) const; + /** + * @brief returns a list of signatures to this key + * @param subkeys if signatures on subkeys should be included + */ + KGpgSignNode::List getSignatures(const bool subkeys) const; + /** + * @brief get the user id or user attribute with the given number + * @param index the index of the user id to return + * @return the requested subitem or NULL if that is not present + * + * User ids indexes are 1-based, so 0 is not a valid index. Passing + * 1 as index will return the object itself, representing the primary + * user id. + */ + const KGpgSignableNode *getUid(const unsigned int index) const; + + /** + * @brief compare the id of this node to the given other node + * @param other key id to compare to + * @return if ids are identical + * + * This handles different length of the id string. + */ + bool compareId(const QString &other) const; +Q_SIGNALS: + void expanded(); + +public slots: + /** + * @brief read all subitems + * + * This will read in all subitems (e.g. subkeys, signatures). When + * this is done the expanded() signal is emitted. The signal is emitted + * immediately if the key has been expanded before. + * + * This will not update the child items in case they are already present. + * Use KGpgItemModel::refreshKey() instead. + */ + void expand(); +}; + +#endif /* KGPGKEYNODE_H */ diff --git a/kgpg/core/KGpgNode.cpp b/kgpg/core/KGpgNode.cpp new file mode 100644 index 0000000..18645f8 --- /dev/null +++ b/kgpg/core/KGpgNode.cpp @@ -0,0 +1,337 @@ +/* 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 tr("Name of uid (comment) %1 (%2)").arg(getName()).arg(getComment()); + //return QString("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 "KGpgNode.moc" diff --git a/kgpg/core/KGpgNode.h b/kgpg/core/KGpgNode.h new file mode 100644 index 0000000..1d89875 --- /dev/null +++ b/kgpg/core/KGpgNode.h @@ -0,0 +1,156 @@ +/* Copyright 2008,2009 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 . + */ +#ifndef KGPGNODE_H +#define KGPGNODE_H + +#include +#include "kgpgkey.h" + +class KGpgExpandableNode; +class KGpgKeyNode; +class KGpgRootNode; +class KGpgUidNode; +class KGpgSignableNode; +class KGpgSubkeyNode; +class KGpgUatNode; +class KGpgGroupNode; +class KGpgRefNode; +class KGpgGroupMemberNode; +class KGpgSignNode; +class KGpgOrphanNode; +class KGpgItemModel; + +/** + * @brief The abstract base class for all classes representing keyring data + */ +class KGpgNode : public QObject +{ + Q_OBJECT + + friend class KGpgItemModel; + + KGpgNode(); // = delete C++0x +protected: + KGpgExpandableNode *m_parent; + KGpgItemModel *m_model; + + /** + * constructor + * @param parent the parent node in item hierarchy + */ + explicit KGpgNode(KGpgExpandableNode *parent); + +public: + typedef QList List; + + /** + * destructor + */ + virtual ~KGpgNode(); + + /** + * Returns if this node has child nodes + * + * This may be reimplemented by child classes so they can indicate that + * there are child nodes before actually loading them. + */ + virtual bool hasChildren() const; + /** + * Return how many child nodes exist + * + * When the child nodes do not already exist this will create them. + * This is the reason why this method is not const. + */ + virtual int getChildCount(); + /** + * Returns the child node at the given index + * @param index child index + * + * index may be in range 0 to getChildCount() - 1. + */ + virtual KGpgNode *getChild(const int index) const; + /** + * Returns the index for a given child node + * @return -1 if the given node is not a child of this object + */ + virtual int getChildIndex(KGpgNode *node) const; + + /** + * Returns the item type of this object + * + * Since every subclass returns a distinct value you can use the + * result of this function to decide which cast to take. Note that + * there are subclasses (KGpgKeyNode, KGpgGroupMemberNode) that + * can return two different values. + */ + virtual KgpgCore::KgpgItemType getType() const = 0; + virtual KgpgCore::KgpgKeyTrust getTrust() const; + /** + * Returns a string describing the size of this object + * + * Subclasses may return a value that makes sense for whatever + * object they represent. + * + * The default implementation returns an empty string. + */ + virtual QString getSize() const; + virtual QString getName() const; + virtual QString getEmail() const; + virtual QDateTime getExpiration() const; + virtual QDateTime getCreation() const; + virtual QString getId() const; + virtual QString getComment() const; + virtual QString getNameComment() const; + /** + * Returns the parent node in the key hierarchy + * + * For all "primary" items like keys and key groups this will + * return the (invisible) root node. Calling this function for + * the root node will return %NULL. No other node but the root + * node has a %NULL parent. + */ + KGpgExpandableNode *getParentKeyNode() const; + + KGpgExpandableNode *toExpandableNode(); + const KGpgExpandableNode *toExpandableNode() const; + KGpgSignableNode *toSignableNode(); + const KGpgSignableNode *toSignableNode() const; + KGpgKeyNode *toKeyNode(); + const KGpgKeyNode *toKeyNode() const; + KGpgRootNode *toRootNode(); + const KGpgRootNode *toRootNode() const; + KGpgUidNode *toUidNode(); + const KGpgUidNode *toUidNode() const; + KGpgSubkeyNode *toSubkeyNode(); + const KGpgSubkeyNode *toSubkeyNode() const; + KGpgUatNode *toUatNode(); + const KGpgUatNode *toUatNode() const; + KGpgGroupNode *toGroupNode(); + const KGpgGroupNode *toGroupNode() const; + KGpgRefNode *toRefNode(); + const KGpgRefNode *toRefNode() const; + KGpgGroupMemberNode *toGroupMemberNode(); + const KGpgGroupMemberNode *toGroupMemberNode() const; + KGpgSignNode *toSignNode(); + const KGpgSignNode *toSignNode() const; + KGpgOrphanNode *toOrphanNode(); + const KGpgOrphanNode *toOrphanNode() const; +}; + +#endif /* KGPGNODE_H */ diff --git a/kgpg/core/KGpgOrphanNode.cpp b/kgpg/core/KGpgOrphanNode.cpp new file mode 100644 index 0000000..f245121 --- /dev/null +++ b/kgpg/core/KGpgOrphanNode.cpp @@ -0,0 +1,84 @@ +/* Copyright 2008,2009,2010,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 "KGpgOrphanNode.h" + +KGpgOrphanNode::KGpgOrphanNode(KGpgExpandableNode *parent, const KgpgKey &k) + : KGpgNode(parent), + m_key(new KgpgKey(k)) +{ +} + +KGpgOrphanNode::~KGpgOrphanNode() +{ + delete m_key; +} + +KgpgItemType +KGpgOrphanNode::getType() const +{ + return ITYPE_SECRET; +} + +QString +KGpgOrphanNode::getName() const +{ + return m_key->name(); +} + +QString +KGpgOrphanNode::getEmail() const +{ + return m_key->email(); +} + +QString +KGpgOrphanNode::getSize() const +{ + return QString::number(m_key->size()); +} + +QDateTime +KGpgOrphanNode::getExpiration() const +{ + return m_key->expirationDate(); +} + +QDateTime +KGpgOrphanNode::getCreation() const +{ + return m_key->creationDate(); +} + +QString +KGpgOrphanNode::getId() const +{ + return m_key->fullId(); +} + +KgpgCore::KgpgKeyTrust +KGpgOrphanNode::getTrust() const +{ + return m_key->trust(); +} + +const QString & +KGpgOrphanNode::getFingerprint() const +{ + return m_key->fingerprint(); +} diff --git a/kgpg/core/KGpgOrphanNode.h b/kgpg/core/KGpgOrphanNode.h new file mode 100644 index 0000000..e3b6132 --- /dev/null +++ b/kgpg/core/KGpgOrphanNode.h @@ -0,0 +1,53 @@ +/* Copyright 2008,2009,2010,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 . + */ +#ifndef KGPGORPHANNODE_H +#define KGPGORPHANNODE_H + +#include "KGpgNode.h" + +#include "kgpgkey.h" + +using namespace KgpgCore; + +class KGpgExpandableNode; + +/** + * @brief A lone secret key without public key + */ +class KGpgOrphanNode : public KGpgNode +{ +private: + KgpgCore::KgpgKey *m_key; + +public: + explicit KGpgOrphanNode(KGpgExpandableNode *parent, const KgpgKey &k); + virtual ~KGpgOrphanNode(); + + virtual KgpgCore::KgpgItemType getType() const; + virtual KgpgCore::KgpgKeyTrust getTrust() const; + const QString &getFingerprint() const; + virtual QString getSize() const; + virtual QString getName() const; + virtual QString getEmail() const; + virtual QDateTime getExpiration() const; + virtual QDateTime getCreation() const; + virtual QString getId() const; +}; + +#endif /* KGPGORPHANNODE_H */ diff --git a/kgpg/core/KGpgRefNode.cpp b/kgpg/core/KGpgRefNode.cpp new file mode 100644 index 0000000..a67d6b5 --- /dev/null +++ b/kgpg/core/KGpgRefNode.cpp @@ -0,0 +1,151 @@ +/* Copyright 2008,2009 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 "KGpgRefNode.h" + +//#include + +#include "KGpgExpandableNode.h" +#include "KGpgRootNode.h" + +KGpgRefNode::KGpgRefNode(KGpgExpandableNode *parent, const QString &keyid) + : KGpgNode(parent), + m_id(keyid) +{ + Q_ASSERT(!keyid.isEmpty()); + + KGpgRootNode *root = getRootNode(); + KGpgExpandableNode *pnd = parent; + + do { + m_selfsig = (pnd->getId().right(keyid.length()) == keyid); + if (m_selfsig) + m_keynode = pnd->toKeyNode(); + else + pnd = pnd->getParentKeyNode(); + } while (!m_selfsig && (pnd != root)); + + // Self signatures do net need to get notified by their key: if the key is changed + // the key node is deleted, then those refnode would be deleted anyway. This avoids + // crashes when they would try to find the root node by iterating over their parent + // when the parents destructor is already called (see bug 208659). + if (!m_selfsig) { + m_keynode = root->findKey(keyid); + + if (m_keynode != NULL) { + m_keynode->addRef(this); + } else { + connect(root, SIGNAL(newKeyNode(KGpgKeyNode*)), this, SLOT(keyUpdated(KGpgKeyNode*))); + } + } + + parent->children.append(this); +} + +KGpgRefNode::KGpgRefNode(KGpgExpandableNode *parent, KGpgKeyNode *key) + : KGpgNode(parent), + m_id(key->getId()), + m_keynode(key) +{ + Q_ASSERT(key != NULL); + Q_ASSERT(parent != NULL); + m_keynode->addRef(this); + + parent->children.append(this); +} + +KGpgRefNode::~KGpgRefNode() +{ + if (m_keynode && !m_selfsig) + m_keynode->delRef(this); +} + +KGpgRootNode * +KGpgRefNode::getRootNode() const +{ + KGpgExpandableNode *root; + KGpgExpandableNode *pt = m_parent; + + do { + root = pt; + pt = pt->getParentKeyNode(); + } while (pt != NULL); + + return root->toRootNode(); +} + +void +KGpgRefNode::keyUpdated(KGpgKeyNode *nkey) +{ + Q_ASSERT(m_keynode == NULL); + Q_ASSERT(nkey != NULL); + + if (nkey->getId().right(m_id.length()) == m_id) { + disconnect(sender(), NULL, this, SLOT(keyUpdated(KGpgKeyNode*))); + m_keynode = nkey; + m_keynode->addRef(this); + } +} + +void +KGpgRefNode::unRef(KGpgRootNode *root) +{ + if (root != NULL) + connect(root, SIGNAL(newKeyNode(KGpgKeyNode*)), this, SLOT(keyUpdated(KGpgKeyNode*))); + + m_keynode = NULL; +} + +QString +KGpgRefNode::getId() const +{ + if (m_keynode != NULL) + return m_keynode->getId(); + else + return m_id; +} + +QString +KGpgRefNode::getName() const +{ + if (m_keynode != NULL) + return m_keynode->getName(); + return tr("[No user id found]"); +} + +QString +KGpgRefNode::getEmail() const +{ + if (m_keynode != NULL) + return m_keynode->getEmail(); + return QString(); +} + +bool +KGpgRefNode::isUnknown() const +{ + return (m_keynode == NULL); +} + +KGpgKeyNode * +KGpgRefNode::getRefNode() const +{ + return m_keynode; +} + +//#include "KGpgRefNode.moc" diff --git a/kgpg/core/KGpgRefNode.h b/kgpg/core/KGpgRefNode.h new file mode 100644 index 0000000..f977567 --- /dev/null +++ b/kgpg/core/KGpgRefNode.h @@ -0,0 +1,98 @@ +/* Copyright 2008,2009 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 . + */ +#ifndef KGPGREFNODE_H +#define KGPGREFNODE_H + +#include "KGpgNode.h" + +class KGpgKeyNode; +class KGpgRootNode; + +/** + * @brief Class for child objects that are only a reference to a primary key + * + * This is the base class for all type of objects that match these criteria: + * -they can not have child objects + * -they are only a reference to a primary key (which needs not to be in the + * key ring) + * + * Do not create instances from this class. Use KGpgGroupMemberNode and + * KGpgSignNode as those represent the existing objects. This class exists + * only to get the hierarchy right. + */ +class KGpgRefNode : public KGpgNode +{ + Q_OBJECT + +private: + const QString m_id; + bool m_selfsig; ///< if this is a reference to it's own parent + +protected: + KGpgKeyNode *m_keynode; + + explicit KGpgRefNode(KGpgExpandableNode *parent, KGpgKeyNode *key); + explicit KGpgRefNode(KGpgExpandableNode *parent, const QString &keyid); + + KGpgRootNode *getRootNode() const; + +public: + virtual ~KGpgRefNode(); + + virtual QString getId() const; + virtual QString getName() const; + virtual QString getEmail() const; + /** + * Get the node of the primary key this node references to + * + * This will return the key node of the primary key this node + * references. This may be %NULL if the primary key is not in the key + * ring, e.g. if this is a signature of an unknown key. + * + * @return the node of the primary key or %NULL + */ + virtual KGpgKeyNode *getRefNode() const; + + /** + * Check if the referenced key exists + * + * @return if getRefNode() will return %NULL or not + */ + bool isUnknown() const; + + /** + * Break the current reference + * @param root root node + * + * This is called when the referenced node is going away. + * + * The root node is passed for two reasons: + * @li it doesn't need to be searched again for every ref node which + * can be many in case of an important key node get's deleted + * @li the ref node may be a child of the deleted node, then we can + * not call the parents functions to find the root anymore. This helps + * simplifying the code + */ + void unRef(KGpgRootNode *root); + +private Q_SLOTS: + void keyUpdated(KGpgKeyNode *); +}; + +#endif /* KGPGREFNODE_H */ diff --git a/kgpg/core/KGpgRootNode.cpp b/kgpg/core/KGpgRootNode.cpp new file mode 100644 index 0000000..9ceb571 --- /dev/null +++ b/kgpg/core/KGpgRootNode.cpp @@ -0,0 +1,189 @@ +/* Copyright 2008,2009,2010,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 "KGpgRootNode.h" + +#include "KGpgGroupNode.h" +#include "../kgpginterface.h" +#include "KGpgOrphanNode.h" +//#include "kgpgsettings.h" + +#include +#include + +KGpgRootNode::KGpgRootNode(KGpgItemModel *model) + : KGpgExpandableNode(NULL), + m_groups(0), + m_deleting(false) +{ + m_model = model; +} + +KGpgRootNode::~KGpgRootNode() +{ + m_deleting = true; +} + +void +KGpgRootNode::readChildren() +{ +} + +KgpgCore::KgpgItemType +KGpgRootNode::getType() const +{ + return 0; +} + +void +KGpgRootNode::addGroups(const QStringList &groups) +{ + foreach (const QString &group, groups) { + QStringList members = group.split(QLatin1Char(' ')); + const QString groupName = members.takeFirst(); + new KGpgGroupNode(this, groupName, members); + } +} + +void +KGpgRootNode::addKeys(const QStringList &ids) +{ + KgpgCore::KgpgKeyList publiclist = KgpgInterface::readPublicKeys(ids); + KgpgCore::KgpgKeyList secretlist = KgpgInterface::readSecretKeys(); + + QStringList issec = secretlist; + + for (int i = 0; i < publiclist.size(); ++i) { + KgpgCore::KgpgKey key = publiclist.at(i); + + int index = issec.indexOf(key.fullId()); + if (index != -1) { + key.setSecret(true); + issec.removeAt(index); + secretlist.removeAt(index); + } + + KGpgKeyNode *nd = new KGpgKeyNode(this, key); + emit newKeyNode(nd); + } + + for (int i = 0; i < secretlist.count(); ++i) { + KgpgCore::KgpgKey key = secretlist.at(i); + + new KGpgOrphanNode(this, key); + } +} + +void +KGpgRootNode::refreshKeys(KGpgKeyNode::List nodes) +{ + QStringList ids; + + foreach (const KGpgNode *nd, nodes) + ids << nd->getId(); + + KgpgCore::KgpgKeyList publiclist = KgpgInterface::readPublicKeys(ids); + QStringList issec = KgpgInterface::readSecretKeys(ids); + + for (int i = 0; i < publiclist.size(); ++i) { + KgpgCore::KgpgKey key = publiclist.at(i); + + int index = issec.indexOf(key.fullId()); + if (index != -1) { + key.setSecret(true); + issec.removeAt(index); + } + + for (int j = 0; j < nodes.count(); j++) { + KGpgKeyNode *nd = nodes.at(j); + + if (nd->getId() == key.fingerprint()) { + nodes.removeAt(j); + nd->setKey(key); + break; + } + } + } +} + +KGpgKeyNode * +KGpgRootNode::findKey(const QString &keyId) +{ + int i = findKeyRow(keyId); + if (i >= 0) { + return children[i]->toKeyNode(); + } + + return NULL; +} + +int +KGpgRootNode::findKeyRow(const QString &keyId) +{ + int i = 0; + + foreach (const KGpgNode *node, children) { + if ((node->getType() & ITYPE_PAIR) == 0) { + ++i; + continue; + } + + const KGpgKeyNode *key = node->toKeyNode(); + + if (key->compareId(keyId)) + return i; + ++i; + } + return -1; +} + +int +KGpgRootNode::groupChildren() const +{ + return m_groups; +} + +int +KGpgRootNode::findKeyRow(const KGpgKeyNode *key) +{ + for (int i = 0; i < children.count(); i++) { + if (children[i] == key) + return i; + } + return -1; +} + +KGpgRootNode * +KGpgRootNode::asRootNode() +{ + if (m_deleting) + return NULL; + + return this; +} + +const KGpgRootNode * +KGpgRootNode::asRootNode() const +{ + if (m_deleting) + return NULL; + + return this; +} + +//#include "KGpgRootNode.moc" diff --git a/kgpg/core/KGpgRootNode.h b/kgpg/core/KGpgRootNode.h new file mode 100644 index 0000000..97c597c --- /dev/null +++ b/kgpg/core/KGpgRootNode.h @@ -0,0 +1,129 @@ +/* Copyright 2008,2009 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 . + */ +#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 */ diff --git a/kgpg/core/KGpgSignNode.cpp b/kgpg/core/KGpgSignNode.cpp new file mode 100644 index 0000000..f35bd9a --- /dev/null +++ b/kgpg/core/KGpgSignNode.cpp @@ -0,0 +1,95 @@ +/* Copyright 2008,2009,2010 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 "KGpgSignNode.h" + +#include "KGpgSignableNode.h" + +//#include +#include + +class KGpgSignNodePrivate { +public: + KGpgSignNodePrivate(const QStringList &sl); + + QDateTime m_creation; + QDateTime m_expiration; + bool m_local; + bool m_revocation; +}; + +KGpgSignNodePrivate::KGpgSignNodePrivate(const QStringList &sl) +{ + m_revocation = (sl.at(0) == QLatin1String("rev")); + if (sl.count() < 6) + return; + m_creation = QDateTime::fromTime_t(sl.at(5).toUInt()); + if (sl.count() < 7) + return; + if (!sl.at(6).isEmpty()) + m_expiration = QDateTime::fromTime_t(sl.at(6).toUInt()); + if (sl.count() < 11) + return; + m_local = sl.at(10).endsWith(QLatin1Char( 'l' )); +} + +KGpgSignNode::KGpgSignNode(KGpgSignableNode *parent, const QStringList &s) + : KGpgRefNode(parent, s.at(4)), + d_ptr(new KGpgSignNodePrivate(s)) +{ +} + +KGpgSignNode::~KGpgSignNode() +{ + delete d_ptr; +} + +QDateTime +KGpgSignNode::getExpiration() const +{ + const Q_D(KGpgSignNode); + + return d->m_expiration; +} + +QDateTime +KGpgSignNode::getCreation() const +{ + const Q_D(KGpgSignNode); + + return d->m_creation; +} + +QString +KGpgSignNode::getName() const +{ + const Q_D(KGpgSignNode); + const QString name = KGpgRefNode::getName(); + + if (!d->m_local) + return name; + + //return tr("%1 [local signature]", &name.constData()->toAscii()); + return "fixme"; +} + +KgpgCore::KgpgItemType +KGpgSignNode::getType() const +{ + return KgpgCore::ITYPE_SIGN; +} diff --git a/kgpg/core/KGpgSignNode.h b/kgpg/core/KGpgSignNode.h new file mode 100644 index 0000000..398ee57 --- /dev/null +++ b/kgpg/core/KGpgSignNode.h @@ -0,0 +1,54 @@ +/* Copyright 2008,2009,2010 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 . + */ +#ifndef KGPGSIGNNODE_H +#define KGPGSIGNNODE_H + +#include "KGpgRefNode.h" + +class KGpgSignableNode; + +class KGpgSignNodePrivate; + +/** + * @brief A signature to another key object + */ +class KGpgSignNode : public KGpgRefNode +{ +private: + KGpgSignNodePrivate * const d_ptr; + Q_DECLARE_PRIVATE(KGpgSignNode) + +public: + typedef QList List; + + /** + * @brief constructor for KGpgSignNode + * @param parent the signed node + * @param s GnuPG line describing this signature + */ + explicit KGpgSignNode(KGpgSignableNode *parent, const QStringList &s); + virtual ~KGpgSignNode(); + + virtual KgpgCore::KgpgItemType getType() const; + virtual QDateTime getExpiration() const; + virtual QString getName() const; + virtual QDateTime getCreation() const; +}; + +#endif /* KGPGSIGNNODE_H */ diff --git a/kgpg/core/KGpgSignableNode.cpp b/kgpg/core/KGpgSignableNode.cpp new file mode 100644 index 0000000..e3782c1 --- /dev/null +++ b/kgpg/core/KGpgSignableNode.cpp @@ -0,0 +1,99 @@ +/* Copyright 2008,2009 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 "KGpgSignableNode.h" + +//#include + +KGpgSignableNode::KGpgSignableNode(KGpgExpandableNode *parent) + : KGpgExpandableNode(parent) +{ +} + +KGpgSignableNode::~KGpgSignableNode() +{ +} + +KGpgSignNode::List +KGpgSignableNode::getSignatures(void) const +{ + KGpgSignNode::List ret; + + foreach (KGpgNode *kn, children) { + if (kn->getType() == KgpgCore::ITYPE_SIGN) + ret << kn->toSignNode(); + } + + return ret; +} + +QString +KGpgSignableNode::getSignCount() const +{ + //return i18np("1 signature", "%1 signatures", children.count()); + return tr("1 signature", "%1 signatures", children.count()); +} + +bool +KGpgSignableNode::operator<(const KGpgSignableNode &other) const +{ + return operator<(&other); +} + +bool +KGpgSignableNode::operator<(const KGpgSignableNode *other) const +{ + switch (getType()) { + case KgpgCore::ITYPE_PUBLIC: + case KgpgCore::ITYPE_PAIR: { + const QString myid(getId()); + + switch (other->getType()) { + case KgpgCore::ITYPE_PUBLIC: + case KgpgCore::ITYPE_PAIR: + return (myid < other->getId()); + default: { + const QString otherid(other->getParentKeyNode()->getId()); + + if (myid == otherid) + return true; + return (myid < otherid); + } + } + } + default: { + const QString myp(getParentKeyNode()->getId()); + + switch (other->getType()) { + case KgpgCore::ITYPE_PAIR: + case KgpgCore::ITYPE_PUBLIC: + return (myp < other->getId()); + default: { + const QString otherp(other->getParentKeyNode()->getId()); + + if (otherp == myp) + return (getId().toInt() < other->getId().toInt()); + + return (myp < otherp); + } + } + } + } +} + +//#include "KGpgSignableNode.moc" diff --git a/kgpg/core/KGpgSignableNode.h b/kgpg/core/KGpgSignableNode.h new file mode 100644 index 0000000..fddae25 --- /dev/null +++ b/kgpg/core/KGpgSignableNode.h @@ -0,0 +1,62 @@ +/* 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 . + */ +#ifndef KGPGSIGNABLENODE_H +#define KGPGSIGNABLENODE_H + +#include "KGpgExpandableNode.h" +#include "KGpgSignNode.h" + +/** + * @brief An object that may have KGpgSignNode children + * + * This class represents an object that may be signed, i.e. key nodes, + * user ids, user attributes, and subkeys. + */ +class KGpgSignableNode : public KGpgExpandableNode +{ + Q_OBJECT + +public: + typedef QList List; + typedef QList const_List; + + KGpgSignableNode(KGpgExpandableNode *parent = NULL); + virtual ~KGpgSignableNode(); + + KGpgSignNode::List getSignatures(void) const; + /** + * @brief count signatures + * @return the number of signatures to this object + * + * This does not include the number of signatures to child objects. + */ + virtual QString getSignCount() const; + + bool operator<(const KGpgSignableNode &other) const; + bool operator<(const KGpgSignableNode *other) const; + + /** + * @brief returns the key node this node belongs to + * @returns this node if the node itself is a key or it's parent otherwise + */ + virtual KGpgKeyNode *getKeyNode(void) = 0; + virtual const KGpgKeyNode *getKeyNode(void) const = 0; +}; + +#endif /* KGPGSIGNABLENODE_H */ diff --git a/kgpg/core/KGpgSubkeyNode.cpp b/kgpg/core/KGpgSubkeyNode.cpp new file mode 100644 index 0000000..571ca35 --- /dev/null +++ b/kgpg/core/KGpgSubkeyNode.cpp @@ -0,0 +1,100 @@ +/* Copyright 2008,2009 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 "KGpgSubkeyNode.h" + +//#include + +#include "convert.h" +#include "KGpgKeyNode.h" + +KGpgSubkeyNode::KGpgSubkeyNode(KGpgKeyNode *parent, const KgpgKeySub &k) + : KGpgSignableNode(parent), + m_skey(k) +{ + Q_ASSERT(parent != NULL); +} +KGpgSubkeyNode::~KGpgSubkeyNode() +{ +} + +void +KGpgSubkeyNode::readChildren() +{ +} + +KgpgCore::KgpgItemType +KGpgSubkeyNode::getType() const +{ + return ITYPE_SUB; +} + +KgpgCore::KgpgKeyTrust +KGpgSubkeyNode::getTrust() const +{ + return m_skey.trust(); +} + +QDateTime +KGpgSubkeyNode::getExpiration() const +{ + return m_skey.expirationDate(); +} + +QDateTime +KGpgSubkeyNode::getCreation() const +{ + return m_skey.creationDate(); +} + +QString +KGpgSubkeyNode::getId() const +{ + return m_skey.id(); +} + +KGpgKeyNode * +KGpgSubkeyNode::getKeyNode(void) +{ + return getParentKeyNode()->toKeyNode(); +} + +const KGpgKeyNode * +KGpgSubkeyNode::getKeyNode(void) const +{ + return getParentKeyNode()->toKeyNode(); +} + +QString +KGpgSubkeyNode::getName() const +{ + //return i18n("%1 subkey", Convert::toString(m_skey.algorithm())); + return "TODO"; +} + +QString +KGpgSubkeyNode::getSize() const +{ + return QString::number(m_skey.size()); +} + +KGpgKeyNode * +KGpgSubkeyNode::getParentKeyNode() const +{ + return m_parent->toKeyNode(); +} diff --git a/kgpg/core/KGpgSubkeyNode.h b/kgpg/core/KGpgSubkeyNode.h new file mode 100644 index 0000000..bbe5ab8 --- /dev/null +++ b/kgpg/core/KGpgSubkeyNode.h @@ -0,0 +1,55 @@ +/* Copyright 2008,2009 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 . + */ +#ifndef KGPGSUBKEYNODE_H +#define KGPGSUBKEYNODE_H + +#include "KGpgSignableNode.h" + +#include "kgpgkey.h" + +using namespace KgpgCore; + +/** + * @brief a subkey of a public key or key pair + */ +class KGpgSubkeyNode : public KGpgSignableNode +{ +private: + KgpgCore::KgpgKeySub m_skey; + +protected: + virtual void readChildren(); + +public: + explicit KGpgSubkeyNode(KGpgKeyNode *parent, const KgpgCore::KgpgKeySub &k); + virtual ~KGpgSubkeyNode(); + + virtual KgpgCore::KgpgItemType getType() const; + virtual KgpgCore::KgpgKeyTrust getTrust() const; + virtual QString getSize() const; + virtual QString getName() const; + virtual QDateTime getExpiration() const; + virtual QDateTime getCreation() const; + virtual QString getId() const; + virtual KGpgKeyNode *getKeyNode(void); + virtual const KGpgKeyNode *getKeyNode(void) const; + virtual KGpgKeyNode *getParentKeyNode() const; +}; + +#endif /* KGPGSUBKEYNODE_H */ diff --git a/kgpg/core/KGpgUatNode.cpp b/kgpg/core/KGpgUatNode.cpp new file mode 100644 index 0000000..174db66 --- /dev/null +++ b/kgpg/core/KGpgUatNode.cpp @@ -0,0 +1,174 @@ +/* Copyright 2008,2009,2010,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 "KGpgUatNode.h" + +#include "../gpgproc.h" +#include "KGpgKeyNode.h" + +//#include +//#include + +#include +#include +#include +#include +#include + +class KGpgUatNodePrivate { +public: + KGpgUatNodePrivate(const KGpgKeyNode *parent, const unsigned int index, const QStringList &sl); + + const QString m_idx; + const QPixmap m_pixmap; + QDateTime m_creation; + +private: + static QPixmap loadImage(const KGpgKeyNode *parent, const QString &index); +}; + +KGpgUatNodePrivate::KGpgUatNodePrivate(const KGpgKeyNode *parent, const unsigned int index, const QStringList &sl) + : m_idx(QString::number(index)), + m_pixmap(loadImage(parent, m_idx)) +{ + if (sl.count() < 6) + return; + m_creation = QDateTime::fromTime_t(sl.at(5).toUInt()); +} + +QPixmap +KGpgUatNodePrivate::loadImage(const KGpgKeyNode *parent, const QString &index) +{ + QPixmap pixmap; +#ifdef Q_OS_WIN32 //krazy:exclude=cpp + const QString pgpgoutput = QLatin1String("cmd /C \"echo %I\""); +#else + const QString pgpgoutput = QLatin1String("echo %I"); +#endif + + GPGProc workProcess; + workProcess << + QLatin1String("--no-greeting") << + QLatin1String("--status-fd=2") << + QLatin1String("--photo-viewer") << pgpgoutput << + QLatin1String("--edit-key") << parent->getFingerprint() << + QLatin1String( "uid" ) << index << + QLatin1String( "showphoto" ) << + QLatin1String( "quit" ); + + workProcess.start(); + workProcess.waitForFinished(); + if (workProcess.exitCode() != 0) + return pixmap; + + QString tmpfile; + if (workProcess.readln(tmpfile) < 0) + return pixmap; + + QUrl url(tmpfile); + pixmap.load(url.path()); + QFile::remove(url.path()); + QDir dir; + //dir.rmdir(url.directory()); + + return pixmap; +} + +KGpgUatNode::KGpgUatNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl) + : KGpgSignableNode(parent), + d_ptr(new KGpgUatNodePrivate(parent, index, sl)) +{ +} + +KGpgUatNode::~KGpgUatNode() +{ + delete d_ptr; +} + +QString +KGpgUatNode::getName() const +{ + return tr("Photo id"); +} + +QString +KGpgUatNode::getSize() const +{ + const Q_D(KGpgUatNode); + + return QString::number(d->m_pixmap.width()) + QLatin1Char( 'x' ) + QString::number(d->m_pixmap.height()); +} + +QDateTime +KGpgUatNode::getCreation() const +{ + const Q_D(KGpgUatNode); + + return d->m_creation; +} + +KGpgKeyNode * +KGpgUatNode::getParentKeyNode() const +{ + return m_parent->toKeyNode(); +} + +void +KGpgUatNode::readChildren() +{ +} + +KgpgCore::KgpgItemType +KGpgUatNode::getType() const +{ + return KgpgCore::ITYPE_UAT; +} + +KgpgCore::KgpgKeyTrust +KGpgUatNode::getTrust() const +{ + return KgpgCore::TRUST_NOKEY; +} + +const QPixmap & +KGpgUatNode::getPixmap() const +{ + const Q_D(KGpgUatNode); + + return d->m_pixmap; +} + +QString +KGpgUatNode::getId() const +{ + const Q_D(KGpgUatNode); + + return d->m_idx; +} + +KGpgKeyNode * +KGpgUatNode::getKeyNode(void) +{ + return getParentKeyNode()->toKeyNode(); +} + +const KGpgKeyNode * +KGpgUatNode::getKeyNode(void) const +{ + return getParentKeyNode()->toKeyNode(); +} diff --git a/kgpg/core/KGpgUatNode.h b/kgpg/core/KGpgUatNode.h new file mode 100644 index 0000000..b4c6775 --- /dev/null +++ b/kgpg/core/KGpgUatNode.h @@ -0,0 +1,61 @@ +/* Copyright 2008,2009,2010 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 . + */ +#ifndef KGPGUATNODE_H +#define KGPGUATNODE_H + +#include "KGpgSignableNode.h" + +#include +#include + +class KGpgExpandableNode; +class KGpgKeyNode; +class QPixmap; + +class KGpgUatNodePrivate; + +/** + * @brief A user attribute (i.e. photo id) of a public key or key pair + */ +class KGpgUatNode : public KGpgSignableNode +{ +private: + KGpgUatNodePrivate * const d_ptr; + Q_DECLARE_PRIVATE(KGpgUatNode) + +protected: + virtual void readChildren(); + +public: + explicit KGpgUatNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl); + virtual ~KGpgUatNode(); + + virtual KgpgCore::KgpgItemType getType() const; + virtual KgpgCore::KgpgKeyTrust getTrust() const; + const QPixmap &getPixmap() const; + virtual QString getId() const; + virtual QString getSize() const; + virtual QString getName() const; + virtual QDateTime getCreation() const; + virtual KGpgKeyNode *getParentKeyNode() const; + virtual KGpgKeyNode *getKeyNode(void); + virtual const KGpgKeyNode *getKeyNode(void) const; +}; + +#endif /* KGPGUATNODE_H */ diff --git a/kgpg/core/KGpgUidNode.cpp b/kgpg/core/KGpgUidNode.cpp new file mode 100644 index 0000000..0be6c10 --- /dev/null +++ b/kgpg/core/KGpgUidNode.cpp @@ -0,0 +1,146 @@ +/* Copyright 2008,2009,2010 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 "KGpgUidNode.h" + +#include "KGpgKeyNode.h" +#include "convert.h" + +class KGpgUidNodePrivate { +public: + KGpgUidNodePrivate(const unsigned int index, const QStringList &sl); + + const QString m_index; + QString m_email; + QString m_name; + QString m_comment; + KgpgCore::KgpgKeyTrust m_trust; + bool m_valid; +}; + +KGpgUidNodePrivate::KGpgUidNodePrivate(const unsigned int index, const QStringList &sl) + : m_index(QString::number(index)) +{ + QString fullname(sl.at(9)); + if (fullname.contains(QLatin1Char( '<' )) ) { + m_email = fullname; + + if (fullname.contains(QLatin1Char( ')' )) ) + m_email = m_email.section(QLatin1Char( ')' ), 1); + + m_email = m_email.section(QLatin1Char( '<' ), 1); + m_email.truncate(m_email.length() - 1); + + if (m_email.contains(QLatin1Char( '<' ))) { + // several email addresses in the same key + m_email = m_email.replace(QLatin1Char( '>' ), QLatin1Char( ';' )); + m_email.remove(QLatin1Char( '<' )); + } + } + + m_name = fullname.section(QLatin1String( " <" ), 0, 0); + if (fullname.contains(QLatin1Char( '(' )) ) { + m_name = m_name.section(QLatin1String( " (" ), 0, 0); + m_comment = fullname.section(QLatin1Char( '(' ), 1, 1); + m_comment = m_comment.section(QLatin1Char( ')' ), 0, 0); + } + + m_trust = KgpgCore::Convert::toTrust(sl.at(1)); + m_valid = ((sl.count() <= 11) || !sl.at(11).contains(QLatin1Char( 'D' ))); +} + + +KGpgUidNode::KGpgUidNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl) + : KGpgSignableNode(parent), + d_ptr(new KGpgUidNodePrivate(index, sl)) +{ +} + +KGpgUidNode::~KGpgUidNode() +{ + delete d_ptr; +} + +QString +KGpgUidNode::getName() const +{ + const Q_D(KGpgUidNode); + + return d->m_name; +} + +QString +KGpgUidNode::getEmail() const +{ + const Q_D(KGpgUidNode); + + return d->m_email; +} + +QString +KGpgUidNode::getId() const +{ + const Q_D(KGpgUidNode); + + return d->m_index; +} + +KGpgKeyNode * +KGpgUidNode::getKeyNode(void) +{ + return getParentKeyNode()->toKeyNode(); +} + +const KGpgKeyNode * +KGpgUidNode::getKeyNode(void) const +{ + return getParentKeyNode()->toKeyNode(); +} + +KGpgKeyNode * +KGpgUidNode::getParentKeyNode() const +{ + return m_parent->toKeyNode(); +} + +void +KGpgUidNode::readChildren() +{ +} + +KgpgCore::KgpgItemType +KGpgUidNode::getType() const +{ + return KgpgCore::ITYPE_UID; +} + +KgpgCore::KgpgKeyTrust +KGpgUidNode::getTrust() const +{ + const Q_D(KGpgUidNode); + + return d->m_trust; +} + +QString +KGpgUidNode::getComment() const +{ + const Q_D(KGpgUidNode); + + return d->m_comment; +} diff --git a/kgpg/core/KGpgUidNode.h b/kgpg/core/KGpgUidNode.h new file mode 100644 index 0000000..cd1b563 --- /dev/null +++ b/kgpg/core/KGpgUidNode.h @@ -0,0 +1,57 @@ +/* Copyright 2008,2009,2010 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 . + */ +#ifndef KGPGUIDNODE_H +#define KGPGUIDNODE_H + +#include "KGpgSignableNode.h" + +#include "kgpgkey.h" + +class KGpgKeyNode; + +class KGpgUidNodePrivate; + +/** + * @brief A user id of a public key or key pair + */ +class KGpgUidNode : public KGpgSignableNode +{ +private: + KGpgUidNodePrivate * const d_ptr; + Q_DECLARE_PRIVATE(KGpgUidNode) + +protected: + virtual void readChildren(); + +public: + explicit KGpgUidNode(KGpgKeyNode *parent, const unsigned int index, const QStringList &sl); + virtual ~KGpgUidNode(); + + virtual KgpgCore::KgpgItemType getType() const; + virtual KgpgCore::KgpgKeyTrust getTrust() const; + virtual QString getName() const; + virtual QString getEmail() const; + virtual QString getId() const; + virtual KGpgKeyNode *getKeyNode(void); + virtual const KGpgKeyNode *getKeyNode(void) const; + virtual KGpgKeyNode *getParentKeyNode() const; + virtual QString getComment() const; +}; + +#endif /* KGPGUIDNODE_H */ diff --git a/kgpg/core/convert.cpp b/kgpg/core/convert.cpp new file mode 100644 index 0000000..934ec02 --- /dev/null +++ b/kgpg/core/convert.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2006 Jimmy Gilles + * Copyright (C) 2010 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) any later version. * + * * + * 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "convert.h" + +//#include +//#include +#include +//#include "kgpgsettings.h" +#include "images.h" + +namespace KgpgCore +{ + +QString Convert::toString(const KgpgKeyAlgo algorithm) +{ + switch (algorithm) + { + case ALGO_RSA: return QObject::tr("Encryption algorithm", "RSA"); + case ALGO_DSA: return QObject::tr("Encryption algorithm", "DSA"); + case ALGO_ELGAMAL: return QObject::tr("Encryption algorithm", "ElGamal"); + case ALGO_DSA_ELGAMAL: return QObject::tr("Encryption algorithm", "DSA & ElGamal"); + case ALGO_RSA_RSA: return QObject::tr("Encryption algorithm RSA, Signing algorithm RSA", "RSA & RSA"); + case ALGO_UNKNOWN: + default: return QObject::tr("Unknown algorithm", "Unknown"); + } +} + +QString Convert::toString(const KgpgKeyOwnerTrust ownertrust) +{ + switch (ownertrust) + { + case OWTRUST_UNDEFINED: return QObject::tr("Do not Know"); + case OWTRUST_NONE: return QObject::tr("Do NOT Trust"); + case OWTRUST_MARGINAL: return QObject::tr("Marginally"); + case OWTRUST_FULL: return QObject::tr("Fully"); + case OWTRUST_ULTIMATE: return QObject::tr("Ultimately"); + case OWTRUST_UNKNOWN: + default: return QObject::tr("Unknown trust in key owner", "Unknown"); + } +} + +QString Convert::toString(const KgpgKeyTrust trust) +{ + switch (trust) + { + case TRUST_INVALID: return QObject::tr("Invalid key", "Invalid"); + case TRUST_DISABLED: return QObject::tr("Disabled key", "Disabled"); + case TRUST_REVOKED: return QObject::tr("Revoked"); + case TRUST_EXPIRED: return QObject::tr("Expired key", "Expired"); + case TRUST_UNDEFINED: return QObject::tr("Undefined key trust", "Undefined"); + case TRUST_NONE: return QObject::tr("No trust in key", "None"); + case TRUST_MARGINAL: return QObject::tr("Marginal trust in key", "Marginal"); + case TRUST_FULL: return QObject::tr("Full trust in key", "Full"); + case TRUST_ULTIMATE: return QObject::tr("Ultimate trust in key", "Ultimate"); + case TRUST_UNKNOWN: + default: return QObject::tr("Unknown trust in key", "Unknown"); + } +} + +QColor Convert::toColor(const KgpgKeyTrust trust) +{ + switch (trust) + { + case TRUST_INVALID: + /*case TRUST_DISABLED: return KGpgSettings::colorBad(); + case TRUST_EXPIRED: return KGpgSettings::colorExpired(); + case TRUST_MARGINAL: return KGpgSettings::colorMarginal(); + case TRUST_REVOKED: return KGpgSettings::colorRev(); + case TRUST_UNDEFINED: + case TRUST_NONE: return KGpgSettings::colorUnknown(); + case TRUST_FULL: return KGpgSettings::colorGood(); + case TRUST_ULTIMATE: return KGpgSettings::colorUltimate();*/ + case TRUST_UNKNOWN: + default: return QColor(0,0,0); + //return KGpgSettings::colorUnknown(); + } +} + +QString Convert::toString(const QDate &date) +{ + //return KGlobal::locale()->formatDate(date, KLocale::ShortDate); +} + +KgpgKeyAlgo Convert::toAlgo(const uint v) +{ + switch (v) + { + case 1: return ALGO_RSA; + case 16: + case 20: return ALGO_ELGAMAL; + case 17: return ALGO_DSA; + default: return ALGO_UNKNOWN; + } +} + +KgpgKeyAlgo Convert::toAlgo(const QString &s) +{ + bool b; + unsigned int u = s.toUInt(&b); + return b ? toAlgo(u) : ALGO_UNKNOWN; +} + +KgpgKeyTrust Convert::toTrust(const QChar &c) +{ + switch (c.toAscii()) + { + case 'o': return TRUST_UNKNOWN; + case 'i': return TRUST_INVALID; + case 'd': return TRUST_DISABLED; + case 'r': return TRUST_REVOKED; + case 'e': return TRUST_EXPIRED; + case 'q': return TRUST_UNDEFINED; + case 'n': return TRUST_NONE; + case 'm': return TRUST_MARGINAL; + case 'f': return TRUST_FULL; + case 'u': return TRUST_ULTIMATE; + default: return TRUST_UNKNOWN; + } +} + +KgpgKeyTrust Convert::toTrust(const QString &s) +{ + return s.isEmpty() ? TRUST_UNKNOWN : toTrust(s[0]); +} + +KgpgKeyOwnerTrust Convert::toOwnerTrust(const QChar &c) +{ + switch (c.toAscii()) + { + case 'n': return OWTRUST_NONE; + case 'm': return OWTRUST_MARGINAL; + case 'u': return OWTRUST_ULTIMATE; + case 'f': return OWTRUST_FULL; + default: return OWTRUST_UNDEFINED; + } +} + +KgpgKeyOwnerTrust Convert::toOwnerTrust(const QString &s) +{ + return s.isEmpty() ? OWTRUST_UNDEFINED : toOwnerTrust(s[0]); +} + +QPixmap Convert::toPixmap(const KgpgItemType t) +{ + switch (t) + { + case ITYPE_GROUP: return Images::group(); + case ITYPE_GSECRET: + case ITYPE_SECRET: return Images::orphan(); + case ITYPE_GPUBLIC: + case ITYPE_SUB: + case ITYPE_PUBLIC: return Images::single(); + case ITYPE_GPAIR: + case ITYPE_PAIR: return Images::pair(); + case ITYPE_UID: return Images::userId(); + case ITYPE_UAT: return Images::photo(); + case ITYPE_REVSIGN: return Images::revoke(); + case ITYPE_SIGN: return Images::signature(); + default: Q_ASSERT(1); + return NULL; + } +} + +} // namespace KgpgCore diff --git a/kgpg/core/convert.h b/kgpg/core/convert.h new file mode 100644 index 0000000..96043a8 --- /dev/null +++ b/kgpg/core/convert.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2006 Jimmy Gilles + * Copyright (C) 2010 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) any later version. * + * * + * 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef CONVERT_H +#define CONVERT_H + +#include "kgpgkey.h" + +class QColor; +class QString; +class QPixmap; + +namespace KgpgCore +{ + +class Convert +{ +public: + static QString toString(const KgpgCore::KgpgKeyAlgo algorithm); + static QString toString(const KgpgCore::KgpgKeyOwnerTrust ownertrust); + static QString toString(const KgpgCore::KgpgKeyTrust trust); + static QString toString(const QDate &date); + static QColor toColor(const KgpgCore::KgpgKeyTrust trust); + static KgpgKeyAlgo toAlgo(const uint v); + static KgpgKeyAlgo toAlgo(const QString &s); + static KgpgKeyTrust toTrust(const QChar &c); + static KgpgKeyTrust toTrust(const QString &s); + static KgpgKeyOwnerTrust toOwnerTrust(const QChar &c); + static KgpgKeyOwnerTrust toOwnerTrust(const QString &s); + static QPixmap toPixmap(const KgpgCore::KgpgItemType t); +}; + +} // namespace KgpgCore + +#endif // CONVERT_H diff --git a/kgpg/core/images.cpp b/kgpg/core/images.cpp new file mode 100644 index 0000000..c63dceb --- /dev/null +++ b/kgpg/core/images.cpp @@ -0,0 +1,100 @@ +/*************************************************************************** + * Copyright (C) 2006 by Jimmy Gilles * + * jimmygilles@gmail.com * + * * + * 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) any later version. * + * * + * 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "images.h" + +//#include + +namespace KgpgCore +{ + +QPixmap Images::single() +{ + static QPixmap single; +// if (single.isNull()) +// single = KIconLoader::global()->loadIcon(QLatin1String( "key-single" ), KIconLoader::Small, 20); + return single; +} + +QPixmap Images::pair() +{ + static QPixmap pair; +// if (pair.isNull()) +// pair = KIconLoader::global()->loadIcon(QLatin1String( "key-pair" ), KIconLoader::Small, 20); + return pair; +} + +QPixmap Images::group() +{ + static QPixmap group; +// if (group.isNull()) +// group = KIconLoader::global()->loadIcon(QLatin1String( "key-group" ), KIconLoader::Small, 20); + return group; +} + +QPixmap Images::orphan() +{ + static QPixmap oprpan; +// if (oprpan.isNull()) +// oprpan = KIconLoader::global()->loadIcon(QLatin1String( "key-orphan" ), KIconLoader::Small, 20); + return oprpan; +} + +QPixmap Images::signature() +{ + static QPixmap signature; +// if (signature.isNull()) +// signature = KIconLoader::global()->loadIcon(QLatin1String( "application-pgp-signature" ), KIconLoader::Small, 20); + return signature; +} + +QPixmap Images::userId() +{ + static QPixmap userid; +// if (userid.isNull()) +// userid = KIconLoader::global()->loadIcon(QLatin1String( "x-office-contact" ), KIconLoader::Small, 20); + return userid; +} + +QPixmap Images::photo() +{ + static QPixmap photo; +// if (photo.isNull()) +// photo = KIconLoader::global()->loadIcon(QLatin1String( "image-x-generic" ), KIconLoader::Small, 20); + return photo; +} + +QPixmap Images::revoke() +{ + static QPixmap revoke; +// if (revoke.isNull()) +// revoke = KIconLoader::global()->loadIcon(QLatin1String( "dialog-error" ), KIconLoader::Small, 20); + return revoke; +} + +QPixmap Images::kgpg() +{ + static QPixmap kgpg; +// if (kgpg.isNull()) +// kgpg = KIconLoader::global()->loadIcon(QLatin1String( "kgpg" ), KIconLoader::Desktop); + return kgpg; +} + +} // namespace KgpgCore diff --git a/kgpg/core/images.h b/kgpg/core/images.h new file mode 100644 index 0000000..739a618 --- /dev/null +++ b/kgpg/core/images.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2006 by Jimmy Gilles * + * jimmygilles@gmail.com * + * * + * 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) any later version. * + * * + * 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef IMAGES_H +#define IMAGES_H + +#include + +namespace KgpgCore +{ + +class Images +{ +public: + static QPixmap single(); + static QPixmap pair(); + static QPixmap group(); + static QPixmap orphan(); + static QPixmap signature(); + static QPixmap userId(); + static QPixmap photo(); + static QPixmap revoke(); + + /* Desktop image */ + static QPixmap kgpg(); +}; + +} // namespace KgpgCore + +#endif // IMAGES_H diff --git a/kgpg/core/kgpgkey.cpp b/kgpg/core/kgpgkey.cpp new file mode 100644 index 0000000..57ed820 --- /dev/null +++ b/kgpg/core/kgpgkey.cpp @@ -0,0 +1,354 @@ +/* + * Copyright (C) 2006,2007 Jimmy Gilles + * Copyright (C) 2007,2008,2009,2010,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) any later version. * + * * + ***************************************************************************/ + +#include "kgpgkey.h" + +#include "convert.h" + +//#include + +#include + +namespace KgpgCore +{ + +//BEGIN KeySub +KgpgKeySubPrivate::KgpgKeySubPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, + const KgpgSubKeyType type, const QDateTime &date) + : gpgsubid(id), + gpgsubsize(size), + gpgsubcreation(date), + gpgsubtrust(trust), + gpgsubalgo(algo), + gpgsubtype(type) +{ +} + +bool KgpgKeySubPrivate::operator==(const KgpgKeySubPrivate &other) const +{ + if (gpgsubvalid != other.gpgsubvalid) return false; + if (gpgsubalgo != other.gpgsubalgo) return false; + if (gpgsubid != other.gpgsubid) return false; + if (gpgsubsize != other.gpgsubsize) return false; + if (gpgsubexpiration != other.gpgsubexpiration) return false; + if (gpgsubcreation != other.gpgsubcreation) return false; + if (gpgsubtrust != other.gpgsubtrust) return false; + if (gpgsubtype != other.gpgsubtype) return false; + return true; +} + +KgpgKeySub::KgpgKeySub(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type, + const QDateTime &date) + : d(new KgpgKeySubPrivate(id, size, trust, algo, type, date)) +{ + d->gpgsubvalid = false; +} + +KgpgKeySub::KgpgKeySub(const KgpgKeySub &other) +{ + d = other.d; +} + +void KgpgKeySub::setExpiration(const QDateTime &date) +{ + d->gpgsubexpiration = date; +} + +void KgpgKeySub::setValid(const bool valid) +{ + d->gpgsubvalid = valid; +} + +QString KgpgKeySub::id() const +{ + return d->gpgsubid; +} + +uint KgpgKeySub::size() const +{ + return d->gpgsubsize; +} + +bool KgpgKeySub::unlimited() const +{ + return d->gpgsubexpiration.isNull(); +} + +QDateTime KgpgKeySub::expirationDate() const +{ + return d->gpgsubexpiration; +} + +QDateTime KgpgKeySub::creationDate() const +{ + return d->gpgsubcreation; +} + +KgpgKeyTrust KgpgKeySub::trust() const +{ + return d->gpgsubtrust; +} + +KgpgKeyAlgo KgpgKeySub::algorithm() const +{ + return d->gpgsubalgo; +} + +bool KgpgKeySub::valid() const +{ + return d->gpgsubvalid; +} + +KgpgSubKeyType KgpgKeySub::type() const +{ + return d->gpgsubtype; +} + +bool KgpgKeySub::operator==(const KgpgKeySub &other) const +{ + if (d == other.d) return true; + if ((*d) == (*(other.d))) return true; + return false; +} + +KgpgKeySub& KgpgKeySub::operator=(const KgpgKeySub &other) +{ + d = other.d; + return *this; +} + +//END KeySub + + +//BEGIN Key + +KgpgKeyPrivate::KgpgKeyPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date) + : gpgkeysecret(false), + gpgkeyvalid(false), + gpgkeyid(id), + gpgkeysize(size), + gpgkeytrust(trust), + gpgkeycreation(date), + gpgkeyalgo(algo), + gpgsublist(new KgpgKeySubList()) +{ +} + +bool KgpgKeyPrivate::operator==(const KgpgKeyPrivate &other) const +{ + if (gpgkeysecret != other.gpgkeysecret) return false; + if (gpgkeyvalid != other.gpgkeyvalid) return false; + if (gpgkeymail != other.gpgkeymail) return false; + if (gpgkeyname != other.gpgkeyname) return false; + if (gpgkeycomment != other.gpgkeycomment) return false; + if (gpgkeyfingerprint != other.gpgkeyfingerprint) return false; + if (gpgkeyid != other.gpgkeyid) return false; + if (gpgkeysize != other.gpgkeysize) return false; + if (gpgkeyownertrust != other.gpgkeyownertrust) return false; + if (gpgkeytrust != other.gpgkeytrust) return false; + if (gpgkeycreation != other.gpgkeycreation) return false; + if (gpgkeyexpiration != other.gpgkeyexpiration) return false; + if (gpgkeyalgo != other.gpgkeyalgo) return false; + if (gpgsublist != other.gpgsublist) return false; + return true; +} + +KgpgKey::KgpgKey(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date) + : d(new KgpgKeyPrivate(id, size, trust, algo, date)) +{ +} + +KgpgKey::KgpgKey(const KgpgKey &other) +{ + d = other.d; +} + +void KgpgKey::setSecret(const bool secret) +{ + d->gpgkeysecret = secret; +} + +void KgpgKey::setValid(const bool valid) +{ + d->gpgkeyvalid = valid; +} + +void KgpgKey::setName(const QString &name) +{ + d->gpgkeyname = name; +} + +void KgpgKey::setEmail(const QString &email) +{ + d->gpgkeymail = email; +} + +void KgpgKey::setComment(const QString &comment) +{ + d->gpgkeycomment = comment; +} + +void KgpgKey::setFingerprint(const QString &fingerprint) +{ + d->gpgkeyfingerprint = fingerprint; +} + +void KgpgKey::setOwnerTrust(const KgpgKeyOwnerTrust &owtrust) +{ + d->gpgkeyownertrust = owtrust; +} + +void KgpgKey::setExpiration(const QDateTime &date) +{ + d->gpgkeyexpiration = date; +} + +bool KgpgKey::secret() const +{ + return d->gpgkeysecret; +} + +bool KgpgKey::valid() const +{ + return d->gpgkeyvalid; +} + +QString KgpgKey::id() const +{ + return d->gpgkeyid.right(8); +} + +QString KgpgKey::fullId() const +{ + return d->gpgkeyid; +} + +QString KgpgKey::name() const +{ + return d->gpgkeyname; +} + +QString KgpgKey::email() const +{ + return d->gpgkeymail; +} + +QString KgpgKey::comment() const +{ + return d->gpgkeycomment; +} + +const QString &KgpgKey::fingerprint() const +{ + return d->gpgkeyfingerprint; +} + +QString KgpgKey::fingerprintBeautified() const +{ + QString fingervalue =d->gpgkeyfingerprint; + uint len = fingervalue.length(); + if ((len > 0) && (len % 4 == 0)) + for (uint n = 0; 4 * (n + 1) < len; ++n) + fingervalue.insert(5 * n + 4, QLatin1Char( ' ' )); + return fingervalue; +} + +uint KgpgKey::size() const +{ + return d->gpgkeysize; +} + +uint KgpgKey::encryptionSize() const +{ + // Get the first encryption subkey + for (int i = 0; i < d->gpgsublist->count(); ++i) { + KgpgKeySub temp = d->gpgsublist->at(i); + if (temp.type() & SKT_ENCRYPTION) { + return temp.size(); + } + } + return 0; +} + +KgpgKeyOwnerTrust KgpgKey::ownerTrust() const +{ + return d->gpgkeyownertrust; +} + +KgpgKeyTrust KgpgKey::trust() const +{ + return d->gpgkeytrust; +} + +QDateTime KgpgKey::creationDate() const +{ + return d->gpgkeycreation; +} + +QDateTime KgpgKey::expirationDate() const +{ + return d->gpgkeyexpiration; +} + +bool KgpgKey::unlimited() const +{ + return d->gpgkeyexpiration.isNull(); +} + +KgpgKeyAlgo KgpgKey::algorithm() const +{ + return d->gpgkeyalgo; +} + +KgpgKeyAlgo KgpgKey::encryptionAlgorithm() const +{ + // Get the first encryption subkey + for (int i = 0; i < d->gpgsublist->count(); ++i) { + KgpgKeySub temp = d->gpgsublist->at(i); + if (temp.type() & SKT_ENCRYPTION) { + return temp.algorithm(); + } + } + return ALGO_UNKNOWN; +} + +KgpgKeySubListPtr KgpgKey::subList() const +{ + return d->gpgsublist; +} + +bool KgpgKey::operator==(const KgpgKey &other) const +{ + if (d == other.d) return true; + if ((*d) == (*(other.d))) return true; + return false; +} + +KgpgKey& KgpgKey::operator=(const KgpgKey &other) +{ + d = other.d; + return *this; +} + +KgpgKeyList::operator QStringList() const +{ + QStringList res; + foreach(const KgpgKey &key, *this) + res << key.fullId(); + return res; +} + +//END Key + +} // namespace KgpgCore diff --git a/kgpg/core/kgpgkey.h b/kgpg/core/kgpgkey.h new file mode 100644 index 0000000..f16907c --- /dev/null +++ b/kgpg/core/kgpgkey.h @@ -0,0 +1,327 @@ +/* + * Copyright (C) 2006,2007 Jimmy Gilles + * Copyright (C) 2007,2008,2009,2010,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) any later version. * + * * + ***************************************************************************/ + +#ifndef KGPGKEY_H +#define KGPGKEY_H + +#include +#include +#include +#include +#include +#include + +class QStringList; + +namespace KgpgCore +{ + +//BEGIN Enums + +enum KgpgKeyAlgoFlag +{ + ALGO_UNKNOWN = 0, + ALGO_RSA = 1, + ALGO_DSA = 2, + ALGO_ELGAMAL = 4, + ALGO_DSA_ELGAMAL = ALGO_DSA | ALGO_ELGAMAL, + ALGO_RSA_RSA = 0x10001 +}; +Q_DECLARE_FLAGS(KgpgKeyAlgo, KgpgKeyAlgoFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgKeyAlgo) + +/*! \brief trust levels of keys, uids and uats + * + * These values represent the trust that you have in a public key or obe if it's + * user ids or attributes (i.e. photo ids). They are more or less ordered by + * the level of trust. Every value but the first and the last matches one trust + * value that is + */ +enum KgpgKeyTrustFlag +{ + TRUST_MINIMUM = 0, //!< internal value for use in filters + TRUST_INVALID = 1, //!< key is invalid + TRUST_DISABLED = 2, //!< key is disabled by user (not owner) + TRUST_REVOKED = 3, //!< key is revoked by owner + TRUST_EXPIRED = 4, //!< key is beyond it's expiry date + TRUST_UNDEFINED = 5, //!< trust value undefined (i.e. you did not set a trust level) + TRUST_UNKNOWN = 6, //!< trust value unknown (i.e. no entry in gpg's trust database) + TRUST_NONE = 7, //!< there is no trusted path to this key + TRUST_MARGINAL = 8, //!< there is a minimal level of trust + TRUST_FULL = 9, //!< you can fully trust this key + TRUST_ULTIMATE = 10, //!< this key has highest possible level of trust (e.g. your own secret keys) + TRUST_NOKEY = 11 //!< internal value, e.g. for key groups +}; +Q_DECLARE_FLAGS(KgpgKeyTrust, KgpgKeyTrustFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgKeyTrust) + +/*! \brief trust levels for trust in other key owners + * + * These values represent the trust that you have in other people when they + * sign keys. Once you have signed someones keys you can benefit from the + * keys they have signed if you trust them to carefully check which keys they + * sign. + */ +enum KgpgKeyOwnerTrustFlag +{ + OWTRUST_UNKNOWN = 0, //!< Trust value is unknown (e.g. no entry in trust database). + OWTRUST_UNDEFINED = 1, //!< Trust value undefined (e.g. not trust level set). + OWTRUST_NONE = 2, //!< You do not trust the key owner, keys signed by him are untrusted. + OWTRUST_MARGINAL = 3, //!< You have a minimum level of trust in the key owner. + OWTRUST_FULL = 4, //!< You believe the key owner does good checking. Keys signed by him are trusted by you, too. + OWTRUST_ULTIMATE = 5 //!< There is no doubt in this key owner. This level is used for your own secret keys. +}; +Q_DECLARE_FLAGS(KgpgKeyOwnerTrust, KgpgKeyOwnerTrustFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgKeyOwnerTrust) + +enum KgpgSubKeyTypeFlag +{ + SKT_ENCRYPTION = 0x1, + SKT_SIGNATURE = 0x2, + SKT_AUTHENTICATION = 0x4, + SKT_CERTIFICATION = 0x8 +}; +Q_DECLARE_FLAGS(KgpgSubKeyType, KgpgSubKeyTypeFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgSubKeyType) + +/*! \brief types of items in the item models + * + * Every item in the item models is of one of the following types. Some of the + * items can have properties of more than one basic type, e.g. a key pair can + * act both as a secret and a public key. Because of this the value for key + * pairs is a composite of the two "elementary" types for secret and public + * keys. Other compositions than the ones defined here must not be used to set + * an item type, but may of course be used as a mask for comparison. + */ +enum KgpgItemTypeFlag +{ + ITYPE_GROUP = 1, //!< the element is a GnuPG key group + ITYPE_SECRET = 2, //!< secret key + ITYPE_PUBLIC = 4, //!< public key + ITYPE_PAIR = ITYPE_SECRET | ITYPE_PUBLIC, //!< key pair + ITYPE_GSECRET = ITYPE_GROUP | ITYPE_SECRET, //!< secret key as member of a key group + ITYPE_GPUBLIC = ITYPE_GROUP | ITYPE_PUBLIC, //!< public key as member of a key group + ITYPE_GPAIR = ITYPE_GROUP | ITYPE_PAIR, //!< key pair as member of a key group + ITYPE_SUB = 8, //!< subkey of a public or secret key + ITYPE_UID = 16, //!< additional user id + ITYPE_UAT = 32, //!< user attribute to a key (i.e. photo id) + ITYPE_REVSIGN = 64, //!< revokation signature + ITYPE_SIGN = 128 //!< signature (to a key, uid or uat) +}; +Q_DECLARE_FLAGS(KgpgItemType, KgpgItemTypeFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgItemType) + +//END Enums + +//BEGIN KeySub + +class KgpgKeySubPrivate : public QSharedData +{ + KgpgKeySubPrivate(); +public: + KgpgKeySubPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type, + const QDateTime &date); + + bool gpgsubvalid; + const QString gpgsubid; + const uint gpgsubsize; + QDateTime gpgsubexpiration; + const QDateTime gpgsubcreation; + const KgpgKeyTrust gpgsubtrust; + const KgpgKeyAlgo gpgsubalgo; + const KgpgSubKeyType gpgsubtype; + + bool operator==(const KgpgKeySubPrivate &other) const; + inline bool operator!=(const KgpgKeySubPrivate &other) const + { return !operator==(other); } +}; + +class KgpgKeySub +{ + KgpgKeySub(); +public: + KgpgKeySub(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type, + const QDateTime &date); + KgpgKeySub(const KgpgKeySub &other); + + void setExpiration(const QDateTime &date); + void setValid(const bool valid); // FIXME : is it possible to have a subkey that is not valid (disabled)? Please give an example. Thx. If not, this method should be removed. + + QString id() const; + uint size() const; + bool unlimited() const; + QDateTime expirationDate() const; + QDateTime creationDate() const; + KgpgKeyTrust trust() const; + KgpgKeyAlgo algorithm() const; + bool valid() const; + KgpgSubKeyType type() const; + + bool operator==(const KgpgKeySub &other) const; + inline bool operator!=(const KgpgKeySub &other) const + { return !operator==(other); } + KgpgKeySub& operator=(const KgpgKeySub &other); + +private: + QSharedDataPointer d; +}; + +class KgpgKeySubList : public QList, public QObject +{ +public: + inline KgpgKeySubList() { } + inline explicit KgpgKeySubList(const KgpgKeySub &sub) { append(sub); } + inline KgpgKeySubList(const KgpgKeySubList &other) : QList(other), QObject() { } + inline KgpgKeySubList(const QList &other) : QList(other), QObject() { } + + inline KgpgKeySubList operator+(const KgpgKeySubList &other) const + { + KgpgKeySubList n = *this; + n += other; + return n; + } + + inline KgpgKeySubList &operator<<(KgpgKeySub sub) + { + append(sub); + return *this; + } + + inline KgpgKeySubList &operator<<(const KgpgKeySubList &l) + { + *this += l; + return *this; + } +}; +typedef QPointer KgpgKeySubListPtr; + +//END KeySub + + +//BEGIN Key + +class KgpgKeyPrivate : public QSharedData +{ + KgpgKeyPrivate(); +public: + KgpgKeyPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date); + + bool gpgkeysecret; + bool gpgkeyvalid; + QString gpgkeymail; + QString gpgkeyname; + QString gpgkeycomment; + QString gpgkeyfingerprint; + const QString gpgkeyid; + const uint gpgkeysize; + KgpgKeyOwnerTrust gpgkeyownertrust; + const KgpgKeyTrust gpgkeytrust; + const QDateTime gpgkeycreation; + QDateTime gpgkeyexpiration; + const KgpgKeyAlgo gpgkeyalgo; + + KgpgKeySubListPtr gpgsublist; + + bool operator==(const KgpgKeyPrivate &other) const; + inline bool operator!=(const KgpgKeyPrivate &other) const + { return !operator==(other); } +}; + +class KgpgKey +{ + KgpgKey(); +public: + KgpgKey(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date); + KgpgKey(const KgpgKey &other); + + void setSecret(const bool secret); + void setValid(const bool valid); + void setName(const QString &name); + void setEmail(const QString &email); + void setComment(const QString &comment); + void setFingerprint(const QString &fingerprint); + void setOwnerTrust(const KgpgKeyOwnerTrust &owtrust); + void setExpiration(const QDateTime &date); + + bool secret() const; + bool valid() const; + QString id() const; + QString fullId() const; + QString name() const; + QString email() const; + QString comment() const; + const QString &fingerprint() const; + QString fingerprintBeautified() const; + uint size() const; + uint encryptionSize() const; + KgpgKeyOwnerTrust ownerTrust() const; + KgpgKeyTrust trust() const; + QDateTime creationDate() const; + QDateTime expirationDate() const; + bool unlimited() const; + KgpgKeyAlgo algorithm() const; + KgpgKeyAlgo encryptionAlgorithm() const; + + KgpgKeySubListPtr subList() const; + + bool operator==(const KgpgKey &other) const; + inline bool operator!=(const KgpgKey &other) const + { return !operator==(other); } + KgpgKey& operator=(const KgpgKey &other); + +private: + QSharedDataPointer d; +}; + +class KgpgKeyList : public QList, public QObject +{ +public: + inline KgpgKeyList() { } + inline explicit KgpgKeyList(const KgpgKey &key) { append(key); } + inline KgpgKeyList(const KgpgKeyList &other) : QList(other), QObject() { } + inline KgpgKeyList(const QList &other) : QList(other), QObject() { } + + inline KgpgKeyList& operator=(const KgpgKeyList &other) + { + QList::operator=(static_cast >(other)); + return *this; + } + + inline KgpgKeyList operator+(const KgpgKeyList &other) const + { + KgpgKeyList n = *this; + n += other; + return n; + } + + inline KgpgKeyList &operator<<(KgpgKey key) + { + append(key); + return *this; + } + + inline KgpgKeyList &operator<<(const KgpgKeyList &l) + { + *this += l; + return *this; + } + + operator QStringList() const; +}; + +//END Key + +} // namespace + +#endif // KGPGKEY_H diff --git a/kgpg/images.cpp b/kgpg/images.cpp deleted file mode 100644 index c63dceb..0000000 --- a/kgpg/images.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Jimmy Gilles * - * jimmygilles@gmail.com * - * * - * 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) any later version. * - * * - * 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, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "images.h" - -//#include - -namespace KgpgCore -{ - -QPixmap Images::single() -{ - static QPixmap single; -// if (single.isNull()) -// single = KIconLoader::global()->loadIcon(QLatin1String( "key-single" ), KIconLoader::Small, 20); - return single; -} - -QPixmap Images::pair() -{ - static QPixmap pair; -// if (pair.isNull()) -// pair = KIconLoader::global()->loadIcon(QLatin1String( "key-pair" ), KIconLoader::Small, 20); - return pair; -} - -QPixmap Images::group() -{ - static QPixmap group; -// if (group.isNull()) -// group = KIconLoader::global()->loadIcon(QLatin1String( "key-group" ), KIconLoader::Small, 20); - return group; -} - -QPixmap Images::orphan() -{ - static QPixmap oprpan; -// if (oprpan.isNull()) -// oprpan = KIconLoader::global()->loadIcon(QLatin1String( "key-orphan" ), KIconLoader::Small, 20); - return oprpan; -} - -QPixmap Images::signature() -{ - static QPixmap signature; -// if (signature.isNull()) -// signature = KIconLoader::global()->loadIcon(QLatin1String( "application-pgp-signature" ), KIconLoader::Small, 20); - return signature; -} - -QPixmap Images::userId() -{ - static QPixmap userid; -// if (userid.isNull()) -// userid = KIconLoader::global()->loadIcon(QLatin1String( "x-office-contact" ), KIconLoader::Small, 20); - return userid; -} - -QPixmap Images::photo() -{ - static QPixmap photo; -// if (photo.isNull()) -// photo = KIconLoader::global()->loadIcon(QLatin1String( "image-x-generic" ), KIconLoader::Small, 20); - return photo; -} - -QPixmap Images::revoke() -{ - static QPixmap revoke; -// if (revoke.isNull()) -// revoke = KIconLoader::global()->loadIcon(QLatin1String( "dialog-error" ), KIconLoader::Small, 20); - return revoke; -} - -QPixmap Images::kgpg() -{ - static QPixmap kgpg; -// if (kgpg.isNull()) -// kgpg = KIconLoader::global()->loadIcon(QLatin1String( "kgpg" ), KIconLoader::Desktop); - return kgpg; -} - -} // namespace KgpgCore diff --git a/kgpg/images.h b/kgpg/images.h deleted file mode 100644 index 739a618..0000000 --- a/kgpg/images.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Jimmy Gilles * - * jimmygilles@gmail.com * - * * - * 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) any later version. * - * * - * 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, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef IMAGES_H -#define IMAGES_H - -#include - -namespace KgpgCore -{ - -class Images -{ -public: - static QPixmap single(); - static QPixmap pair(); - static QPixmap group(); - static QPixmap orphan(); - static QPixmap signature(); - static QPixmap userId(); - static QPixmap photo(); - static QPixmap revoke(); - - /* Desktop image */ - static QPixmap kgpg(); -}; - -} // namespace KgpgCore - -#endif // IMAGES_H diff --git a/kgpg/kgpg.pro b/kgpg/kgpg.pro deleted file mode 100644 index 7dd6391..0000000 --- a/kgpg/kgpg.pro +++ /dev/null @@ -1,12 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Wed Aug 1 23:46:35 2012 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -HEADERS += gpgproc.h klinebufferedprocess.h kprocess.h kprocess_p.h -SOURCES += gpgproc.cpp klinebufferedprocess.cpp kprocess.cpp diff --git a/kgpg/kgpginterface.cpp b/kgpg/kgpginterface.cpp index 90dea2d..0c14b33 100644 --- a/kgpg/kgpginterface.cpp +++ b/kgpg/kgpginterface.cpp @@ -15,12 +15,12 @@ #include "kgpginterface.h" #include "gpgproc.h" -#include "convert.h" -#include "KGpgKeyNode.h" -#include "KGpgSignNode.h" -#include "KGpgSubkeyNode.h" -#include "KGpgUatNode.h" -#include "KGpgUidNode.h" +#include "core/convert.h" +#include "core/KGpgKeyNode.h" +#include "core/KGpgSignNode.h" +#include "core/KGpgSubkeyNode.h" +#include "core/KGpgUatNode.h" +#include "core/KGpgUidNode.h" /*#include #include diff --git a/kgpg/kgpginterface.h b/kgpg/kgpginterface.h index 7a289ec..1ed0e53 100644 --- a/kgpg/kgpginterface.h +++ b/kgpg/kgpginterface.h @@ -15,7 +15,7 @@ #ifndef KGPGINTERFACE_H #define KGPGINTERFACE_H -#include "kgpgkey.h" +#include "core/kgpgkey.h" #include class KGpgKeyNode; diff --git a/kgpg/kgpgkey.cpp b/kgpg/kgpgkey.cpp deleted file mode 100644 index 57ed820..0000000 --- a/kgpg/kgpgkey.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright (C) 2006,2007 Jimmy Gilles - * Copyright (C) 2007,2008,2009,2010,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) any later version. * - * * - ***************************************************************************/ - -#include "kgpgkey.h" - -#include "convert.h" - -//#include - -#include - -namespace KgpgCore -{ - -//BEGIN KeySub -KgpgKeySubPrivate::KgpgKeySubPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, - const KgpgSubKeyType type, const QDateTime &date) - : gpgsubid(id), - gpgsubsize(size), - gpgsubcreation(date), - gpgsubtrust(trust), - gpgsubalgo(algo), - gpgsubtype(type) -{ -} - -bool KgpgKeySubPrivate::operator==(const KgpgKeySubPrivate &other) const -{ - if (gpgsubvalid != other.gpgsubvalid) return false; - if (gpgsubalgo != other.gpgsubalgo) return false; - if (gpgsubid != other.gpgsubid) return false; - if (gpgsubsize != other.gpgsubsize) return false; - if (gpgsubexpiration != other.gpgsubexpiration) return false; - if (gpgsubcreation != other.gpgsubcreation) return false; - if (gpgsubtrust != other.gpgsubtrust) return false; - if (gpgsubtype != other.gpgsubtype) return false; - return true; -} - -KgpgKeySub::KgpgKeySub(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type, - const QDateTime &date) - : d(new KgpgKeySubPrivate(id, size, trust, algo, type, date)) -{ - d->gpgsubvalid = false; -} - -KgpgKeySub::KgpgKeySub(const KgpgKeySub &other) -{ - d = other.d; -} - -void KgpgKeySub::setExpiration(const QDateTime &date) -{ - d->gpgsubexpiration = date; -} - -void KgpgKeySub::setValid(const bool valid) -{ - d->gpgsubvalid = valid; -} - -QString KgpgKeySub::id() const -{ - return d->gpgsubid; -} - -uint KgpgKeySub::size() const -{ - return d->gpgsubsize; -} - -bool KgpgKeySub::unlimited() const -{ - return d->gpgsubexpiration.isNull(); -} - -QDateTime KgpgKeySub::expirationDate() const -{ - return d->gpgsubexpiration; -} - -QDateTime KgpgKeySub::creationDate() const -{ - return d->gpgsubcreation; -} - -KgpgKeyTrust KgpgKeySub::trust() const -{ - return d->gpgsubtrust; -} - -KgpgKeyAlgo KgpgKeySub::algorithm() const -{ - return d->gpgsubalgo; -} - -bool KgpgKeySub::valid() const -{ - return d->gpgsubvalid; -} - -KgpgSubKeyType KgpgKeySub::type() const -{ - return d->gpgsubtype; -} - -bool KgpgKeySub::operator==(const KgpgKeySub &other) const -{ - if (d == other.d) return true; - if ((*d) == (*(other.d))) return true; - return false; -} - -KgpgKeySub& KgpgKeySub::operator=(const KgpgKeySub &other) -{ - d = other.d; - return *this; -} - -//END KeySub - - -//BEGIN Key - -KgpgKeyPrivate::KgpgKeyPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date) - : gpgkeysecret(false), - gpgkeyvalid(false), - gpgkeyid(id), - gpgkeysize(size), - gpgkeytrust(trust), - gpgkeycreation(date), - gpgkeyalgo(algo), - gpgsublist(new KgpgKeySubList()) -{ -} - -bool KgpgKeyPrivate::operator==(const KgpgKeyPrivate &other) const -{ - if (gpgkeysecret != other.gpgkeysecret) return false; - if (gpgkeyvalid != other.gpgkeyvalid) return false; - if (gpgkeymail != other.gpgkeymail) return false; - if (gpgkeyname != other.gpgkeyname) return false; - if (gpgkeycomment != other.gpgkeycomment) return false; - if (gpgkeyfingerprint != other.gpgkeyfingerprint) return false; - if (gpgkeyid != other.gpgkeyid) return false; - if (gpgkeysize != other.gpgkeysize) return false; - if (gpgkeyownertrust != other.gpgkeyownertrust) return false; - if (gpgkeytrust != other.gpgkeytrust) return false; - if (gpgkeycreation != other.gpgkeycreation) return false; - if (gpgkeyexpiration != other.gpgkeyexpiration) return false; - if (gpgkeyalgo != other.gpgkeyalgo) return false; - if (gpgsublist != other.gpgsublist) return false; - return true; -} - -KgpgKey::KgpgKey(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date) - : d(new KgpgKeyPrivate(id, size, trust, algo, date)) -{ -} - -KgpgKey::KgpgKey(const KgpgKey &other) -{ - d = other.d; -} - -void KgpgKey::setSecret(const bool secret) -{ - d->gpgkeysecret = secret; -} - -void KgpgKey::setValid(const bool valid) -{ - d->gpgkeyvalid = valid; -} - -void KgpgKey::setName(const QString &name) -{ - d->gpgkeyname = name; -} - -void KgpgKey::setEmail(const QString &email) -{ - d->gpgkeymail = email; -} - -void KgpgKey::setComment(const QString &comment) -{ - d->gpgkeycomment = comment; -} - -void KgpgKey::setFingerprint(const QString &fingerprint) -{ - d->gpgkeyfingerprint = fingerprint; -} - -void KgpgKey::setOwnerTrust(const KgpgKeyOwnerTrust &owtrust) -{ - d->gpgkeyownertrust = owtrust; -} - -void KgpgKey::setExpiration(const QDateTime &date) -{ - d->gpgkeyexpiration = date; -} - -bool KgpgKey::secret() const -{ - return d->gpgkeysecret; -} - -bool KgpgKey::valid() const -{ - return d->gpgkeyvalid; -} - -QString KgpgKey::id() const -{ - return d->gpgkeyid.right(8); -} - -QString KgpgKey::fullId() const -{ - return d->gpgkeyid; -} - -QString KgpgKey::name() const -{ - return d->gpgkeyname; -} - -QString KgpgKey::email() const -{ - return d->gpgkeymail; -} - -QString KgpgKey::comment() const -{ - return d->gpgkeycomment; -} - -const QString &KgpgKey::fingerprint() const -{ - return d->gpgkeyfingerprint; -} - -QString KgpgKey::fingerprintBeautified() const -{ - QString fingervalue =d->gpgkeyfingerprint; - uint len = fingervalue.length(); - if ((len > 0) && (len % 4 == 0)) - for (uint n = 0; 4 * (n + 1) < len; ++n) - fingervalue.insert(5 * n + 4, QLatin1Char( ' ' )); - return fingervalue; -} - -uint KgpgKey::size() const -{ - return d->gpgkeysize; -} - -uint KgpgKey::encryptionSize() const -{ - // Get the first encryption subkey - for (int i = 0; i < d->gpgsublist->count(); ++i) { - KgpgKeySub temp = d->gpgsublist->at(i); - if (temp.type() & SKT_ENCRYPTION) { - return temp.size(); - } - } - return 0; -} - -KgpgKeyOwnerTrust KgpgKey::ownerTrust() const -{ - return d->gpgkeyownertrust; -} - -KgpgKeyTrust KgpgKey::trust() const -{ - return d->gpgkeytrust; -} - -QDateTime KgpgKey::creationDate() const -{ - return d->gpgkeycreation; -} - -QDateTime KgpgKey::expirationDate() const -{ - return d->gpgkeyexpiration; -} - -bool KgpgKey::unlimited() const -{ - return d->gpgkeyexpiration.isNull(); -} - -KgpgKeyAlgo KgpgKey::algorithm() const -{ - return d->gpgkeyalgo; -} - -KgpgKeyAlgo KgpgKey::encryptionAlgorithm() const -{ - // Get the first encryption subkey - for (int i = 0; i < d->gpgsublist->count(); ++i) { - KgpgKeySub temp = d->gpgsublist->at(i); - if (temp.type() & SKT_ENCRYPTION) { - return temp.algorithm(); - } - } - return ALGO_UNKNOWN; -} - -KgpgKeySubListPtr KgpgKey::subList() const -{ - return d->gpgsublist; -} - -bool KgpgKey::operator==(const KgpgKey &other) const -{ - if (d == other.d) return true; - if ((*d) == (*(other.d))) return true; - return false; -} - -KgpgKey& KgpgKey::operator=(const KgpgKey &other) -{ - d = other.d; - return *this; -} - -KgpgKeyList::operator QStringList() const -{ - QStringList res; - foreach(const KgpgKey &key, *this) - res << key.fullId(); - return res; -} - -//END Key - -} // namespace KgpgCore diff --git a/kgpg/kgpgkey.h b/kgpg/kgpgkey.h deleted file mode 100644 index f16907c..0000000 --- a/kgpg/kgpgkey.h +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (C) 2006,2007 Jimmy Gilles - * Copyright (C) 2007,2008,2009,2010,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) any later version. * - * * - ***************************************************************************/ - -#ifndef KGPGKEY_H -#define KGPGKEY_H - -#include -#include -#include -#include -#include -#include - -class QStringList; - -namespace KgpgCore -{ - -//BEGIN Enums - -enum KgpgKeyAlgoFlag -{ - ALGO_UNKNOWN = 0, - ALGO_RSA = 1, - ALGO_DSA = 2, - ALGO_ELGAMAL = 4, - ALGO_DSA_ELGAMAL = ALGO_DSA | ALGO_ELGAMAL, - ALGO_RSA_RSA = 0x10001 -}; -Q_DECLARE_FLAGS(KgpgKeyAlgo, KgpgKeyAlgoFlag) -Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgKeyAlgo) - -/*! \brief trust levels of keys, uids and uats - * - * These values represent the trust that you have in a public key or obe if it's - * user ids or attributes (i.e. photo ids). They are more or less ordered by - * the level of trust. Every value but the first and the last matches one trust - * value that is - */ -enum KgpgKeyTrustFlag -{ - TRUST_MINIMUM = 0, //!< internal value for use in filters - TRUST_INVALID = 1, //!< key is invalid - TRUST_DISABLED = 2, //!< key is disabled by user (not owner) - TRUST_REVOKED = 3, //!< key is revoked by owner - TRUST_EXPIRED = 4, //!< key is beyond it's expiry date - TRUST_UNDEFINED = 5, //!< trust value undefined (i.e. you did not set a trust level) - TRUST_UNKNOWN = 6, //!< trust value unknown (i.e. no entry in gpg's trust database) - TRUST_NONE = 7, //!< there is no trusted path to this key - TRUST_MARGINAL = 8, //!< there is a minimal level of trust - TRUST_FULL = 9, //!< you can fully trust this key - TRUST_ULTIMATE = 10, //!< this key has highest possible level of trust (e.g. your own secret keys) - TRUST_NOKEY = 11 //!< internal value, e.g. for key groups -}; -Q_DECLARE_FLAGS(KgpgKeyTrust, KgpgKeyTrustFlag) -Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgKeyTrust) - -/*! \brief trust levels for trust in other key owners - * - * These values represent the trust that you have in other people when they - * sign keys. Once you have signed someones keys you can benefit from the - * keys they have signed if you trust them to carefully check which keys they - * sign. - */ -enum KgpgKeyOwnerTrustFlag -{ - OWTRUST_UNKNOWN = 0, //!< Trust value is unknown (e.g. no entry in trust database). - OWTRUST_UNDEFINED = 1, //!< Trust value undefined (e.g. not trust level set). - OWTRUST_NONE = 2, //!< You do not trust the key owner, keys signed by him are untrusted. - OWTRUST_MARGINAL = 3, //!< You have a minimum level of trust in the key owner. - OWTRUST_FULL = 4, //!< You believe the key owner does good checking. Keys signed by him are trusted by you, too. - OWTRUST_ULTIMATE = 5 //!< There is no doubt in this key owner. This level is used for your own secret keys. -}; -Q_DECLARE_FLAGS(KgpgKeyOwnerTrust, KgpgKeyOwnerTrustFlag) -Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgKeyOwnerTrust) - -enum KgpgSubKeyTypeFlag -{ - SKT_ENCRYPTION = 0x1, - SKT_SIGNATURE = 0x2, - SKT_AUTHENTICATION = 0x4, - SKT_CERTIFICATION = 0x8 -}; -Q_DECLARE_FLAGS(KgpgSubKeyType, KgpgSubKeyTypeFlag) -Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgSubKeyType) - -/*! \brief types of items in the item models - * - * Every item in the item models is of one of the following types. Some of the - * items can have properties of more than one basic type, e.g. a key pair can - * act both as a secret and a public key. Because of this the value for key - * pairs is a composite of the two "elementary" types for secret and public - * keys. Other compositions than the ones defined here must not be used to set - * an item type, but may of course be used as a mask for comparison. - */ -enum KgpgItemTypeFlag -{ - ITYPE_GROUP = 1, //!< the element is a GnuPG key group - ITYPE_SECRET = 2, //!< secret key - ITYPE_PUBLIC = 4, //!< public key - ITYPE_PAIR = ITYPE_SECRET | ITYPE_PUBLIC, //!< key pair - ITYPE_GSECRET = ITYPE_GROUP | ITYPE_SECRET, //!< secret key as member of a key group - ITYPE_GPUBLIC = ITYPE_GROUP | ITYPE_PUBLIC, //!< public key as member of a key group - ITYPE_GPAIR = ITYPE_GROUP | ITYPE_PAIR, //!< key pair as member of a key group - ITYPE_SUB = 8, //!< subkey of a public or secret key - ITYPE_UID = 16, //!< additional user id - ITYPE_UAT = 32, //!< user attribute to a key (i.e. photo id) - ITYPE_REVSIGN = 64, //!< revokation signature - ITYPE_SIGN = 128 //!< signature (to a key, uid or uat) -}; -Q_DECLARE_FLAGS(KgpgItemType, KgpgItemTypeFlag) -Q_DECLARE_OPERATORS_FOR_FLAGS(KgpgItemType) - -//END Enums - -//BEGIN KeySub - -class KgpgKeySubPrivate : public QSharedData -{ - KgpgKeySubPrivate(); -public: - KgpgKeySubPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type, - const QDateTime &date); - - bool gpgsubvalid; - const QString gpgsubid; - const uint gpgsubsize; - QDateTime gpgsubexpiration; - const QDateTime gpgsubcreation; - const KgpgKeyTrust gpgsubtrust; - const KgpgKeyAlgo gpgsubalgo; - const KgpgSubKeyType gpgsubtype; - - bool operator==(const KgpgKeySubPrivate &other) const; - inline bool operator!=(const KgpgKeySubPrivate &other) const - { return !operator==(other); } -}; - -class KgpgKeySub -{ - KgpgKeySub(); -public: - KgpgKeySub(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type, - const QDateTime &date); - KgpgKeySub(const KgpgKeySub &other); - - void setExpiration(const QDateTime &date); - void setValid(const bool valid); // FIXME : is it possible to have a subkey that is not valid (disabled)? Please give an example. Thx. If not, this method should be removed. - - QString id() const; - uint size() const; - bool unlimited() const; - QDateTime expirationDate() const; - QDateTime creationDate() const; - KgpgKeyTrust trust() const; - KgpgKeyAlgo algorithm() const; - bool valid() const; - KgpgSubKeyType type() const; - - bool operator==(const KgpgKeySub &other) const; - inline bool operator!=(const KgpgKeySub &other) const - { return !operator==(other); } - KgpgKeySub& operator=(const KgpgKeySub &other); - -private: - QSharedDataPointer d; -}; - -class KgpgKeySubList : public QList, public QObject -{ -public: - inline KgpgKeySubList() { } - inline explicit KgpgKeySubList(const KgpgKeySub &sub) { append(sub); } - inline KgpgKeySubList(const KgpgKeySubList &other) : QList(other), QObject() { } - inline KgpgKeySubList(const QList &other) : QList(other), QObject() { } - - inline KgpgKeySubList operator+(const KgpgKeySubList &other) const - { - KgpgKeySubList n = *this; - n += other; - return n; - } - - inline KgpgKeySubList &operator<<(KgpgKeySub sub) - { - append(sub); - return *this; - } - - inline KgpgKeySubList &operator<<(const KgpgKeySubList &l) - { - *this += l; - return *this; - } -}; -typedef QPointer KgpgKeySubListPtr; - -//END KeySub - - -//BEGIN Key - -class KgpgKeyPrivate : public QSharedData -{ - KgpgKeyPrivate(); -public: - KgpgKeyPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date); - - bool gpgkeysecret; - bool gpgkeyvalid; - QString gpgkeymail; - QString gpgkeyname; - QString gpgkeycomment; - QString gpgkeyfingerprint; - const QString gpgkeyid; - const uint gpgkeysize; - KgpgKeyOwnerTrust gpgkeyownertrust; - const KgpgKeyTrust gpgkeytrust; - const QDateTime gpgkeycreation; - QDateTime gpgkeyexpiration; - const KgpgKeyAlgo gpgkeyalgo; - - KgpgKeySubListPtr gpgsublist; - - bool operator==(const KgpgKeyPrivate &other) const; - inline bool operator!=(const KgpgKeyPrivate &other) const - { return !operator==(other); } -}; - -class KgpgKey -{ - KgpgKey(); -public: - KgpgKey(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const QDateTime &date); - KgpgKey(const KgpgKey &other); - - void setSecret(const bool secret); - void setValid(const bool valid); - void setName(const QString &name); - void setEmail(const QString &email); - void setComment(const QString &comment); - void setFingerprint(const QString &fingerprint); - void setOwnerTrust(const KgpgKeyOwnerTrust &owtrust); - void setExpiration(const QDateTime &date); - - bool secret() const; - bool valid() const; - QString id() const; - QString fullId() const; - QString name() const; - QString email() const; - QString comment() const; - const QString &fingerprint() const; - QString fingerprintBeautified() const; - uint size() const; - uint encryptionSize() const; - KgpgKeyOwnerTrust ownerTrust() const; - KgpgKeyTrust trust() const; - QDateTime creationDate() const; - QDateTime expirationDate() const; - bool unlimited() const; - KgpgKeyAlgo algorithm() const; - KgpgKeyAlgo encryptionAlgorithm() const; - - KgpgKeySubListPtr subList() const; - - bool operator==(const KgpgKey &other) const; - inline bool operator!=(const KgpgKey &other) const - { return !operator==(other); } - KgpgKey& operator=(const KgpgKey &other); - -private: - QSharedDataPointer d; -}; - -class KgpgKeyList : public QList, public QObject -{ -public: - inline KgpgKeyList() { } - inline explicit KgpgKeyList(const KgpgKey &key) { append(key); } - inline KgpgKeyList(const KgpgKeyList &other) : QList(other), QObject() { } - inline KgpgKeyList(const QList &other) : QList(other), QObject() { } - - inline KgpgKeyList& operator=(const KgpgKeyList &other) - { - QList::operator=(static_cast >(other)); - return *this; - } - - inline KgpgKeyList operator+(const KgpgKeyList &other) const - { - KgpgKeyList n = *this; - n += other; - return n; - } - - inline KgpgKeyList &operator<<(KgpgKey key) - { - append(key); - return *this; - } - - inline KgpgKeyList &operator<<(const KgpgKeyList &l) - { - *this += l; - return *this; - } - - operator QStringList() const; -}; - -//END Key - -} // namespace - -#endif // KGPGKEY_H diff --git a/mainwindow.h b/mainwindow.h index 79928af..6df5ab4 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -30,7 +30,7 @@ #include "settingsdialog.h" #include "verifynotification.h" #include "wizard.h" -#include "kgpg/kgpgkey.h" +#include "kgpg/core/kgpgkey.h" QT_BEGIN_NAMESPACE class QMainWindow; -- cgit v1.2.3