File indexing completed on 2024-04-28 04:32:37
0001 /* 0002 SPDX-FileCopyrightText: 2006 Pino Toscano <pino@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _OKULAR_BOOKMARK_MANAGER_H_ 0008 #define _OKULAR_BOOKMARK_MANAGER_H_ 0009 0010 #include <KBookmark> 0011 0012 #include "okularcore_export.h" 0013 #include <QObject> 0014 #include <QUrl> 0015 0016 class QAction; 0017 0018 namespace Okular 0019 { 0020 class Document; 0021 class DocumentPrivate; 0022 class DocumentViewport; 0023 0024 /** 0025 * @brief Bookmarks manager utility. 0026 * 0027 * This class is responsible for loading and saving the bookmarks using the 0028 * proper format, and for working with them (eg querying, adding, removing). 0029 */ 0030 class OKULARCORE_EXPORT BookmarkManager : public QObject 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 ~BookmarkManager() override; 0036 0037 /** 0038 * Returns the list of documents with bookmarks. 0039 */ 0040 QList<QUrl> files() const; 0041 0042 /** 0043 * Returns the list of bookmarks for the specified @p documentUrl. 0044 */ 0045 KBookmark::List bookmarks(const QUrl &documentUrl) const; 0046 0047 /** 0048 * Returns the list of bookmarks for document 0049 * @since 0.14 (KDE 4.8) 0050 */ 0051 KBookmark::List bookmarks() const; 0052 0053 /** 0054 * Returns the list of bookmarks for the given page of the document 0055 * @since 0.15 (KDE 4.9) 0056 */ 0057 KBookmark::List bookmarks(int page) const; 0058 0059 /** 0060 * Returns the bookmark for the given page of the document 0061 * @since 0.14 (KDE 4.8) 0062 */ 0063 KBookmark bookmark(int page) const; 0064 0065 /** 0066 * Returns the bookmark for the given @p viewport of the document 0067 * @since 0.15 (KDE 4.9) 0068 */ 0069 KBookmark bookmark(const DocumentViewport &viewport) const; 0070 0071 /** 0072 * Forces to save the list of bookmarks. 0073 */ 0074 void save() const; 0075 0076 /** 0077 * Adds a bookmark for the given @p page. 0078 */ 0079 void addBookmark(int page); 0080 0081 /** 0082 * Adds a bookmark for the given viewport @p vp 0083 * @since 0.15 (KDE 4.9) 0084 */ 0085 void addBookmark(const DocumentViewport &vp); 0086 0087 /** 0088 * Adds a new bookmark for the @p documentUrl at the specified viewport @p vp, 0089 * with an optional @p title. 0090 * 0091 * If no @p title is specified, then \em \#n will be used. 0092 */ 0093 bool addBookmark(const QUrl &documentUrl, const Okular::DocumentViewport &vp, const QString &title = QString()); 0094 0095 /** 0096 * Remove a bookmark for the given @p page. 0097 */ 0098 void removeBookmark(int page); 0099 0100 /** 0101 * Remove a bookmark for the given viewport @p vp 0102 * @since 0.15 (KDE 4.9) 0103 */ 0104 void removeBookmark(const DocumentViewport &vp); 0105 0106 /** 0107 * Removes the bookmark @p bm for the @p documentUrl specified. 0108 */ 0109 int removeBookmark(const QUrl &documentUrl, const KBookmark &bm); 0110 0111 /** 0112 * Removes the bookmarks in @p list for the @p documentUrl specified. 0113 * 0114 * @note it will remove only the bookmarks which belong to @p documentUrl 0115 * 0116 * @since 0.11 (KDE 4.5) 0117 */ 0118 void removeBookmarks(const QUrl &documentUrl, const KBookmark::List &list); 0119 0120 /** 0121 * Returns the bookmark given bookmark of the document 0122 * @since 0.14 (KDE 4.8) 0123 */ 0124 void renameBookmark(KBookmark *bm, const QString &newName); 0125 0126 /** 0127 * Renames the top-level bookmark for the @p documentUrl specified with 0128 * the @p newName specified. 0129 * @since 0.15 (KDE 4.9) 0130 */ 0131 void renameBookmark(const QUrl &documentUrl, const QString &newName); 0132 0133 /** 0134 * Returns title for the @p documentUrl 0135 * @since 0.15 (KDE 4.9) 0136 */ 0137 QString titleForUrl(const QUrl &documentUrl) const; 0138 0139 /** 0140 * Returns whether the given @p page is bookmarked. 0141 */ 0142 bool isBookmarked(int page) const; 0143 0144 /** 0145 * Return whether the given @p viewport is bookmarked. 0146 * @since 0.15 (KDE 4.9) 0147 */ 0148 bool isBookmarked(const DocumentViewport &viewport) const; 0149 0150 /** 0151 * Given a @p viewport, returns the next bookmark 0152 * @since 0.15 (KDE 4.9) 0153 */ 0154 KBookmark nextBookmark(const DocumentViewport &viewport) const; 0155 0156 /** 0157 * Given a @p viewport, returns the previous bookmark 0158 * @since 0.15 (KDE 4.9) 0159 */ 0160 KBookmark previousBookmark(const DocumentViewport &viewport) const; 0161 0162 /** 0163 * Returns a list of actions for the bookmarks of the specified @p url. 0164 * 0165 * @note the actions will have no parents, so you have to delete them 0166 * yourself 0167 */ 0168 QList<QAction *> actionsForUrl(const QUrl &documentUrl) const; 0169 0170 Q_SIGNALS: 0171 /** 0172 * The bookmark manager is requesting to open the specified @p url. 0173 */ 0174 void openUrl(const QUrl &url); 0175 0176 /** 0177 * This signal is emitted whenever bookmarks have been saved. 0178 */ 0179 void saved(); 0180 0181 /** 0182 * The bookmarks for specified @p url were changed. 0183 * 0184 * @since 0.7 (KDE 4.1) 0185 */ 0186 void bookmarksChanged(const QUrl &url); 0187 0188 private: 0189 class Private; 0190 Private *const d; 0191 friend class Private; 0192 0193 // private interface used by the Document 0194 friend class Document; 0195 friend class DocumentPrivate; 0196 0197 explicit BookmarkManager(DocumentPrivate *document); 0198 0199 void setUrl(const QUrl &url); 0200 bool setPageBookmark(int page); 0201 bool removePageBookmark(int page); 0202 0203 Q_DISABLE_COPY(BookmarkManager) 0204 }; 0205 0206 } 0207 0208 #endif