File indexing completed on 2024-04-28 05:45:25
0001 /* 0002 * SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org> 0003 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef DOLPHINVIEWACTIONHANDLER_H 0009 #define DOLPHINVIEWACTIONHANDLER_H 0010 0011 #include "dolphin_export.h" 0012 #include "selectionmode/bottombar.h" 0013 #include "views/dolphinview.h" 0014 0015 #include <QObject> 0016 0017 class KToggleAction; 0018 class QAction; 0019 class QActionGroup; 0020 class DolphinView; 0021 class KActionCollection; 0022 class KFileItemList; 0023 namespace SelectionMode 0024 { 0025 class ActionTextHelper; 0026 } 0027 0028 /** 0029 * @short Handles all actions for DolphinView 0030 * 0031 * The action handler owns all the actions and slots related to DolphinView, 0032 * but the view that it acts upon can be switched to another one 0033 * (this is used in the case of split views). 0034 * 0035 * The purpose of this class is also to share this code between DolphinMainWindow 0036 * and DolphinPart. 0037 * 0038 * @see DolphinView 0039 * @see DolphinMainWindow 0040 * @see DolphinPart 0041 */ 0042 class DOLPHIN_EXPORT DolphinViewActionHandler : public QObject 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 explicit DolphinViewActionHandler(KActionCollection *collection, SelectionMode::ActionTextHelper *actionTextHelper, QObject *parent); 0048 0049 /** 0050 * Sets the view that this action handler should work on. 0051 */ 0052 void setCurrentView(DolphinView *view); 0053 0054 /** 0055 * Returns the view that this action handler should work on. 0056 */ 0057 DolphinView *currentView(); 0058 0059 /** 0060 * Returns the name of the action for the current viewmode 0061 */ 0062 QString currentViewModeActionName() const; 0063 0064 /** 0065 * Returns m_actionCollection 0066 */ 0067 KActionCollection *actionCollection(); 0068 0069 public Q_SLOTS: 0070 /** 0071 * Update all actions in the 'View' menu, i.e. those that depend on the 0072 * settings in the current view. 0073 */ 0074 void updateViewActions(); 0075 0076 Q_SIGNALS: 0077 /** 0078 * Emitted by DolphinViewActionHandler when the user triggered an action. 0079 * This is only used for clearing the statusbar in DolphinMainWindow. 0080 */ 0081 void actionBeingHandled(); 0082 0083 /** 0084 * Emitted if the user requested creating a new directory by the F10 key. 0085 * The receiver of the signal (DolphinMainWindow or DolphinPart) invokes 0086 * the method createDirectory of their KNewFileMenu instance. 0087 */ 0088 void createDirectoryTriggered(); 0089 0090 /** Used to request either entering or leaving of selection mode */ 0091 void selectionModeChangeTriggered(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents = SelectionMode::BottomBar::Contents::GeneralContents); 0092 0093 private Q_SLOTS: 0094 /** 0095 * Emitted when the user requested a change of view mode 0096 */ 0097 void slotViewModeActionTriggered(QAction *); 0098 0099 /** 0100 * Let the user input a name for the selected item(s) and trigger 0101 * a renaming afterwards. 0102 */ 0103 void slotRename(); 0104 0105 /** 0106 * Moves the selected items of the active view to the trash. 0107 * This methods adds "shift means del" handling. 0108 */ 0109 void slotTrashActivated(); 0110 0111 /** 0112 * Deletes the selected items of the active view. 0113 */ 0114 void slotDeleteItems(); 0115 0116 /** 0117 * Switches between showing a preview of the file content and showing the icon. 0118 */ 0119 void togglePreview(bool); 0120 0121 /** Updates the state of the 'Show preview' menu action. */ 0122 void slotPreviewsShownChanged(bool shown); 0123 0124 /** Increases the size of the current set view mode. */ 0125 void zoomIn(); 0126 0127 /** Decreases the size of the current set view mode. */ 0128 void zoomOut(); 0129 0130 /** Resets the size of the current set view mode to default. */ 0131 void zoomReset(); 0132 0133 /** Switches between a separate sorting and a mixed sorting of files and folders. */ 0134 void toggleSortFoldersFirst(); 0135 0136 /** 0137 * Updates the state of the 'Sort Ascending/Descending' action. 0138 */ 0139 void slotSortOrderChanged(Qt::SortOrder order); 0140 0141 /** 0142 * Updates the state of the 'Sort Folders First' action. 0143 */ 0144 void slotSortFoldersFirstChanged(bool foldersFirst); 0145 0146 /** 0147 * Switches between showing hidden files last or not. 0148 */ 0149 void toggleSortHiddenLast(); 0150 0151 /** 0152 * Updates the state of the 'Sort Hidden Last' action. 0153 */ 0154 void slotSortHiddenLastChanged(bool hiddenLast); 0155 0156 /** 0157 * Updates the state of the 'Sort by' actions. 0158 */ 0159 void slotSortRoleChanged(const QByteArray &role); 0160 0161 /** 0162 * Updates the state of the 'Zoom In' and 'Zoom Out' actions. 0163 */ 0164 void slotZoomLevelChanged(int current, int previous); 0165 0166 /** 0167 * Switches on or off the displaying of additional information 0168 * as specified by \a action. 0169 */ 0170 void toggleVisibleRole(QAction *action); 0171 0172 /** 0173 * Changes the sorting of the current view. 0174 */ 0175 void slotSortTriggered(QAction *); 0176 0177 /** 0178 * Updates the state of the 'Additional Information' actions. 0179 */ 0180 void slotVisibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous); 0181 0182 /** 0183 * Switches between sorting by groups or not. 0184 */ 0185 void toggleGroupedSorting(bool); 0186 0187 /** 0188 * Updates the state of the 'Categorized sorting' menu action. 0189 */ 0190 void slotGroupedSortingChanged(bool sortCategorized); 0191 0192 /** 0193 * Switches between showing and hiding of hidden marked files 0194 */ 0195 void toggleShowHiddenFiles(bool); 0196 0197 /** 0198 * Updates the state of the 'Show hidden files' menu action. 0199 */ 0200 void slotHiddenFilesShownChanged(bool shown); 0201 0202 /** 0203 * Updates the state of the 'Create Folder...' action. 0204 */ 0205 void slotWriteStateChanged(bool isFolderWritable); 0206 0207 /** 0208 * Opens the view properties dialog, which allows to modify the properties 0209 * of the currently active view. 0210 */ 0211 void slotAdjustViewProperties(); 0212 0213 /** 0214 * Begins a duplicate operation on the selected files 0215 */ 0216 void slotDuplicate(); 0217 0218 /** 0219 * Connected to the "properties" action. 0220 * Opens the properties dialog for the selected items of the 0221 * active view. The properties dialog shows information 0222 * like name, size and permissions. 0223 */ 0224 void slotProperties(); 0225 0226 /** 0227 * Copies the path of the first selected KFileItem into Clipboard. 0228 */ 0229 void slotCopyPath(); 0230 0231 /** 0232 * Changes the name of the menu that contains basic actions like "Copy", "Rename", ... 0233 * The name is changed to something like "Actions for 3 Selected Items" to be extra 0234 * explicit of how these basic actions are used. 0235 */ 0236 void slotSelectionChanged(const KFileItemList &selection); 0237 0238 private: 0239 /** 0240 * Create all the actions. 0241 * This is called only once (by the constructor) 0242 */ 0243 void createActions(SelectionMode::ActionTextHelper *actionTextHelper); 0244 0245 /** 0246 * Creates an action-group out of all roles from KFileItemModel. 0247 * Dependent on the group-prefix either a radiobutton-group is 0248 * created for sorting (prefix is "sort_by_") or a checkbox-group 0249 * is created for additional information (prefix is "show_"). 0250 * The changes of actions are reported to slotSortTriggered() or 0251 * toggleAdditionalInfo(). 0252 */ 0253 QActionGroup *createFileItemRolesActionGroup(const QString &groupPrefix); 0254 0255 /** 0256 * Returns the "switch to icons mode" action. 0257 * Helper method for createActions(); 0258 */ 0259 KToggleAction *iconsModeAction(); 0260 0261 /** 0262 * Returns the "switch to compact mode" action. 0263 * Helper method for createActions(); 0264 */ 0265 KToggleAction *compactModeAction(); 0266 0267 /** 0268 * Returns the "switch to details mode" action. 0269 * Helper method for createActions(); 0270 */ 0271 KToggleAction *detailsModeAction(); 0272 0273 KActionCollection *m_actionCollection; 0274 DolphinView *m_currentView; 0275 0276 QHash<QByteArray, KToggleAction *> m_sortByActions; 0277 QHash<QByteArray, KToggleAction *> m_visibleRoles; 0278 }; 0279 0280 #endif /* DOLPHINVIEWACTIONHANDLER_H */