]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Let's keep it simple: only offer a basic context menu for the treeview sidebar.
[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 <kdedesktopmimetype.h>
24 #include <kfileitem.h>
25 #include <kservice.h>
26 #include <kurl.h>
27
28 #include <QString>
29 #include <QVector>
30
31 class KMenu;
32 class KFileItem;
33 class QAction;
34 class DolphinMainWindow;
35
36 /**
37 * @brief Represents the context menu which appears when doing a right
38 * click on an item or the viewport of the file manager.
39 *
40 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
41 * dynamic sub menus are shown when opening a context menu above
42 * an item:
43 * - 'Open With': Contains all applications which are registered to
44 * open items of the given MIME type.
45 * - 'Actions': Contains all actions which can be applied to the
46 * given item.
47 */
48 class DolphinContextMenu
49 {
50 public:
51 enum ViewType
52 {
53 ItemsView,
54 SidebarView
55 };
56
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 * @viewType On which view type is the context menu shown.
66 */
67 DolphinContextMenu(DolphinMainWindow* parent,
68 KFileItem* fileInfo,
69 const KUrl& baseUrl,
70 ViewType viewType = ItemsView);
71
72 virtual ~DolphinContextMenu();
73
74 /** Opens the context menu modal. */
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 * Inserts the 'Open With...' submenu to \a popup.
87 * @param popup Menu where the 'Open With...' sub menu should
88 * be added.
89 * @param openWithVector Output parameter which contains all 'Open with...'
90 * services.
91 * @return Identifier of the first 'Open With...' entry.
92 * All succeeding identifiers have an increased value of 1
93 * to the predecessor.
94 */
95 QList<QAction*> insertOpenWithItems(KMenu* popup,
96 QVector<KService::Ptr>& openWithVector);
97
98 /**
99 * Inserts the 'Actions...' submenu to \a popup.
100 * @param popup Menu where the 'Actions...' sub menu should
101 * be added.
102 * @param openWithVector Output parameter which contains all 'Actions...'
103 * services.
104 */
105 QList<QAction*> insertActionItems(KMenu* popup,
106 QVector<KDEDesktopMimeType::Service>& actionsVector);
107
108 /**
109 * Returns true, if 'menu' contains already
110 * an entry with the name 'entryName'.
111 */
112 bool containsEntry(const KMenu* menu,
113 const QString& entryName) const;
114
115 private:
116 struct Entry {
117 int type;
118 QString name;
119 QString filePath; // empty for separator
120 QString templatePath; // same as filePath for template
121 QString icon;
122 QString comment;
123 };
124
125 enum ContextType {
126 NoContext = 0,
127 ItemContext = 1,
128 TrashContext = 2
129 };
130
131 DolphinMainWindow* m_mainWindow;
132 KFileItem* m_fileInfo;
133 KUrl m_baseUrl;
134 KFileItemList m_selectedItems;
135 KUrl::List m_selectedUrls;
136 ViewType m_viewType;
137 int m_context;
138 };
139
140 #endif