1 /***************************************************************************
2 * Copyright (C) 2008 by David Faure <faure@kde.org> *
3 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinviewactionhandler.h"
23 #include "dolphindebug.h"
24 #include "kitemviews/kfileitemmodel.h"
25 #include "settings/viewpropertiesdialog.h"
26 #include "views/zoomlevelinfo.h"
29 #include <Baloo/IndexerConfig>
31 #include <KActionCollection>
32 #include <KActionMenu>
33 #include <KLocalizedString>
34 #include <KNewFileMenu>
35 #include <KPropertiesDialog>
36 #include <KProtocolManager>
41 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
43 m_actionCollection(collection
),
44 m_currentView(nullptr),
48 Q_ASSERT(m_actionCollection
);
52 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
57 disconnect(m_currentView
, nullptr, this, nullptr);
62 connect(view
, &DolphinView::modeChanged
,
63 this, &DolphinViewActionHandler::updateViewActions
);
64 connect(view
, &DolphinView::previewsShownChanged
,
65 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
66 connect(view
, &DolphinView::sortOrderChanged
,
67 this, &DolphinViewActionHandler::slotSortOrderChanged
);
68 connect(view
, &DolphinView::sortFoldersFirstChanged
,
69 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
70 connect(view
, &DolphinView::visibleRolesChanged
,
71 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
72 connect(view
, &DolphinView::groupedSortingChanged
,
73 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
74 connect(view
, &DolphinView::hiddenFilesShownChanged
,
75 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
76 connect(view
, &DolphinView::sortRoleChanged
,
77 this, &DolphinViewActionHandler::slotSortRoleChanged
);
78 connect(view
, &DolphinView::zoomLevelChanged
,
79 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
80 connect(view
, &DolphinView::writeStateChanged
,
81 this, &DolphinViewActionHandler::slotWriteStateChanged
);
84 DolphinView
* DolphinViewActionHandler::currentView()
89 void DolphinViewActionHandler::createActions()
91 // This action doesn't appear in the GUI, it's for the shortcut only.
92 // KNewFileMenu takes care of the GUI stuff.
93 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
94 newDirAction
->setText(i18nc("@action", "Create Folder..."));
95 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
96 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
97 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
98 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
102 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
103 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
104 "items in your current selection.<nl/>Renaming multiple items "
105 "at once amounts to their new names differing only in a number."));
107 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
108 auto trashShortcuts
= trashAction
->shortcuts();
109 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
110 trashShortcuts
.append(QKeySequence::Delete
);
111 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
113 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
114 "items in your current selection to the <filename>Trash"
115 "</filename>.<nl/>The trash is a temporary storage where "
116 "items can be deleted from if disk space is needed."));
118 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
119 auto deleteShortcuts
= deleteAction
->shortcuts();
120 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
121 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
122 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
124 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
125 "the items in your current selection completely. They can "
126 "not be recovered by normal means."));
128 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
129 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
130 // can be used for deleting the file (#76016). It needs to be a separate action
131 // so that the Edit menu isn't affected.
132 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
133 // The descriptive text is just for the shortcuts editor.
134 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
135 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
136 deleteWithTrashShortcut
->setEnabled(false);
137 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
139 QAction
* duplicateAction
= m_actionCollection
->addAction(QStringLiteral("duplicate"));
140 duplicateAction
->setText(i18nc("@action:inmenu File", "Duplicate Here"));
141 duplicateAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
142 m_actionCollection
->setDefaultShortcut(duplicateAction
, Qt::CTRL
| Qt::Key_D
);
143 duplicateAction
->setEnabled(false);
144 connect(duplicateAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDuplicate
);
146 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
147 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
148 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
149 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
150 "This shows a complete list of properties of the currently "
151 "selected items in a new window.<nl/>If nothing is selected the "
152 "window will be about the currently viewed folder instead.<nl/>"
153 "You can configure advanced options there like managing "
154 "read- and write-permissions."));
155 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
156 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
157 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
160 KToggleAction
* iconsAction
= iconsModeAction();
161 KToggleAction
* compactAction
= compactModeAction();
162 KToggleAction
* detailsAction
= detailsModeAction();
164 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
165 "<para>This switches to a view mode that focuses on the folder "
166 "and file icons. This mode makes it easy to distinguish folders "
167 "from files and to detect items with distinctive <emphasis>"
168 "file types</emphasis>.</para><para> This mode is handy to "
169 "browse through pictures when the <interface>Preview"
170 "</interface> option is enabled.</para>"));
171 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
172 "<para>This switches to a compact view mode that lists the folders "
173 "and files in columns with the names beside the icons.</para><para>"
174 "This helps to keep the overview in folders with many items.</para>"));
175 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
176 "<para>This switches to a list view mode that focuses on folder "
177 "and file details.</para><para>Click on a detail in the column "
178 "header to sort the items by it. Click again to sort the other "
179 "way around. To select which details should be displayed click "
180 "the header with the right mouse button.</para><para>You can "
181 "view the contents of a folder without leaving the current "
182 "location by clicking to the left of it. This way you can view "
183 "the contents of multiple folders in the same list.</para>"));
185 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
186 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
187 viewModeActions
->addAction(iconsAction
);
188 viewModeActions
->addAction(compactAction
);
189 viewModeActions
->addAction(detailsAction
);
190 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
191 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
193 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
194 &DolphinViewActionHandler::zoomIn
,
196 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
198 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
199 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
200 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
201 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
202 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
203 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
+ Qt::Key_0
});
204 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
206 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
207 &DolphinViewActionHandler::zoomOut
,
209 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
211 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
212 showPreview
->setText(i18nc("@action:intoolbar", "Show Previews"));
213 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
214 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
215 "enabled, the icons are based on the actual file or folder "
216 "contents.<nl/>For example the icons of images become scaled "
217 "down versions of the images."));
218 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
219 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
221 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
222 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
223 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
226 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
228 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
229 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
230 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
231 sortByActionMenu
->setDelayed(false);
233 foreach (QAction
* action
, sortByActionGroup
->actions()) {
234 sortByActionMenu
->addAction(action
);
237 sortByActionMenu
->addSeparator();
239 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
240 group
->setExclusive(true);
242 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
243 ascendingAction
->setActionGroup(group
);
244 connect(ascendingAction
, &QAction::triggered
, this, [this] {
245 m_currentView
->setSortOrder(Qt::AscendingOrder
);
248 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
249 descendingAction
->setActionGroup(group
);
250 connect(descendingAction
, &QAction::triggered
, this, [this] {
251 m_currentView
->setSortOrder(Qt::DescendingOrder
);
254 sortByActionMenu
->addAction(ascendingAction
);
255 sortByActionMenu
->addAction(descendingAction
);
256 sortByActionMenu
->addSeparator();
257 sortByActionMenu
->addAction(sortFoldersFirst
);
259 // View -> Additional Information
260 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
262 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
263 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
264 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
265 visibleRolesMenu
->setDelayed(false);
267 foreach (QAction
* action
, visibleRolesGroup
->actions()) {
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
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
279 showHiddenFiles
->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
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
, {Qt::ALT
+ Qt::Key_Period
, Qt::CTRL
+ Qt::Key_H
, Qt::Key_F8
});
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 foreach (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 emit
actionBeingHandled();
386 m_currentView
->renameSelectedItems();
389 void DolphinViewActionHandler::slotTrashActivated()
391 emit
actionBeingHandled();
392 m_currentView
->trashSelectedItems();
395 void DolphinViewActionHandler::slotDeleteItems()
397 emit
actionBeingHandled();
398 m_currentView
->deleteSelectedItems();
401 void DolphinViewActionHandler::togglePreview(bool show
)
403 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 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 QSet
<QByteArray
> checkedRoles
= current
.toSet();
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 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
);
559 // #374508: don't overwrite custom icons.
560 const QString iconName
= showHiddenFilesAction
->icon().name();
561 if (!iconName
.isEmpty() && iconName
!= QLatin1String("view-visible") && iconName
!= QLatin1String("view-hidden")) {
565 showHiddenFilesAction
->setIcon(QIcon::fromTheme(shown
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
568 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
570 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
571 KProtocolManager::supportsMakeDir(currentView()->url()));
574 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
576 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
577 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
578 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
579 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
580 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
581 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
585 KToggleAction
* DolphinViewActionHandler::compactModeAction()
587 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
588 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
589 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
590 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
591 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
592 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
596 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
598 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
599 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
600 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
601 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
602 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
603 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
607 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
609 KToggleAction
* action
= m_sortByActions
.value(role
);
611 action
->setChecked(true);
613 if (!action
->icon().isNull()) {
614 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
615 sortByMenu
->setIcon(action
->icon());
619 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
620 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
622 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
623 descending
->setText(i18nc("Sort descending", "Z-A"));
624 ascending
->setText(i18nc("Sort ascending", "A-Z"));
625 } else if (role
== "size") {
626 descending
->setText(i18nc("Sort descending", "Largest first"));
627 ascending
->setText(i18nc("Sort ascending", "Smallest first"));
628 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
629 descending
->setText(i18nc("Sort descending", "Newest first"));
630 ascending
->setText(i18nc("Sort ascending", "Oldest first"));
631 } else if (role
== "rating") {
632 descending
->setText(i18nc("Sort descending", "Highest first"));
633 ascending
->setText(i18nc("Sort ascending", "Lowest first"));
635 descending
->setText(i18nc("Sort descending", "Descending"));
636 ascending
->setText(i18nc("Sort ascending", "Ascending"));
639 slotSortOrderChanged(m_currentView
->sortOrder());
642 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
646 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
648 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
651 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
653 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
657 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
659 // The radiobuttons of the "Sort By"-menu are split between the main-menu
660 // and several sub-menus. Because of this they don't have a common
661 // action-group that assures an exclusive toggle-state between the main-menu
662 // actions and the sub-menu-actions. If an action gets checked, it must
663 // be assured that all other actions get unchecked, except the ascending/
664 // descending actions
665 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
666 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
668 foreach (QAction
* subAction
, actionMenu
->menu()->actions()) {
669 subAction
->setChecked(false);
671 } else if (groupAction
->actionGroup()) {
672 groupAction
->setChecked(false);
675 action
->setChecked(true);
677 // Apply the activated sort-role to the view
678 const QByteArray role
= action
->data().toByteArray();
679 m_currentView
->setSortRole(role
);
682 void DolphinViewActionHandler::slotAdjustViewProperties()
684 emit
actionBeingHandled();
685 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
690 void DolphinViewActionHandler::slotDuplicate()
692 emit
actionBeingHandled();
693 m_currentView
->duplicateSelectedItems();
696 void DolphinViewActionHandler::slotProperties()
698 KPropertiesDialog
* dialog
= nullptr;
699 const KFileItemList list
= m_currentView
->selectedItems();
700 if (list
.isEmpty()) {
701 const QUrl url
= m_currentView
->url();
702 dialog
= new KPropertiesDialog(url
, m_currentView
);
704 dialog
= new KPropertiesDialog(list
, m_currentView
);
707 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
710 dialog
->activateWindow();