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