summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-08-18 16:50:12 (GMT)
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-08-18 17:10:56 (GMT)
commit6e7675c8b7af9bd51796552fc4ce75612cbc41c5 (patch)
treeb015c038ee7c3b93629c7ceda3fc3d123c41a497 /demos
parentfdf8956419fc784b458ef1d42c98fde526f9f5d5 (diff)
downloadQt-6e7675c8b7af9bd51796552fc4ce75612cbc41c5.zip
Qt-6e7675c8b7af9bd51796552fc4ce75612cbc41c5.tar.gz
Qt-6e7675c8b7af9bd51796552fc4ce75612cbc41c5.tar.bz2
Made the browser demo use the new QXmlStreamReader functions
Same as in the bookmarks example.
Diffstat (limited to 'demos')
-rw-r--r--demos/browser/xbel.cpp109
-rw-r--r--demos/browser/xbel.h1
2 files changed, 36 insertions, 74 deletions
diff --git a/demos/browser/xbel.cpp b/demos/browser/xbel.cpp
index ed62868..66b49a4 100644
--- a/demos/browser/xbel.cpp
+++ b/demos/browser/xbel.cpp
@@ -133,16 +133,13 @@ BookmarkNode *XbelReader::read(QIODevice *device)
{
BookmarkNode *root = new BookmarkNode(BookmarkNode::Root);
setDevice(device);
- while (!atEnd()) {
- readNext();
- if (isStartElement()) {
- QString version = attributes().value(QLatin1String("version")).toString();
- if (name() == QLatin1String("xbel")
- && (version.isEmpty() || version == QLatin1String("1.0"))) {
- readXBEL(root);
- } else {
- raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
- }
+ if (readNextStartElement()) {
+ QString version = attributes().value(QLatin1String("version")).toString();
+ if (name() == QLatin1String("xbel")
+ && (version.isEmpty() || version == QLatin1String("1.0"))) {
+ readXBEL(root);
+ } else {
+ raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
}
}
return root;
@@ -152,21 +149,15 @@ void XbelReader::readXBEL(BookmarkNode *parent)
{
Q_ASSERT(isStartElement() && name() == QLatin1String("xbel"));
- while (!atEnd()) {
- readNext();
- if (isEndElement())
- break;
-
- if (isStartElement()) {
- if (name() == QLatin1String("folder"))
- readFolder(parent);
- else if (name() == QLatin1String("bookmark"))
- readBookmarkNode(parent);
- else if (name() == QLatin1String("separator"))
- readSeparator(parent);
- else
- skipUnknownElement();
- }
+ while (readNextStartElement()) {
+ if (name() == QLatin1String("folder"))
+ readFolder(parent);
+ else if (name() == QLatin1String("bookmark"))
+ readBookmarkNode(parent);
+ else if (name() == QLatin1String("separator"))
+ readSeparator(parent);
+ else
+ skipCurrentElement();
}
}
@@ -177,26 +168,19 @@ void XbelReader::readFolder(BookmarkNode *parent)
BookmarkNode *folder = new BookmarkNode(BookmarkNode::Folder, parent);
folder->expanded = (attributes().value(QLatin1String("folded")) == QLatin1String("no"));
- while (!atEnd()) {
- readNext();
-
- if (isEndElement())
- break;
-
- if (isStartElement()) {
- if (name() == QLatin1String("title"))
- readTitle(folder);
- else if (name() == QLatin1String("desc"))
- readDescription(folder);
- else if (name() == QLatin1String("folder"))
- readFolder(folder);
- else if (name() == QLatin1String("bookmark"))
- readBookmarkNode(folder);
- else if (name() == QLatin1String("separator"))
- readSeparator(folder);
- else
- skipUnknownElement();
- }
+ while (readNextStartElement()) {
+ if (name() == QLatin1String("title"))
+ readTitle(folder);
+ else if (name() == QLatin1String("desc"))
+ readDescription(folder);
+ else if (name() == QLatin1String("folder"))
+ readFolder(folder);
+ else if (name() == QLatin1String("bookmark"))
+ readBookmarkNode(folder);
+ else if (name() == QLatin1String("separator"))
+ readSeparator(folder);
+ else
+ skipCurrentElement();
}
}
@@ -224,39 +208,18 @@ void XbelReader::readBookmarkNode(BookmarkNode *parent)
Q_ASSERT(isStartElement() && name() == QLatin1String("bookmark"));
BookmarkNode *bookmark = new BookmarkNode(BookmarkNode::Bookmark, parent);
bookmark->url = attributes().value(QLatin1String("href")).toString();
- while (!atEnd()) {
- readNext();
- if (isEndElement())
- break;
-
- if (isStartElement()) {
- if (name() == QLatin1String("title"))
- readTitle(bookmark);
- else if (name() == QLatin1String("desc"))
- readDescription(bookmark);
- else
- skipUnknownElement();
- }
+ while (readNextStartElement()) {
+ if (name() == QLatin1String("title"))
+ readTitle(bookmark);
+ else if (name() == QLatin1String("desc"))
+ readDescription(bookmark);
+ else
+ skipCurrentElement();
}
if (bookmark->title.isEmpty())
bookmark->title = QObject::tr("Unknown title");
}
-void XbelReader::skipUnknownElement()
-{
- Q_ASSERT(isStartElement());
-
- while (!atEnd()) {
- readNext();
-
- if (isEndElement())
- break;
-
- if (isStartElement())
- skipUnknownElement();
- }
-}
-
XbelWriter::XbelWriter()
{
diff --git a/demos/browser/xbel.h b/demos/browser/xbel.h
index 2bdffe1..ec9008e 100644
--- a/demos/browser/xbel.h
+++ b/demos/browser/xbel.h
@@ -87,7 +87,6 @@ public:
BookmarkNode *read(QIODevice *device);
private:
- void skipUnknownElement();
void readXBEL(BookmarkNode *parent);
void readTitle(BookmarkNode *parent);
void readDescription(BookmarkNode *parent);