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