]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinviewactionhandler.cpp
668623c8c91ab078770ba408f2b462ff95ab72c6
[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 #include <konq_operations.h>
29
30 #include <QPointer>
31 #include <QMenu>
32
33 #include <KActionCollection>
34 #include <KActionMenu>
35 #include <kitemviews/kfileitemmodel.h>
36 #include <KLocalizedString>
37 #include <KNewFileMenu>
38 #include <KSelectAction>
39 #include <KToggleAction>
40 #include <KPropertiesDialog>
41 #include <QIcon>
42
43 #include <KDebug>
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("create_dir");
102 newDirAction->setText(i18nc("@action", "Create Folder..."));
103 m_actionCollection->setDefaultShortcut(newDirAction, Qt::Key_F10);
104 newDirAction->setIcon(QIcon::fromTheme("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("rename");
111 rename->setText(i18nc("@action:inmenu File", "Rename..."));
112 m_actionCollection->setDefaultShortcut(rename, Qt::Key_F2);
113 rename->setIcon(QIcon::fromTheme("edit-rename"));
114 connect(rename, &QAction::triggered, this, &DolphinViewActionHandler::slotRename);
115
116 QAction* moveToTrash = m_actionCollection->addAction("move_to_trash");
117 moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
118 moveToTrash->setIcon(QIcon::fromTheme("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("delete");
124 deleteAction->setIcon(QIcon::fromTheme("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("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( "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("document-properties"));
144 m_actionCollection->setDefaultShortcuts(propertiesAction, QList<QKeySequence>() << 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>("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>("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("view-preview"));
172 connect(showPreview, &KToggleAction::triggered, this, &DolphinViewActionHandler::togglePreview);
173
174 KToggleAction* sortDescending = m_actionCollection->add<KToggleAction>("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>("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("sort_by_");
184
185 KActionMenu* sortByActionMenu = m_actionCollection->add<KActionMenu>("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("show_");
198
199 KActionMenu* visibleRolesMenu = m_actionCollection->add<KActionMenu>("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>("show_in_groups");
208 showInGroups->setIcon(QIcon::fromTheme("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>("show_hidden_files");
213 showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
214 m_actionCollection->setDefaultShortcuts(showHiddenFiles, QList<QKeySequence>() << Qt::ALT + Qt::Key_Period << Qt::Key_F8);
215 connect(showHiddenFiles, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleShowHiddenFiles);
216
217 QAction* adjustViewProps = m_actionCollection->addAction("view_properties");
218 adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
219 connect(adjustViewProps, &QAction::triggered, this, &DolphinViewActionHandler::slotAdjustViewProperties);
220 }
221
222 QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString& groupPrefix)
223 {
224 const bool isSortGroup = (groupPrefix == QLatin1String("sort_by_"));
225 Q_ASSERT(isSortGroup || (!isSortGroup && groupPrefix == QLatin1String("show_")));
226
227 QActionGroup* rolesActionGroup = new QActionGroup(m_actionCollection);
228 rolesActionGroup->setExclusive(isSortGroup);
229 if (isSortGroup) {
230 connect(rolesActionGroup, &QActionGroup::triggered,
231 this, &DolphinViewActionHandler::slotSortTriggered);
232 } else {
233 connect(rolesActionGroup, &QActionGroup::triggered,
234 this, &DolphinViewActionHandler::toggleVisibleRole);
235 }
236
237 QString groupName;
238 KActionMenu* groupMenu = 0;
239 QActionGroup* groupMenuGroup = 0;
240
241 bool indexingEnabled = false;
242 #ifdef HAVE_BALOO
243 Baloo::IndexerConfig config;
244 indexingEnabled = config.fileIndexingEnabled();
245 #endif
246
247 const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
248 foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
249 if (!isSortGroup && info.role == "text") {
250 // It should not be possible to hide the "text" role
251 continue;
252 }
253
254 KToggleAction* action = 0;
255 const QString name = groupPrefix + info.role;
256 if (info.group.isEmpty()) {
257 action = m_actionCollection->add<KToggleAction>(name);
258 action->setActionGroup(rolesActionGroup);
259 } else {
260 if (!groupMenu || info.group != groupName) {
261 groupName = info.group;
262 groupMenu = m_actionCollection->add<KActionMenu>(groupName);
263 groupMenu->setText(groupName);
264 groupMenu->setActionGroup(rolesActionGroup);
265
266 groupMenuGroup = new QActionGroup(groupMenu);
267 groupMenuGroup->setExclusive(isSortGroup);
268 if (isSortGroup) {
269 connect(groupMenuGroup, &QActionGroup::triggered,
270 this, &DolphinViewActionHandler::slotSortTriggered);
271 } else {
272 connect(groupMenuGroup, &QActionGroup::triggered,
273 this, &DolphinViewActionHandler::toggleVisibleRole);
274 }
275 }
276
277 action = new KToggleAction(groupMenu);
278 action->setActionGroup(groupMenuGroup);
279 groupMenu->addAction(action);
280 }
281 action->setText(info.translation);
282 action->setData(info.role);
283
284 const bool enable = (!info.requiresBaloo && !info.requiresIndexer) ||
285 (info.requiresBaloo) ||
286 (info.requiresIndexer && indexingEnabled);
287 action->setEnabled(enable);
288
289 if (isSortGroup) {
290 m_sortByActions.insert(info.role, action);
291 } else {
292 m_visibleRoles.insert(info.role, action);
293 }
294 }
295
296 return rolesActionGroup;
297 }
298
299 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
300 {
301 const DolphinView::Mode mode = action->data().value<DolphinView::Mode>();
302 m_currentView->setMode(mode);
303
304 QAction* viewModeMenu = m_actionCollection->action("view_mode");
305 viewModeMenu->setIcon(action->icon());
306 }
307
308 void DolphinViewActionHandler::slotRename()
309 {
310 emit actionBeingHandled();
311 m_currentView->renameSelectedItems();
312 }
313
314 void DolphinViewActionHandler::slotTrashActivated()
315 {
316 emit actionBeingHandled();
317 m_currentView->trashSelectedItems();
318 }
319
320 void DolphinViewActionHandler::slotDeleteItems()
321 {
322 emit actionBeingHandled();
323 m_currentView->deleteSelectedItems();
324 }
325
326 void DolphinViewActionHandler::togglePreview(bool show)
327 {
328 emit actionBeingHandled();
329 m_currentView->setPreviewsShown(show);
330 }
331
332 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown)
333 {
334 Q_UNUSED(shown);
335 // It is not enough to update the 'Show Preview' action, also
336 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
337 updateViewActions();
338 }
339
340 QString DolphinViewActionHandler::currentViewModeActionName() const
341 {
342 switch (m_currentView->mode()) {
343 case DolphinView::IconsView:
344 return "icons";
345 case DolphinView::DetailsView:
346 return "details";
347 case DolphinView::CompactView:
348 return "compact";
349 default:
350 Q_ASSERT(false);
351 break;
352 }
353 return QString(); // can't happen
354 }
355
356 KActionCollection* DolphinViewActionHandler::actionCollection()
357 {
358 return m_actionCollection;
359 }
360
361 void DolphinViewActionHandler::updateViewActions()
362 {
363 QAction* viewModeAction = m_actionCollection->action(currentViewModeActionName());
364 if (viewModeAction) {
365 viewModeAction->setChecked(true);
366
367 QAction* viewModeMenu = m_actionCollection->action("view_mode");
368 viewModeMenu->setIcon(viewModeAction->icon());
369 }
370
371 QAction* showPreviewAction = m_actionCollection->action("show_preview");
372 showPreviewAction->setChecked(m_currentView->previewsShown());
373
374 slotSortOrderChanged(m_currentView->sortOrder());
375 slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst());
376 slotVisibleRolesChanged(m_currentView->visibleRoles(), QList<QByteArray>());
377 slotGroupedSortingChanged(m_currentView->groupedSorting());
378 slotSortRoleChanged(m_currentView->sortRole());
379 slotZoomLevelChanged(m_currentView->zoomLevel(), -1);
380
381 QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
382 showHiddenFilesAction->setChecked(m_currentView->hiddenFilesShown());
383 }
384
385 void DolphinViewActionHandler::zoomIn()
386 {
387 const int level = m_currentView->zoomLevel();
388 m_currentView->setZoomLevel(level + 1);
389 updateViewActions();
390 }
391
392 void DolphinViewActionHandler::zoomOut()
393 {
394 const int level = m_currentView->zoomLevel();
395 m_currentView->setZoomLevel(level - 1);
396 updateViewActions();
397 }
398
399 void DolphinViewActionHandler::toggleSortOrder()
400 {
401 const Qt::SortOrder order = (m_currentView->sortOrder() == Qt::AscendingOrder) ?
402 Qt::DescendingOrder :
403 Qt::AscendingOrder;
404 m_currentView->setSortOrder(order);
405 }
406
407 void DolphinViewActionHandler::toggleSortFoldersFirst()
408 {
409 const bool sortFirst = m_currentView->sortFoldersFirst();
410 m_currentView->setSortFoldersFirst(!sortFirst);
411 }
412
413 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order)
414 {
415 QAction* descending = m_actionCollection->action("descending");
416 const bool sortDescending = (order == Qt::DescendingOrder);
417 descending->setChecked(sortDescending);
418 }
419
420 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
421 {
422 m_actionCollection->action("folders_first")->setChecked(foldersFirst);
423 }
424
425 void DolphinViewActionHandler::toggleVisibleRole(QAction* action)
426 {
427 emit actionBeingHandled();
428
429 const QByteArray toggledRole = action->data().toByteArray();
430
431 QList<QByteArray> roles = m_currentView->visibleRoles();
432
433 const bool show = action->isChecked();
434
435 const int index = roles.indexOf(toggledRole);
436 const bool containsInfo = (index >= 0);
437 if (show && !containsInfo) {
438 roles.append(toggledRole);
439 m_currentView->setVisibleRoles(roles);
440 } else if (!show && containsInfo) {
441 roles.removeAt(index);
442 m_currentView->setVisibleRoles(roles);
443 Q_ASSERT(roles.indexOf(toggledRole) < 0);
444 }
445 }
446
447 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList<QByteArray>& current,
448 const QList<QByteArray>& previous)
449 {
450 Q_UNUSED(previous);
451
452 const QSet<QByteArray> checkedRoles = current.toSet();
453 QHashIterator<QByteArray, KToggleAction*> it(m_visibleRoles);
454 while (it.hasNext()) {
455 it.next();
456 const QByteArray& role = it.key();
457 KToggleAction* action = it.value();
458 action->setChecked(checkedRoles.contains(role));
459 }
460 }
461
462 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped)
463 {
464 m_currentView->setGroupedSorting(grouped);
465 }
466
467 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting)
468 {
469 QAction* showInGroupsAction = m_actionCollection->action("show_in_groups");
470 showInGroupsAction->setChecked(groupedSorting);
471 }
472
473 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show)
474 {
475 emit actionBeingHandled();
476 m_currentView->setHiddenFilesShown(show);
477 }
478
479 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
480 {
481 QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
482 showHiddenFilesAction->setChecked(shown);
483 }
484
485 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
486 {
487 m_actionCollection->action("create_dir")->setEnabled(isFolderWritable);
488 }
489
490 KToggleAction* DolphinViewActionHandler::iconsModeAction()
491 {
492 KToggleAction* iconsView = m_actionCollection->add<KToggleAction>("icons");
493 iconsView->setText(i18nc("@action:inmenu View Mode", "Icons"));
494 iconsView->setToolTip(i18nc("@info", "Icons view mode"));
495 m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL | Qt::Key_1);
496 iconsView->setIcon(QIcon::fromTheme("view-list-icons"));
497 iconsView->setData(QVariant::fromValue(DolphinView::IconsView));
498 return iconsView;
499 }
500
501 KToggleAction* DolphinViewActionHandler::compactModeAction()
502 {
503 KToggleAction* iconsView = m_actionCollection->add<KToggleAction>("compact");
504 iconsView->setText(i18nc("@action:inmenu View Mode", "Compact"));
505 iconsView->setToolTip(i18nc("@info", "Compact view mode"));
506 m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL | Qt::Key_2);
507 iconsView->setIcon(QIcon::fromTheme("view-list-details")); // TODO: discuss with Oxygen-team the wrong (?) name
508 iconsView->setData(QVariant::fromValue(DolphinView::CompactView));
509 return iconsView;
510 }
511
512 KToggleAction* DolphinViewActionHandler::detailsModeAction()
513 {
514 KToggleAction* detailsView = m_actionCollection->add<KToggleAction>("details");
515 detailsView->setText(i18nc("@action:inmenu View Mode", "Details"));
516 detailsView->setToolTip(i18nc("@info", "Details view mode"));
517 m_actionCollection->setDefaultShortcut(detailsView, Qt::CTRL | Qt::Key_3);
518 detailsView->setIcon(QIcon::fromTheme("view-list-tree"));
519 detailsView->setData(QVariant::fromValue(DolphinView::DetailsView));
520 return detailsView;
521 }
522
523 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
524 {
525 KToggleAction* action = m_sortByActions.value(role);
526 if (action) {
527 action->setChecked(true);
528
529 if (!action->icon().isNull()) {
530 QAction* sortByMenu = m_actionCollection->action("sort");
531 sortByMenu->setIcon(action->icon());
532 }
533 }
534 }
535
536 void DolphinViewActionHandler::slotZoomLevelChanged(int current, int previous)
537 {
538 Q_UNUSED(previous);
539
540 QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
541 if (zoomInAction) {
542 zoomInAction->setEnabled(current < ZoomLevelInfo::maximumLevel());
543 }
544
545 QAction* zoomOutAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomOut));
546 if (zoomOutAction) {
547 zoomOutAction->setEnabled(current > ZoomLevelInfo::minimumLevel());
548 }
549 }
550
551 void DolphinViewActionHandler::slotSortTriggered(QAction* action)
552 {
553 // The radiobuttons of the "Sort By"-menu are split between the main-menu
554 // and several sub-menus. Because of this they don't have a common
555 // action-group that assures an exclusive toggle-state between the main-menu
556 // actions and the sub-menu-actions. If an action gets checked, it must
557 // be assured that all other actions get unchecked.
558 QAction* sortByMenu = m_actionCollection->action("sort");
559 foreach (QAction* groupAction, sortByMenu->menu()->actions()) {
560 KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction);
561 if (actionMenu) {
562 foreach (QAction* subAction, actionMenu->menu()->actions()) {
563 subAction->setChecked(false);
564 }
565 } else if (groupAction->actionGroup()) {
566 groupAction->setChecked(false);
567 }
568 }
569 action->setChecked(true);
570
571 // Apply the activated sort-role to the view
572 const QByteArray role = action->data().toByteArray();
573 m_currentView->setSortRole(role);
574 }
575
576 void DolphinViewActionHandler::slotAdjustViewProperties()
577 {
578 emit actionBeingHandled();
579 QPointer<ViewPropertiesDialog> dialog = new ViewPropertiesDialog(m_currentView);
580 dialog->exec();
581 delete dialog;
582 }
583
584 void DolphinViewActionHandler::slotProperties()
585 {
586 KPropertiesDialog* dialog = 0;
587 const KFileItemList list = m_currentView->selectedItems();
588 if (list.isEmpty()) {
589 const QUrl url = m_currentView->url();
590 dialog = new KPropertiesDialog(url, m_currentView);
591 } else {
592 dialog = new KPropertiesDialog(list, m_currentView);
593 }
594
595 dialog->setAttribute(Qt::WA_DeleteOnClose);
596 dialog->show();
597 dialog->raise();
598 dialog->activateWindow();
599 }