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"
16 #include <Baloo/IndexerConfig>
18 #include <KActionCollection>
19 #include <KActionMenu>
20 #include <KLocalizedString>
21 #include <KNewFileMenu>
22 #include <KPropertiesDialog>
23 #include <KProtocolManager>
27 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
29 m_actionCollection(collection
),
30 m_currentView(nullptr),
34 Q_ASSERT(m_actionCollection
);
38 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
43 disconnect(m_currentView
, nullptr, this, nullptr);
48 connect(view
, &DolphinView::modeChanged
,
49 this, &DolphinViewActionHandler::updateViewActions
);
50 connect(view
, &DolphinView::previewsShownChanged
,
51 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
52 connect(view
, &DolphinView::sortOrderChanged
,
53 this, &DolphinViewActionHandler::slotSortOrderChanged
);
54 connect(view
, &DolphinView::sortFoldersFirstChanged
,
55 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
56 connect(view
, &DolphinView::visibleRolesChanged
,
57 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
58 connect(view
, &DolphinView::groupedSortingChanged
,
59 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
60 connect(view
, &DolphinView::hiddenFilesShownChanged
,
61 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
62 connect(view
, &DolphinView::sortRoleChanged
,
63 this, &DolphinViewActionHandler::slotSortRoleChanged
);
64 connect(view
, &DolphinView::zoomLevelChanged
,
65 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
66 connect(view
, &DolphinView::writeStateChanged
,
67 this, &DolphinViewActionHandler::slotWriteStateChanged
);
70 DolphinView
* DolphinViewActionHandler::currentView()
75 void DolphinViewActionHandler::createActions()
77 // This action doesn't appear in the GUI, it's for the shortcut only.
78 // KNewFileMenu takes care of the GUI stuff.
79 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
80 newDirAction
->setText(i18nc("@action", "Create Folder..."));
81 #if KCONFIG_VERSION >= QT_VERSION_CHECK(5, 74, 0)
82 m_actionCollection
->setDefaultShortcuts(newDirAction
, KStandardShortcut::createFolder());
84 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
86 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
87 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
88 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
92 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
93 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
94 "items in your current selection.<nl/>Renaming multiple items "
95 "at once amounts to their new names differing only in a number."));
97 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
98 auto trashShortcuts
= trashAction
->shortcuts();
99 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
100 trashShortcuts
.append(QKeySequence::Delete
);
101 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
103 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
104 "items in your current selection to the <filename>Trash"
105 "</filename>.<nl/>The trash is a temporary storage where "
106 "items can be deleted from if disk space is needed."));
108 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
109 auto deleteShortcuts
= deleteAction
->shortcuts();
110 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
111 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
112 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
114 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
115 "the items in your current selection completely. They can "
116 "not be recovered by normal means."));
118 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
119 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
120 // can be used for deleting the file (#76016). It needs to be a separate action
121 // so that the Edit menu isn't affected.
122 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
123 // The descriptive text is just for the shortcuts editor.
124 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
125 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
126 deleteWithTrashShortcut
->setEnabled(false);
127 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
129 QAction
* duplicateAction
= m_actionCollection
->addAction(QStringLiteral("duplicate"));
130 duplicateAction
->setText(i18nc("@action:inmenu File", "Duplicate Here"));
131 duplicateAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
132 m_actionCollection
->setDefaultShortcut(duplicateAction
, Qt::CTRL
| Qt::Key_D
);
133 duplicateAction
->setEnabled(false);
134 connect(duplicateAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDuplicate
);
136 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
137 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
138 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
139 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
140 "This shows a complete list of properties of the currently "
141 "selected items in a new window.<nl/>If nothing is selected the "
142 "window will be about the currently viewed folder instead.<nl/>"
143 "You can configure advanced options there like managing "
144 "read- and write-permissions."));
145 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
146 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
147 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
149 QAction
*copyPathAction
= m_actionCollection
->addAction( QStringLiteral("copy_location") );
150 copyPathAction
->setText(i18nc("@action:incontextmenu", "Copy Location"));
151 copyPathAction
->setWhatsThis(i18nc("@info:whatsthis copy_location",
152 "This will copy the path of the first selected item into the clipboard."
155 copyPathAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
156 m_actionCollection
->setDefaultShortcuts(copyPathAction
, {Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_C
});
157 connect(copyPathAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotCopyPath
);
161 KToggleAction
* iconsAction
= iconsModeAction();
162 KToggleAction
* compactAction
= compactModeAction();
163 KToggleAction
* detailsAction
= detailsModeAction();
165 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
166 "<para>This switches to a view mode that focuses on the folder "
167 "and file icons. This mode makes it easy to distinguish folders "
168 "from files and to detect items with distinctive <emphasis>"
169 "file types</emphasis>.</para><para> This mode is handy to "
170 "browse through pictures when the <interface>Preview"
171 "</interface> option is enabled.</para>"));
172 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
173 "<para>This switches to a compact view mode that lists the folders "
174 "and files in columns with the names beside the icons.</para><para>"
175 "This helps to keep the overview in folders with many items.</para>"));
176 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
177 "<para>This switches to a list view mode that focuses on folder "
178 "and file details.</para><para>Click on a detail in the column "
179 "header to sort the items by it. Click again to sort the other "
180 "way around. To select which details should be displayed click "
181 "the header with the right mouse button.</para><para>You can "
182 "view the contents of a folder without leaving the current "
183 "location by clicking to the left of it. This way you can view "
184 "the contents of multiple folders in the same list.</para>"));
186 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
187 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
188 viewModeActions
->addAction(iconsAction
);
189 viewModeActions
->addAction(compactAction
);
190 viewModeActions
->addAction(detailsAction
);
191 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
192 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
194 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
195 &DolphinViewActionHandler::zoomIn
,
197 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
199 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
200 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
201 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
202 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
203 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
204 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
+ Qt::Key_0
});
205 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
207 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
208 &DolphinViewActionHandler::zoomOut
,
210 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
212 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
213 showPreview
->setText(i18nc("@action:intoolbar", "Show Previews"));
214 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
215 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
216 "enabled, the icons are based on the actual file or folder "
217 "contents.<nl/>For example the icons of images become scaled "
218 "down versions of the images."));
219 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
220 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
222 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
223 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
224 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
227 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
229 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
230 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
231 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
232 sortByActionMenu
->setDelayed(false);
234 const auto sortByActionGroupActions
= sortByActionGroup
->actions();
235 for (QAction
* action
: sortByActionGroupActions
) {
236 sortByActionMenu
->addAction(action
);
239 sortByActionMenu
->addSeparator();
241 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
242 group
->setExclusive(true);
244 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
245 ascendingAction
->setActionGroup(group
);
246 connect(ascendingAction
, &QAction::triggered
, this, [this] {
247 m_currentView
->setSortOrder(Qt::AscendingOrder
);
250 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
251 descendingAction
->setActionGroup(group
);
252 connect(descendingAction
, &QAction::triggered
, this, [this] {
253 m_currentView
->setSortOrder(Qt::DescendingOrder
);
256 sortByActionMenu
->addAction(ascendingAction
);
257 sortByActionMenu
->addAction(descendingAction
);
258 sortByActionMenu
->addSeparator();
259 sortByActionMenu
->addAction(sortFoldersFirst
);
261 // View -> Additional Information
262 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
264 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
265 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
266 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
267 visibleRolesMenu
->setDelayed(false);
269 const auto visibleRolesGroupActions
= visibleRolesGroup
->actions();
270 for (QAction
* action
: visibleRolesGroupActions
) {
271 visibleRolesMenu
->addAction(action
);
274 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
275 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
276 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
277 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
278 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
280 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
281 showHiddenFiles
->setIcon(QIcon::fromTheme(QStringLiteral("view-visible")));
282 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
283 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
284 "this is enabled <emphasis>hidden</emphasis> files and folders "
285 "are visible. They will be displayed semi-transparent.</para>"
286 "<para>Hidden items only differ from other ones in that their "
287 "name starts with a \".\". In general there is no need for "
288 "users to access them which is why they are hidden.</para>"));
289 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, KStandardShortcut::showHideHiddenFiles());
290 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
292 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
293 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
294 adjustViewProps
->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
295 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
296 "in which all folder view properties can be adjusted."));
297 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
300 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
302 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
303 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
305 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
306 rolesActionGroup
->setExclusive(isSortGroup
);
308 connect(rolesActionGroup
, &QActionGroup::triggered
,
309 this, &DolphinViewActionHandler::slotSortTriggered
);
311 connect(rolesActionGroup
, &QActionGroup::triggered
,
312 this, &DolphinViewActionHandler::toggleVisibleRole
);
316 KActionMenu
* groupMenu
= nullptr;
317 QActionGroup
* groupMenuGroup
= nullptr;
319 bool indexingEnabled
= false;
321 Baloo::IndexerConfig config
;
322 indexingEnabled
= config
.fileIndexingEnabled();
325 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
326 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
327 if (!isSortGroup
&& info
.role
== "text") {
328 // It should not be possible to hide the "text" role
332 KToggleAction
* action
= nullptr;
333 const QString name
= groupPrefix
+ info
.role
;
334 if (info
.group
.isEmpty()) {
335 action
= m_actionCollection
->add
<KToggleAction
>(name
);
336 action
->setActionGroup(rolesActionGroup
);
338 if (!groupMenu
|| info
.group
!= groupName
) {
339 groupName
= info
.group
;
340 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
341 groupMenu
->setText(groupName
);
342 groupMenu
->setActionGroup(rolesActionGroup
);
344 groupMenuGroup
= new QActionGroup(groupMenu
);
345 groupMenuGroup
->setExclusive(isSortGroup
);
347 connect(groupMenuGroup
, &QActionGroup::triggered
,
348 this, &DolphinViewActionHandler::slotSortTriggered
);
350 connect(groupMenuGroup
, &QActionGroup::triggered
,
351 this, &DolphinViewActionHandler::toggleVisibleRole
);
355 action
= new KToggleAction(groupMenu
);
356 action
->setActionGroup(groupMenuGroup
);
357 groupMenu
->addAction(action
);
359 action
->setText(info
.translation
);
360 action
->setData(info
.role
);
362 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
363 (info
.requiresBaloo
) ||
364 (info
.requiresIndexer
&& indexingEnabled
);
365 action
->setEnabled(enable
);
368 m_sortByActions
.insert(info
.role
, action
);
370 m_visibleRoles
.insert(info
.role
, action
);
374 return rolesActionGroup
;
377 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
379 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
380 m_currentView
->setMode(mode
);
382 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
383 viewModeMenu
->setIcon(action
->icon());
386 void DolphinViewActionHandler::slotRename()
388 Q_EMIT
actionBeingHandled();
389 m_currentView
->renameSelectedItems();
392 void DolphinViewActionHandler::slotTrashActivated()
394 Q_EMIT
actionBeingHandled();
395 m_currentView
->trashSelectedItems();
398 void DolphinViewActionHandler::slotDeleteItems()
400 Q_EMIT
actionBeingHandled();
401 m_currentView
->deleteSelectedItems();
404 void DolphinViewActionHandler::togglePreview(bool show
)
406 Q_EMIT
actionBeingHandled();
407 m_currentView
->setPreviewsShown(show
);
410 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
413 // It is not enough to update the 'Show Preview' action, also
414 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
418 QString
DolphinViewActionHandler::currentViewModeActionName() const
420 switch (m_currentView
->mode()) {
421 case DolphinView::IconsView
:
422 return QStringLiteral("icons");
423 case DolphinView::DetailsView
:
424 return QStringLiteral("details");
425 case DolphinView::CompactView
:
426 return QStringLiteral("compact");
431 return QString(); // can't happen
434 KActionCollection
* DolphinViewActionHandler::actionCollection()
436 return m_actionCollection
;
439 void DolphinViewActionHandler::updateViewActions()
441 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
442 if (viewModeAction
) {
443 viewModeAction
->setChecked(true);
445 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
446 viewModeMenu
->setIcon(viewModeAction
->icon());
449 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
450 showPreviewAction
->setChecked(m_currentView
->previewsShown());
452 slotSortOrderChanged(m_currentView
->sortOrder());
453 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
454 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
455 slotGroupedSortingChanged(m_currentView
->groupedSorting());
456 slotSortRoleChanged(m_currentView
->sortRole());
457 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
459 // Updates the "show_hidden_files" action state and icon
460 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
463 void DolphinViewActionHandler::zoomIn()
465 const int level
= m_currentView
->zoomLevel();
466 m_currentView
->setZoomLevel(level
+ 1);
470 void DolphinViewActionHandler::zoomOut()
472 const int level
= m_currentView
->zoomLevel();
473 m_currentView
->setZoomLevel(level
- 1);
477 void DolphinViewActionHandler::zoomReset()
479 m_currentView
->resetZoomLevel();
483 void DolphinViewActionHandler::toggleSortFoldersFirst()
485 const bool sortFirst
= m_currentView
->sortFoldersFirst();
486 m_currentView
->setSortFoldersFirst(!sortFirst
);
489 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
491 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
492 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
493 const bool sortDescending
= (order
== Qt::DescendingOrder
);
494 descending
->setChecked(sortDescending
);
495 ascending
->setChecked(!sortDescending
);
498 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
500 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
503 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
505 Q_EMIT
actionBeingHandled();
507 const QByteArray toggledRole
= action
->data().toByteArray();
509 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
511 const bool show
= action
->isChecked();
513 const int index
= roles
.indexOf(toggledRole
);
514 const bool containsInfo
= (index
>= 0);
515 if (show
&& !containsInfo
) {
516 roles
.append(toggledRole
);
517 m_currentView
->setVisibleRoles(roles
);
518 } else if (!show
&& containsInfo
) {
519 roles
.removeAt(index
);
520 m_currentView
->setVisibleRoles(roles
);
521 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
525 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
526 const QList
<QByteArray
>& previous
)
530 const auto checkedRoles
= QSet
<QByteArray
>(current
.constBegin(), current
.constEnd());
531 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
532 while (it
.hasNext()) {
534 const QByteArray
& role
= it
.key();
535 KToggleAction
* action
= it
.value();
536 action
->setChecked(checkedRoles
.contains(role
));
540 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
542 m_currentView
->setGroupedSorting(grouped
);
545 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
547 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
548 showInGroupsAction
->setChecked(groupedSorting
);
551 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
553 Q_EMIT
actionBeingHandled();
554 m_currentView
->setHiddenFilesShown(show
);
557 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
559 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
560 showHiddenFilesAction
->setChecked(shown
);
563 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
565 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
566 KProtocolManager::supportsMakeDir(currentView()->url()));
569 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
571 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
572 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
573 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
574 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
575 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
576 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
580 KToggleAction
* DolphinViewActionHandler::compactModeAction()
582 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
583 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
584 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
585 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
586 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
587 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
591 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
593 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
594 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
595 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
596 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
597 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
598 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
602 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
604 KToggleAction
* action
= m_sortByActions
.value(role
);
606 action
->setChecked(true);
608 if (!action
->icon().isNull()) {
609 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
610 sortByMenu
->setIcon(action
->icon());
614 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
615 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
617 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
618 descending
->setText(i18nc("Sort descending", "Z-A"));
619 ascending
->setText(i18nc("Sort ascending", "A-Z"));
620 } else if (role
== "size") {
621 descending
->setText(i18nc("Sort descending", "Largest First"));
622 ascending
->setText(i18nc("Sort ascending", "Smallest First"));
623 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
624 descending
->setText(i18nc("Sort descending", "Newest First"));
625 ascending
->setText(i18nc("Sort ascending", "Oldest First"));
626 } else if (role
== "rating") {
627 descending
->setText(i18nc("Sort descending", "Highest First"));
628 ascending
->setText(i18nc("Sort ascending", "Lowest First"));
630 descending
->setText(i18nc("Sort descending", "Descending"));
631 ascending
->setText(i18nc("Sort ascending", "Ascending"));
634 slotSortOrderChanged(m_currentView
->sortOrder());
637 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
641 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
643 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
646 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
648 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
652 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
654 // The radiobuttons of the "Sort By"-menu are split between the main-menu
655 // and several sub-menus. Because of this they don't have a common
656 // action-group that assures an exclusive toggle-state between the main-menu
657 // actions and the sub-menu-actions. If an action gets checked, it must
658 // be assured that all other actions get unchecked, except the ascending/
659 // descending actions
660 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
661 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
663 const auto actions
= actionMenu
->menu()->actions();
664 for (QAction
* subAction
: actions
) {
665 subAction
->setChecked(false);
667 } else if (groupAction
->actionGroup()) {
668 groupAction
->setChecked(false);
671 action
->setChecked(true);
673 // Apply the activated sort-role to the view
674 const QByteArray role
= action
->data().toByteArray();
675 m_currentView
->setSortRole(role
);
678 void DolphinViewActionHandler::slotAdjustViewProperties()
680 Q_EMIT
actionBeingHandled();
681 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
686 void DolphinViewActionHandler::slotDuplicate()
688 Q_EMIT
actionBeingHandled();
689 m_currentView
->duplicateSelectedItems();
692 void DolphinViewActionHandler::slotProperties()
694 KPropertiesDialog
* dialog
= nullptr;
695 const KFileItemList list
= m_currentView
->selectedItems();
696 if (list
.isEmpty()) {
697 const QUrl url
= m_currentView
->url();
698 dialog
= new KPropertiesDialog(url
, m_currentView
);
700 dialog
= new KPropertiesDialog(list
, m_currentView
);
703 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
706 dialog
->activateWindow();
709 void DolphinViewActionHandler::slotCopyPath()
711 m_currentView
->copyPathToClipboard();