aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bookmarks')
-rw-r--r--lib/bookmarks/bookmarkformat.cpp9
-rw-r--r--lib/bookmarks/bookmarkformat.h4
-rw-r--r--lib/bookmarks/formats/ffjson.cpp45
-rw-r--r--lib/bookmarks/formats/ffjson.h19
-rw-r--r--lib/bookmarks/meson.build2
5 files changed, 75 insertions, 4 deletions
diff --git a/lib/bookmarks/bookmarkformat.cpp b/lib/bookmarks/bookmarkformat.cpp
index e6149cd..87b816c 100644
--- a/lib/bookmarks/bookmarkformat.cpp
+++ b/lib/bookmarks/bookmarkformat.cpp
@@ -8,19 +8,24 @@
#include "bookmarkformat.h"
#include "formats/xbel.h"
+#include "formats/ffjson.h"
#include <QIODevice>
template<>
void BookmarkFormat<BookmarkFormats::XbelFormat>::read(BookmarkItem *root) const
{
- Q_CHECK_PTR(m_device);
Xbel::read(m_device, root);
}
template<>
void BookmarkFormat<BookmarkFormats::XbelFormat>::write(BookmarkItem *root)
{
- Q_CHECK_PTR(m_device);
Xbel::write(m_device, root);
}
+template<>
+void BookmarkFormat<BookmarkFormats::FirefoxJsonFormat>::read(BookmarkItem *root) const
+{
+ FFJson::read(m_device, root);
+}
+
diff --git a/lib/bookmarks/bookmarkformat.h b/lib/bookmarks/bookmarkformat.h
index 673acbd..5cd1860 100644
--- a/lib/bookmarks/bookmarkformat.h
+++ b/lib/bookmarks/bookmarkformat.h
@@ -14,7 +14,8 @@
class QIODevice;
enum BookmarkFormats {
- XbelFormat
+ XbelFormat,
+ FirefoxJsonFormat
};
template<BookmarkFormats format>
@@ -23,6 +24,7 @@ class BookmarkFormat
public:
explicit BookmarkFormat(QIODevice *device)
{
+ Q_CHECK_PTR(m_device);
m_device = device;
}
~BookmarkFormat()
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);
+}
diff --git a/lib/bookmarks/formats/ffjson.h b/lib/bookmarks/formats/ffjson.h
new file mode 100644
index 0000000..cc6ac24
--- /dev/null
+++ b/lib/bookmarks/formats/ffjson.h
@@ -0,0 +1,19 @@
+/*
+ * 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
+ */
+
+#ifndef FFJSON_H
+#define FFJSON_H
+
+class QIODevice;
+class BookmarkItem;
+namespace FFJson
+{
+void read(QIODevice *device, BookmarkItem *item);
+}
+
+#endif // FFJSON_H
diff --git a/lib/bookmarks/meson.build b/lib/bookmarks/meson.build
index a7f603b..81c1ece 100644
--- a/lib/bookmarks/meson.build
+++ b/lib/bookmarks/meson.build
@@ -5,7 +5,7 @@ bookmarks_moc = mod_qt5.preprocess(
bookmarks_lib = static_library('bookmarks',
[ bookmarks_moc,
- 'bookmarkformat.cpp', 'formats/xbel.cpp',
+ 'bookmarkformat.cpp', 'formats/xbel.cpp', 'formats/ffjson.cpp',
'bookmarkitem.cpp', 'bookmarkmodel.cpp' ],
dependencies: dep_qt5
)