]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinviewactionhandler.cpp
Prepare view-engine for non-KFileItem usecase
[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-nepomuk.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 <KAction>
31 #include <KActionCollection>
32 #include <KActionMenu>
33 #include <kitemviews/kfileitemmodel.h>
34 #include <KLocale>
35 #include <KMenu>
36 #include <KNewFileMenu>
37 #include <KSelectAction>
38 #include <KToggleAction>
39 #include <KPropertiesDialog>
40 #include <KIcon>
41
42 #ifdef HAVE_NEPOMUK
43 #include <Nepomuk/ResourceManager>
44 #endif
45
46 #include <KDebug>
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, SIGNAL(modeChanged(DolphinView::Mode,DolphinView::Mode)),
70 this, SLOT(updateViewActions()));
71 connect(view, SIGNAL(previewsShownChanged(bool)),
72 this, SLOT(slotPreviewsShownChanged(bool)));
73 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
74 this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
75 connect(view, SIGNAL(sortFoldersFirstChanged(bool)),
76 this, SLOT(slotSortFoldersFirstChanged(bool)));
77 connect(view, SIGNAL(visibleRolesChanged(QList<QByteArray>,QList<QByteArray>)),
78 this, SLOT(slotVisibleRolesChanged(QList<QByteArray>,QList<QByteArray>)));
79 connect(view, SIGNAL(groupedSortingChanged(bool)),
80 this, SLOT(slotGroupedSortingChanged(bool)));
81 connect(view, SIGNAL(hiddenFilesShownChanged(bool)),
82 this, SLOT(slotHiddenFilesShownChanged(bool)));
83 connect(view, SIGNAL(sortRoleChanged(QByteArray)),
84 this, SLOT(slotSortRoleChanged(QByteArray)));
85 connect(view, SIGNAL(zoomLevelChanged(int,int)),
86 this, SLOT(slotZoomLevelChanged(int,int)));
87 }
88
89 DolphinView* DolphinViewActionHandler::currentView()
90 {
91 return m_currentView;
92 }
93
94 void DolphinViewActionHandler::createActions()
95 {
96 // This action doesn't appear in the GUI, it's for the shortcut only.
97 // KNewFileMenu takes care of the GUI stuff.
98 KAction* newDirAction = m_actionCollection->addAction("create_dir");
99 newDirAction->setText(i18nc("@action", "Create Folder..."));
100 newDirAction->setShortcut(Qt::Key_F10);
101 newDirAction->setIcon(KIcon("folder-new"));
102 connect(newDirAction, SIGNAL(triggered()), this, SIGNAL(createDirectory()));
103
104 // File menu
105
106 KAction* rename = m_actionCollection->addAction("rename");
107 rename->setText(i18nc("@action:inmenu File", "Rename..."));
108 rename->setShortcut(Qt::Key_F2);
109 rename->setIcon(KIcon("edit-rename"));
110 connect(rename, SIGNAL(triggered()), this, SLOT(slotRename()));
111
112 KAction* moveToTrash = m_actionCollection->addAction("move_to_trash");
113 moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
114 moveToTrash->setIcon(KIcon("user-trash"));
115 moveToTrash->setShortcut(QKeySequence::Delete);
116 connect(moveToTrash, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)),
117 this, SLOT(slotTrashActivated(Qt::MouseButtons,Qt::KeyboardModifiers)));
118
119 KAction* deleteAction = m_actionCollection->addAction("delete");
120 deleteAction->setIcon(KIcon("edit-delete"));
121 deleteAction->setText(i18nc("@action:inmenu File", "Delete"));
122 deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
123 connect(deleteAction, SIGNAL(triggered()), this, SLOT(slotDeleteItems()));
124
125 // This action is useful for being enabled when "move_to_trash" should be
126 // disabled and "delete" is enabled (e.g. non-local files), so that Key_Del
127 // can be used for deleting the file (#76016). It needs to be a separate action
128 // so that the Edit menu isn't affected.
129 KAction* deleteWithTrashShortcut = m_actionCollection->addAction("delete_shortcut");
130 // The descriptive text is just for the shortcuts editor.
131 deleteWithTrashShortcut->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
132 deleteWithTrashShortcut->setShortcut(QKeySequence::Delete);
133 deleteWithTrashShortcut->setEnabled(false);
134 connect(deleteWithTrashShortcut, SIGNAL(triggered()), this, SLOT(slotDeleteItems()));
135
136 KAction *propertiesAction = m_actionCollection->addAction( "properties" );
137 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
138 propertiesAction->setText( i18nc("@action:inmenu File", "Properties") );
139 propertiesAction->setIcon(KIcon("document-properties"));
140 propertiesAction->setShortcut(Qt::ALT | Qt::Key_Return);
141 connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties()));
142
143 // View menu
144 KToggleAction* iconsAction = iconsModeAction();
145 KToggleAction* compactAction = compactModeAction();
146 KToggleAction* detailsAction = detailsModeAction();
147
148 KSelectAction* viewModeActions = m_actionCollection->add<KSelectAction>("view_mode");
149 viewModeActions->setText(i18nc("@action:intoolbar", "View Mode"));
150 viewModeActions->addAction(iconsAction);
151 viewModeActions->addAction(compactAction);
152 viewModeActions->addAction(detailsAction);
153 viewModeActions->setToolBarMode(KSelectAction::MenuMode);
154 connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*)));
155
156 KStandardAction::zoomIn(this,
157 SLOT(zoomIn()),
158 m_actionCollection);
159
160 KStandardAction::zoomOut(this,
161 SLOT(zoomOut()),
162 m_actionCollection);
163
164 KToggleAction* showPreview = m_actionCollection->add<KToggleAction>("show_preview");
165 showPreview->setText(i18nc("@action:intoolbar", "Preview"));
166 showPreview->setToolTip(i18nc("@info", "Show preview of files and folders"));
167 showPreview->setIcon(KIcon("view-preview"));
168 connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool)));
169
170 KToggleAction* sortDescending = m_actionCollection->add<KToggleAction>("descending");
171 sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
172 connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
173
174 KToggleAction* sortFoldersFirst = m_actionCollection->add<KToggleAction>("folders_first");
175 sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First"));
176 connect(sortFoldersFirst, SIGNAL(triggered()), this, SLOT(toggleSortFoldersFirst()));
177
178 // View -> Sort By
179 QActionGroup* sortByActionGroup = createFileItemRolesActionGroup("sort_by_");
180
181 KActionMenu* sortByActionMenu = m_actionCollection->add<KActionMenu>("sort");
182 sortByActionMenu->setText(i18nc("@action:inmenu View", "Sort By"));
183 sortByActionMenu->setDelayed(false);
184
185 foreach (QAction* action, sortByActionGroup->actions()) {
186 sortByActionMenu->addAction(action);
187 }
188 sortByActionMenu->addSeparator();
189 sortByActionMenu->addAction(sortDescending);
190 sortByActionMenu->addAction(sortFoldersFirst);
191
192 // View -> Additional Information
193 QActionGroup* visibleRolesGroup = createFileItemRolesActionGroup("show_");
194
195 KActionMenu* visibleRolesMenu = m_actionCollection->add<KActionMenu>("additional_info");
196 visibleRolesMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
197 visibleRolesMenu->setDelayed(false);
198
199 foreach (QAction* action, visibleRolesGroup->actions()) {
200 visibleRolesMenu->addAction(action);
201 }
202
203 KToggleAction* showInGroups = m_actionCollection->add<KToggleAction>("show_in_groups");
204 showInGroups->setIcon(KIcon("view-group"));
205 showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups"));
206 connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleGroupedSorting(bool)));
207
208 KToggleAction* showHiddenFiles = m_actionCollection->add<KToggleAction>("show_hidden_files");
209 showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
210 showHiddenFiles->setShortcuts(QList<QKeySequence>() << Qt::ALT + Qt::Key_Period << Qt::Key_F8);
211 connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool)));
212
213 KAction* adjustViewProps = m_actionCollection->addAction("view_properties");
214 adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
215 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(slotAdjustViewProperties()));
216 }
217
218 QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString& groupPrefix)
219 {
220 const bool isSortGroup = (groupPrefix == QLatin1String("sort_by_"));
221 Q_ASSERT(isSortGroup || (!isSortGroup && groupPrefix == QLatin1String("show_")));
222
223 QActionGroup* rolesActionGroup = new QActionGroup(m_actionCollection);
224 rolesActionGroup->setExclusive(isSortGroup);
225 if (isSortGroup) {
226 connect(rolesActionGroup, SIGNAL(triggered(QAction*)),
227 this, SLOT(slotSortTriggered(QAction*)));
228 } else {
229 connect(rolesActionGroup, SIGNAL(triggered(QAction*)),
230 this, SLOT(toggleVisibleRole(QAction*)));
231 }
232
233 QString groupName;
234 KActionMenu* groupMenu = 0;
235 QActionGroup* groupMenuGroup = 0;
236
237 bool nepomukRunning = false;
238 bool indexingEnabled = false;
239 #ifdef HAVE_NEPOMUK
240 nepomukRunning = (Nepomuk::ResourceManager::instance()->init() == 0);
241 if (nepomukRunning) {
242 KConfig config("nepomukserverrc");
243 indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", false);
244 }
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, SIGNAL(triggered(QAction*)),
270 this, SLOT(slotSortTriggered(QAction*)));
271 } else {
272 connect(groupMenuGroup, SIGNAL(triggered(QAction*)),
273 this, SLOT(toggleVisibleRole(QAction*)));
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.requiresNepomuk && !info.requiresIndexer) ||
285 (info.requiresNepomuk && nepomukRunning) ||
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(KIcon(action->icon()));
306 }
307
308 void DolphinViewActionHandler::slotRename()
309 {
310 emit actionBeingHandled();
311 m_currentView->renameSelectedItems();
312 }
313
314 void DolphinViewActionHandler::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers modifiers)
315 {
316 emit actionBeingHandled();
317 // Note: kde3's konq_mainwindow.cpp used to check
318 // reason == KAction::PopupMenuActivation && ...
319 // but this isn't supported anymore
320 if (modifiers & Qt::ShiftModifier) {
321 m_currentView->deleteSelectedItems();
322 } else {
323 m_currentView->trashSelectedItems();
324 }
325 }
326
327 void DolphinViewActionHandler::slotDeleteItems()
328 {
329 emit actionBeingHandled();
330 m_currentView->deleteSelectedItems();
331 }
332
333 void DolphinViewActionHandler::togglePreview(bool show)
334 {
335 emit actionBeingHandled();
336 m_currentView->setPreviewsShown(show);
337 }
338
339 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown)
340 {
341 Q_UNUSED(shown);
342 // It is not enough to update the 'Show Preview' action, also
343 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
344 updateViewActions();
345 }
346
347 QString DolphinViewActionHandler::currentViewModeActionName() const
348 {
349 switch (m_currentView->mode()) {
350 case DolphinView::IconsView:
351 return "icons";
352 case DolphinView::DetailsView:
353 return "details";
354 case DolphinView::CompactView:
355 return "compact";
356 default:
357 Q_ASSERT(false);
358 break;
359 }
360 return QString(); // can't happen
361 }
362
363 KActionCollection* DolphinViewActionHandler::actionCollection()
364 {
365 return m_actionCollection;
366 }
367
368 void DolphinViewActionHandler::updateViewActions()
369 {
370 QAction* viewModeAction = m_actionCollection->action(currentViewModeActionName());
371 if (viewModeAction) {
372 viewModeAction->setChecked(true);
373
374 QAction* viewModeMenu = m_actionCollection->action("view_mode");
375 viewModeMenu->setIcon(KIcon(viewModeAction->icon()));
376 }
377
378 QAction* showPreviewAction = m_actionCollection->action("show_preview");
379 showPreviewAction->setChecked(m_currentView->previewsShown());
380
381 slotSortOrderChanged(m_currentView->sortOrder());
382 slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst());
383 slotVisibleRolesChanged(m_currentView->visibleRoles(), QList<QByteArray>());
384 slotGroupedSortingChanged(m_currentView->groupedSorting());
385 slotSortRoleChanged(m_currentView->sortRole());
386 slotZoomLevelChanged(m_currentView->zoomLevel(), -1);
387
388 QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
389 showHiddenFilesAction->setChecked(m_currentView->hiddenFilesShown());
390 }
391
392 void DolphinViewActionHandler::zoomIn()
393 {
394 const int level = m_currentView->zoomLevel();
395 m_currentView->setZoomLevel(level + 1);
396 updateViewActions();
397 }
398
399 void DolphinViewActionHandler::zoomOut()
400 {
401 const int level = m_currentView->zoomLevel();
402 m_currentView->setZoomLevel(level - 1);
403 updateViewActions();
404 }
405
406 void DolphinViewActionHandler::toggleSortOrder()
407 {
408 const Qt::SortOrder order = (m_currentView->sortOrder() == Qt::AscendingOrder) ?
409 Qt::DescendingOrder :
410 Qt::AscendingOrder;
411 m_currentView->setSortOrder(order);
412 }
413
414 void DolphinViewActionHandler::toggleSortFoldersFirst()
415 {
416 const bool sortFirst = m_currentView->sortFoldersFirst();
417 m_currentView->setSortFoldersFirst(!sortFirst);
418 }
419
420 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order)
421 {
422 QAction* descending = m_actionCollection->action("descending");
423 const bool sortDescending = (order == Qt::DescendingOrder);
424 descending->setChecked(sortDescending);
425 }
426
427 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
428 {
429 m_actionCollection->action("folders_first")->setChecked(foldersFirst);
430 }
431
432 void DolphinViewActionHandler::toggleVisibleRole(QAction* action)
433 {
434 emit actionBeingHandled();
435
436 const QByteArray toggledRole = action->data().toByteArray();
437
438 QList<QByteArray> roles = m_currentView->visibleRoles();
439
440 const bool show = action->isChecked();
441
442 const int index = roles.indexOf(toggledRole);
443 const bool containsInfo = (index >= 0);
444 if (show && !containsInfo) {
445 roles.append(toggledRole);
446 m_currentView->setVisibleRoles(roles);
447 } else if (!show && containsInfo) {
448 roles.removeAt(index);
449 m_currentView->setVisibleRoles(roles);
450 Q_ASSERT(roles.indexOf(toggledRole) < 0);
451 }
452 }
453
454 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList<QByteArray>& current,
455 const QList<QByteArray>& previous)
456 {
457 Q_UNUSED(previous);
458
459 const QSet<QByteArray> checkedRoles = current.toSet();
460 QHashIterator<QByteArray, KToggleAction*> it(m_visibleRoles);
461 while (it.hasNext()) {
462 it.next();
463 const QByteArray& role = it.key();
464 KToggleAction* action = it.value();
465 action->setChecked(checkedRoles.contains(role));
466 }
467 }
468
469 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped)
470 {
471 m_currentView->setGroupedSorting(grouped);
472 }
473
474 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting)
475 {
476 QAction* showInGroupsAction = m_actionCollection->action("show_in_groups");
477 showInGroupsAction->setChecked(groupedSorting);
478 }
479
480 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show)
481 {
482 emit actionBeingHandled();
483 m_currentView->setHiddenFilesShown(show);
484 }
485
486 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
487 {
488 QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
489 showHiddenFilesAction->setChecked(shown);
490 }
491
492 KToggleAction* DolphinViewActionHandler::iconsModeAction()
493 {
494 KToggleAction* iconsView = m_actionCollection->add<KToggleAction>("icons");
495 iconsView->setText(i18nc("@action:inmenu View Mode", "Icons"));
496 iconsView->setToolTip(i18nc("@info", "Icons view mode"));
497 iconsView->setShortcut(Qt::CTRL | Qt::Key_1);
498 iconsView->setIcon(KIcon("view-list-icons"));
499 iconsView->setData(QVariant::fromValue(DolphinView::IconsView));
500 return iconsView;
501 }
502
503 KToggleAction* DolphinViewActionHandler::compactModeAction()
504 {
505 KToggleAction* iconsView = m_actionCollection->add<KToggleAction>("compact");
506 iconsView->setText(i18nc("@action:inmenu View Mode", "Compact"));
507 iconsView->setToolTip(i18nc("@info", "Compact view mode"));
508 iconsView->setShortcut(Qt::CTRL | Qt::Key_2);
509 iconsView->setIcon(KIcon("view-list-details")); // TODO: discuss with Oxygen-team the wrong (?) name
510 iconsView->setData(QVariant::fromValue(DolphinView::CompactView));
511 return iconsView;
512 }
513
514 KToggleAction* DolphinViewActionHandler::detailsModeAction()
515 {
516 KToggleAction* detailsView = m_actionCollection->add<KToggleAction>("details");
517 detailsView->setText(i18nc("@action:inmenu View Mode", "Details"));
518 detailsView->setToolTip(i18nc("@info", "Details view mode"));
519 detailsView->setShortcut(Qt::CTRL | Qt::Key_3);
520 detailsView->setIcon(KIcon("view-list-tree"));
521 detailsView->setData(QVariant::fromValue(DolphinView::DetailsView));
522 return detailsView;
523 }
524
525 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
526 {
527 KToggleAction* action = m_sortByActions.value(role);
528 if (action) {
529 action->setChecked(true);
530
531 QAction* sortByMenu = m_actionCollection->action("sort");
532 sortByMenu->setIcon(KIcon(action->icon()));
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 KUrl 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 }