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