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 | 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 : public KMenu |
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 | * @pos Position in screen coordinates. |
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 QPoint& pos, |
77 | const KFileItem& fileInfo, |
78 | const KUrl& baseUrl); |
79 | |
80 | virtual (); |
81 | |
82 | void (const QList<QAction*>& actions); |
83 | |
84 | /** |
85 | * Opens the context menu model and returns the requested |
86 | * command, that should be triggered by the caller. If |
87 | * Command::None has been returned, either the context-menu |
88 | * had been closed without executing an action or an |
89 | * already available action from the main-window has been |
90 | * executed. |
91 | */ |
92 | Command (); |
93 | |
94 | protected: |
95 | virtual void (QKeyEvent *ev); |
96 | virtual void (QKeyEvent *ev); |
97 | |
98 | private: |
99 | void (); |
100 | void (); |
101 | void (); |
102 | void (); |
103 | |
104 | void (const KFileItemListProperties&); |
105 | |
106 | /** |
107 | * Adds the "Show menubar" action to the menu if the |
108 | * menubar is hidden. |
109 | */ |
110 | void (); |
111 | |
112 | bool (const KUrl& url) const; |
113 | |
114 | QAction* (); |
115 | |
116 | KFileItemListProperties& () const; |
117 | |
118 | /** |
119 | * Returns the file item for m_baseUrl. |
120 | */ |
121 | KFileItem (); |
122 | |
123 | /** |
124 | * Adds actions that have been installed as service-menu. |
125 | * (see http://techbase.kde.org/index.php?title=Development/Tutorials/Creating_Konqueror_Service_Menus) |
126 | */ |
127 | void (KFileItemActions& fileItemActions); |
128 | |
129 | /** |
130 | * Adds actions that are provided by a KFileItemActionPlugin. |
131 | */ |
132 | void (); |
133 | |
134 | /** |
135 | * Adds actions that are provided by a KVersionControlPlugin. |
136 | */ |
137 | void (); |
138 | |
139 | /** |
140 | * Adds custom actions e.g. like the "[x] Expandable Folders"-action |
141 | * provided in the details view. |
142 | */ |
143 | void (); |
144 | |
145 | private: |
146 | struct |
147 | { |
148 | int ; |
149 | QString ; |
150 | QString ; // empty for separator |
151 | QString ; // same as filePath for template |
152 | QString ; |
153 | QString ; |
154 | }; |
155 | |
156 | enum |
157 | { |
158 | = 0, |
159 | = 1, |
160 | = 2 |
161 | }; |
162 | |
163 | QPoint ; |
164 | DolphinMainWindow* m_mainWindow; |
165 | |
166 | KFileItem ; |
167 | |
168 | KUrl ; |
169 | KFileItem* ; /// File item for m_baseUrl |
170 | |
171 | KFileItemList ; |
172 | mutable KFileItemListProperties* ; |
173 | |
174 | int ; |
175 | KonqCopyToMenu ; |
176 | QList<QAction*> ; |
177 | |
178 | Command m_command; |
179 | |
180 | DolphinRemoveAction* ; // Action that represents either 'Move To Trash' or 'Delete' |
181 | }; |
182 | |
183 | #endif |
184 | |