]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
commited initial version of Dolphin
[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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <kmountpoint.h>
28 #include <q3valuevector.h>
29 #include <kservice.h>
30 #include <kpropertiesdialog.h>
31 #include <kdedesktopmimetype.h>
32
33 class KPopupMenu;
34 class KFileItem;
35 class QPoint;
36 class QWidget;
37 class DolphinView;
38
39 /**
40 * @brief Represents the context menu which appears when doing a right
41 * click on an item or the viewport of the file manager.
42 *
43 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
44 * dynamic sub menus are shown when opening a context menu above
45 * an item:
46 * - 'Open With': Contains all applications which are registered to
47 * open items of the given MIME type.
48 * - 'Actions': Contains all actions which can be applied to the
49 * given item.
50 *
51 * @author Peter Penz <peter.penz@gmx.at>
52 */
53 class DolphinContextMenu
54 {
55 public:
56 /**
57 * @parent Pointer to the dolphin view the context menu
58 * belongs to.
59 * @fileInfo Pointer to the file item the context menu
60 * is applied. If 0 is passed, the context menu
61 * is above the viewport.
62 * @pos Position of the upper left edge of the context menu.
63 */
64 DolphinContextMenu(DolphinView* parent,
65 KFileItem* fileInfo,
66 const QPoint& pos);
67
68 virtual ~DolphinContextMenu();
69
70 /** Opens the context menu modal. */
71 void open();
72
73 private:
74 void openViewportContextMenu();
75 void openItemContextMenu();
76
77 /**
78 * Inserts the 'Open With...' submenu to \a popup.
79 * @param popup Menu where the 'Open With...' sub menu should
80 * be added.
81 * @param openWithVector Output parameter which contains all 'Open with...'
82 * services.
83 * @return Identifier of the first 'Open With...' entry.
84 * All succeeding identifiers have an increased value of 1
85 * to the predecessor.
86 */
87 int insertOpenWithItems(KPopupMenu* popup,
88 Q3ValueVector<KService::Ptr>& openWithVector);
89
90 /**
91 * Inserts the 'Actions...' submenu to \a popup.
92 * @param popup Menu where the 'Actions...' sub menu should
93 * be added.
94 * @param openWithVector Output parameter which contains all 'Actions...'
95 * services.
96 */
97 void insertActionItems(KPopupMenu* popup,
98 Q3ValueVector<KDEDesktopMimeType::Service>& actionsVector);
99
100 /**
101 * Returns true, if 'menu' contains already
102 * an entry with the name 'entryName'.
103 */
104 bool containsEntry(const KPopupMenu* menu,
105 const QString& entryName) const;
106
107 enum {
108 submenuID = 90,
109 bookmarkID = 91,
110 openWithIDStart = 100,
111 actionsIDStart = 1000,
112 };
113
114 DolphinView* m_dolphinView;
115 KFileItem* m_fileInfo;
116 QPoint m_pos;
117
118 struct Entry {
119 int type;
120 QString name;
121 QString filePath; // empty for separator
122 QString templatePath; // same as filePath for template
123 QString icon;
124 QString comment;
125 };
126 };
127
128 #endif