diff options
Diffstat (limited to 'lib/bookmarks/xbel.cpp')
-rw-r--r-- | lib/bookmarks/xbel.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/bookmarks/xbel.cpp b/lib/bookmarks/xbel.cpp index cd17f2d..a1bf2f6 100644 --- a/lib/bookmarks/xbel.cpp +++ b/lib/bookmarks/xbel.cpp @@ -8,6 +8,9 @@ #include "xbel.h" #include <QFile> +#include <QAbstractItemModel> +#include "bookmarkitem.h" +#include "bookmarkmodel.h" XbelReader::XbelReader(QIODevice *file) { @@ -38,6 +41,30 @@ void readChildElements(QXmlStreamReader &reader, BookmarksView *widget, QTreeWid } } +void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent) +{ + while(reader.readNextStartElement()) { + if(reader.name() == "title") { + parent->setData(BookmarkItem::Title, reader.readElementText()); + + } else if(reader.name() == "folder") { + auto *item = new BookmarkItem({}, BookmarkItem::Folder, parent); + item->setExpanded(!(reader.attributes().value("folded") == QLatin1Literal("yes"))); + parent->appendChild(item); + readChildElements(reader, item); + + } else if(reader.name() == "bookmark") { + auto *item = new BookmarkItem({}, BookmarkItem::Bookmark, parent); + item->setData(BookmarkItem::Href, reader.attributes().value("href").toString()); + parent->appendChild(item); + readChildElements(reader, item); + + } else { + reader.skipCurrentElement(); + } + } +} + void XbelReader::read(BookmarksView *treeWidget) { QXmlStreamReader qXmlStreamReader(m_file); @@ -51,6 +78,19 @@ void XbelReader::read(BookmarksView *treeWidget) } } +void XbelReader::read(BookmarkModel *model) +{ + QXmlStreamReader qXmlStreamReader(m_file); + + if(qXmlStreamReader.readNextStartElement()) { + if(!(qXmlStreamReader.name() == "xbel" && qXmlStreamReader.attributes().value("version") == "1.0")) { + return; + } + + readChildElements(qXmlStreamReader, model->root()); + } +} + XbelWriter::XbelWriter(QIODevice *file) { Q_CHECK_PTR(file); |