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