KBookmarks

kbookmarkmenu.h
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
4 SPDX-FileCopyrightText: 2006 Daniel Teske <teske@squorn.de>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef __kbookmarkmenu_h__
10#define __kbookmarkmenu_h__
11
12#include <kbookmarkswidgets_export.h>
13
14#include <QObject>
15#include <memory>
16
17class QAction;
18class QMenu;
19class KBookmark;
21class KBookmarkOwner;
22class KBookmarkMenu;
23
24class KBookmarkMenuPrivate;
25
26/**
27 * @class KBookmarkMenu kbookmarkmenu.h KBookmarkMenu
28 *
29 * This class provides a bookmark menu. It is typically used in
30 * cooperation with KActionMenu but doesn't have to be.
31 *
32 * If you use this class by itself, then it will use KDE defaults for
33 * everything -- the bookmark path, bookmark editor, bookmark launcher..
34 * everything. These defaults reside in the classes
35 * KBookmarkOwner (editing bookmarks) and KBookmarkManager
36 * (almost everything else). If you wish to change the defaults in
37 * any way, you must reimplement either this class or KBookmarkOwner.
38 *
39 * Using this class is very simple:
40 *
41 * 1) Create a popup menu (either KActionMenu or QMenu will do)
42 * 2) Instantiate a new KBookmarkMenu object using the above popup
43 * menu as a parameter
44 * 3) Insert your (now full) popup menu wherever you wish
45 *
46 * The functionality of this class can be disabled with the "action/bookmarks"
47 * Kiosk action (see the KAuthorized namespace).
48 */
50{
51 Q_OBJECT
52public:
53 /**
54 * Fills a bookmark menu
55 * (one instance of KBookmarkMenu is created for the toplevel menu,
56 * but also one per submenu).
57 *
58 * @param manager the bookmark manager to use (i.e. for reading and writing)
59 * @param owner implementation of the KBookmarkOwner callback interface.
60 * @note If you pass a null KBookmarkOwner to the constructor, the
61 * openBookmark signal is not emitted, instead QDesktopServices::openUrl is used to open the bookmark.
62 * @param parentMenu menu to be filled
63 * @since 5.69
64 */
65 KBookmarkMenu(KBookmarkManager *manager, KBookmarkOwner *owner, QMenu *parentMenu);
66
67 /**
68 * Creates a bookmark submenu
69 *
70 * @todo KF6: give ownership of the bookmarkmenu to another qobject, e.g. parentMenu.
71 * Currently this is a QObject without a parent, use setParent to benefit from automatic deletion.
72 */
73 KBookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, const QString &parentAddress);
74
75 ~KBookmarkMenu() override;
76
77 /**
78 * Call ensureUpToDate() if you need KBookmarkMenu to adjust to its
79 * final size before it is executed.
80 **/
81 void ensureUpToDate();
82
83 /**
84 * Returns the action for adding a bookmark. If you are using KXmlGui, you can add it to your
85 * action collection.
86 * @code
87 * KBookmarkMenu *menu = new KBookmarkMenu(manager, owner, parentMenu);
88 * QAction *addAction = menu->addBookmarkAction();
89 * actionCollection()->addAction(addAction->objectName(), addAction);
90 * @endcode
91 * @return the action for adding a bookmark.
92 * @since 5.69
93 */
94 QAction *addBookmarkAction() const;
95
96 /**
97 * Returns the action for adding all current tabs as bookmarks. If you are using KXmlGui, you can
98 * add it to your action collection.
99 * @code
100 * KBookmarkMenu *menu = new KBookmarkMenu(manager, owner, parentMenu);
101 * QAction *bookmarkTabsAction = menu->bookmarkTabsAsFolderAction();
102 * actionCollection()->addAction(bookmarkTabsAction->objectName(), bookmarkTabsAction);
103 * @endcode
104 * @return the action for adding all current tabs as bookmarks.
105 * @since 5.69
106 */
107 QAction *bookmarkTabsAsFolderAction() const;
108
109 /**
110 * Returns the action for adding a new bookmarks folder. If you are using KXmlGui, you can add it
111 * to your action collection.
112 * @code
113 * KBookmarkMenu *menu = new KBookmarkMenu(manager, owner, parentMenu);
114 * QAction *newBookmarkFolderAction = menu->bookmarkTabsAsFolderAction();
115 * actionCollection()->addAction(newBookmarkFolderAction->objectName(), newBookmarkFolderAction);
116 * @endcode
117 * @return the action for adding a new bookmarks folder
118 * @since 5.70
119 */
120 QAction *newBookmarkFolderAction() const;
121
122 /**
123 * Returns the action for editing bookmarks. If you are using KXmlGui, you can add it to your
124 * action collection.
125 * @code
126 * KBookmarkMenu *menu = new KBookmarkMenu(manager, owner, parentMenu);
127 * QAction *editAction = menu->editBookmarksAction();
128 * actionCollection()->addAction(editAction->objectName(), editAction);
129 * @endcode
130 * @return the action for editing bookmarks.
131 * @since 5.69
132 */
133 QAction *editBookmarksAction() const;
134
135 /**
136 * Set this to true to make any "Edit Bookmarks" dialog
137 * show UI elements that are specific to browsers.
138 *
139 * @since 6.0
140 */
141 void setBrowserMode(bool browserMode);
142
143 /**
144 * Whether any "Edit Bookmarks" dialog shows UI elements
145 * that are specific to browsers.
146 *
147 * @since 6.0
148 */
149 bool browserMode() const;
150
151public Q_SLOTS:
152 // public for KonqBookmarkBar
153 void slotBookmarksChanged(const QString &);
154
155protected Q_SLOTS:
156 void slotAboutToShow();
157 void slotAddBookmarksList();
158 void slotAddBookmark();
159 void slotNewFolder();
160 void slotOpenFolderInTabs();
161
162protected:
163 virtual void clear();
164 virtual void refill();
165 virtual QAction *actionForBookmark(const KBookmark &bm);
166 virtual QMenu *contextMenu(QAction *action);
167
168 void addActions();
169 void fillBookmarks();
170 void addAddBookmark();
171 void addAddBookmarksList();
172 void addEditBookmarks();
173 void addNewFolder();
174 void addOpenInTabs();
175
176 bool isRoot() const;
177 bool isDirty() const;
178
179 /**
180 * Parent bookmark for this menu.
181 */
182 QString parentAddress() const;
183
184 KBookmarkManager *manager() const;
185 KBookmarkOwner *owner() const;
186 /**
187 * The menu in which we insert our actions
188 * Supplied in the constructor.
189 */
190 QMenu *parentMenu() const;
191
192 /**
193 * List of our sub menus
194 */
196
197 /**
198 * List of our actions.
199 */
201
202private Q_SLOTS:
203 KBOOKMARKSWIDGETS_NO_EXPORT void slotCustomContextMenu(const QPoint &);
204
205private:
206 void slotEditBookmarks();
207 KBOOKMARKSWIDGETS_NO_EXPORT void init();
208
209private:
210 std::unique_ptr<KBookmarkMenuPrivate> const d;
211};
212
213#endif
This class implements the reading/writing of bookmarks in XML.
This class provides a bookmark menu.
QList< QAction * > m_actions
List of our actions.
QList< KBookmarkMenu * > m_lstSubMenus
List of our sub menus.
The KBookmarkMenu and KBookmarkBar classes gives the user the ability to either edit bookmarks or add...
A class representing a bookmark.
Definition kbookmark.h:27
void clear()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.