aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/formats/ffjson.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bookmarks/formats/ffjson.cpp')
-rw-r--r--lib/bookmarks/formats/ffjson.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/bookmarks/formats/ffjson.cpp b/lib/bookmarks/formats/ffjson.cpp
new file mode 100644
index 0000000..f173904
--- /dev/null
+++ b/lib/bookmarks/formats/ffjson.cpp
@@ -0,0 +1,45 @@
+/*
+ * 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 "ffjson.h"
+#include "bookmarkitem.h"
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonArray>
+#include <QDebug>
+
+void readChildElements(const QJsonObject &object, BookmarkItem *item)
+{
+ for(const auto c : object["children"].toArray()) {
+ const auto child = c.toObject();
+ const auto type = child["type"].toString();
+
+ if(type == "text/x-moz-place-container") {
+ auto *childItem = new BookmarkItem({}, BookmarkItem::Folder, item);
+ childItem->setExpanded(true);
+ childItem->setData(BookmarkItem::Title, child["title"].toString());
+ item->appendChild(childItem);
+ readChildElements(child, childItem);
+
+ } else if(type == "text/x-moz-place") {
+ auto *childItem = new BookmarkItem({}, BookmarkItem::Bookmark, item);
+ childItem->setData(BookmarkItem::Title, child["title"].toString());
+ childItem->setData(BookmarkItem::Href, child["uri"].toString());
+ item->appendChild(childItem);
+
+ } else {
+ qDebug() << "!!! unknown type " << qUtf8Printable(type);
+ }
+ }
+}
+
+void FFJson::read(QIODevice *device, BookmarkItem *item)
+{
+ const auto doc = QJsonDocument::fromJson(device->readAll());
+ readChildElements(doc.object(), item);
+}