]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinviewactionhandler.h
Add clang-format and format code as in Frameworks
[dolphin.git] / src / views / dolphinviewactionhandler.h
1 /*
2 * SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
3 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #ifndef DOLPHINVIEWACTIONHANDLER_H
9 #define DOLPHINVIEWACTIONHANDLER_H
10
11 #include "dolphin_export.h"
12 #include "selectionmode/bottombar.h"
13 #include "views/dolphinview.h"
14
15 #include <QObject>
16
17 class KToggleAction;
18 class QAction;
19 class QActionGroup;
20 class DolphinView;
21 class KActionCollection;
22 class KFileItemList;
23 namespace SelectionMode
24 {
25 class ActionTextHelper;
26 }
27
28 /**
29 * @short Handles all actions for DolphinView
30 *
31 * The action handler owns all the actions and slots related to DolphinView,
32 * but the view that it acts upon can be switched to another one
33 * (this is used in the case of split views).
34 *
35 * The purpose of this class is also to share this code between DolphinMainWindow
36 * and DolphinPart.
37 *
38 * @see DolphinView
39 * @see DolphinMainWindow
40 * @see DolphinPart
41 */
42 class DOLPHIN_EXPORT DolphinViewActionHandler : public QObject
43 {
44 Q_OBJECT
45
46 public:
47 explicit DolphinViewActionHandler(KActionCollection *collection, SelectionMode::ActionTextHelper *actionTextHelper, QObject *parent);
48
49 /**
50 * Sets the view that this action handler should work on.
51 */
52 void setCurrentView(DolphinView *view);
53
54 /**
55 * Returns the view that this action handler should work on.
56 */
57 DolphinView *currentView();
58
59 /**
60 * Returns the name of the action for the current viewmode
61 */
62 QString currentViewModeActionName() const;
63
64 /**
65 * Returns m_actionCollection
66 */
67 KActionCollection *actionCollection();
68
69 public Q_SLOTS:
70 /**
71 * Update all actions in the 'View' menu, i.e. those that depend on the
72 * settings in the current view.
73 */
74 void updateViewActions();
75
76 Q_SIGNALS:
77 /**
78 * Emitted by DolphinViewActionHandler when the user triggered an action.
79 * This is only used for clearing the statusbar in DolphinMainWindow.
80 */
81 void actionBeingHandled();
82
83 /**
84 * Emitted if the user requested creating a new directory by the F10 key.
85 * The receiver of the signal (DolphinMainWindow or DolphinPart) invokes
86 * the method createDirectory of their KNewFileMenu instance.
87 */
88 void createDirectoryTriggered();
89
90 /** Used to request either entering or leaving of selection mode */
91 void selectionModeChangeTriggered(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents = SelectionMode::BottomBar::Contents::GeneralContents);
92
93 private Q_SLOTS:
94 /**
95 * Emitted when the user requested a change of view mode
96 */
97 void slotViewModeActionTriggered(QAction *);
98
99 /**
100 * Let the user input a name for the selected item(s) and trigger
101 * a renaming afterwards.
102 */
103 void slotRename();
104
105 /**
106 * Moves the selected items of the active view to the trash.
107 * This methods adds "shift means del" handling.
108 */
109 void slotTrashActivated();
110
111 /**
112 * Deletes the selected items of the active view.
113 */
114 void slotDeleteItems();
115
116 /**
117 * Switches between showing a preview of the file content and showing the icon.
118 */
119 void togglePreview(bool);
120
121 /** Updates the state of the 'Show preview' menu action. */
122 void slotPreviewsShownChanged(bool shown);
123
124 /** Increases the size of the current set view mode. */
125 void zoomIn();
126
127 /** Decreases the size of the current set view mode. */
128 void zoomOut();
129
130 /** Resets the size of the current set view mode to default. */
131 void zoomReset();
132
133 /** Switches between a separate sorting and a mixed sorting of files and folders. */
134 void toggleSortFoldersFirst();
135
136 /**
137 * Updates the state of the 'Sort Ascending/Descending' action.
138 */
139 void slotSortOrderChanged(Qt::SortOrder order);
140
141 /**
142 * Updates the state of the 'Sort Folders First' action.
143 */
144 void slotSortFoldersFirstChanged(bool foldersFirst);
145
146 /**
147 * Switches between showing hidden files last or not.
148 */
149 void toggleSortHiddenLast();
150
151 /**
152 * Updates the state of the 'Sort Hidden Last' action.
153 */
154 void slotSortHiddenLastChanged(bool hiddenLast);
155
156 /**
157 * Updates the state of the 'Sort by' actions.
158 */
159 void slotSortRoleChanged(const QByteArray &role);
160
161 /**
162 * Updates the state of the 'Zoom In' and 'Zoom Out' actions.
163 */
164 void slotZoomLevelChanged(int current, int previous);
165
166 /**
167 * Switches on or off the displaying of additional information
168 * as specified by \a action.
169 */
170 void toggleVisibleRole(QAction *action);
171
172 /**
173 * Changes the sorting of the current view.
174 */
175 void slotSortTriggered(QAction *);
176
177 /**
178 * Updates the state of the 'Additional Information' actions.
179 */
180 void slotVisibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous);
181
182 /**
183 * Switches between sorting by groups or not.
184 */
185 void toggleGroupedSorting(bool);
186
187 /**
188 * Updates the state of the 'Categorized sorting' menu action.
189 */
190 void slotGroupedSortingChanged(bool sortCategorized);
191
192 /**
193 * Switches between showing and hiding of hidden marked files
194 */
195 void toggleShowHiddenFiles(bool);
196
197 /**
198 * Updates the state of the 'Show hidden files' menu action.
199 */
200 void slotHiddenFilesShownChanged(bool shown);
201
202 /**
203 * Updates the state of the 'Create Folder...' action.
204 */
205 void slotWriteStateChanged(bool isFolderWritable);
206
207 /**
208 * Opens the view properties dialog, which allows to modify the properties
209 * of the currently active view.
210 */
211 void slotAdjustViewProperties();
212
213 /**
214 * Begins a duplicate operation on the selected files
215 */
216 void slotDuplicate();
217
218 /**
219 * Connected to the "properties" action.
220 * Opens the properties dialog for the selected items of the
221 * active view. The properties dialog shows information
222 * like name, size and permissions.
223 */
224 void slotProperties();
225
226 /**
227 * Copies the path of the first selected KFileItem into Clipboard.
228 */
229 void slotCopyPath();
230
231 /**
232 * Changes the name of the menu that contains basic actions like "Copy", "Rename", ...
233 * The name is changed to something like "Actions for 3 Selected Items" to be extra
234 * explicit of how these basic actions are used.
235 */
236 void slotSelectionChanged(const KFileItemList &selection);
237
238 private:
239 /**
240 * Create all the actions.
241 * This is called only once (by the constructor)
242 */
243 void createActions(SelectionMode::ActionTextHelper *actionTextHelper);
244
245 /**
246 * Creates an action-group out of all roles from KFileItemModel.
247 * Dependent on the group-prefix either a radiobutton-group is
248 * created for sorting (prefix is "sort_by_") or a checkbox-group
249 * is created for additional information (prefix is "show_").
250 * The changes of actions are reported to slotSortTriggered() or
251 * toggleAdditionalInfo().
252 */
253 QActionGroup *createFileItemRolesActionGroup(const QString &groupPrefix);
254
255 /**
256 * Returns the "switch to icons mode" action.
257 * Helper method for createActions();
258 */
259 KToggleAction *iconsModeAction();
260
261 /**
262 * Returns the "switch to compact mode" action.
263 * Helper method for createActions();
264 */
265 KToggleAction *compactModeAction();
266
267 /**
268 * Returns the "switch to details mode" action.
269 * Helper method for createActions();
270 */
271 KToggleAction *detailsModeAction();
272
273 KActionCollection *m_actionCollection;
274 DolphinView *m_currentView;
275
276 QHash<QByteArray, KToggleAction *> m_sortByActions;
277 QHash<QByteArray, KToggleAction *> m_visibleRoles;
278 };
279
280 #endif /* DOLPHINVIEWACTIONHANDLER_H */