]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Use capitalized KDE includes
[dolphin.git] / src / dolphincontextmenu.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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 <KService>
25 #include <KUrl>
26 #include <konq_copytomenu.h>
27
28 #include <QObject>
29
30 #include <QVector>
31
32 #include <QScopedPointer>
33
34 class KMenu;
35 class KFileItem;
36 class QAction;
37 class DolphinMainWindow;
38 class KFileItemActions;
39 class KFileItemListProperties;
40
41 /**
42 * @brief Represents the context menu which appears when doing a right
43 * click on an item or the viewport of the file manager.
44 *
45 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
46 * dynamic sub menus are shown when opening a context menu above
47 * an item:
48 * - 'Open With': Contains all applications which are registered to
49 * open items of the given MIME type.
50 * - 'Actions': Contains all actions which can be applied to the
51 * given item.
52 */
53 class DolphinContextMenu : public QObject
54 {
55 Q_OBJECT
56
57 public:
58 enum Command
59 {
60 None,
61 OpenParentFolderInNewWindow,
62 OpenParentFolderInNewTab
63 };
64
65 /**
66 * @parent Pointer to the main window the context menu
67 * belongs to.
68 * @fileInfo Pointer to the file item the context menu
69 * is applied. If 0 is passed, the context menu
70 * is above the viewport.
71 * @baseUrl Base URL of the viewport where the context menu
72 * should be opened.
73 */
74 DolphinContextMenu(DolphinMainWindow* parent,
75 const KFileItem& fileInfo,
76 const KUrl& baseUrl);
77
78 virtual ~DolphinContextMenu();
79
80 void setCustomActions(const QList<QAction*>& actions);
81
82 /**
83 * Opens the context menu model and returns the requested
84 * command, that should be triggered by the caller. If
85 * Command::None has been returned, either the context-menu
86 * had been closed without executing an action or an
87 * already available action from the main-window has been
88 * executed.
89 */
90 Command open();
91
92 /**
93 * TODO: This method is a workaround for a X11-issue in combination
94 * with KModifierKeyInfo: When constructing KModifierKeyInfo in the
95 * constructor of the context menu, the user interface might freeze.
96 * To bypass this, the KModifierKeyInfo is constructed in DolphinMainWindow
97 * directly after starting the application. Remove this method, if
98 * the X11-issue got fixed (contact the maintainer of KModifierKeyInfo for
99 * more details).
100 */
101 static void initializeModifierKeyInfo();
102
103 private slots:
104 /**
105 * Is invoked if a key modifier has been pressed and updates the context
106 * menu to show the 'Delete' action instead of the 'Move To Trash' action
107 * if the shift-key has been pressed.
108 */
109 void slotKeyModifierPressed(Qt::Key key, bool pressed);
110
111 /**
112 * Triggers the 'Delete'-action if the shift-key has been pressed, otherwise
113 * the 'Move to Trash'-action gets triggered.
114 */
115 void slotRemoveActionTriggered();
116
117 private:
118 void openTrashContextMenu();
119 void openTrashItemContextMenu();
120 void openItemContextMenu();
121 void openViewportContextMenu();
122
123 void insertDefaultItemActions();
124
125 /**
126 * Adds the "Show menubar" action to the menu if the
127 * menubar is hidden.
128 */
129 void addShowMenubarAction();
130
131 /**
132 * Returns a name for adding the URL \a url to the Places panel.
133 */
134 QString placesName(const KUrl& url) const;
135
136 bool placeExists(const KUrl& url) const;
137
138 QAction* createPasteAction();
139
140 KFileItemListProperties& selectedItemsProperties();
141
142 /**
143 * Returns the file item for m_baseUrl.
144 */
145 KFileItem baseFileItem();
146
147 /**
148 * Adds actions that have been installed as service-menu.
149 * (see http://techbase.kde.org/index.php?title=Development/Tutorials/Creating_Konqueror_Service_Menus)
150 */
151 void addServiceActions(KFileItemActions& fileItemActions);
152
153 /**
154 * Adds actions that are provided by a KFileItemActionPlugin.
155 */
156 void addFileItemPluginActions();
157
158 /**
159 * Adds actions that are provided by a KVersionControlPlugin.
160 */
161 void addVersionControlPluginActions();
162
163 /**
164 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
165 * provided in the details view.
166 */
167 void addCustomActions();
168
169 /**
170 * Updates m_removeAction to represent the 'Delete'-action if the shift-key
171 * has been pressed. Otherwise it represents the 'Move to Trash'-action.
172 */
173 void updateRemoveAction();
174
175 private:
176 struct Entry
177 {
178 int type;
179 QString name;
180 QString filePath; // empty for separator
181 QString templatePath; // same as filePath for template
182 QString icon;
183 QString comment;
184 };
185
186 enum ContextType
187 {
188 NoContext = 0,
189 ItemContext = 1,
190 TrashContext = 2
191 };
192
193 DolphinMainWindow* m_mainWindow;
194
195 KFileItem m_fileInfo;
196
197 KUrl m_baseUrl;
198 KFileItem* m_baseFileItem; /// File item for m_baseUrl
199
200 KFileItemList m_selectedItems;
201 KFileItemListProperties* m_selectedItemsProperties;
202
203 int m_context;
204 KonqCopyToMenu m_copyToMenu;
205 QList<QAction*> m_customActions;
206 KMenu* m_popup;
207
208 Command m_command;
209
210 bool m_shiftPressed;
211 QAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
212 };
213
214 #endif