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