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