digiKam
bookmarknode.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2017-05-15
7  * Description : a node container for bookmarks
8  *
9  * Copyright (C) 2017-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_BOOKMARK_NODE_H
25 #define DIGIKAM_BOOKMARK_NODE_H
26 
27 // Qt includes
28 
29 #include <QObject>
30 #include <QString>
31 #include <QList>
32 #include <QDateTime>
33 #include <QIODevice>
34 #include <QXmlStreamReader>
35 #include <QXmlStreamWriter>
36 
37 namespace Digikam
38 {
39 
40 class BookmarkNode : public QObject
41 {
42  Q_OBJECT
43 
44 public:
45 
46  enum Type
47  {
53  };
54 
55 public:
56 
57  explicit BookmarkNode(Type type = Root, BookmarkNode* const parent = nullptr);
58  ~BookmarkNode() override;
59 
60  bool operator==(const BookmarkNode& other) const;
61 
62  Type type() const;
63  void setType(Type type);
64 
66  BookmarkNode* parent() const;
67 
68  void add(BookmarkNode* const child, int offset = -1);
69  void remove(BookmarkNode* const child);
70 
71 public:
72 
73  QString url;
74  QString title;
75  QString desc;
76  QDateTime dateAdded;
77  bool expanded;
78 
79 private:
80 
81  // Disable
82  BookmarkNode(const BookmarkNode&) = delete;
83  BookmarkNode& operator=(const BookmarkNode&) = delete;
84 
85 private:
86 
87  class Private;
88  Private* const d;
89 };
90 
91 // -----------------------------------------------------------
92 
93 class XbelReader : public QXmlStreamReader
94 {
95 public:
96 
97  explicit XbelReader();
98 
99  BookmarkNode* read(const QString& fileName);
100  BookmarkNode* read(QIODevice* const device, bool addRootFolder = false);
101 
102 private:
103 
104  void readXBEL(BookmarkNode* const parent);
105  void readTitle(BookmarkNode* const parent);
106  void readDescription(BookmarkNode* const parent);
107  void readSeparator(BookmarkNode* const parent);
108  void readFolder(BookmarkNode* const parent);
109  void readBookmarkNode(BookmarkNode* const parent);
110 };
111 
112 // -----------------------------------------------------------
113 
114 class XbelWriter : public QXmlStreamWriter
115 {
116 public:
117 
118  explicit XbelWriter();
119 
120  bool write(const QString& fileName, const BookmarkNode* const root);
121  bool write(QIODevice* const device, const BookmarkNode* const root);
122 
123 private:
124 
125  void writeItem(const BookmarkNode* const parent);
126 };
127 
128 } // namespace Digikam
129 
130 #endif // DIGIKAM_BOOKMARK_NODE_H
Definition: bookmarknode.h:41
Type type() const
Definition: bookmarknode.cpp:111
void remove(BookmarkNode *const child)
Definition: bookmarknode.cpp:150
bool operator==(const BookmarkNode &other) const
Definition: bookmarknode.cpp:87
QString title
Definition: bookmarknode.h:74
QString desc
Definition: bookmarknode.h:75
void add(BookmarkNode *const child, int offset=-1)
Definition: bookmarknode.cpp:131
QDateTime dateAdded
Definition: bookmarknode.h:76
Type
Definition: bookmarknode.h:47
@ Separator
Definition: bookmarknode.h:51
@ RootFolder
Definition: bookmarknode.h:52
@ Folder
Definition: bookmarknode.h:49
@ Root
Definition: bookmarknode.h:48
@ Bookmark
Definition: bookmarknode.h:50
QList< BookmarkNode * > children() const
Definition: bookmarknode.cpp:121
void setType(Type type)
Definition: bookmarknode.cpp:116
BookmarkNode * parent() const
Definition: bookmarknode.cpp:126
BookmarkNode(Type type=Root, BookmarkNode *const parent=nullptr)
Definition: bookmarknode.cpp:58
bool expanded
Definition: bookmarknode.h:77
QString url
Definition: bookmarknode.h:73
~BookmarkNode() override
Definition: bookmarknode.cpp:72
Definition: bookmarknode.h:94
XbelReader()
Definition: bookmarknode.cpp:158
BookmarkNode * read(const QString &fileName)
Definition: bookmarknode.cpp:162
Definition: bookmarknode.h:115
bool write(const QString &fileName, const BookmarkNode *const root)
Definition: bookmarknode.cpp:332
XbelWriter()
Definition: bookmarknode.cpp:327
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43
Type
Definition: gpsitemcontainer.h:45