]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Show location in window title for non-local URLs. Thanks to Mark Gaiser for the patch...
[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
29 #include <QtCore/QObject>
30
31 #include <QtCore/QVector>
32
33 class KMenu;
34 class KFileItem;
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 QObject
53 {
54 Q_OBJECT
55
56 public:
57 /**
58 * @parent Pointer to the main window the context menu
59 * belongs to.
60 * @fileInfo Pointer to the file item the context menu
61 * is applied. If 0 is passed, the context menu
62 * is above the viewport.
63 * @baseUrl Base URL of the viewport where the context menu
64 * should be opened.
65 */
66 DolphinContextMenu(DolphinMainWindow* parent,
67 const KFileItem& fileInfo,
68 const KUrl& baseUrl);
69
70 virtual ~DolphinContextMenu();
71
72 void setCustomActions(const QList<QAction*>& actions);
73
74 /** Opens the context menu model. */
75 void open();
76
77 private:
78 void openTrashContextMenu();
79 void openTrashItemContextMenu();
80 void openItemContextMenu();
81 void openViewportContextMenu();
82
83 void insertDefaultItemActions(KMenu* popup);
84
85 /**
86 * Adds the "Show menubar" action to the menu if the
87 * menubar is hidden.
88 */
89 void addShowMenubarAction(KMenu* menu);
90
91 /**
92 * Returns a name for adding the URL \a url to the Places panel.
93 */
94 QString placesName(const KUrl& url) const;
95
96 bool placeExists(const KUrl& url) const;
97
98 QAction* createPasteAction();
99
100 private:
101 KFileItemListProperties& capabilities();
102 void addServiceActions(KMenu* menu, KFileItemActions& fileItemActions);
103 void addVersionControlActions(KMenu* menu);
104 void addCustomActions(KMenu* menu);
105
106 private:
107 struct Entry
108 {
109 int type;
110 QString name;
111 QString filePath; // empty for separator
112 QString templatePath; // same as filePath for template
113 QString icon;
114 QString comment;
115 };
116
117 enum ContextType
118 {
119 NoContext = 0,
120 ItemContext = 1,
121 TrashContext = 2
122 };
123
124 DolphinMainWindow* m_mainWindow;
125 KFileItemListProperties* m_capabilities;
126 KFileItem m_fileInfo;
127 KUrl m_baseUrl;
128 KFileItemList m_selectedItems;
129 KUrl::List m_selectedUrls;
130 int m_context;
131 KonqCopyToMenu m_copyToMenu;
132 QList<QAction*> m_customActions;
133 };
134
135 #endif