]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Backport for #156375: don't add a place having an empty name
[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
28 #include <QtCore/QObject>
29
30 #include <QtCore/QVector>
31
32 class KMenu;
33 class KFileItem;
34 class QAction;
35 class DolphinMainWindow;
36
37 /**
38 * @brief Represents the context menu which appears when doing a right
39 * click on an item or the viewport of the file manager.
40 *
41 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
42 * dynamic sub menus are shown when opening a context menu above
43 * an item:
44 * - 'Open With': Contains all applications which are registered to
45 * open items of the given MIME type.
46 * - 'Actions': Contains all actions which can be applied to the
47 * given item.
48 */
49 class DolphinContextMenu : public QObject
50 {
51 Q_OBJECT
52
53 public:
54 /**
55 * @parent Pointer to the main window the context menu
56 * belongs to.
57 * @fileInfo Pointer to the file item the context menu
58 * is applied. If 0 is passed, the context menu
59 * is above the viewport.
60 * @baseUrl Base URL of the viewport where the context menu
61 * should be opened.
62 */
63 DolphinContextMenu(DolphinMainWindow* parent,
64 const KFileItem& fileInfo,
65 const KUrl& baseUrl);
66
67 virtual ~DolphinContextMenu();
68
69 /** Opens the context menu model. */
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 * Returns true, if 'menu' contains already
95 * an entry with the name 'entryName'.
96 */
97 bool containsEntry(const KMenu* menu,
98 const QString& entryName) const;
99
100 /**
101 * Adds the "Show menubar" action to the menu if the
102 * menubar is hidden.
103 */
104 void addShowMenubarAction(KMenu* menu);
105
106 /**
107 * Returns a name for adding the URL \a url to the Places panel.
108 */
109 QString placesName(const KUrl& url) const;
110
111 private:
112 struct Entry
113 {
114 int type;
115 QString name;
116 QString filePath; // empty for separator
117 QString templatePath; // same as filePath for template
118 QString icon;
119 QString comment;
120 };
121
122 enum ContextType
123 {
124 NoContext = 0,
125 ItemContext = 1,
126 TrashContext = 2
127 };
128
129 DolphinMainWindow* m_mainWindow;
130 KFileItem m_fileInfo;
131 KUrl m_baseUrl;
132 KFileItemList m_selectedItems;
133 KUrl::List m_selectedUrls;
134 int m_context;
135 };
136
137 #endif