aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks
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
parentContext menu: add actions for MediaTypeNone (diff)
downloadsmolbote-6e89bf230725e59e71a3273bf8492ed0a2066716.tar.xz
Bookmarks: move xbel implementation to formats/
Diffstat (limited to 'lib/bookmarks')
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp8
-rw-r--r--lib/bookmarks/formats/format.cpp26
-rw-r--r--lib/bookmarks/formats/format.h36
-rw-r--r--lib/bookmarks/formats/xbel.cpp (renamed from lib/bookmarks/xbel.cpp)0
-rw-r--r--lib/bookmarks/formats/xbel.h (renamed from lib/bookmarks/xbel.h)0
-rw-r--r--lib/bookmarks/meson.build2
-rw-r--r--lib/bookmarks/model/bookmarkmodel.cpp2
7 files changed, 69 insertions, 5 deletions
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
index f3ef4df..aed7e97 100644
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -11,7 +11,7 @@
#include "model/bookmarkitem.h"
#include "model/bookmarkmodel.h"
#include "ui_bookmarksform.h"
-#include "xbel.h"
+#include "formats/format.h"
#include <QTreeView>
#include <QUrl>
@@ -48,7 +48,8 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
m_bookmarksPath = path;
QFile bookmarksFile(m_bookmarksPath);
if(bookmarksFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- Xbel::read(&bookmarksFile, model->root());
+ BookmarksFormat<XbelFormat> format(&bookmarksFile);
+ format.read(model->root());
bookmarksFile.close();
}
model->resetModified();
@@ -123,7 +124,8 @@ void BookmarksWidget::save()
QFile bookmarksFile(m_bookmarksPath);
if(bookmarksFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
- Xbel::write(&bookmarksFile, model->root());
+ BookmarksFormat<XbelFormat> format(&bookmarksFile);
+ format.write(model->root());
bookmarksFile.flush();
bookmarksFile.close();
model->resetModified();
diff --git a/lib/bookmarks/formats/format.cpp b/lib/bookmarks/formats/format.cpp
new file mode 100644
index 0000000..551151c
--- /dev/null
+++ b/lib/bookmarks/formats/format.cpp
@@ -0,0 +1,26 @@
+/*
+ * 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 "format.h"
+#include "xbel.h"
+#include <QIODevice>
+
+template<>
+void BookmarksFormat<BookmarksFormats::XbelFormat>::read(BookmarkItem *root)
+{
+ Q_CHECK_PTR(m_device);
+ Xbel::read(m_device, root);
+}
+
+template<>
+void BookmarksFormat<BookmarksFormats::XbelFormat>::write(BookmarkItem *root)
+{
+ Q_CHECK_PTR(m_device);
+ Xbel::write(m_device, root);
+}
+
diff --git a/lib/bookmarks/formats/format.h b/lib/bookmarks/formats/format.h
new file mode 100644
index 0000000..e96dfcc
--- /dev/null
+++ b/lib/bookmarks/formats/format.h
@@ -0,0 +1,36 @@
+/*
+ * 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/xbel.cpp b/lib/bookmarks/formats/xbel.cpp
index 1cb5756..1cb5756 100644
--- a/lib/bookmarks/xbel.cpp
+++ b/lib/bookmarks/formats/xbel.cpp
diff --git a/lib/bookmarks/xbel.h b/lib/bookmarks/formats/xbel.h
index 44a65bb..44a65bb 100644
--- a/lib/bookmarks/xbel.h
+++ b/lib/bookmarks/formats/xbel.h
diff --git a/lib/bookmarks/meson.build b/lib/bookmarks/meson.build
index cdcdd47..3049e3c 100644
--- a/lib/bookmarks/meson.build
+++ b/lib/bookmarks/meson.build
@@ -7,7 +7,7 @@ bookmarks_moc = mod_qt5.preprocess(
bookmarks_lib = static_library('bookmarks',
['bookmarkswidget.cpp', bookmarks_moc,
- 'xbel.cpp', 'xbel.h',
+ 'formats/format.cpp', 'formats/xbel.cpp',
'model/bookmarkitem.cpp', 'model/bookmarkmodel.cpp',
'forms/editbookmarkdialog.cpp'],
dependencies: dep_qt5
diff --git a/lib/bookmarks/model/bookmarkmodel.cpp b/lib/bookmarks/model/bookmarkmodel.cpp
index 9214c24..895b178 100644
--- a/lib/bookmarks/model/bookmarkmodel.cpp
+++ b/lib/bookmarks/model/bookmarkmodel.cpp
@@ -8,7 +8,7 @@
#include "bookmarkmodel.h"
#include "bookmarkitem.h"
-#include "xbel.h"
+#include "formats/xbel.h"
#include <QBuffer>
#include <QMimeData>
#include <QRegularExpression>