]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Fix the edit-menu action disabling/enabling bug in dolphinpart finally! Also, move...
[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 #include <konq_copytomenu.h>
28
29 #include <QtCore/QObject>
30
31 #include <QtCore/QVector>
32
33 class KMenu;
34 class KFileItem;
35 class QAction;
36 class DolphinMainWindow;
37 class KonqFileItemCapabilities;
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 class DolphinContextMenu : public QObject
52 {
53 Q_OBJECT
54
55 public:
56 /**
57 * @parent Pointer to the main window 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 * @baseUrl Base URL of the viewport where the context menu
63 * should be opened.
64 */
65 DolphinContextMenu(DolphinMainWindow* parent,
66 const KFileItem& fileInfo,
67 const KUrl& baseUrl);
68
69 virtual ~DolphinContextMenu();
70
71 /** Opens the context menu model. */
72 void open();
73
74 private:
75 void openTrashContextMenu();
76 void openTrashItemContextMenu();
77 void openItemContextMenu();
78 void openViewportContextMenu();
79
80 void insertDefaultItemActions(KMenu* popup);
81
82 /**
83 * Inserts the 'Open With...' submenu to \a popup.
84 * @param popup Menu where the 'Open With...' sub menu should
85 * be added.
86 * @param openWithVector Output parameter which contains all 'Open with...'
87 * services.
88 * @return Identifier of the first 'Open With...' entry.
89 * All succeeding identifiers have an increased value of 1
90 * to the predecessor.
91 */
92 QList<QAction*> insertOpenWithItems(KMenu* popup,
93 QVector<KService::Ptr>& openWithVector);
94
95 /**
96 * Returns true, if 'menu' contains already
97 * an entry with the name 'entryName'.
98 */
99 bool containsEntry(const KMenu* menu,
100 const QString& entryName) const;
101
102 /**
103 * Adds the "Show menubar" action to the menu if the
104 * menubar is hidden.
105 */
106 void addShowMenubarAction(KMenu* menu);
107
108 /**
109 * Returns a name for adding the URL \a url to the Places panel.
110 */
111 QString placesName(const KUrl& url) const;
112
113 QAction* createPasteAction();
114
115 private:
116 KonqFileItemCapabilities& capabilities();
117
118 private:
119 struct Entry
120 {
121 int type;
122 QString name;
123 QString filePath; // empty for separator
124 QString templatePath; // same as filePath for template
125 QString icon;
126 QString comment;
127 };
128
129 enum ContextType
130 {
131 NoContext = 0,
132 ItemContext = 1,
133 TrashContext = 2
134 };
135
136 DolphinMainWindow* m_mainWindow;
137 KonqFileItemCapabilities* m_capabilities;
138 KFileItem m_fileInfo;
139 KUrl m_baseUrl;
140 KFileItemList m_selectedItems;
141 KUrl::List m_selectedUrls;
142 int m_context;
143 KonqCopyToMenu m_copyToMenu;
144 };
145
146 #endif