diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-04-15 08:04:38 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-04-15 08:04:38 +0000 |
| commit | c0e76a9646b63f8135b6a4c5774c353fc7842c83 (patch) | |
| tree | dc0943c64dddebfbff629e603d56d12f41a54b91 /source | |
| parent | 9720d62c6d626fc8ef14e0fb1964ba8686e603b1 (diff) | |
| download | qxmpp-c0e76a9646b63f8135b6a4c5774c353fc7842c83.tar.gz | |
move QXmppRosterIq parsing out of QXmppStream
Diffstat (limited to 'source')
| -rw-r--r-- | source/QXmppRosterIq.cpp | 31 | ||||
| -rw-r--r-- | source/QXmppRosterIq.h | 5 | ||||
| -rw-r--r-- | source/QXmppStream.cpp | 35 |
3 files changed, 19 insertions, 52 deletions
diff --git a/source/QXmppRosterIq.cpp b/source/QXmppRosterIq.cpp index 46fa6bc1..4ae4fa13 100644 --- a/source/QXmppRosterIq.cpp +++ b/source/QXmppRosterIq.cpp @@ -28,22 +28,6 @@ #include "QXmppConstants.h" #include "QXmppUtils.h" -QXmppRosterIq::QXmppRosterIq(QXmppIq::Type type) - : QXmppIq(type) -{ - -} - -QXmppRosterIq::QXmppRosterIq(const QString& type) - : QXmppIq(type) -{ -} - -QXmppRosterIq::~QXmppRosterIq() -{ - -} - void QXmppRosterIq::addItem(const Item& item) { m_items.append(item); @@ -54,6 +38,11 @@ QList<QXmppRosterIq::Item> QXmppRosterIq::items() const return m_items; } +bool QXmppRosterIq::isRosterIq(const QDomElement &element) +{ + return (element.firstChildElement("query").namespaceURI() == ns_roster); +} + void QXmppRosterIq::parse(const QDomElement &element) { QXmppStanza::parse(element); @@ -71,8 +60,14 @@ void QXmppRosterIq::parse(const QDomElement &element) itemElement.attribute("subscription")); item.setSubscriptionStatus( itemElement.attribute("ask")); - item.addGroup( - itemElement.firstChildElement("group").firstChildElement().text()); + + QDomElement groupElement = itemElement.firstChildElement("group"); + while(!groupElement.isNull()) + { + item.addGroup(groupElement.text()); + groupElement = groupElement.nextSiblingElement("group"); + } + m_items.append(item); itemElement = itemElement.nextSiblingElement(); } diff --git a/source/QXmppRosterIq.h b/source/QXmppRosterIq.h index 66e113f7..9e491623 100644 --- a/source/QXmppRosterIq.h +++ b/source/QXmppRosterIq.h @@ -79,13 +79,10 @@ public: QSet<QString> m_groups; }; - QXmppRosterIq(QXmppIq::Type type); - QXmppRosterIq(const QString& type); - ~QXmppRosterIq(); - void addItem(const Item&); QList<Item> items() const; + static bool isRosterIq(const QDomElement &element); void parse(const QDomElement &element); void toXmlElementFromChild(QXmlStreamWriter *writer) const; diff --git a/source/QXmppStream.cpp b/source/QXmppStream.cpp index f896f8ee..5f843f4c 100644 --- a/source/QXmppStream.cpp +++ b/source/QXmppStream.cpp @@ -553,36 +553,10 @@ void QXmppStream::parser(const QByteArray& data) processBindIq(bind); iqPacket = bind; } - else if(nodeRecv.firstChildElement("query"). - namespaceURI() == ns_roster) + else if(QXmppRosterIq::isRosterIq(nodeRecv)) { - QDomElement itemElement = nodeRecv. - firstChildElement("query"). - firstChildElement("item"); - QXmppRosterIq rosterIq(nodeRecv.attribute("type")); - rosterIq.setId(id); - rosterIq.setTo(to); - rosterIq.setFrom(from); - while(!itemElement.isNull()) - { - QXmppRosterIq::Item item; - item.setName(itemElement.attribute("name")); - item.setBareJid(itemElement.attribute("jid")); - item.setSubscriptionTypeFromStr( - itemElement.attribute("subscription")); - item.setSubscriptionStatus( - itemElement.attribute("ask")); - - QDomElement groupElement = itemElement.firstChildElement("group"); - while(!groupElement.isNull()) - { - item.addGroup(groupElement.text()); - groupElement = groupElement.nextSiblingElement("group"); - } - - rosterIq.addItem(item); - itemElement = itemElement.nextSiblingElement(); - } + QXmppRosterIq rosterIq; + rosterIq.parse(nodeRecv); processRosterIq(rosterIq); iqPacket = rosterIq; } @@ -1029,7 +1003,8 @@ void QXmppStream::sendSubscriptionRequest(const QString& to) void QXmppStream::sendRosterRequest() { - QXmppRosterIq roster(QXmppIq::Get); + QXmppRosterIq roster; + roster.setType(QXmppIq::Get); roster.setFrom(getConfiguration().jid()); m_rosterReqId = roster.id(); sendPacket(roster); |
