]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
SVN_SILENT: assure that the position of the methods in the cpp file matchs with the...
[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 slots:
73 void pasteIntoFolder();
74
75 private:
76 void openTrashContextMenu();
77 void openTrashItemContextMenu();
78 void openItemContextMenu();
79 void openViewportContextMenu();
80
81 void insertDefaultItemActions(KMenu* popup);
82
83 /**
84 * Inserts the 'Open With...' submenu to \a popup.
85 * @param popup Menu where the 'Open With...' sub menu should
86 * be added.
87 * @param openWithVector Output parameter which contains all 'Open with...'
88 * services.
89 * @return Identifier of the first 'Open With...' entry.
90 * All succeeding identifiers have an increased value of 1
91 * to the predecessor.
92 */
93 QList<QAction*> insertOpenWithItems(KMenu* popup,
94 QVector<KService::Ptr>& openWithVector);
95
96 /**
97 * Returns true, if 'menu' contains already
98 * an entry with the name 'entryName'.
99 */
100 bool containsEntry(const KMenu* menu,
101 const QString& entryName) const;
102
103 /**
104 * Adds the "Show menubar" action to the menu if the
105 * menubar is hidden.
106 */
107 void addShowMenubarAction(KMenu* menu);
108
109 /**
110 * Returns a name for adding the URL \a url to the Places panel.
111 */
112 QString placesName(const KUrl& url) const;
113
114 QAction* createPasteAction();
115
116 private:
117 struct Entry
118 {
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 enum ContextType
128 {
129 NoContext = 0,
130 ItemContext = 1,
131 TrashContext = 2
132 };
133
134 DolphinMainWindow* m_mainWindow;
135 KFileItem m_fileInfo;
136 KUrl m_baseUrl;
137 KFileItemList m_selectedItems;
138 KUrl::List m_selectedUrls;
139 int m_context;
140 };
141
142 #endif