]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Popupmenu: use KIO 5.27's new addPluginActionsTo method
[dolphin.git] / src / dolphincontextmenu.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef DOLPHINCONTEXTMENU_H
21 #define DOLPHINCONTEXTMENU_H
22
23 #include <KFileItem>
24 #include <QUrl>
25 #include <KFileCopyToMenu>
26 #include <QMenu>
27
28
29
30
31 class QAction;
32 class DolphinMainWindow;
33 class KFileItemActions;
34 class KFileItemListProperties;
35 class DolphinRemoveAction;
36
37 /**
38 * @brief Represents the context menu which appears when doing a right
39 * click on an item or the viewport of the file manager.
40 *
41 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
42 * dynamic sub menus are shown when opening a context menu above
43 * an item:
44 * - 'Open With': Contains all applications which are registered to
45 * open items of the given MIME type.
46 * - 'Actions': Contains all actions which can be applied to the
47 * given item.
48 */
49 class DolphinContextMenu : public QMenu
50 {
51 Q_OBJECT
52
53 public:
54 enum Command
55 {
56 None,
57 OpenParentFolder,
58 OpenParentFolderInNewWindow,
59 OpenParentFolderInNewTab
60 };
61
62 /**
63 * @parent Pointer to the main window the context menu
64 * belongs to.
65 * @pos Position in screen coordinates.
66 * @fileInfo Pointer to the file item the context menu
67 * is applied. If 0 is passed, the context menu
68 * is above the viewport.
69 * @baseUrl Base URL of the viewport where the context menu
70 * should be opened.
71 */
72 DolphinContextMenu(DolphinMainWindow* parent,
73 const QPoint& pos,
74 const KFileItem& fileInfo,
75 const QUrl& baseUrl);
76
77 virtual ~DolphinContextMenu();
78
79 void setCustomActions(const QList<QAction*>& actions);
80
81 /**
82 * Opens the context menu model and returns the requested
83 * command, that should be triggered by the caller. If
84 * Command::None has been returned, either the context-menu
85 * had been closed without executing an action or an
86 * already available action from the main-window has been
87 * executed.
88 */
89 Command open();
90
91 protected:
92 virtual void keyPressEvent(QKeyEvent *ev) Q_DECL_OVERRIDE;
93 virtual void keyReleaseEvent(QKeyEvent *ev) Q_DECL_OVERRIDE;
94
95 private:
96 void openTrashContextMenu();
97 void openTrashItemContextMenu();
98 void openItemContextMenu();
99 void openViewportContextMenu();
100
101 void insertDefaultItemActions(const KFileItemListProperties&);
102
103 /**
104 * Adds the "Show menubar" action to the menu if the
105 * menubar is hidden.
106 */
107 void addShowMenuBarAction();
108
109 bool placeExists(const QUrl& url) const;
110
111 QAction* createPasteAction();
112
113 KFileItemListProperties& selectedItemsProperties() const;
114
115 /**
116 * Returns the file item for m_baseUrl.
117 */
118 KFileItem baseFileItem();
119
120 /**
121 * Adds actions that have been installed as service-menu.
122 * (see http://techbase.kde.org/index.php?title=Development/Tutorials/Creating_Konqueror_Service_Menus)
123 */
124 void addServiceActions(KFileItemActions& fileItemActions);
125
126 /**
127 * Adds actions that are provided by a KFileItemActionPlugin.
128 */
129 void addFileItemPluginActions(KFileItemActions& fileItemActions);
130
131 /**
132 * Adds actions that are provided by a KVersionControlPlugin.
133 */
134 void addVersionControlPluginActions();
135
136 /**
137 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
138 * provided in the details view.
139 */
140 void addCustomActions();
141
142 private:
143 struct Entry
144 {
145 int type;
146 QString name;
147 QString filePath; // empty for separator
148 QString templatePath; // same as filePath for template
149 QString icon;
150 QString comment;
151 };
152
153 enum ContextType
154 {
155 NoContext = 0,
156 ItemContext = 1,
157 TrashContext = 2
158 };
159
160 QPoint m_pos;
161 DolphinMainWindow* m_mainWindow;
162
163 KFileItem m_fileInfo;
164
165 QUrl m_baseUrl;
166 KFileItem* m_baseFileItem; /// File item for m_baseUrl
167
168 KFileItemList m_selectedItems;
169 mutable KFileItemListProperties* m_selectedItemsProperties;
170
171 int m_context;
172 KFileCopyToMenu m_copyToMenu;
173 QList<QAction*> m_customActions;
174
175 Command m_command;
176
177 DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
178 };
179
180 #endif