diff options
author | axis <qt-info@nokia.com> | 2009-08-19 09:24:04 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-08-19 09:24:04 (GMT) |
commit | 2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65 (patch) | |
tree | 24dae3a4532870d61282841f6bb186cb008ab747 /demos/browser | |
parent | b3a3652abbf1cb4ebba6c6257ecf47f8dc022d93 (diff) | |
parent | 20d2b7312456435e5e1a98dba7c2cc96b44fe83c (diff) | |
download | Qt-2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65.zip Qt-2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65.tar.gz Qt-2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts:
tests/auto/auto.pro
Diffstat (limited to 'demos/browser')
-rw-r--r-- | demos/browser/xbel.cpp | 109 | ||||
-rw-r--r-- | demos/browser/xbel.h | 1 |
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); |