1/* This file is part of the KDE project
2 Copyright (C) 1998-2009 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2 of the License or
7 ( at your option ) version 3 or, at the discretion of KDE e.V.
8 ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 KONQ_MENUACTIONS_H
22#define KONQ_MENUACTIONS_H
23
24#include <kfileitem.h>
25#include <libkonq_export.h>
26
27class KFileItemActions;
28class KFileItemListProperties;
29class KAction;
30class KonqPopupMenuInformation;
31class QMenu;
32
33/**
34 * This class handles the user-defined actions for a url in a popupmenu.
35 * User-defined actions include:
36 * - builtin services like mount/unmount for old-style device desktop files
37 * - user-defined actions for a .desktop file, defined in the file itself (see the desktop entry standard)
38 * - servicemenus actions, defined in .desktop files and selected based on the mimetype of the url
39 *
40 * In addition it can also add "open with" actions.
41 */
42class LIBKONQ_EXPORT KonqMenuActions
43{
44public:
45 /**
46 * Creates a KonqMenuActions instance.
47 * Note that this instance must stay alive for at least as long as the popupmenu;
48 * it has the slots for the actions created by addActionsTo.
49 */
50 KonqMenuActions();
51
52 /**
53 * Destructor
54 */
55 ~KonqMenuActions();
56
57 /**
58 * Sets all the data for the next instance of the popupmenu.
59 * @see KonqPopupMenuInformation
60 * @deprecated use setItemList+setParentWidget
61 */
62 KDE_DEPRECATED void setPopupMenuInfo(const KonqPopupMenuInformation& info);
63
64 /**
65 * Sets all the data for the next instance of the popupmenu.
66 * @see KFileItemListProperties
67 * @since 4.3
68 */
69 void setItemListProperties(const KFileItemListProperties& itemList);
70
71 /**
72 * Set the parent widget for any dialogs being shown.
73 *
74 * This should normally be your mainwindow, not a popup menu,
75 * so that it still exists even after the popup is closed
76 * (e.g. error message from KRun) and so that QAction::setStatusTip
77 * can find a statusbar, too.
78 * @since 4.3
79 */
80 void setParentWidget(QWidget* widget);
81
82 /**
83 * Generate the user-defined actions and submenus, and adds them to the @p menu.
84 * User-defined actions include:
85 * - builtin services like mount/unmount for old-style device desktop files
86 * - user-defined actions for a .desktop file, defined in the file itself (see the desktop entry standard)
87 * - servicemenus actions, defined in .desktop files and selected based on the mimetype of the url
88 *
89 * When KFileItemListProperties::supportsWriting() is false, actions that modify the files are not shown.
90 * This is controlled by Require=Write in the servicemenu desktop files.
91 *
92 * All actions are created as children of the menu.
93 * @return the number of actions added
94 */
95 int addActionsTo(QMenu* menu); // NOTE: renamed to addServiceActionsTo() in KFileItemActions
96
97 /**
98 * Generate the "Open With <Application>" actions, and adds them to the @p menu.
99 * All actions are created as children of the menu.
100 * @param menu the QMenu where to add actions
101 * @param traderConstraint this constraint allows to exclude the current application
102 * from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".
103 */
104 void addOpenWithActionsTo(QMenu* menu, const QString& traderConstraint);
105
106 /**
107 * Returns an action for the preferred app only.
108 * @param traderConstraint this constraint allows to exclude the current application
109 * from the "open with" list. Example: "DesktopEntryName != 'kfmclient'".
110 * @return the action - or 0 if no application was found.
111 * @since 4.3 -- TODO REMOVE AND PORT FOLDERVIEW
112 */
113 KAction* preferredOpenWithAction(const QString& traderConstraint);
114
115private:
116 KFileItemActions* const d;
117};
118
119#endif /* KONQ_MENUACTIONS_H */
120