summaryrefslogtreecommitdiffstats
path: root/weather/src/xoapweatherresponse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'weather/src/xoapweatherresponse.cpp')
-rw-r--r--weather/src/xoapweatherresponse.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/weather/src/xoapweatherresponse.cpp b/weather/src/xoapweatherresponse.cpp
new file mode 100644
index 0000000..5804bc9
--- /dev/null
+++ b/weather/src/xoapweatherresponse.cpp
@@ -0,0 +1,50 @@
+#include "xoapweatherresponse.h"
+
+#include <QDebug>
+
+static inline int strToInt(const QString &str, int defaultValue)
+{
+ bool ok;
+ int result = str.toInt(&ok);
+ return ok ? result : defaultValue;
+}
+
+static inline QString getNodeContentText(QDomNode node)
+{
+ if (node.childNodes().count() == 0 || !node.childNodes().at(0).isText())
+ return QString();
+ return node.childNodes().at(0).nodeValue();
+}
+
+void XoapWeatherResponse::Item::read(QDomElement element)
+{
+ m_id = element.attribute("id");
+ m_type = strToInt(element.attribute("type"), 0);
+ m_texts.clear();
+ m_texts << getNodeContentText(element).split(",", QString::SkipEmptyParts);
+}
+
+XoapWeatherResponse::XoapWeatherResponse()
+{
+}
+
+void XoapWeatherResponse::read(QDomElement element)
+{
+ m_version = element.attribute("ver");
+ for (int i = 0; i < element.childNodes().count(); ++i) {
+ if (element.childNodes().at(i).isElement()) {
+ Item item;
+ item.read(element.childNodes().at(i).toElement());
+ m_list.append(item);
+ }
+ }
+}
+
+void XoapWeatherResponse::print()
+{
+ /*
+ qDebug() << m_version << m_list.count() << " items";
+ for (int i = 0; i < m_list.count(); ++i)
+ qDebug() << "item " << i << " : " << m_list[i].id() << m_list[i].type() << m_list[i].texts();
+ */
+}