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>
40 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
42 m_actionCollection(collection
),
43 m_currentView(nullptr),
47 Q_ASSERT(m_actionCollection
);
51 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
56 disconnect(m_currentView
, nullptr, this, nullptr);
61 connect(view
, &DolphinView::modeChanged
,
62 this, &DolphinViewActionHandler::updateViewActions
);
63 connect(view
, &DolphinView::previewsShownChanged
,
64 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
65 connect(view
, &DolphinView::sortOrderChanged
,
66 this, &DolphinViewActionHandler::slotSortOrderChanged
);
67 connect(view
, &DolphinView::sortFoldersFirstChanged
,
68 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
69 connect(view
, &DolphinView::visibleRolesChanged
,
70 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
71 connect(view
, &DolphinView::groupedSortingChanged
,
72 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
73 connect(view
, &DolphinView::hiddenFilesShownChanged
,
74 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
75 connect(view
, &DolphinView::sortRoleChanged
,
76 this, &DolphinViewActionHandler::slotSortRoleChanged
);
77 connect(view
, &DolphinView::zoomLevelChanged
,
78 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
79 connect(view
, &DolphinView::writeStateChanged
,
80 this, &DolphinViewActionHandler::slotWriteStateChanged
);
83 DolphinView
* DolphinViewActionHandler::currentView()
88 void DolphinViewActionHandler::createActions()
90 // This action doesn't appear in the GUI, it's for the shortcut only.
91 // KNewFileMenu takes care of the GUI stuff.
92 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
93 newDirAction
->setText(i18nc("@action", "Create Folder..."));
94 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
95 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
96 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
97 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
101 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
102 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
103 "items in your current selection.<nl/>Renaming multiple items "
104 "at once amounts to their new names differing only in a number."));
106 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
107 auto trashShortcuts
= trashAction
->shortcuts();
108 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
109 trashShortcuts
.append(QKeySequence::Delete
);
110 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
112 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
113 "items in your current selection to the <filename>Trash"
114 "</filename>.<nl/>The trash is a temporary storage where "
115 "items can be deleted from if disk space is needed."));
117 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
118 auto deleteShortcuts
= deleteAction
->shortcuts();
119 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
120 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
121 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
123 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
124 "the items in your current selection completely. They can "
125 "not be recovered by normal means."));
127 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
128 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
129 // can be used for deleting the file (#76016). It needs to be a separate action
130 // so that the Edit menu isn't affected.
131 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
132 // The descriptive text is just for the shortcuts editor.
133 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
134 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
135 deleteWithTrashShortcut
->setEnabled(false);
136 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
138 QAction
* duplicateAction
= m_actionCollection
->addAction(QStringLiteral("duplicate"));
139 duplicateAction
->setText(i18nc("@action:inmenu File", "Duplicate Here"));
140 duplicateAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
141 m_actionCollection
->setDefaultShortcut(duplicateAction
, Qt::CTRL
| Qt::Key_D
);
142 duplicateAction
->setEnabled(false);
143 connect(duplicateAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDuplicate
);
145 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
146 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
147 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
148 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
149 "This shows a complete list of properties of the currently "
150 "selected items in a new window.<nl/>If nothing is selected the "
151 "window will be about the currently viewed folder instead.<nl/>"
152 "You can configure advanced options there like managing "
153 "read- and write-permissions."));
154 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
155 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
156 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
158 QAction
*copyPathAction
= m_actionCollection
->addAction( QStringLiteral("copy_location") );
159 copyPathAction
->setText(i18nc("@action:incontextmenu", "Copy location"));
160 copyPathAction
->setWhatsThis(i18nc("@info:whatsthis copy_location",
161 "This will copy the path of the first selected item into the clipboard."
164 copyPathAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
165 m_actionCollection
->setDefaultShortcuts(copyPathAction
, {Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_C
});
166 connect(copyPathAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotCopyPath
);
170 KToggleAction
* iconsAction
= iconsModeAction();
171 KToggleAction
* compactAction
= compactModeAction();
172 KToggleAction
* detailsAction
= detailsModeAction();
174 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
175 "<para>This switches to a view mode that focuses on the folder "
176 "and file icons. This mode makes it easy to distinguish folders "
177 "from files and to detect items with distinctive <emphasis>"
178 "file types</emphasis>.</para><para> This mode is handy to "
179 "browse through pictures when the <interface>Preview"
180 "</interface> option is enabled.</para>"));
181 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
182 "<para>This switches to a compact view mode that lists the folders "
183 "and files in columns with the names beside the icons.</para><para>"
184 "This helps to keep the overview in folders with many items.</para>"));
185 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
186 "<para>This switches to a list view mode that focuses on folder "
187 "and file details.</para><para>Click on a detail in the column "
188 "header to sort the items by it. Click again to sort the other "
189 "way around. To select which details should be displayed click "
190 "the header with the right mouse button.</para><para>You can "
191 "view the contents of a folder without leaving the current "
192 "location by clicking to the left of it. This way you can view "
193 "the contents of multiple folders in the same list.</para>"));
195 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
196 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
197 viewModeActions
->addAction(iconsAction
);
198 viewModeActions
->addAction(compactAction
);
199 viewModeActions
->addAction(detailsAction
);
200 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
201 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
203 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
204 &DolphinViewActionHandler::zoomIn
,
206 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
208 QAction
* zoomResetAction
= m_actionCollection
->addAction(QStringLiteral("view_zoom_reset"));
209 zoomResetAction
->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
210 zoomResetAction
->setToolTip(i18n("Zoom To Default"));
211 zoomResetAction
->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
212 zoomResetAction
->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
213 m_actionCollection
->setDefaultShortcuts(zoomResetAction
, {Qt::CTRL
+ Qt::Key_0
});
214 connect(zoomResetAction
, &QAction::triggered
, this, &DolphinViewActionHandler::zoomReset
);
216 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
217 &DolphinViewActionHandler::zoomOut
,
219 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
221 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
222 showPreview
->setText(i18nc("@action:intoolbar", "Show Previews"));
223 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
224 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
225 "enabled, the icons are based on the actual file or folder "
226 "contents.<nl/>For example the icons of images become scaled "
227 "down versions of the images."));
228 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
229 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
231 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
232 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
233 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
236 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
238 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
239 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
240 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
241 sortByActionMenu
->setDelayed(false);
243 foreach (QAction
* action
, sortByActionGroup
->actions()) {
244 sortByActionMenu
->addAction(action
);
247 sortByActionMenu
->addSeparator();
249 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
250 group
->setExclusive(true);
252 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
253 ascendingAction
->setActionGroup(group
);
254 connect(ascendingAction
, &QAction::triggered
, this, [this] {
255 m_currentView
->setSortOrder(Qt::AscendingOrder
);
258 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
259 descendingAction
->setActionGroup(group
);
260 connect(descendingAction
, &QAction::triggered
, this, [this] {
261 m_currentView
->setSortOrder(Qt::DescendingOrder
);
264 sortByActionMenu
->addAction(ascendingAction
);
265 sortByActionMenu
->addAction(descendingAction
);
266 sortByActionMenu
->addSeparator();
267 sortByActionMenu
->addAction(sortFoldersFirst
);
269 // View -> Additional Information
270 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
272 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
273 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Show Additional Information"));
274 visibleRolesMenu
->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
275 visibleRolesMenu
->setDelayed(false);
277 foreach (QAction
* action
, visibleRolesGroup
->actions()) {
278 visibleRolesMenu
->addAction(action
);
281 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
282 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
283 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
284 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
285 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
287 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
288 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
289 showHiddenFiles
->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
290 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
291 "this is enabled <emphasis>hidden</emphasis> files and folders "
292 "are visible. They will be displayed semi-transparent.</para>"
293 "<para>Hidden items only differ from other ones in that their "
294 "name starts with a \".\". In general there is no need for "
295 "users to access them which is why they are hidden.</para>"));
296 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, KStandardShortcut::showHideHiddenFiles());
297 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
299 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
300 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
301 adjustViewProps
->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
302 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
303 "in which all folder view properties can be adjusted."));
304 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
307 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
309 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
310 Q_ASSERT(isSortGroup
|| groupPrefix
== QLatin1String("show_"));
312 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
313 rolesActionGroup
->setExclusive(isSortGroup
);
315 connect(rolesActionGroup
, &QActionGroup::triggered
,
316 this, &DolphinViewActionHandler::slotSortTriggered
);
318 connect(rolesActionGroup
, &QActionGroup::triggered
,
319 this, &DolphinViewActionHandler::toggleVisibleRole
);
323 KActionMenu
* groupMenu
= nullptr;
324 QActionGroup
* groupMenuGroup
= nullptr;
326 bool indexingEnabled
= false;
328 Baloo::IndexerConfig config
;
329 indexingEnabled
= config
.fileIndexingEnabled();
332 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
333 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
334 if (!isSortGroup
&& info
.role
== "text") {
335 // It should not be possible to hide the "text" role
339 KToggleAction
* action
= nullptr;
340 const QString name
= groupPrefix
+ info
.role
;
341 if (info
.group
.isEmpty()) {
342 action
= m_actionCollection
->add
<KToggleAction
>(name
);
343 action
->setActionGroup(rolesActionGroup
);
345 if (!groupMenu
|| info
.group
!= groupName
) {
346 groupName
= info
.group
;
347 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
348 groupMenu
->setText(groupName
);
349 groupMenu
->setActionGroup(rolesActionGroup
);
351 groupMenuGroup
= new QActionGroup(groupMenu
);
352 groupMenuGroup
->setExclusive(isSortGroup
);
354 connect(groupMenuGroup
, &QActionGroup::triggered
,
355 this, &DolphinViewActionHandler::slotSortTriggered
);
357 connect(groupMenuGroup
, &QActionGroup::triggered
,
358 this, &DolphinViewActionHandler::toggleVisibleRole
);
362 action
= new KToggleAction(groupMenu
);
363 action
->setActionGroup(groupMenuGroup
);
364 groupMenu
->addAction(action
);
366 action
->setText(info
.translation
);
367 action
->setData(info
.role
);
369 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
370 (info
.requiresBaloo
) ||
371 (info
.requiresIndexer
&& indexingEnabled
);
372 action
->setEnabled(enable
);
375 m_sortByActions
.insert(info
.role
, action
);
377 m_visibleRoles
.insert(info
.role
, action
);
381 return rolesActionGroup
;
384 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
386 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
387 m_currentView
->setMode(mode
);
389 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
390 viewModeMenu
->setIcon(action
->icon());
393 void DolphinViewActionHandler::slotRename()
395 emit
actionBeingHandled();
396 m_currentView
->renameSelectedItems();
399 void DolphinViewActionHandler::slotTrashActivated()
401 emit
actionBeingHandled();
402 m_currentView
->trashSelectedItems();
405 void DolphinViewActionHandler::slotDeleteItems()
407 emit
actionBeingHandled();
408 m_currentView
->deleteSelectedItems();
411 void DolphinViewActionHandler::togglePreview(bool show
)
413 emit
actionBeingHandled();
414 m_currentView
->setPreviewsShown(show
);
417 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
420 // It is not enough to update the 'Show Preview' action, also
421 // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
425 QString
DolphinViewActionHandler::currentViewModeActionName() const
427 switch (m_currentView
->mode()) {
428 case DolphinView::IconsView
:
429 return QStringLiteral("icons");
430 case DolphinView::DetailsView
:
431 return QStringLiteral("details");
432 case DolphinView::CompactView
:
433 return QStringLiteral("compact");
438 return QString(); // can't happen
441 KActionCollection
* DolphinViewActionHandler::actionCollection()
443 return m_actionCollection
;
446 void DolphinViewActionHandler::updateViewActions()
448 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
449 if (viewModeAction
) {
450 viewModeAction
->setChecked(true);
452 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
453 viewModeMenu
->setIcon(viewModeAction
->icon());
456 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
457 showPreviewAction
->setChecked(m_currentView
->previewsShown());
459 slotSortOrderChanged(m_currentView
->sortOrder());
460 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
461 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
462 slotGroupedSortingChanged(m_currentView
->groupedSorting());
463 slotSortRoleChanged(m_currentView
->sortRole());
464 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
466 // Updates the "show_hidden_files" action state and icon
467 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
470 void DolphinViewActionHandler::zoomIn()
472 const int level
= m_currentView
->zoomLevel();
473 m_currentView
->setZoomLevel(level
+ 1);
477 void DolphinViewActionHandler::zoomOut()
479 const int level
= m_currentView
->zoomLevel();
480 m_currentView
->setZoomLevel(level
- 1);
484 void DolphinViewActionHandler::zoomReset()
486 m_currentView
->resetZoomLevel();
490 void DolphinViewActionHandler::toggleSortFoldersFirst()
492 const bool sortFirst
= m_currentView
->sortFoldersFirst();
493 m_currentView
->setSortFoldersFirst(!sortFirst
);
496 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
498 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
499 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
500 const bool sortDescending
= (order
== Qt::DescendingOrder
);
501 descending
->setChecked(sortDescending
);
502 ascending
->setChecked(!sortDescending
);
505 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
507 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
510 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
512 emit
actionBeingHandled();
514 const QByteArray toggledRole
= action
->data().toByteArray();
516 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
518 const bool show
= action
->isChecked();
520 const int index
= roles
.indexOf(toggledRole
);
521 const bool containsInfo
= (index
>= 0);
522 if (show
&& !containsInfo
) {
523 roles
.append(toggledRole
);
524 m_currentView
->setVisibleRoles(roles
);
525 } else if (!show
&& containsInfo
) {
526 roles
.removeAt(index
);
527 m_currentView
->setVisibleRoles(roles
);
528 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
532 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
533 const QList
<QByteArray
>& previous
)
537 const QSet
<QByteArray
> checkedRoles
= current
.toSet();
538 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
539 while (it
.hasNext()) {
541 const QByteArray
& role
= it
.key();
542 KToggleAction
* action
= it
.value();
543 action
->setChecked(checkedRoles
.contains(role
));
547 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
549 m_currentView
->setGroupedSorting(grouped
);
552 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
554 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
555 showInGroupsAction
->setChecked(groupedSorting
);
558 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
560 emit
actionBeingHandled();
561 m_currentView
->setHiddenFilesShown(show
);
564 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
566 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
567 showHiddenFilesAction
->setChecked(shown
);
569 // #374508: don't overwrite custom icons.
570 const QString iconName
= showHiddenFilesAction
->icon().name();
571 if (!iconName
.isEmpty() && iconName
!= QLatin1String("view-visible") && iconName
!= QLatin1String("view-hidden")) {
575 showHiddenFilesAction
->setIcon(QIcon::fromTheme(shown
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
578 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
580 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
581 KProtocolManager::supportsMakeDir(currentView()->url()));
584 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
586 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
587 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
588 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
589 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
590 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
591 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
595 KToggleAction
* DolphinViewActionHandler::compactModeAction()
597 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
598 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
599 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
600 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
601 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
602 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
606 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
608 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
609 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
610 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
611 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
612 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
613 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
617 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
619 KToggleAction
* action
= m_sortByActions
.value(role
);
621 action
->setChecked(true);
623 if (!action
->icon().isNull()) {
624 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
625 sortByMenu
->setIcon(action
->icon());
629 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
630 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
632 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
633 descending
->setText(i18nc("Sort descending", "Z-A"));
634 ascending
->setText(i18nc("Sort ascending", "A-Z"));
635 } else if (role
== "size") {
636 descending
->setText(i18nc("Sort descending", "Largest first"));
637 ascending
->setText(i18nc("Sort ascending", "Smallest first"));
638 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
639 descending
->setText(i18nc("Sort descending", "Newest first"));
640 ascending
->setText(i18nc("Sort ascending", "Oldest first"));
641 } else if (role
== "rating") {
642 descending
->setText(i18nc("Sort descending", "Highest first"));
643 ascending
->setText(i18nc("Sort ascending", "Lowest first"));
645 descending
->setText(i18nc("Sort descending", "Descending"));
646 ascending
->setText(i18nc("Sort ascending", "Ascending"));
649 slotSortOrderChanged(m_currentView
->sortOrder());
652 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
656 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
658 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
661 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
663 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
667 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
669 // The radiobuttons of the "Sort By"-menu are split between the main-menu
670 // and several sub-menus. Because of this they don't have a common
671 // action-group that assures an exclusive toggle-state between the main-menu
672 // actions and the sub-menu-actions. If an action gets checked, it must
673 // be assured that all other actions get unchecked, except the ascending/
674 // descending actions
675 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
676 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
678 foreach (QAction
* subAction
, actionMenu
->menu()->actions()) {
679 subAction
->setChecked(false);
681 } else if (groupAction
->actionGroup()) {
682 groupAction
->setChecked(false);
685 action
->setChecked(true);
687 // Apply the activated sort-role to the view
688 const QByteArray role
= action
->data().toByteArray();
689 m_currentView
->setSortRole(role
);
692 void DolphinViewActionHandler::slotAdjustViewProperties()
694 emit
actionBeingHandled();
695 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
700 void DolphinViewActionHandler::slotDuplicate()
702 emit
actionBeingHandled();
703 m_currentView
->duplicateSelectedItems();
706 void DolphinViewActionHandler::slotProperties()
708 KPropertiesDialog
* dialog
= nullptr;
709 const KFileItemList list
= m_currentView
->selectedItems();
710 if (list
.isEmpty()) {
711 const QUrl url
= m_currentView
->url();
712 dialog
= new KPropertiesDialog(url
, m_currentView
);
714 dialog
= new KPropertiesDialog(list
, m_currentView
);
717 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
720 dialog
->activateWindow();
723 void DolphinViewActionHandler::slotCopyPath()
725 m_currentView
->copyPathToClipboard();