]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Merge remote-tracking branch 'origin/master' into frameworks
[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 <KService>
25 #include <KUrl>
26 #include <konq_copytomenu.h>
27 #include <QMenu>
28
29 #include <QObject>
30
31 #include <QVector>
32
33 #include <QScopedPointer>
34
35 class QAction;
36 class DolphinMainWindow;
37 class KFileItemActions;
38 class KFileItemListProperties;
39 class DolphinRemoveAction;
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 QMenu
54 {
55 Q_OBJECT
56
57 public:
58 enum Command
59 {
60 None,
61 OpenParentFolder,
62 OpenParentFolderInNewWindow,
63 OpenParentFolderInNewTab
64 };
65
66 /**
67 * @parent Pointer to the main window the context menu
68 * belongs to.
69 * @pos Position in screen coordinates.
70 * @fileInfo Pointer to the file item the context menu
71 * is applied. If 0 is passed, the context menu
72 * is above the viewport.
73 * @baseUrl Base URL of the viewport where the context menu
74 * should be opened.
75 */
76 DolphinContextMenu(DolphinMainWindow* parent,
77 const QPoint& pos,
78 const KFileItem& fileInfo,
79 const KUrl& baseUrl);
80
81 virtual ~DolphinContextMenu();
82
83 void setCustomActions(const QList<QAction*>& actions);
84
85 /**
86 * Opens the context menu model and returns the requested
87 * command, that should be triggered by the caller. If
88 * Command::None has been returned, either the context-menu
89 * had been closed without executing an action or an
90 * already available action from the main-window has been
91 * executed.
92 */
93 Command open();
94
95 protected:
96 virtual void keyPressEvent(QKeyEvent *ev);
97 virtual void keyReleaseEvent(QKeyEvent *ev);
98
99 private:
100 void openTrashContextMenu();
101 void openTrashItemContextMenu();
102 void openItemContextMenu();
103 void openViewportContextMenu();
104
105 void insertDefaultItemActions(const KFileItemListProperties&);
106
107 /**
108 * Adds the "Show menubar" action to the menu if the
109 * menubar is hidden.
110 */
111 void addShowMenuBarAction();
112
113 bool placeExists(const KUrl& url) const;
114
115 QAction* createPasteAction();
116
117 KFileItemListProperties& selectedItemsProperties() const;
118
119 /**
120 * Returns the file item for m_baseUrl.
121 */
122 KFileItem baseFileItem();
123
124 /**
125 * Adds actions that have been installed as service-menu.
126 * (see http://techbase.kde.org/index.php?title=Development/Tutorials/Creating_Konqueror_Service_Menus)
127 */
128 void addServiceActions(KFileItemActions& fileItemActions);
129
130 /**
131 * Adds actions that are provided by a KFileItemActionPlugin.
132 */
133 void addFileItemPluginActions();
134
135 /**
136 * Adds actions that are provided by a KVersionControlPlugin.
137 */
138 void addVersionControlPluginActions();
139
140 /**
141 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
142 * provided in the details view.
143 */
144 void addCustomActions();
145
146 private:
147 struct Entry
148 {
149 int type;
150 QString name;
151 QString filePath; // empty for separator
152 QString templatePath; // same as filePath for template
153 QString icon;
154 QString comment;
155 };
156
157 enum ContextType
158 {
159 NoContext = 0,
160 ItemContext = 1,
161 TrashContext = 2
162 };
163
164 QPoint m_pos;
165 DolphinMainWindow* m_mainWindow;
166
167 KFileItem m_fileInfo;
168
169 KUrl m_baseUrl;
170 KFileItem* m_baseFileItem; /// File item for m_baseUrl
171
172 KFileItemList m_selectedItems;
173 mutable KFileItemListProperties* m_selectedItemsProperties;
174
175 int m_context;
176 KonqCopyToMenu m_copyToMenu;
177 QList<QAction*> m_customActions;
178
179 Command m_command;
180
181 DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
182 };
183
184 #endif