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 <kwidgetsaddons_version.h>
52 #include <QAbstractItemView>
53 #include <QActionGroup>
54 #include <QApplication>
57 #include <QGraphicsOpacityEffect>
58 #include <QGraphicsSceneDragDropEvent>
61 #include <QMimeDatabase>
62 #include <QPixmapCache>
67 #include <QVBoxLayout>
69 DolphinView::DolphinView(const QUrl
& url
, QWidget
* parent
) :
72 m_tabsForFiles(false),
73 m_assureVisibleCurrentIndex(false),
74 m_isFolderWritable(true),
77 m_viewPropertiesContext(),
78 m_mode(DolphinView::IconsView
),
84 m_toolTipManager(nullptr),
85 m_selectionChangedTimer(nullptr),
87 m_scrollToCurrentItem(false),
88 m_restoredContentsPosition(),
90 m_clearSelectionBeforeSelectingNewItems(false),
91 m_markFirstNewlySelectedItemAsCurrent(false),
92 m_versionControlObserver(nullptr),
93 m_twoClicksRenamingTimer(nullptr),
94 m_placeholderLabel(nullptr),
95 m_showLoadingPlaceholderTimer(nullptr)
97 m_topLayout
= new QVBoxLayout(this);
98 m_topLayout
->setSpacing(0);
99 m_topLayout
->setContentsMargins(0, 0, 0, 0);
101 // When a new item has been created by the "Create New..." menu, the item should
102 // get selected and it must be assured that the item will get visible. As the
103 // creation is done asynchronously, several signals must be checked:
104 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated
,
105 this, &DolphinView::observeCreatedItem
);
107 m_selectionChangedTimer
= new QTimer(this);
108 m_selectionChangedTimer
->setSingleShot(true);
109 m_selectionChangedTimer
->setInterval(300);
110 connect(m_selectionChangedTimer
, &QTimer::timeout
,
111 this, &DolphinView::emitSelectionChangedSignal
);
113 m_model
= new KFileItemModel(this);
114 m_view
= new DolphinItemListView();
115 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting
);
116 m_view
->setVisibleRoles({"text"});
119 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
120 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
121 controller
->setAutoActivationDelay(delay
);
123 // The EnlargeSmallPreviews setting can only be changed after the model
124 // has been set in the view by KItemListController.
125 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
127 m_container
= new KItemListContainer(controller
, this);
128 m_container
->installEventFilter(this);
129 setFocusProxy(m_container
);
130 connect(m_container
->horizontalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
131 connect(m_container
->verticalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
133 m_showLoadingPlaceholderTimer
= new QTimer(this);
134 m_showLoadingPlaceholderTimer
->setInterval(500);
135 m_showLoadingPlaceholderTimer
->setSingleShot(true);
136 connect(m_showLoadingPlaceholderTimer
, &QTimer::timeout
, this, &DolphinView::showLoadingPlaceholder
);
138 // Show some placeholder text for empty folders
139 // This is made using a heavily-modified QLabel rather than a KTitleWidget
140 // because KTitleWidget can't be told to turn off mouse-selectable text
141 m_placeholderLabel
= new QLabel(this);
142 QFont placeholderLabelFont
;
143 // To match the size of a level 2 Heading/KTitleWidget
144 placeholderLabelFont
.setPointSize(qRound(placeholderLabelFont
.pointSize() * 1.3));
145 m_placeholderLabel
->setFont(placeholderLabelFont
);
146 m_placeholderLabel
->setTextInteractionFlags(Qt::NoTextInteraction
);
147 m_placeholderLabel
->setWordWrap(true);
148 m_placeholderLabel
->setAlignment(Qt::AlignCenter
);
149 // Match opacity of QML placeholder label component
150 auto *effect
= new QGraphicsOpacityEffect(m_placeholderLabel
);
151 effect
->setOpacity(0.5);
152 m_placeholderLabel
->setGraphicsEffect(effect
);
153 // Set initial text and visibility
154 updatePlaceholderLabel();
156 auto *centeringLayout
= new QVBoxLayout(m_container
);
157 centeringLayout
->addWidget(m_placeholderLabel
);
158 centeringLayout
->setAlignment(m_placeholderLabel
, Qt::AlignCenter
);
160 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
161 connect(controller
, &KItemListController::itemActivated
, this, &DolphinView::slotItemActivated
);
162 connect(controller
, &KItemListController::itemsActivated
, this, &DolphinView::slotItemsActivated
);
163 connect(controller
, &KItemListController::itemMiddleClicked
, this, &DolphinView::slotItemMiddleClicked
);
164 connect(controller
, &KItemListController::itemContextMenuRequested
, this, &DolphinView::slotItemContextMenuRequested
);
165 connect(controller
, &KItemListController::viewContextMenuRequested
, this, &DolphinView::slotViewContextMenuRequested
);
166 connect(controller
, &KItemListController::headerContextMenuRequested
, this, &DolphinView::slotHeaderContextMenuRequested
);
167 connect(controller
, &KItemListController::mouseButtonPressed
, this, &DolphinView::slotMouseButtonPressed
);
168 connect(controller
, &KItemListController::itemHovered
, this, &DolphinView::slotItemHovered
);
169 connect(controller
, &KItemListController::itemUnhovered
, this, &DolphinView::slotItemUnhovered
);
170 connect(controller
, &KItemListController::itemDropEvent
, this, &DolphinView::slotItemDropEvent
);
171 connect(controller
, &KItemListController::escapePressed
, this, &DolphinView::stopLoading
);
172 connect(controller
, &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
173 connect(controller
, &KItemListController::selectedItemTextPressed
, this, &DolphinView::slotSelectedItemTextPressed
);
174 connect(controller
, &KItemListController::increaseZoom
, this, &DolphinView::slotIncreaseZoom
);
175 connect(controller
, &KItemListController::decreaseZoom
, this, &DolphinView::slotDecreaseZoom
);
176 connect(controller
, &KItemListController::swipeUp
, this, &DolphinView::slotSwipeUp
);
177 connect(controller
, &KItemListController::selectionModeChangeRequested
, this, &DolphinView::selectionModeChangeRequested
);
179 connect(m_model
, &KFileItemModel::directoryLoadingStarted
, this, &DolphinView::slotDirectoryLoadingStarted
);
180 connect(m_model
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
181 connect(m_model
, &KFileItemModel::directoryLoadingCanceled
, this, &DolphinView::slotDirectoryLoadingCanceled
);
182 connect(m_model
, &KFileItemModel::directoryLoadingProgress
, this, &DolphinView::directoryLoadingProgress
);
183 connect(m_model
, &KFileItemModel::directorySortingProgress
, this, &DolphinView::directorySortingProgress
);
184 connect(m_model
, &KFileItemModel::itemsChanged
,
185 this, &DolphinView::slotItemsChanged
);
186 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &DolphinView::itemCountChanged
);
187 connect(m_model
, &KFileItemModel::itemsInserted
, this, &DolphinView::itemCountChanged
);
188 connect(m_model
, &KFileItemModel::infoMessage
, this, &DolphinView::infoMessage
);
189 connect(m_model
, &KFileItemModel::errorMessage
, this, &DolphinView::errorMessage
);
190 connect(m_model
, &KFileItemModel::directoryRedirection
, this, &DolphinView::slotDirectoryRedirection
);
191 connect(m_model
, &KFileItemModel::urlIsFileError
, this, &DolphinView::urlIsFileError
);
192 connect(m_model
, &KFileItemModel::fileItemsChanged
, this, &DolphinView::fileItemsChanged
);
194 connect(this, &DolphinView::itemCountChanged
,
195 this, &DolphinView::updatePlaceholderLabel
);
197 m_view
->installEventFilter(this);
198 connect(m_view
, &DolphinItemListView::sortOrderChanged
,
199 this, &DolphinView::slotSortOrderChangedByHeader
);
200 connect(m_view
, &DolphinItemListView::sortRoleChanged
,
201 this, &DolphinView::slotSortRoleChangedByHeader
);
202 connect(m_view
, &DolphinItemListView::visibleRolesChanged
,
203 this, &DolphinView::slotVisibleRolesChangedByHeader
);
204 connect(m_view
, &DolphinItemListView::roleEditingCanceled
,
205 this, &DolphinView::slotRoleEditingCanceled
);
206 connect(m_view
->header(), &KItemListHeader::columnWidthChangeFinished
,
207 this, &DolphinView::slotHeaderColumnWidthChangeFinished
);
208 connect(m_view
->header(), &KItemListHeader::sidePaddingChanged
,
209 this, &DolphinView::slotSidePaddingWidthChanged
);
211 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
212 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
,
213 this, &DolphinView::slotSelectionChanged
);
216 m_toolTipManager
= new ToolTipManager(this);
217 connect(m_toolTipManager
, &ToolTipManager::urlActivated
, this, &DolphinView::urlActivated
);
220 m_versionControlObserver
= new VersionControlObserver(this);
221 m_versionControlObserver
->setView(this);
222 m_versionControlObserver
->setModel(m_model
);
223 connect(m_versionControlObserver
, &VersionControlObserver::infoMessage
, this, &DolphinView::infoMessage
);
224 connect(m_versionControlObserver
, &VersionControlObserver::errorMessage
, this, &DolphinView::errorMessage
);
225 connect(m_versionControlObserver
, &VersionControlObserver::operationCompletedMessage
, this, &DolphinView::operationCompletedMessage
);
227 m_twoClicksRenamingTimer
= new QTimer(this);
228 m_twoClicksRenamingTimer
->setSingleShot(true);
229 connect(m_twoClicksRenamingTimer
, &QTimer::timeout
, this, &DolphinView::slotTwoClicksRenamingTimerTimeout
);
231 applyViewProperties();
232 m_topLayout
->addWidget(m_container
);
237 DolphinView::~DolphinView()
239 disconnect(m_container
->controller(), &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
242 QUrl
DolphinView::url() const
247 void DolphinView::setActive(bool active
)
249 if (active
== m_active
) {
258 m_container
->setFocus();
260 Q_EMIT
writeStateChanged(m_isFolderWritable
);
264 bool DolphinView::isActive() const
269 void DolphinView::setViewMode(Mode mode
)
271 if (mode
!= m_mode
) {
272 ViewProperties
props(viewPropertiesUrl());
273 props
.setViewMode(mode
);
275 // We pass the new ViewProperties to applyViewProperties, rather than
276 // storing them on disk and letting applyViewProperties() read them
277 // from there, to prevent that changing the view mode fails if the
278 // .directory file is not writable (see bug 318534).
279 applyViewProperties(props
);
283 DolphinView::Mode
DolphinView::viewMode() const
288 void DolphinView::setSelectionModeEnabled(const bool enabled
)
291 m_proxyStyle
= std::make_unique
<SelectionMode::SingleClickSelectionProxyStyle
>();
292 setStyle(m_proxyStyle
.get());
293 m_view
->setStyle(m_proxyStyle
.get());
294 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False
);
296 setStyle(QApplication::style());
297 m_view
->setStyle(QApplication::style());
298 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting
);
300 m_container
->controller()->setSelectionModeEnabled(enabled
);
303 bool DolphinView::selectionMode() const
305 return m_container
->controller()->selectionMode();
308 void DolphinView::setPreviewsShown(bool show
)
310 if (previewsShown() == show
) {
314 ViewProperties
props(viewPropertiesUrl());
315 props
.setPreviewsShown(show
);
317 const int oldZoomLevel
= m_view
->zoomLevel();
318 m_view
->setPreviewsShown(show
);
319 Q_EMIT
previewsShownChanged(show
);
321 const int newZoomLevel
= m_view
->zoomLevel();
322 if (newZoomLevel
!= oldZoomLevel
) {
323 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
327 bool DolphinView::previewsShown() const
329 return m_view
->previewsShown();
332 void DolphinView::setHiddenFilesShown(bool show
)
334 if (m_model
->showHiddenFiles() == show
) {
338 const KFileItemList itemList
= selectedItems();
339 m_selectedUrls
.clear();
340 m_selectedUrls
= itemList
.urlList();
342 ViewProperties
props(viewPropertiesUrl());
343 props
.setHiddenFilesShown(show
);
345 m_model
->setShowHiddenFiles(show
);
346 Q_EMIT
hiddenFilesShownChanged(show
);
349 bool DolphinView::hiddenFilesShown() const
351 return m_model
->showHiddenFiles();
354 void DolphinView::setGroupedSorting(bool grouped
)
356 if (grouped
== groupedSorting()) {
360 ViewProperties
props(viewPropertiesUrl());
361 props
.setGroupedSorting(grouped
);
364 m_container
->controller()->model()->setGroupedSorting(grouped
);
366 Q_EMIT
groupedSortingChanged(grouped
);
369 bool DolphinView::groupedSorting() const
371 return m_model
->groupedSorting();
374 KFileItemList
DolphinView::items() const
377 const int itemCount
= m_model
->count();
378 list
.reserve(itemCount
);
380 for (int i
= 0; i
< itemCount
; ++i
) {
381 list
.append(m_model
->fileItem(i
));
387 int DolphinView::itemsCount() const
389 return m_model
->count();
392 KFileItemList
DolphinView::selectedItems() const
394 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
396 KFileItemList selectedItems
;
397 const auto items
= selectionManager
->selectedItems();
398 selectedItems
.reserve(items
.count());
399 for (int index
: items
) {
400 selectedItems
.append(m_model
->fileItem(index
));
402 return selectedItems
;
405 int DolphinView::selectedItemsCount() const
407 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
408 return selectionManager
->selectedItems().count();
411 void DolphinView::markUrlsAsSelected(const QList
<QUrl
>& urls
)
413 m_selectedUrls
= urls
;
416 void DolphinView::markUrlAsCurrent(const QUrl
&url
)
418 m_currentItemUrl
= url
;
419 m_scrollToCurrentItem
= true;
422 void DolphinView::selectItems(const QRegularExpression
®exp
, bool enabled
)
424 const KItemListSelectionManager::SelectionMode mode
= enabled
425 ? KItemListSelectionManager::Select
426 : KItemListSelectionManager::Deselect
;
427 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
429 for (int index
= 0; index
< m_model
->count(); index
++) {
430 const KFileItem item
= m_model
->fileItem(index
);
431 if (regexp
.match(item
.text()).hasMatch()) {
432 // An alternative approach would be to store the matching items in a KItemSet and
433 // select them in one go after the loop, but we'd need a new function
434 // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
436 selectionManager
->setSelected(index
, 1, mode
);
441 void DolphinView::setZoomLevel(int level
)
443 const int oldZoomLevel
= zoomLevel();
444 m_view
->setZoomLevel(level
);
445 if (zoomLevel() != oldZoomLevel
) {
447 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
451 int DolphinView::zoomLevel() const
453 return m_view
->zoomLevel();
456 void DolphinView::setSortRole(const QByteArray
& role
)
458 if (role
!= sortRole()) {
459 updateSortRole(role
);
463 QByteArray
DolphinView::sortRole() const
465 const KItemModelBase
* model
= m_container
->controller()->model();
466 return model
->sortRole();
469 void DolphinView::setSortOrder(Qt::SortOrder order
)
471 if (sortOrder() != order
) {
472 updateSortOrder(order
);
476 Qt::SortOrder
DolphinView::sortOrder() const
478 return m_model
->sortOrder();
481 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
483 if (sortFoldersFirst() != foldersFirst
) {
484 updateSortFoldersFirst(foldersFirst
);
488 bool DolphinView::sortFoldersFirst() const
490 return m_model
->sortDirectoriesFirst();
493 void DolphinView::setSortHiddenLast(bool hiddenLast
)
495 if (sortHiddenLast() != hiddenLast
) {
496 updateSortHiddenLast(hiddenLast
);
500 bool DolphinView::sortHiddenLast() const
502 return m_model
->sortHiddenLast();
505 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
507 const QList
<QByteArray
> previousRoles
= roles
;
509 ViewProperties
props(viewPropertiesUrl());
510 props
.setVisibleRoles(roles
);
512 m_visibleRoles
= roles
;
513 m_view
->setVisibleRoles(roles
);
515 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousRoles
);
518 QList
<QByteArray
> DolphinView::visibleRoles() const
520 return m_visibleRoles
;
523 void DolphinView::reload()
525 QByteArray viewState
;
526 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
527 saveState(saveStream
);
530 loadDirectory(url(), true);
532 QDataStream
restoreStream(viewState
);
533 restoreState(restoreStream
);
536 void DolphinView::readSettings()
538 const int oldZoomLevel
= m_view
->zoomLevel();
540 GeneralSettings::self()->load();
541 m_view
->readSettings();
542 applyViewProperties();
544 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
545 m_container
->controller()->setAutoActivationDelay(delay
);
547 const int newZoomLevel
= m_view
->zoomLevel();
548 if (newZoomLevel
!= oldZoomLevel
) {
549 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
553 void DolphinView::writeSettings()
555 GeneralSettings::self()->save();
556 m_view
->writeSettings();
559 void DolphinView::setNameFilter(const QString
& nameFilter
)
561 m_model
->setNameFilter(nameFilter
);
564 QString
DolphinView::nameFilter() const
566 return m_model
->nameFilter();
569 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
571 return m_model
->setMimeTypeFilters(filters
);
574 QStringList
DolphinView::mimeTypeFilters() const
576 return m_model
->mimeTypeFilters();
579 void DolphinView::requestStatusBarText()
581 if (m_statJobForStatusBarText
) {
582 // Kill the pending request.
583 m_statJobForStatusBarText
->kill();
586 if (m_container
->controller()->selectionManager()->hasSelection()) {
589 KIO::filesize_t totalFileSize
= 0;
591 // Give a summary of the status of the selected files
592 const KFileItemList list
= selectedItems();
593 for (const KFileItem
& item
: list
) {
598 totalFileSize
+= item
.size();
602 if (folderCount
+ fileCount
== 1) {
603 // If only one item is selected, show info about it
604 Q_EMIT
statusBarTextChanged(list
.first().getStatusBarInfo());
606 // At least 2 items are selected
607 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, HasSelection
);
609 } else { // has no selection
610 if (!m_model
->rootItem().url().isValid()) {
614 m_statJobForStatusBarText
= KIO::statDetails(m_model
->rootItem().url(),
615 KIO::StatJob::SourceSide
, KIO::StatRecursiveSize
, KIO::HideProgressInfo
);
616 connect(m_statJobForStatusBarText
, &KJob::result
,
617 this, &DolphinView::slotStatJobResult
);
618 m_statJobForStatusBarText
->start();
622 void DolphinView::emitStatusBarText(const int folderCount
, const int fileCount
,
623 KIO::filesize_t totalFileSize
, const Selection selection
)
629 if (selection
== HasSelection
) {
630 // At least 2 items are selected because the case of 1 selected item is handled in
631 // DolphinView::requestStatusBarText().
632 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
633 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
635 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
636 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
639 if (fileCount
> 0 && folderCount
> 0) {
640 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
641 foldersText
, filesText
,
642 KFormat().formatByteSize(totalFileSize
));
643 } else if (fileCount
> 0) {
644 summary
= i18nc("@info:status files (size)", "%1 (%2)",
646 KFormat().formatByteSize(totalFileSize
));
647 } else if (folderCount
> 0) {
648 summary
= foldersText
;
650 summary
= i18nc("@info:status", "0 Folders, 0 Files");
652 Q_EMIT
statusBarTextChanged(summary
);
655 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
657 QList
<QAction
*> actions
;
659 if (items
.isEmpty()) {
660 const KFileItem item
= m_model
->rootItem();
661 if (!item
.isNull()) {
662 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
665 actions
= m_versionControlObserver
->actions(items
);
671 void DolphinView::setUrl(const QUrl
& url
)
683 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
684 this, &DolphinView::slotRoleEditingFinished
);
686 // It is important to clear the items from the model before
687 // applying the view properties, otherwise expensive operations
688 // might be done on the existing items although they get cleared
689 // anyhow afterwards by loadDirectory().
691 applyViewProperties();
694 Q_EMIT
urlChanged(url
);
697 void DolphinView::selectAll()
699 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
700 selectionManager
->setSelected(0, m_model
->count());
703 void DolphinView::invertSelection()
705 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
706 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
709 void DolphinView::clearSelection()
711 m_selectedUrls
.clear();
712 m_container
->controller()->selectionManager()->clearSelection();
715 void DolphinView::renameSelectedItems()
717 const KFileItemList items
= selectedItems();
718 if (items
.isEmpty()) {
722 if (items
.count() == 1 && GeneralSettings::renameInline()) {
723 const int index
= m_model
->index(items
.first());
725 QMetaObject::Connection
* const connection
= new QMetaObject::Connection
;
726 *connection
= connect(m_view
, &KItemListView::scrollingStopped
, this, [=](){
727 QObject::disconnect(*connection
);
730 m_view
->editRole(index
, "text");
734 connect(m_view
, &DolphinItemListView::roleEditingFinished
,
735 this, &DolphinView::slotRoleEditingFinished
);
737 m_view
->scrollToItem(index
);
740 KIO::RenameFileDialog
* dialog
= new KIO::RenameFileDialog(items
, this);
741 connect(dialog
, &KIO::RenameFileDialog::renamingFinished
,
742 this, &DolphinView::slotRenameDialogRenamingFinished
);
747 // Assure that the current index remains visible when KFileItemModel
748 // will notify the view about changed items (which might result in
749 // a changed sorting).
750 m_assureVisibleCurrentIndex
= true;
753 void DolphinView::trashSelectedItems()
755 const QList
<QUrl
> list
= simplifiedSelectedUrls();
756 KIO::JobUiDelegate uiDelegate
;
757 uiDelegate
.setWindow(window());
758 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Trash
, KIO::JobUiDelegate::DefaultConfirmation
)) {
759 KIO::Job
* job
= KIO::trash(list
);
760 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash
, list
, QUrl(QStringLiteral("trash:/")), job
);
761 KJobWidgets::setWindow(job
, this);
762 connect(job
, &KIO::Job::result
,
763 this, &DolphinView::slotTrashFileFinished
);
767 void DolphinView::deleteSelectedItems()
769 const QList
<QUrl
> list
= simplifiedSelectedUrls();
771 KIO::JobUiDelegate uiDelegate
;
772 uiDelegate
.setWindow(window());
773 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Delete
, KIO::JobUiDelegate::DefaultConfirmation
)) {
774 KIO::Job
* job
= KIO::del(list
);
775 KJobWidgets::setWindow(job
, this);
776 connect(job
, &KIO::Job::result
,
777 this, &DolphinView::slotDeleteFileFinished
);
781 void DolphinView::cutSelectedItemsToClipboard()
783 QMimeData
* mimeData
= selectionMimeData();
784 KIO::setClipboardDataCut(mimeData
, true);
785 KUrlMimeData::exportUrlsToPortal(mimeData
);
786 QApplication::clipboard()->setMimeData(mimeData
);
789 void DolphinView::copySelectedItemsToClipboard()
791 QMimeData
*mimeData
= selectionMimeData();
792 KUrlMimeData::exportUrlsToPortal(mimeData
);
793 QApplication::clipboard()->setMimeData(mimeData
);
796 void DolphinView::copySelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
798 KIO::CopyJob
* job
= KIO::copy(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
799 KJobWidgets::setWindow(job
, this);
801 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
802 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
803 KIO::FileUndoManager::self()->recordCopyJob(job
);
806 void DolphinView::moveSelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
808 KIO::CopyJob
* job
= KIO::move(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
809 KJobWidgets::setWindow(job
, this);
811 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
812 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
813 KIO::FileUndoManager::self()->recordCopyJob(job
);
817 void DolphinView::paste()
822 void DolphinView::pasteIntoFolder()
824 const KFileItemList items
= selectedItems();
825 if ((items
.count() == 1) && items
.first().isDir()) {
826 pasteToUrl(items
.first().url());
830 void DolphinView::duplicateSelectedItems()
832 const KFileItemList itemList
= selectedItems();
833 if (itemList
.isEmpty()) {
837 const QMimeDatabase db
;
839 // Duplicate all selected items and append "copy" to the end of the file name
840 // but before the filename extension, if present
841 QList
<QUrl
> newSelection
;
842 for (const auto &item
: itemList
) {
843 const QUrl originalURL
= item
.url();
844 const QString originalDirectoryPath
= originalURL
.adjusted(QUrl::RemoveFilename
).path();
845 const QString originalFileName
= item
.name();
847 QString extension
= db
.suffixForFileName(originalFileName
);
849 QUrl duplicateURL
= originalURL
;
851 // No extension; new filename is "<oldfilename> copy"
852 if (extension
.isEmpty()) {
853 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFileName
));
854 // There's an extension; new filename is "<oldfilename> copy.<extension>"
856 // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it
857 extension
= QLatin1String(".") + extension
;
858 const QString originalFilenameWithoutExtension
= originalFileName
.chopped(extension
.size());
859 // Preserve file's original filename extension in case the casing differs
860 // from what QMimeDatabase::suffixForFileName() returned
861 const QString originalExtension
= originalFileName
.right(extension
.size());
862 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension
) + originalExtension
);
865 KIO::CopyJob
* job
= KIO::copyAs(originalURL
, duplicateURL
);
866 KJobWidgets::setWindow(job
, this);
869 newSelection
<< duplicateURL
;
870 KIO::FileUndoManager::self()->recordCopyJob(job
);
874 forceUrlsSelection(newSelection
.first(), newSelection
);
877 void DolphinView::stopLoading()
879 m_model
->cancelDirectoryLoading();
882 void DolphinView::updatePalette()
884 QColor color
= KColorScheme(isActiveWindow() ? QPalette::Active
: QPalette::Inactive
, KColorScheme::View
).background().color();
889 QWidget
* viewport
= m_container
->viewport();
892 palette
.setColor(viewport
->backgroundRole(), color
);
893 viewport
->setPalette(palette
);
899 void DolphinView::abortTwoClicksRenaming()
901 m_twoClicksRenamingItemUrl
.clear();
902 m_twoClicksRenamingTimer
->stop();
905 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
907 switch (event
->type()) {
908 case QEvent::PaletteChange
:
910 QPixmapCache::clear();
913 case QEvent::WindowActivate
:
914 case QEvent::WindowDeactivate
:
918 case QEvent::KeyPress
:
919 hideToolTip(ToolTipManager::HideBehavior::Instantly
);
920 if (GeneralSettings::useTabForSwitchingSplitView()) {
921 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
922 if (keyEvent
->key() == Qt::Key_Tab
&& keyEvent
->modifiers() == Qt::NoModifier
) {
923 Q_EMIT
toggleActiveViewRequested();
928 case QEvent::FocusIn
:
929 if (watched
== m_container
) {
934 case QEvent::GraphicsSceneDragEnter
:
935 if (watched
== m_view
) {
937 abortTwoClicksRenaming();
941 case QEvent::GraphicsSceneDragLeave
:
942 if (watched
== m_view
) {
947 case QEvent::GraphicsSceneDrop
:
948 if (watched
== m_view
) {
953 case QEvent::ToolTip
:
954 tryShowNameToolTip(static_cast<QHelpEvent
*>(event
));
960 return QWidget::eventFilter(watched
, event
);
963 void DolphinView::wheelEvent(QWheelEvent
* event
)
965 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
966 const QPoint numDegrees
= event
->angleDelta() / 8;
967 const QPoint numSteps
= numDegrees
/ 15;
969 setZoomLevel(zoomLevel() + numSteps
.y());
976 void DolphinView::hideEvent(QHideEvent
* event
)
979 QWidget::hideEvent(event
);
982 bool DolphinView::event(QEvent
* event
)
984 if (event
->type() == QEvent::WindowDeactivate
) {
986 * Dolphin leaves file preview tooltips open even when is not visible.
988 * Hide tool-tip when Dolphin loses focus.
991 abortTwoClicksRenaming();
994 return QWidget::event(event
);
997 void DolphinView::activate()
1002 void DolphinView::slotItemActivated(int index
)
1004 abortTwoClicksRenaming();
1006 const KFileItem item
= m_model
->fileItem(index
);
1007 if (!item
.isNull()) {
1008 Q_EMIT
itemActivated(item
);
1012 void DolphinView::slotItemsActivated(const KItemSet
&indexes
)
1014 Q_ASSERT(indexes
.count() >= 2);
1016 abortTwoClicksRenaming();
1018 const auto modifiers
= QGuiApplication::keyboardModifiers();
1020 if (indexes
.count() > 5) {
1021 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
1022 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1023 const int answer
= KMessageBox::warningTwoActions(this, question
, {},
1025 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1027 KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes
.count()),
1028 QStringLiteral("document-open")),
1029 KStandardGuiItem::cancel());
1030 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1031 if (answer
!= KMessageBox::PrimaryAction
) {
1033 if (answer
!= KMessageBox::Yes
) {
1039 KFileItemList items
;
1040 items
.reserve(indexes
.count());
1042 for (int index
: indexes
) {
1043 KFileItem item
= m_model
->fileItem(index
);
1044 const QUrl
& url
= openItemAsFolderUrl(item
);
1046 if (!url
.isEmpty()) {
1047 // Open folders in new tabs or in new windows depending on the modifier
1048 // The ctrl+shift behavior is ignored because we are handling multiple items
1049 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1050 if (modifiers
& Qt::ShiftModifier
&& !(modifiers
& Qt::ControlModifier
)) {
1051 Q_EMIT
windowRequested(url
);
1053 Q_EMIT
tabRequested(url
);
1060 if (items
.count() == 1) {
1061 Q_EMIT
itemActivated(items
.first());
1062 } else if (items
.count() > 1) {
1063 Q_EMIT
itemsActivated(items
);
1067 void DolphinView::slotItemMiddleClicked(int index
)
1069 const KFileItem
& item
= m_model
->fileItem(index
);
1070 const QUrl
& url
= openItemAsFolderUrl(item
);
1071 const auto modifiers
= QGuiApplication::keyboardModifiers();
1072 if (!url
.isEmpty()) {
1073 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1074 if (modifiers
& Qt::ShiftModifier
) {
1075 Q_EMIT
activeTabRequested(url
);
1077 Q_EMIT
tabRequested(url
);
1079 } else if (isTabsForFilesEnabled()) {
1080 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1081 if (modifiers
& Qt::ShiftModifier
) {
1082 Q_EMIT
activeTabRequested(item
.url());
1084 Q_EMIT
tabRequested(item
.url());
1089 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
1091 // Force emit of a selection changed signal before we request the
1092 // context menu, to update the edit-actions first. (See Bug 294013)
1093 if (m_selectionChangedTimer
->isActive()) {
1094 emitSelectionChangedSignal();
1097 const KFileItem item
= m_model
->fileItem(index
);
1098 Q_EMIT
requestContextMenu(pos
.toPoint(), item
, selectedItems(), url());
1101 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
1103 Q_EMIT
requestContextMenu(pos
.toPoint(), KFileItem(), selectedItems(), url());
1106 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
1108 ViewProperties
props(viewPropertiesUrl());
1110 QPointer
<QMenu
> menu
= new QMenu(QApplication::activeWindow());
1112 KItemListView
* view
= m_container
->controller()->view();
1113 const QList
<QByteArray
> visibleRolesSet
= view
->visibleRoles();
1115 bool indexingEnabled
= false;
1117 Baloo::IndexerConfig config
;
1118 indexingEnabled
= config
.fileIndexingEnabled();
1122 QMenu
* groupMenu
= nullptr;
1124 // Add all roles to the menu that can be shown or hidden by the user
1125 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
1126 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
1127 if (info
.role
== "text") {
1128 // It should not be possible to hide the "text" role
1132 const QString text
= m_model
->roleDescription(info
.role
);
1133 QAction
* action
= nullptr;
1134 if (info
.group
.isEmpty()) {
1135 action
= menu
->addAction(text
);
1137 if (!groupMenu
|| info
.group
!= groupName
) {
1138 groupName
= info
.group
;
1139 groupMenu
= menu
->addMenu(groupName
);
1142 action
= groupMenu
->addAction(text
);
1145 action
->setCheckable(true);
1146 action
->setChecked(visibleRolesSet
.contains(info
.role
));
1147 action
->setData(info
.role
);
1149 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
1150 (info
.requiresBaloo
) ||
1151 (info
.requiresIndexer
&& indexingEnabled
);
1152 action
->setEnabled(enable
);
1155 menu
->addSeparator();
1157 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
1158 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
1160 QAction
* toggleSidePaddingAction
= menu
->addAction(i18nc("@action:inmenu", "Side Padding"));
1161 toggleSidePaddingAction
->setCheckable(true);
1162 toggleSidePaddingAction
->setChecked(view
->header()->sidePadding() > 0);
1164 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
1165 autoAdjustWidthsAction
->setCheckable(true);
1166 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
1167 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
1169 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
1170 customWidthsAction
->setCheckable(true);
1171 customWidthsAction
->setChecked(!autoColumnWidths
);
1172 customWidthsAction
->setActionGroup(widthsGroup
);
1174 QAction
* action
= menu
->exec(pos
.toPoint());
1175 if (menu
&& action
) {
1176 KItemListHeader
* header
= view
->header();
1178 if (action
== autoAdjustWidthsAction
) {
1179 // Clear the column-widths from the viewproperties and turn on
1180 // the automatic resizing of the columns
1181 props
.setHeaderColumnWidths(QList
<int>());
1182 header
->setAutomaticColumnResizing(true);
1183 } else if (action
== customWidthsAction
) {
1184 // Apply the current column-widths as custom column-widths and turn
1185 // off the automatic resizing of the columns
1186 QList
<int> columnWidths
;
1187 const auto visibleRoles
= view
->visibleRoles();
1188 columnWidths
.reserve(visibleRoles
.count());
1189 for (const QByteArray
& role
: visibleRoles
) {
1190 columnWidths
.append(header
->columnWidth(role
));
1192 props
.setHeaderColumnWidths(columnWidths
);
1193 header
->setAutomaticColumnResizing(false);
1194 } else if (action
== toggleSidePaddingAction
) {
1195 header
->setSidePadding(toggleSidePaddingAction
->isChecked() ? 20 : 0);
1197 // Show or hide the selected role
1198 const QByteArray selectedRole
= action
->data().toByteArray();
1200 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
1201 if (action
->isChecked()) {
1202 visibleRoles
.append(selectedRole
);
1204 visibleRoles
.removeOne(selectedRole
);
1207 view
->setVisibleRoles(visibleRoles
);
1208 props
.setVisibleRoles(visibleRoles
);
1210 QList
<int> columnWidths
;
1211 if (!header
->automaticColumnResizing()) {
1212 const auto visibleRoles
= view
->visibleRoles();
1213 columnWidths
.reserve(visibleRoles
.count());
1214 for (const QByteArray
& role
: visibleRoles
) {
1215 columnWidths
.append(header
->columnWidth(role
));
1218 props
.setHeaderColumnWidths(columnWidths
);
1225 void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray
& role
, qreal current
)
1227 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
1229 ViewProperties
props(viewPropertiesUrl());
1230 QList
<int> columnWidths
= props
.headerColumnWidths();
1231 if (columnWidths
.count() != visibleRoles
.count()) {
1232 columnWidths
.clear();
1233 columnWidths
.reserve(visibleRoles
.count());
1234 const KItemListHeader
* header
= m_view
->header();
1235 for (const QByteArray
& role
: visibleRoles
) {
1236 const int width
= header
->columnWidth(role
);
1237 columnWidths
.append(width
);
1241 const int roleIndex
= visibleRoles
.indexOf(role
);
1242 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
1243 columnWidths
[roleIndex
] = current
;
1245 props
.setHeaderColumnWidths(columnWidths
);
1248 void DolphinView::slotSidePaddingWidthChanged(qreal width
)
1250 ViewProperties
props(viewPropertiesUrl());
1251 DetailsModeSettings::setSidePadding(int(width
));
1252 m_view
->writeSettings();
1255 void DolphinView::slotItemHovered(int index
)
1257 const KFileItem item
= m_model
->fileItem(index
);
1259 if (GeneralSettings::showToolTips() && !m_dragging
) {
1260 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1261 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1262 itemRect
.moveTo(pos
);
1265 auto nativeParent
= nativeParentWidget();
1267 m_toolTipManager
->showToolTip(item
, itemRect
, nativeParent
->windowHandle());
1272 Q_EMIT
requestItemInfo(item
);
1275 void DolphinView::slotItemUnhovered(int index
)
1279 Q_EMIT
requestItemInfo(KFileItem());
1282 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1285 KFileItem destItem
= m_model
->fileItem(index
);
1286 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1287 // Use the URL of the view as drop target if the item is no directory
1289 destItem
= m_model
->rootItem();
1292 // The item represents a directory or desktop-file
1293 destUrl
= destItem
.mostLocalUrl();
1296 QDropEvent
dropEvent(event
->pos().toPoint(),
1297 event
->possibleActions(),
1300 event
->modifiers());
1301 dropUrls(destUrl
, &dropEvent
, this);
1306 void DolphinView::dropUrls(const QUrl
&destUrl
, QDropEvent
*dropEvent
, QWidget
*dropWidget
)
1308 KIO::DropJob
* job
= DragAndDropHelper::dropUrls(destUrl
, dropEvent
, dropWidget
);
1311 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
1313 if (destUrl
== url()) {
1314 // Mark the dropped urls as selected.
1315 m_clearSelectionBeforeSelectingNewItems
= true;
1316 m_markFirstNewlySelectedItemAsCurrent
= true;
1317 connect(job
, &KIO::DropJob::itemCreated
, this, &DolphinView::slotItemCreated
);
1322 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1324 if (previous
!= nullptr) {
1325 Q_ASSERT(qobject_cast
<KFileItemModel
*>(previous
));
1326 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(previous
);
1327 disconnect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1328 m_versionControlObserver
->setModel(nullptr);
1332 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1333 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1334 connect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1335 m_versionControlObserver
->setModel(fileItemModel
);
1339 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1345 if (buttons
& Qt::BackButton
) {
1346 Q_EMIT
goBackRequested();
1347 } else if (buttons
& Qt::ForwardButton
) {
1348 Q_EMIT
goForwardRequested();
1352 void DolphinView::slotSelectedItemTextPressed(int index
)
1354 if (GeneralSettings::renameInline() && !m_view
->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick
)) {
1355 const KFileItem item
= m_model
->fileItem(index
);
1356 const KFileItemListProperties
capabilities(KFileItemList() << item
);
1357 if (capabilities
.supportsMoving()) {
1358 m_twoClicksRenamingItemUrl
= item
.url();
1359 m_twoClicksRenamingTimer
->start(QApplication::doubleClickInterval());
1364 void DolphinView::slotCopyingDone(KIO::Job
*, const QUrl
&, const QUrl
&to
)
1366 slotItemCreated(to
);
1369 void DolphinView::slotItemCreated(const QUrl
& url
)
1371 if (m_markFirstNewlySelectedItemAsCurrent
) {
1372 markUrlAsCurrent(url
);
1373 m_markFirstNewlySelectedItemAsCurrent
= false;
1375 m_selectedUrls
<< url
;
1378 void DolphinView::slotJobResult(KJob
*job
)
1380 if (job
->error() && job
->error() != KIO::ERR_USER_CANCELED
) {
1381 Q_EMIT
errorMessage(job
->errorString());
1383 if (!m_selectedUrls
.isEmpty()) {
1384 m_selectedUrls
= KDirModel::simplifiedUrlList(m_selectedUrls
);
1388 void DolphinView::slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
)
1390 const int currentCount
= current
.count();
1391 const int previousCount
= previous
.count();
1392 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1393 (currentCount
> 0 && previousCount
== 0);
1395 // If nothing has been selected before and something got selected (or if something
1396 // was selected before and now nothing is selected) the selectionChangedSignal must
1397 // be emitted asynchronously as fast as possible to update the edit-actions.
1398 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1399 m_selectionChangedTimer
->start();
1402 void DolphinView::emitSelectionChangedSignal()
1404 m_selectionChangedTimer
->stop();
1405 Q_EMIT
selectionChanged(selectedItems());
1408 void DolphinView::slotStatJobResult(KJob
*job
)
1410 int folderCount
= 0;
1412 KIO::filesize_t totalFileSize
= 0;
1413 bool countFileSize
= true;
1415 const auto entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1416 if (entry
.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE
)) {
1417 // We have a precomputed value.
1418 totalFileSize
= static_cast<KIO::filesize_t
>(
1419 entry
.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE
));
1420 countFileSize
= false;
1423 const int itemCount
= m_model
->count();
1424 for (int i
= 0; i
< itemCount
; ++i
) {
1425 const KFileItem item
= m_model
->fileItem(i
);
1430 if (countFileSize
) {
1431 totalFileSize
+= item
.size();
1435 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, NoSelection
);
1438 void DolphinView::updateSortRole(const QByteArray
& role
)
1440 ViewProperties
props(viewPropertiesUrl());
1441 props
.setSortRole(role
);
1443 KItemModelBase
* model
= m_container
->controller()->model();
1444 model
->setSortRole(role
);
1446 Q_EMIT
sortRoleChanged(role
);
1449 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1451 ViewProperties
props(viewPropertiesUrl());
1452 props
.setSortOrder(order
);
1454 m_model
->setSortOrder(order
);
1456 Q_EMIT
sortOrderChanged(order
);
1459 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1461 ViewProperties
props(viewPropertiesUrl());
1462 props
.setSortFoldersFirst(foldersFirst
);
1464 m_model
->setSortDirectoriesFirst(foldersFirst
);
1466 Q_EMIT
sortFoldersFirstChanged(foldersFirst
);
1469 void DolphinView::updateSortHiddenLast(bool hiddenLast
)
1471 ViewProperties
props(viewPropertiesUrl());
1472 props
.setSortHiddenLast(hiddenLast
);
1474 m_model
->setSortHiddenLast(hiddenLast
);
1476 Q_EMIT
sortHiddenLastChanged(hiddenLast
);
1480 QPair
<bool, QString
> DolphinView::pasteInfo() const
1482 const QMimeData
*mimeData
= QApplication::clipboard()->mimeData();
1483 QPair
<bool, QString
> info
;
1484 info
.second
= KIO::pasteActionText(mimeData
, &info
.first
, rootItem());
1488 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1490 m_tabsForFiles
= tabsForFiles
;
1493 bool DolphinView::isTabsForFilesEnabled() const
1495 return m_tabsForFiles
;
1498 bool DolphinView::itemsExpandable() const
1500 return m_mode
== DetailsView
;
1503 bool DolphinView::isExpanded(const KFileItem
& item
) const
1505 Q_ASSERT(item
.isDir());
1506 Q_ASSERT(items().contains(item
));
1507 if (!itemsExpandable()) {
1510 return m_model
->isExpanded(m_model
->index(item
));
1513 void DolphinView::restoreState(QDataStream
& stream
)
1515 // Read the version number of the view state and check if the version is supported.
1516 quint32 version
= 0;
1519 // The version of the view state isn't supported, we can't restore it.
1523 // Restore the current item that had the keyboard focus
1524 stream
>> m_currentItemUrl
;
1526 // Restore the previously selected items
1527 stream
>> m_selectedUrls
;
1529 // Restore the view position
1530 stream
>> m_restoredContentsPosition
;
1532 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1535 m_model
->restoreExpandedDirectories(urls
);
1538 void DolphinView::saveState(QDataStream
& stream
)
1540 stream
<< quint32(1); // View state version
1542 // Save the current item that has the keyboard focus
1543 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1544 if (currentIndex
!= -1) {
1545 KFileItem item
= m_model
->fileItem(currentIndex
);
1546 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1547 QUrl currentItemUrl
= item
.url();
1548 stream
<< currentItemUrl
;
1553 // Save the selected urls
1554 stream
<< selectedItems().urlList();
1556 // Save view position
1557 const qreal x
= m_container
->horizontalScrollBar()->value();
1558 const qreal y
= m_container
->verticalScrollBar()->value();
1559 stream
<< QPoint(x
, y
);
1561 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1562 stream
<< m_model
->expandedDirectories();
1565 KFileItem
DolphinView::rootItem() const
1567 return m_model
->rootItem();
1570 void DolphinView::setViewPropertiesContext(const QString
& context
)
1572 m_viewPropertiesContext
= context
;
1575 QString
DolphinView::viewPropertiesContext() const
1577 return m_viewPropertiesContext
;
1580 QUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1582 if (item
.isNull()) {
1586 QUrl url
= item
.targetUrl();
1592 if (item
.isMimeTypeKnown()) {
1593 const QString
& mimetype
= item
.mimetype();
1595 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1596 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1597 // zip:/<path>/ when clicking on a zip file, etc.
1598 // The .protocol file specifies the mimetype that the kioslave handles.
1599 // Note that we don't use mimetype inheritance since we don't want to
1600 // open OpenDocument files as zip folders...
1601 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1602 if (!protocol
.isEmpty()) {
1603 url
.setScheme(protocol
);
1608 if (mimetype
== QLatin1String("application/x-desktop")) {
1609 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1610 KDesktopFile
desktopFile(url
.toLocalFile());
1611 if (desktopFile
.hasLinkType()) {
1612 const QString linkUrl
= desktopFile
.readUrl();
1613 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1614 return QUrl::fromUserInput(linkUrl
);
1623 void DolphinView::resetZoomLevel()
1625 ViewModeSettings settings
{m_mode
};
1626 settings
.useDefaults(true);
1627 const int defaultIconSize
= settings
.iconSize();
1628 settings
.useDefaults(false);
1630 setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(QSize(defaultIconSize
, defaultIconSize
)));
1633 void DolphinView::observeCreatedItem(const QUrl
& url
)
1636 forceUrlsSelection(url
, {url
});
1640 void DolphinView::slotDirectoryRedirection(const QUrl
& oldUrl
, const QUrl
& newUrl
)
1642 if (oldUrl
.matches(url(), QUrl::StripTrailingSlash
)) {
1643 Q_EMIT
redirection(oldUrl
, newUrl
);
1644 m_url
= newUrl
; // #186947
1648 void DolphinView::updateViewState()
1650 if (m_currentItemUrl
!= QUrl()) {
1651 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1653 // if there is a selection already, leave it that way
1654 if (!selectionManager
->hasSelection()) {
1655 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1656 if (currentIndex
!= -1) {
1657 selectionManager
->setCurrentItem(currentIndex
);
1659 // scroll to current item and reset the state
1660 if (m_scrollToCurrentItem
) {
1661 m_view
->scrollToItem(currentIndex
);
1662 m_scrollToCurrentItem
= false;
1664 m_currentItemUrl
= QUrl();
1666 selectionManager
->setCurrentItem(0);
1669 m_currentItemUrl
= QUrl();
1673 if (!m_restoredContentsPosition
.isNull()) {
1674 const int x
= m_restoredContentsPosition
.x();
1675 const int y
= m_restoredContentsPosition
.y();
1676 m_restoredContentsPosition
= QPoint();
1678 m_container
->horizontalScrollBar()->setValue(x
);
1679 m_container
->verticalScrollBar()->setValue(y
);
1682 if (!m_selectedUrls
.isEmpty()) {
1683 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1685 // if there is a selection already, leave it that way
1686 if (!selectionManager
->hasSelection()) {
1687 if (m_clearSelectionBeforeSelectingNewItems
) {
1688 selectionManager
->clearSelection();
1689 m_clearSelectionBeforeSelectingNewItems
= false;
1692 KItemSet selectedItems
= selectionManager
->selectedItems();
1694 QList
<QUrl
>::iterator it
= m_selectedUrls
.begin();
1695 while (it
!= m_selectedUrls
.end()) {
1696 const int index
= m_model
->index(*it
);
1698 selectedItems
.insert(index
);
1699 it
= m_selectedUrls
.erase(it
);
1705 if (!selectedItems
.isEmpty()) {
1706 selectionManager
->beginAnchoredSelection(selectionManager
->currentItem());
1707 selectionManager
->setSelectedItems(selectedItems
);
1713 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior
)
1715 if (GeneralSettings::showToolTips()) {
1717 m_toolTipManager
->hideToolTip(behavior
);
1721 } else if (m_mode
== DolphinView::IconsView
) {
1722 QToolTip::hideText();
1726 void DolphinView::slotTwoClicksRenamingTimerTimeout()
1728 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1730 // verify that only one item is selected
1731 if (selectionManager
->selectedItems().count() == 1) {
1732 const int index
= selectionManager
->currentItem();
1733 const QUrl fileItemUrl
= m_model
->fileItem(index
).url();
1735 // check if the selected item was the same item that started the twoClicksRenaming
1736 if (fileItemUrl
.isValid() && m_twoClicksRenamingItemUrl
== fileItemUrl
) {
1737 renameSelectedItems();
1742 void DolphinView::slotTrashFileFinished(KJob
* job
)
1744 if (job
->error() == 0) {
1745 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
1746 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1747 Q_EMIT
errorMessage(job
->errorString());
1751 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1753 if (job
->error() == 0) {
1754 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1755 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1756 Q_EMIT
errorMessage(job
->errorString());
1760 void DolphinView::slotRenamingResult(KJob
* job
)
1763 KIO::CopyJob
*copyJob
= qobject_cast
<KIO::CopyJob
*>(job
);
1765 const QUrl newUrl
= copyJob
->destUrl();
1766 const int index
= m_model
->index(newUrl
);
1768 QHash
<QByteArray
, QVariant
> data
;
1769 const QUrl oldUrl
= copyJob
->srcUrls().at(0);
1770 data
.insert("text", oldUrl
.fileName());
1771 m_model
->setData(index
, data
);
1776 void DolphinView::slotDirectoryLoadingStarted()
1778 m_loadingState
= LoadingState::Loading
;
1779 updatePlaceholderLabel();
1781 // Disable the writestate temporary until it can be determined in a fast way
1782 // in DolphinView::slotDirectoryLoadingCompleted()
1783 if (m_isFolderWritable
) {
1784 m_isFolderWritable
= false;
1785 Q_EMIT
writeStateChanged(m_isFolderWritable
);
1788 Q_EMIT
directoryLoadingStarted();
1791 void DolphinView::slotDirectoryLoadingCompleted()
1793 m_loadingState
= LoadingState::Completed
;
1795 // Update the view-state. This has to be done asynchronously
1796 // because the view might not be in its final state yet.
1797 QTimer::singleShot(0, this, &DolphinView::updateViewState
);
1799 // Update the placeholder label in case we found that the folder was empty
1802 Q_EMIT
directoryLoadingCompleted();
1804 updatePlaceholderLabel();
1805 updateWritableState();
1808 void DolphinView::slotDirectoryLoadingCanceled()
1810 m_loadingState
= LoadingState::Canceled
;
1812 updatePlaceholderLabel();
1814 Q_EMIT
directoryLoadingCanceled();
1817 void DolphinView::slotItemsChanged()
1819 m_assureVisibleCurrentIndex
= false;
1822 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1825 Q_ASSERT(m_model
->sortOrder() == current
);
1827 ViewProperties
props(viewPropertiesUrl());
1828 props
.setSortOrder(current
);
1830 Q_EMIT
sortOrderChanged(current
);
1833 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1836 Q_ASSERT(m_model
->sortRole() == current
);
1838 ViewProperties
props(viewPropertiesUrl());
1839 props
.setSortRole(current
);
1841 Q_EMIT
sortRoleChanged(current
);
1844 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1845 const QList
<QByteArray
>& previous
)
1848 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1850 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1852 m_visibleRoles
= current
;
1854 ViewProperties
props(viewPropertiesUrl());
1855 props
.setVisibleRoles(m_visibleRoles
);
1857 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1860 void DolphinView::slotRoleEditingCanceled()
1862 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1863 this, &DolphinView::slotRoleEditingFinished
);
1866 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1868 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1869 this, &DolphinView::slotRoleEditingFinished
);
1871 const KFileItemList items
= selectedItems();
1872 if (items
.count() != 1) {
1876 if (role
== "text") {
1877 const KFileItem oldItem
= items
.first();
1878 const EditResult retVal
= value
.value
<EditResult
>();
1879 const QString newName
= retVal
.newName
;
1880 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1Char('.') && newName
!= QLatin1String("..")) {
1881 const QUrl oldUrl
= oldItem
.url();
1883 QUrl newUrl
= oldUrl
.adjusted(QUrl::RemoveFilename
);
1884 newUrl
.setPath(newUrl
.path() + KIO::encodeFileName(newName
));
1887 //Confirm hiding file/directory by renaming inline
1888 if (!hiddenFilesShown() && newName
.startsWith(QLatin1Char('.')) && !oldItem
.name().startsWith(QLatin1Char('.'))) {
1889 KGuiItem
yesGuiItem(KStandardGuiItem::yes());
1890 yesGuiItem
.setText(i18nc("@action:button", "Rename and Hide"));
1892 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1893 const auto code
= KMessageBox::questionTwoActions(this,
1895 const auto code
= KMessageBox::questionYesNo(this,
1897 oldItem
.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
1898 "Do you still want to rename it?")
1899 : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
1900 "Do you still want to rename it?"),
1901 oldItem
.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"),
1903 KStandardGuiItem::cancel(),
1904 QStringLiteral("ConfirmHide")
1907 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1908 if (code
== KMessageBox::SecondaryAction
) {
1910 if (code
== KMessageBox::No
) {
1917 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1918 if (!newNameExistsAlready
&& m_model
->index(oldUrl
) == index
) {
1919 // Only change the data in the model if no item with the new name
1920 // is in the model yet. If there is an item with the new name
1921 // already, calling KIO::CopyJob will open a dialog
1922 // asking for a new name, and KFileItemModel will update the
1923 // data when the dir lister signals that the file name has changed.
1924 QHash
<QByteArray
, QVariant
> data
;
1925 data
.insert(role
, retVal
.newName
);
1926 m_model
->setData(index
, data
);
1929 KIO::Job
* job
= KIO::moveAs(oldUrl
, newUrl
);
1930 KJobWidgets::setWindow(job
, this);
1931 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename
, {oldUrl
}, newUrl
, job
);
1932 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
1934 forceUrlsSelection(newUrl
, {newUrl
});
1936 if (!newNameExistsAlready
) {
1937 // Only connect the result signal if there is no item with the new name
1938 // in the model yet, see bug 328262.
1939 connect(job
, &KJob::result
, this, &DolphinView::slotRenamingResult
);
1942 if (retVal
.direction
!= EditDone
) {
1943 const short indexShift
= retVal
.direction
== EditNext
? 1 : -1;
1944 m_container
->controller()->selectionManager()->setSelected(index
, 1, KItemListSelectionManager::Deselect
);
1945 m_container
->controller()->selectionManager()->setSelected(index
+ indexShift
, 1,
1946 KItemListSelectionManager::Select
);
1947 renameSelectedItems();
1952 void DolphinView::loadDirectory(const QUrl
& url
, bool reload
)
1954 if (!url
.isValid()) {
1955 const QString
location(url
.toDisplayString(QUrl::PreferLocalFile
));
1956 if (location
.isEmpty()) {
1957 Q_EMIT
errorMessage(i18nc("@info:status", "The location is empty."));
1959 Q_EMIT
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1965 m_model
->refreshDirectory(url
);
1967 m_model
->loadDirectory(url
);
1971 void DolphinView::applyViewProperties()
1973 const ViewProperties
props(viewPropertiesUrl());
1974 applyViewProperties(props
);
1977 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1979 m_view
->beginTransaction();
1981 const Mode mode
= props
.viewMode();
1982 if (m_mode
!= mode
) {
1983 const Mode previousMode
= m_mode
;
1986 // Changing the mode might result in changing
1987 // the zoom level. Remember the old zoom level so
1988 // that zoomLevelChanged() can get emitted.
1989 const int oldZoomLevel
= m_view
->zoomLevel();
1992 Q_EMIT
modeChanged(m_mode
, previousMode
);
1994 if (m_view
->zoomLevel() != oldZoomLevel
) {
1995 Q_EMIT
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1999 const bool hiddenFilesShown
= props
.hiddenFilesShown();
2000 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
2001 m_model
->setShowHiddenFiles(hiddenFilesShown
);
2002 Q_EMIT
hiddenFilesShownChanged(hiddenFilesShown
);
2005 const bool groupedSorting
= props
.groupedSorting();
2006 if (groupedSorting
!= m_model
->groupedSorting()) {
2007 m_model
->setGroupedSorting(groupedSorting
);
2008 Q_EMIT
groupedSortingChanged(groupedSorting
);
2011 const QByteArray sortRole
= props
.sortRole();
2012 if (sortRole
!= m_model
->sortRole()) {
2013 m_model
->setSortRole(sortRole
);
2014 Q_EMIT
sortRoleChanged(sortRole
);
2017 const Qt::SortOrder sortOrder
= props
.sortOrder();
2018 if (sortOrder
!= m_model
->sortOrder()) {
2019 m_model
->setSortOrder(sortOrder
);
2020 Q_EMIT
sortOrderChanged(sortOrder
);
2023 const bool sortFoldersFirst
= props
.sortFoldersFirst();
2024 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
2025 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
2026 Q_EMIT
sortFoldersFirstChanged(sortFoldersFirst
);
2029 const bool sortHiddenLast
= props
.sortHiddenLast();
2030 if (sortHiddenLast
!= m_model
->sortHiddenLast()) {
2031 m_model
->setSortHiddenLast(sortHiddenLast
);
2032 Q_EMIT
sortHiddenLastChanged(sortHiddenLast
);
2035 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
2036 if (visibleRoles
!= m_visibleRoles
) {
2037 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
2038 m_visibleRoles
= visibleRoles
;
2039 m_view
->setVisibleRoles(visibleRoles
);
2040 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
2043 const bool previewsShown
= props
.previewsShown();
2044 if (previewsShown
!= m_view
->previewsShown()) {
2045 const int oldZoomLevel
= zoomLevel();
2047 m_view
->setPreviewsShown(previewsShown
);
2048 Q_EMIT
previewsShownChanged(previewsShown
);
2050 // Changing the preview-state might result in a changed zoom-level
2051 if (oldZoomLevel
!= zoomLevel()) {
2052 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
2056 KItemListView
* itemListView
= m_container
->controller()->view();
2057 if (itemListView
->isHeaderVisible()) {
2058 KItemListHeader
* header
= itemListView
->header();
2059 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
2060 const int rolesCount
= m_visibleRoles
.count();
2061 if (headerColumnWidths
.count() == rolesCount
) {
2062 header
->setAutomaticColumnResizing(false);
2064 QHash
<QByteArray
, qreal
> columnWidths
;
2065 for (int i
= 0; i
< rolesCount
; ++i
) {
2066 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
2068 header
->setColumnWidths(columnWidths
);
2070 header
->setAutomaticColumnResizing(true);
2072 header
->setSidePadding(DetailsModeSettings::sidePadding());
2075 m_view
->endTransaction();
2078 void DolphinView::applyModeToView()
2081 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
2082 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
2083 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
2084 default: Q_ASSERT(false); break;
2088 void DolphinView::pasteToUrl(const QUrl
& url
)
2090 KIO::PasteJob
*job
= KIO::paste(QApplication::clipboard()->mimeData(), url
);
2091 KJobWidgets::setWindow(job
, this);
2092 m_clearSelectionBeforeSelectingNewItems
= true;
2093 m_markFirstNewlySelectedItemAsCurrent
= true;
2094 connect(job
, &KIO::PasteJob::itemCreated
, this, &DolphinView::slotItemCreated
);
2095 connect(job
, &KIO::PasteJob::result
, this, &DolphinView::slotJobResult
);
2098 QList
<QUrl
> DolphinView::simplifiedSelectedUrls() const
2102 const KFileItemList items
= selectedItems();
2103 urls
.reserve(items
.count());
2104 for (const KFileItem
& item
: items
) {
2105 urls
.append(item
.url());
2108 if (itemsExpandable()) {
2109 // TODO: Check if we still need KDirModel for this in KDE 5.0
2110 urls
= KDirModel::simplifiedUrlList(urls
);
2116 QMimeData
* DolphinView::selectionMimeData() const
2118 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
2119 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
2121 return m_model
->createMimeData(selectedIndexes
);
2124 void DolphinView::updateWritableState()
2126 const bool wasFolderWritable
= m_isFolderWritable
;
2127 m_isFolderWritable
= false;
2129 KFileItem item
= m_model
->rootItem();
2130 if (item
.isNull()) {
2131 // Try to find out if the URL is writable even if the "root item" is
2132 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
2133 item
= KFileItem(url());
2134 item
.setDelayedMimeTypes(true);
2137 KFileItemListProperties
capabilities(KFileItemList() << item
);
2138 m_isFolderWritable
= capabilities
.supportsWriting();
2140 if (m_isFolderWritable
!= wasFolderWritable
) {
2141 Q_EMIT
writeStateChanged(m_isFolderWritable
);
2145 QUrl
DolphinView::viewPropertiesUrl() const
2147 if (m_viewPropertiesContext
.isEmpty()) {
2152 url
.setScheme(m_url
.scheme());
2153 url
.setPath(m_viewPropertiesContext
);
2157 void DolphinView::slotRenameDialogRenamingFinished(const QList
<QUrl
>& urls
)
2159 forceUrlsSelection(urls
.first(), urls
);
2162 void DolphinView::forceUrlsSelection(const QUrl
& current
, const QList
<QUrl
>& selected
)
2165 m_clearSelectionBeforeSelectingNewItems
= true;
2166 markUrlAsCurrent(current
);
2167 markUrlsAsSelected(selected
);
2170 void DolphinView::copyPathToClipboard()
2172 const KFileItemList list
= selectedItems();
2173 if (list
.isEmpty()) {
2176 const KFileItem
& item
= list
.at(0);
2177 QString path
= item
.localPath();
2178 if (path
.isEmpty()) {
2179 path
= item
.url().toDisplayString();
2181 QClipboard
* clipboard
= QApplication::clipboard();
2182 if (clipboard
== nullptr) {
2185 clipboard
->setText(path
);
2188 void DolphinView::slotIncreaseZoom()
2190 setZoomLevel(zoomLevel() + 1);
2193 void DolphinView::slotDecreaseZoom()
2195 setZoomLevel(zoomLevel() - 1);
2198 void DolphinView::slotSwipeUp()
2200 Q_EMIT
goUpRequested();
2203 void DolphinView::showLoadingPlaceholder()
2205 m_placeholderLabel
->setText(i18n("Loading..."));
2206 m_placeholderLabel
->setVisible(true);
2209 void DolphinView::updatePlaceholderLabel()
2211 m_showLoadingPlaceholderTimer
->stop();
2212 if (itemsCount() > 0) {
2213 m_placeholderLabel
->setVisible(false);
2217 if (m_loadingState
== LoadingState::Loading
) {
2218 m_placeholderLabel
->setVisible(false);
2219 m_showLoadingPlaceholderTimer
->start();
2223 if (m_loadingState
== LoadingState::Canceled
) {
2224 m_placeholderLabel
->setText(i18n("Loading canceled"));
2225 } else if (!nameFilter().isEmpty()) {
2226 m_placeholderLabel
->setText(i18n("No items matching the filter"));
2227 } else if (m_url
.scheme() == QLatin1String("baloosearch") || m_url
.scheme() == QLatin1String("filenamesearch")) {
2228 m_placeholderLabel
->setText(i18n("No items matching the search"));
2229 } else if (m_url
.scheme() == QLatin1String("trash") && m_url
.path() == QLatin1String("/")) {
2230 m_placeholderLabel
->setText(i18n("Trash is empty"));
2231 } else if (m_url
.scheme() == QLatin1String("tags")) {
2232 if (m_url
.path() == QLatin1Char('/')) {
2233 m_placeholderLabel
->setText(i18n("No tags"));
2235 const QString tagName
= m_url
.path().mid(1); // Remove leading /
2236 m_placeholderLabel
->setText(i18n("No files tagged with \"%1\"", tagName
));
2239 } else if (m_url
.scheme() == QLatin1String("recentlyused")) {
2240 m_placeholderLabel
->setText(i18n("No recently used items"));
2241 } else if (m_url
.scheme() == QLatin1String("smb")) {
2242 m_placeholderLabel
->setText(i18n("No shared folders found"));
2243 } else if (m_url
.scheme() == QLatin1String("network")) {
2244 m_placeholderLabel
->setText(i18n("No relevant network resources found"));
2245 } else if (m_url
.scheme() == QLatin1String("mtp") && m_url
.path() == QLatin1String("/")) {
2246 m_placeholderLabel
->setText(i18n("No MTP-compatible devices found"));
2247 } else if (m_url
.scheme() == QLatin1String("bluetooth")) {
2248 m_placeholderLabel
->setText(i18n("No Bluetooth devices found"));
2250 m_placeholderLabel
->setText(i18n("Folder is empty"));
2253 m_placeholderLabel
->setVisible(true);
2256 void DolphinView::tryShowNameToolTip(QHelpEvent
* event
)
2258 if (!GeneralSettings::showToolTips() && m_mode
== DolphinView::IconsView
) {
2259 const std::optional
<int> index
= m_view
->itemAt(event
->pos());
2261 if (!index
.has_value()) {
2265 // Check whether the filename has been elided
2266 const bool isElided
= m_view
->isElided(index
.value());
2269 const KFileItem item
= m_model
->fileItem(index
.value());
2270 const QString text
= item
.text();
2271 const QPoint pos
= mapToGlobal(event
->pos());
2272 QToolTip::showText(pos
, text
);