]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Don't force the context menu to be valid only for DolphinView instances, make it...
[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 /**
52 * @parent Pointer to the main window the context menu
53 * belongs to.
54 * @fileInfo Pointer to the file item the context menu
55 * is applied. If 0 is passed, the context menu
56 * is above the viewport.
57 * @baseUrl Base URL of the viewport where the context menu
58 * should be opened.
59 * @selectedItems Selected items where the actions of the context menu
60 * are applied.
61 */
62 DolphinContextMenu(DolphinMainWindow* parent,
63 KFileItem* fileInfo,
64 const KUrl& baseUrl,
65 KFileItemList selectedItems);
66
67 virtual ~DolphinContextMenu();
68
69 /** Opens the context menu modal. */
70 void open();
71
72 private:
73 void openTrashContextMenu();
74 void openTrashItemContextMenu();
75 void openItemContextMenu();
76 void openViewportContextMenu();
77
78 void insertDefaultItemActions(KMenu* popup);
79
80 /**
81 * Inserts the 'Open With...' submenu to \a popup.
82 * @param popup Menu where the 'Open With...' sub menu should
83 * be added.
84 * @param openWithVector Output parameter which contains all 'Open with...'
85 * services.
86 * @return Identifier of the first 'Open With...' entry.
87 * All succeeding identifiers have an increased value of 1
88 * to the predecessor.
89 */
90 QList<QAction*> insertOpenWithItems(KMenu* popup,
91 QVector<KService::Ptr>& openWithVector);
92
93 /**
94 * Inserts the 'Actions...' submenu to \a popup.
95 * @param popup Menu where the 'Actions...' sub menu should
96 * be added.
97 * @param openWithVector Output parameter which contains all 'Actions...'
98 * services.
99 */
100 QList<QAction*> insertActionItems(KMenu* popup,
101 QVector<KDEDesktopMimeType::Service>& actionsVector);
102
103 /**
104 * Returns true, if 'menu' contains already
105 * an entry with the name 'entryName'.
106 */
107 bool containsEntry(const KMenu* menu,
108 const QString& entryName) const;
109
110 private:
111 struct Entry {
112 int type;
113 QString name;
114 QString filePath; // empty for separator
115 QString templatePath; // same as filePath for template
116 QString icon;
117 QString comment;
118 };
119
120 enum ContextType {
121 NoContext = 0,
122 ItemContext = 1,
123 TrashContext = 2
124 };
125
126 DolphinMainWindow* m_mainWindow;
127 KFileItem* m_fileInfo;
128 KUrl m_baseUrl;
129 KFileItemList m_selectedItems;
130 KUrl::List m_selectedUrls;
131 int m_context;
132 };
133
134 #endif