diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-01-16 21:40:15 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-01-16 21:55:45 +0200 |
commit | 198be208d49990c3535ac765735768ad1ae79c1b (patch) | |
tree | 98b3ef03f55e0f08893cdd6713effbf54f10f11f /lib/bookmarks/formats/ffjson.cpp | |
parent | Move BookmarksWidget out of libbookmarks (diff) | |
download | smolbote-198be208d49990c3535ac765735768ad1ae79c1b.tar.xz |
Add Firefox bookmarks.json format to libbookmarks
- can only read folders and bookmarks, their title and uri fields
Not supported by Bookmark Model:
- Separator items
- Date added and Date modified fields
Diffstat (limited to 'lib/bookmarks/formats/ffjson.cpp')
-rw-r--r-- | lib/bookmarks/formats/ffjson.cpp | 45 |
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); +} |