1// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
2// vim: set ts=4 sts=4 sw=4 et:
3/* This file is part of the KDE project
4 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
5 Copyright (C) 2006 Daniel Teske <teske@squorn.de>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#ifndef __kbookmarkmenu_h__
24#define __kbookmarkmenu_h__
25
26#include <sys/types.h>
27
28#include <QtCore/QObject>
29#include <QtCore/QStack>
30
31#include <klocale.h>
32#include <kaction.h>
33#include <kactionmenu.h>
34#include <kicon.h>
35#include <krun.h>
36#include <kmenu.h>
37
38#include "kbookmark.h"
39#include "kbookmarkmanager.h"
40
41class QString;
42class QMenu;
43class KBookmark;
44class KAction;
45class QAction;
46class KActionMenu;
47class KActionCollection;
48class KBookmarkOwner;
49class KBookmarkMenu;
50class KMenu;
51class KBookmarkActionInterface;
52
53class KBookmarkMenuPrivate; // Not implemented
54
55namespace KIO { class Job; }
56
57/**
58 * This class provides a bookmark menu. It is typically used in
59 * cooperation with KActionMenu but doesn't have to be.
60 *
61 * If you use this class by itself, then it will use KDE defaults for
62 * everything -- the bookmark path, bookmark editor, bookmark launcher..
63 * everything. These defaults reside in the classes
64 * KBookmarkOwner (editing bookmarks) and KBookmarkManager
65 * (almost everything else). If you wish to change the defaults in
66 * any way, you must reimplement either this class or KBookmarkOwner.
67 *
68 * Using this class is very simple:
69 *
70 * 1) Create a popup menu (either KActionMenu or KMenu will do)
71 * 2) Instantiate a new KBookmarkMenu object using the above popup
72 * menu as a parameter
73 * 3) Insert your (now full) popup menu wherever you wish
74 *
75 */
76class KIO_EXPORT KBookmarkMenu : public QObject
77{
78 Q_OBJECT
79public:
80 /**
81 * Fills a bookmark menu
82 * (one instance of KBookmarkMenu is created for the toplevel menu,
83 * but also one per submenu).
84 *
85 * @param mgr The bookmark manager to use (i.e. for reading and writing)
86 * @param owner implementation of the KBookmarkOwner callback interface.
87 * Note: If you pass a null KBookmarkOwner to the constructor, the
88 * openBookmark signal is not emitted, instead KRun is used to open the bookmark.
89 * @param parentMenu menu to be filled
90 * @param collec parent collection for the KActions.
91 *
92 * @todo KDE 5: give ownership of the bookmarkmenu to another qobject, e.g. parentMenu.
93 * Currently this is a QObject without a parent, use setParent to benefit from automatic deletion.
94 */
95 KBookmarkMenu( KBookmarkManager* mgr, KBookmarkOwner * owner, KMenu * parentMenu, KActionCollection *collec);
96
97 /**
98 * Creates a bookmark submenu
99 *
100 * @todo KDE 5: give ownership of the bookmarkmenu to another qobject, e.g. parentMenu.
101 * Currently this is a QObject without a parent, use setParent to benefit from automatic deletion.
102 */
103 KBookmarkMenu( KBookmarkManager* mgr, KBookmarkOwner * owner,
104 KMenu * parentMenu, const QString & parentAddress);
105
106 ~KBookmarkMenu();
107
108 /**
109 * Call ensureUpToDate() if you need KBookmarkMenu to adjust to its
110 * final size before it is executed.
111 **/
112 void ensureUpToDate();
113
114public Q_SLOTS:
115 // public for KonqBookmarkBar
116 void slotBookmarksChanged( const QString & );
117
118protected Q_SLOTS:
119 void slotAboutToShow();
120 void slotAddBookmarksList();
121 void slotAddBookmark();
122 void slotNewFolder();
123 void slotOpenFolderInTabs();
124
125protected:
126 virtual void clear();
127 virtual void refill();
128 virtual QAction* actionForBookmark(const KBookmark &bm);
129 virtual KMenu * contextMenu(QAction * action );
130
131 void addActions();
132 void fillBookmarks();
133 void addAddBookmark();
134 void addAddBookmarksList();
135 void addEditBookmarks();
136 void addNewFolder();
137 void addOpenInTabs();
138
139
140 bool isRoot() const;
141 bool isDirty() const;
142
143 /**
144 * Parent bookmark for this menu.
145 */
146 QString parentAddress() const;
147
148 KBookmarkManager * manager() const;
149 KBookmarkOwner * owner() const;
150 /**
151 * The menu in which we insert our actions
152 * Supplied in the constructor.
153 */
154 KMenu * parentMenu() const;
155
156 /**
157 * List of our sub menus
158 */
159 QList<KBookmarkMenu *> m_lstSubMenus;
160
161 // This is used to "export" our actions into an actionlist
162 // we got in the constructor. So that the program can show our
163 // actions in their shortcut dialog
164 KActionCollection * m_actionCollection;
165 /**
166 * List of our actions.
167 */
168 QList<QAction *> m_actions;
169
170
171private Q_SLOTS:
172 void slotCustomContextMenu( const QPoint & );
173
174private:
175 KBookmarkMenuPrivate* d;
176
177 bool m_bIsRoot;
178 bool m_bDirty;
179 KBookmarkManager * m_pManager;
180 KBookmarkOwner * m_pOwner;
181
182 KMenu * m_parentMenu;
183
184private:
185 QString m_parentAddress;
186};
187
188class KIO_EXPORT KBookmarkContextMenu : public KMenu
189{
190 Q_OBJECT
191
192public:
193 KBookmarkContextMenu(const KBookmark & bm, KBookmarkManager * manager, KBookmarkOwner *owner, QWidget * parent = 0);
194 virtual ~KBookmarkContextMenu();
195 virtual void addActions();
196
197public Q_SLOTS:
198 void slotEditAt();
199 void slotProperties();
200 void slotInsert();
201 void slotRemove();
202 void slotCopyLocation();
203 void slotOpenFolderInTabs();
204
205protected:
206 void addBookmark();
207 void addFolderActions();
208 void addProperties();
209 void addBookmarkActions();
210 void addOpenFolderInTabs();
211
212 KBookmarkManager * manager() const;
213 KBookmarkOwner * owner() const;
214 KBookmark bookmark() const;
215
216private Q_SLOTS:
217 void slotAboutToShow();
218
219private:
220 KBookmark bm;
221 KBookmarkManager * m_pManager;
222 KBookmarkOwner * m_pOwner;
223};
224
225class KIO_EXPORT KBookmarkActionInterface
226{
227public:
228 KBookmarkActionInterface(const KBookmark &bk);
229 virtual ~KBookmarkActionInterface();
230 const KBookmark bookmark() const;
231private:
232 KBookmark bm;
233};
234
235/***
236 * A wrapper around KActionMenu to provide a nice constructor for bookmark groups.
237 *
238 */
239
240class KIO_EXPORT KBookmarkActionMenu : public KActionMenu, public KBookmarkActionInterface
241{
242public:
243 KBookmarkActionMenu(const KBookmark &bm, QObject *parent);
244 KBookmarkActionMenu(const KBookmark &bm, const QString & text, QObject *parent);
245 virtual ~KBookmarkActionMenu();
246};
247
248/***
249 * This class is a KAction for bookmarks.
250 * It provides a nice constructor.
251 * And on triggered uses the owner to open the bookmark.
252 *
253 */
254
255class KIO_EXPORT KBookmarkAction : public KAction, public KBookmarkActionInterface
256{
257 Q_OBJECT
258public:
259 KBookmarkAction(const KBookmark &bk, KBookmarkOwner* owner, QObject *parent);
260 virtual ~KBookmarkAction();
261
262public Q_SLOTS:
263 void slotSelected(Qt::MouseButtons mb, Qt::KeyboardModifiers km);
264
265private:
266 KBookmarkOwner* m_pOwner;
267};
268
269#endif
270