aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bookmarks/bookmarkformat.cpp (renamed from lib/bookmarks/formats/format.cpp)8
-rw-r--r--lib/bookmarks/bookmarkformat.h67
-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)0
-rw-r--r--lib/bookmarks/bookmarkmodel.cpp (renamed from lib/bookmarks/model/bookmarkmodel.cpp)0
-rw-r--r--lib/bookmarks/bookmarkmodel.h (renamed from lib/bookmarks/model/bookmarkmodel.h)0
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp14
-rw-r--r--lib/bookmarks/formats/format.h36
-rw-r--r--lib/bookmarks/formats/xbel.cpp2
-rw-r--r--lib/bookmarks/forms/editbookmarkdialog.cpp4
-rw-r--r--lib/bookmarks/meson.build6
11 files changed, 81 insertions, 56 deletions
diff --git a/lib/bookmarks/formats/format.cpp b/lib/bookmarks/bookmarkformat.cpp
index 551151c..e6149cd 100644
--- a/lib/bookmarks/formats/format.cpp
+++ b/lib/bookmarks/bookmarkformat.cpp
@@ -6,19 +6,19 @@
* SPDX-License-Identifier: GPL-3.0
*/
-#include "format.h"
-#include "xbel.h"
+#include "bookmarkformat.h"
+#include "formats/xbel.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);
diff --git a/lib/bookmarks/bookmarkformat.h b/lib/bookmarks/bookmarkformat.h
new file mode 100644
index 0000000..673acbd
--- /dev/null
+++ b/lib/bookmarks/bookmarkformat.h
@@ -0,0 +1,67 @@
+/*
+ * 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
+};
+
+template<BookmarkFormats format>
+class BookmarkFormat
+{
+public:
+ explicit BookmarkFormat(QIODevice *device)
+ {
+ m_device = device;
+ }
+ ~BookmarkFormat()
+ {
+ m_device->close();
+ }
+
+ 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..8c9463f 100644
--- a/lib/bookmarks/model/bookmarkitem.h
+++ b/lib/bookmarks/bookmarkitem.h
diff --git a/lib/bookmarks/model/bookmarkmodel.cpp b/lib/bookmarks/bookmarkmodel.cpp
index 895b178..895b178 100644
--- a/lib/bookmarks/model/bookmarkmodel.cpp
+++ b/lib/bookmarks/bookmarkmodel.cpp
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/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
index aed7e97..29e388c 100644
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -8,10 +8,8 @@
#include "bookmarkswidget.h"
#include "forms/editbookmarkdialog.h"
-#include "model/bookmarkitem.h"
-#include "model/bookmarkmodel.h"
#include "ui_bookmarksform.h"
-#include "formats/format.h"
+#include "bookmarkformat.h"
#include <QTreeView>
#include <QUrl>
@@ -48,9 +46,7 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
m_bookmarksPath = path;
QFile bookmarksFile(m_bookmarksPath);
if(bookmarksFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- BookmarksFormat<XbelFormat> format(&bookmarksFile);
- format.read(model->root());
- bookmarksFile.close();
+ BookmarkFormat<XbelFormat>(&bookmarksFile) >> model;
}
model->resetModified();
@@ -124,11 +120,9 @@ void BookmarksWidget::save()
QFile bookmarksFile(m_bookmarksPath);
if(bookmarksFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
- BookmarksFormat<XbelFormat> format(&bookmarksFile);
- format.write(model->root());
+ BookmarkFormat<XbelFormat> f(&bookmarksFile);
+ model >> f;
bookmarksFile.flush();
- bookmarksFile.close();
- model->resetModified();
}
}
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..174995d 100644
--- a/lib/bookmarks/formats/xbel.cpp
+++ b/lib/bookmarks/formats/xbel.cpp
@@ -7,7 +7,7 @@
*/
#include "xbel.h"
-#include "model/bookmarkitem.h"
+#include "bookmarkitem.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
diff --git a/lib/bookmarks/forms/editbookmarkdialog.cpp b/lib/bookmarks/forms/editbookmarkdialog.cpp
index 9c6efa0..7df90b8 100644
--- a/lib/bookmarks/forms/editbookmarkdialog.cpp
+++ b/lib/bookmarks/forms/editbookmarkdialog.cpp
@@ -7,8 +7,8 @@
*/
#include "editbookmarkdialog.h"
-#include "model/bookmarkitem.h"
-#include "model/bookmarkmodel.h"
+#include "bookmarkitem.h"
+#include "bookmarkmodel.h"
#include "ui_editbookmarkdialog.h"
EditBookmarkDialog::EditBookmarkDialog(BookmarkModel *model, const QModelIndex &index, QWidget *parent)
diff --git a/lib/bookmarks/meson.build b/lib/bookmarks/meson.build
index 3049e3c..78d0510 100644
--- a/lib/bookmarks/meson.build
+++ b/lib/bookmarks/meson.build
@@ -1,14 +1,14 @@
bookmarks_inc = include_directories('.')
bookmarks_moc = mod_qt5.preprocess(
- moc_headers: ['bookmarkswidget.h', 'model/bookmarkmodel.h', 'forms/editbookmarkdialog.h'],
+ moc_headers: ['bookmarkswidget.h', 'bookmarkmodel.h', 'forms/editbookmarkdialog.h'],
ui_files: ['bookmarksform.ui', 'forms/editbookmarkdialog.ui'],
dependencies: dep_qt5
)
bookmarks_lib = static_library('bookmarks',
['bookmarkswidget.cpp', bookmarks_moc,
- 'formats/format.cpp', 'formats/xbel.cpp',
- 'model/bookmarkitem.cpp', 'model/bookmarkmodel.cpp',
+ 'bookmarksloader.cpp', 'formats/xbel.cpp',
+ 'bookmarkitem.cpp', 'bookmarkmodel.cpp',
'forms/editbookmarkdialog.cpp'],
dependencies: dep_qt5
)