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>
26 #include <QActionGroup>
30 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
32 m_actionCollection(collection
),
33 m_currentView(nullptr),
37 Q_ASSERT(m_actionCollection
);
41 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
46 disconnect(m_currentView
, nullptr, this, nullptr);
51 connect(view
, &DolphinView::modeChanged
,
52 this, &DolphinViewActionHandler::updateViewActions
);
53 connect(view
, &DolphinView::previewsShownChanged
,
54 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
55 connect(view
, &DolphinView::sortOrderChanged
,
56 this, &DolphinViewActionHandler::slotSortOrderChanged
);
57 connect(view
, &DolphinView::sortFoldersFirstChanged
,
58 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
59 connect(view
, &DolphinView::visibleRolesChanged
,
60 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
61 connect(view
, &DolphinView::groupedSortingChanged
,
62 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
63 connect(view
, &DolphinView::hiddenFilesShownChanged
,
64 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
65 connect(view
, &DolphinView::sortRoleChanged
,
66 this, &DolphinViewActionHandler::slotSortRoleChanged
);
67 connect(view
, &DolphinView::zoomLevelChanged
,
68 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
69 connect(view
, &DolphinView::writeStateChanged
,
70 this, &DolphinViewActionHandler::slotWriteStateChanged
);
73 DolphinView
* DolphinViewActionHandler::currentView()
78 void DolphinViewActionHandler::createActions()
80 // This action doesn't appear in the GUI, it's for the shortcut only.
81 // KNewFileMenu takes care of the GUI stuff.
82 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
83 newDirAction
->setText(i18nc("@action", "Create Folder..."));
84 m_actionCollection
->setDefaultShortcuts(newDirAction
, KStandardShortcut::createFolder());
85 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
86 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
87 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
91 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
92 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
93 "items in your current selection.<nl/>Renaming multiple items "
94 "at once amounts to their new names differing only in a number."));
96 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
97 auto trashShortcuts
= trashAction
->shortcuts();
98 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
99 trashShortcuts
.append(QKeySequence::Delete
);
100 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
102 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
103 "items in your current selection to the <filename>Trash"
104 "</filename>.<nl/>The trash is a temporary storage where "
105 "items can be deleted from if disk space is needed."));
107 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
108 auto deleteShortcuts
= deleteAction
->shortcuts();
109 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
110 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
111 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
113 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
114 "the items in your current selection completely. They can "
115 "not be recovered by normal means."));
117 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
118 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
119 // can be used for deleting the file (#76016). It needs to be a separate action
120 // so that the Edit menu isn't affected.
121 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
122 // The descriptive text is just for the shortcuts editor.
123 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
124 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
125 deleteWithTrashShortcut
->setEnabled(false);
126 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
128 QAction
* duplicateAction
= m_actionCollection
->addAction(QStringLiteral("duplicate"));
129 duplicateAction
->setText(i18nc("@action:inmenu File", "Duplicate Here"));
130 duplicateAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
131 m_actionCollection
->setDefaultShortcut(duplicateAction
, Qt::CTRL
| Qt::Key_D
);
132 duplicateAction
->setEnabled(false);
133 connect(duplicateAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDuplicate
);
135 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
136 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
137 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
138 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
139 "This shows a complete list of properties of the currently "
140 "selected items in a new window.<nl/>If nothing is selected the "
141 "window will be about the currently viewed folder instead.<nl/>"
142 "You can configure advanced options there like managing "
143 "read- and write-permissions."));
144 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
145 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
| Qt::Key_Return
, Qt::ALT
| Qt::Key_Enter
});
146 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
148 QAction
*copyPathAction
= m_actionCollection
->addAction( QStringLiteral("copy_location") );
149 copyPathAction
->setText(i18nc("@action:incontextmenu", "Copy Location"));
150 copyPathAction
->setWhatsThis(i18nc("@info:whatsthis copy_location",
151 "This will copy the path of the first selected item into the clipboard."
154 copyPathAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
155 m_actionCollection
->setDefaultShortcuts(copyPathAction
, {Qt::CTRL
| Qt::ALT
| Qt::Key_C
});
156 connect(copyPathAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotCopyPath
);
160 KToggleAction
* iconsAction
= iconsModeAction();
161 KToggleAction
* compactAction
= compactModeAction();
162 KToggleAction
* detailsAction
= detailsModeAction();
164 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
165 "<para>This switches to a view mode that focuses on the folder "
166 "and file icons. This mode makes it easy to distinguish folders "
167 "from files and to detect items with distinctive <emphasis>"
168 "file types</emphasis>.</para><para> This mode is handy to "
169 "browse through pictures when the <interface>Preview"
170 "</interface> option is enabled.</para>"));
171 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
172 "<para>This switches to a compact view mode that lists the folders "
173 "and files in columns with the names beside the icons.</para><para>"
174 "This helps to keep the overview in folders with many items.</para>"));
175 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
176 "<para>This switches to a list view mode that focuses on folder "
177 "and file details.</para><para>Click on a detail in the column "
178 "header to sort the items by it. Click again to sort the other "
179 "way around. To select which details should be displayed click "
180 "the header with the right mouse button.</para><para>You can "
181 "view the contents of a folder without leaving the current "
182 "location by clicking to the left of it. This way you can view "
183 "the contents of multiple folders in the same list.</para>"));
185 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
186 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
187 viewModeActions
->addAction(iconsAction
);
188 viewModeActions
->addAction(compactAction
);
189 viewModeActions
->addAction(detailsAction
);
190 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
191 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
193 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
194 &DolphinViewActionHandler::zoomIn
,
196 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
198 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
199 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
200 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
201 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
202 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
203 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
| Qt::Key_0
});
204 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
206 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
207 &DolphinViewActionHandler::zoomOut
,
209 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
211 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
212 showPreview
->setText(i18nc("@action:intoolbar", "Show Previews"));
213 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
214 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
215 "enabled, the icons are based on the actual file or folder "
216 "contents.<nl/>For example the icons of images become scaled "
217 "down versions of the images."));
218 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
219 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
221 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
222 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
223 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
226 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
228 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
229 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
230 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
231 sortByActionMenu
->setDelayed(false);
233 const auto sortByActionGroupActions
= sortByActionGroup
->actions();
234 for (QAction
* action
: sortByActionGroupActions
) {
235 sortByActionMenu
->addAction(action
);
238 sortByActionMenu
->addSeparator();
240 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
241 group
->setExclusive(true);
243 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
244 ascendingAction
->setActionGroup(group
);
245 connect(ascendingAction
, &QAction::triggered
, this, [this] {
246 m_currentView
->setSortOrder(Qt::AscendingOrder
);
249 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
250 descendingAction
->setActionGroup(group
);
251 connect(descendingAction
, &QAction::triggered
, this, [this] {
252 m_currentView
->setSortOrder(Qt::DescendingOrder
);
255 sortByActionMenu
->addAction(ascendingAction
);
256 sortByActionMenu
->addAction(descendingAction
);
257 sortByActionMenu
->addSeparator();
258 sortByActionMenu
->addAction(sortFoldersFirst
);
260 // View -> Additional Information
261 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
263 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
264 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
265 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
266 visibleRolesMenu
->setDelayed(false);
268 const auto visibleRolesGroupActions
= visibleRolesGroup
->actions();
269 for (QAction
* action
: visibleRolesGroupActions
) {
270 visibleRolesMenu
->addAction(action
);
273 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
274 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
275 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
276 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
277 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
279 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
280 showHiddenFiles
->setIcon(QIcon::fromTheme(QStringLiteral("view-visible")));
281 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
282 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
283 "this is enabled <emphasis>hidden</emphasis> files and folders "
284 "are visible. They will be displayed semi-transparent.</para>"
285 "<para>Hidden items only differ from other ones in that their "
286 "name starts with a \".\". In general there is no need for "
287 "users to access them which is why they are hidden.</para>"));
288 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, KStandardShortcut::showHideHiddenFiles());
289 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
291 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
292 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
293 adjustViewProps
->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
294 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
295 "in which all folder view properties can be adjusted."));
296 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
299 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
301 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
302 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
304 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
305 rolesActionGroup
->setExclusive(isSortGroup
);
307 connect(rolesActionGroup
, &QActionGroup::triggered
,
308 this, &DolphinViewActionHandler::slotSortTriggered
);
310 connect(rolesActionGroup
, &QActionGroup::triggered
,
311 this, &DolphinViewActionHandler::toggleVisibleRole
);
315 KActionMenu
* groupMenu
= nullptr;
316 QActionGroup
* groupMenuGroup
= nullptr;
318 bool indexingEnabled
= false;
320 Baloo::IndexerConfig config
;
321 indexingEnabled
= config
.fileIndexingEnabled();
324 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
325 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
326 if (!isSortGroup
&& info
.role
== "text") {
327 // It should not be possible to hide the "text" role
331 KToggleAction
* action
= nullptr;
332 const QString name
= groupPrefix
+ info
.role
;
333 if (info
.group
.isEmpty()) {
334 action
= m_actionCollection
->add
<KToggleAction
>(name
);
335 action
->setActionGroup(rolesActionGroup
);
337 if (!groupMenu
|| info
.group
!= groupName
) {
338 groupName
= info
.group
;
339 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
340 groupMenu
->setText(groupName
);
341 groupMenu
->setActionGroup(rolesActionGroup
);
343 groupMenuGroup
= new QActionGroup(groupMenu
);
344 groupMenuGroup
->setExclusive(isSortGroup
);
346 connect(groupMenuGroup
, &QActionGroup::triggered
,
347 this, &DolphinViewActionHandler::slotSortTriggered
);
349 connect(groupMenuGroup
, &QActionGroup::triggered
,
350 this, &DolphinViewActionHandler::toggleVisibleRole
);
354 action
= new KToggleAction(groupMenu
);
355 action
->setActionGroup(groupMenuGroup
);
356 groupMenu
->addAction(action
);
358 action
->setText(info
.translation
);
359 action
->setData(info
.role
);
361 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
362 (info
.requiresBaloo
) ||
363 (info
.requiresIndexer
&& indexingEnabled
);
364 action
->setEnabled(enable
);
367 m_sortByActions
.insert(info
.role
, action
);
369 m_visibleRoles
.insert(info
.role
, action
);
373 return rolesActionGroup
;
376 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
378 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
379 m_currentView
->setMode(mode
);
381 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
382 viewModeMenu
->setIcon(action
->icon());
385 void DolphinViewActionHandler::slotRename()
387 Q_EMIT
actionBeingHandled();
388 m_currentView
->renameSelectedItems();
391 void DolphinViewActionHandler::slotTrashActivated()
393 Q_EMIT
actionBeingHandled();
394 m_currentView
->trashSelectedItems();
397 void DolphinViewActionHandler::slotDeleteItems()
399 Q_EMIT
actionBeingHandled();
400 m_currentView
->deleteSelectedItems();
403 void DolphinViewActionHandler::togglePreview(bool show
)
405 Q_EMIT
actionBeingHandled();
406 m_currentView
->setPreviewsShown(show
);
409 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
412 // It is not enough to update the 'Show Preview' action, also
413 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
417 QString
DolphinViewActionHandler::currentViewModeActionName() const
419 switch (m_currentView
->mode()) {
420 case DolphinView::IconsView
:
421 return QStringLiteral("icons");
422 case DolphinView::DetailsView
:
423 return QStringLiteral("details");
424 case DolphinView::CompactView
:
425 return QStringLiteral("compact");
430 return QString(); // can't happen
433 KActionCollection
* DolphinViewActionHandler::actionCollection()
435 return m_actionCollection
;
438 void DolphinViewActionHandler::updateViewActions()
440 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
441 if (viewModeAction
) {
442 viewModeAction
->setChecked(true);
444 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
445 viewModeMenu
->setIcon(viewModeAction
->icon());
448 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
449 showPreviewAction
->setChecked(m_currentView
->previewsShown());
451 slotSortOrderChanged(m_currentView
->sortOrder());
452 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
453 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
454 slotGroupedSortingChanged(m_currentView
->groupedSorting());
455 slotSortRoleChanged(m_currentView
->sortRole());
456 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
458 // Updates the "show_hidden_files" action state and icon
459 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
462 void DolphinViewActionHandler::zoomIn()
464 const int level
= m_currentView
->zoomLevel();
465 m_currentView
->setZoomLevel(level
+ 1);
469 void DolphinViewActionHandler::zoomOut()
471 const int level
= m_currentView
->zoomLevel();
472 m_currentView
->setZoomLevel(level
- 1);
476 void DolphinViewActionHandler::zoomReset()
478 m_currentView
->resetZoomLevel();
482 void DolphinViewActionHandler::toggleSortFoldersFirst()
484 const bool sortFirst
= m_currentView
->sortFoldersFirst();
485 m_currentView
->setSortFoldersFirst(!sortFirst
);
488 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
490 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
491 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
492 const bool sortDescending
= (order
== Qt::DescendingOrder
);
493 descending
->setChecked(sortDescending
);
494 ascending
->setChecked(!sortDescending
);
497 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
499 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
502 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
504 Q_EMIT
actionBeingHandled();
506 const QByteArray toggledRole
= action
->data().toByteArray();
508 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
510 const bool show
= action
->isChecked();
512 const int index
= roles
.indexOf(toggledRole
);
513 const bool containsInfo
= (index
>= 0);
514 if (show
&& !containsInfo
) {
515 roles
.append(toggledRole
);
516 m_currentView
->setVisibleRoles(roles
);
517 } else if (!show
&& containsInfo
) {
518 roles
.removeAt(index
);
519 m_currentView
->setVisibleRoles(roles
);
520 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
524 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
525 const QList
<QByteArray
>& previous
)
529 const auto checkedRoles
= QSet
<QByteArray
>(current
.constBegin(), current
.constEnd());
530 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
531 while (it
.hasNext()) {
533 const QByteArray
& role
= it
.key();
534 KToggleAction
* action
= it
.value();
535 action
->setChecked(checkedRoles
.contains(role
));
539 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
541 m_currentView
->setGroupedSorting(grouped
);
544 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
546 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
547 showInGroupsAction
->setChecked(groupedSorting
);
550 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
552 Q_EMIT
actionBeingHandled();
553 m_currentView
->setHiddenFilesShown(show
);
556 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
558 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
559 showHiddenFilesAction
->setChecked(shown
);
562 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
564 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
565 KProtocolManager::supportsMakeDir(currentView()->url()));
568 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
570 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
571 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
572 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
573 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
| Qt::Key_1
);
574 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
575 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
579 KToggleAction
* DolphinViewActionHandler::compactModeAction()
581 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
582 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
583 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
584 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
| Qt::Key_2
);
585 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
586 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
590 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
592 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
593 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
594 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
595 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
| Qt::Key_3
);
596 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
597 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
601 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
603 KToggleAction
* action
= m_sortByActions
.value(role
);
605 action
->setChecked(true);
607 if (!action
->icon().isNull()) {
608 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
609 sortByMenu
->setIcon(action
->icon());
613 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
614 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
616 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
617 descending
->setText(i18nc("Sort descending", "Z-A"));
618 ascending
->setText(i18nc("Sort ascending", "A-Z"));
619 } else if (role
== "size") {
620 descending
->setText(i18nc("Sort descending", "Largest First"));
621 ascending
->setText(i18nc("Sort ascending", "Smallest First"));
622 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
623 descending
->setText(i18nc("Sort descending", "Newest First"));
624 ascending
->setText(i18nc("Sort ascending", "Oldest First"));
625 } else if (role
== "rating") {
626 descending
->setText(i18nc("Sort descending", "Highest First"));
627 ascending
->setText(i18nc("Sort ascending", "Lowest First"));
629 descending
->setText(i18nc("Sort descending", "Descending"));
630 ascending
->setText(i18nc("Sort ascending", "Ascending"));
633 slotSortOrderChanged(m_currentView
->sortOrder());
636 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
640 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
642 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
645 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
647 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
651 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
653 // The radiobuttons of the "Sort By"-menu are split between the main-menu
654 // and several sub-menus. Because of this they don't have a common
655 // action-group that assures an exclusive toggle-state between the main-menu
656 // actions and the sub-menu-actions. If an action gets checked, it must
657 // be assured that all other actions get unchecked, except the ascending/
658 // descending actions
659 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
660 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
662 const auto actions
= actionMenu
->menu()->actions();
663 for (QAction
* subAction
: actions
) {
664 subAction
->setChecked(false);
666 } else if (groupAction
->actionGroup()) {
667 groupAction
->setChecked(false);
670 action
->setChecked(true);
672 // Apply the activated sort-role to the view
673 const QByteArray role
= action
->data().toByteArray();
674 m_currentView
->setSortRole(role
);
677 void DolphinViewActionHandler::slotAdjustViewProperties()
679 Q_EMIT
actionBeingHandled();
680 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
685 void DolphinViewActionHandler::slotDuplicate()
687 Q_EMIT
actionBeingHandled();
688 m_currentView
->duplicateSelectedItems();
691 void DolphinViewActionHandler::slotProperties()
693 KPropertiesDialog
* dialog
= nullptr;
694 const KFileItemList list
= m_currentView
->selectedItems();
695 if (list
.isEmpty()) {
696 const QUrl url
= m_currentView
->url();
697 dialog
= new KPropertiesDialog(url
, m_currentView
);
699 dialog
= new KPropertiesDialog(list
, m_currentView
);
702 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
705 dialog
->activateWindow();
708 void DolphinViewActionHandler::slotCopyPath()
710 m_currentView
->copyPathToClipboard();