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