]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinviewactionhandler.cpp
Merge branch 'Applications/15.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 <QIcon>
41
42 #include "dolphindebug.h"
43
44 #ifdef HAVE_BALOO
45 #include <Baloo/IndexerConfig>
46 #endif
47
48 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
49 QObject(parent),
50 m_actionCollection(collection),
51 m_currentView(0),
52 m_sortByActions(),
53 m_visibleRoles()
54 {
55 Q_ASSERT(m_actionCollection);
56 createActions();
57 }
58
59 void DolphinViewActionHandler::setCurrentView(DolphinView* view)
60 {
61 Q_ASSERT(view);
62
63 if (m_currentView) {
64 disconnect(m_currentView, 0, this, 0);
65 }
66
67 m_currentView = view;
68
69 connect(view, &DolphinView::modeChanged,
70 this, &DolphinViewActionHandler::updateViewActions);
71 connect(view, &DolphinView::previewsShownChanged,
72 this, &DolphinViewActionHandler::slotPreviewsShownChanged);
73 connect(view, &DolphinView::sortOrderChanged,
74 this, &DolphinViewActionHandler::slotSortOrderChanged);
75 connect(view, &DolphinView::sortFoldersFirstChanged,
76 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged);
77 connect(view, &DolphinView::visibleRolesChanged,
78 this, &DolphinViewActionHandler::slotVisibleRolesChanged);
79 connect(view, &DolphinView::groupedSortingChanged,
80 this, &DolphinViewActionHandler::slotGroupedSortingChanged);
81 connect(view, &DolphinView::hiddenFilesShownChanged,
82 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged);
83 connect(view, &DolphinView::sortRoleChanged,
84 this, &DolphinViewActionHandler::slotSortRoleChanged);
85 connect(view, &DolphinView::zoomLevelChanged,
86 this, &DolphinViewActionHandler::slotZoomLevelChanged);
87 connect(view, &DolphinView::writeStateChanged,
88 this, &DolphinViewActionHandler::slotWriteStateChanged);
89 }
90
91 DolphinView* DolphinViewActionHandler::currentView()
92 {
93 return m_currentView;
94 }
95
96 void DolphinViewActionHandler::createActions()
97 {
98 // This action doesn't appear in the GUI, it's for the shortcut only.
99 // KNewFileMenu takes care of the GUI stuff.
100 QAction* newDirAction = m_actionCollection->addAction("create_dir");
101 newDirAction->setText(i18nc("@action", "Create Folder..."));
102 m_actionCollection->setDefaultShortcut(newDirAction, Qt::Key_F10);
103 newDirAction->setIcon(QIcon::fromTheme("folder-new"));
104 newDirAction->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
105 connect(newDirAction, &QAction::triggered, this, &DolphinViewActionHandler::createDirectory);
106
107 // File menu
108
109 QAction* rename = m_actionCollection->addAction("rename");
110 rename->setText(i18nc("@action:inmenu File", "Rename..."));
111 m_actionCollection->setDefaultShortcut(rename, Qt::Key_F2);
112 rename->setIcon(QIcon::fromTheme("edit-rename"));
113 connect(rename, &QAction::triggered, this, &DolphinViewActionHandler::slotRename);
114
115 QAction* moveToTrash = m_actionCollection->addAction("move_to_trash");
116 moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
117 moveToTrash->setIcon(QIcon::fromTheme("user-trash"));
118 m_actionCollection->setDefaultShortcut(moveToTrash, QKeySequence::Delete);
119 connect(moveToTrash, &QAction::triggered,
120 this, &DolphinViewActionHandler::slotTrashActivated);
121
122 QAction* deleteAction = m_actionCollection->addAction("delete");
123 deleteAction->setIcon(QIcon::fromTheme("edit-delete"));
124 deleteAction->setText(i18nc("@action:inmenu File", "Delete"));
125 m_actionCollection->setDefaultShortcut(deleteAction, Qt::SHIFT | Qt::Key_Delete);
126 connect(deleteAction, &QAction::triggered, this, &DolphinViewActionHandler::slotDeleteItems);
127
128 // This action is useful for being enabled when "move_to_trash" should be
129 // disabled and "delete" is enabled (e.g. non-local files), so that Key_Del
130 // can be used for deleting the file (#76016). It needs to be a separate action
131 // so that the Edit menu isn't affected.
132 QAction* deleteWithTrashShortcut = m_actionCollection->addAction("delete_shortcut");
133 // The descriptive text is just for the shortcuts editor.
134 deleteWithTrashShortcut->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
135 m_actionCollection->setDefaultShortcut(deleteWithTrashShortcut, QKeySequence::Delete);
136 deleteWithTrashShortcut->setEnabled(false);
137 connect(deleteWithTrashShortcut, &QAction::triggered, this, &DolphinViewActionHandler::slotDeleteItems);
138
139 QAction *propertiesAction = m_actionCollection->addAction( "properties" );
140 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
141 propertiesAction->setText( i18nc("@action:inmenu File", "Properties") );
142 propertiesAction->setIcon(QIcon::fromTheme("document-properties"));
143 m_actionCollection->setDefaultShortcuts(propertiesAction, {Qt::ALT + Qt::Key_Return, Qt::ALT + Qt::Key_Enter});
144 connect(propertiesAction, &QAction::triggered, this, &DolphinViewActionHandler::slotProperties);
145
146 // View menu
147 KToggleAction* iconsAction = iconsModeAction();
148 KToggleAction* compactAction = compactModeAction();
149 KToggleAction* detailsAction = detailsModeAction();
150
151 KSelectAction* viewModeActions = m_actionCollection->add<KSelectAction>("view_mode");
152 viewModeActions->setText(i18nc("@action:intoolbar", "View Mode"));
153 viewModeActions->addAction(iconsAction);
154 viewModeActions->addAction(compactAction);
155 viewModeActions->addAction(detailsAction);
156 viewModeActions->setToolBarMode(KSelectAction::MenuMode);
157 connect(viewModeActions, static_cast<void(KSelectAction::*)(QAction*)>(&KSelectAction::triggered), this, &DolphinViewActionHandler::slotViewModeActionTriggered);
158
159 KStandardAction::zoomIn(this,
160 SLOT(zoomIn()),
161 m_actionCollection);
162
163 KStandardAction::zoomOut(this,
164 SLOT(zoomOut()),
165 m_actionCollection);
166
167 KToggleAction* showPreview = m_actionCollection->add<KToggleAction>("show_preview");
168 showPreview->setText(i18nc("@action:intoolbar", "Preview"));
169 showPreview->setToolTip(i18nc("@info", "Show preview of files and folders"));
170 showPreview->setIcon(QIcon::fromTheme("view-preview"));
171 connect(showPreview, &KToggleAction::triggered, this, &DolphinViewActionHandler::togglePreview);
172
173 KToggleAction* sortDescending = m_actionCollection->add<KToggleAction>("descending");
174 sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
175 connect(sortDescending, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortOrder);
176
177 KToggleAction* sortFoldersFirst = m_actionCollection->add<KToggleAction>("folders_first");
178 sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First"));
179 connect(sortFoldersFirst, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortFoldersFirst);
180
181 // View -> Sort By
182 QActionGroup* sortByActionGroup = createFileItemRolesActionGroup("sort_by_");
183
184 KActionMenu* sortByActionMenu = m_actionCollection->add<KActionMenu>("sort");
185 sortByActionMenu->setText(i18nc("@action:inmenu View", "Sort By"));
186 sortByActionMenu->setDelayed(false);
187
188 foreach (QAction* action, sortByActionGroup->actions()) {
189 sortByActionMenu->addAction(action);
190 }
191 sortByActionMenu->addSeparator();
192 sortByActionMenu->addAction(sortDescending);
193 sortByActionMenu->addAction(sortFoldersFirst);
194
195 // View -> Additional Information
196 QActionGroup* visibleRolesGroup = createFileItemRolesActionGroup("show_");
197
198 KActionMenu* visibleRolesMenu = m_actionCollection->add<KActionMenu>("additional_info");
199 visibleRolesMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
200 visibleRolesMenu->setDelayed(false);
201
202 foreach (QAction* action, visibleRolesGroup->actions()) {
203 visibleRolesMenu->addAction(action);
204 }
205
206 KToggleAction* showInGroups = m_actionCollection->add<KToggleAction>("show_in_groups");
207 showInGroups->setIcon(QIcon::fromTheme("view-group"));
208 showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups"));
209 connect(showInGroups, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleGroupedSorting);
210
211 KToggleAction* showHiddenFiles = m_actionCollection->add<KToggleAction>("show_hidden_files");
212 showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
213 m_actionCollection->setDefaultShortcuts(showHiddenFiles, {Qt::ALT + Qt::Key_Period, Qt::Key_F8});
214 connect(showHiddenFiles, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleShowHiddenFiles);
215
216 QAction* adjustViewProps = m_actionCollection->addAction("view_properties");
217 adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
218 connect(adjustViewProps, &QAction::triggered, this, &DolphinViewActionHandler::slotAdjustViewProperties);
219 }
220
221 QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString& groupPrefix)
222 {
223 const bool isSortGroup = (groupPrefix == QLatin1String("sort_by_"));
224 Q_ASSERT(isSortGroup || (!isSortGroup && groupPrefix == QLatin1String("show_")));
225
226 QActionGroup* rolesActionGroup = new QActionGroup(m_actionCollection);
227 rolesActionGroup->setExclusive(isSortGroup);
228 if (isSortGroup) {
229 connect(rolesActionGroup, &QActionGroup::triggered,
230 this, &DolphinViewActionHandler::slotSortTriggered);
231 } else {
232 connect(rolesActionGroup, &QActionGroup::triggered,
233 this, &DolphinViewActionHandler::toggleVisibleRole);
234 }
235
236 QString groupName;
237 KActionMenu* groupMenu = 0;
238 QActionGroup* groupMenuGroup = 0;
239
240 bool indexingEnabled = false;
241 #ifdef HAVE_BALOO
242 Baloo::IndexerConfig config;
243 indexingEnabled = config.fileIndexingEnabled();
244 #endif
245
246 const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
247 foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
248 if (!isSortGroup && info.role == "text") {
249 // It should not be possible to hide the "text" role
250 continue;
251 }
252
253 KToggleAction* action = 0;
254 const QString name = groupPrefix + info.role;
255 if (info.group.isEmpty()) {
256 action = m_actionCollection->add<KToggleAction>(name);
257 action->setActionGroup(rolesActionGroup);
258 } else {
259 if (!groupMenu || info.group != groupName) {
260 groupName = info.group;
261 groupMenu = m_actionCollection->add<KActionMenu>(groupName);
262 groupMenu->setText(groupName);
263 groupMenu->setActionGroup(rolesActionGroup);
264
265 groupMenuGroup = new QActionGroup(groupMenu);
266 groupMenuGroup->setExclusive(isSortGroup);
267 if (isSortGroup) {
268 connect(groupMenuGroup, &QActionGroup::triggered,
269 this, &DolphinViewActionHandler::slotSortTriggered);
270 } else {
271 connect(groupMenuGroup, &QActionGroup::triggered,
272 this, &DolphinViewActionHandler::toggleVisibleRole);
273 }
274 }
275
276 action = new KToggleAction(groupMenu);
277 action->setActionGroup(groupMenuGroup);
278 groupMenu->addAction(action);
279 }
280 action->setText(info.translation);
281 action->setData(info.role);
282
283 const bool enable = (!info.requiresBaloo && !info.requiresIndexer) ||
284 (info.requiresBaloo) ||
285 (info.requiresIndexer && indexingEnabled);
286 action->setEnabled(enable);
287
288 if (isSortGroup) {
289 m_sortByActions.insert(info.role, action);
290 } else {
291 m_visibleRoles.insert(info.role, action);
292 }
293 }
294
295 return rolesActionGroup;
296 }
297
298 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
299 {
300 const DolphinView::Mode mode = action->data().value<DolphinView::Mode>();
301 m_currentView->setMode(mode);
302
303 QAction* viewModeMenu = m_actionCollection->action("view_mode");
304 viewModeMenu->setIcon(action->icon());
305 }
306
307 void DolphinViewActionHandler::slotRename()
308 {
309 emit actionBeingHandled();
310 m_currentView->renameSelectedItems();
311 }
312
313 void DolphinViewActionHandler::slotTrashActivated()
314 {
315 emit actionBeingHandled();
316 m_currentView->trashSelectedItems();
317 }
318
319 void DolphinViewActionHandler::slotDeleteItems()
320 {
321 emit actionBeingHandled();
322 m_currentView->deleteSelectedItems();
323 }
324
325 void DolphinViewActionHandler::togglePreview(bool show)
326 {
327 emit actionBeingHandled();
328 m_currentView->setPreviewsShown(show);
329 }
330
331 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown)
332 {
333 Q_UNUSED(shown);
334 // It is not enough to update the 'Show Preview' action, also
335 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
336 updateViewActions();
337 }
338
339 QString DolphinViewActionHandler::currentViewModeActionName() const
340 {
341 switch (m_currentView->mode()) {
342 case DolphinView::IconsView:
343 return "icons";
344 case DolphinView::DetailsView:
345 return "details";
346 case DolphinView::CompactView:
347 return "compact";
348 default:
349 Q_ASSERT(false);
350 break;
351 }
352 return QString(); // can't happen
353 }
354
355 KActionCollection* DolphinViewActionHandler::actionCollection()
356 {
357 return m_actionCollection;
358 }
359
360 void DolphinViewActionHandler::updateViewActions()
361 {
362 QAction* viewModeAction = m_actionCollection->action(currentViewModeActionName());
363 if (viewModeAction) {
364 viewModeAction->setChecked(true);
365
366 QAction* viewModeMenu = m_actionCollection->action("view_mode");
367 viewModeMenu->setIcon(viewModeAction->icon());
368 }
369
370 QAction* showPreviewAction = m_actionCollection->action("show_preview");
371 showPreviewAction->setChecked(m_currentView->previewsShown());
372
373 slotSortOrderChanged(m_currentView->sortOrder());
374 slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst());
375 slotVisibleRolesChanged(m_currentView->visibleRoles(), QList<QByteArray>());
376 slotGroupedSortingChanged(m_currentView->groupedSorting());
377 slotSortRoleChanged(m_currentView->sortRole());
378 slotZoomLevelChanged(m_currentView->zoomLevel(), -1);
379
380 QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
381 showHiddenFilesAction->setChecked(m_currentView->hiddenFilesShown());
382 }
383
384 void DolphinViewActionHandler::zoomIn()
385 {
386 const int level = m_currentView->zoomLevel();
387 m_currentView->setZoomLevel(level + 1);
388 updateViewActions();
389 }
390
391 void DolphinViewActionHandler::zoomOut()
392 {
393 const int level = m_currentView->zoomLevel();
394 m_currentView->setZoomLevel(level - 1);
395 updateViewActions();
396 }
397
398 void DolphinViewActionHandler::toggleSortOrder()
399 {
400 const Qt::SortOrder order = (m_currentView->sortOrder() == Qt::AscendingOrder) ?
401 Qt::DescendingOrder :
402 Qt::AscendingOrder;
403 m_currentView->setSortOrder(order);
404 }
405
406 void DolphinViewActionHandler::toggleSortFoldersFirst()
407 {
408 const bool sortFirst = m_currentView->sortFoldersFirst();
409 m_currentView->setSortFoldersFirst(!sortFirst);
410 }
411
412 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order)
413 {
414 QAction* descending = m_actionCollection->action("descending");
415 const bool sortDescending = (order == Qt::DescendingOrder);
416 descending->setChecked(sortDescending);
417 }
418
419 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
420 {
421 m_actionCollection->action("folders_first")->setChecked(foldersFirst);
422 }
423
424 void DolphinViewActionHandler::toggleVisibleRole(QAction* action)
425 {
426 emit actionBeingHandled();
427
428 const QByteArray toggledRole = action->data().toByteArray();
429
430 QList<QByteArray> roles = m_currentView->visibleRoles();
431
432 const bool show = action->isChecked();
433
434 const int index = roles.indexOf(toggledRole);
435 const bool containsInfo = (index >= 0);
436 if (show && !containsInfo) {
437 roles.append(toggledRole);
438 m_currentView->setVisibleRoles(roles);
439 } else if (!show && containsInfo) {
440 roles.removeAt(index);
441 m_currentView->setVisibleRoles(roles);
442 Q_ASSERT(roles.indexOf(toggledRole) < 0);
443 }
444 }
445
446 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList<QByteArray>& current,
447 const QList<QByteArray>& previous)
448 {
449 Q_UNUSED(previous);
450
451 const QSet<QByteArray> checkedRoles = current.toSet();
452 QHashIterator<QByteArray, KToggleAction*> it(m_visibleRoles);
453 while (it.hasNext()) {
454 it.next();
455 const QByteArray& role = it.key();
456 KToggleAction* action = it.value();
457 action->setChecked(checkedRoles.contains(role));
458 }
459 }
460
461 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped)
462 {
463 m_currentView->setGroupedSorting(grouped);
464 }
465
466 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting)
467 {
468 QAction* showInGroupsAction = m_actionCollection->action("show_in_groups");
469 showInGroupsAction->setChecked(groupedSorting);
470 }
471
472 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show)
473 {
474 emit actionBeingHandled();
475 m_currentView->setHiddenFilesShown(show);
476 }
477
478 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
479 {
480 QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
481 showHiddenFilesAction->setChecked(shown);
482 }
483
484 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
485 {
486 m_actionCollection->action("create_dir")->setEnabled(isFolderWritable);
487 }
488
489 KToggleAction* DolphinViewActionHandler::iconsModeAction()
490 {
491 KToggleAction* iconsView = m_actionCollection->add<KToggleAction>("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("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>("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("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>("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("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("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("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 = 0;
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 }