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