Commit 3f86a667 authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

Make signatures store a reference to their master.

This allows to immediately invalidate all signatures from a deleted key without 
reloading the complete keyring etc. Group members behave the same.

This patch brings only the infrastructure, the benefits we could get all over 
the place will come next.

svn path=/trunk/KDE/kdeutils/kgpg/; revision=787811
parent 3b54a709
......@@ -103,7 +103,8 @@ KGpgRootNode::addKeys(const QStringList &ids)
secretlist.removeAt(index);
}
new KGpgKeyNode(this, key);
KGpgKeyNode *nd = new KGpgKeyNode(this, key);
emit newKeyNode(nd);
}
for (int i = 0; i < secretlist.count(); ++i)
......@@ -151,6 +152,7 @@ KGpgKeyNode::KGpgKeyNode(KGpgExpandableNode *parent, const KgpgKey &k)
KGpgKeyNode::~KGpgKeyNode()
{
emit updated(NULL);
}
KgpgItemType
......@@ -293,22 +295,8 @@ KGpgUidNode::getId() const
}
KGpgSignNode::KGpgSignNode(KGpgExpandableNode *parent, const KgpgKeySign &s)
: KGpgNode(parent), m_sign(new KgpgKeySign(s))
: KGpgRefNode(parent, s.fullId()), m_sign(new KgpgKeySign(s))
{
Q_ASSERT(parent != NULL);
parent->children.append(this);
}
QString
KGpgSignNode::getName() const
{
return m_sign->name();
}
QString
KGpgSignNode::getEmail() const
{
return m_sign->email();
}
QDate
......@@ -329,13 +317,6 @@ KGpgSignNode::getId() const
return m_sign->fullId();
}
bool
KGpgSignNode::isUnknown() const
{
// ugly hack to detect unknown keys
return (m_sign->name().startsWith('[') && m_sign->name().endsWith(']'));
}
KGpgSubkeyNode::KGpgSubkeyNode(KGpgKeyNode *parent, const KgpgKeySub &k)
: KGpgExpandableNode(parent), m_skey(k)
{
......@@ -454,60 +435,134 @@ KGpgGroupNode::readChildren()
new KGpgGroupMemberNode(this, QString(*it));
}
KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, const QString &k)
KGpgRefNode::KGpgRefNode(KGpgExpandableNode *parent, const QString &keyid)
: KGpgNode(parent)
{
KgpgInterface *iface = new KgpgInterface();
KgpgKeyList l = iface->readPublicKeys(true, k);
delete iface;
m_key = new KgpgKey(l.at(0));
KGpgExpandableNode *pt = parent->getParentKeyNode();
while (pt->getParentKeyNode() != NULL)
pt = pt->getParentKeyNode();
KGpgRootNode *root = static_cast<KGpgRootNode *>(pt);
m_keynode = root->findKey(keyid);
if (m_keynode != NULL) {
connect(m_keynode, SIGNAL(updated(KGpgKeyNode *)), this, SLOT(keyUpdated(KGpgKeyNode *)));
} else {
m_id = keyid;
connect(root, SIGNAL(newKeyNode(KGpgKeyNode *)), this, SLOT(keyUpdated(KGpgKeyNode *)));
}
parent->children.append(this);
}
KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, const KGpgKeyNode *k)
KGpgRefNode::KGpgRefNode(KGpgExpandableNode *parent, KGpgKeyNode *key)
: KGpgNode(parent)
{
m_key = new KgpgKey(*k->m_key);
Q_ASSERT(key != NULL);
Q_ASSERT(parent != NULL);
m_keynode = key;
parent->children.append(this);
}
void
KGpgRefNode::keyUpdated(KGpgKeyNode *nkey)
{
KGpgExpandableNode *pt = m_parent->getParentKeyNode();
while (pt->getParentKeyNode() != NULL)
pt = pt->getParentKeyNode();
KGpgRootNode *root = static_cast<KGpgRootNode *>(pt);
if (nkey == NULL) {
m_id = m_keynode->getId();
disconnect(this, SLOT(keyUpdated(KGpgKeyNode *)));
connect(root, SIGNAL(newKeyNode(KGpgKeyNode *)), this, SLOT(keyUpdated(KGpgKeyNode *)));
m_keynode = NULL;
} else if ((m_keynode == NULL) && (nkey->getId().right(m_id.length()) == m_id)) {
m_id.clear();
disconnect(this, SLOT(keyUpdated(KGpgKeyNode *)));
connect(nkey, SIGNAL(updated(KGpgKeyNode *)), this, SLOT(keyUpdated(KGpgKeyNode *)));
m_keynode = nkey;
}
}
QString
KGpgGroupMemberNode::getName() const
KGpgRefNode::getId() const
{
return m_key->name();
if (m_keynode != NULL)
return m_keynode->getId();
else
return m_id;
}
QString
KGpgGroupMemberNode::getEmail() const
KGpgRefNode::getName() const
{
if (m_keynode != NULL)
return m_keynode->getName();
return i18n("[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);
}
KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, const QString &k)
: KGpgRefNode(parent, k)
{
return m_key->email();
}
KGpgGroupMemberNode::KGpgGroupMemberNode(KGpgGroupNode *parent, KGpgKeyNode *k)
: KGpgRefNode(parent, k)
{
}
KgpgKeyTrust KGpgGroupMemberNode::getTrust() const
{
if (m_keynode != NULL)
return m_keynode->getTrust();
return TRUST_NOKEY;
}
KgpgItemType KGpgGroupMemberNode::getType() const
{
if (m_keynode != NULL)
return m_keynode->getType() | ITYPE_GROUP;
return ITYPE_PUBLIC | ITYPE_GROUP;
}
QString
KGpgGroupMemberNode::getSize() const
{
return QString::number(m_key->size());
if (m_keynode != NULL)
return m_keynode->getSize();
return QString();
}
QDate
KGpgGroupMemberNode::getExpiration() const
{
return m_key->expirationDate();
if (m_keynode != NULL)
return m_keynode->getExpiration();
return QDate();
}
QDate
KGpgGroupMemberNode::getCreation() const
{
return m_key->creationDate();
}
QString
KGpgGroupMemberNode::getId() const
{
return m_key->fingerprint();
if (m_keynode != NULL)
return m_keynode->getCreation();
return QDate();
}
KGpgOrphanNode::KGpgOrphanNode(KGpgExpandableNode *parent, const KgpgKey &k)
......
......@@ -63,8 +63,7 @@ public:
class KGpgExpandableNode : public KGpgNode
{
friend class KGpgSignNode;
friend class KGpgGroupMemberNode;
friend class KGpgRefNode;
friend class KGpgSubkeyNode;
protected:
......@@ -90,6 +89,8 @@ public:
class KGpgKeyNode : public KGpgExpandableNode
{
Q_OBJECT
friend class KGpgGroupMemberNode;
private:
......@@ -126,12 +127,17 @@ public:
virtual QString getComment() const
{ return m_key->comment(); }
virtual QString getSignCount() const;
Q_SIGNALS:
void updated(KGpgKeyNode *);
};
typedef QList<KGpgKeyNode *> KGpgKeyNodeList;
class KGpgRootNode : public KGpgExpandableNode
{
Q_OBJECT
friend class KGpgGroupNode;
private:
......@@ -156,6 +162,9 @@ public:
int groupChildren() const
{ return m_groups; }
Q_SIGNALS:
void newKeyNode(KGpgKeyNode *);
};
class KGpgUidNode : public KGpgExpandableNode
......@@ -267,33 +276,53 @@ public:
virtual QString getName() const;
};
class KGpgGroupMemberNode : public KGpgNode
class KGpgRefNode: public KGpgNode
{
Q_OBJECT
private:
// this is not what we want. We want a reference to the KGpgNode of that key id.
KgpgKey *m_key;
QString m_id;
protected:
KGpgKeyNode *m_keynode;
explicit KGpgRefNode(KGpgExpandableNode *parent, KGpgKeyNode *key);
explicit KGpgRefNode(KGpgExpandableNode *parent, const QString &keyid);
public:
virtual ~KGpgRefNode()
{ }
virtual QString getId() const;
virtual QString getName() const;
virtual QString getEmail() const;
virtual KGpgKeyNode *getRefNode() const
{ return m_keynode; }
bool isUnknown() const;
private Q_SLOTS:
void keyUpdated(KGpgKeyNode *);
};
class KGpgGroupMemberNode : public KGpgRefNode
{
public:
explicit KGpgGroupMemberNode(KGpgGroupNode *parent, const QString &k);
explicit KGpgGroupMemberNode(KGpgGroupNode *parent, const KGpgKeyNode *k);
explicit KGpgGroupMemberNode(KGpgGroupNode *parent, KGpgKeyNode *k);
virtual ~KGpgGroupMemberNode()
{ delete m_key; }
{ }
virtual KgpgKeyTrust getTrust() const
{ return m_key->trust(); }
virtual KgpgItemType getType() const
{ return KGpgKeyNode::getType(m_key) | ITYPE_GROUP; }
virtual KgpgKeyTrust getTrust() const;
virtual KgpgItemType getType() const;
virtual QString getSize() const;
virtual QString getName() const;
virtual QString getEmail() const;
virtual QDate getExpiration() const;
virtual QDate getCreation() const;
virtual QString getId() const;
virtual KGpgGroupNode *getParentKeyNode() const
{ return static_cast<KGpgGroupNode *>(m_parent); }
};
class KGpgSignNode : public KGpgNode
class KGpgSignNode : public KGpgRefNode
{
private:
KgpgKeySign *m_sign;
......@@ -305,15 +334,11 @@ public:
virtual KgpgItemType getType() const
{ return ITYPE_SIGN; }
virtual QString getName() const;
virtual QString getEmail() const;
virtual QDate getExpiration() const;
virtual QDate getCreation() const;
virtual QString getId() const;
virtual QString getComment() const
{ return m_sign->comment(); }
bool isUnknown() const;
};
class KGpgOrphanNode : public KGpgNode
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment