[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdeplasma-addons/plasma/sreich/books-runner] runners/books: xml has me stuck. gosh why couldn't thi
From: Shaun Reich <shaun.reich () kdemail ! net>
Date: 2012-02-28 3:33:57
Message-ID: 20120228033357.8810EA60A9 () git ! kde ! org
[Download RAW message or body]
Git commit 941f1fe7c36236dfffbecebbe17324f4819d788f by Shaun Reich.
Committed on 28/02/2012 at 04:33.
Pushed by sreich into branch 'plasma/sreich/books-runner'.
xml has me stuck. gosh why couldn't this just use json...
M +92 -4 runners/books/books.cpp
M +4 -1 runners/books/books.h
http://commits.kde.org/kdeplasma-addons/941f1fe7c36236dfffbecebbe17324f4819d788f
diff --git a/runners/books/books.cpp b/runners/books/books.cpp
index d33439e..c8c67e2 100644
--- a/runners/books/books.cpp
+++ b/runners/books/books.cpp
@@ -30,7 +30,8 @@
#include <QtCore/QWaitCondition>
#include <QtCore/QEventLoop>
#include <QtCore/QMap>
-#include <qjson/parser.h>
+#include <QXmlStreamReader>
+#include <QDomDocument>
Books::Books(QObject *parent, const QVariantList& args)
: Plasma::AbstractRunner(parent, args)
@@ -72,7 +73,7 @@ void Books::match(Plasma::RunnerContext &context)
connect(&booksJob, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
- parseJson(booksJob.data(), context);
+ parseXML(booksJob.data());//, context);
}
void Books::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch \
&match) @@ -81,9 +82,96 @@ void Books::run(const Plasma::RunnerContext &context, \
const Plasma::QueryMatch & opener->setRunExecutables(false);
}
-void Books::parseJson(const QByteArray& data, Plasma::RunnerContext &context)
+void Books::parseXML(QByteArray data)
{
- kDebug() << "XML PARSER ONLINE" << data;
+// QXmlStreamReader xml(data);
+//
+// if (xml.hasError()) {
+// kError() << "Books Runner xml parse failure";
+// return;
+// }
+//
+// while (!xml.atEnd()) {
+// QXmlStreamReader::TokenType token = xml.readNext();
+//
+// if (token == QXmlStreamReader::StartDocument) {
+// continue;
+// }
+//
+// if (token == QXmlStreamReader::StartElement) {
+// kDebug() << "NAME!" << xml.name() ;
+// // if (xml.name() == "results") {
+// parseBook(xml);
+// // return;
+// // }
+// xml.readNext();
+// }
+// }
+
+
+ QXmlStreamReader xml(data);
+
+ while (!xml.atEnd()) {
+ QXmlStreamReader::TokenType token = xml.readNext();
+
+ if (token == QXmlStreamReader::StartDocument) {
+ continue;
+ }
+
+ kDebug() << "TEXT!" << xml.name();
+ ///// xml.readNext();
+ }
}
+void Books::parseBook(QXmlStreamReader& xml)
+{
+ QStringRef name = xml.name();
+ QString currentElement;
+
+ QStringList videoTitles;
+ QStringList videoLinks;
+
+ kDebug() << "NAME: " << name;
+
+ QXmlStreamAttributes attributes = xml.attributes();
+ while (!xml.atEnd()) {// && xml.tokenType() != QXmlStreamReader::EndDocument) {
+ kDebug() << "WHILE LOOP(((((((((((((((((()))))))))))))))))), name: " << \
xml.name(); + kDebug() << "ELEMTN: " << xml.readElementText();
+ kDebug() << "CURRENTELEMENT: " << currentElement;
+
+ if (xml.name() == "title") {
+ kDebug() << attributes.value("plain").toString();
+ }
+
+ if (xml.name() == "thumbnail") {
+ QStringRef attribute = attributes.value("url");
+ kDebug() << "ATTRIBUTE: " << attribute;
+ }
+ // if (name == "title") {
+ // kDebug() << "GOT TITLE: " << name;
+ // videoTitles.append(xml.readElementText());
+ //
+ // } else if (name == "link") {
+ //
+ // if (xml.attributes().value("rel").toString() == \
"alternate") { + // kDebug() << "ATTRIBUTES: " \
<< xml.attributes().value("href"); + // const \
QString& link = xml.attributes().value("href").toString(); + // \
if (link != "http://www.youtube.com") { + // \
videoLinks.append(link); + // }
+ // }
+ // }
+
+ xml.readNext();
+ attributes = xml.attributes();
+ currentElement = xml.readElementText();
+ kDebug() << currentElement;
+ }
+
+ if (!videoTitles.isEmpty() && !videoLinks.isEmpty()) {
+ kDebug() << "TITLE WAS: " << videoTitles;
+ kDebug() << "LINK WAS: " << videoLinks;
+ }
+ }
+
#include "books.moc"
diff --git a/runners/books/books.h b/runners/books/books.h
index 84d049c..ea16428 100644
--- a/runners/books/books.h
+++ b/runners/books/books.h
@@ -26,6 +26,8 @@
#include <KUrl>
#include <QByteArray>
+class QXmlStreamReader;
+
class Books : public Plasma::AbstractRunner {
Q_OBJECT
@@ -40,7 +42,8 @@ Q_SIGNALS:
void matchMade(Plasma::RunnerContext *context);
private:
- void parseJson(const QByteArray& data, Plasma::RunnerContext &context);
+ void parseXML(QByteArray data);
+ void parseBook(QXmlStreamReader& xml);
QNetworkAccessManager *m_thumbnailDownloader;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic