File indexing completed on 2025-01-19 03:58:02
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2017-05-15 0007 * Description : a node container for bookmarks 0008 * 0009 * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_BOOKMARK_NODE_H 0016 #define DIGIKAM_BOOKMARK_NODE_H 0017 0018 // Qt includes 0019 0020 #include <QObject> 0021 #include <QString> 0022 #include <QList> 0023 #include <QDateTime> 0024 #include <QIODevice> 0025 #include <QXmlStreamReader> 0026 #include <QXmlStreamWriter> 0027 0028 namespace Digikam 0029 { 0030 0031 class BookmarkNode : public QObject 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 0037 enum Type 0038 { 0039 Root, 0040 Folder, 0041 Bookmark, 0042 Separator, 0043 RootFolder 0044 }; 0045 0046 public: 0047 0048 explicit BookmarkNode(Type type = Root, BookmarkNode* const parent = nullptr); 0049 ~BookmarkNode() override; 0050 0051 bool operator==(const BookmarkNode& other) const; 0052 0053 Type type() const; 0054 void setType(Type type); 0055 0056 QList<BookmarkNode*> children() const; 0057 BookmarkNode* parent() const; 0058 0059 void add(BookmarkNode* const child, int offset = -1); 0060 void remove(BookmarkNode* const child); 0061 0062 public: 0063 0064 QString url; 0065 QString title; 0066 QString desc; 0067 QDateTime dateAdded; 0068 bool expanded; 0069 0070 private: 0071 0072 // Disable 0073 BookmarkNode(const BookmarkNode&) = delete; 0074 BookmarkNode& operator=(const BookmarkNode&) = delete; 0075 0076 private: 0077 0078 class Private; 0079 Private* const d; 0080 }; 0081 0082 // ----------------------------------------------------------- 0083 0084 class XbelReader : public QXmlStreamReader 0085 { 0086 public: 0087 0088 explicit XbelReader(); 0089 0090 BookmarkNode* read(const QString& fileName); 0091 BookmarkNode* read(QIODevice* const device, bool addRootFolder = false); 0092 0093 private: 0094 0095 void readXBEL(BookmarkNode* const parent); 0096 void readTitle(BookmarkNode* const parent); 0097 void readDescription(BookmarkNode* const parent); 0098 void readSeparator(BookmarkNode* const parent); 0099 void readFolder(BookmarkNode* const parent); 0100 void readBookmarkNode(BookmarkNode* const parent); 0101 }; 0102 0103 // ----------------------------------------------------------- 0104 0105 class XbelWriter : public QXmlStreamWriter 0106 { 0107 public: 0108 0109 explicit XbelWriter(); 0110 0111 bool write(const QString& fileName, const BookmarkNode* const root); 0112 bool write(QIODevice* const device, const BookmarkNode* const root); 0113 0114 private: 0115 0116 void writeItem(const BookmarkNode* const parent); 0117 }; 0118 0119 } // namespace Digikam 0120 0121 #endif // DIGIKAM_BOOKMARK_NODE_H