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 "versioncontrol/versioncontrolobserver.h"
24 #include "viewproperties.h"
25 #include "views/tooltips/tooltipmanager.h"
26 #include "zoomlevelinfo.h"
29 #include <Baloo/IndexerConfig>
31 #include <KColorScheme>
32 #include <KDesktopFile>
34 #include <KFileItemListProperties>
36 #include <KIO/CopyJob>
37 #include <KIO/DeleteJob>
38 #include <KIO/DropJob>
39 #include <KIO/JobUiDelegate>
41 #include <KIO/PasteJob>
42 #include <KIO/PreviewJob>
43 #include <KIO/RenameFileDialog>
44 #include <KJobWidgets>
45 #include <KLocalizedString>
46 #include <KMessageBox>
47 #include <KProtocolManager>
49 #include <QAbstractItemView>
50 #include <QActionGroup>
51 #include <QApplication>
54 #include <QGraphicsOpacityEffect>
55 #include <QGraphicsSceneDragDropEvent>
58 #include <QMimeDatabase>
59 #include <QPixmapCache>
64 #include <QVBoxLayout>
66 DolphinView::DolphinView(const QUrl
& url
, QWidget
* parent
) :
69 m_tabsForFiles(false),
70 m_assureVisibleCurrentIndex(false),
71 m_isFolderWritable(true),
74 m_viewPropertiesContext(),
75 m_mode(DolphinView::IconsView
),
81 m_toolTipManager(nullptr),
82 m_selectionChangedTimer(nullptr),
84 m_scrollToCurrentItem(false),
85 m_restoredContentsPosition(),
87 m_clearSelectionBeforeSelectingNewItems(false),
88 m_markFirstNewlySelectedItemAsCurrent(false),
89 m_versionControlObserver(nullptr),
90 m_twoClicksRenamingTimer(nullptr),
91 m_placeholderLabel(nullptr),
92 m_showLoadingPlaceholderTimer(nullptr)
94 m_topLayout
= new QVBoxLayout(this);
95 m_topLayout
->setSpacing(0);
96 m_topLayout
->setContentsMargins(0, 0, 0, 0);
98 // When a new item has been created by the "Create New..." menu, the item should
99 // get selected and it must be assured that the item will get visible. As the
100 // creation is done asynchronously, several signals must be checked:
101 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated
,
102 this, &DolphinView::observeCreatedItem
);
104 m_selectionChangedTimer
= new QTimer(this);
105 m_selectionChangedTimer
->setSingleShot(true);
106 m_selectionChangedTimer
->setInterval(300);
107 connect(m_selectionChangedTimer
, &QTimer::timeout
,
108 this, &DolphinView::emitSelectionChangedSignal
);
110 m_model
= new KFileItemModel(this);
111 m_view
= new DolphinItemListView();
112 m_view
->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
113 m_view
->setVisibleRoles({"text"});
116 KItemListController
* controller
= new KItemListController(m_model
, m_view
, this);
117 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
118 controller
->setAutoActivationDelay(delay
);
120 // The EnlargeSmallPreviews setting can only be changed after the model
121 // has been set in the view by KItemListController.
122 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
124 m_container
= new KItemListContainer(controller
, this);
125 m_container
->installEventFilter(this);
126 setFocusProxy(m_container
);
127 connect(m_container
->horizontalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
128 connect(m_container
->verticalScrollBar(), &QScrollBar::valueChanged
, this, [=] { hideToolTip(); });
130 m_showLoadingPlaceholderTimer
= new QTimer(this);
131 m_showLoadingPlaceholderTimer
->setInterval(500);
132 m_showLoadingPlaceholderTimer
->setSingleShot(true);
133 connect(m_showLoadingPlaceholderTimer
, &QTimer::timeout
, this, &DolphinView::showLoadingPlaceholder
);
135 // Show some placeholder text for empty folders
136 // This is made using a heavily-modified QLabel rather than a KTitleWidget
137 // because KTitleWidget can't be told to turn off mouse-selectable text
138 m_placeholderLabel
= new QLabel(this);
139 QFont placeholderLabelFont
;
140 // To match the size of a level 2 Heading/KTitleWidget
141 placeholderLabelFont
.setPointSize(qRound(placeholderLabelFont
.pointSize() * 1.3));
142 m_placeholderLabel
->setFont(placeholderLabelFont
);
143 m_placeholderLabel
->setTextInteractionFlags(Qt::NoTextInteraction
);
144 m_placeholderLabel
->setWordWrap(true);
145 m_placeholderLabel
->setAlignment(Qt::AlignCenter
);
146 // Match opacity of QML placeholder label component
147 auto *effect
= new QGraphicsOpacityEffect(m_placeholderLabel
);
148 effect
->setOpacity(0.5);
149 m_placeholderLabel
->setGraphicsEffect(effect
);
150 // Set initial text and visibility
151 updatePlaceholderLabel();
153 auto *centeringLayout
= new QVBoxLayout(m_container
);
154 centeringLayout
->addWidget(m_placeholderLabel
);
155 centeringLayout
->setAlignment(m_placeholderLabel
, Qt::AlignCenter
);
157 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
158 connect(controller
, &KItemListController::itemActivated
, this, &DolphinView::slotItemActivated
);
159 connect(controller
, &KItemListController::itemsActivated
, this, &DolphinView::slotItemsActivated
);
160 connect(controller
, &KItemListController::itemMiddleClicked
, this, &DolphinView::slotItemMiddleClicked
);
161 connect(controller
, &KItemListController::itemContextMenuRequested
, this, &DolphinView::slotItemContextMenuRequested
);
162 connect(controller
, &KItemListController::viewContextMenuRequested
, this, &DolphinView::slotViewContextMenuRequested
);
163 connect(controller
, &KItemListController::headerContextMenuRequested
, this, &DolphinView::slotHeaderContextMenuRequested
);
164 connect(controller
, &KItemListController::mouseButtonPressed
, this, &DolphinView::slotMouseButtonPressed
);
165 connect(controller
, &KItemListController::itemHovered
, this, &DolphinView::slotItemHovered
);
166 connect(controller
, &KItemListController::itemUnhovered
, this, &DolphinView::slotItemUnhovered
);
167 connect(controller
, &KItemListController::itemDropEvent
, this, &DolphinView::slotItemDropEvent
);
168 connect(controller
, &KItemListController::escapePressed
, this, &DolphinView::stopLoading
);
169 connect(controller
, &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
170 connect(controller
, &KItemListController::selectedItemTextPressed
, this, &DolphinView::slotSelectedItemTextPressed
);
171 connect(controller
, &KItemListController::increaseZoom
, this, &DolphinView::slotIncreaseZoom
);
172 connect(controller
, &KItemListController::decreaseZoom
, this, &DolphinView::slotDecreaseZoom
);
173 connect(controller
, &KItemListController::swipeUp
, this, &DolphinView::slotSwipeUp
);
175 connect(m_model
, &KFileItemModel::directoryLoadingStarted
, this, &DolphinView::slotDirectoryLoadingStarted
);
176 connect(m_model
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
177 connect(m_model
, &KFileItemModel::directoryLoadingCanceled
, this, &DolphinView::slotDirectoryLoadingCanceled
);
178 connect(m_model
, &KFileItemModel::directoryLoadingProgress
, this, &DolphinView::directoryLoadingProgress
);
179 connect(m_model
, &KFileItemModel::directorySortingProgress
, this, &DolphinView::directorySortingProgress
);
180 connect(m_model
, &KFileItemModel::itemsChanged
,
181 this, &DolphinView::slotItemsChanged
);
182 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &DolphinView::itemCountChanged
);
183 connect(m_model
, &KFileItemModel::itemsInserted
, this, &DolphinView::itemCountChanged
);
184 connect(m_model
, &KFileItemModel::infoMessage
, this, &DolphinView::infoMessage
);
185 connect(m_model
, &KFileItemModel::errorMessage
, this, &DolphinView::errorMessage
);
186 connect(m_model
, &KFileItemModel::directoryRedirection
, this, &DolphinView::slotDirectoryRedirection
);
187 connect(m_model
, &KFileItemModel::urlIsFileError
, this, &DolphinView::urlIsFileError
);
188 connect(m_model
, &KFileItemModel::fileItemsChanged
, this, &DolphinView::fileItemsChanged
);
190 connect(this, &DolphinView::itemCountChanged
,
191 this, &DolphinView::updatePlaceholderLabel
);
193 m_view
->installEventFilter(this);
194 connect(m_view
, &DolphinItemListView::sortOrderChanged
,
195 this, &DolphinView::slotSortOrderChangedByHeader
);
196 connect(m_view
, &DolphinItemListView::sortRoleChanged
,
197 this, &DolphinView::slotSortRoleChangedByHeader
);
198 connect(m_view
, &DolphinItemListView::visibleRolesChanged
,
199 this, &DolphinView::slotVisibleRolesChangedByHeader
);
200 connect(m_view
, &DolphinItemListView::roleEditingCanceled
,
201 this, &DolphinView::slotRoleEditingCanceled
);
202 connect(m_view
->header(), &KItemListHeader::columnWidthChangeFinished
,
203 this, &DolphinView::slotHeaderColumnWidthChangeFinished
);
204 connect(m_view
->header(), &KItemListHeader::sidePaddingChanged
,
205 this, &DolphinView::slotSidePaddingWidthChanged
);
207 KItemListSelectionManager
* selectionManager
= controller
->selectionManager();
208 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
,
209 this, &DolphinView::slotSelectionChanged
);
212 m_toolTipManager
= new ToolTipManager(this);
213 connect(m_toolTipManager
, &ToolTipManager::urlActivated
, this, &DolphinView::urlActivated
);
216 m_versionControlObserver
= new VersionControlObserver(this);
217 m_versionControlObserver
->setView(this);
218 m_versionControlObserver
->setModel(m_model
);
219 connect(m_versionControlObserver
, &VersionControlObserver::infoMessage
, this, &DolphinView::infoMessage
);
220 connect(m_versionControlObserver
, &VersionControlObserver::errorMessage
, this, &DolphinView::errorMessage
);
221 connect(m_versionControlObserver
, &VersionControlObserver::operationCompletedMessage
, this, &DolphinView::operationCompletedMessage
);
223 m_twoClicksRenamingTimer
= new QTimer(this);
224 m_twoClicksRenamingTimer
->setSingleShot(true);
225 connect(m_twoClicksRenamingTimer
, &QTimer::timeout
, this, &DolphinView::slotTwoClicksRenamingTimerTimeout
);
227 applyViewProperties();
228 m_topLayout
->addWidget(m_container
);
233 DolphinView::~DolphinView()
237 QUrl
DolphinView::url() const
242 void DolphinView::setActive(bool active
)
244 if (active
== m_active
) {
253 m_container
->setFocus();
255 Q_EMIT
writeStateChanged(m_isFolderWritable
);
259 bool DolphinView::isActive() const
264 void DolphinView::setMode(Mode mode
)
266 if (mode
!= m_mode
) {
267 ViewProperties
props(viewPropertiesUrl());
268 props
.setViewMode(mode
);
270 // We pass the new ViewProperties to applyViewProperties, rather than
271 // storing them on disk and letting applyViewProperties() read them
272 // from there, to prevent that changing the view mode fails if the
273 // .directory file is not writable (see bug 318534).
274 applyViewProperties(props
);
278 DolphinView::Mode
DolphinView::mode() const
283 void DolphinView::setPreviewsShown(bool show
)
285 if (previewsShown() == show
) {
289 ViewProperties
props(viewPropertiesUrl());
290 props
.setPreviewsShown(show
);
292 const int oldZoomLevel
= m_view
->zoomLevel();
293 m_view
->setPreviewsShown(show
);
294 Q_EMIT
previewsShownChanged(show
);
296 const int newZoomLevel
= m_view
->zoomLevel();
297 if (newZoomLevel
!= oldZoomLevel
) {
298 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
302 bool DolphinView::previewsShown() const
304 return m_view
->previewsShown();
307 void DolphinView::setHiddenFilesShown(bool show
)
309 if (m_model
->showHiddenFiles() == show
) {
313 const KFileItemList itemList
= selectedItems();
314 m_selectedUrls
.clear();
315 m_selectedUrls
= itemList
.urlList();
317 ViewProperties
props(viewPropertiesUrl());
318 props
.setHiddenFilesShown(show
);
320 m_model
->setShowHiddenFiles(show
);
321 Q_EMIT
hiddenFilesShownChanged(show
);
324 bool DolphinView::hiddenFilesShown() const
326 return m_model
->showHiddenFiles();
329 void DolphinView::setGroupedSorting(bool grouped
)
331 if (grouped
== groupedSorting()) {
335 ViewProperties
props(viewPropertiesUrl());
336 props
.setGroupedSorting(grouped
);
339 m_container
->controller()->model()->setGroupedSorting(grouped
);
341 Q_EMIT
groupedSortingChanged(grouped
);
344 bool DolphinView::groupedSorting() const
346 return m_model
->groupedSorting();
349 KFileItemList
DolphinView::items() const
352 const int itemCount
= m_model
->count();
353 list
.reserve(itemCount
);
355 for (int i
= 0; i
< itemCount
; ++i
) {
356 list
.append(m_model
->fileItem(i
));
362 int DolphinView::itemsCount() const
364 return m_model
->count();
367 KFileItemList
DolphinView::selectedItems() const
369 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
371 KFileItemList selectedItems
;
372 const auto items
= selectionManager
->selectedItems();
373 selectedItems
.reserve(items
.count());
374 for (int index
: items
) {
375 selectedItems
.append(m_model
->fileItem(index
));
377 return selectedItems
;
380 int DolphinView::selectedItemsCount() const
382 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
383 return selectionManager
->selectedItems().count();
386 void DolphinView::markUrlsAsSelected(const QList
<QUrl
>& urls
)
388 m_selectedUrls
= urls
;
391 void DolphinView::markUrlAsCurrent(const QUrl
&url
)
393 m_currentItemUrl
= url
;
394 m_scrollToCurrentItem
= true;
397 void DolphinView::selectItems(const QRegularExpression
®exp
, bool enabled
)
399 const KItemListSelectionManager::SelectionMode mode
= enabled
400 ? KItemListSelectionManager::Select
401 : KItemListSelectionManager::Deselect
;
402 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
404 for (int index
= 0; index
< m_model
->count(); index
++) {
405 const KFileItem item
= m_model
->fileItem(index
);
406 if (regexp
.match(item
.text()).hasMatch()) {
407 // An alternative approach would be to store the matching items in a KItemSet and
408 // select them in one go after the loop, but we'd need a new function
409 // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
411 selectionManager
->setSelected(index
, 1, mode
);
416 void DolphinView::setZoomLevel(int level
)
418 const int oldZoomLevel
= zoomLevel();
419 m_view
->setZoomLevel(level
);
420 if (zoomLevel() != oldZoomLevel
) {
422 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
426 int DolphinView::zoomLevel() const
428 return m_view
->zoomLevel();
431 void DolphinView::setSortRole(const QByteArray
& role
)
433 if (role
!= sortRole()) {
434 updateSortRole(role
);
438 QByteArray
DolphinView::sortRole() const
440 const KItemModelBase
* model
= m_container
->controller()->model();
441 return model
->sortRole();
444 void DolphinView::setSortOrder(Qt::SortOrder order
)
446 if (sortOrder() != order
) {
447 updateSortOrder(order
);
451 Qt::SortOrder
DolphinView::sortOrder() const
453 return m_model
->sortOrder();
456 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
458 if (sortFoldersFirst() != foldersFirst
) {
459 updateSortFoldersFirst(foldersFirst
);
463 bool DolphinView::sortFoldersFirst() const
465 return m_model
->sortDirectoriesFirst();
468 void DolphinView::setSortHiddenLast(bool hiddenLast
)
470 if (sortHiddenLast() != hiddenLast
) {
471 updateSortHiddenLast(hiddenLast
);
475 bool DolphinView::sortHiddenLast() const
477 return m_model
->sortHiddenLast();
480 void DolphinView::setVisibleRoles(const QList
<QByteArray
>& roles
)
482 const QList
<QByteArray
> previousRoles
= roles
;
484 ViewProperties
props(viewPropertiesUrl());
485 props
.setVisibleRoles(roles
);
487 m_visibleRoles
= roles
;
488 m_view
->setVisibleRoles(roles
);
490 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousRoles
);
493 QList
<QByteArray
> DolphinView::visibleRoles() const
495 return m_visibleRoles
;
498 void DolphinView::reload()
500 QByteArray viewState
;
501 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
502 saveState(saveStream
);
505 loadDirectory(url(), true);
507 QDataStream
restoreStream(viewState
);
508 restoreState(restoreStream
);
511 void DolphinView::readSettings()
513 const int oldZoomLevel
= m_view
->zoomLevel();
515 GeneralSettings::self()->load();
516 m_view
->readSettings();
517 applyViewProperties();
519 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
520 m_container
->controller()->setAutoActivationDelay(delay
);
522 const int newZoomLevel
= m_view
->zoomLevel();
523 if (newZoomLevel
!= oldZoomLevel
) {
524 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
528 void DolphinView::writeSettings()
530 GeneralSettings::self()->save();
531 m_view
->writeSettings();
534 void DolphinView::setNameFilter(const QString
& nameFilter
)
536 m_model
->setNameFilter(nameFilter
);
539 QString
DolphinView::nameFilter() const
541 return m_model
->nameFilter();
544 void DolphinView::setMimeTypeFilters(const QStringList
& filters
)
546 return m_model
->setMimeTypeFilters(filters
);
549 QStringList
DolphinView::mimeTypeFilters() const
551 return m_model
->mimeTypeFilters();
554 void DolphinView::requestStatusBarText()
556 if (m_statJobForStatusBarText
) {
557 // Kill the pending request.
558 m_statJobForStatusBarText
->kill();
561 if (m_container
->controller()->selectionManager()->hasSelection()) {
564 KIO::filesize_t totalFileSize
= 0;
566 // Give a summary of the status of the selected files
567 const KFileItemList list
= selectedItems();
568 for (const KFileItem
& item
: list
) {
573 totalFileSize
+= item
.size();
577 if (folderCount
+ fileCount
== 1) {
578 // If only one item is selected, show info about it
579 Q_EMIT
statusBarTextChanged(list
.first().getStatusBarInfo());
581 // At least 2 items are selected
582 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, HasSelection
);
584 } else { // has no selection
585 if (!m_model
->rootItem().url().isValid()) {
589 m_statJobForStatusBarText
= KIO::statDetails(m_model
->rootItem().url(),
590 KIO::StatJob::SourceSide
, KIO::StatRecursiveSize
, KIO::HideProgressInfo
);
591 connect(m_statJobForStatusBarText
, &KJob::result
,
592 this, &DolphinView::slotStatJobResult
);
593 m_statJobForStatusBarText
->start();
597 void DolphinView::emitStatusBarText(const int folderCount
, const int fileCount
,
598 KIO::filesize_t totalFileSize
, const Selection selection
)
604 if (selection
== HasSelection
) {
605 // At least 2 items are selected because the case of 1 selected item is handled in
606 // DolphinView::requestStatusBarText().
607 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
608 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
610 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
611 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
614 if (fileCount
> 0 && folderCount
> 0) {
615 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
616 foldersText
, filesText
,
617 KFormat().formatByteSize(totalFileSize
));
618 } else if (fileCount
> 0) {
619 summary
= i18nc("@info:status files (size)", "%1 (%2)",
621 KFormat().formatByteSize(totalFileSize
));
622 } else if (folderCount
> 0) {
623 summary
= foldersText
;
625 summary
= i18nc("@info:status", "0 Folders, 0 Files");
627 Q_EMIT
statusBarTextChanged(summary
);
630 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
632 QList
<QAction
*> actions
;
634 if (items
.isEmpty()) {
635 const KFileItem item
= m_model
->rootItem();
636 if (!item
.isNull()) {
637 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
640 actions
= m_versionControlObserver
->actions(items
);
646 void DolphinView::setUrl(const QUrl
& url
)
658 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
659 this, &DolphinView::slotRoleEditingFinished
);
661 // It is important to clear the items from the model before
662 // applying the view properties, otherwise expensive operations
663 // might be done on the existing items although they get cleared
664 // anyhow afterwards by loadDirectory().
666 applyViewProperties();
669 Q_EMIT
urlChanged(url
);
672 void DolphinView::selectAll()
674 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
675 selectionManager
->setSelected(0, m_model
->count());
678 void DolphinView::invertSelection()
680 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
681 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
684 void DolphinView::clearSelection()
686 m_selectedUrls
.clear();
687 m_container
->controller()->selectionManager()->clearSelection();
690 void DolphinView::renameSelectedItems()
692 const KFileItemList items
= selectedItems();
693 if (items
.isEmpty()) {
697 if (items
.count() == 1 && GeneralSettings::renameInline()) {
698 const int index
= m_model
->index(items
.first());
700 QMetaObject::Connection
* const connection
= new QMetaObject::Connection
;
701 *connection
= connect(m_view
, &KItemListView::scrollingStopped
, this, [=](){
702 QObject::disconnect(*connection
);
705 m_view
->editRole(index
, "text");
709 connect(m_view
, &DolphinItemListView::roleEditingFinished
,
710 this, &DolphinView::slotRoleEditingFinished
);
712 m_view
->scrollToItem(index
);
715 KIO::RenameFileDialog
* dialog
= new KIO::RenameFileDialog(items
, this);
716 connect(dialog
, &KIO::RenameFileDialog::renamingFinished
,
717 this, &DolphinView::slotRenameDialogRenamingFinished
);
722 // Assure that the current index remains visible when KFileItemModel
723 // will notify the view about changed items (which might result in
724 // a changed sorting).
725 m_assureVisibleCurrentIndex
= true;
728 void DolphinView::trashSelectedItems()
730 const QList
<QUrl
> list
= simplifiedSelectedUrls();
731 KIO::JobUiDelegate uiDelegate
;
732 uiDelegate
.setWindow(window());
733 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Trash
, KIO::JobUiDelegate::DefaultConfirmation
)) {
734 KIO::Job
* job
= KIO::trash(list
);
735 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash
, list
, QUrl(QStringLiteral("trash:/")), job
);
736 KJobWidgets::setWindow(job
, this);
737 connect(job
, &KIO::Job::result
,
738 this, &DolphinView::slotTrashFileFinished
);
742 void DolphinView::deleteSelectedItems()
744 const QList
<QUrl
> list
= simplifiedSelectedUrls();
746 KIO::JobUiDelegate uiDelegate
;
747 uiDelegate
.setWindow(window());
748 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Delete
, KIO::JobUiDelegate::DefaultConfirmation
)) {
749 KIO::Job
* job
= KIO::del(list
);
750 KJobWidgets::setWindow(job
, this);
751 connect(job
, &KIO::Job::result
,
752 this, &DolphinView::slotDeleteFileFinished
);
756 void DolphinView::cutSelectedItemsToClipboard()
758 QMimeData
* mimeData
= selectionMimeData();
759 KIO::setClipboardDataCut(mimeData
, true);
760 QApplication::clipboard()->setMimeData(mimeData
);
763 void DolphinView::copySelectedItemsToClipboard()
765 QMimeData
* mimeData
= selectionMimeData();
766 QApplication::clipboard()->setMimeData(mimeData
);
769 void DolphinView::copySelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
771 KIO::CopyJob
* job
= KIO::copy(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
772 KJobWidgets::setWindow(job
, this);
774 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
775 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
776 KIO::FileUndoManager::self()->recordCopyJob(job
);
779 void DolphinView::moveSelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
781 KIO::CopyJob
* job
= KIO::move(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
782 KJobWidgets::setWindow(job
, this);
784 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
785 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
786 KIO::FileUndoManager::self()->recordCopyJob(job
);
790 void DolphinView::paste()
795 void DolphinView::pasteIntoFolder()
797 const KFileItemList items
= selectedItems();
798 if ((items
.count() == 1) && items
.first().isDir()) {
799 pasteToUrl(items
.first().url());
803 void DolphinView::duplicateSelectedItems()
805 const KFileItemList itemList
= selectedItems();
806 if (itemList
.isEmpty()) {
810 const QMimeDatabase db
;
812 // Duplicate all selected items and append "copy" to the end of the file name
813 // but before the filename extension, if present
814 QList
<QUrl
> newSelection
;
815 for (const auto &item
: itemList
) {
816 const QUrl originalURL
= item
.url();
817 const QString originalDirectoryPath
= originalURL
.adjusted(QUrl::RemoveFilename
).path();
818 const QString originalFileName
= item
.name();
820 QString extension
= db
.suffixForFileName(originalFileName
);
822 QUrl duplicateURL
= originalURL
;
824 // No extension; new filename is "<oldfilename> copy"
825 if (extension
.isEmpty()) {
826 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFileName
));
827 // There's an extension; new filename is "<oldfilename> copy.<extension>"
829 // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it
830 extension
= QLatin1String(".") + extension
;
831 const QString originalFilenameWithoutExtension
= originalFileName
.chopped(extension
.size());
832 // Preserve file's original filename extension in case the casing differs
833 // from what QMimeDatabase::suffixForFileName() returned
834 const QString originalExtension
= originalFileName
.right(extension
.size());
835 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension
) + originalExtension
);
838 KIO::CopyJob
* job
= KIO::copyAs(originalURL
, duplicateURL
);
839 KJobWidgets::setWindow(job
, this);
842 newSelection
<< duplicateURL
;
843 KIO::FileUndoManager::self()->recordCopyJob(job
);
847 forceUrlsSelection(newSelection
.first(), newSelection
);
850 void DolphinView::stopLoading()
852 m_model
->cancelDirectoryLoading();
855 void DolphinView::updatePalette()
857 QColor color
= KColorScheme(isActiveWindow() ? QPalette::Active
: QPalette::Inactive
, KColorScheme::View
).background().color();
862 QWidget
* viewport
= m_container
->viewport();
865 palette
.setColor(viewport
->backgroundRole(), color
);
866 viewport
->setPalette(palette
);
872 void DolphinView::abortTwoClicksRenaming()
874 m_twoClicksRenamingItemUrl
.clear();
875 m_twoClicksRenamingTimer
->stop();
878 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
880 switch (event
->type()) {
881 case QEvent::PaletteChange
:
883 QPixmapCache::clear();
886 case QEvent::WindowActivate
:
887 case QEvent::WindowDeactivate
:
891 case QEvent::KeyPress
:
892 hideToolTip(ToolTipManager::HideBehavior::Instantly
);
893 if (GeneralSettings::useTabForSwitchingSplitView()) {
894 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
895 if (keyEvent
->key() == Qt::Key_Tab
&& keyEvent
->modifiers() == Qt::NoModifier
) {
896 Q_EMIT
toggleActiveViewRequested();
901 case QEvent::FocusIn
:
902 if (watched
== m_container
) {
907 case QEvent::GraphicsSceneDragEnter
:
908 if (watched
== m_view
) {
910 abortTwoClicksRenaming();
914 case QEvent::GraphicsSceneDragLeave
:
915 if (watched
== m_view
) {
920 case QEvent::GraphicsSceneDrop
:
921 if (watched
== m_view
) {
926 case QEvent::ToolTip
:
927 tryShowNameToolTip(static_cast<QHelpEvent
*>(event
));
933 return QWidget::eventFilter(watched
, event
);
936 void DolphinView::wheelEvent(QWheelEvent
* event
)
938 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
939 const QPoint numDegrees
= event
->angleDelta() / 8;
940 const QPoint numSteps
= numDegrees
/ 15;
942 setZoomLevel(zoomLevel() + numSteps
.y());
949 void DolphinView::hideEvent(QHideEvent
* event
)
952 QWidget::hideEvent(event
);
955 bool DolphinView::event(QEvent
* event
)
957 if (event
->type() == QEvent::WindowDeactivate
) {
959 * Dolphin leaves file preview tooltips open even when is not visible.
961 * Hide tool-tip when Dolphin loses focus.
964 abortTwoClicksRenaming();
967 return QWidget::event(event
);
970 void DolphinView::activate()
975 void DolphinView::slotItemActivated(int index
)
977 abortTwoClicksRenaming();
979 const KFileItem item
= m_model
->fileItem(index
);
980 if (!item
.isNull()) {
981 Q_EMIT
itemActivated(item
);
985 void DolphinView::slotItemsActivated(const KItemSet
&indexes
)
987 Q_ASSERT(indexes
.count() >= 2);
989 abortTwoClicksRenaming();
991 const auto modifiers
= QGuiApplication::keyboardModifiers();
993 if (indexes
.count() > 5) {
994 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
995 const int answer
= KMessageBox::warningYesNo(this, question
);
996 if (answer
!= KMessageBox::Yes
) {
1001 KFileItemList items
;
1002 items
.reserve(indexes
.count());
1004 for (int index
: indexes
) {
1005 KFileItem item
= m_model
->fileItem(index
);
1006 const QUrl
& url
= openItemAsFolderUrl(item
);
1008 if (!url
.isEmpty()) {
1009 // Open folders in new tabs or in new windows depending on the modifier
1010 // The ctrl+shift behavior is ignored because we are handling multiple items
1011 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1012 if (modifiers
& Qt::ShiftModifier
&& !(modifiers
& Qt::ControlModifier
)) {
1013 Q_EMIT
windowRequested(url
);
1015 Q_EMIT
tabRequested(url
);
1022 if (items
.count() == 1) {
1023 Q_EMIT
itemActivated(items
.first());
1024 } else if (items
.count() > 1) {
1025 Q_EMIT
itemsActivated(items
);
1029 void DolphinView::slotItemMiddleClicked(int index
)
1031 const KFileItem
& item
= m_model
->fileItem(index
);
1032 const QUrl
& url
= openItemAsFolderUrl(item
);
1033 const auto modifiers
= QGuiApplication::keyboardModifiers();
1034 if (!url
.isEmpty()) {
1035 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1036 if (modifiers
& Qt::ShiftModifier
) {
1037 Q_EMIT
activeTabRequested(url
);
1039 Q_EMIT
tabRequested(url
);
1041 } else if (isTabsForFilesEnabled()) {
1042 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1043 if (modifiers
& Qt::ShiftModifier
) {
1044 Q_EMIT
activeTabRequested(item
.url());
1046 Q_EMIT
tabRequested(item
.url());
1051 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
& pos
)
1053 // Force emit of a selection changed signal before we request the
1054 // context menu, to update the edit-actions first. (See Bug 294013)
1055 if (m_selectionChangedTimer
->isActive()) {
1056 emitSelectionChangedSignal();
1059 const KFileItem item
= m_model
->fileItem(index
);
1060 Q_EMIT
requestContextMenu(pos
.toPoint(), item
, selectedItems(), url());
1063 void DolphinView::slotViewContextMenuRequested(const QPointF
& pos
)
1065 Q_EMIT
requestContextMenu(pos
.toPoint(), KFileItem(), selectedItems(), url());
1068 void DolphinView::slotHeaderContextMenuRequested(const QPointF
& pos
)
1070 ViewProperties
props(viewPropertiesUrl());
1072 QPointer
<QMenu
> menu
= new QMenu(QApplication::activeWindow());
1074 KItemListView
* view
= m_container
->controller()->view();
1075 const QList
<QByteArray
> visibleRolesSet
= view
->visibleRoles();
1077 bool indexingEnabled
= false;
1079 Baloo::IndexerConfig config
;
1080 indexingEnabled
= config
.fileIndexingEnabled();
1084 QMenu
* groupMenu
= nullptr;
1086 // Add all roles to the menu that can be shown or hidden by the user
1087 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
1088 for (const KFileItemModel::RoleInfo
& info
: rolesInfo
) {
1089 if (info
.role
== "text") {
1090 // It should not be possible to hide the "text" role
1094 const QString text
= m_model
->roleDescription(info
.role
);
1095 QAction
* action
= nullptr;
1096 if (info
.group
.isEmpty()) {
1097 action
= menu
->addAction(text
);
1099 if (!groupMenu
|| info
.group
!= groupName
) {
1100 groupName
= info
.group
;
1101 groupMenu
= menu
->addMenu(groupName
);
1104 action
= groupMenu
->addAction(text
);
1107 action
->setCheckable(true);
1108 action
->setChecked(visibleRolesSet
.contains(info
.role
));
1109 action
->setData(info
.role
);
1111 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
1112 (info
.requiresBaloo
) ||
1113 (info
.requiresIndexer
&& indexingEnabled
);
1114 action
->setEnabled(enable
);
1117 menu
->addSeparator();
1119 QActionGroup
* widthsGroup
= new QActionGroup(menu
);
1120 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
1122 QAction
* toggleSidePaddingAction
= menu
->addAction(i18nc("@action:inmenu", "Side Padding"));
1123 toggleSidePaddingAction
->setCheckable(true);
1124 toggleSidePaddingAction
->setChecked(view
->header()->sidePadding() > 0);
1126 QAction
* autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
1127 autoAdjustWidthsAction
->setCheckable(true);
1128 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
1129 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
1131 QAction
* customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
1132 customWidthsAction
->setCheckable(true);
1133 customWidthsAction
->setChecked(!autoColumnWidths
);
1134 customWidthsAction
->setActionGroup(widthsGroup
);
1136 QAction
* action
= menu
->exec(pos
.toPoint());
1137 if (menu
&& action
) {
1138 KItemListHeader
* header
= view
->header();
1140 if (action
== autoAdjustWidthsAction
) {
1141 // Clear the column-widths from the viewproperties and turn on
1142 // the automatic resizing of the columns
1143 props
.setHeaderColumnWidths(QList
<int>());
1144 header
->setAutomaticColumnResizing(true);
1145 } else if (action
== customWidthsAction
) {
1146 // Apply the current column-widths as custom column-widths and turn
1147 // off the automatic resizing of the columns
1148 QList
<int> columnWidths
;
1149 const auto visibleRoles
= view
->visibleRoles();
1150 columnWidths
.reserve(visibleRoles
.count());
1151 for (const QByteArray
& role
: visibleRoles
) {
1152 columnWidths
.append(header
->columnWidth(role
));
1154 props
.setHeaderColumnWidths(columnWidths
);
1155 header
->setAutomaticColumnResizing(false);
1156 } else if (action
== toggleSidePaddingAction
) {
1157 header
->setSidePadding(toggleSidePaddingAction
->isChecked() ? 20 : 0);
1159 // Show or hide the selected role
1160 const QByteArray selectedRole
= action
->data().toByteArray();
1162 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
1163 if (action
->isChecked()) {
1164 visibleRoles
.append(selectedRole
);
1166 visibleRoles
.removeOne(selectedRole
);
1169 view
->setVisibleRoles(visibleRoles
);
1170 props
.setVisibleRoles(visibleRoles
);
1172 QList
<int> columnWidths
;
1173 if (!header
->automaticColumnResizing()) {
1174 const auto visibleRoles
= view
->visibleRoles();
1175 columnWidths
.reserve(visibleRoles
.count());
1176 for (const QByteArray
& role
: visibleRoles
) {
1177 columnWidths
.append(header
->columnWidth(role
));
1180 props
.setHeaderColumnWidths(columnWidths
);
1187 void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray
& role
, qreal current
)
1189 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
1191 ViewProperties
props(viewPropertiesUrl());
1192 QList
<int> columnWidths
= props
.headerColumnWidths();
1193 if (columnWidths
.count() != visibleRoles
.count()) {
1194 columnWidths
.clear();
1195 columnWidths
.reserve(visibleRoles
.count());
1196 const KItemListHeader
* header
= m_view
->header();
1197 for (const QByteArray
& role
: visibleRoles
) {
1198 const int width
= header
->columnWidth(role
);
1199 columnWidths
.append(width
);
1203 const int roleIndex
= visibleRoles
.indexOf(role
);
1204 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
1205 columnWidths
[roleIndex
] = current
;
1207 props
.setHeaderColumnWidths(columnWidths
);
1210 void DolphinView::slotSidePaddingWidthChanged(qreal width
)
1212 ViewProperties
props(viewPropertiesUrl());
1213 DetailsModeSettings::setSidePadding(int(width
));
1214 m_view
->writeSettings();
1217 void DolphinView::slotItemHovered(int index
)
1219 const KFileItem item
= m_model
->fileItem(index
);
1221 if (GeneralSettings::showToolTips() && !m_dragging
) {
1222 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1223 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1224 itemRect
.moveTo(pos
);
1227 auto nativeParent
= nativeParentWidget();
1229 m_toolTipManager
->showToolTip(item
, itemRect
, nativeParent
->windowHandle());
1234 Q_EMIT
requestItemInfo(item
);
1237 void DolphinView::slotItemUnhovered(int index
)
1241 Q_EMIT
requestItemInfo(KFileItem());
1244 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
* event
)
1247 KFileItem destItem
= m_model
->fileItem(index
);
1248 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1249 // Use the URL of the view as drop target if the item is no directory
1251 destItem
= m_model
->rootItem();
1254 // The item represents a directory or desktop-file
1255 destUrl
= destItem
.mostLocalUrl();
1258 QDropEvent
dropEvent(event
->pos().toPoint(),
1259 event
->possibleActions(),
1262 event
->modifiers());
1263 dropUrls(destUrl
, &dropEvent
, this);
1268 void DolphinView::dropUrls(const QUrl
&destUrl
, QDropEvent
*dropEvent
, QWidget
*dropWidget
)
1270 KIO::DropJob
* job
= DragAndDropHelper::dropUrls(destUrl
, dropEvent
, dropWidget
);
1273 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
1275 if (destUrl
== url()) {
1276 // Mark the dropped urls as selected.
1277 m_clearSelectionBeforeSelectingNewItems
= true;
1278 m_markFirstNewlySelectedItemAsCurrent
= true;
1279 connect(job
, &KIO::DropJob::itemCreated
, this, &DolphinView::slotItemCreated
);
1284 void DolphinView::slotModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
)
1286 if (previous
!= nullptr) {
1287 Q_ASSERT(qobject_cast
<KFileItemModel
*>(previous
));
1288 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(previous
);
1289 disconnect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1290 m_versionControlObserver
->setModel(nullptr);
1294 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1295 KFileItemModel
* fileItemModel
= static_cast<KFileItemModel
*>(current
);
1296 connect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1297 m_versionControlObserver
->setModel(fileItemModel
);
1301 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1307 if (buttons
& Qt::BackButton
) {
1308 Q_EMIT
goBackRequested();
1309 } else if (buttons
& Qt::ForwardButton
) {
1310 Q_EMIT
goForwardRequested();
1314 void DolphinView::slotSelectedItemTextPressed(int index
)
1316 if (GeneralSettings::renameInline() && !m_view
->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick
)) {
1317 const KFileItem item
= m_model
->fileItem(index
);
1318 const KFileItemListProperties
capabilities(KFileItemList() << item
);
1319 if (capabilities
.supportsMoving()) {
1320 m_twoClicksRenamingItemUrl
= item
.url();
1321 m_twoClicksRenamingTimer
->start(QApplication::doubleClickInterval());
1326 void DolphinView::slotCopyingDone(KIO::Job
*, const QUrl
&, const QUrl
&to
)
1328 slotItemCreated(to
);
1331 void DolphinView::slotItemCreated(const QUrl
& url
)
1333 if (m_markFirstNewlySelectedItemAsCurrent
) {
1334 markUrlAsCurrent(url
);
1335 m_markFirstNewlySelectedItemAsCurrent
= false;
1337 m_selectedUrls
<< url
;
1340 void DolphinView::slotJobResult(KJob
*job
)
1343 Q_EMIT
errorMessage(job
->errorString());
1345 if (!m_selectedUrls
.isEmpty()) {
1346 m_selectedUrls
= KDirModel::simplifiedUrlList(m_selectedUrls
);
1350 void DolphinView::slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
)
1352 const int currentCount
= current
.count();
1353 const int previousCount
= previous
.count();
1354 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) ||
1355 (currentCount
> 0 && previousCount
== 0);
1357 // If nothing has been selected before and something got selected (or if something
1358 // was selected before and now nothing is selected) the selectionChangedSignal must
1359 // be emitted asynchronously as fast as possible to update the edit-actions.
1360 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1361 m_selectionChangedTimer
->start();
1364 void DolphinView::emitSelectionChangedSignal()
1366 m_selectionChangedTimer
->stop();
1367 Q_EMIT
selectionChanged(selectedItems());
1370 void DolphinView::slotStatJobResult(KJob
*job
)
1372 int folderCount
= 0;
1374 KIO::filesize_t totalFileSize
= 0;
1375 bool countFileSize
= true;
1377 const auto entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1378 if (entry
.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE
)) {
1379 // We have a precomputed value.
1380 totalFileSize
= static_cast<KIO::filesize_t
>(
1381 entry
.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE
));
1382 countFileSize
= false;
1385 const int itemCount
= m_model
->count();
1386 for (int i
= 0; i
< itemCount
; ++i
) {
1387 const KFileItem item
= m_model
->fileItem(i
);
1392 if (countFileSize
) {
1393 totalFileSize
+= item
.size();
1397 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, NoSelection
);
1400 void DolphinView::updateSortRole(const QByteArray
& role
)
1402 ViewProperties
props(viewPropertiesUrl());
1403 props
.setSortRole(role
);
1405 KItemModelBase
* model
= m_container
->controller()->model();
1406 model
->setSortRole(role
);
1408 Q_EMIT
sortRoleChanged(role
);
1411 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1413 ViewProperties
props(viewPropertiesUrl());
1414 props
.setSortOrder(order
);
1416 m_model
->setSortOrder(order
);
1418 Q_EMIT
sortOrderChanged(order
);
1421 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1423 ViewProperties
props(viewPropertiesUrl());
1424 props
.setSortFoldersFirst(foldersFirst
);
1426 m_model
->setSortDirectoriesFirst(foldersFirst
);
1428 Q_EMIT
sortFoldersFirstChanged(foldersFirst
);
1431 void DolphinView::updateSortHiddenLast(bool hiddenLast
)
1433 ViewProperties
props(viewPropertiesUrl());
1434 props
.setSortHiddenLast(hiddenLast
);
1436 m_model
->setSortHiddenLast(hiddenLast
);
1438 Q_EMIT
sortHiddenLastChanged(hiddenLast
);
1442 QPair
<bool, QString
> DolphinView::pasteInfo() const
1444 const QMimeData
*mimeData
= QApplication::clipboard()->mimeData();
1445 QPair
<bool, QString
> info
;
1446 info
.second
= KIO::pasteActionText(mimeData
, &info
.first
, rootItem());
1450 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1452 m_tabsForFiles
= tabsForFiles
;
1455 bool DolphinView::isTabsForFilesEnabled() const
1457 return m_tabsForFiles
;
1460 bool DolphinView::itemsExpandable() const
1462 return m_mode
== DetailsView
;
1465 void DolphinView::restoreState(QDataStream
& stream
)
1467 // Read the version number of the view state and check if the version is supported.
1468 quint32 version
= 0;
1471 // The version of the view state isn't supported, we can't restore it.
1475 // Restore the current item that had the keyboard focus
1476 stream
>> m_currentItemUrl
;
1478 // Restore the previously selected items
1479 stream
>> m_selectedUrls
;
1481 // Restore the view position
1482 stream
>> m_restoredContentsPosition
;
1484 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1487 m_model
->restoreExpandedDirectories(urls
);
1490 void DolphinView::saveState(QDataStream
& stream
)
1492 stream
<< quint32(1); // View state version
1494 // Save the current item that has the keyboard focus
1495 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1496 if (currentIndex
!= -1) {
1497 KFileItem item
= m_model
->fileItem(currentIndex
);
1498 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1499 QUrl currentItemUrl
= item
.url();
1500 stream
<< currentItemUrl
;
1505 // Save the selected urls
1506 stream
<< selectedItems().urlList();
1508 // Save view position
1509 const qreal x
= m_container
->horizontalScrollBar()->value();
1510 const qreal y
= m_container
->verticalScrollBar()->value();
1511 stream
<< QPoint(x
, y
);
1513 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1514 stream
<< m_model
->expandedDirectories();
1517 KFileItem
DolphinView::rootItem() const
1519 return m_model
->rootItem();
1522 void DolphinView::setViewPropertiesContext(const QString
& context
)
1524 m_viewPropertiesContext
= context
;
1527 QString
DolphinView::viewPropertiesContext() const
1529 return m_viewPropertiesContext
;
1532 QUrl
DolphinView::openItemAsFolderUrl(const KFileItem
& item
, const bool browseThroughArchives
)
1534 if (item
.isNull()) {
1538 QUrl url
= item
.targetUrl();
1544 if (item
.isMimeTypeKnown()) {
1545 const QString
& mimetype
= item
.mimetype();
1547 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1548 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1549 // zip:/<path>/ when clicking on a zip file, etc.
1550 // The .protocol file specifies the mimetype that the kioslave handles.
1551 // Note that we don't use mimetype inheritance since we don't want to
1552 // open OpenDocument files as zip folders...
1553 const QString
& protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1554 if (!protocol
.isEmpty()) {
1555 url
.setScheme(protocol
);
1560 if (mimetype
== QLatin1String("application/x-desktop")) {
1561 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1562 KDesktopFile
desktopFile(url
.toLocalFile());
1563 if (desktopFile
.hasLinkType()) {
1564 const QString linkUrl
= desktopFile
.readUrl();
1565 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1566 return QUrl::fromUserInput(linkUrl
);
1575 void DolphinView::resetZoomLevel()
1577 ViewModeSettings settings
{m_mode
};
1578 settings
.useDefaults(true);
1579 const int defaultIconSize
= settings
.iconSize();
1580 settings
.useDefaults(false);
1582 setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(QSize(defaultIconSize
, defaultIconSize
)));
1585 void DolphinView::observeCreatedItem(const QUrl
& url
)
1588 forceUrlsSelection(url
, {url
});
1592 void DolphinView::slotDirectoryRedirection(const QUrl
& oldUrl
, const QUrl
& newUrl
)
1594 if (oldUrl
.matches(url(), QUrl::StripTrailingSlash
)) {
1595 Q_EMIT
redirection(oldUrl
, newUrl
);
1596 m_url
= newUrl
; // #186947
1600 void DolphinView::updateViewState()
1602 if (m_currentItemUrl
!= QUrl()) {
1603 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1605 // if there is a selection already, leave it that way
1606 if (!selectionManager
->hasSelection()) {
1607 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1608 if (currentIndex
!= -1) {
1609 selectionManager
->setCurrentItem(currentIndex
);
1611 // scroll to current item and reset the state
1612 if (m_scrollToCurrentItem
) {
1613 m_view
->scrollToItem(currentIndex
);
1614 m_scrollToCurrentItem
= false;
1616 m_currentItemUrl
= QUrl();
1618 selectionManager
->setCurrentItem(0);
1621 m_currentItemUrl
= QUrl();
1625 if (!m_restoredContentsPosition
.isNull()) {
1626 const int x
= m_restoredContentsPosition
.x();
1627 const int y
= m_restoredContentsPosition
.y();
1628 m_restoredContentsPosition
= QPoint();
1630 m_container
->horizontalScrollBar()->setValue(x
);
1631 m_container
->verticalScrollBar()->setValue(y
);
1634 if (!m_selectedUrls
.isEmpty()) {
1635 KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1637 // if there is a selection already, leave it that way
1638 if (!selectionManager
->hasSelection()) {
1639 if (m_clearSelectionBeforeSelectingNewItems
) {
1640 selectionManager
->clearSelection();
1641 m_clearSelectionBeforeSelectingNewItems
= false;
1644 KItemSet selectedItems
= selectionManager
->selectedItems();
1646 QList
<QUrl
>::iterator it
= m_selectedUrls
.begin();
1647 while (it
!= m_selectedUrls
.end()) {
1648 const int index
= m_model
->index(*it
);
1650 selectedItems
.insert(index
);
1651 it
= m_selectedUrls
.erase(it
);
1657 if (!selectedItems
.isEmpty()) {
1658 selectionManager
->beginAnchoredSelection(selectionManager
->currentItem());
1659 selectionManager
->setSelectedItems(selectedItems
);
1665 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior
)
1667 if (GeneralSettings::showToolTips()) {
1669 m_toolTipManager
->hideToolTip(behavior
);
1673 } else if (m_mode
== DolphinView::IconsView
) {
1674 QToolTip::hideText();
1678 void DolphinView::slotTwoClicksRenamingTimerTimeout()
1680 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
1682 // verify that only one item is selected
1683 if (selectionManager
->selectedItems().count() == 1) {
1684 const int index
= selectionManager
->currentItem();
1685 const QUrl fileItemUrl
= m_model
->fileItem(index
).url();
1687 // check if the selected item was the same item that started the twoClicksRenaming
1688 if (fileItemUrl
.isValid() && m_twoClicksRenamingItemUrl
== fileItemUrl
) {
1689 renameSelectedItems();
1694 void DolphinView::slotTrashFileFinished(KJob
* job
)
1696 if (job
->error() == 0) {
1697 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
1698 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1699 Q_EMIT
errorMessage(job
->errorString());
1703 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1705 if (job
->error() == 0) {
1706 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1707 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1708 Q_EMIT
errorMessage(job
->errorString());
1712 void DolphinView::slotRenamingResult(KJob
* job
)
1715 KIO::CopyJob
*copyJob
= qobject_cast
<KIO::CopyJob
*>(job
);
1717 const QUrl newUrl
= copyJob
->destUrl();
1718 const int index
= m_model
->index(newUrl
);
1720 QHash
<QByteArray
, QVariant
> data
;
1721 const QUrl oldUrl
= copyJob
->srcUrls().at(0);
1722 data
.insert("text", oldUrl
.fileName());
1723 m_model
->setData(index
, data
);
1728 void DolphinView::slotDirectoryLoadingStarted()
1730 m_loadingState
= LoadingState::Loading
;
1731 updatePlaceholderLabel();
1733 // Disable the writestate temporary until it can be determined in a fast way
1734 // in DolphinView::slotDirectoryLoadingCompleted()
1735 if (m_isFolderWritable
) {
1736 m_isFolderWritable
= false;
1737 Q_EMIT
writeStateChanged(m_isFolderWritable
);
1740 Q_EMIT
directoryLoadingStarted();
1743 void DolphinView::slotDirectoryLoadingCompleted()
1745 m_loadingState
= LoadingState::Completed
;
1747 // Update the view-state. This has to be done asynchronously
1748 // because the view might not be in its final state yet.
1749 QTimer::singleShot(0, this, &DolphinView::updateViewState
);
1751 // Update the placeholder label in case we found that the folder was empty
1754 Q_EMIT
directoryLoadingCompleted();
1756 updatePlaceholderLabel();
1757 updateWritableState();
1760 void DolphinView::slotDirectoryLoadingCanceled()
1762 m_loadingState
= LoadingState::Canceled
;
1764 updatePlaceholderLabel();
1766 Q_EMIT
directoryLoadingCanceled();
1769 void DolphinView::slotItemsChanged()
1771 m_assureVisibleCurrentIndex
= false;
1774 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1777 Q_ASSERT(m_model
->sortOrder() == current
);
1779 ViewProperties
props(viewPropertiesUrl());
1780 props
.setSortOrder(current
);
1782 Q_EMIT
sortOrderChanged(current
);
1785 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
& current
, const QByteArray
& previous
)
1788 Q_ASSERT(m_model
->sortRole() == current
);
1790 ViewProperties
props(viewPropertiesUrl());
1791 props
.setSortRole(current
);
1793 Q_EMIT
sortRoleChanged(current
);
1796 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
>& current
,
1797 const QList
<QByteArray
>& previous
)
1800 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1802 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1804 m_visibleRoles
= current
;
1806 ViewProperties
props(viewPropertiesUrl());
1807 props
.setVisibleRoles(m_visibleRoles
);
1809 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1812 void DolphinView::slotRoleEditingCanceled()
1814 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1815 this, &DolphinView::slotRoleEditingFinished
);
1818 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
)
1820 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
,
1821 this, &DolphinView::slotRoleEditingFinished
);
1823 const KFileItemList items
= selectedItems();
1824 if (items
.count() != 1) {
1828 if (role
== "text") {
1829 const KFileItem oldItem
= items
.first();
1830 const EditResult retVal
= value
.value
<EditResult
>();
1831 const QString newName
= retVal
.newName
;
1832 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1Char('.') && newName
!= QLatin1String("..")) {
1833 const QUrl oldUrl
= oldItem
.url();
1835 QUrl newUrl
= oldUrl
.adjusted(QUrl::RemoveFilename
);
1836 newUrl
.setPath(newUrl
.path() + KIO::encodeFileName(newName
));
1839 //Confirm hiding file/directory by renaming inline
1840 if (!hiddenFilesShown() && newName
.startsWith(QLatin1Char('.')) && !oldItem
.name().startsWith(QLatin1Char('.'))) {
1841 KGuiItem
yesGuiItem(KStandardGuiItem::yes());
1842 yesGuiItem
.setText(i18nc("@action:button", "Rename and Hide"));
1844 const auto code
= KMessageBox::questionYesNo(this,
1845 oldItem
.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
1846 "Do you still want to rename it?")
1847 : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
1848 "Do you still want to rename it?"),
1849 oldItem
.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"),
1851 KStandardGuiItem::cancel(),
1852 QStringLiteral("ConfirmHide")
1855 if (code
== KMessageBox::No
) {
1861 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1862 if (!newNameExistsAlready
&& m_model
->index(oldUrl
) == index
) {
1863 // Only change the data in the model if no item with the new name
1864 // is in the model yet. If there is an item with the new name
1865 // already, calling KIO::CopyJob will open a dialog
1866 // asking for a new name, and KFileItemModel will update the
1867 // data when the dir lister signals that the file name has changed.
1868 QHash
<QByteArray
, QVariant
> data
;
1869 data
.insert(role
, retVal
.newName
);
1870 m_model
->setData(index
, data
);
1873 KIO::Job
* job
= KIO::moveAs(oldUrl
, newUrl
);
1874 KJobWidgets::setWindow(job
, this);
1875 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename
, {oldUrl
}, newUrl
, job
);
1876 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
1878 forceUrlsSelection(newUrl
, {newUrl
});
1880 if (!newNameExistsAlready
) {
1881 // Only connect the result signal if there is no item with the new name
1882 // in the model yet, see bug 328262.
1883 connect(job
, &KJob::result
, this, &DolphinView::slotRenamingResult
);
1886 if (retVal
.direction
!= EditDone
) {
1887 const short indexShift
= retVal
.direction
== EditNext
? 1 : -1;
1888 m_container
->controller()->selectionManager()->setSelected(index
, 1, KItemListSelectionManager::Deselect
);
1889 m_container
->controller()->selectionManager()->setSelected(index
+ indexShift
, 1,
1890 KItemListSelectionManager::Select
);
1891 renameSelectedItems();
1896 void DolphinView::loadDirectory(const QUrl
& url
, bool reload
)
1898 if (!url
.isValid()) {
1899 const QString
location(url
.toDisplayString(QUrl::PreferLocalFile
));
1900 if (location
.isEmpty()) {
1901 Q_EMIT
errorMessage(i18nc("@info:status", "The location is empty."));
1903 Q_EMIT
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1909 m_model
->refreshDirectory(url
);
1911 m_model
->loadDirectory(url
);
1915 void DolphinView::applyViewProperties()
1917 const ViewProperties
props(viewPropertiesUrl());
1918 applyViewProperties(props
);
1921 void DolphinView::applyViewProperties(const ViewProperties
& props
)
1923 m_view
->beginTransaction();
1925 const Mode mode
= props
.viewMode();
1926 if (m_mode
!= mode
) {
1927 const Mode previousMode
= m_mode
;
1930 // Changing the mode might result in changing
1931 // the zoom level. Remember the old zoom level so
1932 // that zoomLevelChanged() can get emitted.
1933 const int oldZoomLevel
= m_view
->zoomLevel();
1936 Q_EMIT
modeChanged(m_mode
, previousMode
);
1938 if (m_view
->zoomLevel() != oldZoomLevel
) {
1939 Q_EMIT
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1943 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1944 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1945 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1946 Q_EMIT
hiddenFilesShownChanged(hiddenFilesShown
);
1949 const bool groupedSorting
= props
.groupedSorting();
1950 if (groupedSorting
!= m_model
->groupedSorting()) {
1951 m_model
->setGroupedSorting(groupedSorting
);
1952 Q_EMIT
groupedSortingChanged(groupedSorting
);
1955 const QByteArray sortRole
= props
.sortRole();
1956 if (sortRole
!= m_model
->sortRole()) {
1957 m_model
->setSortRole(sortRole
);
1958 Q_EMIT
sortRoleChanged(sortRole
);
1961 const Qt::SortOrder sortOrder
= props
.sortOrder();
1962 if (sortOrder
!= m_model
->sortOrder()) {
1963 m_model
->setSortOrder(sortOrder
);
1964 Q_EMIT
sortOrderChanged(sortOrder
);
1967 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1968 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
1969 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
1970 Q_EMIT
sortFoldersFirstChanged(sortFoldersFirst
);
1973 const bool sortHiddenLast
= props
.sortHiddenLast();
1974 if (sortHiddenLast
!= m_model
->sortHiddenLast()) {
1975 m_model
->setSortHiddenLast(sortHiddenLast
);
1976 Q_EMIT
sortHiddenLastChanged(sortHiddenLast
);
1979 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
1980 if (visibleRoles
!= m_visibleRoles
) {
1981 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1982 m_visibleRoles
= visibleRoles
;
1983 m_view
->setVisibleRoles(visibleRoles
);
1984 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1987 const bool previewsShown
= props
.previewsShown();
1988 if (previewsShown
!= m_view
->previewsShown()) {
1989 const int oldZoomLevel
= zoomLevel();
1991 m_view
->setPreviewsShown(previewsShown
);
1992 Q_EMIT
previewsShownChanged(previewsShown
);
1994 // Changing the preview-state might result in a changed zoom-level
1995 if (oldZoomLevel
!= zoomLevel()) {
1996 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
2000 KItemListView
* itemListView
= m_container
->controller()->view();
2001 if (itemListView
->isHeaderVisible()) {
2002 KItemListHeader
* header
= itemListView
->header();
2003 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
2004 const int rolesCount
= m_visibleRoles
.count();
2005 if (headerColumnWidths
.count() == rolesCount
) {
2006 header
->setAutomaticColumnResizing(false);
2008 QHash
<QByteArray
, qreal
> columnWidths
;
2009 for (int i
= 0; i
< rolesCount
; ++i
) {
2010 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
2012 header
->setColumnWidths(columnWidths
);
2014 header
->setAutomaticColumnResizing(true);
2016 header
->setSidePadding(DetailsModeSettings::sidePadding());
2019 m_view
->endTransaction();
2022 void DolphinView::applyModeToView()
2025 case IconsView
: m_view
->setItemLayout(KFileItemListView::IconsLayout
); break;
2026 case CompactView
: m_view
->setItemLayout(KFileItemListView::CompactLayout
); break;
2027 case DetailsView
: m_view
->setItemLayout(KFileItemListView::DetailsLayout
); break;
2028 default: Q_ASSERT(false); break;
2032 void DolphinView::pasteToUrl(const QUrl
& url
)
2034 KIO::PasteJob
*job
= KIO::paste(QApplication::clipboard()->mimeData(), url
);
2035 KJobWidgets::setWindow(job
, this);
2036 m_clearSelectionBeforeSelectingNewItems
= true;
2037 m_markFirstNewlySelectedItemAsCurrent
= true;
2038 connect(job
, &KIO::PasteJob::itemCreated
, this, &DolphinView::slotItemCreated
);
2039 connect(job
, &KIO::PasteJob::result
, this, &DolphinView::slotJobResult
);
2042 QList
<QUrl
> DolphinView::simplifiedSelectedUrls() const
2046 const KFileItemList items
= selectedItems();
2047 urls
.reserve(items
.count());
2048 for (const KFileItem
& item
: items
) {
2049 urls
.append(item
.url());
2052 if (itemsExpandable()) {
2053 // TODO: Check if we still need KDirModel for this in KDE 5.0
2054 urls
= KDirModel::simplifiedUrlList(urls
);
2060 QMimeData
* DolphinView::selectionMimeData() const
2062 const KItemListSelectionManager
* selectionManager
= m_container
->controller()->selectionManager();
2063 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
2065 return m_model
->createMimeData(selectedIndexes
);
2068 void DolphinView::updateWritableState()
2070 const bool wasFolderWritable
= m_isFolderWritable
;
2071 m_isFolderWritable
= false;
2073 KFileItem item
= m_model
->rootItem();
2074 if (item
.isNull()) {
2075 // Try to find out if the URL is writable even if the "root item" is
2076 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
2077 item
= KFileItem(url());
2078 item
.setDelayedMimeTypes(true);
2081 KFileItemListProperties
capabilities(KFileItemList() << item
);
2082 m_isFolderWritable
= capabilities
.supportsWriting();
2084 if (m_isFolderWritable
!= wasFolderWritable
) {
2085 Q_EMIT
writeStateChanged(m_isFolderWritable
);
2089 QUrl
DolphinView::viewPropertiesUrl() const
2091 if (m_viewPropertiesContext
.isEmpty()) {
2096 url
.setScheme(m_url
.scheme());
2097 url
.setPath(m_viewPropertiesContext
);
2101 void DolphinView::slotRenameDialogRenamingFinished(const QList
<QUrl
>& urls
)
2103 forceUrlsSelection(urls
.first(), urls
);
2106 void DolphinView::forceUrlsSelection(const QUrl
& current
, const QList
<QUrl
>& selected
)
2109 m_clearSelectionBeforeSelectingNewItems
= true;
2110 markUrlAsCurrent(current
);
2111 markUrlsAsSelected(selected
);
2114 void DolphinView::copyPathToClipboard()
2116 const KFileItemList list
= selectedItems();
2117 if (list
.isEmpty()) {
2120 const KFileItem
& item
= list
.at(0);
2121 QString path
= item
.localPath();
2122 if (path
.isEmpty()) {
2123 path
= item
.url().toDisplayString();
2125 QClipboard
* clipboard
= QApplication::clipboard();
2126 if (clipboard
== nullptr) {
2129 clipboard
->setText(path
);
2132 void DolphinView::slotIncreaseZoom()
2134 setZoomLevel(zoomLevel() + 1);
2137 void DolphinView::slotDecreaseZoom()
2139 setZoomLevel(zoomLevel() - 1);
2142 void DolphinView::slotSwipeUp()
2144 Q_EMIT
goUpRequested();
2147 void DolphinView::showLoadingPlaceholder()
2149 m_placeholderLabel
->setText(i18n("Loading..."));
2150 m_placeholderLabel
->setVisible(true);
2153 void DolphinView::updatePlaceholderLabel()
2155 m_showLoadingPlaceholderTimer
->stop();
2156 if (itemsCount() > 0) {
2157 m_placeholderLabel
->setVisible(false);
2161 if (m_loadingState
== LoadingState::Loading
) {
2162 m_placeholderLabel
->setVisible(false);
2163 m_showLoadingPlaceholderTimer
->start();
2167 if (m_loadingState
== LoadingState::Canceled
) {
2168 m_placeholderLabel
->setText(i18n("Loading canceled"));
2169 } else if (!nameFilter().isEmpty()) {
2170 m_placeholderLabel
->setText(i18n("No items matching the filter"));
2171 } else if (m_url
.scheme() == QLatin1String("baloosearch") || m_url
.scheme() == QLatin1String("filenamesearch")) {
2172 m_placeholderLabel
->setText(i18n("No items matching the search"));
2173 } else if (m_url
.scheme() == QLatin1String("trash") && m_url
.path() == QLatin1String("/")) {
2174 m_placeholderLabel
->setText(i18n("Trash is empty"));
2175 } else if (m_url
.scheme() == QLatin1String("tags")) {
2176 if (m_url
.path() == QLatin1Char('/')) {
2177 m_placeholderLabel
->setText(i18n("No tags"));
2179 const QString tagName
= m_url
.path().mid(1); // Remove leading /
2180 m_placeholderLabel
->setText(i18n("No files tagged with \"%1\"", tagName
));
2183 } else if (m_url
.scheme() == QLatin1String("recentlyused")) {
2184 m_placeholderLabel
->setText(i18n("No recently used items"));
2185 } else if (m_url
.scheme() == QLatin1String("smb")) {
2186 m_placeholderLabel
->setText(i18n("No shared folders found"));
2187 } else if (m_url
.scheme() == QLatin1String("network")) {
2188 m_placeholderLabel
->setText(i18n("No relevant network resources found"));
2189 } else if (m_url
.scheme() == QLatin1String("mtp") && m_url
.path() == QLatin1String("/")) {
2190 m_placeholderLabel
->setText(i18n("No MTP-compatible devices found"));
2191 } else if (m_url
.scheme() == QLatin1String("bluetooth")) {
2192 m_placeholderLabel
->setText(i18n("No Bluetooth devices found"));
2194 m_placeholderLabel
->setText(i18n("Folder is empty"));
2197 m_placeholderLabel
->setVisible(true);
2200 void DolphinView::tryShowNameToolTip(QHelpEvent
* event
)
2202 if (!GeneralSettings::showToolTips() && m_mode
== DolphinView::IconsView
) {
2203 const std::optional
<int> index
= m_view
->itemAt(event
->pos());
2205 if (!index
.has_value()) {
2209 // Check whether the filename has been elided
2210 const bool isElided
= m_view
->isElided(index
.value());
2213 const KFileItem item
= m_model
->fileItem(index
.value());
2214 const QString text
= item
.text();
2215 const QPoint pos
= mapToGlobal(event
->pos());
2216 QToolTip::showText(pos
, text
);