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