1/* This file is part of the KDE project
2 Copyright (C) 1998-2008 David Faure <faure@kde.org>
3 Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __konqpopupmenu_h
22#define __konqpopupmenu_h
23
24#include <sys/types.h>
25
26#include <QtCore/QMap>
27#include <QMenu>
28
29#include <kaction.h>
30#include <kactioncollection.h>
31#include <kfileitem.h>
32#include <kparts/browserextension.h>
33#include <kservice.h>
34
35#include <libkonq_export.h>
36
37class KNewFileMenu;
38class KFileItemActions;
39
40class KBookmarkManager;
41class KonqPopupMenuPrivate;
42
43/**
44 * This class implements the popup menu for URLs in konqueror and kdesktop
45 * It's usage is very simple : on right click, create the KonqPopupMenu instance
46 * with the correct arguments, then exec() to make it appear, then destroy it.
47 *
48 * Users of KonqPopupMenu include: konqueror, the media applet, the trash applet
49 * (and the desktop icons, in kde3)
50 */
51class LIBKONQ_EXPORT KonqPopupMenu : public QMenu // KDE5 TODO: inherit KMenu to benefit from KAcceleratorManager automatically
52{
53 Q_OBJECT
54public:
55
56 /**
57 * Flags set by the calling application (e.g. konqueror), unlike
58 * KParts::BrowserExtension::PopupFlags, which are set by the calling part
59 */
60 typedef uint Flags;
61 enum { NoFlags = 0,
62 ShowNewWindow = 1,
63 NoPlugins = 2 /*for the unittest*/ };
64 // WARNING: bitfield. Next item is 4
65
66 /**
67 * Constructor
68 * @param manager the bookmark manager for the "add to bookmark" action
69 * Only used if KParts::BrowserExtension::ShowBookmark is set
70 * @param items the list of file items the popupmenu should be shown for
71 * @param viewURL the URL shown in the view, to test for RMB click on view background
72 * @param actions list of actions the caller wants to see in the menu
73 * @param newMenu "New" menu, shared with the File menu, in konqueror
74 * @param parentWidget the widget we're showing this popup for. Helps destroying
75 * the popup if the widget is destroyed before the popup.
76 * @param appFlags flags from the KonqPopupMenu::Flags enum, set by the calling application
77 * @param partFlags flags from the BrowserExtension enum, set by the calling part
78 *
79 * The actions to pass in include :
80 * showmenubar, go_back, go_forward, go_up, cut, copy, paste, pasteto
81 * The others items are automatically inserted.
82 *
83 * @todo that list is probably not be up-to-date
84 */
85 KonqPopupMenu( const KFileItemList &items,
86 const KUrl& viewURL,
87 KActionCollection & actions,
88 KNewFileMenu * newMenu,
89 Flags appFlags,
90 KParts::BrowserExtension::PopupFlags partFlags /*= KParts::BrowserExtension::DefaultPopupItems*/,
91 QWidget * parentWidget,
92 KBookmarkManager *manager = 0,
93 const KParts::BrowserExtension::ActionGroupMap& actionGroups = KParts::BrowserExtension::ActionGroupMap()
94 );
95
96 /**
97 * Don't forget to destroy the object
98 */
99 ~KonqPopupMenu();
100
101 /**
102 * Set the title of the URL, when the popupmenu is opened for a single URL.
103 * This is used if the user chooses to add a bookmark for this URL.
104 */
105 void setURLTitle( const QString& urlTitle );
106 KFileItemActions* fileItemActions() const;
107
108private:
109 Q_PRIVATE_SLOT(d, void slotPopupNewDir())
110 Q_PRIVATE_SLOT(d, void slotPopupNewView())
111 Q_PRIVATE_SLOT(d, void slotPopupEmptyTrashBin())
112 Q_PRIVATE_SLOT(d, void slotConfigTrashBin())
113 Q_PRIVATE_SLOT(d, void slotPopupRestoreTrashedItems())
114 Q_PRIVATE_SLOT(d, void slotPopupAddToBookmark())
115 Q_PRIVATE_SLOT(d, void slotPopupMimeType())
116 Q_PRIVATE_SLOT(d, void slotPopupProperties())
117 Q_PRIVATE_SLOT(d, void slotOpenShareFileDialog())
118 Q_PRIVATE_SLOT(d, void slotShowOriginalFile())
119
120private:
121 KonqPopupMenuPrivate *d;
122};
123
124#endif
125