1 /* This file was part of the KDE libraries 2 3 SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org> 4 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 5 6 SPDX-License-Identifier: GPL-2.0-or-later 7 */ 8 9 // Born as kdelibs/kio/kfile/kfilebookmarkhandler.h 10 11 #ifndef BOOKMARKHANDLER_H 12 #define BOOKMARKHANDLER_H 13 14 // KDE 15 #include <KBookmarkManager> 16 #include <KBookmarkOwner> 17 18 // Konsole 19 #include "konsoleprivate_export.h" 20 21 class QMenu; 22 class QUrl; 23 class KActionCollection; 24 25 namespace Konsole 26 { 27 class ViewProperties; 28 29 /** 30 * This class handles the communication between the bookmark menu and the active session, 31 * providing a suggested title and URL when the user clicks the "Add Bookmark" item in 32 * the bookmarks menu. 33 * 34 * The bookmark handler is associated with a session controller, which is used to 35 * determine the working URL of the current session. When the user changes the active 36 * view, the bookmark handler's controller should be changed using setController() 37 * 38 * When the user selects a bookmark, the openUrl() signal is emitted. 39 */ 40 class KONSOLEPRIVATE_EXPORT BookmarkHandler : public QObject, public KBookmarkOwner 41 { 42 Q_OBJECT 43 44 public: 45 /** 46 * Constructs a new bookmark handler for Konsole bookmarks. 47 * 48 * @param collection The collection which the bookmark menu's actions should be added to 49 * @param menu The menu which the bookmark actions should be added to 50 * @param toplevel TODO: Document me 51 * @param parent The parent object 52 */ 53 BookmarkHandler(KActionCollection *collection, QMenu *menu, bool toplevel, QObject *parent); 54 ~BookmarkHandler() override; 55 56 QUrl currentUrl() const override; 57 QString currentTitle() const override; 58 QString currentIcon() const override; 59 bool enableOption(BookmarkOption option) const override; 60 bool supportsTabs() const override; 61 QList<KBookmarkOwner::FutureBookmark> currentBookmarkList() const override; 62 void openFolderinTabs(const KBookmarkGroup &group) override; 63 64 /** 65 * Returns the menu which this bookmark handler inserts its actions into. 66 */ menu()67 QMenu *menu() const 68 { 69 return _menu; 70 } 71 72 QList<ViewProperties *> views() const; 73 ViewProperties *activeView() const; 74 75 public Q_SLOTS: 76 /** 77 * 78 */ 79 void setViews(const QList<ViewProperties *> &views); 80 81 void setActiveView(ViewProperties *view); 82 83 Q_SIGNALS: 84 /** 85 * Emitted when the user selects a bookmark from the bookmark menu. 86 * 87 * @param url The url of the bookmark which was selected by the user. 88 */ 89 void openUrl(const QUrl &url); 90 91 /** 92 * Emitted when the user selects 'Open Folder in Tabs' 93 * from the bookmark menu. 94 * 95 * @param urls The urls of the bookmarks in the folder whose 96 * 'Open Folder in Tabs' action was triggered 97 */ 98 void openUrls(const QList<QUrl> &urls); 99 100 private Q_SLOTS: 101 void openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) override; 102 103 private: 104 Q_DISABLE_COPY(BookmarkHandler) 105 106 QString titleForView(ViewProperties *view) const; 107 QUrl urlForView(ViewProperties *view) const; 108 QString iconForView(ViewProperties *view) const; 109 110 QMenu *_menu; 111 QString _file; 112 bool _toplevel; 113 ViewProperties *_activeView; 114 QList<ViewProperties *> _views; 115 }; 116 } 117 118 #endif // BOOKMARKHANDLER_H 119