aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-02-12 09:02:12 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-02-12 09:02:12 +0000
commita6ad55d9c69e7d7b87c02cec81abe3e5f483aba7 (patch)
tree803bfea8473b2e56950c4792635f199a68f701d2 /source
parent903de5cfd0195333e2c34333567b88af6b8cea68 (diff)
downloadqxmpp-a6ad55d9c69e7d7b87c02cec81abe3e5f483aba7.tar.gz
rework service discovery to use a generic QXmppElement
Diffstat (limited to 'source')
-rw-r--r--source/QXmppDiscoveryIq.cpp48
-rw-r--r--source/QXmppDiscoveryIq.h26
-rw-r--r--source/QXmppElement.cpp71
-rw-r--r--source/QXmppElement.h52
-rw-r--r--source/source.pro4
5 files changed, 134 insertions, 67 deletions
diff --git a/source/QXmppDiscoveryIq.cpp b/source/QXmppDiscoveryIq.cpp
index b5cb8d93..0207314f 100644
--- a/source/QXmppDiscoveryIq.cpp
+++ b/source/QXmppDiscoveryIq.cpp
@@ -27,37 +27,12 @@
#include <QDomElement>
-QStringList QXmppDiscoveryItem::attributes() const
-{
- return m_attributes.keys();
-}
-
-QString QXmppDiscoveryItem::attribute(const QString &name) const
-{
- return m_attributes.value(name);
-}
-
-void QXmppDiscoveryItem::setAttribute(const QString &name, const QString &value)
-{
- m_attributes.insert(name, value);
-}
-
-QString QXmppDiscoveryItem::type() const
-{
- return m_type;
-}
-
-void QXmppDiscoveryItem::setType(const QString &type)
-{
- m_type = type;
-}
-
-QList<QXmppDiscoveryItem> QXmppDiscoveryIq::getItems() const
+QList<QXmppElement> QXmppDiscoveryIq::getItems() const
{
return m_items;
}
-void QXmppDiscoveryIq::setItems(const QList<QXmppDiscoveryItem> &items)
+void QXmppDiscoveryIq::setItems(const QList<QXmppElement> &items)
{
m_items = items;
}
@@ -93,15 +68,7 @@ void QXmppDiscoveryIq::parse( QDomElement &element )
QDomElement itemElement = queryElement.firstChildElement();
while (!itemElement.isNull())
{
- QXmppDiscoveryItem item;
- item.setType(itemElement.tagName());
- QDomNamedNodeMap attributes = itemElement.attributes();
- for (int i = 0; i < attributes.size(); i++)
- {
- QDomAttr attr = attributes.item(i).toAttr();
- item.setAttribute(attr.name(), attr.value());
- }
- m_items.append(item);
+ m_items.append(QXmppElement(element));
itemElement = itemElement.nextSiblingElement();
}
}
@@ -111,13 +78,8 @@ void QXmppDiscoveryIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
writer->writeStartElement("query");
helperToXmlAddAttribute(writer, "xmlns",
m_queryType == InfoQuery ? ns_disco_info : ns_disco_items);
- foreach (const QXmppDiscoveryItem &item, m_items)
- {
- writer->writeStartElement(item.type());
- foreach (const QString &attr, item.attributes())
- helperToXmlAddAttribute(writer, attr, item.attribute(attr));
- writer->writeEndElement();
- }
+ foreach (const QXmppElement &item, m_items)
+ item.toXml(writer);
writer->writeEndElement();
}
diff --git a/source/QXmppDiscoveryIq.h b/source/QXmppDiscoveryIq.h
index 31c97630..09dc6d7d 100644
--- a/source/QXmppDiscoveryIq.h
+++ b/source/QXmppDiscoveryIq.h
@@ -24,29 +24,11 @@
#ifndef QXMPPDISCOVERY_H
#define QXMPPDISCOVERY_H
+#include "QXmppElement.h"
#include "QXmppIq.h"
-#include <QMap>
-#include <QStringList>
-
class QDomElement;
-class QXmppDiscoveryItem
-{
-public:
- QStringList attributes() const;
-
- QString attribute(const QString &name) const;
- void setAttribute(const QString &name, const QString &value);
-
- QString type() const;
- void setType(const QString &type);
-
-private:
- QMap<QString, QString> m_attributes;
- QString m_type;
-};
-
class QXmppDiscoveryIq : public QXmppIq
{
public:
@@ -59,14 +41,14 @@ public:
void parse( QDomElement &element );
static bool isDiscoveryIq( QDomElement &element );
- QList<QXmppDiscoveryItem> getItems() const;
- void setItems(const QList<QXmppDiscoveryItem> &items);
+ QList<QXmppElement> getItems() const;
+ void setItems(const QList<QXmppElement> &items);
enum QueryType getQueryType() const;
void setQueryType(enum QueryType type);
private:
- QList<QXmppDiscoveryItem> m_items;
+ QList<QXmppElement> m_items;
enum QueryType m_queryType;
};
diff --git a/source/QXmppElement.cpp b/source/QXmppElement.cpp
new file mode 100644
index 00000000..21571417
--- /dev/null
+++ b/source/QXmppElement.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 Bolloré telecom
+ *
+ * Author:
+ * Jeremy Lainé
+ *
+ * Source:
+ * http://code.google.com/p/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ */
+
+#include "QXmppElement.h"
+#include "QXmppUtils.h"
+
+#include <QDomElement>
+
+QXmppElement::QXmppElement()
+{
+}
+
+QXmppElement::QXmppElement(const QDomElement &element)
+{
+ m_tagName = element.tagName();
+ QDomNamedNodeMap attributes = element.attributes();
+ for (int i = 0; i < attributes.size(); i++)
+ {
+ QDomAttr attr = attributes.item(i).toAttr();
+ m_attributes.insert(attr.name(), attr.value());
+ }
+}
+
+QString QXmppElement::attribute(const QString &name) const
+{
+ return m_attributes.value(name);
+}
+
+void QXmppElement::setAttribute(const QString &name, const QString &value)
+{
+ m_attributes.insert(name, value);
+}
+
+QString QXmppElement::tagName() const
+{
+ return m_tagName;
+}
+
+void QXmppElement::setTagName(const QString &tagName)
+{
+ m_tagName = tagName;
+}
+
+void QXmppElement::toXml(QXmlStreamWriter *writer) const
+{
+ writer->writeStartElement(m_tagName);
+ foreach (const QString &attr, m_attributes.keys())
+ helperToXmlAddAttribute(writer, attr, m_attributes.value(attr));
+ writer->writeEndElement();
+}
+
diff --git a/source/QXmppElement.h b/source/QXmppElement.h
new file mode 100644
index 00000000..ca1159ba
--- /dev/null
+++ b/source/QXmppElement.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Bolloré telecom
+ *
+ * Author:
+ * Jeremy Lainé
+ *
+ * Source:
+ * http://code.google.com/p/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ */
+
+#ifndef QXMPPELEMENT_H
+#define QXMPPELEMENT_H
+
+#include <QMap>
+#include <QString>
+#include <QXmlStreamWriter>
+
+class QDomElement;
+
+class QXmppElement
+{
+public:
+ QXmppElement();
+ QXmppElement(const QDomElement &element);
+
+ QString attribute(const QString &name) const;
+ void setAttribute(const QString &name, const QString &value);
+
+ QString tagName() const;
+ void setTagName(const QString &type);
+
+ void toXml(QXmlStreamWriter *writer) const;
+
+private:
+ QMap<QString, QString> m_attributes;
+ QString m_tagName;
+};
+
+#endif
diff --git a/source/source.pro b/source/source.pro
index 82f4fd19..4926c7bf 100644
--- a/source/source.pro
+++ b/source/source.pro
@@ -14,13 +14,13 @@ else {
# Header files
HEADERS += QXmppUtils.h \
- QXmppArchiveIq.h \
QXmppArchiveManager.h \
QXmppBind.h \
QXmppClient.h \
QXmppConfiguration.h \
QXmppConstants.h \
QXmppDiscoveryIq.h \
+ QXmppElement.h \
QXmppIq.h \
QXmppMessage.h \
QXmppPacket.h \
@@ -48,13 +48,13 @@ HEADERS += QXmppUtils.h \
# Source files
SOURCES += QXmppUtils.cpp \
- QXmppArchiveIq.cpp \
QXmppArchiveManager.cpp \
QXmppBind.cpp \
QXmppClient.cpp \
QXmppConfiguration.cpp \
QXmppConstants.cpp \
QXmppDiscoveryIq.cpp \
+ QXmppElement.cpp \
QXmppIq.cpp \
QXmppMessage.cpp \
QXmppPacket.cpp \