aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/bookmarks/bookmarkformat.cpp12
-rw-r--r--lib/bookmarks/bookmarkformat.h35
-rw-r--r--lib/bookmarks/bookmarkitem.cpp5
-rw-r--r--lib/bookmarks/bookmarkitem.h1
-rw-r--r--lib/bookmarks/bookmarkmodel.h34
5 files changed, 48 insertions, 39 deletions
diff --git a/lib/bookmarks/bookmarkformat.cpp b/lib/bookmarks/bookmarkformat.cpp
index 87b816c..491d69a 100644
--- a/lib/bookmarks/bookmarkformat.cpp
+++ b/lib/bookmarks/bookmarkformat.cpp
@@ -7,25 +7,25 @@
*/
#include "bookmarkformat.h"
-#include "formats/xbel.h"
+#include "bookmarkitem.h"
#include "formats/ffjson.h"
+#include "formats/xbel.h"
#include <QIODevice>
-template<>
+template <>
void BookmarkFormat<BookmarkFormats::XbelFormat>::read(BookmarkItem *root) const
{
Xbel::read(m_device, root);
}
-template<>
-void BookmarkFormat<BookmarkFormats::XbelFormat>::write(BookmarkItem *root)
+template <>
+void BookmarkFormat<BookmarkFormats::XbelFormat>::write(const BookmarkItem *root)
{
Xbel::write(m_device, root);
}
-template<>
+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 c886546..cdae24e 100644
--- a/lib/bookmarks/bookmarkformat.h
+++ b/lib/bookmarks/bookmarkformat.h
@@ -9,57 +9,28 @@
#ifndef BOOKMARKFORMAT_H
#define BOOKMARKFORMAT_H
-#include "bookmarkmodel.h"
-
class QIODevice;
+class BookmarkItem;
enum BookmarkFormats {
XbelFormat,
FirefoxJsonFormat
};
-template<BookmarkFormats format>
+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);
+ void write(const 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/bookmarkitem.cpp b/lib/bookmarks/bookmarkitem.cpp
index d361e26..242ab57 100644
--- a/lib/bookmarks/bookmarkitem.cpp
+++ b/lib/bookmarks/bookmarkitem.cpp
@@ -109,6 +109,11 @@ QIcon BookmarkItem::icon()
return m_icon;
}
+QIcon BookmarkItem::icon() const
+{
+ return m_icon;
+}
+
bool BookmarkItem::isExpanded() const
{
return m_isExpanded;
diff --git a/lib/bookmarks/bookmarkitem.h b/lib/bookmarks/bookmarkitem.h
index 97d3e89..310d263 100644
--- a/lib/bookmarks/bookmarkitem.h
+++ b/lib/bookmarks/bookmarkitem.h
@@ -49,6 +49,7 @@ public:
bool setData(Fields column, const QVariant &data);
QIcon icon();
+ QIcon icon() const;
bool isExpanded() const;
void setExpanded(bool expanded);
diff --git a/lib/bookmarks/bookmarkmodel.h b/lib/bookmarks/bookmarkmodel.h
index 300b724..1ddab1e 100644
--- a/lib/bookmarks/bookmarkmodel.h
+++ b/lib/bookmarks/bookmarkmodel.h
@@ -9,6 +9,7 @@
#ifndef SMOLBOTE_BOOKMARKMODEL_H
#define SMOLBOTE_BOOKMARKMODEL_H
+#include "bookmarkformat.h"
#include "bookmarkitem.h"
#include <QAbstractItemModel>
@@ -16,6 +17,11 @@ class BookmarkModel : public QAbstractItemModel
{
Q_OBJECT
+ template <BookmarkFormats T>
+ friend void operator<<(BookmarkModel *model, const BookmarkFormat<T> &format);
+ template <BookmarkFormats T>
+ friend void operator>>(const BookmarkFormat<T> &format, BookmarkModel *model);
+
public:
explicit BookmarkModel(QObject *parent = nullptr);
~BookmarkModel() override;
@@ -45,7 +51,7 @@ public:
QModelIndex parent(const QModelIndex &index) const override;
QModelIndex parentFolder(const QModelIndex &index) const;
- BookmarkItem *root()
+ const BookmarkItem *root() const
{
return rootItem;
}
@@ -70,4 +76,30 @@ private:
bool m_isModified = false;
};
+template <BookmarkFormats T>
+void operator<<(BookmarkModel *model, const BookmarkFormat<T> &format)
+{
+ format.read(model->rootItem);
+}
+
+template <BookmarkFormats T>
+void operator>>(const BookmarkFormat<T> &format, BookmarkModel *model)
+{
+ format.read(model->rootItem);
+}
+
+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 // SMOLBOTE_BOOKMARKMODEL_H