1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef DOLPHINCONTEXTMENU_H
21 #define DOLPHINCONTEXTMENU_H
23 #include <kdesktopfileactions.h>
24 #include <kfileitem.h>
27 #include <konq_copytomenu.h>
29 #include <QtCore/QObject>
31 #include <QtCore/QVector>
33 #include <QScopedPointer>
38 class DolphinMainWindow
;
39 class KFileItemActions
;
40 class KFileItemListProperties
;
43 * @brief Represents the context menu which appears when doing a right
44 * click on an item or the viewport of the file manager.
46 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
47 * dynamic sub menus are shown when opening a context menu above
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
54 class DolphinContextMenu
: public QObject
60 * @parent Pointer to the main window the context menu
62 * @fileInfo Pointer to the file item the context menu
63 * is applied. If 0 is passed, the context menu
64 * is above the viewport.
65 * @baseUrl Base URL of the viewport where the context menu
68 DolphinContextMenu(DolphinMainWindow
* parent
,
69 const KFileItem
& fileInfo
,
72 virtual ~DolphinContextMenu();
74 void setCustomActions(const QList
<QAction
*>& actions
);
76 /** Opens the context menu model. */
80 * TODO: This method is a workaround for a X11-issue in combination
81 * with KModifierKeyInfo: When constructing KModifierKeyInfo in the
82 * constructor of the context menu, the user interface might freeze.
83 * To bypass this, the KModifierKeyInfo is constructed in DolphinMainWindow
84 * directly after starting the application. Remove this method, if
85 * the X11-issue got fixed (contact the maintainer of KModifierKeyInfo for
88 static void initializeModifierKeyInfo();
92 * Is invoked if a key modifier has been pressed and updates the context
93 * menu to show the 'Delete' action instead of the 'Move To Trash' action
94 * if the shift-key has been pressed.
96 void slotKeyModifierPressed(Qt::Key key
, bool pressed
);
99 * Triggers the 'Delete'-action if the shift-key has been pressed, otherwise
100 * the 'Move to Trash'-action gets triggered.
102 void slotRemoveActionTriggered();
105 void openTrashContextMenu();
106 void openTrashItemContextMenu();
107 void openItemContextMenu();
108 void openViewportContextMenu();
110 void insertDefaultItemActions();
113 * Adds the "Show menubar" action to the menu if the
116 void addShowMenubarAction();
119 * Returns a name for adding the URL \a url to the Places panel.
121 QString
placesName(const KUrl
& url
) const;
123 bool placeExists(const KUrl
& url
) const;
125 QAction
* createPasteAction();
127 KFileItemListProperties
& capabilities();
128 void addServiceActions(KFileItemActions
& fileItemActions
);
129 void addVersionControlActions();
130 void addCustomActions();
133 * Updates m_removeAction to represent the 'Delete'-action if the shift-key
134 * has been pressed. Otherwise it represents the 'Move to Trash'-action.
136 void updateRemoveAction();
143 QString filePath
; // empty for separator
144 QString templatePath
; // same as filePath for template
156 DolphinMainWindow
* m_mainWindow
;
157 KFileItemListProperties
* m_capabilities
;
158 KFileItem m_fileInfo
;
160 KFileItemList m_selectedItems
;
161 KUrl::List m_selectedUrls
;
163 KonqCopyToMenu m_copyToMenu
;
164 QList
<QAction
*> m_customActions
;
165 QScopedPointer
<KMenu
> m_popup
;
168 QAction
* m_removeAction
; // Action that represents either 'Move To Trash' or 'Delete'