aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-03-17 10:50:05 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-03-17 10:50:05 +0000
commit3219e12750f46d693375f682136fc364fa99a92e (patch)
treee70ee6adf357984f8259a1330760fce58e3525cd /source
parentba0c25c412c88c829075e56b498edb898480b80e (diff)
downloadqxmpp-3219e12750f46d693375f682136fc364fa99a92e.tar.gz
improve XEP-0004 API
Diffstat (limited to 'source')
-rw-r--r--source/QXmppDataForm.cpp25
-rw-r--r--source/QXmppDataForm.h11
2 files changed, 25 insertions, 11 deletions
diff --git a/source/QXmppDataForm.cpp b/source/QXmppDataForm.cpp
index a0915196..f46e4ad1 100644
--- a/source/QXmppDataForm.cpp
+++ b/source/QXmppDataForm.cpp
@@ -63,14 +63,14 @@ void QXmppDataForm::Field::setDescription(const QString &description)
m_description = description;
}
-QString QXmppDataForm::Field::id() const
+QString QXmppDataForm::Field::key() const
{
- return m_id;
+ return m_key;
}
-void QXmppDataForm::Field::setId(const QString &id)
+void QXmppDataForm::Field::setKey(const QString &key)
{
- m_id = id;
+ m_key = key;
}
QString QXmppDataForm::Field::label() const
@@ -173,8 +173,16 @@ void QXmppDataForm::setType(QXmppDataForm::Type type)
m_type = type;
}
+bool QXmppDataForm::isNull() const
+{
+ return m_type == QXmppDataForm::None;
+}
+
void QXmppDataForm::parse(const QDomElement &element)
{
+ if (element.isNull())
+ return;
+
/* form type */
const QString typeStr = element.attribute("type");
if (typeStr == "form")
@@ -188,7 +196,7 @@ void QXmppDataForm::parse(const QDomElement &element)
else
{
qWarning() << "Unknown form type" << typeStr;
- m_type = static_cast<QXmppDataForm::Type>(-1);
+ return;
}
/* form properties */
@@ -218,7 +226,7 @@ void QXmppDataForm::parse(const QDomElement &element)
/* field attributes */
field.setLabel(fieldElement.attribute("label"));
- field.setId(fieldElement.attribute("var"));
+ field.setKey(fieldElement.attribute("var"));
/* field value(s) */
if (type == QXmppDataForm::Field::BooleanField)
@@ -271,6 +279,9 @@ void QXmppDataForm::parse(const QDomElement &element)
void QXmppDataForm::toXml(QXmlStreamWriter *writer) const
{
+ if (isNull())
+ return;
+
writer->writeStartElement("x");
helperToXmlAddAttribute(writer, "xmlns", ns_data);
@@ -313,7 +324,7 @@ void QXmppDataForm::toXml(QXmlStreamWriter *writer) const
/* field attributes */
helperToXmlAddAttribute(writer, "label", field.label());
- helperToXmlAddAttribute(writer, "var", field.id());
+ helperToXmlAddAttribute(writer, "var", field.key());
/* field value(s) */
if (type == QXmppDataForm::Field::BooleanField)
diff --git a/source/QXmppDataForm.h b/source/QXmppDataForm.h
index 91b8ca7a..c33520eb 100644
--- a/source/QXmppDataForm.h
+++ b/source/QXmppDataForm.h
@@ -56,8 +56,8 @@ public:
QString description() const;
void setDescription(const QString &description);
- QString id() const;
- void setId(const QString &id);
+ QString key() const;
+ void setKey(const QString &key);
QString label() const;
void setLabel(const QString &label);
@@ -75,8 +75,8 @@ public:
void setValue(const QVariant &value);
private:
- QString m_id;
QString m_description;
+ QString m_key;
QString m_label;
QList<QPair<QString, QString> > m_options;
bool m_required;
@@ -86,13 +86,14 @@ public:
enum Type
{
+ None,
Form,
Submit,
Cancel,
Result,
};
- QXmppDataForm(QXmppDataForm::Type type = QXmppDataForm::Form);
+ QXmppDataForm(QXmppDataForm::Type type = QXmppDataForm::None);
QString instructions() const;
void setInstructions(const QString &instructions);
@@ -107,6 +108,8 @@ public:
QXmppDataForm::Type type() const;
void setType(QXmppDataForm::Type type);
+ bool isNull() const;
+
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;