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