]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Thanks to David Faure the 'Copy To' and 'Move To' menus in the context menu can also...
[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
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 class DolphinContextMenu : public QObject
51 {
52 Q_OBJECT
53
54 public:
55 /**
56 * @parent Pointer to the main window 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 * @baseUrl Base URL of the viewport where the context menu
62 * should be opened.
63 */
64 DolphinContextMenu(DolphinMainWindow* parent,
65 const KFileItem& fileInfo,
66 const KUrl& baseUrl);
67
68 virtual ~DolphinContextMenu();
69
70 /** Opens the context menu model. */
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 * Returns true, if 'menu' contains already
96 * an entry with the name 'entryName'.
97 */
98 bool containsEntry(const KMenu* menu,
99 const QString& entryName) const;
100
101 /**
102 * Adds the "Show menubar" action to the menu if the
103 * menubar is hidden.
104 */
105 void addShowMenubarAction(KMenu* menu);
106
107 /**
108 * Returns a name for adding the URL \a url to the Places panel.
109 */
110 QString placesName(const KUrl& url) const;
111
112 QAction* createPasteAction();
113
114 private:
115 struct Entry
116 {
117 int type;
118 QString name;
119 QString filePath; // empty for separator
120 QString templatePath; // same as filePath for template
121 QString icon;
122 QString comment;
123 };
124
125 enum ContextType
126 {
127 NoContext = 0,
128 ItemContext = 1,
129 TrashContext = 2
130 };
131
132 DolphinMainWindow* m_mainWindow;
133 KFileItem m_fileInfo;
134 KUrl m_baseUrl;
135 KFileItemList m_selectedItems;
136 KUrl::List m_selectedUrls;
137 int m_context;
138 KonqCopyToMenu m_copyToMenu;
139 };
140
141 #endif