aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-08-02 08:29:05 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-08-02 08:29:05 +0000
commit940110fba452f022319b9c3d37390d104ad0553e (patch)
tree4611fa3b62b34a1537afc1248d34d774d7984d6d
parentfix build (diff)
downloadgpg4usb-940110fba452f022319b9c3d37390d104ad0553e.tar.gz
gpg4usb-940110fba452f022319b9c3d37390d104ad0553e.zip
lots of classes from kgpg, keylist works now
git-svn-id: http://cpunk.de/svn/src/gpg4usb/branches/0.3.2-mac@923 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--gpg4usb.pro34
-rw-r--r--gpgcontext.cpp22
-rw-r--r--kgpg/KGpgExpandableNode.cpp88
-rw-r--r--kgpg/KGpgExpandableNode.h85
-rw-r--r--kgpg/KGpgGroupMemberNode.cpp100
-rw-r--r--kgpg/KGpgGroupMemberNode.h61
-rw-r--r--kgpg/KGpgGroupNode.cpp279
-rw-r--r--kgpg/KGpgGroupNode.h84
-rw-r--r--kgpg/KGpgKeyNode.cpp358
-rw-r--r--kgpg/KGpgKeyNode.h191
-rw-r--r--kgpg/KGpgNode.cpp337
-rw-r--r--kgpg/KGpgNode.h156
-rw-r--r--kgpg/KGpgOrphanNode.cpp84
-rw-r--r--kgpg/KGpgOrphanNode.h53
-rw-r--r--kgpg/KGpgRefNode.cpp151
-rw-r--r--kgpg/KGpgRefNode.h98
-rw-r--r--kgpg/KGpgRootNode.cpp189
-rw-r--r--kgpg/KGpgRootNode.h129
-rw-r--r--kgpg/KGpgSignNode.cpp95
-rw-r--r--kgpg/KGpgSignNode.h54
-rw-r--r--kgpg/KGpgSignableNode.cpp99
-rw-r--r--kgpg/KGpgSignableNode.h62
-rw-r--r--kgpg/KGpgSubkeyNode.cpp100
-rw-r--r--kgpg/KGpgSubkeyNode.h55
-rw-r--r--kgpg/KGpgUatNode.cpp174
-rw-r--r--kgpg/KGpgUatNode.h61
-rw-r--r--kgpg/KGpgUidNode.cpp146
-rw-r--r--kgpg/KGpgUidNode.h57
-rw-r--r--kgpg/convert.cpp183
-rw-r--r--kgpg/convert.h53
-rw-r--r--kgpg/gpgproc.cpp18
-rw-r--r--kgpg/gpgproc.h1
-rw-r--r--kgpg/images.cpp100
-rw-r--r--kgpg/images.h47
-rw-r--r--kgpg/kgpginterface.cpp423
-rw-r--r--kgpg/kgpginterface.h52
-rw-r--r--kgpg/kgpgkey.cpp354
-rw-r--r--kgpg/kgpgkey.h327
38 files changed, 4955 insertions, 5 deletions
diff --git a/gpg4usb.pro b/gpg4usb.pro
index baa82e4..2c487a1 100644
--- a/gpg4usb.pro
+++ b/gpg4usb.pro
@@ -45,6 +45,23 @@ HEADERS += attachments.h \
kgpg/klinebufferedprocess.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 \
gpgconstants.h
SOURCES += attachments.cpp \
@@ -73,6 +90,23 @@ SOURCES += attachments.cpp \
kgpg/gpgproc.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 \
gpgconstants.cpp
RC_FILE = gpg4usb.rc
diff --git a/gpgcontext.cpp b/gpgcontext.cpp
index 9ed13b4..b430513 100644
--- a/gpgcontext.cpp
+++ b/gpgcontext.cpp
@@ -21,7 +21,9 @@
#include "gpgcontext.h"
#include "kgpg/gpgproc.h"
+#include "kgpg/kgpginterface.h"
#include "kgpg/klinebufferedprocess.h"
+#include "kgpg/kgpgkey.h"
#ifdef _WIN32
#include <windows.h>
#include <unistd.h> /* contains read/write */
@@ -210,9 +212,25 @@ gpgme_key_t GpgContext::getKeyDetails(QString uid)
GpgKeyList GpgContext::listKeys()
{
+ KgpgInterface::readPublicKeys();
+
GpgKeyList keys;
- GPGProc process(this, gpgBin);
+ KgpgCore::KgpgKeyList kl = KgpgInterface::readPublicKeys();
+
+ foreach(KgpgCore::KgpgKey kkey, kl) {
+ GpgKey key;
+ key.email = kkey.email();
+ //key.expired = kkey.expirationDate().toString();
+ key.expired = false;
+ key.fpr = kkey.fingerprint();
+ key.id = kkey.id();
+ key.name = kkey.name();
+ key.revoked = false;
+ keys.append(key);
+ }
+
+/* GPGProc process(this, gpgBin);
process <<
QLatin1String("--with-colons") <<
QLatin1String("--with-fingerprint") <<
@@ -222,7 +240,7 @@ GpgKeyList GpgContext::listKeys()
process.setOutputChannelMode(KProcess::MergedChannels);
process.start();
- process.waitForFinished(-1);
+ process.waitForFinished(-1);*/
//while (item == process->)
diff --git a/kgpg/KGpgExpandableNode.cpp b/kgpg/KGpgExpandableNode.cpp
new file mode 100644
index 0000000..4cf9607
--- /dev/null
+++ b/kgpg/KGpgExpandableNode.cpp
@@ -0,0 +1,88 @@
+/* Copyright 2008,2009,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgExpandableNode.h"
+
+//#include "kgpgsettings.h"
+#include "convert.h"
+//#include "model/kgpgitemmodel.h"
+
+//#include <KLocale>
+
+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
new file mode 100644
index 0000000..39f351d
--- /dev/null
+++ b/kgpg/KGpgExpandableNode.h
@@ -0,0 +1,85 @@
+/* Copyright 2008,2009,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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
new file mode 100644
index 0000000..e7a9f97
--- /dev/null
+++ b/kgpg/KGpgGroupMemberNode.cpp
@@ -0,0 +1,100 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgGroupMemberNode.h"
+
+#include <QDateTime>
+
+#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
new file mode 100644
index 0000000..2a456ef
--- /dev/null
+++ b/kgpg/KGpgGroupMemberNode.h
@@ -0,0 +1,61 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef KGPGGROUPMEMBERNODE_H
+#define KGPGGROUPMEMBERNODE_H
+
+#include "KGpgRefNode.h"
+
+#include <QPixmap>
+#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
new file mode 100644
index 0000000..3475303
--- /dev/null
+++ b/kgpg/KGpgGroupNode.cpp
@@ -0,0 +1,279 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgGroupNode.h"
+
+#include "KGpgGroupMemberNode.h"
+#include "KGpgRootNode.h"
+//#include "kgpgsettings.h"
+
+#include <QDebug>
+//#include <KLocale>
+#include <QFile>
+#include <QStringList>
+#include <QTextStream>
+
+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
new file mode 100644
index 0000000..5aca837
--- /dev/null
+++ b/kgpg/KGpgGroupNode.h
@@ -0,0 +1,84 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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
new file mode 100644
index 0000000..285c8f1
--- /dev/null
+++ b/kgpg/KGpgKeyNode.cpp
@@ -0,0 +1,358 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#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 <KLocale>
+
+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<KGpgGroupNode *>
+KGpgKeyNode::getGroups(void) const
+{
+ QList<KGpgGroupNode *> ret;
+
+ foreach (KGpgGroupMemberNode *gnd, getGroupRefs())
+ ret.append(gnd->getParentKeyNode());
+
+ return ret;
+}
+
+QList<KGpgRefNode *>
+KGpgKeyNode::getRefsOfType(const KgpgItemType &type) const
+{
+ QList<KGpgRefNode *> ret;
+
+ foreach (KGpgRefNode *nd, m_refs) {
+ if (nd->getType() & type)
+ ret.append(nd);
+ }
+
+ return ret;
+}
+
+QList<KGpgGroupMemberNode *>
+KGpgKeyNode::getGroupRefs(void) const
+{
+ QList<KGpgGroupMemberNode *> ret;
+
+ foreach (KGpgRefNode *rn, getRefsOfType(KgpgCore::ITYPE_GROUP))
+ ret.append(rn->toGroupMemberNode());
+
+ return ret;
+}
+
+KGpgSignNode::List
+KGpgKeyNode::getSignRefs(void) const
+{
+ KGpgSignNode::List ret;
+
+ QList<KGpgRefNode *> 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
new file mode 100644
index 0000000..caf0ba4
--- /dev/null
+++ b/kgpg/KGpgKeyNode.h
@@ -0,0 +1,191 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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<KGpgRefNode *> m_refs;
+ QList<KGpgRefNode *> getRefsOfType(const KgpgCore::KgpgItemType &type) const;
+
+public:
+ typedef QList<KGpgKeyNode *> List;
+ typedef QList<const KGpgKeyNode *> 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<KGpgGroupNode *> getGroups(void) const;
+ /**
+ * @brief returns a list of all group member nodes that reference this key
+ */
+ QList<KGpgGroupMemberNode *> 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
new file mode 100644
index 0000000..18645f8
--- /dev/null
+++ b/kgpg/KGpgNode.cpp
@@ -0,0 +1,337 @@
+/* Copyright 2008,2009,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#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 <KLocale>
+
+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<KGpgExpandableNode *>(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<const KGpgExpandableNode *>(this);
+}
+
+KGpgSignableNode *
+KGpgNode::toSignableNode()
+{
+ Q_ASSERT(getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT));
+
+ return qobject_cast<KGpgSignableNode *>(this);
+}
+
+const KGpgSignableNode *
+KGpgNode::toSignableNode() const
+{
+ Q_ASSERT(getType() & (KgpgCore::ITYPE_PAIR | KgpgCore::ITYPE_SUB | KgpgCore::ITYPE_UID | KgpgCore::ITYPE_UAT));
+
+ return qobject_cast<const KGpgSignableNode *>(this);
+}
+
+KGpgKeyNode *
+KGpgNode::toKeyNode()
+{
+ Q_ASSERT(getType() & KgpgCore::ITYPE_PAIR);
+ Q_ASSERT(!(getType() & KgpgCore::ITYPE_GROUP));
+
+ return qobject_cast<KGpgKeyNode *>(this);
+}
+
+const KGpgKeyNode *
+KGpgNode::toKeyNode() const
+{
+ Q_ASSERT(getType() & KgpgCore::ITYPE_PAIR);
+ Q_ASSERT(!(getType() & KgpgCore::ITYPE_GROUP));
+
+ return qobject_cast<const KGpgKeyNode *>(this);
+}
+
+KGpgRootNode *
+KGpgNode::toRootNode()
+{
+ Q_ASSERT((m_parent == NULL) && (getType() == 0));
+
+ return static_cast<KGpgRootNode *>(this)->asRootNode();
+}
+
+const KGpgRootNode *
+KGpgNode::toRootNode() const
+{
+ Q_ASSERT((m_parent == NULL) && (getType() == 0));
+
+ return static_cast<const KGpgRootNode *>(this)->asRootNode();
+}
+
+KGpgUidNode *
+KGpgNode::toUidNode()
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_UID);
+
+ return static_cast<KGpgUidNode *>(this);
+}
+
+const KGpgUidNode *
+KGpgNode::toUidNode() const
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_UID);
+
+ return static_cast<const KGpgUidNode *>(this);
+}
+
+KGpgSubkeyNode *
+KGpgNode::toSubkeyNode()
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_SUB);
+
+ return static_cast<KGpgSubkeyNode *>(this);
+}
+
+const KGpgSubkeyNode *
+KGpgNode::toSubkeyNode() const
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_SUB);
+
+ return static_cast<const KGpgSubkeyNode *>(this);
+}
+
+KGpgUatNode *
+KGpgNode::toUatNode()
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_UAT);
+
+ return static_cast<KGpgUatNode *>(this);
+}
+
+const KGpgUatNode *
+KGpgNode::toUatNode() const
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_UAT);
+
+ return static_cast<const KGpgUatNode *>(this);
+}
+
+KGpgGroupNode *
+KGpgNode::toGroupNode()
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_GROUP);
+
+ return static_cast<KGpgGroupNode *>(this);
+}
+
+const KGpgGroupNode *
+KGpgNode::toGroupNode() const
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_GROUP);
+
+ return static_cast<const KGpgGroupNode *>(this);
+}
+
+KGpgRefNode *
+KGpgNode::toRefNode()
+{
+ Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)) || (getType() & KgpgCore::ITYPE_SIGN));
+
+ return qobject_cast<KGpgRefNode *>(this);
+}
+
+const KGpgRefNode *
+KGpgNode::toRefNode() const
+{
+ Q_ASSERT(((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR)) || (getType() & KgpgCore::ITYPE_SIGN));
+
+ return qobject_cast<const KGpgRefNode *>(this);
+}
+
+KGpgGroupMemberNode *
+KGpgNode::toGroupMemberNode()
+{
+ Q_ASSERT((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR));
+
+ return static_cast<KGpgGroupMemberNode *>(this);
+}
+
+const KGpgGroupMemberNode *
+KGpgNode::toGroupMemberNode() const
+{
+ Q_ASSERT((getType() & KgpgCore::ITYPE_GROUP) && (getType() & KgpgCore::ITYPE_PAIR));
+
+ return static_cast<const KGpgGroupMemberNode *>(this);
+}
+
+KGpgSignNode *
+KGpgNode::toSignNode()
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_SIGN);
+
+ return static_cast<KGpgSignNode *>(this);
+}
+
+const KGpgSignNode *
+KGpgNode::toSignNode() const
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_SIGN);
+
+ return static_cast<const KGpgSignNode *>(this);
+}
+
+KGpgOrphanNode *
+KGpgNode::toOrphanNode()
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_SECRET);
+
+ return static_cast<KGpgOrphanNode *>(this);
+}
+
+const KGpgOrphanNode *
+KGpgNode::toOrphanNode() const
+{
+ Q_ASSERT(getType() == KgpgCore::ITYPE_SECRET);
+
+ return static_cast<const KGpgOrphanNode *>(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
new file mode 100644
index 0000000..1d89875
--- /dev/null
+++ b/kgpg/KGpgNode.h
@@ -0,0 +1,156 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef KGPGNODE_H
+#define KGPGNODE_H
+
+#include <QPixmap>
+#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<KGpgNode *> 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
new file mode 100644
index 0000000..f245121
--- /dev/null
+++ b/kgpg/KGpgOrphanNode.cpp
@@ -0,0 +1,84 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#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
new file mode 100644
index 0000000..e3b6132
--- /dev/null
+++ b/kgpg/KGpgOrphanNode.h
@@ -0,0 +1,53 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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
new file mode 100644
index 0000000..a67d6b5
--- /dev/null
+++ b/kgpg/KGpgRefNode.cpp
@@ -0,0 +1,151 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgRefNode.h"
+
+//#include <KLocale>
+
+#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
new file mode 100644
index 0000000..f977567
--- /dev/null
+++ b/kgpg/KGpgRefNode.h
@@ -0,0 +1,98 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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
new file mode 100644
index 0000000..416aa0a
--- /dev/null
+++ b/kgpg/KGpgRootNode.cpp
@@ -0,0 +1,189 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgRootNode.h"
+
+#include "KGpgGroupNode.h"
+#include "kgpginterface.h"
+#include "KGpgOrphanNode.h"
+//#include "kgpgsettings.h"
+
+#include <QString>
+#include <QStringList>
+
+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
new file mode 100644
index 0000000..97c597c
--- /dev/null
+++ b/kgpg/KGpgRootNode.h
@@ -0,0 +1,129 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef KGPGROOTNODE_H
+#define KGPGROOTNODE_H
+
+#include "KGpgExpandableNode.h"
+#include "KGpgKeyNode.h"
+
+class KGpgGroupNode;
+class QString;
+class QStringList;
+
+/**
+ * @brief The parent of all key data objects
+ *
+ * This object is invisible to the user but acts as the internal base object for
+ * everything in the keyring. It is anchestor of all other KGpgNode objects and
+ * the only one that will ever return NULL when calling getParentKeyNode() on it.
+ *
+ * There is only one object of this type around at any time.
+ */
+class KGpgRootNode : public KGpgExpandableNode
+{
+ Q_OBJECT
+
+ friend class KGpgGroupNode;
+
+private:
+ int m_groups;
+ int m_deleting;
+
+protected:
+ virtual void readChildren();
+
+public:
+ explicit KGpgRootNode(KGpgItemModel *model);
+ virtual ~KGpgRootNode();
+
+ virtual KgpgCore::KgpgItemType getType() const;
+
+ /**
+ * Create new group nodes
+ * @param groups list of group names to create
+ */
+ void addGroups(const QStringList &groups);
+ void addKeys(const QStringList &ids = QStringList());
+ void refreshKeys(KGpgKeyNode::List nodes);
+ /**
+ * Find a key node with the given id
+ *
+ * This scans the list of primary keys for a key with the given id
+ * and returns the corresponding key node.
+ *
+ * The key id will be matched against the characters given in keyId.
+ * If you give only 8 or 16 byte you will still find the key if it
+ * exists. To be really sure to find the correct node you should pass
+ * the complete fingerprint whenever possible.
+ *
+ * @param keyId the key id to find, any length is permitted
+ * @return pointer to key node or %NULL if no such key
+ */
+ KGpgKeyNode *findKey(const QString &keyId);
+ /**
+ * Return the child number of the key with the given id
+ *
+ * This scans the list of direct children for a key with the given
+ * key id. It returns the number in the internal list of children
+ * which is identical to the row number in the item model. Since
+ * proxy models may sort the items you should only call this function
+ * from the primary model (i.e. KGpgItemModel).
+ *
+ * The key id will be matched against the characters given in keyId.
+ * If you give only 8 or 16 byte you will still find the key if it
+ * exists. To be really sure to find the correct node you should pass
+ * the complete fingerprint whenever possible.
+ *
+ * @param keyId the key id to find, any length is permitted
+ * @return the child number or -1 if there is no such key
+ */
+ int findKeyRow(const QString &keyId);
+
+ /**
+ * Return the child number of the given key
+ * @param key the key to search for
+ *
+ * @overload
+ */
+ int findKeyRow(const KGpgKeyNode *key);
+
+ /**
+ * Return the group count
+ * @return the number of group nodes
+ */
+ int groupChildren() const;
+
+ /**
+ * Return a pointer to this object or NULL
+ *
+ * This returns a pointer to this object if the object will persist,
+ * i.e. is not currently in destruction. If the object is already
+ * cleaning up NULL is returned.
+ */
+ KGpgRootNode *asRootNode();
+ /**
+ * @overload
+ */
+ const KGpgRootNode *asRootNode() const;
+
+Q_SIGNALS:
+ void newKeyNode(KGpgKeyNode *);
+};
+
+#endif /* KGPGROOTNODE_H */
diff --git a/kgpg/KGpgSignNode.cpp b/kgpg/KGpgSignNode.cpp
new file mode 100644
index 0000000..f35bd9a
--- /dev/null
+++ b/kgpg/KGpgSignNode.cpp
@@ -0,0 +1,95 @@
+/* Copyright 2008,2009,2010 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgSignNode.h"
+
+#include "KGpgSignableNode.h"
+
+//#include <KLocale>
+#include <QLocale>
+
+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
new file mode 100644
index 0000000..398ee57
--- /dev/null
+++ b/kgpg/KGpgSignNode.h
@@ -0,0 +1,54 @@
+/* Copyright 2008,2009,2010 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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<KGpgSignNode *> 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
new file mode 100644
index 0000000..e3782c1
--- /dev/null
+++ b/kgpg/KGpgSignableNode.cpp
@@ -0,0 +1,99 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgSignableNode.h"
+
+//#include <KLocale>
+
+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
new file mode 100644
index 0000000..fddae25
--- /dev/null
+++ b/kgpg/KGpgSignableNode.h
@@ -0,0 +1,62 @@
+/* Copyright 2008,2009,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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<KGpgSignableNode *> List;
+ typedef QList<const KGpgSignableNode *> 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
new file mode 100644
index 0000000..571ca35
--- /dev/null
+++ b/kgpg/KGpgSubkeyNode.cpp
@@ -0,0 +1,100 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgSubkeyNode.h"
+
+//#include <KLocale>
+
+#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
new file mode 100644
index 0000000..bbe5ab8
--- /dev/null
+++ b/kgpg/KGpgSubkeyNode.h
@@ -0,0 +1,55 @@
+/* Copyright 2008,2009 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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
new file mode 100644
index 0000000..3457e82
--- /dev/null
+++ b/kgpg/KGpgUatNode.cpp
@@ -0,0 +1,174 @@
+/* Copyright 2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "KGpgUatNode.h"
+
+#include "gpgproc.h"
+#include "KGpgKeyNode.h"
+
+//#include <KLocale>
+//#include <KUrl>
+
+#include <QUrl>
+#include <QDir>
+#include <QFile>
+#include <QPixmap>
+#include <QDateTime>
+
+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
new file mode 100644
index 0000000..b4c6775
--- /dev/null
+++ b/kgpg/KGpgUatNode.h
@@ -0,0 +1,61 @@
+/* Copyright 2008,2009,2010 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef KGPGUATNODE_H
+#define KGPGUATNODE_H
+
+#include "KGpgSignableNode.h"
+
+#include <QDateTime>
+#include <QPixmap>
+
+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
new file mode 100644
index 0000000..0be6c10
--- /dev/null
+++ b/kgpg/KGpgUidNode.cpp
@@ -0,0 +1,146 @@
+/* Copyright 2008,2009,2010 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#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
new file mode 100644
index 0000000..cd1b563
--- /dev/null
+++ b/kgpg/KGpgUidNode.h
@@ -0,0 +1,57 @@
+/* Copyright 2008,2009,2010 Rolf Eike Beer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef 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
new file mode 100644
index 0000000..934ec02
--- /dev/null
+++ b/kgpg/convert.cpp
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2006 Jimmy Gilles <[email protected]>
+ * Copyright (C) 2010 Rolf Eike Beer <[email protected]>
+ */
+/***************************************************************************
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) 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 <KGlobal>
+//#include <KLocale>
+#include <QTranslator>
+//#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
new file mode 100644
index 0000000..96043a8
--- /dev/null
+++ b/kgpg/convert.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2006 Jimmy Gilles <[email protected]>
+ * Copyright (C) 2010 Rolf Eike Beer <[email protected]>
+ */
+/***************************************************************************
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) 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/gpgproc.cpp b/kgpg/gpgproc.cpp
index a834be4..8ed8b45 100644
--- a/kgpg/gpgproc.cpp
+++ b/kgpg/gpgproc.cpp
@@ -160,9 +160,21 @@ GPGProc::resetProcess(const QString &binary)
qDebug() << "bin:" << binary;
- /*if (binary.isEmpty())
- executable = KGpgSettings::gpgBinaryPath();
- else*/
+ if (binary.isEmpty()) {
+ //executable = KGpgSettings::gpgBinaryPath();
+ QString appPath = qApp->applicationDirPath();
+ QString gpgBin;
+ #ifdef Q_WS_WIN
+ gpgBin = appPath + "/bin/gpg.exe";
+ #endif
+ #ifdef Q_WS_MAC
+ gpgBin = appPath + "/bin/gpg-mac.app";
+ #endif
+ #ifdef Q_WS_X11
+ gpgBin = appPath + "/bin/gpg";
+ #endif
+ executable = gpgBin;
+ } else
executable = binary;
if (bin->binary() != executable)
diff --git a/kgpg/gpgproc.h b/kgpg/gpgproc.h
index ce868db..7f9ae9b 100644
--- a/kgpg/gpgproc.h
+++ b/kgpg/gpgproc.h
@@ -15,6 +15,7 @@
#include <QString>
#include <QStringList>
+#include <QApplication>
#include "klinebufferedprocess.h"
diff --git a/kgpg/images.cpp b/kgpg/images.cpp
new file mode 100644
index 0000000..c63dceb
--- /dev/null
+++ b/kgpg/images.cpp
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Jimmy Gilles *
+ * *
+ * 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 <KIconLoader>
+
+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
new file mode 100644
index 0000000..739a618
--- /dev/null
+++ b/kgpg/images.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Jimmy Gilles *
+ * *
+ * 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 <QPixmap>
+
+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/kgpginterface.cpp b/kgpg/kgpginterface.cpp
new file mode 100644
index 0000000..f430a84
--- /dev/null
+++ b/kgpg/kgpginterface.cpp
@@ -0,0 +1,423 @@
+/*
+ * Copyright (C) 2002 Jean-Baptiste Mardelle <[email protected]>
+ * Copyright (C) 2007,2008,2009,2010,2011,2012
+ * Rolf Eike Beer <[email protected]>
+ */
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#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 <KConfig>
+#include <KDebug>
+#include <KGlobal>
+#include <KLocale>
+#include <KMessageBox>
+#include <KPasswordDialog>
+#include <KProcess>
+#include <KPushButton>*/
+#include <QFile>
+#include <QPointer>
+#include <QString>
+#include <QTextStream>
+#include <QDebug>
+
+using namespace KgpgCore;
+
+QString KgpgInterface::getGpgSetting(const QString &name, const QString &configfile)
+{
+ const QString tmp(name.simplified() + QLatin1Char( ' ' ));
+ QFile qfile(configfile);
+
+ if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
+ QTextStream t(&qfile);
+ while (!t.atEnd()) {
+ QString result(t.readLine().simplified());
+ if (result.startsWith(tmp)) {
+ result = result.mid(tmp.length()).simplified();
+ return result.section(QLatin1Char( ' ' ), 0, 0);
+ }
+ }
+ qfile.close();
+ }
+
+ return QString();
+}
+
+void KgpgInterface::setGpgSetting(const QString &name, const QString &value, const QString &url)
+{
+ QFile qfile(url);
+
+ if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
+ const QString temp(name + QLatin1Char( ' ' ));
+ QString texttowrite;
+ bool found = false;
+ QTextStream t(&qfile);
+
+ while (!t.atEnd()) {
+ QString result = t.readLine();
+ if (result.simplified().startsWith(temp)) {
+ if (!value.isEmpty())
+ result = temp + QLatin1Char( ' ' ) + value;
+ else
+ result.clear();
+ found = true;
+ }
+
+ texttowrite += result + QLatin1Char( '\n' );
+ }
+
+ qfile.close();
+ if ((!found) && (!value.isEmpty()))
+ texttowrite += QLatin1Char( '\n' ) + temp + QLatin1Char( ' ' ) + value;
+
+ if (qfile.open(QIODevice::WriteOnly)) {
+ QTextStream t(&qfile);
+ t << texttowrite;
+ qfile.close();
+ }
+ }
+}
+
+bool KgpgInterface::getGpgBoolSetting(const QString &name, const QString &configfile)
+{
+ QFile qfile(configfile);
+ if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
+ QTextStream t(&qfile);
+ while (!t.atEnd()) {
+ if (t.readLine().simplified().startsWith(name))
+ return true;
+ }
+ qfile.close();
+ }
+ return false;
+}
+
+void KgpgInterface::setGpgBoolSetting(const QString &name, const bool enable, const QString &url)
+{
+ QFile qfile(url);
+
+ if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
+ QString texttowrite;
+ bool found = false;
+ QTextStream t(&qfile);
+
+ while (!t.atEnd()) {
+ QString result(t.readLine());
+
+ if (result.simplified().startsWith(name)) {
+ if (enable)
+ result = name;
+ else
+ result.clear();
+
+ found = true;
+ }
+
+ texttowrite += result + QLatin1Char( '\n' );
+ }
+ qfile.close();
+
+ if ((!found) && (enable))
+ texttowrite += name;
+
+ if (qfile.open(QIODevice::WriteOnly)) {
+ QTextStream t(&qfile);
+ t << texttowrite;
+ qfile.close();
+ }
+ }
+}
+
+/*int KgpgInterface::sendPassphrase(const QString &text, KProcess *process, QWidget *widget)
+{
+ QPointer<KProcess> gpgprocess = process;
+ QByteArray passphrase;
+ int code;
+
+ QPointer<KPasswordDialog> dlg = new KPasswordDialog(widget);
+ QObject::connect(process, SIGNAL(processExited()), dlg->button(KDialog::Cancel), SLOT(click()));
+ dlg->setPrompt(text);
+ code = dlg->exec();
+ if (!dlg.isNull())
+ passphrase = dlg->password().toUtf8();
+ delete dlg;
+
+ if (code != KPasswordDialog::Accepted)
+ return 1;
+
+ if (!gpgprocess.isNull())
+ gpgprocess->write(passphrase + '\n');
+
+ return 0;
+}*/
+
+/**
+ * @param p the process that reads the GnuPG data
+ * @param readNode the node where the signatures are read for
+ */
+static KgpgCore::KgpgKeyList
+readPublicKeysProcess(GPGProc &p, KGpgKeyNode *readNode)
+{
+ QStringList lsp;
+ int items;
+ KgpgCore::KgpgKeyList publiclistkeys;
+ KgpgCore::KgpgKey *publickey = NULL;
+ unsigned int idIndex = 0;
+ QString log;
+ KGpgSignableNode *currentSNode = NULL; ///< the current (sub)node signatures are read for
+
+ while ((items = p.readln(lsp)) >= 0) {
+ if ((lsp.at(0) == QLatin1String( "pub" )) && (items >= 10)) {
+ publiclistkeys << KgpgKey(lsp.at(4), lsp.at(2).toUInt(), Convert::toTrust(lsp.at(1)),
+ Convert::toAlgo(lsp.at(3).toInt()), QDateTime::fromTime_t(lsp.at(5).toUInt()));
+
+ publickey = &publiclistkeys.last();
+
+ publickey->setOwnerTrust(Convert::toOwnerTrust(lsp.at(8)));
+
+ if (lsp.at(6).isEmpty())
+ publickey->setExpiration(QDateTime());
+ else
+ publickey->setExpiration(QDateTime::fromTime_t(lsp.at(6).toUInt()));
+
+ publickey->setValid((items <= 11) || !lsp.at(11).contains(QLatin1Char( 'D' ), Qt::CaseSensitive)); // disabled key
+
+ idIndex = 0;
+ } else if ((lsp.at(0) == QLatin1String( "fpr" )) && (items >= 10)) {
+ const QString fingervalue(lsp.at(9));
+
+ publickey->setFingerprint(fingervalue);
+ } else if ((lsp.at(0) == QLatin1String( "sub" )) && (items >= 7)) {
+ KgpgSubKeyType subtype;
+
+ if (items > 11) {
+ if (lsp.at(11).contains(QLatin1Char( 's' )))
+ subtype |= SKT_SIGNATURE;
+ if (lsp.at(11).contains(QLatin1Char( 'e' )))
+ subtype |= SKT_ENCRYPTION;
+ if (lsp.at(11).contains(QLatin1Char( 'e' )))
+ subtype |= SKT_AUTHENTICATION;
+ if (lsp.at(11).contains(QLatin1Char( 'e' )))
+ subtype |= SKT_CERTIFICATION;
+ }
+
+ KgpgKeySub sub(lsp.at(4), lsp.at(2).toUInt(), Convert::toTrust(lsp.at(1)),
+ Convert::toAlgo(lsp.at(3).toInt()), subtype, QDateTime::fromTime_t(lsp.at(5).toUInt()));
+
+ // FIXME: Please see kgpgkey.h, KgpgSubKey class
+ if (items <= 11)
+ sub.setValid(true);
+ else
+ sub.setValid(!lsp.at(11).contains(QLatin1Char( 'D' )));
+
+ if (lsp.at(6).isEmpty())
+ sub.setExpiration(QDateTime());
+ else
+ sub.setExpiration(QDateTime::fromTime_t(lsp.at(6).toUInt()));
+
+ publickey->subList()->append(sub);
+ if (readNode == NULL)
+ currentSNode = NULL;
+ else
+ currentSNode = new KGpgSubkeyNode(readNode, sub);
+ } else if (lsp.at(0) == QLatin1String( "uat" )) {
+ idIndex++;
+ if (readNode != NULL) {
+ currentSNode = new KGpgUatNode(readNode, idIndex, lsp);
+ }
+ } else if ((lsp.at(0) == QLatin1String( "uid" )) && (items >= 10)) {
+ if (idIndex == 0) {
+ QString fullname(lsp.at(9));
+ QString kmail;
+ if (fullname.contains(QLatin1Char( '<' )) ) {
+ kmail = fullname;
+
+ if (fullname.contains(QLatin1Char( ')' )) )
+ kmail = kmail.section(QLatin1Char( ')' ), 1);
+
+ kmail = kmail.section(QLatin1Char( '<' ), 1);
+ kmail.truncate(kmail.length() - 1);
+
+ if (kmail.contains(QLatin1Char( '<' ))) {
+ // several email addresses in the same key
+ kmail = kmail.replace(QLatin1Char( '>' ), QLatin1Char( ';' ));
+ kmail.remove(QLatin1Char( '<' ));
+ }
+ }
+
+ QString kname(fullname.section( QLatin1String( " <" ), 0, 0));
+ QString comment;
+ if (fullname.contains(QLatin1Char( '(' )) ) {
+ kname = kname.section( QLatin1String( " (" ), 0, 0);
+ comment = fullname.section(QLatin1Char( '(' ), 1, 1);
+ comment = comment.section(QLatin1Char( ')' ), 0, 0);
+ }
+
+ idIndex++;
+ publickey->setEmail(kmail);
+ publickey->setComment(comment);
+ publickey->setName(kname);
+
+ currentSNode = readNode;
+ } else {
+ idIndex++;
+ if (readNode != NULL) {
+ currentSNode = new KGpgUidNode(readNode, idIndex, lsp);
+ }
+ }
+ } else if (((lsp.at(0) == QLatin1String( "sig" )) || (lsp.at(0) == QLatin1String( "rev" ))) && (items >= 11)) {
+ // there are no strings here that could have a recoded QLatin1Char( ':' ) in them
+ const QString signature = lsp.join(QLatin1String(":"));
+
+ if (currentSNode != NULL)
+ (void) new KGpgSignNode(currentSNode, lsp);
+ } else {
+ log += lsp.join(QString(QLatin1Char( ':' ))) + QLatin1Char( '\n' );
+ }
+ }
+
+ if (p.exitCode() != 0) {
+// KMessageBox::detailedError(NULL, i18n("An error occurred while scanning your keyring"), log);
+ qDebug() << "An error occurred while scanning your keyring" << " - " << log;
+ log.clear();
+ }
+
+ return publiclistkeys;
+}
+
+KgpgKeyList KgpgInterface::readPublicKeys(const QStringList &ids)
+{
+ GPGProc process;
+ process <<
+ QLatin1String("--with-colons") <<
+ QLatin1String("--with-fingerprint") <<
+ QLatin1String("--fixed-list-mode") <<
+ QLatin1String("--list-keys") <<
+ ids;
+
+ process.setOutputChannelMode(KProcess::MergedChannels);
+
+ process.start();
+ process.waitForFinished(-1);
+ return readPublicKeysProcess(process, NULL);
+}
+
+void KgpgInterface::readSignatures(KGpgKeyNode *node)
+{
+ GPGProc process;
+ process <<
+ QLatin1String("--with-colons") <<
+ QLatin1String("--with-fingerprint") <<
+ QLatin1String("--fixed-list-mode") <<
+ QLatin1String("--list-sigs") <<
+ node->getId();
+
+ process.setOutputChannelMode(KProcess::MergedChannels);
+
+ process.start();
+ process.waitForFinished(-1);
+
+ readPublicKeysProcess(process, node);
+}
+
+static KgpgCore::KgpgKeyList
+readSecretKeysProcess(GPGProc &p)
+{
+ QStringList lsp;
+ int items;
+ bool hasuid = true;
+ KgpgCore::KgpgKeyList result;
+ KgpgCore::KgpgKey *secretkey = NULL;
+
+ while ( (items = p.readln(lsp)) >= 0 ) {
+ if ((lsp.at(0) == QLatin1String( "sec" )) && (items >= 10)) {
+ result << KgpgKey(lsp.at(4), lsp.at(2).toUInt(), Convert::toTrust(lsp.at(1)),
+ Convert::toAlgo(lsp.at(3).toInt()), QDateTime::fromTime_t(lsp.at(5).toUInt()));
+
+ secretkey = &result.last();
+
+ secretkey->setSecret(true);
+
+ if (lsp.at(6).isEmpty())
+ secretkey->setExpiration(QDateTime());
+ else
+ secretkey->setExpiration(QDateTime::fromTime_t(lsp.at(6).toUInt()));
+ hasuid = true;
+ } else if ((lsp.at(0) == QLatin1String( "uid" )) && (items >= 10)) {
+ if (hasuid)
+ continue;
+
+ hasuid = true;
+
+ const QString fullname(lsp.at(9));
+ if (fullname.contains(QLatin1Char( '<' ) )) {
+ QString kmail(fullname);
+
+ if (fullname.contains(QLatin1Char( ')' ) ))
+ kmail = kmail.section(QLatin1Char( ')' ), 1);
+
+ kmail = kmail.section(QLatin1Char( '<' ), 1);
+ kmail.truncate(kmail.length() - 1);
+
+ if (kmail.contains(QLatin1Char( '<' ) )) { // several email addresses in the same key
+ kmail = kmail.replace(QLatin1Char( '>' ), QLatin1Char( ';' ));
+ kmail.remove(QLatin1Char( '<' ));
+ }
+
+ secretkey->setEmail(kmail);
+ } else {
+ secretkey->setEmail(QString());
+ }
+
+ QString kname(fullname.section( QLatin1String( " <" ), 0, 0));
+ if (fullname.contains(QLatin1Char( '(' ) )) {
+ kname = kname.section( QLatin1String( " (" ), 0, 0);
+ QString comment = fullname.section(QLatin1Char( '(' ), 1, 1);
+ comment = comment.section(QLatin1Char( ')' ), 0, 0);
+
+ secretkey->setComment(comment);
+ } else {
+ secretkey->setComment(QString());
+ }
+ secretkey->setName(kname);
+ } else if ((lsp.at(0) == QLatin1String( "fpr" )) && (items >= 10)) {
+ secretkey->setFingerprint(lsp.at(9));
+ }
+ }
+
+ return result;
+}
+
+KgpgKeyList KgpgInterface::readSecretKeys(const QStringList &ids)
+{
+ GPGProc process;
+ process <<
+ QLatin1String("--with-colons") <<
+ QLatin1String("--list-secret-keys") <<
+ QLatin1String("--with-fingerprint") <<
+ QLatin1String("--fixed-list-mode") <<
+ ids;
+
+ process.start();
+ process.waitForFinished(-1);
+ KgpgCore::KgpgKeyList result = readSecretKeysProcess(process);
+
+ return result;
+}
+
+//#include "kgpginterface.moc"
diff --git a/kgpg/kgpginterface.h b/kgpg/kgpginterface.h
new file mode 100644
index 0000000..7a289ec
--- /dev/null
+++ b/kgpg/kgpginterface.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2002 Jean-Baptiste Mardelle <[email protected]>
+ * Copyright (C) 2007,2008,2009,2010,2011,2012
+ * Rolf Eike Beer <[email protected]>
+ */
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KGPGINTERFACE_H
+#define KGPGINTERFACE_H
+
+#include "kgpgkey.h"
+#include <QStringList>
+
+class KGpgKeyNode;
+class KProcess;
+class QString;
+class QApplication;
+
+/**
+ * GnuPG interface functions
+ */
+namespace KgpgInterface {
+ QString getGpgSetting(const QString &name, const QString &configfile);
+ void setGpgSetting(const QString &name, const QString &value, const QString &url);
+
+ bool getGpgBoolSetting(const QString &name, const QString &configfile);
+ void setGpgBoolSetting(const QString &name, const bool enable, const QString &url);
+
+ /**
+ * @brief ask the user for a passphrase and send it to the given gpg process
+ * @param text text is the message that must be displayed in the MessageBox
+ * @param process GnuPG process
+ * @param isnew if the password is a \e new password that must be confirmed. Default is true
+ * @param widget parent widget of this dialog or NULL
+ * @return 0 if there is no error
+ * @return 1 if there is an error
+ */
+ int sendPassphrase(const QString &text, KProcess *process, QWidget *widget = NULL);
+
+ KgpgCore::KgpgKeyList readPublicKeys(const QStringList &ids = QStringList());
+ void readSignatures(KGpgKeyNode *node);
+ KgpgCore::KgpgKeyList readSecretKeys(const QStringList &ids = QStringList());
+};
+
+#endif // KGPGINTERFACE_H
diff --git a/kgpg/kgpgkey.cpp b/kgpg/kgpgkey.cpp
new file mode 100644
index 0000000..57ed820
--- /dev/null
+++ b/kgpg/kgpgkey.cpp
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) 2006,2007 Jimmy Gilles <[email protected]>
+ * Copyright (C) 2007,2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ */
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "kgpgkey.h"
+
+#include "convert.h"
+
+//#include <KLocale>
+
+#include <QStringList>
+
+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
new file mode 100644
index 0000000..f16907c
--- /dev/null
+++ b/kgpg/kgpgkey.h
@@ -0,0 +1,327 @@
+/*
+ * Copyright (C) 2006,2007 Jimmy Gilles <[email protected]>
+ * Copyright (C) 2007,2008,2009,2010,2012 Rolf Eike Beer <[email protected]>
+ */
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KGPGKEY_H
+#define KGPGKEY_H
+
+#include <QSharedDataPointer>
+#include <QSharedData>
+#include <QPointer>
+#include <QObject>
+#include <QList>
+#include <QDateTime>
+
+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<KgpgKeySubPrivate> d;
+};
+
+class KgpgKeySubList : public QList<KgpgKeySub>, public QObject
+{
+public:
+ inline KgpgKeySubList() { }
+ inline explicit KgpgKeySubList(const KgpgKeySub &sub) { append(sub); }
+ inline KgpgKeySubList(const KgpgKeySubList &other) : QList<KgpgKeySub>(other), QObject() { }
+ inline KgpgKeySubList(const QList<KgpgKeySub> &other) : QList<KgpgKeySub>(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<KgpgKeySubList> 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<KgpgKeyPrivate> d;
+};
+
+class KgpgKeyList : public QList<KgpgKey>, public QObject
+{
+public:
+ inline KgpgKeyList() { }
+ inline explicit KgpgKeyList(const KgpgKey &key) { append(key); }
+ inline KgpgKeyList(const KgpgKeyList &other) : QList<KgpgKey>(other), QObject() { }
+ inline KgpgKeyList(const QList<KgpgKey> &other) : QList<KgpgKey>(other), QObject() { }
+
+ inline KgpgKeyList& operator=(const KgpgKeyList &other)
+ {
+ QList<KgpgKey>::operator=(static_cast<const QList<KgpgKey> >(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