]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
-pedantic
[dolphin.git] / src / dolphincontextmenu.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #ifndef DOLPHINCONTEXTMENU_H
22 #define DOLPHINCONTEXTMENU_H
23
24 #include <qpoint.h>
25 #include <qstring.h>
26 #include <q3valuelist.h>
27 #include <q3valuevector.h>
28 #include <kservice.h>
29 #include <kpropertiesdialog.h>
30 #include <kdedesktopmimetype.h>
31
32 class KMenu;
33 class KFileItem;
34 class QPoint;
35 class QWidget;
36 class DolphinView;
37
38 /**
39 * @brief Represents the context menu which appears when doing a right
40 * click on an item or the viewport of the file manager.
41 *
42 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
43 * dynamic sub menus are shown when opening a context menu above
44 * an item:
45 * - 'Open With': Contains all applications which are registered to
46 * open items of the given MIME type.
47 * - 'Actions': Contains all actions which can be applied to the
48 * given item.
49 *
50 * @author Peter Penz <peter.penz@gmx.at>
51 */
52 class DolphinContextMenu
53 {
54 public:
55 /**
56 * @parent Pointer to the dolphin view the context menu
57 * belongs to.
58 * @fileInfo Pointer to the file item the context menu
59 * is applied. If 0 is passed, the context menu
60 * is above the viewport.
61 * @pos Position of the upper left edge of the context menu.
62 */
63 DolphinContextMenu(DolphinView* parent,
64 KFileItem* fileInfo,
65 const QPoint& pos);
66
67 virtual ~DolphinContextMenu();
68
69 /** Opens the context menu modal. */
70 void open();
71
72 private:
73 void openViewportContextMenu();
74 void openItemContextMenu();
75
76 /**
77 * Inserts the 'Open With...' submenu to \a popup.
78 * @param popup Menu where the 'Open With...' sub menu should
79 * be added.
80 * @param openWithVector Output parameter which contains all 'Open with...'
81 * services.
82 * @return Identifier of the first 'Open With...' entry.
83 * All succeeding identifiers have an increased value of 1
84 * to the predecessor.
85 */
86 QList<QAction*> insertOpenWithItems(KMenu* popup,
87 Q3ValueVector<KService::Ptr>& openWithVector);
88
89 /**
90 * Inserts the 'Actions...' submenu to \a popup.
91 * @param popup Menu where the 'Actions...' sub menu should
92 * be added.
93 * @param openWithVector Output parameter which contains all 'Actions...'
94 * services.
95 */
96 QList<QAction*> insertActionItems(KMenu* popup,
97 Q3ValueVector<KDEDesktopMimeType::Service>& actionsVector);
98
99 /**
100 * Returns true, if 'menu' contains already
101 * an entry with the name 'entryName'.
102 */
103 bool containsEntry(const KMenu* menu,
104 const QString& entryName) const;
105
106 enum {
107 submenuID = 90,
108 bookmarkID = 91,
109 openWithIDStart = 100,
110 actionsIDStart = 1000
111 };
112
113 DolphinView* m_dolphinView;
114 KFileItem* m_fileInfo;
115 QPoint m_pos;
116
117 struct Entry {
118 int type;
119 QString name;
120 QString filePath; // empty for separator
121 QString templatePath; // same as filePath for template
122 QString icon;
123 QString comment;
124 };
125 };
126
127 #endif