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 ***************************************************************************/
21 #include "dolphinviewactionhandler.h"
23 #include "dolphindebug.h"
24 #include "kitemviews/kfileitemmodel.h"
25 #include "settings/viewpropertiesdialog.h"
26 #include "views/zoomlevelinfo.h"
29 #include <Baloo/IndexerConfig>
31 #include <KActionCollection>
32 #include <KActionMenu>
33 #include <KLocalizedString>
34 #include <KNewFileMenu>
35 #include <KPropertiesDialog>
36 #include <KProtocolManager>
41 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
43 m_actionCollection(collection
),
44 m_currentView(nullptr),
48 Q_ASSERT(m_actionCollection
);
52 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
57 disconnect(m_currentView
, nullptr, this, nullptr);
62 connect(view
, &DolphinView::modeChanged
,
63 this, &DolphinViewActionHandler::updateViewActions
);
64 connect(view
, &DolphinView::previewsShownChanged
,
65 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
66 connect(view
, &DolphinView::sortOrderChanged
,
67 this, &DolphinViewActionHandler::slotSortOrderChanged
);
68 connect(view
, &DolphinView::sortFoldersFirstChanged
,
69 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
70 connect(view
, &DolphinView::visibleRolesChanged
,
71 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
72 connect(view
, &DolphinView::groupedSortingChanged
,
73 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
74 connect(view
, &DolphinView::hiddenFilesShownChanged
,
75 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
76 connect(view
, &DolphinView::sortRoleChanged
,
77 this, &DolphinViewActionHandler::slotSortRoleChanged
);
78 connect(view
, &DolphinView::zoomLevelChanged
,
79 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
80 connect(view
, &DolphinView::writeStateChanged
,
81 this, &DolphinViewActionHandler::slotWriteStateChanged
);
84 DolphinView
* DolphinViewActionHandler::currentView()
89 void DolphinViewActionHandler::createActions()
91 // This action doesn't appear in the GUI, it's for the shortcut only.
92 // KNewFileMenu takes care of the GUI stuff.
93 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
94 newDirAction
->setText(i18nc("@action", "Create Folder..."));
95 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
96 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
97 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
98 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
102 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
103 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
104 "items in your current selection.<nl/>Renaming multiple items "
105 "at once amounts to their new names differing only in a number."));
107 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
108 auto trashShortcuts
= trashAction
->shortcuts();
109 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
110 trashShortcuts
.append(QKeySequence::Delete
);
111 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
113 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
114 "items in your current selection to the <filename>Trash"
115 "</filename>.<nl/>The trash is a temporary storage where "
116 "items can be deleted from if disk space is needed."));
118 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
119 auto deleteShortcuts
= deleteAction
->shortcuts();
120 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
121 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
122 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
124 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
125 "the items in your current selection completely. They can "
126 "not be recovered by normal means."));
128 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
129 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
130 // can be used for deleting the file (#76016). It needs to be a separate action
131 // so that the Edit menu isn't affected.
132 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
133 // The descriptive text is just for the shortcuts editor.
134 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
135 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
136 deleteWithTrashShortcut
->setEnabled(false);
137 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
139 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
140 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
141 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
142 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
143 "This shows a complete list of properties of the currently "
144 "selected items in a new window.<nl/>If nothing is selected the "
145 "window will be about the currently viewed folder instead.<nl/>"
146 "You can configure advanced options there like managing "
147 "read- and write-permissions."));
148 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
149 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
150 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
153 KToggleAction
* iconsAction
= iconsModeAction();
154 KToggleAction
* compactAction
= compactModeAction();
155 KToggleAction
* detailsAction
= detailsModeAction();
157 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
158 "<para>This switches to a view mode that focuses on the folder "
159 "and file icons. This mode makes it easy to distinguish folders "
160 "from files and to detect items with distinctive <emphasis>"
161 "file types</emphasis>.</para><para> This mode is handy to "
162 "browse through pictures when the <interface>Preview"
163 "</interface> option is enabled.</para>"));
164 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
165 "<para>This switches to a compact view mode that lists the folders "
166 "and files in columns with the names beside the icons.</para><para>"
167 "This helps to keep the overview in folders with many items.</para>"));
168 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
169 "<para>This switches to a list view mode that focuses on folder "
170 "and file details.</para><para>Click on a detail in the column "
171 "header to sort the items by it. Click again to sort the other "
172 "way around. To select which details should be displayed click "
173 "the header with the right mouse button.</para><para>You can "
174 "view the contents of a folder without leaving the current "
175 "location by clicking to the left of it. This way you can view "
176 "the contents of multiple folders in the same list.</para>"));
178 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
179 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
180 viewModeActions
->addAction(iconsAction
);
181 viewModeActions
->addAction(compactAction
);
182 viewModeActions
->addAction(detailsAction
);
183 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
184 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
186 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
187 &DolphinViewActionHandler::zoomIn
,
189 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
191 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
192 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
193 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
194 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
195 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
196 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
+ Qt::Key_0
});
197 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
199 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
200 &DolphinViewActionHandler::zoomOut
,
202 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
204 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
205 showPreview
->setText(i18nc("@action:intoolbar", "Preview"));
206 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
207 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
208 "enabled, the icons are based on the actual file or folder "
209 "contents.<nl/>For example the icons of images become scaled "
210 "down versions of the images."));
211 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
212 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
214 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
215 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
216 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
219 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
221 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
222 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
223 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
224 sortByActionMenu
->setDelayed(false);
226 foreach (QAction
* action
, sortByActionGroup
->actions()) {
227 sortByActionMenu
->addAction(action
);
230 sortByActionMenu
->addSeparator();
232 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
233 group
->setExclusive(true);
235 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
236 ascendingAction
->setActionGroup(group
);
237 connect(ascendingAction
, &QAction::triggered
, this, [this] {
238 m_currentView
->setSortOrder(Qt::AscendingOrder
);
241 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
242 descendingAction
->setActionGroup(group
);
243 connect(descendingAction
, &QAction::triggered
, this, [this] {
244 m_currentView
->setSortOrder(Qt::DescendingOrder
);
247 sortByActionMenu
->addAction(ascendingAction
);
248 sortByActionMenu
->addAction(descendingAction
);
249 sortByActionMenu
->addSeparator();
250 sortByActionMenu
->addAction(sortFoldersFirst
);
252 // View -> Additional Information
253 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
255 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
256 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Additional Information"));
257 visibleRolesMenu
->setDelayed(false);
259 foreach (QAction
* action
, visibleRolesGroup
->actions()) {
260 visibleRolesMenu
->addAction(action
);
263 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
264 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
265 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
266 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
267 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
269 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
270 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Hidden Files"));
271 showHiddenFiles
->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
272 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
273 "this is enabled <emphasis>hidden</emphasis> files and folders "
274 "are visible. They will be displayed semi-transparent.</para>"
275 "<para>Hidden items only differ from other ones in that their "
276 "name starts with a \".\". In general there is no need for "
277 "users to access them which is why they are hidden.</para>"));
278 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, {Qt::ALT
+ Qt::Key_Period
, Qt::CTRL
+ Qt::Key_H
, Qt::Key_F8
});
279 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
281 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
282 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
283 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
284 "in which all folder view properties can be adjusted."));
285 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
288 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
290 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
291 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
293 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
294 rolesActionGroup
->setExclusive(isSortGroup
);
296 connect(rolesActionGroup
, &QActionGroup::triggered
,
297 this, &DolphinViewActionHandler::slotSortTriggered
);
299 connect(rolesActionGroup
, &QActionGroup::triggered
,
300 this, &DolphinViewActionHandler::toggleVisibleRole
);
304 KActionMenu
* groupMenu
= nullptr;
305 QActionGroup
* groupMenuGroup
= nullptr;
307 bool indexingEnabled
= false;
309 Baloo::IndexerConfig config
;
310 indexingEnabled
= config
.fileIndexingEnabled();
313 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
314 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
315 if (!isSortGroup
&& info
.role
== "text") {
316 // It should not be possible to hide the "text" role
320 KToggleAction
* action
= nullptr;
321 const QString name
= groupPrefix
+ info
.role
;
322 if (info
.group
.isEmpty()) {
323 action
= m_actionCollection
->add
<KToggleAction
>(name
);
324 action
->setActionGroup(rolesActionGroup
);
326 if (!groupMenu
|| info
.group
!= groupName
) {
327 groupName
= info
.group
;
328 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
329 groupMenu
->setText(groupName
);
330 groupMenu
->setActionGroup(rolesActionGroup
);
332 groupMenuGroup
= new QActionGroup(groupMenu
);
333 groupMenuGroup
->setExclusive(isSortGroup
);
335 connect(groupMenuGroup
, &QActionGroup::triggered
,
336 this, &DolphinViewActionHandler::slotSortTriggered
);
338 connect(groupMenuGroup
, &QActionGroup::triggered
,
339 this, &DolphinViewActionHandler::toggleVisibleRole
);
343 action
= new KToggleAction(groupMenu
);
344 action
->setActionGroup(groupMenuGroup
);
345 groupMenu
->addAction(action
);
347 action
->setText(info
.translation
);
348 action
->setData(info
.role
);
350 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
351 (info
.requiresBaloo
) ||
352 (info
.requiresIndexer
&& indexingEnabled
);
353 action
->setEnabled(enable
);
356 m_sortByActions
.insert(info
.role
, action
);
358 m_visibleRoles
.insert(info
.role
, action
);
362 return rolesActionGroup
;
365 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
367 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
368 m_currentView
->setMode(mode
);
370 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
371 viewModeMenu
->setIcon(action
->icon());
374 void DolphinViewActionHandler::slotRename()
376 emit
actionBeingHandled();
377 m_currentView
->renameSelectedItems();
380 void DolphinViewActionHandler::slotTrashActivated()
382 emit
actionBeingHandled();
383 m_currentView
->trashSelectedItems();
386 void DolphinViewActionHandler::slotDeleteItems()
388 emit
actionBeingHandled();
389 m_currentView
->deleteSelectedItems();
392 void DolphinViewActionHandler::togglePreview(bool show
)
394 emit
actionBeingHandled();
395 m_currentView
->setPreviewsShown(show
);
398 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
401 // It is not enough to update the 'Show Preview' action, also
402 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
406 QString
DolphinViewActionHandler::currentViewModeActionName() const
408 switch (m_currentView
->mode()) {
409 case DolphinView::IconsView
:
410 return QStringLiteral("icons");
411 case DolphinView::DetailsView
:
412 return QStringLiteral("details");
413 case DolphinView::CompactView
:
414 return QStringLiteral("compact");
419 return QString(); // can't happen
422 KActionCollection
* DolphinViewActionHandler::actionCollection()
424 return m_actionCollection
;
427 void DolphinViewActionHandler::updateViewActions()
429 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
430 if (viewModeAction
) {
431 viewModeAction
->setChecked(true);
433 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
434 viewModeMenu
->setIcon(viewModeAction
->icon());
437 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
438 showPreviewAction
->setChecked(m_currentView
->previewsShown());
440 slotSortOrderChanged(m_currentView
->sortOrder());
441 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
442 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
443 slotGroupedSortingChanged(m_currentView
->groupedSorting());
444 slotSortRoleChanged(m_currentView
->sortRole());
445 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
447 // Updates the "show_hidden_files" action state and icon
448 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
451 void DolphinViewActionHandler::zoomIn()
453 const int level
= m_currentView
->zoomLevel();
454 m_currentView
->setZoomLevel(level
+ 1);
458 void DolphinViewActionHandler::zoomOut()
460 const int level
= m_currentView
->zoomLevel();
461 m_currentView
->setZoomLevel(level
- 1);
465 void DolphinViewActionHandler::zoomReset()
467 m_currentView
->resetZoomLevel();
471 void DolphinViewActionHandler::toggleSortFoldersFirst()
473 const bool sortFirst
= m_currentView
->sortFoldersFirst();
474 m_currentView
->setSortFoldersFirst(!sortFirst
);
477 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
479 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
480 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
481 const bool sortDescending
= (order
== Qt::DescendingOrder
);
482 descending
->setChecked(sortDescending
);
483 ascending
->setChecked(!sortDescending
);
486 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
488 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
491 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
493 emit
actionBeingHandled();
495 const QByteArray toggledRole
= action
->data().toByteArray();
497 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
499 const bool show
= action
->isChecked();
501 const int index
= roles
.indexOf(toggledRole
);
502 const bool containsInfo
= (index
>= 0);
503 if (show
&& !containsInfo
) {
504 roles
.append(toggledRole
);
505 m_currentView
->setVisibleRoles(roles
);
506 } else if (!show
&& containsInfo
) {
507 roles
.removeAt(index
);
508 m_currentView
->setVisibleRoles(roles
);
509 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
513 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
514 const QList
<QByteArray
>& previous
)
518 const QSet
<QByteArray
> checkedRoles
= current
.toSet();
519 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
520 while (it
.hasNext()) {
522 const QByteArray
& role
= it
.key();
523 KToggleAction
* action
= it
.value();
524 action
->setChecked(checkedRoles
.contains(role
));
528 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
530 m_currentView
->setGroupedSorting(grouped
);
533 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
535 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
536 showInGroupsAction
->setChecked(groupedSorting
);
539 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
541 emit
actionBeingHandled();
542 m_currentView
->setHiddenFilesShown(show
);
545 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
547 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
548 showHiddenFilesAction
->setChecked(shown
);
550 // #374508: don't overwrite custom icons.
551 const QString iconName
= showHiddenFilesAction
->icon().name();
552 if (!iconName
.isEmpty() && iconName
!= QLatin1String("view-visible") && iconName
!= QLatin1String("view-hidden")) {
556 showHiddenFilesAction
->setIcon(QIcon::fromTheme(shown
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
559 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
561 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
562 KProtocolManager::supportsMakeDir(currentView()->url()));
565 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
567 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
568 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
569 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
570 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
571 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
572 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
576 KToggleAction
* DolphinViewActionHandler::compactModeAction()
578 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
579 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
580 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
581 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
582 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
583 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
587 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
589 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
590 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
591 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
592 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
593 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
594 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
598 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
600 KToggleAction
* action
= m_sortByActions
.value(role
);
602 action
->setChecked(true);
604 if (!action
->icon().isNull()) {
605 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
606 sortByMenu
->setIcon(action
->icon());
610 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
611 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
613 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
614 descending
->setText(i18nc("Sort descending", "Z-A"));
615 ascending
->setText(i18nc("Sort ascending", "A-Z"));
616 } else if (role
== "size") {
617 descending
->setText(i18nc("Sort descending", "Largest first"));
618 ascending
->setText(i18nc("Sort ascending", "Smallest first"));
619 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
620 descending
->setText(i18nc("Sort descending", "Newest first"));
621 ascending
->setText(i18nc("Sort ascending", "Oldest first"));
622 } else if (role
== "rating") {
623 descending
->setText(i18nc("Sort descending", "Highest first"));
624 ascending
->setText(i18nc("Sort ascending", "Lowest first"));
626 descending
->setText(i18nc("Sort descending", "Descending"));
627 ascending
->setText(i18nc("Sort ascending", "Ascending"));
630 slotSortOrderChanged(m_currentView
->sortOrder());
633 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
637 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
639 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
642 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
644 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
648 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
650 // The radiobuttons of the "Sort By"-menu are split between the main-menu
651 // and several sub-menus. Because of this they don't have a common
652 // action-group that assures an exclusive toggle-state between the main-menu
653 // actions and the sub-menu-actions. If an action gets checked, it must
654 // be assured that all other actions get unchecked, except the ascending/
655 // descending actions
656 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
657 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
658 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
660 foreach (QAction
* subAction
, actionMenu
->menu()->actions()) {
661 subAction
->setChecked(false);
663 } else if (groupAction
->actionGroup()) {
664 groupAction
->setChecked(false);
667 action
->setChecked(true);
669 // Apply the activated sort-role to the view
670 const QByteArray role
= action
->data().toByteArray();
671 m_currentView
->setSortRole(role
);
674 void DolphinViewActionHandler::slotAdjustViewProperties()
676 emit
actionBeingHandled();
677 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
682 void DolphinViewActionHandler::slotProperties()
684 KPropertiesDialog
* dialog
= nullptr;
685 const KFileItemList list
= m_currentView
->selectedItems();
686 if (list
.isEmpty()) {
687 const QUrl url
= m_currentView
->url();
688 dialog
= new KPropertiesDialog(url
, m_currentView
);
690 dialog
= new KPropertiesDialog(list
, m_currentView
);
693 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
696 dialog
->activateWindow();