]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Merge remote-tracking branch 'origin/KDE/4.10'
[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 <KMenu>
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
40 /**
41 * @brief Represents the context menu which appears when doing a right
42 * click on an item or the viewport of the file manager.
43 *
44 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
45 * dynamic sub menus are shown when opening a context menu above
46 * an item:
47 * - 'Open With': Contains all applications which are registered to
48 * open items of the given MIME type.
49 * - 'Actions': Contains all actions which can be applied to the
50 * given item.
51 */
52 class DolphinContextMenu : public KMenu
53 {
54 Q_OBJECT
55
56 public:
57 enum Command
58 {
59 None,
60 OpenParentFolderInNewWindow,
61 OpenParentFolderInNewTab
62 };
63
64 /**
65 * @parent Pointer to the main window the context menu
66 * belongs to.
67 * @pos Position in screen coordinates.
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 QPoint& pos,
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 protected:
94 virtual void keyPressEvent(QKeyEvent *ev);
95 virtual void keyReleaseEvent(QKeyEvent *ev);
96
97 private slots:
98 /**
99 * Triggers the 'Delete'-action if the shift-key has been pressed, otherwise
100 * the 'Move to Trash'-action gets triggered.
101 */
102 void slotRemoveActionTriggered();
103
104 private:
105 void openTrashContextMenu();
106 void openTrashItemContextMenu();
107 void openItemContextMenu();
108 void openViewportContextMenu();
109
110 void insertDefaultItemActions();
111
112 /**
113 * Adds the "Show menubar" action to the menu if the
114 * menubar is hidden.
115 */
116 void addShowMenuBarAction();
117
118 bool placeExists(const KUrl& url) const;
119
120 QAction* createPasteAction();
121
122 KFileItemListProperties& selectedItemsProperties() const;
123
124 /**
125 * Returns the file item for m_baseUrl.
126 */
127 KFileItem baseFileItem();
128
129 /**
130 * Adds actions that have been installed as service-menu.
131 * (see http://techbase.kde.org/index.php?title=Development/Tutorials/Creating_Konqueror_Service_Menus)
132 */
133 void addServiceActions(KFileItemActions& fileItemActions);
134
135 /**
136 * Adds actions that are provided by a KFileItemActionPlugin.
137 */
138 void addFileItemPluginActions();
139
140 /**
141 * Adds actions that are provided by a KVersionControlPlugin.
142 */
143 void addVersionControlPluginActions();
144
145 /**
146 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
147 * provided in the details view.
148 */
149 void addCustomActions();
150
151 /**
152 * Updates m_removeAction to represent the 'Delete'-action if the shift-key
153 * has been pressed or the selection is not local. Otherwise it represents
154 * the 'Move to Trash'-action.
155 */
156 void updateRemoveAction();
157
158 /**
159 * @return True if a moving to the trash should be done instead of
160 * deleting the selected items.
161 * @see updateRemoveAction(), slotRemoveActionTriggered()
162 */
163 bool moveToTrash() const;
164
165 private:
166 struct Entry
167 {
168 int type;
169 QString name;
170 QString filePath; // empty for separator
171 QString templatePath; // same as filePath for template
172 QString icon;
173 QString comment;
174 };
175
176 enum ContextType
177 {
178 NoContext = 0,
179 ItemContext = 1,
180 TrashContext = 2
181 };
182
183 QPoint m_pos;
184 DolphinMainWindow* m_mainWindow;
185
186 KFileItem m_fileInfo;
187
188 KUrl m_baseUrl;
189 KFileItem* m_baseFileItem; /// File item for m_baseUrl
190
191 KFileItemList m_selectedItems;
192 mutable KFileItemListProperties* m_selectedItemsProperties;
193
194 int m_context;
195 KonqCopyToMenu m_copyToMenu;
196 QList<QAction*> m_customActions;
197
198 Command m_command;
199
200 bool m_shiftPressed;
201 QAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
202 };
203
204 #endif