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 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
82 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
83 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
84 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
88 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
89 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
90 "items in your current selection.<nl/>Renaming multiple items "
91 "at once amounts to their new names differing only in a number."));
93 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
94 auto trashShortcuts
= trashAction
->shortcuts();
95 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
96 trashShortcuts
.append(QKeySequence::Delete
);
97 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
99 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
100 "items in your current selection to the <filename>Trash"
101 "</filename>.<nl/>The trash is a temporary storage where "
102 "items can be deleted from if disk space is needed."));
104 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
105 auto deleteShortcuts
= deleteAction
->shortcuts();
106 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
107 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
108 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
110 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
111 "the items in your current selection completely. They can "
112 "not be recovered by normal means."));
114 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
115 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
116 // can be used for deleting the file (#76016). It needs to be a separate action
117 // so that the Edit menu isn't affected.
118 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
119 // The descriptive text is just for the shortcuts editor.
120 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
121 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
122 deleteWithTrashShortcut
->setEnabled(false);
123 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
125 QAction
* duplicateAction
= m_actionCollection
->addAction(QStringLiteral("duplicate"));
126 duplicateAction
->setText(i18nc("@action:inmenu File", "Duplicate Here"));
127 duplicateAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
128 m_actionCollection
->setDefaultShortcut(duplicateAction
, Qt::CTRL
| Qt::Key_D
);
129 duplicateAction
->setEnabled(false);
130 connect(duplicateAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDuplicate
);
132 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
133 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
134 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
135 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
136 "This shows a complete list of properties of the currently "
137 "selected items in a new window.<nl/>If nothing is selected the "
138 "window will be about the currently viewed folder instead.<nl/>"
139 "You can configure advanced options there like managing "
140 "read- and write-permissions."));
141 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
142 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
143 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
145 QAction
*copyPathAction
= m_actionCollection
->addAction( QStringLiteral("copy_location") );
146 copyPathAction
->setText(i18nc("@action:incontextmenu", "Copy Location"));
147 copyPathAction
->setWhatsThis(i18nc("@info:whatsthis copy_location",
148 "This will copy the path of the first selected item into the clipboard."
151 copyPathAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
152 m_actionCollection
->setDefaultShortcuts(copyPathAction
, {Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_C
});
153 connect(copyPathAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotCopyPath
);
157 KToggleAction
* iconsAction
= iconsModeAction();
158 KToggleAction
* compactAction
= compactModeAction();
159 KToggleAction
* detailsAction
= detailsModeAction();
161 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
162 "<para>This switches to a view mode that focuses on the folder "
163 "and file icons. This mode makes it easy to distinguish folders "
164 "from files and to detect items with distinctive <emphasis>"
165 "file types</emphasis>.</para><para> This mode is handy to "
166 "browse through pictures when the <interface>Preview"
167 "</interface> option is enabled.</para>"));
168 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
169 "<para>This switches to a compact view mode that lists the folders "
170 "and files in columns with the names beside the icons.</para><para>"
171 "This helps to keep the overview in folders with many items.</para>"));
172 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
173 "<para>This switches to a list view mode that focuses on folder "
174 "and file details.</para><para>Click on a detail in the column "
175 "header to sort the items by it. Click again to sort the other "
176 "way around. To select which details should be displayed click "
177 "the header with the right mouse button.</para><para>You can "
178 "view the contents of a folder without leaving the current "
179 "location by clicking to the left of it. This way you can view "
180 "the contents of multiple folders in the same list.</para>"));
182 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
183 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
184 viewModeActions
->addAction(iconsAction
);
185 viewModeActions
->addAction(compactAction
);
186 viewModeActions
->addAction(detailsAction
);
187 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
188 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
190 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
191 &DolphinViewActionHandler::zoomIn
,
193 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
195 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
196 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
197 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
198 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
199 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
200 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
+ Qt::Key_0
});
201 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
203 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
204 &DolphinViewActionHandler::zoomOut
,
206 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
208 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
209 showPreview
->setText(i18nc("@action:intoolbar", "Show Previews"));
210 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
211 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
212 "enabled, the icons are based on the actual file or folder "
213 "contents.<nl/>For example the icons of images become scaled "
214 "down versions of the images."));
215 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
216 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
218 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
219 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
220 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
223 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
225 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
226 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
227 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
228 sortByActionMenu
->setDelayed(false);
230 foreach (QAction
* action
, sortByActionGroup
->actions()) {
231 sortByActionMenu
->addAction(action
);
234 sortByActionMenu
->addSeparator();
236 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
237 group
->setExclusive(true);
239 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
240 ascendingAction
->setActionGroup(group
);
241 connect(ascendingAction
, &QAction::triggered
, this, [this] {
242 m_currentView
->setSortOrder(Qt::AscendingOrder
);
245 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
246 descendingAction
->setActionGroup(group
);
247 connect(descendingAction
, &QAction::triggered
, this, [this] {
248 m_currentView
->setSortOrder(Qt::DescendingOrder
);
251 sortByActionMenu
->addAction(ascendingAction
);
252 sortByActionMenu
->addAction(descendingAction
);
253 sortByActionMenu
->addSeparator();
254 sortByActionMenu
->addAction(sortFoldersFirst
);
256 // View -> Additional Information
257 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
259 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
260 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
261 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
262 visibleRolesMenu
->setDelayed(false);
264 foreach (QAction
* action
, visibleRolesGroup
->actions()) {
265 visibleRolesMenu
->addAction(action
);
268 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
269 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
270 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
271 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
272 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
274 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
275 showHiddenFiles
->setIcon(QIcon::fromTheme(QStringLiteral("view-visible")));
276 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
277 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
278 "this is enabled <emphasis>hidden</emphasis> files and folders "
279 "are visible. They will be displayed semi-transparent.</para>"
280 "<para>Hidden items only differ from other ones in that their "
281 "name starts with a \".\". In general there is no need for "
282 "users to access them which is why they are hidden.</para>"));
283 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, KStandardShortcut::showHideHiddenFiles());
284 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
286 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
287 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
288 adjustViewProps
->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
289 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
290 "in which all folder view properties can be adjusted."));
291 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
294 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
296 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
297 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
299 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
300 rolesActionGroup
->setExclusive(isSortGroup
);
302 connect(rolesActionGroup
, &QActionGroup::triggered
,
303 this, &DolphinViewActionHandler::slotSortTriggered
);
305 connect(rolesActionGroup
, &QActionGroup::triggered
,
306 this, &DolphinViewActionHandler::toggleVisibleRole
);
310 KActionMenu
* groupMenu
= nullptr;
311 QActionGroup
* groupMenuGroup
= nullptr;
313 bool indexingEnabled
= false;
315 Baloo::IndexerConfig config
;
316 indexingEnabled
= config
.fileIndexingEnabled();
319 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
320 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
321 if (!isSortGroup
&& info
.role
== "text") {
322 // It should not be possible to hide the "text" role
326 KToggleAction
* action
= nullptr;
327 const QString name
= groupPrefix
+ info
.role
;
328 if (info
.group
.isEmpty()) {
329 action
= m_actionCollection
->add
<KToggleAction
>(name
);
330 action
->setActionGroup(rolesActionGroup
);
332 if (!groupMenu
|| info
.group
!= groupName
) {
333 groupName
= info
.group
;
334 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
335 groupMenu
->setText(groupName
);
336 groupMenu
->setActionGroup(rolesActionGroup
);
338 groupMenuGroup
= new QActionGroup(groupMenu
);
339 groupMenuGroup
->setExclusive(isSortGroup
);
341 connect(groupMenuGroup
, &QActionGroup::triggered
,
342 this, &DolphinViewActionHandler::slotSortTriggered
);
344 connect(groupMenuGroup
, &QActionGroup::triggered
,
345 this, &DolphinViewActionHandler::toggleVisibleRole
);
349 action
= new KToggleAction(groupMenu
);
350 action
->setActionGroup(groupMenuGroup
);
351 groupMenu
->addAction(action
);
353 action
->setText(info
.translation
);
354 action
->setData(info
.role
);
356 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
357 (info
.requiresBaloo
) ||
358 (info
.requiresIndexer
&& indexingEnabled
);
359 action
->setEnabled(enable
);
362 m_sortByActions
.insert(info
.role
, action
);
364 m_visibleRoles
.insert(info
.role
, action
);
368 return rolesActionGroup
;
371 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
373 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
374 m_currentView
->setMode(mode
);
376 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
377 viewModeMenu
->setIcon(action
->icon());
380 void DolphinViewActionHandler::slotRename()
382 emit
actionBeingHandled();
383 m_currentView
->renameSelectedItems();
386 void DolphinViewActionHandler::slotTrashActivated()
388 emit
actionBeingHandled();
389 m_currentView
->trashSelectedItems();
392 void DolphinViewActionHandler::slotDeleteItems()
394 emit
actionBeingHandled();
395 m_currentView
->deleteSelectedItems();
398 void DolphinViewActionHandler::togglePreview(bool show
)
400 emit
actionBeingHandled();
401 m_currentView
->setPreviewsShown(show
);
404 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
407 // It is not enough to update the 'Show Preview' action, also
408 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
412 QString
DolphinViewActionHandler::currentViewModeActionName() const
414 switch (m_currentView
->mode()) {
415 case DolphinView::IconsView
:
416 return QStringLiteral("icons");
417 case DolphinView::DetailsView
:
418 return QStringLiteral("details");
419 case DolphinView::CompactView
:
420 return QStringLiteral("compact");
425 return QString(); // can't happen
428 KActionCollection
* DolphinViewActionHandler::actionCollection()
430 return m_actionCollection
;
433 void DolphinViewActionHandler::updateViewActions()
435 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
436 if (viewModeAction
) {
437 viewModeAction
->setChecked(true);
439 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
440 viewModeMenu
->setIcon(viewModeAction
->icon());
443 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
444 showPreviewAction
->setChecked(m_currentView
->previewsShown());
446 slotSortOrderChanged(m_currentView
->sortOrder());
447 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
448 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
449 slotGroupedSortingChanged(m_currentView
->groupedSorting());
450 slotSortRoleChanged(m_currentView
->sortRole());
451 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
453 // Updates the "show_hidden_files" action state and icon
454 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
457 void DolphinViewActionHandler::zoomIn()
459 const int level
= m_currentView
->zoomLevel();
460 m_currentView
->setZoomLevel(level
+ 1);
464 void DolphinViewActionHandler::zoomOut()
466 const int level
= m_currentView
->zoomLevel();
467 m_currentView
->setZoomLevel(level
- 1);
471 void DolphinViewActionHandler::zoomReset()
473 m_currentView
->resetZoomLevel();
477 void DolphinViewActionHandler::toggleSortFoldersFirst()
479 const bool sortFirst
= m_currentView
->sortFoldersFirst();
480 m_currentView
->setSortFoldersFirst(!sortFirst
);
483 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
485 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
486 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
487 const bool sortDescending
= (order
== Qt::DescendingOrder
);
488 descending
->setChecked(sortDescending
);
489 ascending
->setChecked(!sortDescending
);
492 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
494 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
497 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
499 emit
actionBeingHandled();
501 const QByteArray toggledRole
= action
->data().toByteArray();
503 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
505 const bool show
= action
->isChecked();
507 const int index
= roles
.indexOf(toggledRole
);
508 const bool containsInfo
= (index
>= 0);
509 if (show
&& !containsInfo
) {
510 roles
.append(toggledRole
);
511 m_currentView
->setVisibleRoles(roles
);
512 } else if (!show
&& containsInfo
) {
513 roles
.removeAt(index
);
514 m_currentView
->setVisibleRoles(roles
);
515 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
519 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
520 const QList
<QByteArray
>& previous
)
524 const QSet
<QByteArray
> checkedRoles
= current
.toSet();
525 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
526 while (it
.hasNext()) {
528 const QByteArray
& role
= it
.key();
529 KToggleAction
* action
= it
.value();
530 action
->setChecked(checkedRoles
.contains(role
));
534 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
536 m_currentView
->setGroupedSorting(grouped
);
539 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
541 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
542 showInGroupsAction
->setChecked(groupedSorting
);
545 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
547 emit
actionBeingHandled();
548 m_currentView
->setHiddenFilesShown(show
);
551 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
553 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
554 showHiddenFilesAction
->setChecked(shown
);
557 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
559 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
560 KProtocolManager::supportsMakeDir(currentView()->url()));
563 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
565 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
566 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
567 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
568 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
569 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
570 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
574 KToggleAction
* DolphinViewActionHandler::compactModeAction()
576 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
577 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
578 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
579 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
580 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
581 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
585 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
587 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
588 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
589 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
590 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
591 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
592 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
596 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
598 KToggleAction
* action
= m_sortByActions
.value(role
);
600 action
->setChecked(true);
602 if (!action
->icon().isNull()) {
603 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
604 sortByMenu
->setIcon(action
->icon());
608 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
609 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
611 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
612 descending
->setText(i18nc("Sort descending", "Z-A"));
613 ascending
->setText(i18nc("Sort ascending", "A-Z"));
614 } else if (role
== "size") {
615 descending
->setText(i18nc("Sort descending", "Largest First"));
616 ascending
->setText(i18nc("Sort ascending", "Smallest First"));
617 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
618 descending
->setText(i18nc("Sort descending", "Newest First"));
619 ascending
->setText(i18nc("Sort ascending", "Oldest First"));
620 } else if (role
== "rating") {
621 descending
->setText(i18nc("Sort descending", "Highest First"));
622 ascending
->setText(i18nc("Sort ascending", "Lowest First"));
624 descending
->setText(i18nc("Sort descending", "Descending"));
625 ascending
->setText(i18nc("Sort ascending", "Ascending"));
628 slotSortOrderChanged(m_currentView
->sortOrder());
631 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
635 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
637 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
640 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
642 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
646 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
648 // The radiobuttons of the "Sort By"-menu are split between the main-menu
649 // and several sub-menus. Because of this they don't have a common
650 // action-group that assures an exclusive toggle-state between the main-menu
651 // actions and the sub-menu-actions. If an action gets checked, it must
652 // be assured that all other actions get unchecked, except the ascending/
653 // descending actions
654 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
655 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
657 foreach (QAction
* subAction
, actionMenu
->menu()->actions()) {
658 subAction
->setChecked(false);
660 } else if (groupAction
->actionGroup()) {
661 groupAction
->setChecked(false);
664 action
->setChecked(true);
666 // Apply the activated sort-role to the view
667 const QByteArray role
= action
->data().toByteArray();
668 m_currentView
->setSortRole(role
);
671 void DolphinViewActionHandler::slotAdjustViewProperties()
673 emit
actionBeingHandled();
674 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
679 void DolphinViewActionHandler::slotDuplicate()
681 emit
actionBeingHandled();
682 m_currentView
->duplicateSelectedItems();
685 void DolphinViewActionHandler::slotProperties()
687 KPropertiesDialog
* dialog
= nullptr;
688 const KFileItemList list
= m_currentView
->selectedItems();
689 if (list
.isEmpty()) {
690 const QUrl url
= m_currentView
->url();
691 dialog
= new KPropertiesDialog(url
, m_currentView
);
693 dialog
= new KPropertiesDialog(list
, m_currentView
);
696 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
699 dialog
->activateWindow();
702 void DolphinViewActionHandler::slotCopyPath()
704 m_currentView
->copyPathToClipboard();