1 /***************************************************************************
2 * Copyright (C) 2008 by David Faure <faure@kde.org> *
3 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
22 #ifndef DOLPHINVIEWACTIONHANDLER_H
23 #define DOLPHINVIEWACTIONHANDLER_H
25 #include "libdolphin_export.h"
26 #include <KActionMenu>
27 #include <KSelectAction>
28 #include "views/dolphinview.h"
35 class KActionCollection
;
38 * @short Handles all actions for DolphinView
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).
44 * The purpose of this class is also to share this code between DolphinMainWindow
48 * @see DolphinMainWindow
51 class LIBDOLPHINPRIVATE_EXPORT DolphinViewActionHandler
: public QObject
56 explicit DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
);
59 * Sets the view that this action handler should work on.
61 void setCurrentView(DolphinView
* view
);
64 * Returns the view that this action handler should work on.
66 DolphinView
* currentView();
69 * Returns the name of the action for the current viewmode
71 QString
currentViewModeActionName() const;
74 * Returns m_actionCollection
76 KActionCollection
* actionCollection();
80 * Update all actions in the 'View' menu, i.e. those that depend on the
81 * settings in the current view.
83 void updateViewActions();
87 * Emitted by DolphinViewActionHandler when the user triggered an action.
88 * This is only used for clearining the statusbar in DolphinMainWindow.
90 void actionBeingHandled();
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.
97 void createDirectory();
101 * Emitted when the user requested a change of view mode
103 void slotViewModeActionTriggered(QAction
*);
106 * Let the user input a name for the selected item(s) and trigger
107 * a renaming afterwards.
112 * Moves the selected items of the active view to the trash.
113 * This methods adds "shift means del" handling.
115 void slotTrashActivated(Qt::MouseButtons
, Qt::KeyboardModifiers
);
118 * Deletes the selected items of the active view.
120 void slotDeleteItems();
123 * Switches between showing a preview of the file content and showing the icon.
125 void togglePreview(bool);
127 /** Updates the state of the 'Show preview' menu action. */
128 void slotPreviewsShownChanged(bool shown
);
130 /** Increases the size of the current set view mode. */
133 /** Decreases the size of the current set view mode. */
136 /** Switches between an ascending and descending sorting order. */
137 void toggleSortOrder();
139 /** Switches between a separate sorting and a mixed sorting of files and folders. */
140 void toggleSortFoldersFirst();
143 * Updates the state of the 'Sort Ascending/Descending' action.
145 void slotSortOrderChanged(Qt::SortOrder order
);
148 * Updates the state of the 'Sort Folders First' action.
150 void slotSortFoldersFirstChanged(bool foldersFirst
);
153 * Updates the state of the 'Sort by' actions.
155 void slotSortRoleChanged(const QByteArray
& role
);
158 * Updates the state of the 'Zoom In' and 'Zoom Out' actions.
160 void slotZoomLevelChanged(int current
, int previous
);
163 * Switches on or off the displaying of additional information
164 * as specified by \a action.
166 void toggleVisibleRole(QAction
* action
);
169 * Changes the sorting of the current view.
171 void slotSortTriggered(QAction
*);
174 * Updates the state of the 'Additional Information' actions.
176 void slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
177 const QList
<QByteArray
>& previous
);
180 * Switches between sorting by groups or not.
182 void toggleGroupedSorting(bool);
185 * Updates the state of the 'Categorized sorting' menu action.
187 void slotGroupedSortingChanged(bool sortCategorized
);
190 * Switches between showing and hiding of hidden marked files
192 void toggleShowHiddenFiles(bool);
195 * Updates the state of the 'Show hidden files' menu action.
197 void slotHiddenFilesShownChanged(bool shown
);
200 * Updates the state of the 'Create Folder...' action.
202 void slotWriteStateChanged(bool isFolderWritable
);
205 * Opens the view properties dialog, which allows to modify the properties
206 * of the currently active view.
208 void slotAdjustViewProperties();
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.
216 void slotProperties();
220 * Create all the actions.
221 * This is called only once (by the constructor)
223 void createActions();
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().
233 QActionGroup
* createFileItemRolesActionGroup(const QString
& groupPrefix
);
236 * Returns the "switch to icons mode" action.
237 * Helper method for createActions();
239 KToggleAction
* iconsModeAction();
242 * Returns the "switch to compact mode" action.
243 * Helper method for createActions();
245 KToggleAction
* compactModeAction();
248 * Returns the "switch to details mode" action.
249 * Helper method for createActions();
251 KToggleAction
* detailsModeAction();
253 KActionCollection
* m_actionCollection
;
254 DolphinView
* m_currentView
;
256 QHash
<QByteArray
, KToggleAction
*> m_sortByActions
;
257 QHash
<QByteArray
, KToggleAction
*> m_visibleRoles
;
260 #endif /* DOLPHINVIEWACTIONHANDLER_H */