]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
GIT_SILENT Update Appstream for new release
[dolphin.git] / src / dolphincontextmenu.h
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINCONTEXTMENU_H
8 #define DOLPHINCONTEXTMENU_H
9
10 #include <KFileCopyToMenu>
11 #include <KFileItem>
12 #include <KFileItemActions>
13
14 #include <QMenu>
15 #include <QUrl>
16
17 class QAction;
18 class DolphinMainWindow;
19 class KFileItemListProperties;
20 class DolphinRemoveAction;
21
22 /**
23 * @brief Represents the context menu which appears when doing a right
24 * click on an item or the viewport of the file manager.
25 *
26 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
27 * dynamic sub menus are shown when opening a context menu above
28 * an item:
29 * - 'Open With': Contains all applications which are registered to
30 * open items of the given MIME type.
31 * - 'Actions': Contains all actions which can be applied to the
32 * given item.
33 */
34 class DolphinContextMenu : public QMenu
35 {
36 Q_OBJECT
37
38 public:
39 /**
40 * @parent Pointer to the main window the context menu
41 * belongs to.
42 * @fileInfo Pointer to the file item the context menu
43 * is applied. If 0 is passed, the context menu
44 * is above the viewport.
45 * @selectedItems The selected items for which the context menu
46 * is opened. This list generally includes \a fileInfo.
47 * @baseUrl Base URL of the viewport where the context menu
48 * should be opened.
49 */
50 DolphinContextMenu(DolphinMainWindow *parent,
51 const KFileItem &fileInfo,
52 const KFileItemList &selectedItems,
53 const QUrl &baseUrl,
54 KFileItemActions *fileItemActions);
55
56 ~DolphinContextMenu() override;
57
58 protected:
59 bool eventFilter(QObject *object, QEvent *event) override;
60
61 private:
62 /**
63 * Adds all the actions and menus to this menu based on all given information.
64 * This method calls the other helper methods for adding actions
65 * based on the context given in the constructor.
66 */
67 void addAllActions();
68
69 void addTrashContextMenu();
70 void addTrashItemContextMenu();
71 void addItemContextMenu();
72 void addViewportContextMenu();
73
74 void insertDefaultItemActions(const KFileItemListProperties &);
75
76 bool placeExists(const QUrl &url) const;
77
78 QAction *createPasteAction();
79
80 KFileItemListProperties &selectedItemsProperties() const;
81
82 /**
83 * Returns the file item for m_baseUrl.
84 */
85 KFileItem baseFileItem();
86
87 /**
88 * Adds "Open With" actions
89 */
90 void addOpenWithActions();
91
92 /**
93 * Add services, custom actions, plugins and version control items to the menu
94 */
95 void addAdditionalActions(const KFileItemListProperties &props);
96
97 private:
98 void addDirectoryItemContextMenu();
99 void addOpenParentFolderActions();
100
101 struct Entry {
102 int type;
103 QString name;
104 QString filePath; // empty for separator
105 QString templatePath; // same as filePath for template
106 QString icon;
107 QString comment;
108 };
109
110 enum ContextType {
111 NoContext = 0,
112 ItemContext = 1,
113 TrashContext = 2,
114 TimelineContext = 4,
115 SearchContext = 8,
116 RecentlyUsedContext = 16,
117 };
118
119 DolphinMainWindow *m_mainWindow;
120
121 KFileItem m_fileInfo;
122
123 QUrl m_baseUrl;
124 KFileItem *m_baseFileItem; /// File item for m_baseUrl
125
126 KFileItemList m_selectedItems;
127 mutable KFileItemListProperties *m_selectedItemsProperties;
128
129 int m_context;
130 KFileCopyToMenu m_copyToMenu;
131
132 DolphinRemoveAction *m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
133 KFileItemActions *m_fileItemActions;
134 };
135
136 #endif