aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/bookmarks/bookmarkformat.cpp (renamed from lib/bookmarks/formats/format.cpp)17
-rw-r--r--lib/bookmarks/bookmarkformat.h65
-rw-r--r--lib/bookmarks/bookmarkitem.cpp (renamed from lib/bookmarks/model/bookmarkitem.cpp)0
-rw-r--r--lib/bookmarks/bookmarkitem.h (renamed from lib/bookmarks/model/bookmarkitem.h)2
-rw-r--r--lib/bookmarks/bookmarkmodel.cpp (renamed from lib/bookmarks/model/bookmarkmodel.cpp)3
-rw-r--r--lib/bookmarks/bookmarkmodel.h (renamed from lib/bookmarks/model/bookmarkmodel.h)0
-rw-r--r--lib/bookmarks/bookmarksform.ui129
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp144
-rw-r--r--lib/bookmarks/bookmarkswidget.h50
-rw-r--r--lib/bookmarks/formats/ffjson.cpp72
-rw-r--r--lib/bookmarks/formats/ffjson.h19
-rw-r--r--lib/bookmarks/formats/format.h36
-rw-r--r--lib/bookmarks/formats/xbel.cpp26
-rw-r--r--lib/bookmarks/forms/editbookmarkdialog.cpp70
-rw-r--r--lib/bookmarks/forms/editbookmarkdialog.h44
-rw-r--r--lib/bookmarks/forms/editbookmarkdialog.ui108
-rw-r--r--lib/bookmarks/meson.build13
17 files changed, 200 insertions, 598 deletions
diff --git a/lib/bookmarks/formats/format.cpp b/lib/bookmarks/bookmarkformat.cpp
index 551151c..87b816c 100644
--- a/lib/bookmarks/formats/format.cpp
+++ b/lib/bookmarks/bookmarkformat.cpp
@@ -6,21 +6,26 @@
* SPDX-License-Identifier: GPL-3.0
*/
-#include "format.h"
-#include "xbel.h"
+#include "bookmarkformat.h"
+#include "formats/xbel.h"
+#include "formats/ffjson.h"
#include <QIODevice>
template<>
-void BookmarksFormat<BookmarksFormats::XbelFormat>::read(BookmarkItem *root)
+void BookmarkFormat<BookmarkFormats::XbelFormat>::read(BookmarkItem *root) const
{
- Q_CHECK_PTR(m_device);
Xbel::read(m_device, root);
}
template<>
-void BookmarksFormat<BookmarksFormats::XbelFormat>::write(BookmarkItem *root)
+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
new file mode 100644
index 0000000..c886546
--- /dev/null
+++ b/lib/bookmarks/bookmarkformat.h
@@ -0,0 +1,65 @@
+/*
+ * 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 BOOKMARKFORMAT_H
+#define BOOKMARKFORMAT_H
+
+#include "bookmarkmodel.h"
+
+class QIODevice;
+
+enum BookmarkFormats {
+ XbelFormat,
+ FirefoxJsonFormat
+};
+
+template<BookmarkFormats format>
+class BookmarkFormat
+{
+public:
+ explicit BookmarkFormat(QIODevice *device)
+ {
+ Q_CHECK_PTR(device);
+ m_device = device;
+ }
+
+ void read(BookmarkItem *root) const;
+ void write(BookmarkItem *root);
+
+protected:
+ QIODevice *m_device;
+};
+
+template<BookmarkFormats T>
+void operator<<(BookmarkModel *model, const BookmarkFormat<T> &format)
+{
+ format.read(model->root());
+}
+
+template<BookmarkFormats T>
+void operator>>(const BookmarkFormat<T> &format, BookmarkModel *model)
+{
+ format.read(model->root());
+}
+
+template<BookmarkFormats T>
+void operator<<(BookmarkFormat<T> &format, BookmarkModel *model)
+{
+ format.write(model->root());
+ model->resetModified();
+}
+
+template<BookmarkFormats T>
+void operator>>(BookmarkModel *model, BookmarkFormat<T> &format)
+{
+ format.write(model->root());
+ model->resetModified();
+}
+
+#endif // BOOKMARKSFORMAT_H
+
diff --git a/lib/bookmarks/model/bookmarkitem.cpp b/lib/bookmarks/bookmarkitem.cpp
index 21d034f..21d034f 100644
--- a/lib/bookmarks/model/bookmarkitem.cpp
+++ b/lib/bookmarks/bookmarkitem.cpp
diff --git a/lib/bookmarks/model/bookmarkitem.h b/lib/bookmarks/bookmarkitem.h
index 8c9463f..6751526 100644
--- a/lib/bookmarks/model/bookmarkitem.h
+++ b/lib/bookmarks/bookmarkitem.h
@@ -27,6 +27,8 @@ public:
Href,
Tags,
Description,
+ DateAdded,
+ LastModified,
FieldCount
};
diff --git a/lib/bookmarks/model/bookmarkmodel.cpp b/lib/bookmarks/bookmarkmodel.cpp
index 895b178..05df3d7 100644
--- a/lib/bookmarks/model/bookmarkmodel.cpp
+++ b/lib/bookmarks/bookmarkmodel.cpp
@@ -12,6 +12,7 @@
#include <QBuffer>
#include <QMimeData>
#include <QRegularExpression>
+#include <QDateTime>
BookmarkModel::BookmarkModel(QObject *parent)
: QAbstractItemModel(parent)
@@ -132,6 +133,7 @@ QModelIndex BookmarkModel::appendBookmark(const QString &title, const QString &u
int row = parentItem->childCount();
beginInsertRows(parent, row, row);
auto *childItem = new BookmarkItem({ title, url }, BookmarkItem::Bookmark, parentItem);
+ childItem->setData(BookmarkItem::DateAdded, QDateTime::currentDateTime());
parentItem->appendChild(childItem);
endInsertRows();
@@ -146,6 +148,7 @@ QModelIndex BookmarkModel::appendFolder(const QString &title, const QModelIndex
beginInsertRows(parent, row, row);
auto *childItem = new BookmarkItem({ title }, BookmarkItem::Folder, parentItem);
+ childItem->setData(BookmarkItem::DateAdded, QDateTime::currentDateTime());
parentItem->appendChild(childItem);
endInsertRows();
diff --git a/lib/bookmarks/model/bookmarkmodel.h b/lib/bookmarks/bookmarkmodel.h
index 300b724..300b724 100644
--- a/lib/bookmarks/model/bookmarkmodel.h
+++ b/lib/bookmarks/bookmarkmodel.h
diff --git a/lib/bookmarks/bookmarksform.ui b/lib/bookmarks/bookmarksform.ui
deleted file mode 100644
index a003e53..0000000
--- a/lib/bookmarks/bookmarksform.ui
+++ /dev/null
@@ -1,129 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>BookmarksDialog</class>
- <widget class="QWidget" name="BookmarksDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>420</width>
- <height>600</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Bookmarks</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QToolButton" name="addFolder_toolButton">
- <property name="text">
- <string>Add Folder</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="addBookmark_toolButton">
- <property name="text">
- <string>Add Bookmark</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="deleteItem_toolButton">
- <property name="text">
- <string>Delete Item</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QTreeView" name="treeView">
- <property name="editTriggers">
- <set>QAbstractItemView::NoEditTriggers</set>
- </property>
- <property name="dragEnabled">
- <bool>true</bool>
- </property>
- <property name="dragDropMode">
- <enum>QAbstractItemView::DragDrop</enum>
- </property>
- <property name="defaultDropAction">
- <enum>Qt::MoveAction</enum>
- </property>
- <attribute name="headerDefaultSectionSize">
- <number>200</number>
- </attribute>
- <attribute name="headerMinimumSectionSize">
- <number>50</number>
- </attribute>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="bookmark_groupBox">
- <property name="title">
- <string>Edit Bookmark</string>
- </property>
- <layout class="QFormLayout" name="formLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="bookmarkTitle_label">
- <property name="text">
- <string>Title</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="bookmarkHref_label">
- <property name="text">
- <string>Address</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="bookmarkTitle"/>
- </item>
- <item row="1" column="1">
- <widget class="QLineEdit" name="bookmarkHref"/>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="folder_groupBox">
- <property name="title">
- <string>Edit Folder</string>
- </property>
- <layout class="QFormLayout" name="formLayout_2">
- <item row="0" column="0">
- <widget class="QLabel" name="folderTitle_label">
- <property name="text">
- <string>Name</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="folderTitle"/>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
deleted file mode 100644
index aed7e97..0000000
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ /dev/null
@@ -1,144 +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 "bookmarkswidget.h"
-#include "forms/editbookmarkdialog.h"
-#include "model/bookmarkitem.h"
-#include "model/bookmarkmodel.h"
-#include "ui_bookmarksform.h"
-#include "formats/format.h"
-#include <QTreeView>
-#include <QUrl>
-
-inline void expandChildren(QTreeView *view, BookmarkModel *model, const QModelIndex &rootIndex)
-{
- for(int i = 0; i < model->rowCount(rootIndex); ++i) {
- QModelIndex idx = model->index(i, 0, rootIndex);
- if(model->isItemExpanded(idx))
- view->expand(idx);
-
- // check if index has children
- if(model->rowCount(idx) > 0)
- expandChildren(view, model, idx);
- }
-}
-
-BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::BookmarksDialog)
-{
- // make sure this dialog does not get deleted on close
- setAttribute(Qt::WA_DeleteOnClose, false);
-
- ui->setupUi(this);
- ui->bookmark_groupBox->setVisible(false);
- ui->folder_groupBox->setVisible(false);
-
- ui->addFolder_toolButton->setIcon(style()->standardPixmap(QStyle::SP_DirIcon));
- ui->addBookmark_toolButton->setIcon(style()->standardPixmap(QStyle::SP_FileIcon));
- ui->deleteItem_toolButton->setIcon(style()->standardPixmap(QStyle::SP_TrashIcon));
- ui->deleteItem_toolButton->setShortcut(QKeySequence::Delete);
-
- model = new BookmarkModel(this);
- m_bookmarksPath = path;
- QFile bookmarksFile(m_bookmarksPath);
- if(bookmarksFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- BookmarksFormat<XbelFormat> format(&bookmarksFile);
- format.read(model->root());
- bookmarksFile.close();
- }
- model->resetModified();
-
- ui->treeView->setModel(model);
- expandChildren(ui->treeView, model, QModelIndex());
-
- // item activated
- connect(ui->treeView, &QTreeView::activated, this, [this](const QModelIndex &index) {
- if(index.column() == 1)
- emit openUrl(index.data(Qt::DisplayRole).toUrl());
- else
- editBookmark(index);
- });
-
- connect(ui->treeView, &QTreeView::expanded, this, [this](const QModelIndex &index) {
- model->setItemExpanded(index, true);
- });
- connect(ui->treeView, &QTreeView::collapsed, this, [this](const QModelIndex &index) {
- model->setItemExpanded(index, false);
- });
-
- ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(ui->treeView, &QTreeView::customContextMenuRequested, this, [this](const QPoint &pos) {
- const QModelIndex idx = ui->treeView->indexAt(pos);
- if(idx.isValid()) {
- const QUrl url = model->data(idx, 1, Qt::DisplayRole).toUrl();
- const QPoint _pos = ui->treeView->viewport()->mapToGlobal(pos);
-
- emit showContextMenu(url, _pos);
- }
- });
-
- // addBookmark
- connect(ui->addBookmark_toolButton, &QToolButton::clicked, this, [this]() {
- const QModelIndex idx = model->parentFolder(ui->treeView->currentIndex());
- const QModelIndex childIdx = model->appendBookmark(tr("Title"), QString(), idx);
- ui->treeView->setCurrentIndex(childIdx);
- editBookmark(childIdx);
- });
-
- // addFolder
- connect(ui->addFolder_toolButton, &QToolButton::clicked, this, [this]() {
- const QModelIndex idx = model->parentFolder(ui->treeView->currentIndex());
- const QModelIndex childIdx = model->appendFolder(tr("Title"), idx);
- ui->treeView->setCurrentIndex(childIdx);
- editBookmark(childIdx);
- });
-
- // deleteItem
- connect(ui->deleteItem_toolButton, &QToolButton::clicked, this, [this]() {
- const QModelIndex idx = ui->treeView->currentIndex();
- model->removeRow(idx.row(), idx.parent());
- });
-}
-
-BookmarksWidget::~BookmarksWidget()
-{
- delete ui;
-}
-
-void BookmarksWidget::editBookmark(const QModelIndex &index)
-{
- auto *dlg = new EditBookmarkDialog(model, index, this);
- dlg->exec();
-}
-
-void BookmarksWidget::save()
-{
- if(!model->isModified())
- return;
-
- QFile bookmarksFile(m_bookmarksPath);
- if(bookmarksFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
- BookmarksFormat<XbelFormat> format(&bookmarksFile);
- format.write(model->root());
- bookmarksFile.flush();
- bookmarksFile.close();
- model->resetModified();
- }
-}
-
-void BookmarksWidget::addBookmark(const QString &title, const QString &url)
-{
- model->appendBookmark(title, url, QModelIndex());
-}
-
-void BookmarksWidget::search(const QString &term, const std::function<void(QStringList &)> &callback) const
-{
- QStringList ret = model->search(term);
- callback(ret);
-}
diff --git a/lib/bookmarks/bookmarkswidget.h b/lib/bookmarks/bookmarkswidget.h
deleted file mode 100644
index 149d2a6..0000000
--- a/lib/bookmarks/bookmarkswidget.h
+++ /dev/null
@@ -1,50 +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
- */
-
-#ifndef BOOKMARKSDIALOG_H
-#define BOOKMARKSDIALOG_H
-
-#include <QFile>
-#include <QShortcut>
-#include <QWidget>
-#include <functional>
-
-namespace Ui
-{
-class BookmarksDialog;
-}
-
-class BookmarksView;
-class BookmarkModel;
-class BookmarksWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit BookmarksWidget(const QString &path, QWidget *parent = nullptr);
- ~BookmarksWidget() override;
-
-protected:
- void editBookmark(const QModelIndex &index);
-
-signals:
- void showContextMenu(const QUrl &url, const QPoint &pos);
- void openUrl(const QUrl &url);
-
-public slots:
- void save();
- void addBookmark(const QString &title, const QString &url);
- void search(const QString &term, const std::function<void(QStringList &)> &callback) const;
-
-private:
- Ui::BookmarksDialog *ui;
- QString m_bookmarksPath;
- BookmarkModel *model;
-};
-
-#endif // BOOKMARKSDIALOG_H
diff --git a/lib/bookmarks/formats/ffjson.cpp b/lib/bookmarks/formats/ffjson.cpp
new file mode 100644
index 0000000..1fe6a96
--- /dev/null
+++ b/lib/bookmarks/formats/ffjson.cpp
@@ -0,0 +1,72 @@
+/*
+ * 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>
+#include <QDateTime>
+
+inline auto asDate(const QJsonValue &v)
+{
+ // timestamps in bookmarks.json are, for some reason, in *micro*seconds
+ return QDateTime::fromMSecsSinceEpoch(v.toVariant().toLongLong() / 1000);
+}
+
+inline void readElementData(const QJsonObject &object, BookmarkItem *item)
+{
+ item->setData(BookmarkItem::Title, object["title"].toString());
+ item->setData(BookmarkItem::DateAdded, asDate(object["dateAdded"]));
+ item->setData(BookmarkItem::LastModified, asDate(object["lastModified"]));
+
+ // tags
+ const auto tags = object["tags"].toString().split(",");
+ if(!tags.isEmpty())
+ item->setData(BookmarkItem::Tags, tags);
+
+ // descriptions
+ for(const auto &a : object["annos"].toArray()) {
+ const auto anno = a.toObject();
+ if(anno["name"] == "bookmarkProperties/description") {
+ item->setData(BookmarkItem::Description, anno["value"].toString());
+ }
+ }
+}
+
+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);
+ readElementData(child, childItem);
+ item->appendChild(childItem);
+ readChildElements(child, childItem);
+
+ } else if(type == "text/x-moz-place") {
+ auto *childItem = new BookmarkItem({}, BookmarkItem::Bookmark, item);
+ readElementData(child, childItem);
+ 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/formats/format.h b/lib/bookmarks/formats/format.h
deleted file mode 100644
index e96dfcc..0000000
--- a/lib/bookmarks/formats/format.h
+++ /dev/null
@@ -1,36 +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
- */
-
-#ifndef BOOKMARKSFORMAT_H
-#define BOOKMARKSFORMAT_H
-
-class QIODevice;
-class BookmarkItem;
-
-enum BookmarksFormats {
- XbelFormat
-};
-
-template<BookmarksFormats format>
-class BookmarksFormat
-{
-public:
- explicit BookmarksFormat(QIODevice *device)
- {
- m_device = device;
- }
-
- void read(BookmarkItem *root);
- void write(BookmarkItem *root);
-
-protected:
- QIODevice *m_device;
-};
-
-#endif // BOOKMARKSFORMAT_H
-
diff --git a/lib/bookmarks/formats/xbel.cpp b/lib/bookmarks/formats/xbel.cpp
index 1cb5756..bac2bc8 100644
--- a/lib/bookmarks/formats/xbel.cpp
+++ b/lib/bookmarks/formats/xbel.cpp
@@ -7,9 +7,10 @@
*/
#include "xbel.h"
-#include "model/bookmarkitem.h"
+#include "bookmarkitem.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
+#include <QDateTime>
inline void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent)
{
@@ -17,6 +18,12 @@ inline void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent)
if(reader.name() == "title") {
parent->setData(BookmarkItem::Title, reader.readElementText());
+ } else if(reader.name() == "dateAdded") {
+ parent->setData(BookmarkItem::DateAdded, QDateTime::fromString(reader.readElementText(), Qt::RFC2822Date));
+
+ } else if(reader.name() == "lastModified") {
+ parent->setData(BookmarkItem::LastModified, QDateTime::fromString(reader.readElementText(), Qt::RFC2822Date));
+
} else if(reader.name() == "tags") {
parent->setData(BookmarkItem::Tags, reader.readElementText().split(";"));
@@ -54,6 +61,19 @@ void Xbel::read(QIODevice *device, BookmarkItem *item)
}
}
+inline void writeCommon(QXmlStreamWriter &writer, const BookmarkItem *item)
+{
+ writer.writeTextElement("title", item->data(BookmarkItem::Title).toString());
+
+ const auto dateAdded = item->data(BookmarkItem::DateAdded);
+ if(!dateAdded.isNull())
+ writer.writeTextElement("dateAdded", dateAdded.toDateTime().toString(Qt::RFC2822Date));
+
+ const auto lastModified = item->data(BookmarkItem::LastModified);
+ if(!lastModified.isNull())
+ writer.writeTextElement("lastModified", lastModified.toDateTime().toString(Qt::RFC2822Date));
+}
+
inline void writeChildElements(QXmlStreamWriter &writer, const BookmarkItem *item)
{
switch(item->type()) {
@@ -66,7 +86,7 @@ inline void writeChildElements(QXmlStreamWriter &writer, const BookmarkItem *ite
case BookmarkItem::Folder:
writer.writeStartElement("folder");
writer.writeAttribute("folded", !item->isExpanded() ? "yes" : "no");
- writer.writeTextElement("title", item->data(BookmarkItem::Title).toString());
+ writeCommon(writer, item);
if(!item->data(BookmarkItem::Tags).isNull())
writer.writeTextElement("tags", item->data(BookmarkItem::Tags).toStringList().join(";"));
if(!item->data(BookmarkItem::Description).isNull())
@@ -82,7 +102,7 @@ inline void writeChildElements(QXmlStreamWriter &writer, const BookmarkItem *ite
case BookmarkItem::Bookmark:
writer.writeStartElement("bookmark");
writer.writeAttribute("href", item->data(BookmarkItem::Href).toString());
- writer.writeTextElement("title", item->data(BookmarkItem::Title).toString());
+ writeCommon(writer, item);
if(!item->data(BookmarkItem::Tags).isNull())
writer.writeTextElement("tags", item->data(BookmarkItem::Tags).toStringList().join(";"));
if(!item->data(BookmarkItem::Description).isNull())
diff --git a/lib/bookmarks/forms/editbookmarkdialog.cpp b/lib/bookmarks/forms/editbookmarkdialog.cpp
deleted file mode 100644
index 9c6efa0..0000000
--- a/lib/bookmarks/forms/editbookmarkdialog.cpp
+++ /dev/null
@@ -1,70 +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 "editbookmarkdialog.h"
-#include "model/bookmarkitem.h"
-#include "model/bookmarkmodel.h"
-#include "ui_editbookmarkdialog.h"
-
-EditBookmarkDialog::EditBookmarkDialog(BookmarkModel *model, const QModelIndex &index, QWidget *parent)
- : QDialog(parent)
- , ui(new Ui::EditBookmarkDialog)
-{
- ui->setupUi(this);
- setAttribute(Qt::WA_DeleteOnClose, true);
-
- Q_CHECK_PTR(model);
- m_model = model;
- m_index = index;
-
- ui->title->setText(model->data(index, BookmarkItem::Title, Qt::DisplayRole).toString());
- connect(ui->title, &QLineEdit::editingFinished, this, [this]() {
- titleChanged = true;
- });
-
- ui->address->setText(model->data(index, BookmarkItem::Href, Qt::DisplayRole).toString());
- connect(ui->address, &QLineEdit::editingFinished, this, [this]() {
- hrefChanged = true;
- });
-
- ui->tags->setText(model->data(index, BookmarkItem::Tags, Qt::DisplayRole).toStringList().join(", "));
- connect(ui->tags, &QLineEdit::editingFinished, this, [this]() {
- tagsChanged = true;
- });
-
- ui->description->setPlainText(model->data(index, BookmarkItem::Description, Qt::DisplayRole).toString());
- connect(ui->description, &QPlainTextEdit::textChanged, this, [this]() {
- descriptionChanged = true;
- });
-
- connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &EditBookmarkDialog::saveChanges);
-}
-
-EditBookmarkDialog::~EditBookmarkDialog()
-{
- delete ui;
-}
-
-void EditBookmarkDialog::saveChanges()
-{
- if(titleChanged) {
- m_model->setData(m_index, ui->title->text(), BookmarkItem::Title, Qt::DisplayRole);
- }
-
- if(hrefChanged) {
- m_model->setData(m_index, ui->address->text(), BookmarkItem::Href, Qt::DisplayRole);
- }
-
- if(tagsChanged) {
- m_model->setData(m_index, ui->tags->text().split(", "), BookmarkItem::Tags, Qt::DisplayRole);
- }
-
- if(descriptionChanged) {
- m_model->setData(m_index, ui->description->toPlainText(), BookmarkItem::Description, Qt::DisplayRole);
- }
-}
diff --git a/lib/bookmarks/forms/editbookmarkdialog.h b/lib/bookmarks/forms/editbookmarkdialog.h
deleted file mode 100644
index fb53239..0000000
--- a/lib/bookmarks/forms/editbookmarkdialog.h
+++ /dev/null
@@ -1,44 +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
- */
-
-#ifndef SMOLBOTE_EDITBOOKMARKDIALOG_H
-#define SMOLBOTE_EDITBOOKMARKDIALOG_H
-
-#include <QDialog>
-#include <QModelIndex>
-
-namespace Ui
-{
-class EditBookmarkDialog;
-}
-
-class BookmarkModel;
-class EditBookmarkDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit EditBookmarkDialog(BookmarkModel *model, const QModelIndex &index, QWidget *parent = nullptr);
- ~EditBookmarkDialog() override;
-
-public slots:
- void saveChanges();
-
-private:
- Ui::EditBookmarkDialog *ui;
-
- BookmarkModel *m_model;
- QModelIndex m_index;
-
- bool titleChanged = false;
- bool hrefChanged = false;
- bool tagsChanged = false;
- bool descriptionChanged = false;
-};
-
-#endif // SMOLBOTE_EDITBOOKMARKDIALOG_H
diff --git a/lib/bookmarks/forms/editbookmarkdialog.ui b/lib/bookmarks/forms/editbookmarkdialog.ui
deleted file mode 100644
index b988394..0000000
--- a/lib/bookmarks/forms/editbookmarkdialog.ui
+++ /dev/null
@@ -1,108 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>EditBookmarkDialog</class>
- <widget class="QDialog" name="EditBookmarkDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>320</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Edit Bookmark</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QFormLayout" name="formLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="title_label">
- <property name="text">
- <string>Title</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="title"/>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="address_label">
- <property name="text">
- <string>Address</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLineEdit" name="address"/>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="tags_label">
- <property name="text">
- <string>Tags</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QLineEdit" name="tags"/>
- </item>
- <item row="3" column="0">
- <widget class="QLabel" name="description_label">
- <property name="text">
- <string>Description</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QPlainTextEdit" name="description"/>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>EditBookmarkDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>EditBookmarkDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/lib/bookmarks/meson.build b/lib/bookmarks/meson.build
index 3049e3c..81c1ece 100644
--- a/lib/bookmarks/meson.build
+++ b/lib/bookmarks/meson.build
@@ -1,19 +1,16 @@
-bookmarks_inc = include_directories('.')
bookmarks_moc = mod_qt5.preprocess(
- moc_headers: ['bookmarkswidget.h', 'model/bookmarkmodel.h', 'forms/editbookmarkdialog.h'],
- ui_files: ['bookmarksform.ui', 'forms/editbookmarkdialog.ui'],
+ moc_headers: [ 'bookmarkmodel.h' ],
dependencies: dep_qt5
)
bookmarks_lib = static_library('bookmarks',
- ['bookmarkswidget.cpp', bookmarks_moc,
- 'formats/format.cpp', 'formats/xbel.cpp',
- 'model/bookmarkitem.cpp', 'model/bookmarkmodel.cpp',
- 'forms/editbookmarkdialog.cpp'],
+ [ bookmarks_moc,
+ 'bookmarkformat.cpp', 'formats/xbel.cpp', 'formats/ffjson.cpp',
+ 'bookmarkitem.cpp', 'bookmarkmodel.cpp' ],
dependencies: dep_qt5
)
dep_bookmarks = declare_dependency(
- include_directories: bookmarks_inc,
+ include_directories: include_directories('.'),
link_with: bookmarks_lib
)