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