2 * SPDX-FileCopyrightText: 2006-2009 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Gregor Kališnik <gregor@podnapisi.net>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #include "dolphinview.h"
10 #include "dolphin_generalsettings.h"
11 #include "dolphin_detailsmodesettings.h"
12 #include "dolphinitemlistview.h"
13 #include "dolphinnewfilemenuobserver.h"
14 #include "draganddrophelper.h"
15 #include "kitemviews/kfileitemlistview.h"
16 #include "kitemviews/kfileitemmodel.h"
17 #include "kitemviews/kitemlistcontainer.h"
18 #include "kitemviews/kitemlistcontroller.h"
19 #include "kitemviews/kitemlistheader.h"
20 #include "kitemviews/kitemlistselectionmanager.h"
21 #include "kitemviews/private/kitemlistroleeditor.h"
22 #include "settings/viewmodes/viewmodesettings.h"
23 #include "selectionmode/singleclickselectionproxystyle.h"
24 #include "versioncontrol/versioncontrolobserver.h"
25 #include "viewproperties.h"
26 #include "views/tooltips/tooltipmanager.h"
27 #include "zoomlevelinfo.h"
30 #include <Baloo/IndexerConfig>
32 #include <KColorScheme>
33 #include <KDesktopFile>
35 #include <KFileItemListProperties>
37 #include <KIO/CopyJob>
38 #include <KIO/DeleteJob>
39 #include <KIO/DropJob>
40 #include <KIO/JobUiDelegate>
42 #include <KIO/PasteJob>
43 #include <KIO/RenameFileDialog>
44 #include <KJobWidgets>
45 #include <KLocalizedString>
46 #include <KMessageBox>
47 #include <KProtocolManager>
48 #include <KUrlMimeData>
50 #include <QAbstractItemView>
51 #include <QActionGroup>
52 #include <QApplication>
55 #include <QGraphicsOpacityEffect>
56 #include <QGraphicsSceneDragDropEvent>
59 #include <QMimeDatabase>
60 #include <QPixmapCache>
65 #include <QVBoxLayout>
67 DolphinView::DolphinView(const QUrl
& url
, QWidget
* parent
) :
70 m_tabsForFiles(false),
71 m_assureVisibleCurrentIndex(false),
72 m_isFolderWritable(true),
75 m_viewPropertiesContext(),
76 m_mode(DolphinView::IconsView
),
82 m_toolTipManager(nullptr),
83 m_selectionChangedTimer(nullptr),
85 m_scrollToCurrentItem(false),
86 m_restoredContentsPosition(),
88 m_clearSelectionBeforeSelectingNewItems(false),
89 m_markFirstNewlySelectedItemAsCurrent(false),
90 m_versionControlObserver(nullptr),
91 m_twoClicksRenamingTimer(nullptr),
92 m_placeholderLabel(nullptr),
93 m_showLoadingPlaceholderTimer(nullptr)
95 m_topLayout
= new QVBoxLayout(this);
96 m_topLayout
->setSpacing(0);
97 m_topLayout
->setContentsMargins(0, 0, 0, 0);
99 // When a new item has been created by the "Create New..." menu, the item should
100 // get selected and it must be assured that the item will get visible. As the
101 // creation is done asynchronously, several signals must be checked:
102 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated
,
103 this, &DolphinView::observeCreatedItem
);
105 m_selectionChangedTimer
= new QTimer(this);
106 m_selectionChangedTimer
->setSingleShot(true);
107 m_selectionChangedTimer
->setInterval(300);
108 connect(m_selectionChangedTimer
, &QTimer::timeout
,
109 this, &DolphinView::emitSelectionChangedSignal
);
111 m_model
= new KFileItemModel(this);
112 m_view
= new DolphinItemListView();
113 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting
);
114 m_view
->setVisibleRoles({"text"});
117 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
118 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
119 controller
->setAutoActivationDelay(delay
);
121 // The EnlargeSmallPreviews setting can only be changed after the model
122 // has been set in the view by KItemListController.
123 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
125 m_container
= new KItemListContainer(controller
, this);
126 m_container
->installEventFilter(this);
127 setFocusProxy(m_container
);
128 connect(m_container
->horizontalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
129 connect(m_container
->verticalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
131 m_showLoadingPlaceholderTimer
= new QTimer(this);
132 m_showLoadingPlaceholderTimer
->setInterval(500);
133 m_showLoadingPlaceholderTimer
->setSingleShot(true);
134 connect(m_showLoadingPlaceholderTimer
, &QTimer::timeout
, this, &DolphinView::showLoadingPlaceholder
);
136 // Show some placeholder text for empty folders
137 // This is made using a heavily-modified QLabel rather than a KTitleWidget
138 // because KTitleWidget can't be told to turn off mouse-selectable text
139 m_placeholderLabel
= new QLabel(this);
140 QFont placeholderLabelFont
;
141 // To match the size of a level 2 Heading/KTitleWidget
142 placeholderLabelFont
.setPointSize(qRound(placeholderLabelFont
.pointSize() * 1.3));
143 m_placeholderLabel
->setFont(placeholderLabelFont
);
144 m_placeholderLabel
->setTextInteractionFlags(Qt::NoTextInteraction
);
145 m_placeholderLabel
->setWordWrap(true);
146 m_placeholderLabel
->setAlignment(Qt::AlignCenter
);
147 // Match opacity of QML placeholder label component
148 auto *effect
= new QGraphicsOpacityEffect(m_placeholderLabel
);
149 effect
->setOpacity(0.5);
150 m_placeholderLabel
->setGraphicsEffect(effect
);
151 // Set initial text and visibility
152 updatePlaceholderLabel();
154 auto *centeringLayout
= new QVBoxLayout(m_container
);
155 centeringLayout
->addWidget(m_placeholderLabel
);
156 centeringLayout
->setAlignment(m_placeholderLabel
, Qt::AlignCenter
);
158 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
159 connect(controller
, &KItemListController::itemActivated
, this, &DolphinView::slotItemActivated
);
160 connect(controller
, &KItemListController::itemsActivated
, this, &DolphinView::slotItemsActivated
);
161 connect(controller
, &KItemListController::itemMiddleClicked
, this, &DolphinView::slotItemMiddleClicked
);
162 connect(controller
, &KItemListController::itemContextMenuRequested
, this, &DolphinView::slotItemContextMenuRequested
);
163 connect(controller
, &KItemListController::viewContextMenuRequested
, this, &DolphinView::slotViewContextMenuRequested
);
164 connect(controller
, &KItemListController::headerContextMenuRequested
, this, &DolphinView::slotHeaderContextMenuRequested
);
165 connect(controller
, &KItemListController::mouseButtonPressed
, this, &DolphinView::slotMouseButtonPressed
);
166 connect(controller
, &KItemListController::itemHovered
, this, &DolphinView::slotItemHovered
);
167 connect(controller
, &KItemListController::itemUnhovered
, this, &DolphinView::slotItemUnhovered
);
168 connect(controller
, &KItemListController::itemDropEvent
, this, &DolphinView::slotItemDropEvent
);
169 connect(controller
, &KItemListController::escapePressed
, this, &DolphinView::stopLoading
);
170 connect(controller
, &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
171 connect(controller
, &KItemListController::selectedItemTextPressed
, this, &DolphinView::slotSelectedItemTextPressed
);
172 connect(controller
, &KItemListController::increaseZoom
, this, &DolphinView::slotIncreaseZoom
);
173 connect(controller
, &KItemListController::decreaseZoom
, this, &DolphinView::slotDecreaseZoom
);
174 connect(controller
, &KItemListController::swipeUp
, this, &DolphinView::slotSwipeUp
);
175 connect(controller
, &KItemListController::selectionModeChangeRequested
, this, &DolphinView::selectionModeChangeRequested
);
177 connect(m_model
, &KFileItemModel::directoryLoadingStarted
, this, &DolphinView::slotDirectoryLoadingStarted
);
178 connect(m_model
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
179 connect(m_model
, &KFileItemModel::directoryLoadingCanceled
, this, &DolphinView::slotDirectoryLoadingCanceled
);
180 connect(m_model
, &KFileItemModel::directoryLoadingProgress
, this, &DolphinView::directoryLoadingProgress
);
181 connect(m_model
, &KFileItemModel::directorySortingProgress
, this, &DolphinView::directorySortingProgress
);
182 connect(m_model
, &KFileItemModel::itemsChanged
,
183 this, &DolphinView::slotItemsChanged
);
184 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &DolphinView::itemCountChanged
);
185 connect(m_model
, &KFileItemModel::itemsInserted
, this, &DolphinView::itemCountChanged
);
186 connect(m_model
, &KFileItemModel::infoMessage
, this, &DolphinView::infoMessage
);
187 connect(m_model
, &KFileItemModel::errorMessage
, this, &DolphinView::errorMessage
);
188 connect(m_model
, &KFileItemModel::directoryRedirection
, this, &DolphinView::slotDirectoryRedirection
);
189 connect(m_model
, &KFileItemModel::urlIsFileError
, this, &DolphinView::urlIsFileError
);
190 connect(m_model
, &KFileItemModel::fileItemsChanged
, this, &DolphinView::fileItemsChanged
);
192 connect(this, &DolphinView::itemCountChanged
,
193 this, &DolphinView::updatePlaceholderLabel
);
195 m_view
->installEventFilter(this);
196 connect(m_view
, &DolphinItemListView::sortOrderChanged
,
197 this, &DolphinView::slotSortOrderChangedByHeader
);
198 connect(m_view
, &DolphinItemListView::sortRoleChanged
,
199 this, &DolphinView::slotSortRoleChangedByHeader
);
200 connect(m_view
, &DolphinItemListView::visibleRolesChanged
,
201 this, &DolphinView::slotVisibleRolesChangedByHeader
);
202 connect(m_view
, &DolphinItemListView::roleEditingCanceled
,
203 this, &DolphinView::slotRoleEditingCanceled
);
204 connect(m_view
->header(), &KItemListHeader::columnWidthChangeFinished
,
205 this, &DolphinView::slotHeaderColumnWidthChangeFinished
);
206 connect(m_view
->header(), &KItemListHeader::sidePaddingChanged
,
207 this, &DolphinView::slotSidePaddingWidthChanged
);
209 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
210 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
,
211 this, &DolphinView::slotSelectionChanged
);
214 m_toolTipManager
= new ToolTipManager(this);
215 connect(m_toolTipManager
, &ToolTipManager::urlActivated
, this, &DolphinView::urlActivated
);
218 m_versionControlObserver
= new VersionControlObserver(this);
219 m_versionControlObserver
->setView(this);
220 m_versionControlObserver
->setModel(m_model
);
221 connect(m_versionControlObserver
, &VersionControlObserver::infoMessage
, this, &DolphinView::infoMessage
);
222 connect(m_versionControlObserver
, &VersionControlObserver::errorMessage
, this, &DolphinView::errorMessage
);
223 connect(m_versionControlObserver
, &VersionControlObserver::operationCompletedMessage
, this, &DolphinView::operationCompletedMessage
);
225 m_twoClicksRenamingTimer
= new QTimer(this);
226 m_twoClicksRenamingTimer
->setSingleShot(true);
227 connect(m_twoClicksRenamingTimer
, &QTimer::timeout
, this, &DolphinView::slotTwoClicksRenamingTimerTimeout
);
229 applyViewProperties();
230 m_topLayout
->addWidget(m_container
);
235 DolphinView::~DolphinView()
237 disconnect(m_container
->controller(), &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
240 QUrl
DolphinView::url() const
245 void DolphinView::setActive(bool active
)
247 if (active
== m_active
) {
256 m_container
->setFocus();
258 Q_EMIT
writeStateChanged(m_isFolderWritable
);
262 bool DolphinView::isActive() const
267 void DolphinView::setViewMode(Mode mode
)
269 if (mode
!= m_mode
) {
270 ViewProperties
props(viewPropertiesUrl());
271 props
.setViewMode(mode
);
273 // We pass the new ViewProperties to applyViewProperties, rather than
274 // storing them on disk and letting applyViewProperties() read them
275 // from there, to prevent that changing the view mode fails if the
276 // .directory file is not writable (see bug 318534).
277 applyViewProperties(props
);
281 DolphinView::Mode
DolphinView::viewMode() const
286 void DolphinView::setSelectionModeEnabled(const bool enabled
)
289 m_proxyStyle
= std::make_unique
<SelectionMode::SingleClickSelectionProxyStyle
>();
290 setStyle(m_proxyStyle
.get());
291 m_view
->setStyle(m_proxyStyle
.get());
292 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False
);
294 setStyle(QApplication::style());
295 m_view
->setStyle(QApplication::style());
296 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting
);
298 m_container
->controller()->setSelectionModeEnabled(enabled
);
301 bool DolphinView::selectionMode() const
303 return m_container
->controller()->selectionMode();
306 void DolphinView::setPreviewsShown(bool show
)
308 if (previewsShown() == show
) {
312 ViewProperties
props(viewPropertiesUrl());
313 props
.setPreviewsShown(show
);
315 const int oldZoomLevel
= m_view
->zoomLevel();
316 m_view
->setPreviewsShown(show
);
317 Q_EMIT
previewsShownChanged(show
);
319 const int newZoomLevel
= m_view
->zoomLevel();
320 if (newZoomLevel
!= oldZoomLevel
) {
321 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
325 bool DolphinView::previewsShown() const
327 return m_view
->previewsShown();
330 void DolphinView::setHiddenFilesShown(bool show
)
332 if (m_model
->showHiddenFiles() == show
) {
336 const KFileItemList itemList
= selectedItems();
337 m_selectedUrls
.clear();
338 m_selectedUrls
= itemList
.urlList();
340 ViewProperties
props(viewPropertiesUrl());
341 props
.setHiddenFilesShown(show
);
343 m_model
->setShowHiddenFiles(show
);
344 Q_EMIT
hiddenFilesShownChanged(show
);
347 bool DolphinView::hiddenFilesShown() const
349 return m_model
->showHiddenFiles();
352 void DolphinView::setGroupedSorting(bool grouped
)
354 if (grouped
== groupedSorting()) {
358 ViewProperties
props(viewPropertiesUrl());
359 props
.setGroupedSorting(grouped
);
362 m_container
->controller()->model()->setGroupedSorting(grouped
);
364 Q_EMIT
groupedSortingChanged(grouped
);
367 bool DolphinView::groupedSorting() const
369 return m_model
->groupedSorting();
372 KFileItemList
DolphinView::items() const
375 const int itemCount
= m_model
->count();
376 list
.reserve(itemCount
);
378 for (int i
= 0; i
< itemCount
; ++i
) {
379 list
.append(m_model
->fileItem(i
));
385 int DolphinView::itemsCount() const
387 return m_model
->count();
390 KFileItemList
DolphinView::selectedItems() const
392 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
394 KFileItemList selectedItems
;
395 const auto items
= selectionManager
->selectedItems();
396 selectedItems
.reserve(items
.count());
397 for (int index
: items
) {
398 selectedItems
.append(m_model
->fileItem(index
));
400 return selectedItems
;
403 int DolphinView::selectedItemsCount() const
405 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
406 return selectionManager
->selectedItems().count();
409 void DolphinView::markUrlsAsSelected(const QList
<QUrl
>& urls
)
411 m_selectedUrls
= urls
;
414 void DolphinView::markUrlAsCurrent(const QUrl
&url
)
416 m_currentItemUrl
= url
;
417 m_scrollToCurrentItem
= true;
420 void DolphinView::selectItems(const QRegularExpression
®exp
, bool enabled
)
422 const KItemListSelectionManager::SelectionMode mode
= enabled
423 ? KItemListSelectionManager::Select
424 : KItemListSelectionManager::Deselect
;
425 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
427 for (int index
= 0; index
< m_model
->count(); index
++) {
428 const KFileItem item
= m_model
->fileItem(index
);
429 if (regexp
.match(item
.text()).hasMatch()) {
430 // An alternative approach would be to store the matching items in a KItemSet and
431 // select them in one go after the loop, but we'd need a new function
432 // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
434 selectionManager
->setSelected(index
, 1, mode
);
439 void DolphinView::setZoomLevel(int level
)
441 const int oldZoomLevel
= zoomLevel();
442 m_view
->setZoomLevel(level
);
443 if (zoomLevel() != oldZoomLevel
) {
445 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
449 int DolphinView::zoomLevel() const
451 return m_view
->zoomLevel();
454 void DolphinView::setSortRole(const QByteArray
& role
)
456 if (role
!= sortRole()) {
457 updateSortRole(role
);
461 QByteArray
DolphinView::sortRole() const
463 const KItemModelBase
* model
= m_container
->controller()->model();
464 return model
->sortRole();
467 void DolphinView::setSortOrder(Qt::SortOrder order
)
469 if (sortOrder() != order
) {
470 updateSortOrder(order
);
474 Qt::SortOrder
DolphinView::sortOrder() const
476 return m_model
->sortOrder();
479 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
481 if (sortFoldersFirst() != foldersFirst
) {
482 updateSortFoldersFirst(foldersFirst
);
486 bool DolphinView::sortFoldersFirst() const
488 return m_model
->sortDirectoriesFirst();
491 void DolphinView::setSortHiddenLast(bool hiddenLast
)
493 if (sortHiddenLast() != hiddenLast
) {
494 updateSortHiddenLast(hiddenLast
);
498 bool DolphinView::sortHiddenLast() const
500 return m_model
->sortHiddenLast();
503 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
505 const QList
<QByteArray
> previousRoles
= roles
;
507 ViewProperties
props(viewPropertiesUrl());
508 props
.setVisibleRoles(roles
);
510 m_visibleRoles
= roles
;
511 m_view
->setVisibleRoles(roles
);
513 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousRoles
);
516 QList
<QByteArray
> DolphinView::visibleRoles() const
518 return m_visibleRoles
;
521 void DolphinView::reload()
523 QByteArray viewState
;
524 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
525 saveState(saveStream
);
528 loadDirectory(url(), true);
530 QDataStream
restoreStream(viewState
);
531 restoreState(restoreStream
);
534 void DolphinView::readSettings()
536 const int oldZoomLevel
= m_view
->zoomLevel();
538 GeneralSettings::self()->load();
539 m_view
->readSettings();
540 applyViewProperties();
542 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
543 m_container
->controller()->setAutoActivationDelay(delay
);
545 const int newZoomLevel
= m_view
->zoomLevel();
546 if (newZoomLevel
!= oldZoomLevel
) {
547 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
551 void DolphinView::writeSettings()
553 GeneralSettings::self()->save();
554 m_view
->writeSettings();
557 void DolphinView::setNameFilter(const QString
& nameFilter
)
559 m_model
->setNameFilter(nameFilter
);
562 QString
DolphinView::nameFilter() const
564 return m_model
->nameFilter();
567 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
569 return m_model
->setMimeTypeFilters(filters
);
572 QStringList
DolphinView::mimeTypeFilters() const
574 return m_model
->mimeTypeFilters();
577 void DolphinView::requestStatusBarText()
579 if (m_statJobForStatusBarText
) {
580 // Kill the pending request.
581 m_statJobForStatusBarText
->kill();
584 if (m_container
->controller()->selectionManager()->hasSelection()) {
587 KIO::filesize_t totalFileSize
= 0;
589 // Give a summary of the status of the selected files
590 const KFileItemList list
= selectedItems();
591 for (const KFileItem
& item
: list
) {
596 totalFileSize
+= item
.size();
600 if (folderCount
+ fileCount
== 1) {
601 // If only one item is selected, show info about it
602 Q_EMIT
statusBarTextChanged(list
.first().getStatusBarInfo());
604 // At least 2 items are selected
605 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, HasSelection
);
607 } else { // has no selection
608 if (!m_model
->rootItem().url().isValid()) {
612 m_statJobForStatusBarText
= KIO::statDetails(m_model
->rootItem().url(),
613 KIO::StatJob::SourceSide
, KIO::StatRecursiveSize
, KIO::HideProgressInfo
);
614 connect(m_statJobForStatusBarText
, &KJob::result
,
615 this, &DolphinView::slotStatJobResult
);
616 m_statJobForStatusBarText
->start();
620 void DolphinView::emitStatusBarText(const int folderCount
, const int fileCount
,
621 KIO::filesize_t totalFileSize
, const Selection selection
)
627 if (selection
== HasSelection
) {
628 // At least 2 items are selected because the case of 1 selected item is handled in
629 // DolphinView::requestStatusBarText().
630 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
631 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
633 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
634 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
637 if (fileCount
> 0 && folderCount
> 0) {
638 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
639 foldersText
, filesText
,
640 KFormat().formatByteSize(totalFileSize
));
641 } else if (fileCount
> 0) {
642 summary
= i18nc("@info:status files (size)", "%1 (%2)",
644 KFormat().formatByteSize(totalFileSize
));
645 } else if (folderCount
> 0) {
646 summary
= foldersText
;
648 summary
= i18nc("@info:status", "0 Folders, 0 Files");
650 Q_EMIT
statusBarTextChanged(summary
);
653 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
655 QList
<QAction
*> actions
;
657 if (items
.isEmpty()) {
658 const KFileItem item
= m_model
->rootItem();
659 if (!item
.isNull()) {
660 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
663 actions
= m_versionControlObserver
->actions(items
);
669 void DolphinView::setUrl(const QUrl
& url
)
681 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
682 this, &DolphinView::slotRoleEditingFinished
);
684 // It is important to clear the items from the model before
685 // applying the view properties, otherwise expensive operations
686 // might be done on the existing items although they get cleared
687 // anyhow afterwards by loadDirectory().
689 applyViewProperties();
692 Q_EMIT
urlChanged(url
);
695 void DolphinView::selectAll()
697 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
698 selectionManager
->setSelected(0, m_model
->count());
701 void DolphinView::invertSelection()
703 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
704 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
707 void DolphinView::clearSelection()
709 m_selectedUrls
.clear();
710 m_container
->controller()->selectionManager()->clearSelection();
713 void DolphinView::renameSelectedItems()
715 const KFileItemList items
= selectedItems();
716 if (items
.isEmpty()) {
720 if (items
.count() == 1 && GeneralSettings::renameInline()) {
721 const int index
= m_model
->index(items
.first());
723 QMetaObject::Connection
* const connection
= new QMetaObject::Connection
;
724 *connection
= connect(m_view
, &KItemListView::scrollingStopped
, this, [=](){
725 QObject::disconnect(*connection
);
728 m_view
->editRole(index
, "text");
732 connect(m_view
, &DolphinItemListView::roleEditingFinished
,
733 this, &DolphinView::slotRoleEditingFinished
);
735 m_view
->scrollToItem(index
);
738 KIO::RenameFileDialog
* dialog
= new KIO::RenameFileDialog(items
, this);
739 connect(dialog
, &KIO::RenameFileDialog::renamingFinished
,
740 this, &DolphinView::slotRenameDialogRenamingFinished
);
745 // Assure that the current index remains visible when KFileItemModel
746 // will notify the view about changed items (which might result in
747 // a changed sorting).
748 m_assureVisibleCurrentIndex
= true;
751 void DolphinView::trashSelectedItems()
753 const QList
<QUrl
> list
= simplifiedSelectedUrls();
754 KIO::JobUiDelegate uiDelegate
;
755 uiDelegate
.setWindow(window());
756 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Trash
, KIO::JobUiDelegate::DefaultConfirmation
)) {
757 KIO::Job
* job
= KIO::trash(list
);
758 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash
, list
, QUrl(QStringLiteral("trash:/")), job
);
759 KJobWidgets::setWindow(job
, this);
760 connect(job
, &KIO::Job::result
,
761 this, &DolphinView::slotTrashFileFinished
);
765 void DolphinView::deleteSelectedItems()
767 const QList
<QUrl
> list
= simplifiedSelectedUrls();
769 KIO::JobUiDelegate uiDelegate
;
770 uiDelegate
.setWindow(window());
771 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Delete
, KIO::JobUiDelegate::DefaultConfirmation
)) {
772 KIO::Job
* job
= KIO::del(list
);
773 KJobWidgets::setWindow(job
, this);
774 connect(job
, &KIO::Job::result
,
775 this, &DolphinView::slotDeleteFileFinished
);
779 void DolphinView::cutSelectedItemsToClipboard()
781 QMimeData
* mimeData
= selectionMimeData();
782 KIO::setClipboardDataCut(mimeData
, true);
783 KUrlMimeData::exportUrlsToPortal(mimeData
);
784 QApplication::clipboard()->setMimeData(mimeData
);
787 void DolphinView::copySelectedItemsToClipboard()
789 QMimeData
*mimeData
= selectionMimeData();
790 KUrlMimeData::exportUrlsToPortal(mimeData
);
791 QApplication::clipboard()->setMimeData(mimeData
);
794 void DolphinView::copySelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
796 KIO::CopyJob
* job
= KIO::copy(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
797 KJobWidgets::setWindow(job
, this);
799 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
800 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
801 KIO::FileUndoManager::self()->recordCopyJob(job
);
804 void DolphinView::moveSelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
806 KIO::CopyJob
* job
= KIO::move(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
807 KJobWidgets::setWindow(job
, this);
809 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
810 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
811 KIO::FileUndoManager::self()->recordCopyJob(job
);
815 void DolphinView::paste()
820 void DolphinView::pasteIntoFolder()
822 const KFileItemList items
= selectedItems();
823 if ((items
.count() == 1) && items
.first().isDir()) {
824 pasteToUrl(items
.first().url());
828 void DolphinView::duplicateSelectedItems()
830 const KFileItemList itemList
= selectedItems();
831 if (itemList
.isEmpty()) {
835 const QMimeDatabase db
;
837 // Duplicate all selected items and append "copy" to the end of the file name
838 // but before the filename extension, if present
839 QList
<QUrl
> newSelection
;
840 for (const auto &item
: itemList
) {
841 const QUrl originalURL
= item
.url();
842 const QString originalDirectoryPath
= originalURL
.adjusted(QUrl::RemoveFilename
).path();
843 const QString originalFileName
= item
.name();
845 QString extension
= db
.suffixForFileName(originalFileName
);
847 QUrl duplicateURL
= originalURL
;
849 // No extension; new filename is "<oldfilename> copy"
850 if (extension
.isEmpty()) {
851 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFileName
));
852 // There's an extension; new filename is "<oldfilename> copy.<extension>"
854 // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it
855 extension
= QLatin1String(".") + extension
;
856 const QString originalFilenameWithoutExtension
= originalFileName
.chopped(extension
.size());
857 // Preserve file's original filename extension in case the casing differs
858 // from what QMimeDatabase::suffixForFileName() returned
859 const QString originalExtension
= originalFileName
.right(extension
.size());
860 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension
) + originalExtension
);
863 KIO::CopyJob
* job
= KIO::copyAs(originalURL
, duplicateURL
);
864 KJobWidgets::setWindow(job
, this);
867 newSelection
<< duplicateURL
;
868 KIO::FileUndoManager::self()->recordCopyJob(job
);
872 forceUrlsSelection(newSelection
.first(), newSelection
);
875 void DolphinView::stopLoading()
877 m_model
->cancelDirectoryLoading();
880 void DolphinView::updatePalette()
882 QColor color
= KColorScheme(isActiveWindow() ? QPalette::Active
: QPalette::Inactive
, KColorScheme::View
).background().color();
887 QWidget
* viewport
= m_container
->viewport();
890 palette
.setColor(viewport
->backgroundRole(), color
);
891 viewport
->setPalette(palette
);
897 void DolphinView::abortTwoClicksRenaming()
899 m_twoClicksRenamingItemUrl
.clear();
900 m_twoClicksRenamingTimer
->stop();
903 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
905 switch (event
->type()) {
906 case QEvent::PaletteChange
:
908 QPixmapCache::clear();
911 case QEvent::WindowActivate
:
912 case QEvent::WindowDeactivate
:
916 case QEvent::KeyPress
:
917 hideToolTip(ToolTipManager::HideBehavior::Instantly
);
918 if (GeneralSettings::useTabForSwitchingSplitView()) {
919 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
920 if (keyEvent
->key() == Qt::Key_Tab
&& keyEvent
->modifiers() == Qt::NoModifier
) {
921 Q_EMIT
toggleActiveViewRequested();
926 case QEvent::FocusIn
:
927 if (watched
== m_container
) {
932 case QEvent::GraphicsSceneDragEnter
:
933 if (watched
== m_view
) {
935 abortTwoClicksRenaming();
939 case QEvent::GraphicsSceneDragLeave
:
940 if (watched
== m_view
) {
945 case QEvent::GraphicsSceneDrop
:
946 if (watched
== m_view
) {
951 case QEvent::ToolTip
:
952 tryShowNameToolTip(static_cast<QHelpEvent
*>(event
));
958 return QWidget::eventFilter(watched
, event
);
961 void DolphinView::wheelEvent(QWheelEvent
* event
)
963 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
964 const QPoint numDegrees
= event
->angleDelta() / 8;
965 const QPoint numSteps
= numDegrees
/ 15;
967 setZoomLevel(zoomLevel() + numSteps
.y());
974 void DolphinView::hideEvent(QHideEvent
* event
)
977 QWidget::hideEvent(event
);
980 bool DolphinView::event(QEvent
* event
)
982 if (event
->type() == QEvent::WindowDeactivate
) {
984 * Dolphin leaves file preview tooltips open even when is not visible.
986 * Hide tool-tip when Dolphin loses focus.
989 abortTwoClicksRenaming();
992 return QWidget::event(event
);
995 void DolphinView::activate()
1000 void DolphinView::slotItemActivated(int index
)
1002 abortTwoClicksRenaming();
1004 const KFileItem item
= m_model
->fileItem(index
);
1005 if (!item
.isNull()) {
1006 Q_EMIT
itemActivated(item
);
1010 void DolphinView::slotItemsActivated(const KItemSet
&indexes
)
1012 Q_ASSERT(indexes
.count() >= 2);
1014 abortTwoClicksRenaming();
1016 const auto modifiers
= QGuiApplication::keyboardModifiers();
1018 if (indexes
.count() > 5) {
1019 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
1020 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1021 KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes
.count()),
1022 QStringLiteral("document-open")),
1023 KStandardGuiItem::cancel());
1024 if (answer
!= KMessageBox::Yes
) {
1029 KFileItemList items
;
1030 items
.reserve(indexes
.count());
1032 for (int index
: indexes
) {
1033 KFileItem item
= m_model
->fileItem(index
);
1034 const QUrl
& url
= openItemAsFolderUrl(item
);
1036 if (!url
.isEmpty()) {
1037 // Open folders in new tabs or in new windows depending on the modifier
1038 // The ctrl+shift behavior is ignored because we are handling multiple items
1039 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1040 if (modifiers
& Qt::ShiftModifier
&& !(modifiers
& Qt::ControlModifier
)) {
1041 Q_EMIT
windowRequested(url
);
1043 Q_EMIT
tabRequested(url
);
1050 if (items
.count() == 1) {
1051 Q_EMIT
itemActivated(items
.first());
1052 } else if (items
.count() > 1) {
1053 Q_EMIT
itemsActivated(items
);
1057 void DolphinView::slotItemMiddleClicked(int index
)
1059 const KFileItem
& item
= m_model
->fileItem(index
);
1060 const QUrl
& url
= openItemAsFolderUrl(item
);
1061 const auto modifiers
= QGuiApplication::keyboardModifiers();
1062 if (!url
.isEmpty()) {
1063 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1064 if (modifiers
& Qt::ShiftModifier
) {
1065 Q_EMIT
activeTabRequested(url
);
1067 Q_EMIT
tabRequested(url
);
1069 } else if (isTabsForFilesEnabled()) {
1070 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1071 if (modifiers
& Qt::ShiftModifier
) {
1072 Q_EMIT
activeTabRequested(item
.url());
1074 Q_EMIT
tabRequested(item
.url());
1079 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
1081 // Force emit of a selection changed signal before we request the
1082 // context menu, to update the edit-actions first. (See Bug 294013)
1083 if (m_selectionChangedTimer
->isActive()) {
1084 emitSelectionChangedSignal();
1087 const KFileItem item
= m_model
->fileItem(index
);
1088 Q_EMIT
requestContextMenu(pos
.toPoint(), item
, selectedItems(), url());
1091 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
1093 Q_EMIT
requestContextMenu(pos
.toPoint(), KFileItem(), selectedItems(), url());
1096 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
1098 ViewProperties
props(viewPropertiesUrl());
1100 QPointer
<QMenu
> menu
= new QMenu(QApplication::activeWindow());
1102 KItemListView
* view
= m_container
->controller()->view();
1103 const QList
<QByteArray
> visibleRolesSet
= view
->visibleRoles();
1105 bool indexingEnabled
= false;
1107 Baloo::IndexerConfig config
;
1108 indexingEnabled
= config
.fileIndexingEnabled();
1112 QMenu
* groupMenu
= nullptr;
1114 // Add all roles to the menu that can be shown or hidden by the user
1115 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
1116 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
1117 if (info
.role
== "text") {
1118 // It should not be possible to hide the "text" role
1122 const QString text
= m_model
->roleDescription(info
.role
);
1123 QAction
* action
= nullptr;
1124 if (info
.group
.isEmpty()) {
1125 action
= menu
->addAction(text
);
1127 if (!groupMenu
|| info
.group
!= groupName
) {
1128 groupName
= info
.group
;
1129 groupMenu
= menu
->addMenu(groupName
);
1132 action
= groupMenu
->addAction(text
);
1135 action
->setCheckable(true);
1136 action
->setChecked(visibleRolesSet
.contains(info
.role
));
1137 action
->setData(info
.role
);
1139 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
1140 (info
.requiresBaloo
) ||
1141 (info
.requiresIndexer
&& indexingEnabled
);
1142 action
->setEnabled(enable
);
1145 menu
->addSeparator();
1147 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
1148 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
1150 QAction
* toggleSidePaddingAction
= menu
->addAction(i18nc("@action:inmenu", "Side Padding"));
1151 toggleSidePaddingAction
->setCheckable(true);
1152 toggleSidePaddingAction
->setChecked(view
->header()->sidePadding() > 0);
1154 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
1155 autoAdjustWidthsAction
->setCheckable(true);
1156 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
1157 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
1159 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
1160 customWidthsAction
->setCheckable(true);
1161 customWidthsAction
->setChecked(!autoColumnWidths
);
1162 customWidthsAction
->setActionGroup(widthsGroup
);
1164 QAction
* action
= menu
->exec(pos
.toPoint());
1165 if (menu
&& action
) {
1166 KItemListHeader
* header
= view
->header();
1168 if (action
== autoAdjustWidthsAction
) {
1169 // Clear the column-widths from the viewproperties and turn on
1170 // the automatic resizing of the columns
1171 props
.setHeaderColumnWidths(QList
<int>());
1172 header
->setAutomaticColumnResizing(true);
1173 } else if (action
== customWidthsAction
) {
1174 // Apply the current column-widths as custom column-widths and turn
1175 // off the automatic resizing of the columns
1176 QList
<int> columnWidths
;
1177 const auto visibleRoles
= view
->visibleRoles();
1178 columnWidths
.reserve(visibleRoles
.count());
1179 for (const QByteArray
& role
: visibleRoles
) {
1180 columnWidths
.append(header
->columnWidth(role
));
1182 props
.setHeaderColumnWidths(columnWidths
);
1183 header
->setAutomaticColumnResizing(false);
1184 } else if (action
== toggleSidePaddingAction
) {
1185 header
->setSidePadding(toggleSidePaddingAction
->isChecked() ? 20 : 0);
1187 // Show or hide the selected role
1188 const QByteArray selectedRole
= action
->data().toByteArray();
1190 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
1191 if (action
->isChecked()) {
1192 visibleRoles
.append(selectedRole
);
1194 visibleRoles
.removeOne(selectedRole
);
1197 view
->setVisibleRoles(visibleRoles
);
1198 props
.setVisibleRoles(visibleRoles
);
1200 QList
<int> columnWidths
;
1201 if (!header
->automaticColumnResizing()) {
1202 const auto visibleRoles
= view
->visibleRoles();
1203 columnWidths
.reserve(visibleRoles
.count());
1204 for (const QByteArray
& role
: visibleRoles
) {
1205 columnWidths
.append(header
->columnWidth(role
));
1208 props
.setHeaderColumnWidths(columnWidths
);
1215 void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray
& role
, qreal current
)
1217 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
1219 ViewProperties
props(viewPropertiesUrl());
1220 QList
<int> columnWidths
= props
.headerColumnWidths();
1221 if (columnWidths
.count() != visibleRoles
.count()) {
1222 columnWidths
.clear();
1223 columnWidths
.reserve(visibleRoles
.count());
1224 const KItemListHeader
* header
= m_view
->header();
1225 for (const QByteArray
& role
: visibleRoles
) {
1226 const int width
= header
->columnWidth(role
);
1227 columnWidths
.append(width
);
1231 const int roleIndex
= visibleRoles
.indexOf(role
);
1232 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
1233 columnWidths
[roleIndex
] = current
;
1235 props
.setHeaderColumnWidths(columnWidths
);
1238 void DolphinView::slotSidePaddingWidthChanged(qreal width
)
1240 ViewProperties
props(viewPropertiesUrl());
1241 DetailsModeSettings::setSidePadding(int(width
));
1242 m_view
->writeSettings();
1245 void DolphinView::slotItemHovered(int index
)
1247 const KFileItem item
= m_model
->fileItem(index
);
1249 if (GeneralSettings::showToolTips() && !m_dragging
) {
1250 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1251 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1252 itemRect
.moveTo(pos
);
1255 auto nativeParent
= nativeParentWidget();
1257 m_toolTipManager
->showToolTip(item
, itemRect
, nativeParent
->windowHandle());
1262 Q_EMIT
requestItemInfo(item
);
1265 void DolphinView::slotItemUnhovered(int index
)
1269 Q_EMIT
requestItemInfo(KFileItem());
1272 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1275 KFileItem destItem
= m_model
->fileItem(index
);
1276 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1277 // Use the URL of the view as drop target if the item is no directory
1279 destItem
= m_model
->rootItem();
1282 // The item represents a directory or desktop-file
1283 destUrl
= destItem
.mostLocalUrl();
1286 QDropEvent
dropEvent(event
->pos().toPoint(),
1287 event
->possibleActions(),
1290 event
->modifiers());
1291 dropUrls(destUrl
, &dropEvent
, this);
1296 void DolphinView::dropUrls(const QUrl
&destUrl
, QDropEvent
*dropEvent
, QWidget
*dropWidget
)
1298 KIO::DropJob
* job
= DragAndDropHelper::dropUrls(destUrl
, dropEvent
, dropWidget
);
1301 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
1303 if (destUrl
== url()) {
1304 // Mark the dropped urls as selected.
1305 m_clearSelectionBeforeSelectingNewItems
= true;
1306 m_markFirstNewlySelectedItemAsCurrent
= true;
1307 connect(job
, &KIO::DropJob::itemCreated
, this, &DolphinView::slotItemCreated
);
1312 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1314 if (previous
!= nullptr) {
1315 Q_ASSERT(qobject_cast
<KFileItemModel
*>(previous
));
1316 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(previous
);
1317 disconnect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1318 m_versionControlObserver
->setModel(nullptr);
1322 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1323 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1324 connect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1325 m_versionControlObserver
->setModel(fileItemModel
);
1329 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1335 if (buttons
& Qt::BackButton
) {
1336 Q_EMIT
goBackRequested();
1337 } else if (buttons
& Qt::ForwardButton
) {
1338 Q_EMIT
goForwardRequested();
1342 void DolphinView::slotSelectedItemTextPressed(int index
)
1344 if (GeneralSettings::renameInline() && !m_view
->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick
)) {
1345 const KFileItem item
= m_model
->fileItem(index
);
1346 const KFileItemListProperties
capabilities(KFileItemList() << item
);
1347 if (capabilities
.supportsMoving()) {
1348 m_twoClicksRenamingItemUrl
= item
.url();
1349 m_twoClicksRenamingTimer
->start(QApplication::doubleClickInterval());
1354 void DolphinView::slotCopyingDone(KIO::Job
*, const QUrl
&, const QUrl
&to
)
1356 slotItemCreated(to
);
1359 void DolphinView::slotItemCreated(const QUrl
& url
)
1361 if (m_markFirstNewlySelectedItemAsCurrent
) {
1362 markUrlAsCurrent(url
);
1363 m_markFirstNewlySelectedItemAsCurrent
= false;
1365 m_selectedUrls
<< url
;
1368 void DolphinView::slotJobResult(KJob
*job
)
1370 if (job
->error() && job
->error() != KIO::ERR_USER_CANCELED
) {
1371 Q_EMIT
errorMessage(job
->errorString());
1373 if (!m_selectedUrls
.isEmpty()) {
1374 m_selectedUrls
= KDirModel::simplifiedUrlList(m_selectedUrls
);
1378 void DolphinView::slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
)
1380 const int currentCount
= current
.count();
1381 const int previousCount
= previous
.count();
1382 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1383 (currentCount
> 0 && previousCount
== 0);
1385 // If nothing has been selected before and something got selected (or if something
1386 // was selected before and now nothing is selected) the selectionChangedSignal must
1387 // be emitted asynchronously as fast as possible to update the edit-actions.
1388 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1389 m_selectionChangedTimer
->start();
1392 void DolphinView::emitSelectionChangedSignal()
1394 m_selectionChangedTimer
->stop();
1395 Q_EMIT
selectionChanged(selectedItems());
1398 void DolphinView::slotStatJobResult(KJob
*job
)
1400 int folderCount
= 0;
1402 KIO::filesize_t totalFileSize
= 0;
1403 bool countFileSize
= true;
1405 const auto entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1406 if (entry
.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE
)) {
1407 // We have a precomputed value.
1408 totalFileSize
= static_cast<KIO::filesize_t
>(
1409 entry
.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE
));
1410 countFileSize
= false;
1413 const int itemCount
= m_model
->count();
1414 for (int i
= 0; i
< itemCount
; ++i
) {
1415 const KFileItem item
= m_model
->fileItem(i
);
1420 if (countFileSize
) {
1421 totalFileSize
+= item
.size();
1425 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, NoSelection
);
1428 void DolphinView::updateSortRole(const QByteArray
& role
)
1430 ViewProperties
props(viewPropertiesUrl());
1431 props
.setSortRole(role
);
1433 KItemModelBase
* model
= m_container
->controller()->model();
1434 model
->setSortRole(role
);
1436 Q_EMIT
sortRoleChanged(role
);
1439 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1441 ViewProperties
props(viewPropertiesUrl());
1442 props
.setSortOrder(order
);
1444 m_model
->setSortOrder(order
);
1446 Q_EMIT
sortOrderChanged(order
);
1449 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1451 ViewProperties
props(viewPropertiesUrl());
1452 props
.setSortFoldersFirst(foldersFirst
);
1454 m_model
->setSortDirectoriesFirst(foldersFirst
);
1456 Q_EMIT
sortFoldersFirstChanged(foldersFirst
);
1459 void DolphinView::updateSortHiddenLast(bool hiddenLast
)
1461 ViewProperties
props(viewPropertiesUrl());
1462 props
.setSortHiddenLast(hiddenLast
);
1464 m_model
->setSortHiddenLast(hiddenLast
);
1466 Q_EMIT
sortHiddenLastChanged(hiddenLast
);
1470 QPair
<bool, QString
> DolphinView::pasteInfo() const
1472 const QMimeData
*mimeData
= QApplication::clipboard()->mimeData();
1473 QPair
<bool, QString
> info
;
1474 info
.second
= KIO::pasteActionText(mimeData
, &info
.first
, rootItem());
1478 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1480 m_tabsForFiles
= tabsForFiles
;
1483 bool DolphinView::isTabsForFilesEnabled() const
1485 return m_tabsForFiles
;
1488 bool DolphinView::itemsExpandable() const
1490 return m_mode
== DetailsView
;
1493 bool DolphinView::isExpanded(const KFileItem
& item
) const
1495 Q_ASSERT(item
.isDir());
1496 Q_ASSERT(items().contains(item
));
1497 if (!itemsExpandable()) {
1500 return m_model
->isExpanded(m_model
->index(item
));
1503 void DolphinView::restoreState(QDataStream
& stream
)
1505 // Read the version number of the view state and check if the version is supported.
1506 quint32 version
= 0;
1509 // The version of the view state isn't supported, we can't restore it.
1513 // Restore the current item that had the keyboard focus
1514 stream
>> m_currentItemUrl
;
1516 // Restore the previously selected items
1517 stream
>> m_selectedUrls
;
1519 // Restore the view position
1520 stream
>> m_restoredContentsPosition
;
1522 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1525 m_model
->restoreExpandedDirectories(urls
);
1528 void DolphinView::saveState(QDataStream
& stream
)
1530 stream
<< quint32(1); // View state version
1532 // Save the current item that has the keyboard focus
1533 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1534 if (currentIndex
!= -1) {
1535 KFileItem item
= m_model
->fileItem(currentIndex
);
1536 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1537 QUrl currentItemUrl
= item
.url();
1538 stream
<< currentItemUrl
;
1543 // Save the selected urls
1544 stream
<< selectedItems().urlList();
1546 // Save view position
1547 const qreal x
= m_container
->horizontalScrollBar()->value();
1548 const qreal y
= m_container
->verticalScrollBar()->value();
1549 stream
<< QPoint(x
, y
);
1551 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1552 stream
<< m_model
->expandedDirectories();
1555 KFileItem
DolphinView::rootItem() const
1557 return m_model
->rootItem();
1560 void DolphinView::setViewPropertiesContext(const QString
& context
)
1562 m_viewPropertiesContext
= context
;
1565 QString
DolphinView::viewPropertiesContext() const
1567 return m_viewPropertiesContext
;
1570 QUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1572 if (item
.isNull()) {
1576 QUrl url
= item
.targetUrl();
1582 if (item
.isMimeTypeKnown()) {
1583 const QString
& mimetype
= item
.mimetype();
1585 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1586 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1587 // zip:/<path>/ when clicking on a zip file, etc.
1588 // The .protocol file specifies the mimetype that the kioslave handles.
1589 // Note that we don't use mimetype inheritance since we don't want to
1590 // open OpenDocument files as zip folders...
1591 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1592 if (!protocol
.isEmpty()) {
1593 url
.setScheme(protocol
);
1598 if (mimetype
== QLatin1String("application/x-desktop")) {
1599 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1600 KDesktopFile
desktopFile(url
.toLocalFile());
1601 if (desktopFile
.hasLinkType()) {
1602 const QString linkUrl
= desktopFile
.readUrl();
1603 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1604 return QUrl::fromUserInput(linkUrl
);
1613 void DolphinView::resetZoomLevel()
1615 ViewModeSettings settings
{m_mode
};
1616 settings
.useDefaults(true);
1617 const int defaultIconSize
= settings
.iconSize();
1618 settings
.useDefaults(false);
1620 setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(QSize(defaultIconSize
, defaultIconSize
)));
1623 void DolphinView::observeCreatedItem(const QUrl
& url
)
1626 forceUrlsSelection(url
, {url
});
1630 void DolphinView::slotDirectoryRedirection(const QUrl
& oldUrl
, const QUrl
& newUrl
)
1632 if (oldUrl
.matches(url(), QUrl::StripTrailingSlash
)) {
1633 Q_EMIT
redirection(oldUrl
, newUrl
);
1634 m_url
= newUrl
; // #186947
1638 void DolphinView::updateViewState()
1640 if (m_currentItemUrl
!= QUrl()) {
1641 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1643 // if there is a selection already, leave it that way
1644 if (!selectionManager
->hasSelection()) {
1645 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1646 if (currentIndex
!= -1) {
1647 selectionManager
->setCurrentItem(currentIndex
);
1649 // scroll to current item and reset the state
1650 if (m_scrollToCurrentItem
) {
1651 m_view
->scrollToItem(currentIndex
);
1652 m_scrollToCurrentItem
= false;
1654 m_currentItemUrl
= QUrl();
1656 selectionManager
->setCurrentItem(0);
1659 m_currentItemUrl
= QUrl();
1663 if (!m_restoredContentsPosition
.isNull()) {
1664 const int x
= m_restoredContentsPosition
.x();
1665 const int y
= m_restoredContentsPosition
.y();
1666 m_restoredContentsPosition
= QPoint();
1668 m_container
->horizontalScrollBar()->setValue(x
);
1669 m_container
->verticalScrollBar()->setValue(y
);
1672 if (!m_selectedUrls
.isEmpty()) {
1673 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1675 // if there is a selection already, leave it that way
1676 if (!selectionManager
->hasSelection()) {
1677 if (m_clearSelectionBeforeSelectingNewItems
) {
1678 selectionManager
->clearSelection();
1679 m_clearSelectionBeforeSelectingNewItems
= false;
1682 KItemSet selectedItems
= selectionManager
->selectedItems();
1684 QList
<QUrl
>::iterator it
= m_selectedUrls
.begin();
1685 while (it
!= m_selectedUrls
.end()) {
1686 const int index
= m_model
->index(*it
);
1688 selectedItems
.insert(index
);
1689 it
= m_selectedUrls
.erase(it
);
1695 if (!selectedItems
.isEmpty()) {
1696 selectionManager
->beginAnchoredSelection(selectionManager
->currentItem());
1697 selectionManager
->setSelectedItems(selectedItems
);
1703 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior
)
1705 if (GeneralSettings::showToolTips()) {
1707 m_toolTipManager
->hideToolTip(behavior
);
1711 } else if (m_mode
== DolphinView::IconsView
) {
1712 QToolTip::hideText();
1716 void DolphinView::slotTwoClicksRenamingTimerTimeout()
1718 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1720 // verify that only one item is selected
1721 if (selectionManager
->selectedItems().count() == 1) {
1722 const int index
= selectionManager
->currentItem();
1723 const QUrl fileItemUrl
= m_model
->fileItem(index
).url();
1725 // check if the selected item was the same item that started the twoClicksRenaming
1726 if (fileItemUrl
.isValid() && m_twoClicksRenamingItemUrl
== fileItemUrl
) {
1727 renameSelectedItems();
1732 void DolphinView::slotTrashFileFinished(KJob
* job
)
1734 if (job
->error() == 0) {
1735 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
1736 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1737 Q_EMIT
errorMessage(job
->errorString());
1741 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1743 if (job
->error() == 0) {
1744 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1745 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1746 Q_EMIT
errorMessage(job
->errorString());
1750 void DolphinView::slotRenamingResult(KJob
* job
)
1753 KIO::CopyJob
*copyJob
= qobject_cast
<KIO::CopyJob
*>(job
);
1755 const QUrl newUrl
= copyJob
->destUrl();
1756 const int index
= m_model
->index(newUrl
);
1758 QHash
<QByteArray
, QVariant
> data
;
1759 const QUrl oldUrl
= copyJob
->srcUrls().at(0);
1760 data
.insert("text", oldUrl
.fileName());
1761 m_model
->setData(index
, data
);
1766 void DolphinView::slotDirectoryLoadingStarted()
1768 m_loadingState
= LoadingState::Loading
;
1769 updatePlaceholderLabel();
1771 // Disable the writestate temporary until it can be determined in a fast way
1772 // in DolphinView::slotDirectoryLoadingCompleted()
1773 if (m_isFolderWritable
) {
1774 m_isFolderWritable
= false;
1775 Q_EMIT
writeStateChanged(m_isFolderWritable
);
1778 Q_EMIT
directoryLoadingStarted();
1781 void DolphinView::slotDirectoryLoadingCompleted()
1783 m_loadingState
= LoadingState::Completed
;
1785 // Update the view-state. This has to be done asynchronously
1786 // because the view might not be in its final state yet.
1787 QTimer::singleShot(0, this, &DolphinView::updateViewState
);
1789 // Update the placeholder label in case we found that the folder was empty
1792 Q_EMIT
directoryLoadingCompleted();
1794 updatePlaceholderLabel();
1795 updateWritableState();
1798 void DolphinView::slotDirectoryLoadingCanceled()
1800 m_loadingState
= LoadingState::Canceled
;
1802 updatePlaceholderLabel();
1804 Q_EMIT
directoryLoadingCanceled();
1807 void DolphinView::slotItemsChanged()
1809 m_assureVisibleCurrentIndex
= false;
1812 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1815 Q_ASSERT(m_model
->sortOrder() == current
);
1817 ViewProperties
props(viewPropertiesUrl());
1818 props
.setSortOrder(current
);
1820 Q_EMIT
sortOrderChanged(current
);
1823 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1826 Q_ASSERT(m_model
->sortRole() == current
);
1828 ViewProperties
props(viewPropertiesUrl());
1829 props
.setSortRole(current
);
1831 Q_EMIT
sortRoleChanged(current
);
1834 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1835 const QList
<QByteArray
>& previous
)
1838 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1840 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1842 m_visibleRoles
= current
;
1844 ViewProperties
props(viewPropertiesUrl());
1845 props
.setVisibleRoles(m_visibleRoles
);
1847 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1850 void DolphinView::slotRoleEditingCanceled()
1852 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1853 this, &DolphinView::slotRoleEditingFinished
);
1856 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1858 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1859 this, &DolphinView::slotRoleEditingFinished
);
1861 const KFileItemList items
= selectedItems();
1862 if (items
.count() != 1) {
1866 if (role
== "text") {
1867 const KFileItem oldItem
= items
.first();
1868 const EditResult retVal
= value
.value
<EditResult
>();
1869 const QString newName
= retVal
.newName
;
1870 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1Char('.') && newName
!= QLatin1String("..")) {
1871 const QUrl oldUrl
= oldItem
.url();
1873 QUrl newUrl
= oldUrl
.adjusted(QUrl::RemoveFilename
);
1874 newUrl
.setPath(newUrl
.path() + KIO::encodeFileName(newName
));
1877 //Confirm hiding file/directory by renaming inline
1878 if (!hiddenFilesShown() && newName
.startsWith(QLatin1Char('.')) && !oldItem
.name().startsWith(QLatin1Char('.'))) {
1879 KGuiItem
yesGuiItem(KStandardGuiItem::yes());
1880 yesGuiItem
.setText(i18nc("@action:button", "Rename and Hide"));
1882 const auto code
= KMessageBox::questionYesNo(this,
1883 oldItem
.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
1884 "Do you still want to rename it?")
1885 : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
1886 "Do you still want to rename it?"),
1887 oldItem
.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"),
1889 KStandardGuiItem::cancel(),
1890 QStringLiteral("ConfirmHide")
1893 if (code
== KMessageBox::No
) {
1899 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1900 if (!newNameExistsAlready
&& m_model
->index(oldUrl
) == index
) {
1901 // Only change the data in the model if no item with the new name
1902 // is in the model yet. If there is an item with the new name
1903 // already, calling KIO::CopyJob will open a dialog
1904 // asking for a new name, and KFileItemModel will update the
1905 // data when the dir lister signals that the file name has changed.
1906 QHash
<QByteArray
, QVariant
> data
;
1907 data
.insert(role
, retVal
.newName
);
1908 m_model
->setData(index
, data
);
1911 KIO::Job
* job
= KIO::moveAs(oldUrl
, newUrl
);
1912 KJobWidgets::setWindow(job
, this);
1913 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename
, {oldUrl
}, newUrl
, job
);
1914 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
1916 forceUrlsSelection(newUrl
, {newUrl
});
1918 if (!newNameExistsAlready
) {
1919 // Only connect the result signal if there is no item with the new name
1920 // in the model yet, see bug 328262.
1921 connect(job
, &KJob::result
, this, &DolphinView::slotRenamingResult
);
1924 if (retVal
.direction
!= EditDone
) {
1925 const short indexShift
= retVal
.direction
== EditNext
? 1 : -1;
1926 m_container
->controller()->selectionManager()->setSelected(index
, 1, KItemListSelectionManager::Deselect
);
1927 m_container
->controller()->selectionManager()->setSelected(index
+ indexShift
, 1,
1928 KItemListSelectionManager::Select
);
1929 renameSelectedItems();
1934 void DolphinView::loadDirectory(const QUrl
& url
, bool reload
)
1936 if (!url
.isValid()) {
1937 const QString
location(url
.toDisplayString(QUrl::PreferLocalFile
));
1938 if (location
.isEmpty()) {
1939 Q_EMIT
errorMessage(i18nc("@info:status", "The location is empty."));
1941 Q_EMIT
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1947 m_model
->refreshDirectory(url
);
1949 m_model
->loadDirectory(url
);
1953 void DolphinView::applyViewProperties()
1955 const ViewProperties
props(viewPropertiesUrl());
1956 applyViewProperties(props
);
1959 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1961 m_view
->beginTransaction();
1963 const Mode mode
= props
.viewMode();
1964 if (m_mode
!= mode
) {
1965 const Mode previousMode
= m_mode
;
1968 // Changing the mode might result in changing
1969 // the zoom level. Remember the old zoom level so
1970 // that zoomLevelChanged() can get emitted.
1971 const int oldZoomLevel
= m_view
->zoomLevel();
1974 Q_EMIT
modeChanged(m_mode
, previousMode
);
1976 if (m_view
->zoomLevel() != oldZoomLevel
) {
1977 Q_EMIT
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1981 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1982 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1983 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1984 Q_EMIT
hiddenFilesShownChanged(hiddenFilesShown
);
1987 const bool groupedSorting
= props
.groupedSorting();
1988 if (groupedSorting
!= m_model
->groupedSorting()) {
1989 m_model
->setGroupedSorting(groupedSorting
);
1990 Q_EMIT
groupedSortingChanged(groupedSorting
);
1993 const QByteArray sortRole
= props
.sortRole();
1994 if (sortRole
!= m_model
->sortRole()) {
1995 m_model
->setSortRole(sortRole
);
1996 Q_EMIT
sortRoleChanged(sortRole
);
1999 const Qt::SortOrder sortOrder
= props
.sortOrder();
2000 if (sortOrder
!= m_model
->sortOrder()) {
2001 m_model
->setSortOrder(sortOrder
);
2002 Q_EMIT
sortOrderChanged(sortOrder
);
2005 const bool sortFoldersFirst
= props
.sortFoldersFirst();
2006 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
2007 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
2008 Q_EMIT
sortFoldersFirstChanged(sortFoldersFirst
);
2011 const bool sortHiddenLast
= props
.sortHiddenLast();
2012 if (sortHiddenLast
!= m_model
->sortHiddenLast()) {
2013 m_model
->setSortHiddenLast(sortHiddenLast
);
2014 Q_EMIT
sortHiddenLastChanged(sortHiddenLast
);
2017 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
2018 if (visibleRoles
!= m_visibleRoles
) {
2019 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
2020 m_visibleRoles
= visibleRoles
;
2021 m_view
->setVisibleRoles(visibleRoles
);
2022 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
2025 const bool previewsShown
= props
.previewsShown();
2026 if (previewsShown
!= m_view
->previewsShown()) {
2027 const int oldZoomLevel
= zoomLevel();
2029 m_view
->setPreviewsShown(previewsShown
);
2030 Q_EMIT
previewsShownChanged(previewsShown
);
2032 // Changing the preview-state might result in a changed zoom-level
2033 if (oldZoomLevel
!= zoomLevel()) {
2034 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
2038 KItemListView
* itemListView
= m_container
->controller()->view();
2039 if (itemListView
->isHeaderVisible()) {
2040 KItemListHeader
* header
= itemListView
->header();
2041 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
2042 const int rolesCount
= m_visibleRoles
.count();
2043 if (headerColumnWidths
.count() == rolesCount
) {
2044 header
->setAutomaticColumnResizing(false);
2046 QHash
<QByteArray
, qreal
> columnWidths
;
2047 for (int i
= 0; i
< rolesCount
; ++i
) {
2048 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
2050 header
->setColumnWidths(columnWidths
);
2052 header
->setAutomaticColumnResizing(true);
2054 header
->setSidePadding(DetailsModeSettings::sidePadding());
2057 m_view
->endTransaction();
2060 void DolphinView::applyModeToView()
2063 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
2064 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
2065 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
2066 default: Q_ASSERT(false); break;
2070 void DolphinView::pasteToUrl(const QUrl
& url
)
2072 KIO::PasteJob
*job
= KIO::paste(QApplication::clipboard()->mimeData(), url
);
2073 KJobWidgets::setWindow(job
, this);
2074 m_clearSelectionBeforeSelectingNewItems
= true;
2075 m_markFirstNewlySelectedItemAsCurrent
= true;
2076 connect(job
, &KIO::PasteJob::itemCreated
, this, &DolphinView::slotItemCreated
);
2077 connect(job
, &KIO::PasteJob::result
, this, &DolphinView::slotJobResult
);
2080 QList
<QUrl
> DolphinView::simplifiedSelectedUrls() const
2084 const KFileItemList items
= selectedItems();
2085 urls
.reserve(items
.count());
2086 for (const KFileItem
& item
: items
) {
2087 urls
.append(item
.url());
2090 if (itemsExpandable()) {
2091 // TODO: Check if we still need KDirModel for this in KDE 5.0
2092 urls
= KDirModel::simplifiedUrlList(urls
);
2098 QMimeData
* DolphinView::selectionMimeData() const
2100 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
2101 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
2103 return m_model
->createMimeData(selectedIndexes
);
2106 void DolphinView::updateWritableState()
2108 const bool wasFolderWritable
= m_isFolderWritable
;
2109 m_isFolderWritable
= false;
2111 KFileItem item
= m_model
->rootItem();
2112 if (item
.isNull()) {
2113 // Try to find out if the URL is writable even if the "root item" is
2114 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
2115 item
= KFileItem(url());
2116 item
.setDelayedMimeTypes(true);
2119 KFileItemListProperties
capabilities(KFileItemList() << item
);
2120 m_isFolderWritable
= capabilities
.supportsWriting();
2122 if (m_isFolderWritable
!= wasFolderWritable
) {
2123 Q_EMIT
writeStateChanged(m_isFolderWritable
);
2127 QUrl
DolphinView::viewPropertiesUrl() const
2129 if (m_viewPropertiesContext
.isEmpty()) {
2134 url
.setScheme(m_url
.scheme());
2135 url
.setPath(m_viewPropertiesContext
);
2139 void DolphinView::slotRenameDialogRenamingFinished(const QList
<QUrl
>& urls
)
2141 forceUrlsSelection(urls
.first(), urls
);
2144 void DolphinView::forceUrlsSelection(const QUrl
& current
, const QList
<QUrl
>& selected
)
2147 m_clearSelectionBeforeSelectingNewItems
= true;
2148 markUrlAsCurrent(current
);
2149 markUrlsAsSelected(selected
);
2152 void DolphinView::copyPathToClipboard()
2154 const KFileItemList list
= selectedItems();
2155 if (list
.isEmpty()) {
2158 const KFileItem
& item
= list
.at(0);
2159 QString path
= item
.localPath();
2160 if (path
.isEmpty()) {
2161 path
= item
.url().toDisplayString();
2163 QClipboard
* clipboard
= QApplication::clipboard();
2164 if (clipboard
== nullptr) {
2167 clipboard
->setText(path
);
2170 void DolphinView::slotIncreaseZoom()
2172 setZoomLevel(zoomLevel() + 1);
2175 void DolphinView::slotDecreaseZoom()
2177 setZoomLevel(zoomLevel() - 1);
2180 void DolphinView::slotSwipeUp()
2182 Q_EMIT
goUpRequested();
2185 void DolphinView::showLoadingPlaceholder()
2187 m_placeholderLabel
->setText(i18n("Loading..."));
2188 m_placeholderLabel
->setVisible(true);
2191 void DolphinView::updatePlaceholderLabel()
2193 m_showLoadingPlaceholderTimer
->stop();
2194 if (itemsCount() > 0) {
2195 m_placeholderLabel
->setVisible(false);
2199 if (m_loadingState
== LoadingState::Loading
) {
2200 m_placeholderLabel
->setVisible(false);
2201 m_showLoadingPlaceholderTimer
->start();
2205 if (m_loadingState
== LoadingState::Canceled
) {
2206 m_placeholderLabel
->setText(i18n("Loading canceled"));
2207 } else if (!nameFilter().isEmpty()) {
2208 m_placeholderLabel
->setText(i18n("No items matching the filter"));
2209 } else if (m_url
.scheme() == QLatin1String("baloosearch") || m_url
.scheme() == QLatin1String("filenamesearch")) {
2210 m_placeholderLabel
->setText(i18n("No items matching the search"));
2211 } else if (m_url
.scheme() == QLatin1String("trash") && m_url
.path() == QLatin1String("/")) {
2212 m_placeholderLabel
->setText(i18n("Trash is empty"));
2213 } else if (m_url
.scheme() == QLatin1String("tags")) {
2214 if (m_url
.path() == QLatin1Char('/')) {
2215 m_placeholderLabel
->setText(i18n("No tags"));
2217 const QString tagName
= m_url
.path().mid(1); // Remove leading /
2218 m_placeholderLabel
->setText(i18n("No files tagged with \"%1\"", tagName
));
2221 } else if (m_url
.scheme() == QLatin1String("recentlyused")) {
2222 m_placeholderLabel
->setText(i18n("No recently used items"));
2223 } else if (m_url
.scheme() == QLatin1String("smb")) {
2224 m_placeholderLabel
->setText(i18n("No shared folders found"));
2225 } else if (m_url
.scheme() == QLatin1String("network")) {
2226 m_placeholderLabel
->setText(i18n("No relevant network resources found"));
2227 } else if (m_url
.scheme() == QLatin1String("mtp") && m_url
.path() == QLatin1String("/")) {
2228 m_placeholderLabel
->setText(i18n("No MTP-compatible devices found"));
2229 } else if (m_url
.scheme() == QLatin1String("bluetooth")) {
2230 m_placeholderLabel
->setText(i18n("No Bluetooth devices found"));
2232 m_placeholderLabel
->setText(i18n("Folder is empty"));
2235 m_placeholderLabel
->setVisible(true);
2238 void DolphinView::tryShowNameToolTip(QHelpEvent
* event
)
2240 if (!GeneralSettings::showToolTips() && m_mode
== DolphinView::IconsView
) {
2241 const std::optional
<int> index
= m_view
->itemAt(event
->pos());
2243 if (!index
.has_value()) {
2247 // Check whether the filename has been elided
2248 const bool isElided
= m_view
->isElided(index
.value());
2251 const KFileItem item
= m_model
->fileItem(index
.value());
2252 const QString text
= item
.text();
2253 const QPoint pos
= mapToGlobal(event
->pos());
2254 QToolTip::showText(pos
, text
);