2 * SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
3 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #include "dolphinviewactionhandler.h"
10 #include "dolphindebug.h"
11 #include "kitemviews/kfileitemmodel.h"
12 #include "settings/viewpropertiesdialog.h"
13 #include "views/zoomlevelinfo.h"
14 #include "kconfig_version.h"
17 #include <Baloo/IndexerConfig>
19 #include <KActionCollection>
20 #include <KActionMenu>
21 #include <KLocalizedString>
22 #include <KNewFileMenu>
23 #include <KPropertiesDialog>
24 #include <KProtocolManager>
28 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
30 m_actionCollection(collection
),
31 m_currentView(nullptr),
35 Q_ASSERT(m_actionCollection
);
39 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
44 disconnect(m_currentView
, nullptr, this, nullptr);
49 connect(view
, &DolphinView::modeChanged
,
50 this, &DolphinViewActionHandler::updateViewActions
);
51 connect(view
, &DolphinView::previewsShownChanged
,
52 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
53 connect(view
, &DolphinView::sortOrderChanged
,
54 this, &DolphinViewActionHandler::slotSortOrderChanged
);
55 connect(view
, &DolphinView::sortFoldersFirstChanged
,
56 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
57 connect(view
, &DolphinView::visibleRolesChanged
,
58 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
59 connect(view
, &DolphinView::groupedSortingChanged
,
60 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
61 connect(view
, &DolphinView::hiddenFilesShownChanged
,
62 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
63 connect(view
, &DolphinView::sortRoleChanged
,
64 this, &DolphinViewActionHandler::slotSortRoleChanged
);
65 connect(view
, &DolphinView::zoomLevelChanged
,
66 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
67 connect(view
, &DolphinView::writeStateChanged
,
68 this, &DolphinViewActionHandler::slotWriteStateChanged
);
71 DolphinView
* DolphinViewActionHandler::currentView()
76 void DolphinViewActionHandler::createActions()
78 // This action doesn't appear in the GUI, it's for the shortcut only.
79 // KNewFileMenu takes care of the GUI stuff.
80 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
81 newDirAction
->setText(i18nc("@action", "Create Folder..."));
82 #if KCONFIG_VERSION >= QT_VERSION_CHECK(5, 74, 0)
83 m_actionCollection
->setDefaultShortcuts(newDirAction
, KStandardShortcut::createFolder());
85 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
87 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
88 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
89 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
93 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
94 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
95 "items in your current selection.<nl/>Renaming multiple items "
96 "at once amounts to their new names differing only in a number."));
98 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
99 auto trashShortcuts
= trashAction
->shortcuts();
100 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
101 trashShortcuts
.append(QKeySequence::Delete
);
102 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
104 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
105 "items in your current selection to the <filename>Trash"
106 "</filename>.<nl/>The trash is a temporary storage where "
107 "items can be deleted from if disk space is needed."));
109 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
110 auto deleteShortcuts
= deleteAction
->shortcuts();
111 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
112 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
113 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
115 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
116 "the items in your current selection completely. They can "
117 "not be recovered by normal means."));
119 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
120 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
121 // can be used for deleting the file (#76016). It needs to be a separate action
122 // so that the Edit menu isn't affected.
123 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
124 // The descriptive text is just for the shortcuts editor.
125 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
126 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
127 deleteWithTrashShortcut
->setEnabled(false);
128 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
130 QAction
* duplicateAction
= m_actionCollection
->addAction(QStringLiteral("duplicate"));
131 duplicateAction
->setText(i18nc("@action:inmenu File", "Duplicate Here"));
132 duplicateAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
133 m_actionCollection
->setDefaultShortcut(duplicateAction
, Qt::CTRL
| Qt::Key_D
);
134 duplicateAction
->setEnabled(false);
135 connect(duplicateAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDuplicate
);
137 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
138 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
139 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
140 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
141 "This shows a complete list of properties of the currently "
142 "selected items in a new window.<nl/>If nothing is selected the "
143 "window will be about the currently viewed folder instead.<nl/>"
144 "You can configure advanced options there like managing "
145 "read- and write-permissions."));
146 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
147 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
148 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
150 QAction
*copyPathAction
= m_actionCollection
->addAction( QStringLiteral("copy_location") );
151 copyPathAction
->setText(i18nc("@action:incontextmenu", "Copy Location"));
152 copyPathAction
->setWhatsThis(i18nc("@info:whatsthis copy_location",
153 "This will copy the path of the first selected item into the clipboard."
156 copyPathAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
157 m_actionCollection
->setDefaultShortcuts(copyPathAction
, {Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_C
});
158 connect(copyPathAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotCopyPath
);
162 KToggleAction
* iconsAction
= iconsModeAction();
163 KToggleAction
* compactAction
= compactModeAction();
164 KToggleAction
* detailsAction
= detailsModeAction();
166 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
167 "<para>This switches to a view mode that focuses on the folder "
168 "and file icons. This mode makes it easy to distinguish folders "
169 "from files and to detect items with distinctive <emphasis>"
170 "file types</emphasis>.</para><para> This mode is handy to "
171 "browse through pictures when the <interface>Preview"
172 "</interface> option is enabled.</para>"));
173 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
174 "<para>This switches to a compact view mode that lists the folders "
175 "and files in columns with the names beside the icons.</para><para>"
176 "This helps to keep the overview in folders with many items.</para>"));
177 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
178 "<para>This switches to a list view mode that focuses on folder "
179 "and file details.</para><para>Click on a detail in the column "
180 "header to sort the items by it. Click again to sort the other "
181 "way around. To select which details should be displayed click "
182 "the header with the right mouse button.</para><para>You can "
183 "view the contents of a folder without leaving the current "
184 "location by clicking to the left of it. This way you can view "
185 "the contents of multiple folders in the same list.</para>"));
187 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
188 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
189 viewModeActions
->addAction(iconsAction
);
190 viewModeActions
->addAction(compactAction
);
191 viewModeActions
->addAction(detailsAction
);
192 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
193 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
195 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
196 &DolphinViewActionHandler::zoomIn
,
198 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
200 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
201 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
202 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
203 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
204 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
205 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
+ Qt::Key_0
});
206 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
208 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
209 &DolphinViewActionHandler::zoomOut
,
211 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
213 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
214 showPreview
->setText(i18nc("@action:intoolbar", "Show Previews"));
215 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
216 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
217 "enabled, the icons are based on the actual file or folder "
218 "contents.<nl/>For example the icons of images become scaled "
219 "down versions of the images."));
220 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
221 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
223 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
224 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
225 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
228 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
230 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
231 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
232 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
233 sortByActionMenu
->setDelayed(false);
235 const auto sortByActionGroupActions
= sortByActionGroup
->actions();
236 for (QAction
* action
: sortByActionGroupActions
) {
237 sortByActionMenu
->addAction(action
);
240 sortByActionMenu
->addSeparator();
242 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
243 group
->setExclusive(true);
245 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
246 ascendingAction
->setActionGroup(group
);
247 connect(ascendingAction
, &QAction::triggered
, this, [this] {
248 m_currentView
->setSortOrder(Qt::AscendingOrder
);
251 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
252 descendingAction
->setActionGroup(group
);
253 connect(descendingAction
, &QAction::triggered
, this, [this] {
254 m_currentView
->setSortOrder(Qt::DescendingOrder
);
257 sortByActionMenu
->addAction(ascendingAction
);
258 sortByActionMenu
->addAction(descendingAction
);
259 sortByActionMenu
->addSeparator();
260 sortByActionMenu
->addAction(sortFoldersFirst
);
262 // View -> Additional Information
263 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
265 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
266 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
267 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
268 visibleRolesMenu
->setDelayed(false);
270 const auto visibleRolesGroupActions
= visibleRolesGroup
->actions();
271 for (QAction
* action
: visibleRolesGroupActions
) {
272 visibleRolesMenu
->addAction(action
);
275 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
276 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
277 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
278 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
279 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
281 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
282 showHiddenFiles
->setIcon(QIcon::fromTheme(QStringLiteral("view-visible")));
283 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
284 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
285 "this is enabled <emphasis>hidden</emphasis> files and folders "
286 "are visible. They will be displayed semi-transparent.</para>"
287 "<para>Hidden items only differ from other ones in that their "
288 "name starts with a \".\". In general there is no need for "
289 "users to access them which is why they are hidden.</para>"));
290 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, KStandardShortcut::showHideHiddenFiles());
291 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
293 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
294 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
295 adjustViewProps
->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
296 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
297 "in which all folder view properties can be adjusted."));
298 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
301 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
303 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
304 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
306 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
307 rolesActionGroup
->setExclusive(isSortGroup
);
309 connect(rolesActionGroup
, &QActionGroup::triggered
,
310 this, &DolphinViewActionHandler::slotSortTriggered
);
312 connect(rolesActionGroup
, &QActionGroup::triggered
,
313 this, &DolphinViewActionHandler::toggleVisibleRole
);
317 KActionMenu
* groupMenu
= nullptr;
318 QActionGroup
* groupMenuGroup
= nullptr;
320 bool indexingEnabled
= false;
322 Baloo::IndexerConfig config
;
323 indexingEnabled
= config
.fileIndexingEnabled();
326 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
327 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
328 if (!isSortGroup
&& info
.role
== "text") {
329 // It should not be possible to hide the "text" role
333 KToggleAction
* action
= nullptr;
334 const QString name
= groupPrefix
+ info
.role
;
335 if (info
.group
.isEmpty()) {
336 action
= m_actionCollection
->add
<KToggleAction
>(name
);
337 action
->setActionGroup(rolesActionGroup
);
339 if (!groupMenu
|| info
.group
!= groupName
) {
340 groupName
= info
.group
;
341 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
342 groupMenu
->setText(groupName
);
343 groupMenu
->setActionGroup(rolesActionGroup
);
345 groupMenuGroup
= new QActionGroup(groupMenu
);
346 groupMenuGroup
->setExclusive(isSortGroup
);
348 connect(groupMenuGroup
, &QActionGroup::triggered
,
349 this, &DolphinViewActionHandler::slotSortTriggered
);
351 connect(groupMenuGroup
, &QActionGroup::triggered
,
352 this, &DolphinViewActionHandler::toggleVisibleRole
);
356 action
= new KToggleAction(groupMenu
);
357 action
->setActionGroup(groupMenuGroup
);
358 groupMenu
->addAction(action
);
360 action
->setText(info
.translation
);
361 action
->setData(info
.role
);
363 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
364 (info
.requiresBaloo
) ||
365 (info
.requiresIndexer
&& indexingEnabled
);
366 action
->setEnabled(enable
);
369 m_sortByActions
.insert(info
.role
, action
);
371 m_visibleRoles
.insert(info
.role
, action
);
375 return rolesActionGroup
;
378 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
380 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
381 m_currentView
->setMode(mode
);
383 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
384 viewModeMenu
->setIcon(action
->icon());
387 void DolphinViewActionHandler::slotRename()
389 Q_EMIT
actionBeingHandled();
390 m_currentView
->renameSelectedItems();
393 void DolphinViewActionHandler::slotTrashActivated()
395 Q_EMIT
actionBeingHandled();
396 m_currentView
->trashSelectedItems();
399 void DolphinViewActionHandler::slotDeleteItems()
401 Q_EMIT
actionBeingHandled();
402 m_currentView
->deleteSelectedItems();
405 void DolphinViewActionHandler::togglePreview(bool show
)
407 Q_EMIT
actionBeingHandled();
408 m_currentView
->setPreviewsShown(show
);
411 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
414 // It is not enough to update the 'Show Preview' action, also
415 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
419 QString
DolphinViewActionHandler::currentViewModeActionName() const
421 switch (m_currentView
->mode()) {
422 case DolphinView::IconsView
:
423 return QStringLiteral("icons");
424 case DolphinView::DetailsView
:
425 return QStringLiteral("details");
426 case DolphinView::CompactView
:
427 return QStringLiteral("compact");
432 return QString(); // can't happen
435 KActionCollection
* DolphinViewActionHandler::actionCollection()
437 return m_actionCollection
;
440 void DolphinViewActionHandler::updateViewActions()
442 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
443 if (viewModeAction
) {
444 viewModeAction
->setChecked(true);
446 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
447 viewModeMenu
->setIcon(viewModeAction
->icon());
450 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
451 showPreviewAction
->setChecked(m_currentView
->previewsShown());
453 slotSortOrderChanged(m_currentView
->sortOrder());
454 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
455 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
456 slotGroupedSortingChanged(m_currentView
->groupedSorting());
457 slotSortRoleChanged(m_currentView
->sortRole());
458 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
460 // Updates the "show_hidden_files" action state and icon
461 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
464 void DolphinViewActionHandler::zoomIn()
466 const int level
= m_currentView
->zoomLevel();
467 m_currentView
->setZoomLevel(level
+ 1);
471 void DolphinViewActionHandler::zoomOut()
473 const int level
= m_currentView
->zoomLevel();
474 m_currentView
->setZoomLevel(level
- 1);
478 void DolphinViewActionHandler::zoomReset()
480 m_currentView
->resetZoomLevel();
484 void DolphinViewActionHandler::toggleSortFoldersFirst()
486 const bool sortFirst
= m_currentView
->sortFoldersFirst();
487 m_currentView
->setSortFoldersFirst(!sortFirst
);
490 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
492 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
493 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
494 const bool sortDescending
= (order
== Qt::DescendingOrder
);
495 descending
->setChecked(sortDescending
);
496 ascending
->setChecked(!sortDescending
);
499 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
501 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
504 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
506 Q_EMIT
actionBeingHandled();
508 const QByteArray toggledRole
= action
->data().toByteArray();
510 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
512 const bool show
= action
->isChecked();
514 const int index
= roles
.indexOf(toggledRole
);
515 const bool containsInfo
= (index
>= 0);
516 if (show
&& !containsInfo
) {
517 roles
.append(toggledRole
);
518 m_currentView
->setVisibleRoles(roles
);
519 } else if (!show
&& containsInfo
) {
520 roles
.removeAt(index
);
521 m_currentView
->setVisibleRoles(roles
);
522 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
526 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
527 const QList
<QByteArray
>& previous
)
531 const auto checkedRoles
= QSet
<QByteArray
>(current
.constBegin(), current
.constEnd());
532 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
533 while (it
.hasNext()) {
535 const QByteArray
& role
= it
.key();
536 KToggleAction
* action
= it
.value();
537 action
->setChecked(checkedRoles
.contains(role
));
541 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
543 m_currentView
->setGroupedSorting(grouped
);
546 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
548 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
549 showInGroupsAction
->setChecked(groupedSorting
);
552 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
554 Q_EMIT
actionBeingHandled();
555 m_currentView
->setHiddenFilesShown(show
);
558 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
560 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
561 showHiddenFilesAction
->setChecked(shown
);
564 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
566 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
567 KProtocolManager::supportsMakeDir(currentView()->url()));
570 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
572 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
573 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
574 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
575 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
576 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
577 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
581 KToggleAction
* DolphinViewActionHandler::compactModeAction()
583 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
584 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
585 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
586 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
587 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
588 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
592 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
594 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
595 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
596 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
597 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
598 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
599 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
603 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
605 KToggleAction
* action
= m_sortByActions
.value(role
);
607 action
->setChecked(true);
609 if (!action
->icon().isNull()) {
610 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
611 sortByMenu
->setIcon(action
->icon());
615 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
616 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
618 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
619 descending
->setText(i18nc("Sort descending", "Z-A"));
620 ascending
->setText(i18nc("Sort ascending", "A-Z"));
621 } else if (role
== "size") {
622 descending
->setText(i18nc("Sort descending", "Largest First"));
623 ascending
->setText(i18nc("Sort ascending", "Smallest First"));
624 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
625 descending
->setText(i18nc("Sort descending", "Newest First"));
626 ascending
->setText(i18nc("Sort ascending", "Oldest First"));
627 } else if (role
== "rating") {
628 descending
->setText(i18nc("Sort descending", "Highest First"));
629 ascending
->setText(i18nc("Sort ascending", "Lowest First"));
631 descending
->setText(i18nc("Sort descending", "Descending"));
632 ascending
->setText(i18nc("Sort ascending", "Ascending"));
635 slotSortOrderChanged(m_currentView
->sortOrder());
638 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
642 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
644 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
647 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
649 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
653 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
655 // The radiobuttons of the "Sort By"-menu are split between the main-menu
656 // and several sub-menus. Because of this they don't have a common
657 // action-group that assures an exclusive toggle-state between the main-menu
658 // actions and the sub-menu-actions. If an action gets checked, it must
659 // be assured that all other actions get unchecked, except the ascending/
660 // descending actions
661 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
662 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
664 const auto actions
= actionMenu
->menu()->actions();
665 for (QAction
* subAction
: actions
) {
666 subAction
->setChecked(false);
668 } else if (groupAction
->actionGroup()) {
669 groupAction
->setChecked(false);
672 action
->setChecked(true);
674 // Apply the activated sort-role to the view
675 const QByteArray role
= action
->data().toByteArray();
676 m_currentView
->setSortRole(role
);
679 void DolphinViewActionHandler::slotAdjustViewProperties()
681 Q_EMIT
actionBeingHandled();
682 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
687 void DolphinViewActionHandler::slotDuplicate()
689 Q_EMIT
actionBeingHandled();
690 m_currentView
->duplicateSelectedItems();
693 void DolphinViewActionHandler::slotProperties()
695 KPropertiesDialog
* dialog
= nullptr;
696 const KFileItemList list
= m_currentView
->selectedItems();
697 if (list
.isEmpty()) {
698 const QUrl url
= m_currentView
->url();
699 dialog
= new KPropertiesDialog(url
, m_currentView
);
701 dialog
= new KPropertiesDialog(list
, m_currentView
);
704 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
707 dialog
->activateWindow();
710 void DolphinViewActionHandler::slotCopyPath()
712 m_currentView
->copyPathToClipboard();