1 /***************************************************************************
2 * Copyright (C) 2008 by David Faure <faure@kde.org> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinviewactionhandler.h"
22 #include "dolphinview.h"
24 #include <konq_operations.h>
27 #include <kactioncollection.h>
29 #include <ktoggleaction.h>
31 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
)
33 m_actionCollection(collection
),
36 Q_ASSERT(m_actionCollection
);
40 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
45 disconnect(m_currentView
, 0, this, 0);
49 connect(view
, SIGNAL(showPreviewChanged()),
50 this, SLOT(slotShowPreviewChanged()));
51 connect(view
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
52 this, SLOT(slotSortOrderChanged(Qt::SortOrder
)));
53 connect(view
, SIGNAL(additionalInfoChanged()),
54 this, SLOT(slotAdditionalInfoChanged()));
55 connect(view
, SIGNAL(categorizedSortingChanged()),
56 this, SLOT(slotCategorizedSortingChanged()));
57 connect(view
, SIGNAL(showHiddenFilesChanged()),
58 this, SLOT(slotShowHiddenFilesChanged()));
61 void DolphinViewActionHandler::createActions()
63 // This action doesn't appear in the GUI, it's for the shortcut only.
64 // KNewMenu takes care of the GUI stuff.
65 KAction
* newDirAction
= m_actionCollection
->addAction("create_dir");
66 newDirAction
->setText(i18n("Create Folder..."));
67 newDirAction
->setShortcut(Qt::Key_F10
);
68 connect(newDirAction
, SIGNAL(triggered()), SLOT(slotCreateDir()));
72 KAction
* rename
= m_actionCollection
->addAction("rename");
73 rename
->setText(i18nc("@action:inmenu File", "Rename..."));
74 rename
->setShortcut(Qt::Key_F2
);
75 connect(rename
, SIGNAL(triggered()), this, SLOT(slotRename()));
77 KAction
* moveToTrash
= m_actionCollection
->addAction("move_to_trash");
78 moveToTrash
->setText(i18nc("@action:inmenu File", "Move to Trash"));
79 moveToTrash
->setIcon(KIcon("user-trash"));
80 moveToTrash
->setShortcut(QKeySequence::Delete
);
81 connect(moveToTrash
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)),
82 this, SLOT(slotTrashActivated(Qt::MouseButtons
, Qt::KeyboardModifiers
)));
84 KAction
* deleteAction
= m_actionCollection
->addAction("delete");
85 deleteAction
->setIcon(KIcon("edit-delete"));
86 deleteAction
->setText(i18nc("@action:inmenu File", "Delete"));
87 deleteAction
->setShortcut(Qt::SHIFT
| Qt::Key_Delete
);
88 connect(deleteAction
, SIGNAL(triggered()), this, SLOT(slotDeleteItems()));
92 KStandardAction::zoomIn(this,
96 KStandardAction::zoomOut(this,
100 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>("show_preview");
101 showPreview
->setText(i18nc("@action:intoolbar", "Preview"));
102 showPreview
->setIcon(KIcon("view-preview"));
103 connect(showPreview
, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool)));
105 KToggleAction
* sortDescending
= m_actionCollection
->add
<KToggleAction
>("descending");
106 sortDescending
->setText(i18nc("@action:inmenu Sort", "Descending"));
107 connect(sortDescending
, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
109 QActionGroup
* showInformationActionGroup
= createAdditionalInformationActionGroup();
110 connect(showInformationActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(toggleAdditionalInfo(QAction
*)));
112 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>("show_in_groups");
113 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
114 connect(showInGroups
, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool)));
116 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>("show_hidden_files");
117 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
118 showHiddenFiles
->setShortcut(Qt::ALT
| Qt::Key_Period
);
119 connect(showHiddenFiles
, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool)));
123 QActionGroup
* DolphinViewActionHandler::createAdditionalInformationActionGroup()
125 QActionGroup
* showInformationGroup
= new QActionGroup(m_actionCollection
);
126 showInformationGroup
->setExclusive(false);
128 KToggleAction
* showSizeInfo
= m_actionCollection
->add
<KToggleAction
>("show_size_info");
129 showSizeInfo
->setText(i18nc("@action:inmenu Additional information", "Size"));
130 showSizeInfo
->setData(KFileItemDelegate::Size
);
131 showSizeInfo
->setActionGroup(showInformationGroup
);
133 KToggleAction
* showDateInfo
= m_actionCollection
->add
<KToggleAction
>("show_date_info");
134 showDateInfo
->setText(i18nc("@action:inmenu Additional information", "Date"));
135 showDateInfo
->setData(KFileItemDelegate::ModificationTime
);
136 showDateInfo
->setActionGroup(showInformationGroup
);
138 KToggleAction
* showPermissionsInfo
= m_actionCollection
->add
<KToggleAction
>("show_permissions_info");
139 showPermissionsInfo
->setText(i18nc("@action:inmenu Additional information", "Permissions"));
140 showPermissionsInfo
->setData(KFileItemDelegate::Permissions
);
141 showPermissionsInfo
->setActionGroup(showInformationGroup
);
143 KToggleAction
* showOwnerInfo
= m_actionCollection
->add
<KToggleAction
>("show_owner_info");
144 showOwnerInfo
->setText(i18nc("@action:inmenu Additional information", "Owner"));
145 showOwnerInfo
->setData(KFileItemDelegate::Owner
);
146 showOwnerInfo
->setActionGroup(showInformationGroup
);
148 KToggleAction
* showGroupInfo
= m_actionCollection
->add
<KToggleAction
>("show_group_info");
149 showGroupInfo
->setText(i18nc("@action:inmenu Additional information", "Group"));
150 showGroupInfo
->setData(KFileItemDelegate::OwnerAndGroup
);
151 showGroupInfo
->setActionGroup(showInformationGroup
);
153 KToggleAction
* showMimeInfo
= m_actionCollection
->add
<KToggleAction
>("show_mime_info");
154 showMimeInfo
->setText(i18nc("@action:inmenu Additional information", "Type"));
155 showMimeInfo
->setData(KFileItemDelegate::FriendlyMimeType
);
156 showMimeInfo
->setActionGroup(showInformationGroup
);
158 return showInformationGroup
;
161 void DolphinViewActionHandler::slotCreateDir()
163 Q_ASSERT(m_currentView
);
164 KonqOperations::newDir(m_currentView
, m_currentView
->url());
167 void DolphinViewActionHandler::slotRename()
169 emit
actionBeingHandled();
170 m_currentView
->renameSelectedItems();
173 void DolphinViewActionHandler::slotTrashActivated(Qt::MouseButtons
, Qt::KeyboardModifiers modifiers
)
175 emit
actionBeingHandled();
176 // Note: kde3's konq_mainwindow.cpp used to check
177 // reason == KAction::PopupMenuActivation && ...
178 // but this isn't supported anymore
179 if (modifiers
& Qt::ShiftModifier
)
180 m_currentView
->deleteSelectedItems();
182 m_currentView
->trashSelectedItems();
185 void DolphinViewActionHandler::slotDeleteItems()
187 emit
actionBeingHandled();
188 m_currentView
->deleteSelectedItems();
191 void DolphinViewActionHandler::togglePreview(bool show
)
193 emit
actionBeingHandled();
194 m_currentView
->setShowPreview(show
);
197 void DolphinViewActionHandler::slotShowPreviewChanged()
199 // It is not enough to update the 'Show Preview' action, also
200 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
204 void DolphinViewActionHandler::updateViewActions()
206 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::stdName(KStandardAction::ZoomIn
));
207 if (zoomInAction
!= 0) {
208 zoomInAction
->setEnabled(m_currentView
->isZoomInPossible());
211 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::stdName(KStandardAction::ZoomOut
));
212 if (zoomOutAction
!= 0) {
213 zoomOutAction
->setEnabled(m_currentView
->isZoomOutPossible());
216 QAction
* showPreviewAction
= m_actionCollection
->action("show_preview");
217 showPreviewAction
->setChecked(m_currentView
->showPreview());
219 slotSortOrderChanged(m_currentView
->sortOrder());
220 slotAdditionalInfoChanged();
221 slotCategorizedSortingChanged();
223 QAction
* showHiddenFilesAction
= m_actionCollection
->action("show_hidden_files");
224 showHiddenFilesAction
->setChecked(m_currentView
->showHiddenFiles());
228 void DolphinViewActionHandler::zoomIn()
230 m_currentView
->zoomIn();
234 void DolphinViewActionHandler::zoomOut()
236 m_currentView
->zoomOut();
240 void DolphinViewActionHandler::toggleSortOrder()
242 m_currentView
->toggleSortOrder();
245 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
247 QAction
* descending
= m_actionCollection
->action("descending");
248 const bool sortDescending
= (order
== Qt::DescendingOrder
);
249 descending
->setChecked(sortDescending
);
252 void DolphinViewActionHandler::toggleAdditionalInfo(QAction
* action
)
254 emit
actionBeingHandled();
255 m_currentView
->toggleAdditionalInfo(action
);
258 void DolphinViewActionHandler::slotAdditionalInfoChanged()
260 m_currentView
->updateAdditionalInfoActions(m_actionCollection
);
263 void DolphinViewActionHandler::toggleSortCategorization(bool categorizedSorting
)
265 m_currentView
->setCategorizedSorting(categorizedSorting
);
268 void DolphinViewActionHandler::slotCategorizedSortingChanged()
270 QAction
* showInGroupsAction
= m_actionCollection
->action("show_in_groups");
271 showInGroupsAction
->setChecked(m_currentView
->categorizedSorting());
272 showInGroupsAction
->setEnabled(m_currentView
->supportsCategorizedSorting());
275 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
277 emit
actionBeingHandled();
278 m_currentView
->setShowHiddenFiles(show
);
281 void DolphinViewActionHandler::slotShowHiddenFilesChanged()
283 QAction
* showHiddenFilesAction
= m_actionCollection
->action("show_hidden_files");
284 showHiddenFilesAction
->setChecked(m_currentView
->showHiddenFiles());