aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/xbel.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-11-15 17:02:39 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2019-11-15 17:02:39 +0200
commit6e89bf230725e59e71a3273bf8492ed0a2066716 (patch)
tree972e83be6577900b938768f68125e9e83bcad9ca /lib/bookmarks/xbel.cpp
parentContext menu: add actions for MediaTypeNone (diff)
downloadsmolbote-6e89bf230725e59e71a3273bf8492ed0a2066716.tar.xz
Bookmarks: move xbel implementation to formats/
Diffstat (limited to 'lib/bookmarks/xbel.cpp')
-rw-r--r--lib/bookmarks/xbel.cpp110
1 files changed, 0 insertions, 110 deletions
diff --git a/lib/bookmarks/xbel.cpp b/lib/bookmarks/xbel.cpp
deleted file mode 100644
index 1cb5756..0000000
--- a/lib/bookmarks/xbel.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "xbel.h"
-#include "model/bookmarkitem.h"
-#include <QXmlStreamReader>
-#include <QXmlStreamWriter>
-
-inline void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent)
-{
- while(reader.readNextStartElement()) {
- if(reader.name() == "title") {
- parent->setData(BookmarkItem::Title, reader.readElementText());
-
- } else if(reader.name() == "tags") {
- parent->setData(BookmarkItem::Tags, reader.readElementText().split(";"));
-
- } else if(reader.name() == "description") {
- parent->setData(BookmarkItem::Description, 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 Xbel::read(QIODevice *device, BookmarkItem *item)
-{
- QXmlStreamReader qXmlStreamReader(device);
-
- if(qXmlStreamReader.readNextStartElement()) {
- if(!(qXmlStreamReader.name() == "xbel" && qXmlStreamReader.attributes().value("version") == "1.0")) {
- return;
- }
-
- readChildElements(qXmlStreamReader, item);
- }
-}
-
-inline void writeChildElements(QXmlStreamWriter &writer, const BookmarkItem *item)
-{
- switch(item->type()) {
- case BookmarkItem::Root:
- for(int i = 0; i < item->childCount(); ++i) {
- writeChildElements(writer, item->child(i));
- }
- break;
-
- case BookmarkItem::Folder:
- writer.writeStartElement("folder");
- writer.writeAttribute("folded", !item->isExpanded() ? "yes" : "no");
- writer.writeTextElement("title", item->data(BookmarkItem::Title).toString());
- if(!item->data(BookmarkItem::Tags).isNull())
- writer.writeTextElement("tags", item->data(BookmarkItem::Tags).toStringList().join(";"));
- if(!item->data(BookmarkItem::Description).isNull())
- writer.writeTextElement("description", item->data(BookmarkItem::Description).toString());
-
- for(int i = 0; i < item->childCount(); ++i) {
- writeChildElements(writer, item->child(i));
- }
-
- writer.writeEndElement();
- break;
-
- case BookmarkItem::Bookmark:
- writer.writeStartElement("bookmark");
- writer.writeAttribute("href", item->data(BookmarkItem::Href).toString());
- writer.writeTextElement("title", item->data(BookmarkItem::Title).toString());
- if(!item->data(BookmarkItem::Tags).isNull())
- writer.writeTextElement("tags", item->data(BookmarkItem::Tags).toStringList().join(";"));
- if(!item->data(BookmarkItem::Description).isNull())
- writer.writeTextElement("description", item->data(BookmarkItem::Description).toString());
-
- writer.writeEndElement();
- break;
- }
-}
-
-void Xbel::write(QIODevice *device, const BookmarkItem *item)
-{
- QXmlStreamWriter xmlWriter(device);
- xmlWriter.setAutoFormatting(true);
-
- xmlWriter.writeStartDocument();
- xmlWriter.writeDTD("<!DOCTYPE xbel>");
-
- xmlWriter.writeStartElement("xbel");
- xmlWriter.writeAttribute("version", "1.0");
-
- writeChildElements(xmlWriter, item);
-
- xmlWriter.writeEndDocument();
-}