]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinviewactionhandler.cpp
f4fbddf60cc34f5abbee3fcdcc7450ff9e56c9e7
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by David Faure <faure@kde.org> *
3 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #include "dolphinviewactionhandler.h"
22
23 #include "dolphindebug.h"
24 #include "kitemviews/kfileitemmodel.h"
25 #include "settings/viewpropertiesdialog.h"
26 #include "views/zoomlevelinfo.h"
27
28 #ifdef HAVE_BALOO
29 #include <Baloo/IndexerConfig>
30 #endif
31 #include <KActionCollection>
32 #include <KActionMenu>
33 #include <KLocalizedString>
34 #include <KNewFileMenu>
35 #include <KPropertiesDialog>
36 #include <KProtocolManager>
37
38 #include <QMenu>
39 #include <QPointer>
40
41 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
42 QObject(parent),
43 m_actionCollection(collection),
44 m_currentView(nullptr),
45 m_sortByActions(),
46 m_visibleRoles()
47 {
48 Q_ASSERT(m_actionCollection);
49 createActions();
50 }
51
52 void DolphinViewActionHandler::setCurrentView(DolphinView* view)
53 {
54 Q_ASSERT(view);
55
56 if (m_currentView) {
57 disconnect(m_currentView, nullptr, this, nullptr);
58 }
59
60 m_currentView = view;
61
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);
82 }
83
84 DolphinView* DolphinViewActionHandler::currentView()
85 {
86 return m_currentView;
87 }
88
89 void DolphinViewActionHandler::createActions()
90 {
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);
99
100 // File menu
101
102 KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename, m_actionCollection);
103
104 auto trashAction = KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated, m_actionCollection);
105 auto trashShortcuts = trashAction->shortcuts();
106 if (!trashShortcuts.contains(QKeySequence::Delete)) {
107 trashShortcuts.append(QKeySequence::Delete);
108 m_actionCollection->setDefaultShortcuts(trashAction, trashShortcuts);
109 }
110
111 auto deleteAction = KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection);
112 auto deleteShortcuts = deleteAction->shortcuts();
113 if (!deleteShortcuts.contains(Qt::SHIFT | Qt::Key_Delete)) {
114 deleteShortcuts.append(Qt::SHIFT | Qt::Key_Delete);
115 m_actionCollection->setDefaultShortcuts(deleteAction, deleteShortcuts);
116 }
117
118 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
119 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
120 // can be used for deleting the file (#76016). It needs to be a separate action
121 // so that the Edit menu isn't affected.
122 QAction* deleteWithTrashShortcut = m_actionCollection->addAction(QStringLiteral("delete_shortcut"));
123 // The descriptive text is just for the shortcuts editor.
124 deleteWithTrashShortcut->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
125 m_actionCollection->setDefaultShortcuts(deleteWithTrashShortcut, KStandardShortcut::moveToTrash());
126 deleteWithTrashShortcut->setEnabled(false);
127 connect(deleteWithTrashShortcut, &QAction::triggered, this, &DolphinViewActionHandler::slotDeleteItems);
128
129 QAction *propertiesAction = m_actionCollection->addAction( QStringLiteral("properties") );
130 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
131 propertiesAction->setText( i18nc("@action:inmenu File", "Properties") );
132 propertiesAction->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
133 m_actionCollection->setDefaultShortcuts(propertiesAction, {Qt::ALT + Qt::Key_Return, Qt::ALT + Qt::Key_Enter});
134 connect(propertiesAction, &QAction::triggered, this, &DolphinViewActionHandler::slotProperties);
135
136 // View menu
137 KToggleAction* iconsAction = iconsModeAction();
138 KToggleAction* compactAction = compactModeAction();
139 KToggleAction* detailsAction = detailsModeAction();
140
141 KSelectAction* viewModeActions = m_actionCollection->add<KSelectAction>(QStringLiteral("view_mode"));
142 viewModeActions->setText(i18nc("@action:intoolbar", "View Mode"));
143 viewModeActions->addAction(iconsAction);
144 viewModeActions->addAction(compactAction);
145 viewModeActions->addAction(detailsAction);
146 viewModeActions->setToolBarMode(KSelectAction::MenuMode);
147 connect(viewModeActions, static_cast<void(KSelectAction::*)(QAction*)>(&KSelectAction::triggered), this, &DolphinViewActionHandler::slotViewModeActionTriggered);
148
149 KStandardAction::zoomIn(this,
150 &DolphinViewActionHandler::zoomIn,
151 m_actionCollection);
152
153 KStandardAction::zoomOut(this,
154 &DolphinViewActionHandler::zoomOut,
155 m_actionCollection);
156
157 KToggleAction* showPreview = m_actionCollection->add<KToggleAction>(QStringLiteral("show_preview"));
158 showPreview->setText(i18nc("@action:intoolbar", "Preview"));
159 showPreview->setToolTip(i18nc("@info", "Show preview of files and folders"));
160 showPreview->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
161 connect(showPreview, &KToggleAction::triggered, this, &DolphinViewActionHandler::togglePreview);
162
163 KToggleAction* sortDescending = m_actionCollection->add<KToggleAction>(QStringLiteral("descending"));
164 sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
165 connect(sortDescending, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortOrder);
166
167 KToggleAction* sortFoldersFirst = m_actionCollection->add<KToggleAction>(QStringLiteral("folders_first"));
168 sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First"));
169 connect(sortFoldersFirst, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortFoldersFirst);
170
171 // View -> Sort By
172 QActionGroup* sortByActionGroup = createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
173
174 KActionMenu* sortByActionMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("sort"));
175 sortByActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
176 sortByActionMenu->setText(i18nc("@action:inmenu View", "Sort By"));
177 sortByActionMenu->setDelayed(false);
178
179 foreach (QAction* action, sortByActionGroup->actions()) {
180 sortByActionMenu->addAction(action);
181 }
182 sortByActionMenu->addSeparator();
183 sortByActionMenu->addAction(sortDescending);
184 sortByActionMenu->addAction(sortFoldersFirst);
185
186 // View -> Additional Information
187 QActionGroup* visibleRolesGroup = createFileItemRolesActionGroup(QStringLiteral("show_"));
188
189 KActionMenu* visibleRolesMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("additional_info"));
190 visibleRolesMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
191 visibleRolesMenu->setDelayed(false);
192
193 foreach (QAction* action, visibleRolesGroup->actions()) {
194 visibleRolesMenu->addAction(action);
195 }
196
197 KToggleAction* showInGroups = m_actionCollection->add<KToggleAction>(QStringLiteral("show_in_groups"));
198 showInGroups->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
199 showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups"));
200 connect(showInGroups, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleGroupedSorting);
201
202 KToggleAction* showHiddenFiles = m_actionCollection->add<KToggleAction>(QStringLiteral("show_hidden_files"));
203 showHiddenFiles->setText(i18nc("@action:inmenu View", "Hidden Files"));
204 showHiddenFiles->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
205 m_actionCollection->setDefaultShortcuts(showHiddenFiles, {Qt::ALT + Qt::Key_Period, Qt::CTRL + Qt::Key_H, Qt::Key_F8});
206 connect(showHiddenFiles, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleShowHiddenFiles);
207
208 QAction* adjustViewProps = m_actionCollection->addAction(QStringLiteral("view_properties"));
209 adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
210 connect(adjustViewProps, &QAction::triggered, this, &DolphinViewActionHandler::slotAdjustViewProperties);
211 }
212
213 QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString& groupPrefix)
214 {
215 const bool isSortGroup = (groupPrefix == QLatin1String("sort_by_"));
216 Q_ASSERT(isSortGroup || (!isSortGroup && groupPrefix == QLatin1String("show_")));
217
218 QActionGroup* rolesActionGroup = new QActionGroup(m_actionCollection);
219 rolesActionGroup->setExclusive(isSortGroup);
220 if (isSortGroup) {
221 connect(rolesActionGroup, &QActionGroup::triggered,
222 this, &DolphinViewActionHandler::slotSortTriggered);
223 } else {
224 connect(rolesActionGroup, &QActionGroup::triggered,
225 this, &DolphinViewActionHandler::toggleVisibleRole);
226 }
227
228 QString groupName;
229 KActionMenu* groupMenu = nullptr;
230 QActionGroup* groupMenuGroup = nullptr;
231
232 bool indexingEnabled = false;
233 #ifdef HAVE_BALOO
234 Baloo::IndexerConfig config;
235 indexingEnabled = config.fileIndexingEnabled();
236 #endif
237
238 const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
239 foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
240 if (!isSortGroup && info.role == "text") {
241 // It should not be possible to hide the "text" role
242 continue;
243 }
244
245 KToggleAction* action = nullptr;
246 const QString name = groupPrefix + info.role;
247 if (info.group.isEmpty()) {
248 action = m_actionCollection->add<KToggleAction>(name);
249 action->setActionGroup(rolesActionGroup);
250 } else {
251 if (!groupMenu || info.group != groupName) {
252 groupName = info.group;
253 groupMenu = m_actionCollection->add<KActionMenu>(groupName);
254 groupMenu->setText(groupName);
255 groupMenu->setActionGroup(rolesActionGroup);
256
257 groupMenuGroup = new QActionGroup(groupMenu);
258 groupMenuGroup->setExclusive(isSortGroup);
259 if (isSortGroup) {
260 connect(groupMenuGroup, &QActionGroup::triggered,
261 this, &DolphinViewActionHandler::slotSortTriggered);
262 } else {
263 connect(groupMenuGroup, &QActionGroup::triggered,
264 this, &DolphinViewActionHandler::toggleVisibleRole);
265 }
266 }
267
268 action = new KToggleAction(groupMenu);
269 action->setActionGroup(groupMenuGroup);
270 groupMenu->addAction(action);
271 }
272 action->setText(info.translation);
273 action->setData(info.role);
274
275 const bool enable = (!info.requiresBaloo && !info.requiresIndexer) ||
276 (info.requiresBaloo) ||
277 (info.requiresIndexer && indexingEnabled);
278 action->setEnabled(enable);
279
280 if (isSortGroup) {
281 m_sortByActions.insert(info.role, action);
282 } else {
283 m_visibleRoles.insert(info.role, action);
284 }
285 }
286
287 return rolesActionGroup;
288 }
289
290 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
291 {
292 const DolphinView::Mode mode = action->data().value<DolphinView::Mode>();
293 m_currentView->setMode(mode);
294
295 QAction* viewModeMenu = m_actionCollection->action(QStringLiteral("view_mode"));
296 viewModeMenu->setIcon(action->icon());
297 }
298
299 void DolphinViewActionHandler::slotRename()
300 {
301 emit actionBeingHandled();
302 m_currentView->renameSelectedItems();
303 }
304
305 void DolphinViewActionHandler::slotTrashActivated()
306 {
307 emit actionBeingHandled();
308 m_currentView->trashSelectedItems();
309 }
310
311 void DolphinViewActionHandler::slotDeleteItems()
312 {
313 emit actionBeingHandled();
314 m_currentView->deleteSelectedItems();
315 }
316
317 void DolphinViewActionHandler::togglePreview(bool show)
318 {
319 emit actionBeingHandled();
320 m_currentView->setPreviewsShown(show);
321 }
322
323 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown)
324 {
325 Q_UNUSED(shown);
326 // It is not enough to update the 'Show Preview' action, also
327 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
328 updateViewActions();
329 }
330
331 QString DolphinViewActionHandler::currentViewModeActionName() const
332 {
333 switch (m_currentView->mode()) {
334 case DolphinView::IconsView:
335 return QStringLiteral("icons");
336 case DolphinView::DetailsView:
337 return QStringLiteral("details");
338 case DolphinView::CompactView:
339 return QStringLiteral("compact");
340 default:
341 Q_ASSERT(false);
342 break;
343 }
344 return QString(); // can't happen
345 }
346
347 KActionCollection* DolphinViewActionHandler::actionCollection()
348 {
349 return m_actionCollection;
350 }
351
352 void DolphinViewActionHandler::updateViewActions()
353 {
354 QAction* viewModeAction = m_actionCollection->action(currentViewModeActionName());
355 if (viewModeAction) {
356 viewModeAction->setChecked(true);
357
358 QAction* viewModeMenu = m_actionCollection->action(QStringLiteral("view_mode"));
359 viewModeMenu->setIcon(viewModeAction->icon());
360 }
361
362 QAction* showPreviewAction = m_actionCollection->action(QStringLiteral("show_preview"));
363 showPreviewAction->setChecked(m_currentView->previewsShown());
364
365 slotSortOrderChanged(m_currentView->sortOrder());
366 slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst());
367 slotVisibleRolesChanged(m_currentView->visibleRoles(), QList<QByteArray>());
368 slotGroupedSortingChanged(m_currentView->groupedSorting());
369 slotSortRoleChanged(m_currentView->sortRole());
370 slotZoomLevelChanged(m_currentView->zoomLevel(), -1);
371
372 // Updates the "show_hidden_files" action state and icon
373 slotHiddenFilesShownChanged(m_currentView->hiddenFilesShown());
374 }
375
376 void DolphinViewActionHandler::zoomIn()
377 {
378 const int level = m_currentView->zoomLevel();
379 m_currentView->setZoomLevel(level + 1);
380 updateViewActions();
381 }
382
383 void DolphinViewActionHandler::zoomOut()
384 {
385 const int level = m_currentView->zoomLevel();
386 m_currentView->setZoomLevel(level - 1);
387 updateViewActions();
388 }
389
390 void DolphinViewActionHandler::toggleSortOrder()
391 {
392 const Qt::SortOrder order = (m_currentView->sortOrder() == Qt::AscendingOrder) ?
393 Qt::DescendingOrder :
394 Qt::AscendingOrder;
395 m_currentView->setSortOrder(order);
396 }
397
398 void DolphinViewActionHandler::toggleSortFoldersFirst()
399 {
400 const bool sortFirst = m_currentView->sortFoldersFirst();
401 m_currentView->setSortFoldersFirst(!sortFirst);
402 }
403
404 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order)
405 {
406 QAction* descending = m_actionCollection->action(QStringLiteral("descending"));
407 const bool sortDescending = (order == Qt::DescendingOrder);
408 descending->setChecked(sortDescending);
409 }
410
411 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
412 {
413 m_actionCollection->action(QStringLiteral("folders_first"))->setChecked(foldersFirst);
414 }
415
416 void DolphinViewActionHandler::toggleVisibleRole(QAction* action)
417 {
418 emit actionBeingHandled();
419
420 const QByteArray toggledRole = action->data().toByteArray();
421
422 QList<QByteArray> roles = m_currentView->visibleRoles();
423
424 const bool show = action->isChecked();
425
426 const int index = roles.indexOf(toggledRole);
427 const bool containsInfo = (index >= 0);
428 if (show && !containsInfo) {
429 roles.append(toggledRole);
430 m_currentView->setVisibleRoles(roles);
431 } else if (!show && containsInfo) {
432 roles.removeAt(index);
433 m_currentView->setVisibleRoles(roles);
434 Q_ASSERT(roles.indexOf(toggledRole) < 0);
435 }
436 }
437
438 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList<QByteArray>& current,
439 const QList<QByteArray>& previous)
440 {
441 Q_UNUSED(previous);
442
443 const QSet<QByteArray> checkedRoles = current.toSet();
444 QHashIterator<QByteArray, KToggleAction*> it(m_visibleRoles);
445 while (it.hasNext()) {
446 it.next();
447 const QByteArray& role = it.key();
448 KToggleAction* action = it.value();
449 action->setChecked(checkedRoles.contains(role));
450 }
451 }
452
453 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped)
454 {
455 m_currentView->setGroupedSorting(grouped);
456 }
457
458 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting)
459 {
460 QAction* showInGroupsAction = m_actionCollection->action(QStringLiteral("show_in_groups"));
461 showInGroupsAction->setChecked(groupedSorting);
462 }
463
464 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show)
465 {
466 emit actionBeingHandled();
467 m_currentView->setHiddenFilesShown(show);
468 }
469
470 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
471 {
472 QAction* showHiddenFilesAction = m_actionCollection->action(QStringLiteral("show_hidden_files"));
473 showHiddenFilesAction->setChecked(shown);
474
475 // #374508: don't overwrite custom icons.
476 const QString iconName = showHiddenFilesAction->icon().name();
477 if (!iconName.isEmpty() && iconName != QLatin1String("visibility") && iconName != QLatin1String("hint")) {
478 return;
479 }
480
481 showHiddenFilesAction->setIcon(QIcon::fromTheme(shown ? QStringLiteral("visibility") : QStringLiteral("hint")));
482 }
483
484 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
485 {
486 m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable &&
487 KProtocolManager::supportsMakeDir(currentView()->url()));
488 }
489
490 KToggleAction* DolphinViewActionHandler::iconsModeAction()
491 {
492 KToggleAction* iconsView = m_actionCollection->add<KToggleAction>(QStringLiteral("icons"));
493 iconsView->setText(i18nc("@action:inmenu View Mode", "Icons"));
494 iconsView->setToolTip(i18nc("@info", "Icons view mode"));
495 m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL + Qt::Key_1);
496 iconsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
497 iconsView->setData(QVariant::fromValue(DolphinView::IconsView));
498 return iconsView;
499 }
500
501 KToggleAction* DolphinViewActionHandler::compactModeAction()
502 {
503 KToggleAction* iconsView = m_actionCollection->add<KToggleAction>(QStringLiteral("compact"));
504 iconsView->setText(i18nc("@action:inmenu View Mode", "Compact"));
505 iconsView->setToolTip(i18nc("@info", "Compact view mode"));
506 m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL + Qt::Key_2);
507 iconsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
508 iconsView->setData(QVariant::fromValue(DolphinView::CompactView));
509 return iconsView;
510 }
511
512 KToggleAction* DolphinViewActionHandler::detailsModeAction()
513 {
514 KToggleAction* detailsView = m_actionCollection->add<KToggleAction>(QStringLiteral("details"));
515 detailsView->setText(i18nc("@action:inmenu View Mode", "Details"));
516 detailsView->setToolTip(i18nc("@info", "Details view mode"));
517 m_actionCollection->setDefaultShortcut(detailsView, Qt::CTRL + Qt::Key_3);
518 detailsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
519 detailsView->setData(QVariant::fromValue(DolphinView::DetailsView));
520 return detailsView;
521 }
522
523 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
524 {
525 KToggleAction* action = m_sortByActions.value(role);
526 if (action) {
527 action->setChecked(true);
528
529 if (!action->icon().isNull()) {
530 QAction* sortByMenu = m_actionCollection->action(QStringLiteral("sort"));
531 sortByMenu->setIcon(action->icon());
532 }
533 }
534 }
535
536 void DolphinViewActionHandler::slotZoomLevelChanged(int current, int previous)
537 {
538 Q_UNUSED(previous);
539
540 QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
541 if (zoomInAction) {
542 zoomInAction->setEnabled(current < ZoomLevelInfo::maximumLevel());
543 }
544
545 QAction* zoomOutAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomOut));
546 if (zoomOutAction) {
547 zoomOutAction->setEnabled(current > ZoomLevelInfo::minimumLevel());
548 }
549 }
550
551 void DolphinViewActionHandler::slotSortTriggered(QAction* action)
552 {
553 // The radiobuttons of the "Sort By"-menu are split between the main-menu
554 // and several sub-menus. Because of this they don't have a common
555 // action-group that assures an exclusive toggle-state between the main-menu
556 // actions and the sub-menu-actions. If an action gets checked, it must
557 // be assured that all other actions get unchecked.
558 QAction* sortByMenu = m_actionCollection->action(QStringLiteral("sort"));
559 foreach (QAction* groupAction, sortByMenu->menu()->actions()) {
560 KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction);
561 if (actionMenu) {
562 foreach (QAction* subAction, actionMenu->menu()->actions()) {
563 subAction->setChecked(false);
564 }
565 } else if (groupAction->actionGroup()) {
566 groupAction->setChecked(false);
567 }
568 }
569 action->setChecked(true);
570
571 // Apply the activated sort-role to the view
572 const QByteArray role = action->data().toByteArray();
573 m_currentView->setSortRole(role);
574 }
575
576 void DolphinViewActionHandler::slotAdjustViewProperties()
577 {
578 emit actionBeingHandled();
579 QPointer<ViewPropertiesDialog> dialog = new ViewPropertiesDialog(m_currentView);
580 dialog->exec();
581 delete dialog;
582 }
583
584 void DolphinViewActionHandler::slotProperties()
585 {
586 KPropertiesDialog* dialog = nullptr;
587 const KFileItemList list = m_currentView->selectedItems();
588 if (list.isEmpty()) {
589 const QUrl url = m_currentView->url();
590 dialog = new KPropertiesDialog(url, m_currentView);
591 } else {
592 dialog = new KPropertiesDialog(list, m_currentView);
593 }
594
595 dialog->setAttribute(Qt::WA_DeleteOnClose);
596 dialog->show();
597 dialog->raise();
598 dialog->activateWindow();
599 }