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