File indexing completed on 2024-04-21 05:01:36
0001 /* 0002 This class handles the bookmarks. 0003 0004 SPDX-FileCopyrightText: 2004-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SMB4KBOOKMARKHANDLER_H 0009 #define SMB4KBOOKMARKHANDLER_H 0010 0011 // application specific includes 0012 #include "smb4kglobal.h" 0013 0014 // Qt includes 0015 #include <QList> 0016 #include <QObject> 0017 #include <QScopedPointer> 0018 #include <QUrl> 0019 0020 // forward declarations 0021 class Smb4KBookmark; 0022 class Smb4KBookmarkHandlerPrivate; 0023 class Smb4KBookmarkDialog; 0024 class Smb4KBookmarkEditor; 0025 class Smb4KProfileManager; 0026 0027 /** 0028 * This class belongs the to core classes of Smb4K and manages the 0029 * bookmarks. 0030 * 0031 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0032 */ 0033 0034 class Q_DECL_EXPORT Smb4KBookmarkHandler : public QObject 0035 { 0036 Q_OBJECT 0037 0038 friend class Smb4KBookmarkHandlerPrivate; 0039 0040 public: 0041 /** 0042 * The constructor. 0043 */ 0044 explicit Smb4KBookmarkHandler(QObject *parent = nullptr); 0045 0046 /** 0047 * The destructor. 0048 */ 0049 ~Smb4KBookmarkHandler(); 0050 0051 /** 0052 * This function returns a static pointer to this class. 0053 * 0054 * @returns a static pointer to the Smb4KSynchronizer class. 0055 */ 0056 static Smb4KBookmarkHandler *self(); 0057 0058 /** 0059 * This function adds a new bookmark. The bookmark will be copied 0060 * internally, so it is save to clear the bookmark pointer after 0061 * it was passed to this function. 0062 * 0063 * @param bookmark The bookmark that is to be added. 0064 */ 0065 void addBookmark(const BookmarkPtr &bookmark); 0066 0067 /** 0068 * This function adds several bookmarks at once. It takes a list of 0069 * Smb4KBookmark items. 0070 * 0071 * @param list The list of bookmarks that are to be bookmarked 0072 * 0073 * @param replace If TRUE the old list of bookmarks is replaced by 0074 * @p list. 0075 */ 0076 void addBookmarks(const QList<BookmarkPtr> &list, bool replace = false); 0077 0078 /** 0079 * Remove a bookmark. 0080 * 0081 * @param bookmark The bookmark that is to be removed 0082 */ 0083 void removeBookmark(const BookmarkPtr &bookmark); 0084 0085 /** 0086 * This function removes a category and all the bookmarks it contains. 0087 * 0088 * @param name The group name 0089 */ 0090 void removeCategory(const QString &name); 0091 0092 /** 0093 * Get the list of bookmarks. 0094 * 0095 * @returns The current list of bookmarks stored in the 0096 * bookmark file. 0097 */ 0098 QList<BookmarkPtr> bookmarkList() const; 0099 0100 /** 0101 * Get the list of bookmarks belonging to a certain category. 0102 * 0103 * @param categoryName The name of the category the bookmarks are organized in 0104 * 0105 * @returns a list of bookmarks belonging to a certain category 0106 */ 0107 QList<BookmarkPtr> bookmarkList(const QString &categoryName) const; 0108 0109 /** 0110 * This function searches for a bookmark using its URL and returns a pointer 0111 * to it if it is present or NULL. 0112 * 0113 * @param url The URL of the bookmark that is searched. 0114 * 0115 * @returns the bookmark object that was searched for or NULL if it was not 0116 * found. 0117 */ 0118 BookmarkPtr findBookmarkByUrl(const QUrl &url); 0119 0120 /** 0121 * This function searches for a bookmark using its label and returns a pointer 0122 * to it if it is present or NULL. 0123 * 0124 * @param label The label that is searched. 0125 * 0126 * @returns The bookmark object that was searched for or NULL if it 0127 * wasn't found. 0128 */ 0129 BookmarkPtr findBookmarkByLabel(const QString &label); 0130 0131 /** 0132 * Returns the sorted list of all bookmark categories. 0133 * 0134 * @returns the list of categories 0135 */ 0136 QStringList categoryList() const; 0137 0138 /** 0139 * This function checks if the @p share is already bookmarked or not. 0140 * @param share The share item 0141 * @returns TRUE if the share is bookmarked and FALSE otherwise. 0142 */ 0143 bool isBookmarked(const SharePtr &share); 0144 0145 Q_SIGNALS: 0146 /** 0147 * This signal is emitted when a bookmark was added. 0148 * 0149 * @param bookmark The bookmark that was added 0150 */ 0151 void bookmarkAdded(const BookmarkPtr &bookmark); 0152 0153 /** 0154 * This signal is emitted when a bookmark was removed. 0155 * 0156 * @param bookmark The bookmark that was removed 0157 */ 0158 void bookmarkRemoved(const BookmarkPtr &bookmark); 0159 0160 /** 0161 * Signal emitted when the list of bookmarks has been updated. 0162 */ 0163 void updated(); 0164 0165 protected Q_SLOTS: 0166 /** 0167 * Called when a profile was removed 0168 * 0169 * @param name The name of the profile 0170 */ 0171 void slotProfileRemoved(const QString &name); 0172 0173 /** 0174 * Called when a profile was migrated 0175 * 0176 * @param oldName The old profile name 0177 * @param newName The new profile name 0178 */ 0179 void slotProfileMigrated(const QString &oldName, const QString &newName); 0180 0181 private: 0182 /** 0183 * This function reads the list of bookmarks from the bookmarks file. 0184 */ 0185 void readBookmarkList(); 0186 0187 /** 0188 * This function updates the data of the bookmarks. 0189 */ 0190 void update() const; 0191 0192 /** 0193 * This function writes the bookmarks to the disk. 0194 */ 0195 void writeBookmarkList(); 0196 0197 /** 0198 * Pointer to Smb4KBookmarkHandlerPrivate class 0199 */ 0200 const QScopedPointer<Smb4KBookmarkHandlerPrivate> d; 0201 }; 0202 0203 #endif