File indexing completed on 2024-04-14 15:49:25
0001 /* 0002 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef DOLPHINCONTEXTMENU_H 0008 #define DOLPHINCONTEXTMENU_H 0009 0010 #include <KFileCopyToMenu> 0011 #include <KFileItem> 0012 #include <KFileItemActions> 0013 0014 #include <QMenu> 0015 #include <QUrl> 0016 0017 class QAction; 0018 class DolphinMainWindow; 0019 class KFileItemListProperties; 0020 class DolphinRemoveAction; 0021 0022 /** 0023 * @brief Represents the context menu which appears when doing a right 0024 * click on an item or the viewport of the file manager. 0025 * 0026 * Beside static menu entries (e. g. 'Paste' or 'Properties') two 0027 * dynamic sub menus are shown when opening a context menu above 0028 * an item: 0029 * - 'Open With': Contains all applications which are registered to 0030 * open items of the given MIME type. 0031 * - 'Actions': Contains all actions which can be applied to the 0032 * given item. 0033 */ 0034 class DolphinContextMenu : public QMenu 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 /** 0040 * @parent Pointer to the main window the context menu 0041 * belongs to. 0042 * @fileInfo Pointer to the file item the context menu 0043 * is applied. If 0 is passed, the context menu 0044 * is above the viewport. 0045 * @selectedItems The selected items for which the context menu 0046 * is opened. This list generally includes \a fileInfo. 0047 * @baseUrl Base URL of the viewport where the context menu 0048 * should be opened. 0049 */ 0050 DolphinContextMenu(DolphinMainWindow *parent, 0051 const KFileItem &fileInfo, 0052 const KFileItemList &selectedItems, 0053 const QUrl &baseUrl, 0054 KFileItemActions *fileItemActions); 0055 0056 ~DolphinContextMenu() override; 0057 0058 protected: 0059 bool eventFilter(QObject *object, QEvent *event) override; 0060 0061 private: 0062 /** 0063 * Adds all the actions and menus to this menu based on all given information. 0064 * This method calls the other helper methods for adding actions 0065 * based on the context given in the constructor. 0066 */ 0067 void addAllActions(); 0068 0069 void addTrashContextMenu(); 0070 void addTrashItemContextMenu(); 0071 void addItemContextMenu(); 0072 void addViewportContextMenu(); 0073 0074 void insertDefaultItemActions(const KFileItemListProperties &); 0075 0076 bool placeExists(const QUrl &url) const; 0077 0078 QAction *createPasteAction(); 0079 0080 KFileItemListProperties &selectedItemsProperties() const; 0081 0082 /** 0083 * Returns the file item for m_baseUrl. 0084 */ 0085 KFileItem baseFileItem(); 0086 0087 /** 0088 * Adds "Open With" actions 0089 */ 0090 void addOpenWithActions(); 0091 0092 /** 0093 * Add services, custom actions, plugins and version control items to the menu 0094 */ 0095 void addAdditionalActions(const KFileItemListProperties &props); 0096 0097 private: 0098 void addDirectoryItemContextMenu(); 0099 void addOpenParentFolderActions(); 0100 0101 struct Entry { 0102 int type; 0103 QString name; 0104 QString filePath; // empty for separator 0105 QString templatePath; // same as filePath for template 0106 QString icon; 0107 QString comment; 0108 }; 0109 0110 enum ContextType { 0111 NoContext = 0, 0112 ItemContext = 1, 0113 TrashContext = 2, 0114 TimelineContext = 4, 0115 SearchContext = 8, 0116 RecentlyUsedContext = 16, 0117 }; 0118 0119 DolphinMainWindow *m_mainWindow; 0120 0121 KFileItem m_fileInfo; 0122 0123 QUrl m_baseUrl; 0124 KFileItem *m_baseFileItem; /// File item for m_baseUrl 0125 0126 KFileItemList m_selectedItems; 0127 mutable KFileItemListProperties *m_selectedItemsProperties; 0128 0129 int m_context; 0130 KFileCopyToMenu m_copyToMenu; 0131 0132 DolphinRemoveAction *m_removeAction; // Action that represents either 'Move To Trash' or 'Delete' 0133 KFileItemActions *m_fileItemActions; 0134 }; 0135 0136 #endif