]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Remove the fixed-size workaround, only one action is used now in this case
[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 #include <kmodifierkeyinfo.h>
29
30 #include <QtCore/QObject>
31
32 #include <QtCore/QVector>
33
34 #include <QScopedPointer>
35
36 class KMenu;
37 class KFileItem;
38 class QAction;
39 class DolphinMainWindow;
40 class KFileItemActions;
41 class KFileItemListProperties;
42
43 /**
44 * @brief Represents the context menu which appears when doing a right
45 * click on an item or the viewport of the file manager.
46 *
47 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
48 * dynamic sub menus are shown when opening a context menu above
49 * an item:
50 * - 'Open With': Contains all applications which are registered to
51 * open items of the given MIME type.
52 * - 'Actions': Contains all actions which can be applied to the
53 * given item.
54 */
55 class DolphinContextMenu : public QObject
56 {
57 Q_OBJECT
58
59 public:
60 /**
61 * @parent Pointer to the main window the context menu
62 * belongs to.
63 * @fileInfo Pointer to the file item the context menu
64 * is applied. If 0 is passed, the context menu
65 * is above the viewport.
66 * @baseUrl Base URL of the viewport where the context menu
67 * should be opened.
68 */
69 DolphinContextMenu(DolphinMainWindow* parent,
70 const KFileItem& fileInfo,
71 const KUrl& baseUrl);
72
73 virtual ~DolphinContextMenu();
74
75 void setCustomActions(const QList<QAction*>& actions);
76
77 /** Opens the context menu model. */
78 void open();
79
80 private slots:
81 /**
82 * Is invoked if a key modifier has been pressed and updates the context
83 * menu to show the 'Delete' action instead of the 'Move To Trash' action
84 * if the shift-key has been pressed.
85 */
86 void slotKeyModifierPressed(Qt::Key key, bool pressed);
87
88 /**
89 * Triggers the 'Delete'-action if the shift-key has been pressed, otherwise
90 * the 'Move to Trash'-action gets triggered.
91 */
92 void slotRemoveActionTriggered();
93
94 private:
95 void openTrashContextMenu();
96 void openTrashItemContextMenu();
97 void openItemContextMenu();
98 void openViewportContextMenu();
99
100 void insertDefaultItemActions();
101
102 /**
103 * Adds the "Show menubar" action to the menu if the
104 * menubar is hidden.
105 */
106 void addShowMenubarAction();
107
108 /**
109 * Returns a name for adding the URL \a url to the Places panel.
110 */
111 QString placesName(const KUrl& url) const;
112
113 bool placeExists(const KUrl& url) const;
114
115 QAction* createPasteAction();
116
117 KFileItemListProperties& capabilities();
118 void addServiceActions(KFileItemActions& fileItemActions);
119 void addVersionControlActions();
120 void addCustomActions();
121
122 /**
123 * Updates m_removeAction to represent the 'Delete'-action if the shift-key
124 * has been pressed. Otherwise it represents the 'Move to Trash'-action.
125 */
126 void updateRemoveAction();
127
128 private:
129 struct Entry
130 {
131 int type;
132 QString name;
133 QString filePath; // empty for separator
134 QString templatePath; // same as filePath for template
135 QString icon;
136 QString comment;
137 };
138
139 enum ContextType
140 {
141 NoContext = 0,
142 ItemContext = 1,
143 TrashContext = 2
144 };
145
146 DolphinMainWindow* m_mainWindow;
147 KFileItemListProperties* m_capabilities;
148 KFileItem m_fileInfo;
149 KUrl m_baseUrl;
150 KFileItemList m_selectedItems;
151 KUrl::List m_selectedUrls;
152 int m_context;
153 KonqCopyToMenu m_copyToMenu;
154 QList<QAction*> m_customActions;
155 QScopedPointer<KMenu> m_popup;
156
157 bool m_shiftPressed;
158 KModifierKeyInfo m_keyInfo;
159 QAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
160 };
161
162 #endif