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 m_actionCollection
->setDefaultShortcuts(newDirAction
, KStandardShortcut::createFolder());
83 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
84 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
85 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
89 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
90 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
91 "items in your current selection.<nl/>Renaming multiple items "
92 "at once amounts to their new names differing only in a number."));
94 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
95 auto trashShortcuts
= trashAction
->shortcuts();
96 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
97 trashShortcuts
.append(QKeySequence::Delete
);
98 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
100 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
101 "items in your current selection to the <filename>Trash"
102 "</filename>.<nl/>The trash is a temporary storage where "
103 "items can be deleted from if disk space is needed."));
105 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
106 auto deleteShortcuts
= deleteAction
->shortcuts();
107 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
108 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
109 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
111 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
112 "the items in your current selection completely. They can "
113 "not be recovered by normal means."));
115 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
116 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
117 // can be used for deleting the file (#76016). It needs to be a separate action
118 // so that the Edit menu isn't affected.
119 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
120 // The descriptive text is just for the shortcuts editor.
121 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
122 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
123 deleteWithTrashShortcut
->setEnabled(false);
124 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
126 QAction
* duplicateAction
= m_actionCollection
->addAction(QStringLiteral("duplicate"));
127 duplicateAction
->setText(i18nc("@action:inmenu File", "Duplicate Here"));
128 duplicateAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
129 m_actionCollection
->setDefaultShortcut(duplicateAction
, Qt::CTRL
| Qt::Key_D
);
130 duplicateAction
->setEnabled(false);
131 connect(duplicateAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDuplicate
);
133 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
134 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
135 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
136 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
137 "This shows a complete list of properties of the currently "
138 "selected items in a new window.<nl/>If nothing is selected the "
139 "window will be about the currently viewed folder instead.<nl/>"
140 "You can configure advanced options there like managing "
141 "read- and write-permissions."));
142 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
143 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
| Qt::Key_Return
, Qt::ALT
| Qt::Key_Enter
});
144 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
146 QAction
*copyPathAction
= m_actionCollection
->addAction( QStringLiteral("copy_location") );
147 copyPathAction
->setText(i18nc("@action:incontextmenu", "Copy Location"));
148 copyPathAction
->setWhatsThis(i18nc("@info:whatsthis copy_location",
149 "This will copy the path of the first selected item into the clipboard."
152 copyPathAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
153 m_actionCollection
->setDefaultShortcuts(copyPathAction
, {Qt::CTRL
| Qt::ALT
| Qt::Key_C
});
154 connect(copyPathAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotCopyPath
);
158 KToggleAction
* iconsAction
= iconsModeAction();
159 KToggleAction
* compactAction
= compactModeAction();
160 KToggleAction
* detailsAction
= detailsModeAction();
162 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
163 "<para>This switches to a view mode that focuses on the folder "
164 "and file icons. This mode makes it easy to distinguish folders "
165 "from files and to detect items with distinctive <emphasis>"
166 "file types</emphasis>.</para><para> This mode is handy to "
167 "browse through pictures when the <interface>Preview"
168 "</interface> option is enabled.</para>"));
169 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
170 "<para>This switches to a compact view mode that lists the folders "
171 "and files in columns with the names beside the icons.</para><para>"
172 "This helps to keep the overview in folders with many items.</para>"));
173 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
174 "<para>This switches to a list view mode that focuses on folder "
175 "and file details.</para><para>Click on a detail in the column "
176 "header to sort the items by it. Click again to sort the other "
177 "way around. To select which details should be displayed click "
178 "the header with the right mouse button.</para><para>You can "
179 "view the contents of a folder without leaving the current "
180 "location by clicking to the left of it. This way you can view "
181 "the contents of multiple folders in the same list.</para>"));
183 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
184 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
185 viewModeActions
->addAction(iconsAction
);
186 viewModeActions
->addAction(compactAction
);
187 viewModeActions
->addAction(detailsAction
);
188 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
189 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
191 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
192 &DolphinViewActionHandler::zoomIn
,
194 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
196 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
197 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
198 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
199 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
200 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
201 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
| Qt::Key_0
});
202 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
204 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
205 &DolphinViewActionHandler::zoomOut
,
207 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
209 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
210 showPreview
->setText(i18nc("@action:intoolbar", "Show Previews"));
211 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
212 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
213 "enabled, the icons are based on the actual file or folder "
214 "contents.<nl/>For example the icons of images become scaled "
215 "down versions of the images."));
216 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
217 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
219 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
220 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
221 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
224 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
226 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
227 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
228 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
229 sortByActionMenu
->setDelayed(false);
231 const auto sortByActionGroupActions
= sortByActionGroup
->actions();
232 for (QAction
* action
: sortByActionGroupActions
) {
233 sortByActionMenu
->addAction(action
);
236 sortByActionMenu
->addSeparator();
238 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
239 group
->setExclusive(true);
241 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
242 ascendingAction
->setActionGroup(group
);
243 connect(ascendingAction
, &QAction::triggered
, this, [this] {
244 m_currentView
->setSortOrder(Qt::AscendingOrder
);
247 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
248 descendingAction
->setActionGroup(group
);
249 connect(descendingAction
, &QAction::triggered
, this, [this] {
250 m_currentView
->setSortOrder(Qt::DescendingOrder
);
253 sortByActionMenu
->addAction(ascendingAction
);
254 sortByActionMenu
->addAction(descendingAction
);
255 sortByActionMenu
->addSeparator();
256 sortByActionMenu
->addAction(sortFoldersFirst
);
258 // View -> Additional Information
259 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
261 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
262 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
263 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
264 visibleRolesMenu
->setDelayed(false);
266 const auto visibleRolesGroupActions
= visibleRolesGroup
->actions();
267 for (QAction
* action
: visibleRolesGroupActions
) {
268 visibleRolesMenu
->addAction(action
);
271 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
272 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
273 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
274 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
275 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
277 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
278 showHiddenFiles
->setIcon(QIcon::fromTheme(QStringLiteral("view-visible")));
279 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
280 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
281 "this is enabled <emphasis>hidden</emphasis> files and folders "
282 "are visible. They will be displayed semi-transparent.</para>"
283 "<para>Hidden items only differ from other ones in that their "
284 "name starts with a \".\". In general there is no need for "
285 "users to access them which is why they are hidden.</para>"));
286 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, KStandardShortcut::showHideHiddenFiles());
287 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
289 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
290 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
291 adjustViewProps
->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
292 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
293 "in which all folder view properties can be adjusted."));
294 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
297 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
299 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
300 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
302 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
303 rolesActionGroup
->setExclusive(isSortGroup
);
305 connect(rolesActionGroup
, &QActionGroup::triggered
,
306 this, &DolphinViewActionHandler::slotSortTriggered
);
308 connect(rolesActionGroup
, &QActionGroup::triggered
,
309 this, &DolphinViewActionHandler::toggleVisibleRole
);
313 KActionMenu
* groupMenu
= nullptr;
314 QActionGroup
* groupMenuGroup
= nullptr;
316 bool indexingEnabled
= false;
318 Baloo::IndexerConfig config
;
319 indexingEnabled
= config
.fileIndexingEnabled();
322 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
323 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
324 if (!isSortGroup
&& info
.role
== "text") {
325 // It should not be possible to hide the "text" role
329 KToggleAction
* action
= nullptr;
330 const QString name
= groupPrefix
+ info
.role
;
331 if (info
.group
.isEmpty()) {
332 action
= m_actionCollection
->add
<KToggleAction
>(name
);
333 action
->setActionGroup(rolesActionGroup
);
335 if (!groupMenu
|| info
.group
!= groupName
) {
336 groupName
= info
.group
;
337 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
338 groupMenu
->setText(groupName
);
339 groupMenu
->setActionGroup(rolesActionGroup
);
341 groupMenuGroup
= new QActionGroup(groupMenu
);
342 groupMenuGroup
->setExclusive(isSortGroup
);
344 connect(groupMenuGroup
, &QActionGroup::triggered
,
345 this, &DolphinViewActionHandler::slotSortTriggered
);
347 connect(groupMenuGroup
, &QActionGroup::triggered
,
348 this, &DolphinViewActionHandler::toggleVisibleRole
);
352 action
= new KToggleAction(groupMenu
);
353 action
->setActionGroup(groupMenuGroup
);
354 groupMenu
->addAction(action
);
356 action
->setText(info
.translation
);
357 action
->setData(info
.role
);
359 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
360 (info
.requiresBaloo
) ||
361 (info
.requiresIndexer
&& indexingEnabled
);
362 action
->setEnabled(enable
);
365 m_sortByActions
.insert(info
.role
, action
);
367 m_visibleRoles
.insert(info
.role
, action
);
371 return rolesActionGroup
;
374 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
376 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
377 m_currentView
->setMode(mode
);
379 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
380 viewModeMenu
->setIcon(action
->icon());
383 void DolphinViewActionHandler::slotRename()
385 Q_EMIT
actionBeingHandled();
386 m_currentView
->renameSelectedItems();
389 void DolphinViewActionHandler::slotTrashActivated()
391 Q_EMIT
actionBeingHandled();
392 m_currentView
->trashSelectedItems();
395 void DolphinViewActionHandler::slotDeleteItems()
397 Q_EMIT
actionBeingHandled();
398 m_currentView
->deleteSelectedItems();
401 void DolphinViewActionHandler::togglePreview(bool show
)
403 Q_EMIT
actionBeingHandled();
404 m_currentView
->setPreviewsShown(show
);
407 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
410 // It is not enough to update the 'Show Preview' action, also
411 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
415 QString
DolphinViewActionHandler::currentViewModeActionName() const
417 switch (m_currentView
->mode()) {
418 case DolphinView::IconsView
:
419 return QStringLiteral("icons");
420 case DolphinView::DetailsView
:
421 return QStringLiteral("details");
422 case DolphinView::CompactView
:
423 return QStringLiteral("compact");
428 return QString(); // can't happen
431 KActionCollection
* DolphinViewActionHandler::actionCollection()
433 return m_actionCollection
;
436 void DolphinViewActionHandler::updateViewActions()
438 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
439 if (viewModeAction
) {
440 viewModeAction
->setChecked(true);
442 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
443 viewModeMenu
->setIcon(viewModeAction
->icon());
446 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
447 showPreviewAction
->setChecked(m_currentView
->previewsShown());
449 slotSortOrderChanged(m_currentView
->sortOrder());
450 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
451 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
452 slotGroupedSortingChanged(m_currentView
->groupedSorting());
453 slotSortRoleChanged(m_currentView
->sortRole());
454 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
456 // Updates the "show_hidden_files" action state and icon
457 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
460 void DolphinViewActionHandler::zoomIn()
462 const int level
= m_currentView
->zoomLevel();
463 m_currentView
->setZoomLevel(level
+ 1);
467 void DolphinViewActionHandler::zoomOut()
469 const int level
= m_currentView
->zoomLevel();
470 m_currentView
->setZoomLevel(level
- 1);
474 void DolphinViewActionHandler::zoomReset()
476 m_currentView
->resetZoomLevel();
480 void DolphinViewActionHandler::toggleSortFoldersFirst()
482 const bool sortFirst
= m_currentView
->sortFoldersFirst();
483 m_currentView
->setSortFoldersFirst(!sortFirst
);
486 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
488 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
489 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
490 const bool sortDescending
= (order
== Qt::DescendingOrder
);
491 descending
->setChecked(sortDescending
);
492 ascending
->setChecked(!sortDescending
);
495 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
497 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
500 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
502 Q_EMIT
actionBeingHandled();
504 const QByteArray toggledRole
= action
->data().toByteArray();
506 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
508 const bool show
= action
->isChecked();
510 const int index
= roles
.indexOf(toggledRole
);
511 const bool containsInfo
= (index
>= 0);
512 if (show
&& !containsInfo
) {
513 roles
.append(toggledRole
);
514 m_currentView
->setVisibleRoles(roles
);
515 } else if (!show
&& containsInfo
) {
516 roles
.removeAt(index
);
517 m_currentView
->setVisibleRoles(roles
);
518 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
522 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
523 const QList
<QByteArray
>& previous
)
527 const auto checkedRoles
= QSet
<QByteArray
>(current
.constBegin(), current
.constEnd());
528 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
529 while (it
.hasNext()) {
531 const QByteArray
& role
= it
.key();
532 KToggleAction
* action
= it
.value();
533 action
->setChecked(checkedRoles
.contains(role
));
537 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
539 m_currentView
->setGroupedSorting(grouped
);
542 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
544 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
545 showInGroupsAction
->setChecked(groupedSorting
);
548 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
550 Q_EMIT
actionBeingHandled();
551 m_currentView
->setHiddenFilesShown(show
);
554 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
556 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
557 showHiddenFilesAction
->setChecked(shown
);
560 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
562 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
563 KProtocolManager::supportsMakeDir(currentView()->url()));
566 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
568 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
569 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
570 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
571 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
| Qt::Key_1
);
572 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
573 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
577 KToggleAction
* DolphinViewActionHandler::compactModeAction()
579 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
580 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
581 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
582 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
| Qt::Key_2
);
583 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
584 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
588 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
590 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
591 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
592 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
593 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
| Qt::Key_3
);
594 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
595 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
599 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
601 KToggleAction
* action
= m_sortByActions
.value(role
);
603 action
->setChecked(true);
605 if (!action
->icon().isNull()) {
606 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
607 sortByMenu
->setIcon(action
->icon());
611 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
612 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
614 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
615 descending
->setText(i18nc("Sort descending", "Z-A"));
616 ascending
->setText(i18nc("Sort ascending", "A-Z"));
617 } else if (role
== "size") {
618 descending
->setText(i18nc("Sort descending", "Largest First"));
619 ascending
->setText(i18nc("Sort ascending", "Smallest First"));
620 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
621 descending
->setText(i18nc("Sort descending", "Newest First"));
622 ascending
->setText(i18nc("Sort ascending", "Oldest First"));
623 } else if (role
== "rating") {
624 descending
->setText(i18nc("Sort descending", "Highest First"));
625 ascending
->setText(i18nc("Sort ascending", "Lowest First"));
627 descending
->setText(i18nc("Sort descending", "Descending"));
628 ascending
->setText(i18nc("Sort ascending", "Ascending"));
631 slotSortOrderChanged(m_currentView
->sortOrder());
634 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
638 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
640 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
643 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
645 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
649 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
651 // The radiobuttons of the "Sort By"-menu are split between the main-menu
652 // and several sub-menus. Because of this they don't have a common
653 // action-group that assures an exclusive toggle-state between the main-menu
654 // actions and the sub-menu-actions. If an action gets checked, it must
655 // be assured that all other actions get unchecked, except the ascending/
656 // descending actions
657 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
658 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
660 const auto actions
= actionMenu
->menu()->actions();
661 for (QAction
* subAction
: actions
) {
662 subAction
->setChecked(false);
664 } else if (groupAction
->actionGroup()) {
665 groupAction
->setChecked(false);
668 action
->setChecked(true);
670 // Apply the activated sort-role to the view
671 const QByteArray role
= action
->data().toByteArray();
672 m_currentView
->setSortRole(role
);
675 void DolphinViewActionHandler::slotAdjustViewProperties()
677 Q_EMIT
actionBeingHandled();
678 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
683 void DolphinViewActionHandler::slotDuplicate()
685 Q_EMIT
actionBeingHandled();
686 m_currentView
->duplicateSelectedItems();
689 void DolphinViewActionHandler::slotProperties()
691 KPropertiesDialog
* dialog
= nullptr;
692 const KFileItemList list
= m_currentView
->selectedItems();
693 if (list
.isEmpty()) {
694 const QUrl url
= m_currentView
->url();
695 dialog
= new KPropertiesDialog(url
, m_currentView
);
697 dialog
= new KPropertiesDialog(list
, m_currentView
);
700 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
703 dialog
->activateWindow();
706 void DolphinViewActionHandler::slotCopyPath()
708 m_currentView
->copyPathToClipboard();