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/PreviewJob>
44 #include <KIO/RenameFileDialog>
45 #include <KJobWidgets>
46 #include <KLocalizedString>
47 #include <KMessageBox>
48 #include <KProtocolManager>
49 #include <KUrlMimeData>
51 #include <QAbstractItemView>
52 #include <QActionGroup>
53 #include <QApplication>
56 #include <QGraphicsOpacityEffect>
57 #include <QGraphicsSceneDragDropEvent>
60 #include <QMimeDatabase>
61 #include <QPixmapCache>
66 #include <QVBoxLayout>
68 DolphinView::DolphinView(const QUrl
& url
, QWidget
* parent
) :
71 m_tabsForFiles(false),
72 m_assureVisibleCurrentIndex(false),
73 m_isFolderWritable(true),
76 m_viewPropertiesContext(),
77 m_mode(DolphinView::IconsView
),
83 m_toolTipManager(nullptr),
84 m_selectionChangedTimer(nullptr),
86 m_scrollToCurrentItem(false),
87 m_restoredContentsPosition(),
89 m_clearSelectionBeforeSelectingNewItems(false),
90 m_markFirstNewlySelectedItemAsCurrent(false),
91 m_versionControlObserver(nullptr),
92 m_twoClicksRenamingTimer(nullptr),
93 m_placeholderLabel(nullptr),
94 m_showLoadingPlaceholderTimer(nullptr)
96 m_topLayout
= new QVBoxLayout(this);
97 m_topLayout
->setSpacing(0);
98 m_topLayout
->setContentsMargins(0, 0, 0, 0);
100 // When a new item has been created by the "Create New..." menu, the item should
101 // get selected and it must be assured that the item will get visible. As the
102 // creation is done asynchronously, several signals must be checked:
103 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated
,
104 this, &DolphinView::observeCreatedItem
);
106 m_selectionChangedTimer
= new QTimer(this);
107 m_selectionChangedTimer
->setSingleShot(true);
108 m_selectionChangedTimer
->setInterval(300);
109 connect(m_selectionChangedTimer
, &QTimer::timeout
,
110 this, &DolphinView::emitSelectionChangedSignal
);
112 m_model
= new KFileItemModel(this);
113 m_view
= new DolphinItemListView();
114 m_view
->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
115 m_view
->setVisibleRoles({"text"});
118 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
119 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
120 controller
->setAutoActivationDelay(delay
);
122 // The EnlargeSmallPreviews setting can only be changed after the model
123 // has been set in the view by KItemListController.
124 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
126 m_container
= new KItemListContainer(controller
, this);
127 m_container
->installEventFilter(this);
128 setFocusProxy(m_container
);
129 connect(m_container
->horizontalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
130 connect(m_container
->verticalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
132 m_showLoadingPlaceholderTimer
= new QTimer(this);
133 m_showLoadingPlaceholderTimer
->setInterval(500);
134 m_showLoadingPlaceholderTimer
->setSingleShot(true);
135 connect(m_showLoadingPlaceholderTimer
, &QTimer::timeout
, this, &DolphinView::showLoadingPlaceholder
);
137 // Show some placeholder text for empty folders
138 // This is made using a heavily-modified QLabel rather than a KTitleWidget
139 // because KTitleWidget can't be told to turn off mouse-selectable text
140 m_placeholderLabel
= new QLabel(this);
141 QFont placeholderLabelFont
;
142 // To match the size of a level 2 Heading/KTitleWidget
143 placeholderLabelFont
.setPointSize(qRound(placeholderLabelFont
.pointSize() * 1.3));
144 m_placeholderLabel
->setFont(placeholderLabelFont
);
145 m_placeholderLabel
->setTextInteractionFlags(Qt::NoTextInteraction
);
146 m_placeholderLabel
->setWordWrap(true);
147 m_placeholderLabel
->setAlignment(Qt::AlignCenter
);
148 // Match opacity of QML placeholder label component
149 auto *effect
= new QGraphicsOpacityEffect(m_placeholderLabel
);
150 effect
->setOpacity(0.5);
151 m_placeholderLabel
->setGraphicsEffect(effect
);
152 // Set initial text and visibility
153 updatePlaceholderLabel();
155 auto *centeringLayout
= new QVBoxLayout(m_container
);
156 centeringLayout
->addWidget(m_placeholderLabel
);
157 centeringLayout
->setAlignment(m_placeholderLabel
, Qt::AlignCenter
);
159 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
160 connect(controller
, &KItemListController::itemActivated
, this, &DolphinView::slotItemActivated
);
161 connect(controller
, &KItemListController::itemsActivated
, this, &DolphinView::slotItemsActivated
);
162 connect(controller
, &KItemListController::itemMiddleClicked
, this, &DolphinView::slotItemMiddleClicked
);
163 connect(controller
, &KItemListController::itemContextMenuRequested
, this, &DolphinView::slotItemContextMenuRequested
);
164 connect(controller
, &KItemListController::viewContextMenuRequested
, this, &DolphinView::slotViewContextMenuRequested
);
165 connect(controller
, &KItemListController::headerContextMenuRequested
, this, &DolphinView::slotHeaderContextMenuRequested
);
166 connect(controller
, &KItemListController::mouseButtonPressed
, this, &DolphinView::slotMouseButtonPressed
);
167 connect(controller
, &KItemListController::itemHovered
, this, &DolphinView::slotItemHovered
);
168 connect(controller
, &KItemListController::itemUnhovered
, this, &DolphinView::slotItemUnhovered
);
169 connect(controller
, &KItemListController::itemDropEvent
, this, &DolphinView::slotItemDropEvent
);
170 connect(controller
, &KItemListController::escapePressed
, this, &DolphinView::stopLoading
);
171 connect(controller
, &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
172 connect(controller
, &KItemListController::selectedItemTextPressed
, this, &DolphinView::slotSelectedItemTextPressed
);
173 connect(controller
, &KItemListController::increaseZoom
, this, &DolphinView::slotIncreaseZoom
);
174 connect(controller
, &KItemListController::decreaseZoom
, this, &DolphinView::slotDecreaseZoom
);
175 connect(controller
, &KItemListController::swipeUp
, this, &DolphinView::slotSwipeUp
);
176 connect(controller
, &KItemListController::selectionModeChangeRequested
, this, &DolphinView::selectionModeChangeRequested
);
178 connect(m_model
, &KFileItemModel::directoryLoadingStarted
, this, &DolphinView::slotDirectoryLoadingStarted
);
179 connect(m_model
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
180 connect(m_model
, &KFileItemModel::directoryLoadingCanceled
, this, &DolphinView::slotDirectoryLoadingCanceled
);
181 connect(m_model
, &KFileItemModel::directoryLoadingProgress
, this, &DolphinView::directoryLoadingProgress
);
182 connect(m_model
, &KFileItemModel::directorySortingProgress
, this, &DolphinView::directorySortingProgress
);
183 connect(m_model
, &KFileItemModel::itemsChanged
,
184 this, &DolphinView::slotItemsChanged
);
185 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &DolphinView::itemCountChanged
);
186 connect(m_model
, &KFileItemModel::itemsInserted
, this, &DolphinView::itemCountChanged
);
187 connect(m_model
, &KFileItemModel::infoMessage
, this, &DolphinView::infoMessage
);
188 connect(m_model
, &KFileItemModel::errorMessage
, this, &DolphinView::errorMessage
);
189 connect(m_model
, &KFileItemModel::directoryRedirection
, this, &DolphinView::slotDirectoryRedirection
);
190 connect(m_model
, &KFileItemModel::urlIsFileError
, this, &DolphinView::urlIsFileError
);
191 connect(m_model
, &KFileItemModel::fileItemsChanged
, this, &DolphinView::fileItemsChanged
);
193 connect(this, &DolphinView::itemCountChanged
,
194 this, &DolphinView::updatePlaceholderLabel
);
196 m_view
->installEventFilter(this);
197 connect(m_view
, &DolphinItemListView::sortOrderChanged
,
198 this, &DolphinView::slotSortOrderChangedByHeader
);
199 connect(m_view
, &DolphinItemListView::sortRoleChanged
,
200 this, &DolphinView::slotSortRoleChangedByHeader
);
201 connect(m_view
, &DolphinItemListView::visibleRolesChanged
,
202 this, &DolphinView::slotVisibleRolesChangedByHeader
);
203 connect(m_view
, &DolphinItemListView::roleEditingCanceled
,
204 this, &DolphinView::slotRoleEditingCanceled
);
205 connect(m_view
->header(), &KItemListHeader::columnWidthChangeFinished
,
206 this, &DolphinView::slotHeaderColumnWidthChangeFinished
);
207 connect(m_view
->header(), &KItemListHeader::sidePaddingChanged
,
208 this, &DolphinView::slotSidePaddingWidthChanged
);
210 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
211 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
,
212 this, &DolphinView::slotSelectionChanged
);
215 m_toolTipManager
= new ToolTipManager(this);
216 connect(m_toolTipManager
, &ToolTipManager::urlActivated
, this, &DolphinView::urlActivated
);
219 m_versionControlObserver
= new VersionControlObserver(this);
220 m_versionControlObserver
->setView(this);
221 m_versionControlObserver
->setModel(m_model
);
222 connect(m_versionControlObserver
, &VersionControlObserver::infoMessage
, this, &DolphinView::infoMessage
);
223 connect(m_versionControlObserver
, &VersionControlObserver::errorMessage
, this, &DolphinView::errorMessage
);
224 connect(m_versionControlObserver
, &VersionControlObserver::operationCompletedMessage
, this, &DolphinView::operationCompletedMessage
);
226 m_twoClicksRenamingTimer
= new QTimer(this);
227 m_twoClicksRenamingTimer
->setSingleShot(true);
228 connect(m_twoClicksRenamingTimer
, &QTimer::timeout
, this, &DolphinView::slotTwoClicksRenamingTimerTimeout
);
230 applyViewProperties();
231 m_topLayout
->addWidget(m_container
);
236 DolphinView::~DolphinView()
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());
293 setStyle(QApplication::style());
294 m_view
->setStyle(QApplication::style());
296 m_container
->controller()->setSelectionModeEnabled(enabled
);
299 bool DolphinView::selectionMode() const
301 return m_container
->controller()->selectionMode();
304 void DolphinView::setPreviewsShown(bool show
)
306 if (previewsShown() == show
) {
310 ViewProperties
props(viewPropertiesUrl());
311 props
.setPreviewsShown(show
);
313 const int oldZoomLevel
= m_view
->zoomLevel();
314 m_view
->setPreviewsShown(show
);
315 Q_EMIT
previewsShownChanged(show
);
317 const int newZoomLevel
= m_view
->zoomLevel();
318 if (newZoomLevel
!= oldZoomLevel
) {
319 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
323 bool DolphinView::previewsShown() const
325 return m_view
->previewsShown();
328 void DolphinView::setHiddenFilesShown(bool show
)
330 if (m_model
->showHiddenFiles() == show
) {
334 const KFileItemList itemList
= selectedItems();
335 m_selectedUrls
.clear();
336 m_selectedUrls
= itemList
.urlList();
338 ViewProperties
props(viewPropertiesUrl());
339 props
.setHiddenFilesShown(show
);
341 m_model
->setShowHiddenFiles(show
);
342 Q_EMIT
hiddenFilesShownChanged(show
);
345 bool DolphinView::hiddenFilesShown() const
347 return m_model
->showHiddenFiles();
350 void DolphinView::setGroupedSorting(bool grouped
)
352 if (grouped
== groupedSorting()) {
356 ViewProperties
props(viewPropertiesUrl());
357 props
.setGroupedSorting(grouped
);
360 m_container
->controller()->model()->setGroupedSorting(grouped
);
362 Q_EMIT
groupedSortingChanged(grouped
);
365 bool DolphinView::groupedSorting() const
367 return m_model
->groupedSorting();
370 KFileItemList
DolphinView::items() const
373 const int itemCount
= m_model
->count();
374 list
.reserve(itemCount
);
376 for (int i
= 0; i
< itemCount
; ++i
) {
377 list
.append(m_model
->fileItem(i
));
383 int DolphinView::itemsCount() const
385 return m_model
->count();
388 KFileItemList
DolphinView::selectedItems() const
390 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
392 KFileItemList selectedItems
;
393 const auto items
= selectionManager
->selectedItems();
394 selectedItems
.reserve(items
.count());
395 for (int index
: items
) {
396 selectedItems
.append(m_model
->fileItem(index
));
398 return selectedItems
;
401 int DolphinView::selectedItemsCount() const
403 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
404 return selectionManager
->selectedItems().count();
407 void DolphinView::markUrlsAsSelected(const QList
<QUrl
>& urls
)
409 m_selectedUrls
= urls
;
412 void DolphinView::markUrlAsCurrent(const QUrl
&url
)
414 m_currentItemUrl
= url
;
415 m_scrollToCurrentItem
= true;
418 void DolphinView::selectItems(const QRegularExpression
®exp
, bool enabled
)
420 const KItemListSelectionManager::SelectionMode mode
= enabled
421 ? KItemListSelectionManager::Select
422 : KItemListSelectionManager::Deselect
;
423 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
425 for (int index
= 0; index
< m_model
->count(); index
++) {
426 const KFileItem item
= m_model
->fileItem(index
);
427 if (regexp
.match(item
.text()).hasMatch()) {
428 // An alternative approach would be to store the matching items in a KItemSet and
429 // select them in one go after the loop, but we'd need a new function
430 // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
432 selectionManager
->setSelected(index
, 1, mode
);
437 void DolphinView::setZoomLevel(int level
)
439 const int oldZoomLevel
= zoomLevel();
440 m_view
->setZoomLevel(level
);
441 if (zoomLevel() != oldZoomLevel
) {
443 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
447 int DolphinView::zoomLevel() const
449 return m_view
->zoomLevel();
452 void DolphinView::setSortRole(const QByteArray
& role
)
454 if (role
!= sortRole()) {
455 updateSortRole(role
);
459 QByteArray
DolphinView::sortRole() const
461 const KItemModelBase
* model
= m_container
->controller()->model();
462 return model
->sortRole();
465 void DolphinView::setSortOrder(Qt::SortOrder order
)
467 if (sortOrder() != order
) {
468 updateSortOrder(order
);
472 Qt::SortOrder
DolphinView::sortOrder() const
474 return m_model
->sortOrder();
477 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
479 if (sortFoldersFirst() != foldersFirst
) {
480 updateSortFoldersFirst(foldersFirst
);
484 bool DolphinView::sortFoldersFirst() const
486 return m_model
->sortDirectoriesFirst();
489 void DolphinView::setSortHiddenLast(bool hiddenLast
)
491 if (sortHiddenLast() != hiddenLast
) {
492 updateSortHiddenLast(hiddenLast
);
496 bool DolphinView::sortHiddenLast() const
498 return m_model
->sortHiddenLast();
501 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
503 const QList
<QByteArray
> previousRoles
= roles
;
505 ViewProperties
props(viewPropertiesUrl());
506 props
.setVisibleRoles(roles
);
508 m_visibleRoles
= roles
;
509 m_view
->setVisibleRoles(roles
);
511 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousRoles
);
514 QList
<QByteArray
> DolphinView::visibleRoles() const
516 return m_visibleRoles
;
519 void DolphinView::reload()
521 QByteArray viewState
;
522 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
523 saveState(saveStream
);
526 loadDirectory(url(), true);
528 QDataStream
restoreStream(viewState
);
529 restoreState(restoreStream
);
532 void DolphinView::readSettings()
534 const int oldZoomLevel
= m_view
->zoomLevel();
536 GeneralSettings::self()->load();
537 m_view
->readSettings();
538 applyViewProperties();
540 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
541 m_container
->controller()->setAutoActivationDelay(delay
);
543 const int newZoomLevel
= m_view
->zoomLevel();
544 if (newZoomLevel
!= oldZoomLevel
) {
545 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
549 void DolphinView::writeSettings()
551 GeneralSettings::self()->save();
552 m_view
->writeSettings();
555 void DolphinView::setNameFilter(const QString
& nameFilter
)
557 m_model
->setNameFilter(nameFilter
);
560 QString
DolphinView::nameFilter() const
562 return m_model
->nameFilter();
565 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
567 return m_model
->setMimeTypeFilters(filters
);
570 QStringList
DolphinView::mimeTypeFilters() const
572 return m_model
->mimeTypeFilters();
575 void DolphinView::requestStatusBarText()
577 if (m_statJobForStatusBarText
) {
578 // Kill the pending request.
579 m_statJobForStatusBarText
->kill();
582 if (m_container
->controller()->selectionManager()->hasSelection()) {
585 KIO::filesize_t totalFileSize
= 0;
587 // Give a summary of the status of the selected files
588 const KFileItemList list
= selectedItems();
589 for (const KFileItem
& item
: list
) {
594 totalFileSize
+= item
.size();
598 if (folderCount
+ fileCount
== 1) {
599 // If only one item is selected, show info about it
600 Q_EMIT
statusBarTextChanged(list
.first().getStatusBarInfo());
602 // At least 2 items are selected
603 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, HasSelection
);
605 } else { // has no selection
606 if (!m_model
->rootItem().url().isValid()) {
610 m_statJobForStatusBarText
= KIO::statDetails(m_model
->rootItem().url(),
611 KIO::StatJob::SourceSide
, KIO::StatRecursiveSize
, KIO::HideProgressInfo
);
612 connect(m_statJobForStatusBarText
, &KJob::result
,
613 this, &DolphinView::slotStatJobResult
);
614 m_statJobForStatusBarText
->start();
618 void DolphinView::emitStatusBarText(const int folderCount
, const int fileCount
,
619 KIO::filesize_t totalFileSize
, const Selection selection
)
625 if (selection
== HasSelection
) {
626 // At least 2 items are selected because the case of 1 selected item is handled in
627 // DolphinView::requestStatusBarText().
628 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
629 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
631 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
632 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
635 if (fileCount
> 0 && folderCount
> 0) {
636 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
637 foldersText
, filesText
,
638 KFormat().formatByteSize(totalFileSize
));
639 } else if (fileCount
> 0) {
640 summary
= i18nc("@info:status files (size)", "%1 (%2)",
642 KFormat().formatByteSize(totalFileSize
));
643 } else if (folderCount
> 0) {
644 summary
= foldersText
;
646 summary
= i18nc("@info:status", "0 Folders, 0 Files");
648 Q_EMIT
statusBarTextChanged(summary
);
651 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
653 QList
<QAction
*> actions
;
655 if (items
.isEmpty()) {
656 const KFileItem item
= m_model
->rootItem();
657 if (!item
.isNull()) {
658 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
661 actions
= m_versionControlObserver
->actions(items
);
667 void DolphinView::setUrl(const QUrl
& url
)
679 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
680 this, &DolphinView::slotRoleEditingFinished
);
682 // It is important to clear the items from the model before
683 // applying the view properties, otherwise expensive operations
684 // might be done on the existing items although they get cleared
685 // anyhow afterwards by loadDirectory().
687 applyViewProperties();
690 Q_EMIT
urlChanged(url
);
693 void DolphinView::selectAll()
695 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
696 selectionManager
->setSelected(0, m_model
->count());
699 void DolphinView::invertSelection()
701 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
702 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
705 void DolphinView::clearSelection()
707 m_selectedUrls
.clear();
708 m_container
->controller()->selectionManager()->clearSelection();
711 void DolphinView::renameSelectedItems()
713 const KFileItemList items
= selectedItems();
714 if (items
.isEmpty()) {
718 if (items
.count() == 1 && GeneralSettings::renameInline()) {
719 const int index
= m_model
->index(items
.first());
721 QMetaObject::Connection
* const connection
= new QMetaObject::Connection
;
722 *connection
= connect(m_view
, &KItemListView::scrollingStopped
, this, [=](){
723 QObject::disconnect(*connection
);
726 m_view
->editRole(index
, "text");
730 connect(m_view
, &DolphinItemListView::roleEditingFinished
,
731 this, &DolphinView::slotRoleEditingFinished
);
733 m_view
->scrollToItem(index
);
736 KIO::RenameFileDialog
* dialog
= new KIO::RenameFileDialog(items
, this);
737 connect(dialog
, &KIO::RenameFileDialog::renamingFinished
,
738 this, &DolphinView::slotRenameDialogRenamingFinished
);
743 // Assure that the current index remains visible when KFileItemModel
744 // will notify the view about changed items (which might result in
745 // a changed sorting).
746 m_assureVisibleCurrentIndex
= true;
749 void DolphinView::trashSelectedItems()
751 const QList
<QUrl
> list
= simplifiedSelectedUrls();
752 KIO::JobUiDelegate uiDelegate
;
753 uiDelegate
.setWindow(window());
754 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Trash
, KIO::JobUiDelegate::DefaultConfirmation
)) {
755 KIO::Job
* job
= KIO::trash(list
);
756 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash
, list
, QUrl(QStringLiteral("trash:/")), job
);
757 KJobWidgets::setWindow(job
, this);
758 connect(job
, &KIO::Job::result
,
759 this, &DolphinView::slotTrashFileFinished
);
763 void DolphinView::deleteSelectedItems()
765 const QList
<QUrl
> list
= simplifiedSelectedUrls();
767 KIO::JobUiDelegate uiDelegate
;
768 uiDelegate
.setWindow(window());
769 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Delete
, KIO::JobUiDelegate::DefaultConfirmation
)) {
770 KIO::Job
* job
= KIO::del(list
);
771 KJobWidgets::setWindow(job
, this);
772 connect(job
, &KIO::Job::result
,
773 this, &DolphinView::slotDeleteFileFinished
);
777 void DolphinView::cutSelectedItemsToClipboard()
779 QMimeData
* mimeData
= selectionMimeData();
780 KIO::setClipboardDataCut(mimeData
, true);
781 KUrlMimeData::exportUrlsToPortal(mimeData
);
782 QApplication::clipboard()->setMimeData(mimeData
);
785 void DolphinView::copySelectedItemsToClipboard()
787 QMimeData
*mimeData
= selectionMimeData();
788 KUrlMimeData::exportUrlsToPortal(mimeData
);
789 QApplication::clipboard()->setMimeData(mimeData
);
792 void DolphinView::copySelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
794 KIO::CopyJob
* job
= KIO::copy(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
795 KJobWidgets::setWindow(job
, this);
797 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
798 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
799 KIO::FileUndoManager::self()->recordCopyJob(job
);
802 void DolphinView::moveSelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
804 KIO::CopyJob
* job
= KIO::move(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
805 KJobWidgets::setWindow(job
, this);
807 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
808 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
809 KIO::FileUndoManager::self()->recordCopyJob(job
);
813 void DolphinView::paste()
818 void DolphinView::pasteIntoFolder()
820 const KFileItemList items
= selectedItems();
821 if ((items
.count() == 1) && items
.first().isDir()) {
822 pasteToUrl(items
.first().url());
826 void DolphinView::duplicateSelectedItems()
828 const KFileItemList itemList
= selectedItems();
829 if (itemList
.isEmpty()) {
833 const QMimeDatabase db
;
835 // Duplicate all selected items and append "copy" to the end of the file name
836 // but before the filename extension, if present
837 QList
<QUrl
> newSelection
;
838 for (const auto &item
: itemList
) {
839 const QUrl originalURL
= item
.url();
840 const QString originalDirectoryPath
= originalURL
.adjusted(QUrl::RemoveFilename
).path();
841 const QString originalFileName
= item
.name();
843 QString extension
= db
.suffixForFileName(originalFileName
);
845 QUrl duplicateURL
= originalURL
;
847 // No extension; new filename is "<oldfilename> copy"
848 if (extension
.isEmpty()) {
849 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFileName
));
850 // There's an extension; new filename is "<oldfilename> copy.<extension>"
852 // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it
853 extension
= QLatin1String(".") + extension
;
854 const QString originalFilenameWithoutExtension
= originalFileName
.chopped(extension
.size());
855 // Preserve file's original filename extension in case the casing differs
856 // from what QMimeDatabase::suffixForFileName() returned
857 const QString originalExtension
= originalFileName
.right(extension
.size());
858 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension
) + originalExtension
);
861 KIO::CopyJob
* job
= KIO::copyAs(originalURL
, duplicateURL
);
862 KJobWidgets::setWindow(job
, this);
865 newSelection
<< duplicateURL
;
866 KIO::FileUndoManager::self()->recordCopyJob(job
);
870 forceUrlsSelection(newSelection
.first(), newSelection
);
873 void DolphinView::stopLoading()
875 m_model
->cancelDirectoryLoading();
878 void DolphinView::updatePalette()
880 QColor color
= KColorScheme(isActiveWindow() ? QPalette::Active
: QPalette::Inactive
, KColorScheme::View
).background().color();
885 QWidget
* viewport
= m_container
->viewport();
888 palette
.setColor(viewport
->backgroundRole(), color
);
889 viewport
->setPalette(palette
);
895 void DolphinView::abortTwoClicksRenaming()
897 m_twoClicksRenamingItemUrl
.clear();
898 m_twoClicksRenamingTimer
->stop();
901 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
903 switch (event
->type()) {
904 case QEvent::PaletteChange
:
906 QPixmapCache::clear();
909 case QEvent::WindowActivate
:
910 case QEvent::WindowDeactivate
:
914 case QEvent::KeyPress
:
915 hideToolTip(ToolTipManager::HideBehavior::Instantly
);
916 if (GeneralSettings::useTabForSwitchingSplitView()) {
917 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
918 if (keyEvent
->key() == Qt::Key_Tab
&& keyEvent
->modifiers() == Qt::NoModifier
) {
919 Q_EMIT
toggleActiveViewRequested();
924 case QEvent::FocusIn
:
925 if (watched
== m_container
) {
930 case QEvent::GraphicsSceneDragEnter
:
931 if (watched
== m_view
) {
933 abortTwoClicksRenaming();
937 case QEvent::GraphicsSceneDragLeave
:
938 if (watched
== m_view
) {
943 case QEvent::GraphicsSceneDrop
:
944 if (watched
== m_view
) {
949 case QEvent::ToolTip
:
950 tryShowNameToolTip(static_cast<QHelpEvent
*>(event
));
956 return QWidget::eventFilter(watched
, event
);
959 void DolphinView::wheelEvent(QWheelEvent
* event
)
961 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
962 const QPoint numDegrees
= event
->angleDelta() / 8;
963 const QPoint numSteps
= numDegrees
/ 15;
965 setZoomLevel(zoomLevel() + numSteps
.y());
972 void DolphinView::hideEvent(QHideEvent
* event
)
975 QWidget::hideEvent(event
);
978 bool DolphinView::event(QEvent
* event
)
980 if (event
->type() == QEvent::WindowDeactivate
) {
982 * Dolphin leaves file preview tooltips open even when is not visible.
984 * Hide tool-tip when Dolphin loses focus.
987 abortTwoClicksRenaming();
990 return QWidget::event(event
);
993 void DolphinView::activate()
998 void DolphinView::slotItemActivated(int index
)
1000 abortTwoClicksRenaming();
1002 const KFileItem item
= m_model
->fileItem(index
);
1003 if (!item
.isNull()) {
1004 Q_EMIT
itemActivated(item
);
1008 void DolphinView::slotItemsActivated(const KItemSet
&indexes
)
1010 Q_ASSERT(indexes
.count() >= 2);
1012 abortTwoClicksRenaming();
1014 const auto modifiers
= QGuiApplication::keyboardModifiers();
1016 if (indexes
.count() > 5) {
1017 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
1018 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1019 KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes
.count()),
1020 QStringLiteral("document-open")),
1021 KStandardGuiItem::cancel());
1022 if (answer
!= KMessageBox::Yes
) {
1027 KFileItemList items
;
1028 items
.reserve(indexes
.count());
1030 for (int index
: indexes
) {
1031 KFileItem item
= m_model
->fileItem(index
);
1032 const QUrl
& url
= openItemAsFolderUrl(item
);
1034 if (!url
.isEmpty()) {
1035 // Open folders in new tabs or in new windows depending on the modifier
1036 // The ctrl+shift behavior is ignored because we are handling multiple items
1037 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1038 if (modifiers
& Qt::ShiftModifier
&& !(modifiers
& Qt::ControlModifier
)) {
1039 Q_EMIT
windowRequested(url
);
1041 Q_EMIT
tabRequested(url
);
1048 if (items
.count() == 1) {
1049 Q_EMIT
itemActivated(items
.first());
1050 } else if (items
.count() > 1) {
1051 Q_EMIT
itemsActivated(items
);
1055 void DolphinView::slotItemMiddleClicked(int index
)
1057 const KFileItem
& item
= m_model
->fileItem(index
);
1058 const QUrl
& url
= openItemAsFolderUrl(item
);
1059 const auto modifiers
= QGuiApplication::keyboardModifiers();
1060 if (!url
.isEmpty()) {
1061 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1062 if (modifiers
& Qt::ShiftModifier
) {
1063 Q_EMIT
activeTabRequested(url
);
1065 Q_EMIT
tabRequested(url
);
1067 } else if (isTabsForFilesEnabled()) {
1068 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1069 if (modifiers
& Qt::ShiftModifier
) {
1070 Q_EMIT
activeTabRequested(item
.url());
1072 Q_EMIT
tabRequested(item
.url());
1077 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
1079 // Force emit of a selection changed signal before we request the
1080 // context menu, to update the edit-actions first. (See Bug 294013)
1081 if (m_selectionChangedTimer
->isActive()) {
1082 emitSelectionChangedSignal();
1085 const KFileItem item
= m_model
->fileItem(index
);
1086 Q_EMIT
requestContextMenu(pos
.toPoint(), item
, selectedItems(), url());
1089 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
1091 Q_EMIT
requestContextMenu(pos
.toPoint(), KFileItem(), selectedItems(), url());
1094 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
1096 ViewProperties
props(viewPropertiesUrl());
1098 QPointer
<QMenu
> menu
= new QMenu(QApplication::activeWindow());
1100 KItemListView
* view
= m_container
->controller()->view();
1101 const QList
<QByteArray
> visibleRolesSet
= view
->visibleRoles();
1103 bool indexingEnabled
= false;
1105 Baloo::IndexerConfig config
;
1106 indexingEnabled
= config
.fileIndexingEnabled();
1110 QMenu
* groupMenu
= nullptr;
1112 // Add all roles to the menu that can be shown or hidden by the user
1113 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
1114 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
1115 if (info
.role
== "text") {
1116 // It should not be possible to hide the "text" role
1120 const QString text
= m_model
->roleDescription(info
.role
);
1121 QAction
* action
= nullptr;
1122 if (info
.group
.isEmpty()) {
1123 action
= menu
->addAction(text
);
1125 if (!groupMenu
|| info
.group
!= groupName
) {
1126 groupName
= info
.group
;
1127 groupMenu
= menu
->addMenu(groupName
);
1130 action
= groupMenu
->addAction(text
);
1133 action
->setCheckable(true);
1134 action
->setChecked(visibleRolesSet
.contains(info
.role
));
1135 action
->setData(info
.role
);
1137 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
1138 (info
.requiresBaloo
) ||
1139 (info
.requiresIndexer
&& indexingEnabled
);
1140 action
->setEnabled(enable
);
1143 menu
->addSeparator();
1145 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
1146 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
1148 QAction
* toggleSidePaddingAction
= menu
->addAction(i18nc("@action:inmenu", "Side Padding"));
1149 toggleSidePaddingAction
->setCheckable(true);
1150 toggleSidePaddingAction
->setChecked(view
->header()->sidePadding() > 0);
1152 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
1153 autoAdjustWidthsAction
->setCheckable(true);
1154 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
1155 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
1157 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
1158 customWidthsAction
->setCheckable(true);
1159 customWidthsAction
->setChecked(!autoColumnWidths
);
1160 customWidthsAction
->setActionGroup(widthsGroup
);
1162 QAction
* action
= menu
->exec(pos
.toPoint());
1163 if (menu
&& action
) {
1164 KItemListHeader
* header
= view
->header();
1166 if (action
== autoAdjustWidthsAction
) {
1167 // Clear the column-widths from the viewproperties and turn on
1168 // the automatic resizing of the columns
1169 props
.setHeaderColumnWidths(QList
<int>());
1170 header
->setAutomaticColumnResizing(true);
1171 } else if (action
== customWidthsAction
) {
1172 // Apply the current column-widths as custom column-widths and turn
1173 // off the automatic resizing of the columns
1174 QList
<int> columnWidths
;
1175 const auto visibleRoles
= view
->visibleRoles();
1176 columnWidths
.reserve(visibleRoles
.count());
1177 for (const QByteArray
& role
: visibleRoles
) {
1178 columnWidths
.append(header
->columnWidth(role
));
1180 props
.setHeaderColumnWidths(columnWidths
);
1181 header
->setAutomaticColumnResizing(false);
1182 } else if (action
== toggleSidePaddingAction
) {
1183 header
->setSidePadding(toggleSidePaddingAction
->isChecked() ? 20 : 0);
1185 // Show or hide the selected role
1186 const QByteArray selectedRole
= action
->data().toByteArray();
1188 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
1189 if (action
->isChecked()) {
1190 visibleRoles
.append(selectedRole
);
1192 visibleRoles
.removeOne(selectedRole
);
1195 view
->setVisibleRoles(visibleRoles
);
1196 props
.setVisibleRoles(visibleRoles
);
1198 QList
<int> columnWidths
;
1199 if (!header
->automaticColumnResizing()) {
1200 const auto visibleRoles
= view
->visibleRoles();
1201 columnWidths
.reserve(visibleRoles
.count());
1202 for (const QByteArray
& role
: visibleRoles
) {
1203 columnWidths
.append(header
->columnWidth(role
));
1206 props
.setHeaderColumnWidths(columnWidths
);
1213 void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray
& role
, qreal current
)
1215 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
1217 ViewProperties
props(viewPropertiesUrl());
1218 QList
<int> columnWidths
= props
.headerColumnWidths();
1219 if (columnWidths
.count() != visibleRoles
.count()) {
1220 columnWidths
.clear();
1221 columnWidths
.reserve(visibleRoles
.count());
1222 const KItemListHeader
* header
= m_view
->header();
1223 for (const QByteArray
& role
: visibleRoles
) {
1224 const int width
= header
->columnWidth(role
);
1225 columnWidths
.append(width
);
1229 const int roleIndex
= visibleRoles
.indexOf(role
);
1230 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
1231 columnWidths
[roleIndex
] = current
;
1233 props
.setHeaderColumnWidths(columnWidths
);
1236 void DolphinView::slotSidePaddingWidthChanged(qreal width
)
1238 ViewProperties
props(viewPropertiesUrl());
1239 DetailsModeSettings::setSidePadding(int(width
));
1240 m_view
->writeSettings();
1243 void DolphinView::slotItemHovered(int index
)
1245 const KFileItem item
= m_model
->fileItem(index
);
1247 if (GeneralSettings::showToolTips() && !m_dragging
) {
1248 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1249 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1250 itemRect
.moveTo(pos
);
1253 auto nativeParent
= nativeParentWidget();
1255 m_toolTipManager
->showToolTip(item
, itemRect
, nativeParent
->windowHandle());
1260 Q_EMIT
requestItemInfo(item
);
1263 void DolphinView::slotItemUnhovered(int index
)
1267 Q_EMIT
requestItemInfo(KFileItem());
1270 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1273 KFileItem destItem
= m_model
->fileItem(index
);
1274 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1275 // Use the URL of the view as drop target if the item is no directory
1277 destItem
= m_model
->rootItem();
1280 // The item represents a directory or desktop-file
1281 destUrl
= destItem
.mostLocalUrl();
1284 QDropEvent
dropEvent(event
->pos().toPoint(),
1285 event
->possibleActions(),
1288 event
->modifiers());
1289 dropUrls(destUrl
, &dropEvent
, this);
1294 void DolphinView::dropUrls(const QUrl
&destUrl
, QDropEvent
*dropEvent
, QWidget
*dropWidget
)
1296 KIO::DropJob
* job
= DragAndDropHelper::dropUrls(destUrl
, dropEvent
, dropWidget
);
1299 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
1301 if (destUrl
== url()) {
1302 // Mark the dropped urls as selected.
1303 m_clearSelectionBeforeSelectingNewItems
= true;
1304 m_markFirstNewlySelectedItemAsCurrent
= true;
1305 connect(job
, &KIO::DropJob::itemCreated
, this, &DolphinView::slotItemCreated
);
1310 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1312 if (previous
!= nullptr) {
1313 Q_ASSERT(qobject_cast
<KFileItemModel
*>(previous
));
1314 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(previous
);
1315 disconnect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1316 m_versionControlObserver
->setModel(nullptr);
1320 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1321 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1322 connect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1323 m_versionControlObserver
->setModel(fileItemModel
);
1327 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1333 if (buttons
& Qt::BackButton
) {
1334 Q_EMIT
goBackRequested();
1335 } else if (buttons
& Qt::ForwardButton
) {
1336 Q_EMIT
goForwardRequested();
1340 void DolphinView::slotSelectedItemTextPressed(int index
)
1342 if (GeneralSettings::renameInline() && !m_view
->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick
)) {
1343 const KFileItem item
= m_model
->fileItem(index
);
1344 const KFileItemListProperties
capabilities(KFileItemList() << item
);
1345 if (capabilities
.supportsMoving()) {
1346 m_twoClicksRenamingItemUrl
= item
.url();
1347 m_twoClicksRenamingTimer
->start(QApplication::doubleClickInterval());
1352 void DolphinView::slotCopyingDone(KIO::Job
*, const QUrl
&, const QUrl
&to
)
1354 slotItemCreated(to
);
1357 void DolphinView::slotItemCreated(const QUrl
& url
)
1359 if (m_markFirstNewlySelectedItemAsCurrent
) {
1360 markUrlAsCurrent(url
);
1361 m_markFirstNewlySelectedItemAsCurrent
= false;
1363 m_selectedUrls
<< url
;
1366 void DolphinView::slotJobResult(KJob
*job
)
1369 Q_EMIT
errorMessage(job
->errorString());
1371 if (!m_selectedUrls
.isEmpty()) {
1372 m_selectedUrls
= KDirModel::simplifiedUrlList(m_selectedUrls
);
1376 void DolphinView::slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
)
1378 const int currentCount
= current
.count();
1379 const int previousCount
= previous
.count();
1380 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1381 (currentCount
> 0 && previousCount
== 0);
1383 // If nothing has been selected before and something got selected (or if something
1384 // was selected before and now nothing is selected) the selectionChangedSignal must
1385 // be emitted asynchronously as fast as possible to update the edit-actions.
1386 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1387 m_selectionChangedTimer
->start();
1390 void DolphinView::emitSelectionChangedSignal()
1392 m_selectionChangedTimer
->stop();
1393 Q_EMIT
selectionChanged(selectedItems());
1396 void DolphinView::slotStatJobResult(KJob
*job
)
1398 int folderCount
= 0;
1400 KIO::filesize_t totalFileSize
= 0;
1401 bool countFileSize
= true;
1403 const auto entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1404 if (entry
.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE
)) {
1405 // We have a precomputed value.
1406 totalFileSize
= static_cast<KIO::filesize_t
>(
1407 entry
.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE
));
1408 countFileSize
= false;
1411 const int itemCount
= m_model
->count();
1412 for (int i
= 0; i
< itemCount
; ++i
) {
1413 const KFileItem item
= m_model
->fileItem(i
);
1418 if (countFileSize
) {
1419 totalFileSize
+= item
.size();
1423 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, NoSelection
);
1426 void DolphinView::updateSortRole(const QByteArray
& role
)
1428 ViewProperties
props(viewPropertiesUrl());
1429 props
.setSortRole(role
);
1431 KItemModelBase
* model
= m_container
->controller()->model();
1432 model
->setSortRole(role
);
1434 Q_EMIT
sortRoleChanged(role
);
1437 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1439 ViewProperties
props(viewPropertiesUrl());
1440 props
.setSortOrder(order
);
1442 m_model
->setSortOrder(order
);
1444 Q_EMIT
sortOrderChanged(order
);
1447 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1449 ViewProperties
props(viewPropertiesUrl());
1450 props
.setSortFoldersFirst(foldersFirst
);
1452 m_model
->setSortDirectoriesFirst(foldersFirst
);
1454 Q_EMIT
sortFoldersFirstChanged(foldersFirst
);
1457 void DolphinView::updateSortHiddenLast(bool hiddenLast
)
1459 ViewProperties
props(viewPropertiesUrl());
1460 props
.setSortHiddenLast(hiddenLast
);
1462 m_model
->setSortHiddenLast(hiddenLast
);
1464 Q_EMIT
sortHiddenLastChanged(hiddenLast
);
1468 QPair
<bool, QString
> DolphinView::pasteInfo() const
1470 const QMimeData
*mimeData
= QApplication::clipboard()->mimeData();
1471 QPair
<bool, QString
> info
;
1472 info
.second
= KIO::pasteActionText(mimeData
, &info
.first
, rootItem());
1476 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1478 m_tabsForFiles
= tabsForFiles
;
1481 bool DolphinView::isTabsForFilesEnabled() const
1483 return m_tabsForFiles
;
1486 bool DolphinView::itemsExpandable() const
1488 return m_mode
== DetailsView
;
1491 void DolphinView::restoreState(QDataStream
& stream
)
1493 // Read the version number of the view state and check if the version is supported.
1494 quint32 version
= 0;
1497 // The version of the view state isn't supported, we can't restore it.
1501 // Restore the current item that had the keyboard focus
1502 stream
>> m_currentItemUrl
;
1504 // Restore the previously selected items
1505 stream
>> m_selectedUrls
;
1507 // Restore the view position
1508 stream
>> m_restoredContentsPosition
;
1510 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1513 m_model
->restoreExpandedDirectories(urls
);
1516 void DolphinView::saveState(QDataStream
& stream
)
1518 stream
<< quint32(1); // View state version
1520 // Save the current item that has the keyboard focus
1521 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1522 if (currentIndex
!= -1) {
1523 KFileItem item
= m_model
->fileItem(currentIndex
);
1524 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1525 QUrl currentItemUrl
= item
.url();
1526 stream
<< currentItemUrl
;
1531 // Save the selected urls
1532 stream
<< selectedItems().urlList();
1534 // Save view position
1535 const qreal x
= m_container
->horizontalScrollBar()->value();
1536 const qreal y
= m_container
->verticalScrollBar()->value();
1537 stream
<< QPoint(x
, y
);
1539 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1540 stream
<< m_model
->expandedDirectories();
1543 KFileItem
DolphinView::rootItem() const
1545 return m_model
->rootItem();
1548 void DolphinView::setViewPropertiesContext(const QString
& context
)
1550 m_viewPropertiesContext
= context
;
1553 QString
DolphinView::viewPropertiesContext() const
1555 return m_viewPropertiesContext
;
1558 QUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1560 if (item
.isNull()) {
1564 QUrl url
= item
.targetUrl();
1570 if (item
.isMimeTypeKnown()) {
1571 const QString
& mimetype
= item
.mimetype();
1573 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1574 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1575 // zip:/<path>/ when clicking on a zip file, etc.
1576 // The .protocol file specifies the mimetype that the kioslave handles.
1577 // Note that we don't use mimetype inheritance since we don't want to
1578 // open OpenDocument files as zip folders...
1579 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1580 if (!protocol
.isEmpty()) {
1581 url
.setScheme(protocol
);
1586 if (mimetype
== QLatin1String("application/x-desktop")) {
1587 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1588 KDesktopFile
desktopFile(url
.toLocalFile());
1589 if (desktopFile
.hasLinkType()) {
1590 const QString linkUrl
= desktopFile
.readUrl();
1591 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1592 return QUrl::fromUserInput(linkUrl
);
1601 void DolphinView::resetZoomLevel()
1603 ViewModeSettings settings
{m_mode
};
1604 settings
.useDefaults(true);
1605 const int defaultIconSize
= settings
.iconSize();
1606 settings
.useDefaults(false);
1608 setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(QSize(defaultIconSize
, defaultIconSize
)));
1611 void DolphinView::observeCreatedItem(const QUrl
& url
)
1614 forceUrlsSelection(url
, {url
});
1618 void DolphinView::slotDirectoryRedirection(const QUrl
& oldUrl
, const QUrl
& newUrl
)
1620 if (oldUrl
.matches(url(), QUrl::StripTrailingSlash
)) {
1621 Q_EMIT
redirection(oldUrl
, newUrl
);
1622 m_url
= newUrl
; // #186947
1626 void DolphinView::updateViewState()
1628 if (m_currentItemUrl
!= QUrl()) {
1629 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1631 // if there is a selection already, leave it that way
1632 if (!selectionManager
->hasSelection()) {
1633 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1634 if (currentIndex
!= -1) {
1635 selectionManager
->setCurrentItem(currentIndex
);
1637 // scroll to current item and reset the state
1638 if (m_scrollToCurrentItem
) {
1639 m_view
->scrollToItem(currentIndex
);
1640 m_scrollToCurrentItem
= false;
1642 m_currentItemUrl
= QUrl();
1644 selectionManager
->setCurrentItem(0);
1647 m_currentItemUrl
= QUrl();
1651 if (!m_restoredContentsPosition
.isNull()) {
1652 const int x
= m_restoredContentsPosition
.x();
1653 const int y
= m_restoredContentsPosition
.y();
1654 m_restoredContentsPosition
= QPoint();
1656 m_container
->horizontalScrollBar()->setValue(x
);
1657 m_container
->verticalScrollBar()->setValue(y
);
1660 if (!m_selectedUrls
.isEmpty()) {
1661 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1663 // if there is a selection already, leave it that way
1664 if (!selectionManager
->hasSelection()) {
1665 if (m_clearSelectionBeforeSelectingNewItems
) {
1666 selectionManager
->clearSelection();
1667 m_clearSelectionBeforeSelectingNewItems
= false;
1670 KItemSet selectedItems
= selectionManager
->selectedItems();
1672 QList
<QUrl
>::iterator it
= m_selectedUrls
.begin();
1673 while (it
!= m_selectedUrls
.end()) {
1674 const int index
= m_model
->index(*it
);
1676 selectedItems
.insert(index
);
1677 it
= m_selectedUrls
.erase(it
);
1683 if (!selectedItems
.isEmpty()) {
1684 selectionManager
->beginAnchoredSelection(selectionManager
->currentItem());
1685 selectionManager
->setSelectedItems(selectedItems
);
1691 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior
)
1693 if (GeneralSettings::showToolTips()) {
1695 m_toolTipManager
->hideToolTip(behavior
);
1699 } else if (m_mode
== DolphinView::IconsView
) {
1700 QToolTip::hideText();
1704 void DolphinView::slotTwoClicksRenamingTimerTimeout()
1706 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1708 // verify that only one item is selected
1709 if (selectionManager
->selectedItems().count() == 1) {
1710 const int index
= selectionManager
->currentItem();
1711 const QUrl fileItemUrl
= m_model
->fileItem(index
).url();
1713 // check if the selected item was the same item that started the twoClicksRenaming
1714 if (fileItemUrl
.isValid() && m_twoClicksRenamingItemUrl
== fileItemUrl
) {
1715 renameSelectedItems();
1720 void DolphinView::slotTrashFileFinished(KJob
* job
)
1722 if (job
->error() == 0) {
1723 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
1724 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1725 Q_EMIT
errorMessage(job
->errorString());
1729 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1731 if (job
->error() == 0) {
1732 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1733 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1734 Q_EMIT
errorMessage(job
->errorString());
1738 void DolphinView::slotRenamingResult(KJob
* job
)
1741 KIO::CopyJob
*copyJob
= qobject_cast
<KIO::CopyJob
*>(job
);
1743 const QUrl newUrl
= copyJob
->destUrl();
1744 const int index
= m_model
->index(newUrl
);
1746 QHash
<QByteArray
, QVariant
> data
;
1747 const QUrl oldUrl
= copyJob
->srcUrls().at(0);
1748 data
.insert("text", oldUrl
.fileName());
1749 m_model
->setData(index
, data
);
1754 void DolphinView::slotDirectoryLoadingStarted()
1756 m_loadingState
= LoadingState::Loading
;
1757 updatePlaceholderLabel();
1759 // Disable the writestate temporary until it can be determined in a fast way
1760 // in DolphinView::slotDirectoryLoadingCompleted()
1761 if (m_isFolderWritable
) {
1762 m_isFolderWritable
= false;
1763 Q_EMIT
writeStateChanged(m_isFolderWritable
);
1766 Q_EMIT
directoryLoadingStarted();
1769 void DolphinView::slotDirectoryLoadingCompleted()
1771 m_loadingState
= LoadingState::Completed
;
1773 // Update the view-state. This has to be done asynchronously
1774 // because the view might not be in its final state yet.
1775 QTimer::singleShot(0, this, &DolphinView::updateViewState
);
1777 // Update the placeholder label in case we found that the folder was empty
1780 Q_EMIT
directoryLoadingCompleted();
1782 updatePlaceholderLabel();
1783 updateWritableState();
1786 void DolphinView::slotDirectoryLoadingCanceled()
1788 m_loadingState
= LoadingState::Canceled
;
1790 updatePlaceholderLabel();
1792 Q_EMIT
directoryLoadingCanceled();
1795 void DolphinView::slotItemsChanged()
1797 m_assureVisibleCurrentIndex
= false;
1800 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1803 Q_ASSERT(m_model
->sortOrder() == current
);
1805 ViewProperties
props(viewPropertiesUrl());
1806 props
.setSortOrder(current
);
1808 Q_EMIT
sortOrderChanged(current
);
1811 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1814 Q_ASSERT(m_model
->sortRole() == current
);
1816 ViewProperties
props(viewPropertiesUrl());
1817 props
.setSortRole(current
);
1819 Q_EMIT
sortRoleChanged(current
);
1822 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1823 const QList
<QByteArray
>& previous
)
1826 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1828 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1830 m_visibleRoles
= current
;
1832 ViewProperties
props(viewPropertiesUrl());
1833 props
.setVisibleRoles(m_visibleRoles
);
1835 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1838 void DolphinView::slotRoleEditingCanceled()
1840 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1841 this, &DolphinView::slotRoleEditingFinished
);
1844 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1846 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1847 this, &DolphinView::slotRoleEditingFinished
);
1849 const KFileItemList items
= selectedItems();
1850 if (items
.count() != 1) {
1854 if (role
== "text") {
1855 const KFileItem oldItem
= items
.first();
1856 const EditResult retVal
= value
.value
<EditResult
>();
1857 const QString newName
= retVal
.newName
;
1858 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1Char('.') && newName
!= QLatin1String("..")) {
1859 const QUrl oldUrl
= oldItem
.url();
1861 QUrl newUrl
= oldUrl
.adjusted(QUrl::RemoveFilename
);
1862 newUrl
.setPath(newUrl
.path() + KIO::encodeFileName(newName
));
1865 //Confirm hiding file/directory by renaming inline
1866 if (!hiddenFilesShown() && newName
.startsWith(QLatin1Char('.')) && !oldItem
.name().startsWith(QLatin1Char('.'))) {
1867 KGuiItem
yesGuiItem(KStandardGuiItem::yes());
1868 yesGuiItem
.setText(i18nc("@action:button", "Rename and Hide"));
1870 const auto code
= KMessageBox::questionYesNo(this,
1871 oldItem
.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
1872 "Do you still want to rename it?")
1873 : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
1874 "Do you still want to rename it?"),
1875 oldItem
.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"),
1877 KStandardGuiItem::cancel(),
1878 QStringLiteral("ConfirmHide")
1881 if (code
== KMessageBox::No
) {
1887 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1888 if (!newNameExistsAlready
&& m_model
->index(oldUrl
) == index
) {
1889 // Only change the data in the model if no item with the new name
1890 // is in the model yet. If there is an item with the new name
1891 // already, calling KIO::CopyJob will open a dialog
1892 // asking for a new name, and KFileItemModel will update the
1893 // data when the dir lister signals that the file name has changed.
1894 QHash
<QByteArray
, QVariant
> data
;
1895 data
.insert(role
, retVal
.newName
);
1896 m_model
->setData(index
, data
);
1899 KIO::Job
* job
= KIO::moveAs(oldUrl
, newUrl
);
1900 KJobWidgets::setWindow(job
, this);
1901 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename
, {oldUrl
}, newUrl
, job
);
1902 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
1904 forceUrlsSelection(newUrl
, {newUrl
});
1906 if (!newNameExistsAlready
) {
1907 // Only connect the result signal if there is no item with the new name
1908 // in the model yet, see bug 328262.
1909 connect(job
, &KJob::result
, this, &DolphinView::slotRenamingResult
);
1912 if (retVal
.direction
!= EditDone
) {
1913 const short indexShift
= retVal
.direction
== EditNext
? 1 : -1;
1914 m_container
->controller()->selectionManager()->setSelected(index
, 1, KItemListSelectionManager::Deselect
);
1915 m_container
->controller()->selectionManager()->setSelected(index
+ indexShift
, 1,
1916 KItemListSelectionManager::Select
);
1917 renameSelectedItems();
1922 void DolphinView::loadDirectory(const QUrl
& url
, bool reload
)
1924 if (!url
.isValid()) {
1925 const QString
location(url
.toDisplayString(QUrl::PreferLocalFile
));
1926 if (location
.isEmpty()) {
1927 Q_EMIT
errorMessage(i18nc("@info:status", "The location is empty."));
1929 Q_EMIT
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1935 m_model
->refreshDirectory(url
);
1937 m_model
->loadDirectory(url
);
1941 void DolphinView::applyViewProperties()
1943 const ViewProperties
props(viewPropertiesUrl());
1944 applyViewProperties(props
);
1947 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1949 m_view
->beginTransaction();
1951 const Mode mode
= props
.viewMode();
1952 if (m_mode
!= mode
) {
1953 const Mode previousMode
= m_mode
;
1956 // Changing the mode might result in changing
1957 // the zoom level. Remember the old zoom level so
1958 // that zoomLevelChanged() can get emitted.
1959 const int oldZoomLevel
= m_view
->zoomLevel();
1962 Q_EMIT
modeChanged(m_mode
, previousMode
);
1964 if (m_view
->zoomLevel() != oldZoomLevel
) {
1965 Q_EMIT
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1969 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1970 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1971 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1972 Q_EMIT
hiddenFilesShownChanged(hiddenFilesShown
);
1975 const bool groupedSorting
= props
.groupedSorting();
1976 if (groupedSorting
!= m_model
->groupedSorting()) {
1977 m_model
->setGroupedSorting(groupedSorting
);
1978 Q_EMIT
groupedSortingChanged(groupedSorting
);
1981 const QByteArray sortRole
= props
.sortRole();
1982 if (sortRole
!= m_model
->sortRole()) {
1983 m_model
->setSortRole(sortRole
);
1984 Q_EMIT
sortRoleChanged(sortRole
);
1987 const Qt::SortOrder sortOrder
= props
.sortOrder();
1988 if (sortOrder
!= m_model
->sortOrder()) {
1989 m_model
->setSortOrder(sortOrder
);
1990 Q_EMIT
sortOrderChanged(sortOrder
);
1993 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1994 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1995 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1996 Q_EMIT
sortFoldersFirstChanged(sortFoldersFirst
);
1999 const bool sortHiddenLast
= props
.sortHiddenLast();
2000 if (sortHiddenLast
!= m_model
->sortHiddenLast()) {
2001 m_model
->setSortHiddenLast(sortHiddenLast
);
2002 Q_EMIT
sortHiddenLastChanged(sortHiddenLast
);
2005 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
2006 if (visibleRoles
!= m_visibleRoles
) {
2007 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
2008 m_visibleRoles
= visibleRoles
;
2009 m_view
->setVisibleRoles(visibleRoles
);
2010 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
2013 const bool previewsShown
= props
.previewsShown();
2014 if (previewsShown
!= m_view
->previewsShown()) {
2015 const int oldZoomLevel
= zoomLevel();
2017 m_view
->setPreviewsShown(previewsShown
);
2018 Q_EMIT
previewsShownChanged(previewsShown
);
2020 // Changing the preview-state might result in a changed zoom-level
2021 if (oldZoomLevel
!= zoomLevel()) {
2022 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
2026 KItemListView
* itemListView
= m_container
->controller()->view();
2027 if (itemListView
->isHeaderVisible()) {
2028 KItemListHeader
* header
= itemListView
->header();
2029 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
2030 const int rolesCount
= m_visibleRoles
.count();
2031 if (headerColumnWidths
.count() == rolesCount
) {
2032 header
->setAutomaticColumnResizing(false);
2034 QHash
<QByteArray
, qreal
> columnWidths
;
2035 for (int i
= 0; i
< rolesCount
; ++i
) {
2036 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
2038 header
->setColumnWidths(columnWidths
);
2040 header
->setAutomaticColumnResizing(true);
2042 header
->setSidePadding(DetailsModeSettings::sidePadding());
2045 m_view
->endTransaction();
2048 void DolphinView::applyModeToView()
2051 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
2052 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
2053 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
2054 default: Q_ASSERT(false); break;
2058 void DolphinView::pasteToUrl(const QUrl
& url
)
2060 KIO::PasteJob
*job
= KIO::paste(QApplication::clipboard()->mimeData(), url
);
2061 KJobWidgets::setWindow(job
, this);
2062 m_clearSelectionBeforeSelectingNewItems
= true;
2063 m_markFirstNewlySelectedItemAsCurrent
= true;
2064 connect(job
, &KIO::PasteJob::itemCreated
, this, &DolphinView::slotItemCreated
);
2065 connect(job
, &KIO::PasteJob::result
, this, &DolphinView::slotJobResult
);
2068 QList
<QUrl
> DolphinView::simplifiedSelectedUrls() const
2072 const KFileItemList items
= selectedItems();
2073 urls
.reserve(items
.count());
2074 for (const KFileItem
& item
: items
) {
2075 urls
.append(item
.url());
2078 if (itemsExpandable()) {
2079 // TODO: Check if we still need KDirModel for this in KDE 5.0
2080 urls
= KDirModel::simplifiedUrlList(urls
);
2086 QMimeData
* DolphinView::selectionMimeData() const
2088 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
2089 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
2091 return m_model
->createMimeData(selectedIndexes
);
2094 void DolphinView::updateWritableState()
2096 const bool wasFolderWritable
= m_isFolderWritable
;
2097 m_isFolderWritable
= false;
2099 KFileItem item
= m_model
->rootItem();
2100 if (item
.isNull()) {
2101 // Try to find out if the URL is writable even if the "root item" is
2102 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
2103 item
= KFileItem(url());
2104 item
.setDelayedMimeTypes(true);
2107 KFileItemListProperties
capabilities(KFileItemList() << item
);
2108 m_isFolderWritable
= capabilities
.supportsWriting();
2110 if (m_isFolderWritable
!= wasFolderWritable
) {
2111 Q_EMIT
writeStateChanged(m_isFolderWritable
);
2115 QUrl
DolphinView::viewPropertiesUrl() const
2117 if (m_viewPropertiesContext
.isEmpty()) {
2122 url
.setScheme(m_url
.scheme());
2123 url
.setPath(m_viewPropertiesContext
);
2127 void DolphinView::slotRenameDialogRenamingFinished(const QList
<QUrl
>& urls
)
2129 forceUrlsSelection(urls
.first(), urls
);
2132 void DolphinView::forceUrlsSelection(const QUrl
& current
, const QList
<QUrl
>& selected
)
2135 m_clearSelectionBeforeSelectingNewItems
= true;
2136 markUrlAsCurrent(current
);
2137 markUrlsAsSelected(selected
);
2140 void DolphinView::copyPathToClipboard()
2142 const KFileItemList list
= selectedItems();
2143 if (list
.isEmpty()) {
2146 const KFileItem
& item
= list
.at(0);
2147 QString path
= item
.localPath();
2148 if (path
.isEmpty()) {
2149 path
= item
.url().toDisplayString();
2151 QClipboard
* clipboard
= QApplication::clipboard();
2152 if (clipboard
== nullptr) {
2155 clipboard
->setText(path
);
2158 void DolphinView::slotIncreaseZoom()
2160 setZoomLevel(zoomLevel() + 1);
2163 void DolphinView::slotDecreaseZoom()
2165 setZoomLevel(zoomLevel() - 1);
2168 void DolphinView::slotSwipeUp()
2170 Q_EMIT
goUpRequested();
2173 void DolphinView::showLoadingPlaceholder()
2175 m_placeholderLabel
->setText(i18n("Loading..."));
2176 m_placeholderLabel
->setVisible(true);
2179 void DolphinView::updatePlaceholderLabel()
2181 m_showLoadingPlaceholderTimer
->stop();
2182 if (itemsCount() > 0) {
2183 m_placeholderLabel
->setVisible(false);
2187 if (m_loadingState
== LoadingState::Loading
) {
2188 m_placeholderLabel
->setVisible(false);
2189 m_showLoadingPlaceholderTimer
->start();
2193 if (m_loadingState
== LoadingState::Canceled
) {
2194 m_placeholderLabel
->setText(i18n("Loading canceled"));
2195 } else if (!nameFilter().isEmpty()) {
2196 m_placeholderLabel
->setText(i18n("No items matching the filter"));
2197 } else if (m_url
.scheme() == QLatin1String("baloosearch") || m_url
.scheme() == QLatin1String("filenamesearch")) {
2198 m_placeholderLabel
->setText(i18n("No items matching the search"));
2199 } else if (m_url
.scheme() == QLatin1String("trash") && m_url
.path() == QLatin1String("/")) {
2200 m_placeholderLabel
->setText(i18n("Trash is empty"));
2201 } else if (m_url
.scheme() == QLatin1String("tags")) {
2202 if (m_url
.path() == QLatin1Char('/')) {
2203 m_placeholderLabel
->setText(i18n("No tags"));
2205 const QString tagName
= m_url
.path().mid(1); // Remove leading /
2206 m_placeholderLabel
->setText(i18n("No files tagged with \"%1\"", tagName
));
2209 } else if (m_url
.scheme() == QLatin1String("recentlyused")) {
2210 m_placeholderLabel
->setText(i18n("No recently used items"));
2211 } else if (m_url
.scheme() == QLatin1String("smb")) {
2212 m_placeholderLabel
->setText(i18n("No shared folders found"));
2213 } else if (m_url
.scheme() == QLatin1String("network")) {
2214 m_placeholderLabel
->setText(i18n("No relevant network resources found"));
2215 } else if (m_url
.scheme() == QLatin1String("mtp") && m_url
.path() == QLatin1String("/")) {
2216 m_placeholderLabel
->setText(i18n("No MTP-compatible devices found"));
2217 } else if (m_url
.scheme() == QLatin1String("bluetooth")) {
2218 m_placeholderLabel
->setText(i18n("No Bluetooth devices found"));
2220 m_placeholderLabel
->setText(i18n("Folder is empty"));
2223 m_placeholderLabel
->setVisible(true);
2226 void DolphinView::tryShowNameToolTip(QHelpEvent
* event
)
2228 if (!GeneralSettings::showToolTips() && m_mode
== DolphinView::IconsView
) {
2229 const std::optional
<int> index
= m_view
->itemAt(event
->pos());
2231 if (!index
.has_value()) {
2235 // Check whether the filename has been elided
2236 const bool isElided
= m_view
->isElided(index
.value());
2239 const KFileItem item
= m_model
->fileItem(index
.value());
2240 const QString text
= item
.text();
2241 const QPoint pos
= mapToGlobal(event
->pos());
2242 QToolTip::showText(pos
, text
);