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::ALT
| 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 const auto sortByActionGroupActions
= sortByActionGroup
->actions();
231 for (QAction
* action
: sortByActionGroupActions
) {
232 sortByActionMenu
->addAction(action
);
235 sortByActionMenu
->addSeparator();
237 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
238 group
->setExclusive(true);
240 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
241 ascendingAction
->setActionGroup(group
);
242 connect(ascendingAction
, &QAction::triggered
, this, [this] {
243 m_currentView
->setSortOrder(Qt::AscendingOrder
);
246 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
247 descendingAction
->setActionGroup(group
);
248 connect(descendingAction
, &QAction::triggered
, this, [this] {
249 m_currentView
->setSortOrder(Qt::DescendingOrder
);
252 sortByActionMenu
->addAction(ascendingAction
);
253 sortByActionMenu
->addAction(descendingAction
);
254 sortByActionMenu
->addSeparator();
255 sortByActionMenu
->addAction(sortFoldersFirst
);
257 // View -> Additional Information
258 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
260 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
261 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
262 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
263 visibleRolesMenu
->setDelayed(false);
265 const auto visibleRolesGroupActions
= visibleRolesGroup
->actions();
266 for (QAction
* action
: visibleRolesGroupActions
) {
267 visibleRolesMenu
->addAction(action
);
270 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
271 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
272 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
273 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
274 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
276 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
277 showHiddenFiles
->setIcon(QIcon::fromTheme(QStringLiteral("view-visible")));
278 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
279 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
280 "this is enabled <emphasis>hidden</emphasis> files and folders "
281 "are visible. They will be displayed semi-transparent.</para>"
282 "<para>Hidden items only differ from other ones in that their "
283 "name starts with a \".\". In general there is no need for "
284 "users to access them which is why they are hidden.</para>"));
285 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, KStandardShortcut::showHideHiddenFiles());
286 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
288 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
289 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
290 adjustViewProps
->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
291 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
292 "in which all folder view properties can be adjusted."));
293 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
296 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
298 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
299 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
301 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
302 rolesActionGroup
->setExclusive(isSortGroup
);
304 connect(rolesActionGroup
, &QActionGroup::triggered
,
305 this, &DolphinViewActionHandler::slotSortTriggered
);
307 connect(rolesActionGroup
, &QActionGroup::triggered
,
308 this, &DolphinViewActionHandler::toggleVisibleRole
);
312 KActionMenu
* groupMenu
= nullptr;
313 QActionGroup
* groupMenuGroup
= nullptr;
315 bool indexingEnabled
= false;
317 Baloo::IndexerConfig config
;
318 indexingEnabled
= config
.fileIndexingEnabled();
321 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
322 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
323 if (!isSortGroup
&& info
.role
== "text") {
324 // It should not be possible to hide the "text" role
328 KToggleAction
* action
= nullptr;
329 const QString name
= groupPrefix
+ info
.role
;
330 if (info
.group
.isEmpty()) {
331 action
= m_actionCollection
->add
<KToggleAction
>(name
);
332 action
->setActionGroup(rolesActionGroup
);
334 if (!groupMenu
|| info
.group
!= groupName
) {
335 groupName
= info
.group
;
336 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
337 groupMenu
->setText(groupName
);
338 groupMenu
->setActionGroup(rolesActionGroup
);
340 groupMenuGroup
= new QActionGroup(groupMenu
);
341 groupMenuGroup
->setExclusive(isSortGroup
);
343 connect(groupMenuGroup
, &QActionGroup::triggered
,
344 this, &DolphinViewActionHandler::slotSortTriggered
);
346 connect(groupMenuGroup
, &QActionGroup::triggered
,
347 this, &DolphinViewActionHandler::toggleVisibleRole
);
351 action
= new KToggleAction(groupMenu
);
352 action
->setActionGroup(groupMenuGroup
);
353 groupMenu
->addAction(action
);
355 action
->setText(info
.translation
);
356 action
->setData(info
.role
);
358 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
359 (info
.requiresBaloo
) ||
360 (info
.requiresIndexer
&& indexingEnabled
);
361 action
->setEnabled(enable
);
364 m_sortByActions
.insert(info
.role
, action
);
366 m_visibleRoles
.insert(info
.role
, action
);
370 return rolesActionGroup
;
373 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
375 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
376 m_currentView
->setMode(mode
);
378 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
379 viewModeMenu
->setIcon(action
->icon());
382 void DolphinViewActionHandler::slotRename()
384 Q_EMIT
actionBeingHandled();
385 m_currentView
->renameSelectedItems();
388 void DolphinViewActionHandler::slotTrashActivated()
390 Q_EMIT
actionBeingHandled();
391 m_currentView
->trashSelectedItems();
394 void DolphinViewActionHandler::slotDeleteItems()
396 Q_EMIT
actionBeingHandled();
397 m_currentView
->deleteSelectedItems();
400 void DolphinViewActionHandler::togglePreview(bool show
)
402 Q_EMIT
actionBeingHandled();
403 m_currentView
->setPreviewsShown(show
);
406 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
409 // It is not enough to update the 'Show Preview' action, also
410 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
414 QString
DolphinViewActionHandler::currentViewModeActionName() const
416 switch (m_currentView
->mode()) {
417 case DolphinView::IconsView
:
418 return QStringLiteral("icons");
419 case DolphinView::DetailsView
:
420 return QStringLiteral("details");
421 case DolphinView::CompactView
:
422 return QStringLiteral("compact");
427 return QString(); // can't happen
430 KActionCollection
* DolphinViewActionHandler::actionCollection()
432 return m_actionCollection
;
435 void DolphinViewActionHandler::updateViewActions()
437 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
438 if (viewModeAction
) {
439 viewModeAction
->setChecked(true);
441 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
442 viewModeMenu
->setIcon(viewModeAction
->icon());
445 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
446 showPreviewAction
->setChecked(m_currentView
->previewsShown());
448 slotSortOrderChanged(m_currentView
->sortOrder());
449 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
450 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
451 slotGroupedSortingChanged(m_currentView
->groupedSorting());
452 slotSortRoleChanged(m_currentView
->sortRole());
453 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
455 // Updates the "show_hidden_files" action state and icon
456 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
459 void DolphinViewActionHandler::zoomIn()
461 const int level
= m_currentView
->zoomLevel();
462 m_currentView
->setZoomLevel(level
+ 1);
466 void DolphinViewActionHandler::zoomOut()
468 const int level
= m_currentView
->zoomLevel();
469 m_currentView
->setZoomLevel(level
- 1);
473 void DolphinViewActionHandler::zoomReset()
475 m_currentView
->resetZoomLevel();
479 void DolphinViewActionHandler::toggleSortFoldersFirst()
481 const bool sortFirst
= m_currentView
->sortFoldersFirst();
482 m_currentView
->setSortFoldersFirst(!sortFirst
);
485 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
487 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
488 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
489 const bool sortDescending
= (order
== Qt::DescendingOrder
);
490 descending
->setChecked(sortDescending
);
491 ascending
->setChecked(!sortDescending
);
494 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
496 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
499 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
501 Q_EMIT
actionBeingHandled();
503 const QByteArray toggledRole
= action
->data().toByteArray();
505 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
507 const bool show
= action
->isChecked();
509 const int index
= roles
.indexOf(toggledRole
);
510 const bool containsInfo
= (index
>= 0);
511 if (show
&& !containsInfo
) {
512 roles
.append(toggledRole
);
513 m_currentView
->setVisibleRoles(roles
);
514 } else if (!show
&& containsInfo
) {
515 roles
.removeAt(index
);
516 m_currentView
->setVisibleRoles(roles
);
517 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
521 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
522 const QList
<QByteArray
>& previous
)
526 const auto checkedRoles
= QSet
<QByteArray
>(current
.constBegin(), current
.constEnd());
527 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
528 while (it
.hasNext()) {
530 const QByteArray
& role
= it
.key();
531 KToggleAction
* action
= it
.value();
532 action
->setChecked(checkedRoles
.contains(role
));
536 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
538 m_currentView
->setGroupedSorting(grouped
);
541 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
543 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
544 showInGroupsAction
->setChecked(groupedSorting
);
547 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
549 Q_EMIT
actionBeingHandled();
550 m_currentView
->setHiddenFilesShown(show
);
553 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
555 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
556 showHiddenFilesAction
->setChecked(shown
);
559 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
561 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
562 KProtocolManager::supportsMakeDir(currentView()->url()));
565 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
567 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
568 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
569 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
570 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
571 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
572 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
576 KToggleAction
* DolphinViewActionHandler::compactModeAction()
578 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
579 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
580 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
581 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
582 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
583 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
587 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
589 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
590 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
591 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
592 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
593 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
594 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
598 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
600 KToggleAction
* action
= m_sortByActions
.value(role
);
602 action
->setChecked(true);
604 if (!action
->icon().isNull()) {
605 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
606 sortByMenu
->setIcon(action
->icon());
610 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
611 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
613 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
614 descending
->setText(i18nc("Sort descending", "Z-A"));
615 ascending
->setText(i18nc("Sort ascending", "A-Z"));
616 } else if (role
== "size") {
617 descending
->setText(i18nc("Sort descending", "Largest First"));
618 ascending
->setText(i18nc("Sort ascending", "Smallest First"));
619 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
620 descending
->setText(i18nc("Sort descending", "Newest First"));
621 ascending
->setText(i18nc("Sort ascending", "Oldest First"));
622 } else if (role
== "rating") {
623 descending
->setText(i18nc("Sort descending", "Highest First"));
624 ascending
->setText(i18nc("Sort ascending", "Lowest First"));
626 descending
->setText(i18nc("Sort descending", "Descending"));
627 ascending
->setText(i18nc("Sort ascending", "Ascending"));
630 slotSortOrderChanged(m_currentView
->sortOrder());
633 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
637 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
639 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
642 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
644 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
648 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
650 // The radiobuttons of the "Sort By"-menu are split between the main-menu
651 // and several sub-menus. Because of this they don't have a common
652 // action-group that assures an exclusive toggle-state between the main-menu
653 // actions and the sub-menu-actions. If an action gets checked, it must
654 // be assured that all other actions get unchecked, except the ascending/
655 // descending actions
656 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
657 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
659 const auto actions
= actionMenu
->menu()->actions();
660 for (QAction
* subAction
: actions
) {
661 subAction
->setChecked(false);
663 } else if (groupAction
->actionGroup()) {
664 groupAction
->setChecked(false);
667 action
->setChecked(true);
669 // Apply the activated sort-role to the view
670 const QByteArray role
= action
->data().toByteArray();
671 m_currentView
->setSortRole(role
);
674 void DolphinViewActionHandler::slotAdjustViewProperties()
676 Q_EMIT
actionBeingHandled();
677 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
682 void DolphinViewActionHandler::slotDuplicate()
684 Q_EMIT
actionBeingHandled();
685 m_currentView
->duplicateSelectedItems();
688 void DolphinViewActionHandler::slotProperties()
690 KPropertiesDialog
* dialog
= nullptr;
691 const KFileItemList list
= m_currentView
->selectedItems();
692 if (list
.isEmpty()) {
693 const QUrl url
= m_currentView
->url();
694 dialog
= new KPropertiesDialog(url
, m_currentView
);
696 dialog
= new KPropertiesDialog(list
, m_currentView
);
699 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
702 dialog
->activateWindow();
705 void DolphinViewActionHandler::slotCopyPath()
707 m_currentView
->copyPathToClipboard();