aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/xbel.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-09-24 14:55:35 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-09-24 14:55:35 +0200
commit579c713959c150a276f42b3f69ccfb89d9e6eebb (patch)
tree7c4f2082e2ff5dcdee7fcfe7887e7bbc82ec8bf6 /lib/bookmarks/xbel.cpp
parentAdd bookmark auto-save (5min) (diff)
downloadsmolbote-579c713959c150a276f42b3f69ccfb89d9e6eebb.tar.xz
Bookmarks: add BookmarkItem and BookmarkModel
- read-only xbel - only enabled in debug build
Diffstat (limited to 'lib/bookmarks/xbel.cpp')
-rw-r--r--lib/bookmarks/xbel.cpp40
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);