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