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