]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Create shared lib as discussed with David and Peter
[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 <kdedesktopmimetype.h>
24 #include <kfileitem.h>
25 #include <kservice.h>
26 #include <kurl.h>
27
28 #include <QObject>
29 #include <QString>
30 #include <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 enum ViewType
55 {
56 ItemsView,
57 SidebarView
58 };
59
60 /**
61 * @parent Pointer to the main window the context menu
62 * belongs to.
63 * @fileInfo Pointer to the file item the context menu
64 * is applied. If 0 is passed, the context menu
65 * is above the viewport.
66 * @baseUrl Base URL of the viewport where the context menu
67 * should be opened.
68 * @viewType On which view type is the context menu shown.
69 */
70 DolphinContextMenu(DolphinMainWindow* parent,
71 KFileItem* fileInfo,
72 const KUrl& baseUrl,
73 ViewType viewType = ItemsView);
74
75 virtual ~DolphinContextMenu();
76
77 /** Opens the context menu modal. */
78 void open();
79
80 private slots:
81 /** Cuts the item m_fileInfo. */
82 void cut();
83
84 /** Copies the item m_fileInfo. */
85 void copy();
86
87 /** Paste the clipboard to m_fileInfo. */
88 void paste();
89
90 /** Renames the item m_fileInfo. */
91 void rename();
92
93 /** Moves the item m_fileInfo to the trash. */
94 void moveToTrash();
95
96 /** Deletes the item m_fileInfo. */
97 void deleteItem();
98
99 /** Shows the properties of the item m_fileInfo. */
100 void showProperties();
101
102 private:
103 void openTrashContextMenu();
104 void openTrashItemContextMenu();
105 void openItemContextMenu();
106 void openViewportContextMenu();
107
108 void insertDefaultItemActions(KMenu* popup);
109
110 /**
111 * Inserts the 'Open With...' submenu to \a popup.
112 * @param popup Menu where the 'Open With...' sub menu should
113 * be added.
114 * @param openWithVector Output parameter which contains all 'Open with...'
115 * services.
116 * @return Identifier of the first 'Open With...' entry.
117 * All succeeding identifiers have an increased value of 1
118 * to the predecessor.
119 */
120 QList<QAction*> insertOpenWithItems(KMenu* popup,
121 QVector<KService::Ptr>& openWithVector);
122
123 /**
124 * Inserts the 'Actions...' submenu to \a popup.
125 * @param popup Menu where the 'Actions...' sub menu should
126 * be added.
127 * @param openWithVector Output parameter which contains all 'Actions...'
128 * services.
129 */
130 QList<QAction*> insertActionItems(KMenu* popup,
131 QVector<KDEDesktopMimeType::Service>& actionsVector);
132
133 /**
134 * Returns true, if 'menu' contains already
135 * an entry with the name 'entryName'.
136 */
137 bool containsEntry(const KMenu* menu,
138 const QString& entryName) const;
139
140 private:
141 struct Entry {
142 int type;
143 QString name;
144 QString filePath; // empty for separator
145 QString templatePath; // same as filePath for template
146 QString icon;
147 QString comment;
148 };
149
150 enum ContextType {
151 NoContext = 0,
152 ItemContext = 1,
153 TrashContext = 2
154 };
155
156 DolphinMainWindow* m_mainWindow;
157 KFileItem* m_fileInfo;
158 KUrl m_baseUrl;
159 KFileItemList m_selectedItems;
160 KUrl::List m_selectedUrls;
161 ViewType m_viewType;
162 int m_context;
163 };
164
165 #endif