1 /***************************************************************************
2 * Copyright (C) 2008 by David Faure <faure@kde.org> *
3 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
21 #include "dolphinviewactionhandler.h"
23 #include "dolphindebug.h"
24 #include "kitemviews/kfileitemmodel.h"
25 #include "settings/viewpropertiesdialog.h"
26 #include "views/zoomlevelinfo.h"
29 #include <Baloo/IndexerConfig>
31 #include <KActionCollection>
32 #include <KActionMenu>
33 #include <KLocalizedString>
34 #include <KNewFileMenu>
35 #include <KPropertiesDialog>
36 #include <KProtocolManager>
41 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
43 m_actionCollection(collection
),
44 m_currentView(nullptr),
48 Q_ASSERT(m_actionCollection
);
52 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
57 disconnect(m_currentView
, nullptr, this, nullptr);
62 connect(view
, &DolphinView::modeChanged
,
63 this, &DolphinViewActionHandler::updateViewActions
);
64 connect(view
, &DolphinView::previewsShownChanged
,
65 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
66 connect(view
, &DolphinView::sortOrderChanged
,
67 this, &DolphinViewActionHandler::slotSortOrderChanged
);
68 connect(view
, &DolphinView::sortFoldersFirstChanged
,
69 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
70 connect(view
, &DolphinView::visibleRolesChanged
,
71 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
72 connect(view
, &DolphinView::groupedSortingChanged
,
73 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
74 connect(view
, &DolphinView::hiddenFilesShownChanged
,
75 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
76 connect(view
, &DolphinView::sortRoleChanged
,
77 this, &DolphinViewActionHandler::slotSortRoleChanged
);
78 connect(view
, &DolphinView::zoomLevelChanged
,
79 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
80 connect(view
, &DolphinView::writeStateChanged
,
81 this, &DolphinViewActionHandler::slotWriteStateChanged
);
84 DolphinView
* DolphinViewActionHandler::currentView()
89 void DolphinViewActionHandler::createActions()
91 // This action doesn't appear in the GUI, it's for the shortcut only.
92 // KNewFileMenu takes care of the GUI stuff.
93 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
94 newDirAction
->setText(i18nc("@action", "Create Folder..."));
95 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
96 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
97 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
98 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
102 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
103 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
104 "items in your current selection.<nl/>Renaming multiple items "
105 "at once amounts to their new names differing only in a number."));
107 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
108 auto trashShortcuts
= trashAction
->shortcuts();
109 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
110 trashShortcuts
.append(QKeySequence::Delete
);
111 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
113 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
114 "items in your current selection to the <filename>Trash"
115 "</filename>.<nl/>The trash is a temporary storage where "
116 "items can be deleted from if disk space is needed."));
118 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
119 auto deleteShortcuts
= deleteAction
->shortcuts();
120 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
121 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
122 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
124 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
125 "the items in your current selection completely. They can "
126 "not be recovered by normal means."));
128 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
129 // disabled and KStandardAction::DeleteFile 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(QStringLiteral("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
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
136 deleteWithTrashShortcut
->setEnabled(false);
137 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
139 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("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
->setWhatsThis(xi18nc("@info:whatsthis properties",
143 "This shows a complete list of properties of the currently "
144 "selected items in a new window.<nl/>If nothing is selected the "
145 "window will be about the currently viewed folder instead.<nl/>"
146 "You can configure advanced options there like managing "
147 "read- and write-permissions."));
148 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
149 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
150 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
153 KToggleAction
* iconsAction
= iconsModeAction();
154 KToggleAction
* compactAction
= compactModeAction();
155 KToggleAction
* detailsAction
= detailsModeAction();
157 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
158 "<para>This switches to a view mode that focuses on the folder "
159 "and file icons. This mode makes it easy to distinguish folders "
160 "from files and to detect items with distinctive <emphasis>"
161 "file types</emphasis>.</para><para> This mode is handy to "
162 "browse through pictures when the <interface>Preview"
163 "</interface> option is enabled.</para>"));
164 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
165 "<para>This switches to a compact view mode that lists the folders "
166 "and files in columns with the names beside the icons. <para></para>"
167 "This helps to keep the overview in folders with many items.</para>"));
168 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
169 "<para>This switches to a list view mode that focuses on folder "
170 "and file details.</para><para>Click on a detail in the column "
171 "header to sort the items by it. Click again to sort the other "
172 "way around. To select which details should be displayed click "
173 "the header with the right mouse button.</para><para>You can "
174 "view the contents of a folder without leaving the current "
175 "location by clicking to the left of it. This way you can view "
176 "the contents of multiple folders in the same list.</para>"));
178 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
179 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
180 viewModeActions
->addAction(iconsAction
);
181 viewModeActions
->addAction(compactAction
);
182 viewModeActions
->addAction(detailsAction
);
183 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
184 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
186 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
187 &DolphinViewActionHandler::zoomIn
,
189 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
191 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
192 &DolphinViewActionHandler::zoomOut
,
194 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This reduces the icon size."));
196 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
197 showPreview
->setText(i18nc("@action:intoolbar", "Preview"));
198 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
199 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
200 "enabled, the icons are based on the actual file or folder "
201 "contents.<nl/>For example the icons of images become scaled "
202 "down versions of the images."));
203 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
204 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
206 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
207 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
208 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
211 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
213 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
214 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
215 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
216 sortByActionMenu
->setDelayed(false);
218 foreach (QAction
* action
, sortByActionGroup
->actions()) {
219 sortByActionMenu
->addAction(action
);
222 sortByActionMenu
->addSeparator();
224 QActionGroup
* group
= new QActionGroup(sortByActionMenu
);
225 group
->setExclusive(true);
227 KToggleAction
* ascendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("ascending"));
228 ascendingAction
->setActionGroup(group
);
229 connect(ascendingAction
, &QAction::triggered
, this, [this] {
230 m_currentView
->setSortOrder(Qt::AscendingOrder
);
233 KToggleAction
* descendingAction
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
234 descendingAction
->setActionGroup(group
);
235 connect(descendingAction
, &QAction::triggered
, this, [this] {
236 m_currentView
->setSortOrder(Qt::DescendingOrder
);
239 sortByActionMenu
->addAction(ascendingAction
);
240 sortByActionMenu
->addAction(descendingAction
);
241 sortByActionMenu
->addSeparator();
242 sortByActionMenu
->addAction(sortFoldersFirst
);
244 // View -> Additional Information
245 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
247 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
248 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Additional Information"));
249 visibleRolesMenu
->setDelayed(false);
251 foreach (QAction
* action
, visibleRolesGroup
->actions()) {
252 visibleRolesMenu
->addAction(action
);
255 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
256 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
257 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
258 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
259 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
261 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
262 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Hidden Files"));
263 showHiddenFiles
->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
264 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
265 "this is enabled <emphasis>hidden</emphasis> files and folders "
266 "are visible. They will be displayed semi-transparent.</para>"
267 "<para>Hidden items only differ from other ones in that their "
268 "name starts with a \".\". In general there is no need for "
269 "users to access them which is why they are hidden.</para>"));
270 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, {Qt::ALT
+ Qt::Key_Period
, Qt::CTRL
+ Qt::Key_H
, Qt::Key_F8
});
271 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
273 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
274 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
275 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
276 "in which all folder view properties can be adjusted."));
277 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
280 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
282 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
283 Q_ASSERT(isSortGroup
|| (!isSortGroup
&& groupPrefix
== QLatin1String("show_")));
285 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
286 rolesActionGroup
->setExclusive(isSortGroup
);
288 connect(rolesActionGroup
, &QActionGroup::triggered
,
289 this, &DolphinViewActionHandler::slotSortTriggered
);
291 connect(rolesActionGroup
, &QActionGroup::triggered
,
292 this, &DolphinViewActionHandler::toggleVisibleRole
);
296 KActionMenu
* groupMenu
= nullptr;
297 QActionGroup
* groupMenuGroup
= nullptr;
299 bool indexingEnabled
= false;
301 Baloo::IndexerConfig config
;
302 indexingEnabled
= config
.fileIndexingEnabled();
305 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
306 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
307 if (!isSortGroup
&& info
.role
== "text") {
308 // It should not be possible to hide the "text" role
312 KToggleAction
* action
= nullptr;
313 const QString name
= groupPrefix
+ info
.role
;
314 if (info
.group
.isEmpty()) {
315 action
= m_actionCollection
->add
<KToggleAction
>(name
);
316 action
->setActionGroup(rolesActionGroup
);
318 if (!groupMenu
|| info
.group
!= groupName
) {
319 groupName
= info
.group
;
320 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
321 groupMenu
->setText(groupName
);
322 groupMenu
->setActionGroup(rolesActionGroup
);
324 groupMenuGroup
= new QActionGroup(groupMenu
);
325 groupMenuGroup
->setExclusive(isSortGroup
);
327 connect(groupMenuGroup
, &QActionGroup::triggered
,
328 this, &DolphinViewActionHandler::slotSortTriggered
);
330 connect(groupMenuGroup
, &QActionGroup::triggered
,
331 this, &DolphinViewActionHandler::toggleVisibleRole
);
335 action
= new KToggleAction(groupMenu
);
336 action
->setActionGroup(groupMenuGroup
);
337 groupMenu
->addAction(action
);
339 action
->setText(info
.translation
);
340 action
->setData(info
.role
);
342 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
343 (info
.requiresBaloo
) ||
344 (info
.requiresIndexer
&& indexingEnabled
);
345 action
->setEnabled(enable
);
348 m_sortByActions
.insert(info
.role
, action
);
350 m_visibleRoles
.insert(info
.role
, action
);
354 return rolesActionGroup
;
357 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
359 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
360 m_currentView
->setMode(mode
);
362 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
363 viewModeMenu
->setIcon(action
->icon());
366 void DolphinViewActionHandler::slotRename()
368 emit
actionBeingHandled();
369 m_currentView
->renameSelectedItems();
372 void DolphinViewActionHandler::slotTrashActivated()
374 emit
actionBeingHandled();
375 m_currentView
->trashSelectedItems();
378 void DolphinViewActionHandler::slotDeleteItems()
380 emit
actionBeingHandled();
381 m_currentView
->deleteSelectedItems();
384 void DolphinViewActionHandler::togglePreview(bool show
)
386 emit
actionBeingHandled();
387 m_currentView
->setPreviewsShown(show
);
390 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
393 // It is not enough to update the 'Show Preview' action, also
394 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
398 QString
DolphinViewActionHandler::currentViewModeActionName() const
400 switch (m_currentView
->mode()) {
401 case DolphinView::IconsView
:
402 return QStringLiteral("icons");
403 case DolphinView::DetailsView
:
404 return QStringLiteral("details");
405 case DolphinView::CompactView
:
406 return QStringLiteral("compact");
411 return QString(); // can't happen
414 KActionCollection
* DolphinViewActionHandler::actionCollection()
416 return m_actionCollection
;
419 void DolphinViewActionHandler::updateViewActions()
421 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
422 if (viewModeAction
) {
423 viewModeAction
->setChecked(true);
425 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
426 viewModeMenu
->setIcon(viewModeAction
->icon());
429 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
430 showPreviewAction
->setChecked(m_currentView
->previewsShown());
432 slotSortOrderChanged(m_currentView
->sortOrder());
433 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
434 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
435 slotGroupedSortingChanged(m_currentView
->groupedSorting());
436 slotSortRoleChanged(m_currentView
->sortRole());
437 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
439 // Updates the "show_hidden_files" action state and icon
440 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
443 void DolphinViewActionHandler::zoomIn()
445 const int level
= m_currentView
->zoomLevel();
446 m_currentView
->setZoomLevel(level
+ 1);
450 void DolphinViewActionHandler::zoomOut()
452 const int level
= m_currentView
->zoomLevel();
453 m_currentView
->setZoomLevel(level
- 1);
457 void DolphinViewActionHandler::toggleSortFoldersFirst()
459 const bool sortFirst
= m_currentView
->sortFoldersFirst();
460 m_currentView
->setSortFoldersFirst(!sortFirst
);
463 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
465 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
466 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
467 const bool sortDescending
= (order
== Qt::DescendingOrder
);
468 descending
->setChecked(sortDescending
);
469 ascending
->setChecked(!sortDescending
);
472 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
474 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
477 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
479 emit
actionBeingHandled();
481 const QByteArray toggledRole
= action
->data().toByteArray();
483 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
485 const bool show
= action
->isChecked();
487 const int index
= roles
.indexOf(toggledRole
);
488 const bool containsInfo
= (index
>= 0);
489 if (show
&& !containsInfo
) {
490 roles
.append(toggledRole
);
491 m_currentView
->setVisibleRoles(roles
);
492 } else if (!show
&& containsInfo
) {
493 roles
.removeAt(index
);
494 m_currentView
->setVisibleRoles(roles
);
495 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
499 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
500 const QList
<QByteArray
>& previous
)
504 const QSet
<QByteArray
> checkedRoles
= current
.toSet();
505 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
506 while (it
.hasNext()) {
508 const QByteArray
& role
= it
.key();
509 KToggleAction
* action
= it
.value();
510 action
->setChecked(checkedRoles
.contains(role
));
514 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
516 m_currentView
->setGroupedSorting(grouped
);
519 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
521 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
522 showInGroupsAction
->setChecked(groupedSorting
);
525 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
527 emit
actionBeingHandled();
528 m_currentView
->setHiddenFilesShown(show
);
531 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
533 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
534 showHiddenFilesAction
->setChecked(shown
);
536 // #374508: don't overwrite custom icons.
537 const QString iconName
= showHiddenFilesAction
->icon().name();
538 if (!iconName
.isEmpty() && iconName
!= QLatin1String("visibility") && iconName
!= QLatin1String("hint")) {
542 showHiddenFilesAction
->setIcon(QIcon::fromTheme(shown
? QStringLiteral("visibility") : QStringLiteral("hint")));
545 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
547 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
548 KProtocolManager::supportsMakeDir(currentView()->url()));
551 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
553 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
554 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
555 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
556 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
557 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
558 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
562 KToggleAction
* DolphinViewActionHandler::compactModeAction()
564 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
565 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
566 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
567 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
568 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
569 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
573 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
575 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
576 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
577 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
578 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
579 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
580 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
584 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
586 KToggleAction
* action
= m_sortByActions
.value(role
);
588 action
->setChecked(true);
590 if (!action
->icon().isNull()) {
591 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
592 sortByMenu
->setIcon(action
->icon());
596 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
597 QAction
* ascending
= m_actionCollection
->action(QStringLiteral("ascending"));
599 if (role
== "text" || role
== "type" || role
== "tags" || role
== "comment") {
600 descending
->setText(i18nc("Sort descending", "Z-A"));
601 ascending
->setText(i18nc("Sort ascending", "A-Z"));
602 } else if (role
== "size") {
603 descending
->setText(i18nc("Sort descending", "Largest first"));
604 ascending
->setText(i18nc("Sort ascending", "Smallest first"));
605 } else if (role
== "modificationtime" || role
== "creationtime" || role
== "accesstime") {
606 descending
->setText(i18nc("Sort descending", "Newest first"));
607 ascending
->setText(i18nc("Sort ascending", "Oldest first"));
608 } else if (role
== "rating") {
609 descending
->setText(i18nc("Sort descending", "Highest first"));
610 ascending
->setText(i18nc("Sort ascending", "Lowest first"));
612 descending
->setText(i18nc("Sort descending", "Descending"));
613 ascending
->setText(i18nc("Sort ascending", "Ascending"));
616 slotSortOrderChanged(m_currentView
->sortOrder());
619 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
623 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
625 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
628 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
630 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
634 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
636 // The radiobuttons of the "Sort By"-menu are split between the main-menu
637 // and several sub-menus. Because of this they don't have a common
638 // action-group that assures an exclusive toggle-state between the main-menu
639 // actions and the sub-menu-actions. If an action gets checked, it must
640 // be assured that all other actions get unchecked, except the ascending/
641 // descending actions
642 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
643 for (QAction
*groupAction
: qAsConst(m_sortByActions
)) {
644 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
646 foreach (QAction
* subAction
, actionMenu
->menu()->actions()) {
647 subAction
->setChecked(false);
649 } else if (groupAction
->actionGroup()) {
650 groupAction
->setChecked(false);
653 action
->setChecked(true);
655 // Apply the activated sort-role to the view
656 const QByteArray role
= action
->data().toByteArray();
657 m_currentView
->setSortRole(role
);
660 void DolphinViewActionHandler::slotAdjustViewProperties()
662 emit
actionBeingHandled();
663 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
668 void DolphinViewActionHandler::slotProperties()
670 KPropertiesDialog
* dialog
= nullptr;
671 const KFileItemList list
= m_currentView
->selectedItems();
672 if (list
.isEmpty()) {
673 const QUrl url
= m_currentView
->url();
674 dialog
= new KPropertiesDialog(url
, m_currentView
);
676 dialog
= new KPropertiesDialog(list
, m_currentView
);
679 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
682 dialog
->activateWindow();