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_detailsmodesettings.h"
11 #include "dolphin_generalsettings.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 "selectionmode/singleclickselectionproxystyle.h"
23 #include "settings/viewmodes/viewmodesettings.h"
24 #include "versioncontrol/versioncontrolobserver.h"
25 #include "viewproperties.h"
26 #include "views/tooltips/tooltipmanager.h"
27 #include "zoomlevelinfo.h"
30 #include <Baloo/IndexerConfig>
32 #include <KColorScheme>
33 #include <KDesktopFile>
35 #include <KFileItemListProperties>
37 #include <KIO/CopyJob>
38 #include <KIO/DeleteJob>
39 #include <KIO/DropJob>
40 #include <KIO/JobUiDelegate>
42 #include <KIO/PasteJob>
43 #include <KIO/RenameFileDialog>
44 #include <KJobWidgets>
45 #include <KLocalizedString>
46 #include <KMessageBox>
47 #include <KProtocolManager>
48 #include <KUrlMimeData>
50 #include <kwidgetsaddons_version.h>
52 #include <kio_version.h>
53 #if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0)
54 #include <KIO/DeleteOrTrashJob>
57 #include <QAbstractItemView>
58 #include <QActionGroup>
59 #include <QApplication>
62 #include <QGraphicsOpacityEffect>
63 #include <QGraphicsSceneDragDropEvent>
66 #include <QMimeDatabase>
67 #include <QPixmapCache>
72 #include <QVBoxLayout>
74 DolphinView::DolphinView(const QUrl
&url
, QWidget
*parent
)
77 , m_tabsForFiles(false)
78 , m_assureVisibleCurrentIndex(false)
79 , m_isFolderWritable(true)
82 , m_viewPropertiesContext()
83 , m_mode(DolphinView::IconsView
)
85 , m_topLayout(nullptr)
88 , m_container(nullptr)
89 , m_toolTipManager(nullptr)
90 , m_selectionChangedTimer(nullptr)
92 , m_scrollToCurrentItem(false)
93 , m_restoredContentsPosition()
95 , m_clearSelectionBeforeSelectingNewItems(false)
96 , m_markFirstNewlySelectedItemAsCurrent(false)
97 , m_versionControlObserver(nullptr)
98 , m_twoClicksRenamingTimer(nullptr)
99 , m_placeholderLabel(nullptr)
100 , m_showLoadingPlaceholderTimer(nullptr)
102 m_topLayout
= new QVBoxLayout(this);
103 m_topLayout
->setSpacing(0);
104 m_topLayout
->setContentsMargins(0, 0, 0, 0);
106 // When a new item has been created by the "Create New..." menu, the item should
107 // get selected and it must be assured that the item will get visible. As the
108 // creation is done asynchronously, several signals must be checked:
109 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::itemCreated
, this, &DolphinView::observeCreatedItem
);
111 m_selectionChangedTimer
= new QTimer(this);
112 m_selectionChangedTimer
->setSingleShot(true);
113 m_selectionChangedTimer
->setInterval(300);
114 connect(m_selectionChangedTimer
, &QTimer::timeout
, this, &DolphinView::emitSelectionChangedSignal
);
116 m_model
= new KFileItemModel(this);
117 m_view
= new DolphinItemListView();
118 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting
);
119 m_view
->setVisibleRoles({"text"});
122 KItemListController
*controller
= new KItemListController(m_model
, m_view
, this);
123 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
124 controller
->setAutoActivationDelay(delay
);
126 // The EnlargeSmallPreviews setting can only be changed after the model
127 // has been set in the view by KItemListController.
128 m_view
->setEnlargeSmallPreviews(GeneralSettings::enlargeSmallPreviews());
130 m_container
= new KItemListContainer(controller
, this);
131 m_container
->installEventFilter(this);
132 setFocusProxy(m_container
);
133 connect(m_container
->horizontalScrollBar(), &QScrollBar::valueChanged
, this, [=] {
136 connect(m_container
->verticalScrollBar(), &QScrollBar::valueChanged
, this, [=] {
140 m_showLoadingPlaceholderTimer
= new QTimer(this);
141 m_showLoadingPlaceholderTimer
->setInterval(500);
142 m_showLoadingPlaceholderTimer
->setSingleShot(true);
143 connect(m_showLoadingPlaceholderTimer
, &QTimer::timeout
, this, &DolphinView::showLoadingPlaceholder
);
145 // Show some placeholder text for empty folders
146 // This is made using a heavily-modified QLabel rather than a KTitleWidget
147 // because KTitleWidget can't be told to turn off mouse-selectable text
148 m_placeholderLabel
= new QLabel(this);
149 QFont placeholderLabelFont
;
150 // To match the size of a level 2 Heading/KTitleWidget
151 placeholderLabelFont
.setPointSize(qRound(placeholderLabelFont
.pointSize() * 1.3));
152 m_placeholderLabel
->setFont(placeholderLabelFont
);
153 m_placeholderLabel
->setTextInteractionFlags(Qt::NoTextInteraction
);
154 m_placeholderLabel
->setWordWrap(true);
155 m_placeholderLabel
->setAlignment(Qt::AlignCenter
);
156 // Match opacity of QML placeholder label component
157 auto *effect
= new QGraphicsOpacityEffect(m_placeholderLabel
);
158 effect
->setOpacity(0.5);
159 m_placeholderLabel
->setGraphicsEffect(effect
);
160 // Set initial text and visibility
161 updatePlaceholderLabel();
163 auto *centeringLayout
= new QVBoxLayout(m_container
);
164 centeringLayout
->addWidget(m_placeholderLabel
);
165 centeringLayout
->setAlignment(m_placeholderLabel
, Qt::AlignCenter
);
166 m_placeholderLabel
->setContextMenuPolicy(Qt::CustomContextMenu
);
167 connect(m_placeholderLabel
, &QWidget::customContextMenuRequested
, this, [this](const QPoint
&pos
) {
168 slotViewContextMenuRequested(m_placeholderLabel
->mapToGlobal(pos
));
171 controller
->setSelectionBehavior(KItemListController::MultiSelection
);
172 connect(controller
, &KItemListController::itemActivated
, this, &DolphinView::slotItemActivated
);
173 connect(controller
, &KItemListController::itemsActivated
, this, &DolphinView::slotItemsActivated
);
174 connect(controller
, &KItemListController::itemMiddleClicked
, this, &DolphinView::slotItemMiddleClicked
);
175 connect(controller
, &KItemListController::itemContextMenuRequested
, this, &DolphinView::slotItemContextMenuRequested
);
176 connect(controller
, &KItemListController::viewContextMenuRequested
, this, &DolphinView::slotViewContextMenuRequested
);
177 connect(controller
, &KItemListController::headerContextMenuRequested
, this, &DolphinView::slotHeaderContextMenuRequested
);
178 connect(controller
, &KItemListController::mouseButtonPressed
, this, &DolphinView::slotMouseButtonPressed
);
179 connect(controller
, &KItemListController::itemHovered
, this, &DolphinView::slotItemHovered
);
180 connect(controller
, &KItemListController::itemUnhovered
, this, &DolphinView::slotItemUnhovered
);
181 connect(controller
, &KItemListController::itemDropEvent
, this, &DolphinView::slotItemDropEvent
);
182 connect(controller
, &KItemListController::escapePressed
, this, &DolphinView::stopLoading
);
183 connect(controller
, &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
184 connect(controller
, &KItemListController::selectedItemTextPressed
, this, &DolphinView::slotSelectedItemTextPressed
);
185 connect(controller
, &KItemListController::increaseZoom
, this, &DolphinView::slotIncreaseZoom
);
186 connect(controller
, &KItemListController::decreaseZoom
, this, &DolphinView::slotDecreaseZoom
);
187 connect(controller
, &KItemListController::swipeUp
, this, &DolphinView::slotSwipeUp
);
188 connect(controller
, &KItemListController::selectionModeChangeRequested
, this, &DolphinView::selectionModeChangeRequested
);
190 connect(m_model
, &KFileItemModel::directoryLoadingStarted
, this, &DolphinView::slotDirectoryLoadingStarted
);
191 connect(m_model
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
192 connect(m_model
, &KFileItemModel::directoryLoadingCanceled
, this, &DolphinView::slotDirectoryLoadingCanceled
);
193 connect(m_model
, &KFileItemModel::directoryLoadingProgress
, this, &DolphinView::directoryLoadingProgress
);
194 connect(m_model
, &KFileItemModel::directorySortingProgress
, this, &DolphinView::directorySortingProgress
);
195 connect(m_model
, &KFileItemModel::itemsChanged
, this, &DolphinView::slotItemsChanged
);
196 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &DolphinView::itemCountChanged
);
197 connect(m_model
, &KFileItemModel::itemsInserted
, this, &DolphinView::itemCountChanged
);
198 connect(m_model
, &KFileItemModel::infoMessage
, this, &DolphinView::infoMessage
);
199 connect(m_model
, &KFileItemModel::errorMessage
, this, &DolphinView::errorMessage
);
200 connect(m_model
, &KFileItemModel::directoryRedirection
, this, &DolphinView::slotDirectoryRedirection
);
201 connect(m_model
, &KFileItemModel::urlIsFileError
, this, &DolphinView::urlIsFileError
);
202 connect(m_model
, &KFileItemModel::fileItemsChanged
, this, &DolphinView::fileItemsChanged
);
203 connect(m_model
, &KFileItemModel::currentDirectoryRemoved
, this, &DolphinView::currentDirectoryRemoved
);
205 connect(this, &DolphinView::itemCountChanged
, this, &DolphinView::updatePlaceholderLabel
);
207 m_view
->installEventFilter(this);
208 connect(m_view
, &DolphinItemListView::sortOrderChanged
, this, &DolphinView::slotSortOrderChangedByHeader
);
209 connect(m_view
, &DolphinItemListView::sortRoleChanged
, this, &DolphinView::slotSortRoleChangedByHeader
);
210 connect(m_view
, &DolphinItemListView::visibleRolesChanged
, this, &DolphinView::slotVisibleRolesChangedByHeader
);
211 connect(m_view
, &DolphinItemListView::roleEditingCanceled
, this, &DolphinView::slotRoleEditingCanceled
);
212 connect(m_view
->header(), &KItemListHeader::columnWidthChangeFinished
, this, &DolphinView::slotHeaderColumnWidthChangeFinished
);
213 connect(m_view
->header(), &KItemListHeader::sidePaddingChanged
, this, &DolphinView::slotSidePaddingWidthChanged
);
215 KItemListSelectionManager
*selectionManager
= controller
->selectionManager();
216 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
, this, &DolphinView::slotSelectionChanged
);
219 m_toolTipManager
= new ToolTipManager(this);
220 connect(m_toolTipManager
, &ToolTipManager::urlActivated
, this, &DolphinView::urlActivated
);
223 m_versionControlObserver
= new VersionControlObserver(this);
224 m_versionControlObserver
->setView(this);
225 m_versionControlObserver
->setModel(m_model
);
226 connect(m_versionControlObserver
, &VersionControlObserver::infoMessage
, this, &DolphinView::infoMessage
);
227 connect(m_versionControlObserver
, &VersionControlObserver::errorMessage
, this, &DolphinView::errorMessage
);
228 connect(m_versionControlObserver
, &VersionControlObserver::operationCompletedMessage
, this, &DolphinView::operationCompletedMessage
);
230 m_twoClicksRenamingTimer
= new QTimer(this);
231 m_twoClicksRenamingTimer
->setSingleShot(true);
232 connect(m_twoClicksRenamingTimer
, &QTimer::timeout
, this, &DolphinView::slotTwoClicksRenamingTimerTimeout
);
234 applyViewProperties();
235 m_topLayout
->addWidget(m_container
);
240 DolphinView::~DolphinView()
242 disconnect(m_container
->controller(), &KItemListController::modelChanged
, this, &DolphinView::slotModelChanged
);
245 QUrl
DolphinView::url() const
250 void DolphinView::setActive(bool active
)
252 if (active
== m_active
) {
261 m_container
->setFocus();
263 Q_EMIT
writeStateChanged(m_isFolderWritable
);
267 bool DolphinView::isActive() const
272 void DolphinView::setViewMode(Mode mode
)
274 if (mode
!= m_mode
) {
275 ViewProperties
props(viewPropertiesUrl());
276 props
.setViewMode(mode
);
278 // We pass the new ViewProperties to applyViewProperties, rather than
279 // storing them on disk and letting applyViewProperties() read them
280 // from there, to prevent that changing the view mode fails if the
281 // .directory file is not writable (see bug 318534).
282 applyViewProperties(props
);
286 DolphinView::Mode
DolphinView::viewMode() const
291 void DolphinView::setSelectionModeEnabled(const bool enabled
)
294 m_proxyStyle
= std::make_unique
<SelectionMode::SingleClickSelectionProxyStyle
>();
295 setStyle(m_proxyStyle
.get());
296 m_view
->setStyle(m_proxyStyle
.get());
297 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False
);
299 setStyle(QApplication::style());
300 m_view
->setStyle(QApplication::style());
301 m_view
->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting
);
303 m_container
->controller()->setSelectionModeEnabled(enabled
);
306 bool DolphinView::selectionMode() const
308 return m_container
->controller()->selectionMode();
311 void DolphinView::setPreviewsShown(bool show
)
313 if (previewsShown() == show
) {
317 ViewProperties
props(viewPropertiesUrl());
318 props
.setPreviewsShown(show
);
320 const int oldZoomLevel
= m_view
->zoomLevel();
321 m_view
->setPreviewsShown(show
);
322 Q_EMIT
previewsShownChanged(show
);
324 const int newZoomLevel
= m_view
->zoomLevel();
325 if (newZoomLevel
!= oldZoomLevel
) {
326 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
330 bool DolphinView::previewsShown() const
332 return m_view
->previewsShown();
335 void DolphinView::setHiddenFilesShown(bool show
)
337 if (m_model
->showHiddenFiles() == show
) {
341 const KFileItemList itemList
= selectedItems();
342 m_selectedUrls
.clear();
343 m_selectedUrls
= itemList
.urlList();
345 ViewProperties
props(viewPropertiesUrl());
346 props
.setHiddenFilesShown(show
);
348 m_model
->setShowHiddenFiles(show
);
349 Q_EMIT
hiddenFilesShownChanged(show
);
352 bool DolphinView::hiddenFilesShown() const
354 return m_model
->showHiddenFiles();
357 void DolphinView::setGroupedSorting(bool grouped
)
359 if (grouped
== groupedSorting()) {
363 ViewProperties
props(viewPropertiesUrl());
364 props
.setGroupedSorting(grouped
);
367 m_container
->controller()->model()->setGroupedSorting(grouped
);
369 Q_EMIT
groupedSortingChanged(grouped
);
372 bool DolphinView::groupedSorting() const
374 return m_model
->groupedSorting();
377 KFileItemList
DolphinView::items() const
380 const int itemCount
= m_model
->count();
381 list
.reserve(itemCount
);
383 for (int i
= 0; i
< itemCount
; ++i
) {
384 list
.append(m_model
->fileItem(i
));
390 int DolphinView::itemsCount() const
392 return m_model
->count();
395 KFileItemList
DolphinView::selectedItems() const
397 const KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
399 KFileItemList selectedItems
;
400 const auto items
= selectionManager
->selectedItems();
401 selectedItems
.reserve(items
.count());
402 for (int index
: items
) {
403 selectedItems
.append(m_model
->fileItem(index
));
405 return selectedItems
;
408 int DolphinView::selectedItemsCount() const
410 const KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
411 return selectionManager
->selectedItems().count();
414 void DolphinView::markUrlsAsSelected(const QList
<QUrl
> &urls
)
416 m_selectedUrls
= urls
;
419 void DolphinView::markUrlAsCurrent(const QUrl
&url
)
421 m_currentItemUrl
= url
;
422 m_scrollToCurrentItem
= true;
425 void DolphinView::selectItems(const QRegularExpression
®exp
, bool enabled
)
427 const KItemListSelectionManager::SelectionMode mode
= enabled
? KItemListSelectionManager::Select
: KItemListSelectionManager::Deselect
;
428 KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
430 for (int index
= 0; index
< m_model
->count(); index
++) {
431 const KFileItem item
= m_model
->fileItem(index
);
432 if (regexp
.match(item
.text()).hasMatch()) {
433 // An alternative approach would be to store the matching items in a KItemSet and
434 // select them in one go after the loop, but we'd need a new function
435 // KItemListSelectionManager::setSelected(KItemSet, SelectionMode mode)
437 selectionManager
->setSelected(index
, 1, mode
);
442 void DolphinView::setZoomLevel(int level
)
444 const int oldZoomLevel
= zoomLevel();
445 m_view
->setZoomLevel(level
);
446 if (zoomLevel() != oldZoomLevel
) {
448 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
452 int DolphinView::zoomLevel() const
454 return m_view
->zoomLevel();
457 void DolphinView::setSortRole(const QByteArray
&role
)
459 if (role
!= sortRole()) {
460 updateSortRole(role
);
464 QByteArray
DolphinView::sortRole() const
466 const KItemModelBase
*model
= m_container
->controller()->model();
467 return model
->sortRole();
470 void DolphinView::setSortOrder(Qt::SortOrder order
)
472 if (sortOrder() != order
) {
473 updateSortOrder(order
);
477 Qt::SortOrder
DolphinView::sortOrder() const
479 return m_model
->sortOrder();
482 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
484 if (sortFoldersFirst() != foldersFirst
) {
485 updateSortFoldersFirst(foldersFirst
);
489 bool DolphinView::sortFoldersFirst() const
491 return m_model
->sortDirectoriesFirst();
494 void DolphinView::setSortHiddenLast(bool hiddenLast
)
496 if (sortHiddenLast() != hiddenLast
) {
497 updateSortHiddenLast(hiddenLast
);
501 bool DolphinView::sortHiddenLast() const
503 return m_model
->sortHiddenLast();
506 void DolphinView::setVisibleRoles(const QList
<QByteArray
> &roles
)
508 const QList
<QByteArray
> previousRoles
= roles
;
510 ViewProperties
props(viewPropertiesUrl());
511 props
.setVisibleRoles(roles
);
513 m_visibleRoles
= roles
;
514 m_view
->setVisibleRoles(roles
);
516 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousRoles
);
519 QList
<QByteArray
> DolphinView::visibleRoles() const
521 return m_visibleRoles
;
524 void DolphinView::reload()
526 QByteArray viewState
;
527 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
528 saveState(saveStream
);
531 loadDirectory(url(), true);
533 QDataStream
restoreStream(viewState
);
534 restoreState(restoreStream
);
537 void DolphinView::readSettings()
539 const int oldZoomLevel
= m_view
->zoomLevel();
541 GeneralSettings::self()->load();
542 m_view
->readSettings();
543 applyViewProperties();
545 const int delay
= GeneralSettings::autoExpandFolders() ? 750 : -1;
546 m_container
->controller()->setAutoActivationDelay(delay
);
548 const int newZoomLevel
= m_view
->zoomLevel();
549 if (newZoomLevel
!= oldZoomLevel
) {
550 Q_EMIT
zoomLevelChanged(newZoomLevel
, oldZoomLevel
);
554 void DolphinView::writeSettings()
556 GeneralSettings::self()->save();
557 m_view
->writeSettings();
560 void DolphinView::setNameFilter(const QString
&nameFilter
)
562 m_model
->setNameFilter(nameFilter
);
565 QString
DolphinView::nameFilter() const
567 return m_model
->nameFilter();
570 void DolphinView::setMimeTypeFilters(const QStringList
&filters
)
572 return m_model
->setMimeTypeFilters(filters
);
575 QStringList
DolphinView::mimeTypeFilters() const
577 return m_model
->mimeTypeFilters();
580 void DolphinView::requestStatusBarText()
582 if (m_statJobForStatusBarText
) {
583 // Kill the pending request.
584 m_statJobForStatusBarText
->kill();
587 if (m_container
->controller()->selectionManager()->hasSelection()) {
590 KIO::filesize_t totalFileSize
= 0;
592 // Give a summary of the status of the selected files
593 const KFileItemList list
= selectedItems();
594 for (const KFileItem
&item
: list
) {
599 totalFileSize
+= item
.size();
603 if (folderCount
+ fileCount
== 1) {
604 // If only one item is selected, show info about it
605 Q_EMIT
statusBarTextChanged(list
.first().getStatusBarInfo());
607 // At least 2 items are selected
608 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, HasSelection
);
610 } else { // has no selection
611 if (!m_model
->rootItem().url().isValid()) {
615 m_statJobForStatusBarText
= KIO::statDetails(m_model
->rootItem().url(), KIO::StatJob::SourceSide
, KIO::StatRecursiveSize
, KIO::HideProgressInfo
);
616 connect(m_statJobForStatusBarText
, &KJob::result
, this, &DolphinView::slotStatJobResult
);
617 m_statJobForStatusBarText
->start();
621 void DolphinView::emitStatusBarText(const int folderCount
, const int fileCount
, KIO::filesize_t totalFileSize
, const Selection selection
)
627 if (selection
== HasSelection
) {
628 // At least 2 items are selected because the case of 1 selected item is handled in
629 // DolphinView::requestStatusBarText().
630 foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
631 filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
633 foldersText
= i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount
);
634 filesText
= i18ncp("@info:status", "1 File", "%1 Files", fileCount
);
637 if (fileCount
> 0 && folderCount
> 0) {
638 summary
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)", foldersText
, filesText
, KFormat().formatByteSize(totalFileSize
));
639 } else if (fileCount
> 0) {
640 summary
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KFormat().formatByteSize(totalFileSize
));
641 } else if (folderCount
> 0) {
642 summary
= foldersText
;
644 summary
= i18nc("@info:status", "0 Folders, 0 Files");
646 Q_EMIT
statusBarTextChanged(summary
);
649 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
&items
) const
651 QList
<QAction
*> actions
;
653 if (items
.isEmpty()) {
654 const KFileItem item
= m_model
->rootItem();
655 if (!item
.isNull()) {
656 actions
= m_versionControlObserver
->actions(KFileItemList() << item
);
659 actions
= m_versionControlObserver
->actions(items
);
665 void DolphinView::setUrl(const QUrl
&url
)
677 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
, this, &DolphinView::slotRoleEditingFinished
);
679 // It is important to clear the items from the model before
680 // applying the view properties, otherwise expensive operations
681 // might be done on the existing items although they get cleared
682 // anyhow afterwards by loadDirectory().
684 applyViewProperties();
687 Q_EMIT
urlChanged(url
);
690 void DolphinView::selectAll()
692 KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
693 selectionManager
->setSelected(0, m_model
->count());
696 void DolphinView::invertSelection()
698 KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
699 selectionManager
->setSelected(0, m_model
->count(), KItemListSelectionManager::Toggle
);
702 void DolphinView::clearSelection()
704 m_selectedUrls
.clear();
705 m_container
->controller()->selectionManager()->clearSelection();
708 void DolphinView::renameSelectedItems()
710 const KFileItemList items
= selectedItems();
711 if (items
.isEmpty()) {
715 if (items
.count() == 1 && GeneralSettings::renameInline()) {
716 const int index
= m_model
->index(items
.first());
718 QMetaObject::Connection
*const connection
= new QMetaObject::Connection
;
719 *connection
= connect(m_view
, &KItemListView::scrollingStopped
, this, [=]() {
720 QObject::disconnect(*connection
);
723 m_view
->editRole(index
, "text");
727 connect(m_view
, &DolphinItemListView::roleEditingFinished
, this, &DolphinView::slotRoleEditingFinished
);
729 m_view
->scrollToItem(index
);
732 KIO::RenameFileDialog
*dialog
= new KIO::RenameFileDialog(items
, this);
733 connect(dialog
, &KIO::RenameFileDialog::renamingFinished
, this, &DolphinView::slotRenameDialogRenamingFinished
);
738 // Assure that the current index remains visible when KFileItemModel
739 // will notify the view about changed items (which might result in
740 // a changed sorting).
741 m_assureVisibleCurrentIndex
= true;
744 void DolphinView::trashSelectedItems()
746 const QList
<QUrl
> list
= simplifiedSelectedUrls();
748 #if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0)
749 using Iface
= KIO::AskUserActionInterface
;
750 auto *trashJob
= new KIO::DeleteOrTrashJob(list
, Iface::Trash
, Iface::DefaultConfirmation
, this);
751 connect(trashJob
, &KJob::result
, this, &DolphinView::slotTrashFileFinished
);
754 KIO::JobUiDelegate uiDelegate
;
755 uiDelegate
.setWindow(window());
756 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Trash
, KIO::JobUiDelegate::DefaultConfirmation
)) {
757 KIO::Job
*job
= KIO::trash(list
);
758 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash
, list
, QUrl(QStringLiteral("trash:/")), job
);
759 KJobWidgets::setWindow(job
, this);
760 connect(job
, &KIO::Job::result
, this, &DolphinView::slotTrashFileFinished
);
765 void DolphinView::deleteSelectedItems()
767 const QList
<QUrl
> list
= simplifiedSelectedUrls();
769 #if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0)
770 using Iface
= KIO::AskUserActionInterface
;
771 auto *trashJob
= new KIO::DeleteOrTrashJob(list
, Iface::Delete
, Iface::DefaultConfirmation
, this);
772 connect(trashJob
, &KJob::result
, this, &DolphinView::slotTrashFileFinished
);
775 KIO::JobUiDelegate uiDelegate
;
776 uiDelegate
.setWindow(window());
777 if (uiDelegate
.askDeleteConfirmation(list
, KIO::JobUiDelegate::Delete
, KIO::JobUiDelegate::DefaultConfirmation
)) {
778 KIO::Job
*job
= KIO::del(list
);
779 KJobWidgets::setWindow(job
, this);
780 connect(job
, &KIO::Job::result
, this, &DolphinView::slotDeleteFileFinished
);
785 void DolphinView::cutSelectedItemsToClipboard()
787 QMimeData
*mimeData
= selectionMimeData();
788 KIO::setClipboardDataCut(mimeData
, true);
789 KUrlMimeData::exportUrlsToPortal(mimeData
);
790 QApplication::clipboard()->setMimeData(mimeData
);
793 void DolphinView::copySelectedItemsToClipboard()
795 QMimeData
*mimeData
= selectionMimeData();
796 KUrlMimeData::exportUrlsToPortal(mimeData
);
797 QApplication::clipboard()->setMimeData(mimeData
);
800 void DolphinView::copySelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
802 KIO::CopyJob
*job
= KIO::copy(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
803 KJobWidgets::setWindow(job
, this);
805 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
806 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
807 KIO::FileUndoManager::self()->recordCopyJob(job
);
810 void DolphinView::moveSelectedItems(const KFileItemList
&selection
, const QUrl
&destinationUrl
)
812 KIO::CopyJob
*job
= KIO::move(selection
.urlList(), destinationUrl
, KIO::DefaultFlags
);
813 KJobWidgets::setWindow(job
, this);
815 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
816 connect(job
, &KIO::CopyJob::copyingDone
, this, &DolphinView::slotCopyingDone
);
817 KIO::FileUndoManager::self()->recordCopyJob(job
);
820 void DolphinView::paste()
825 void DolphinView::pasteIntoFolder()
827 const KFileItemList items
= selectedItems();
828 if ((items
.count() == 1) && items
.first().isDir()) {
829 pasteToUrl(items
.first().url());
833 void DolphinView::duplicateSelectedItems()
835 const KFileItemList itemList
= selectedItems();
836 if (itemList
.isEmpty()) {
840 const QMimeDatabase db
;
842 // Duplicate all selected items and append "copy" to the end of the file name
843 // but before the filename extension, if present
844 QList
<QUrl
> newSelection
;
845 for (const auto &item
: itemList
) {
846 const QUrl originalURL
= item
.url();
847 const QString originalDirectoryPath
= originalURL
.adjusted(QUrl::RemoveFilename
).path();
848 const QString originalFileName
= item
.name();
850 QString extension
= db
.suffixForFileName(originalFileName
);
852 QUrl duplicateURL
= originalURL
;
854 // No extension; new filename is "<oldfilename> copy"
855 if (extension
.isEmpty()) {
856 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFileName
));
857 // There's an extension; new filename is "<oldfilename> copy.<extension>"
859 // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it
860 extension
= QLatin1String(".") + extension
;
861 const QString originalFilenameWithoutExtension
= originalFileName
.chopped(extension
.size());
862 // Preserve file's original filename extension in case the casing differs
863 // from what QMimeDatabase::suffixForFileName() returned
864 const QString originalExtension
= originalFileName
.right(extension
.size());
865 duplicateURL
.setPath(originalDirectoryPath
+ i18nc("<filename> copy", "%1 copy", originalFilenameWithoutExtension
) + originalExtension
);
868 KIO::CopyJob
*job
= KIO::copyAs(originalURL
, duplicateURL
);
869 KJobWidgets::setWindow(job
, this);
872 newSelection
<< duplicateURL
;
873 KIO::FileUndoManager::self()->recordCopyJob(job
);
877 forceUrlsSelection(newSelection
.first(), newSelection
);
880 void DolphinView::stopLoading()
882 m_model
->cancelDirectoryLoading();
885 void DolphinView::updatePalette()
887 QColor color
= KColorScheme(isActiveWindow() ? QPalette::Active
: QPalette::Inactive
, KColorScheme::View
).background().color();
892 QWidget
*viewport
= m_container
->viewport();
895 palette
.setColor(viewport
->backgroundRole(), color
);
896 viewport
->setPalette(palette
);
902 void DolphinView::abortTwoClicksRenaming()
904 m_twoClicksRenamingItemUrl
.clear();
905 m_twoClicksRenamingTimer
->stop();
908 bool DolphinView::eventFilter(QObject
*watched
, QEvent
*event
)
910 switch (event
->type()) {
911 case QEvent::PaletteChange
:
913 QPixmapCache::clear();
916 case QEvent::WindowActivate
:
917 case QEvent::WindowDeactivate
:
921 case QEvent::KeyPress
:
922 hideToolTip(ToolTipManager::HideBehavior::Instantly
);
923 if (GeneralSettings::useTabForSwitchingSplitView()) {
924 QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
925 if (keyEvent
->key() == Qt::Key_Tab
&& keyEvent
->modifiers() == Qt::NoModifier
) {
926 Q_EMIT
toggleActiveViewRequested();
931 case QEvent::FocusIn
:
932 if (watched
== m_container
) {
937 case QEvent::GraphicsSceneDragEnter
:
938 if (watched
== m_view
) {
940 abortTwoClicksRenaming();
944 case QEvent::GraphicsSceneDragLeave
:
945 if (watched
== m_view
) {
950 case QEvent::GraphicsSceneDrop
:
951 if (watched
== m_view
) {
956 case QEvent::ToolTip
:
957 tryShowNameToolTip(static_cast<QHelpEvent
*>(event
));
963 return QWidget::eventFilter(watched
, event
);
966 void DolphinView::wheelEvent(QWheelEvent
*event
)
968 if (event
->modifiers().testFlag(Qt::ControlModifier
)) {
969 const QPoint numDegrees
= event
->angleDelta() / 8;
970 const QPoint numSteps
= numDegrees
/ 15;
972 setZoomLevel(zoomLevel() + numSteps
.y());
979 void DolphinView::hideEvent(QHideEvent
*event
)
982 QWidget::hideEvent(event
);
985 bool DolphinView::event(QEvent
*event
)
987 if (event
->type() == QEvent::WindowDeactivate
) {
989 * Dolphin leaves file preview tooltips open even when is not visible.
991 * Hide tool-tip when Dolphin loses focus.
994 abortTwoClicksRenaming();
997 return QWidget::event(event
);
1000 void DolphinView::activate()
1005 void DolphinView::slotItemActivated(int index
)
1007 abortTwoClicksRenaming();
1009 const KFileItem item
= m_model
->fileItem(index
);
1010 if (!item
.isNull()) {
1011 Q_EMIT
itemActivated(item
);
1015 void DolphinView::slotItemsActivated(const KItemSet
&indexes
)
1017 Q_ASSERT(indexes
.count() >= 2);
1019 abortTwoClicksRenaming();
1021 const auto modifiers
= QGuiApplication::keyboardModifiers();
1023 if (indexes
.count() > 5) {
1024 QString question
= i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes
.count());
1025 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1026 const int answer
= KMessageBox::warningTwoActions(
1032 KMessageBox::warningYesNo(this,
1036 KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes
.count()), QStringLiteral("document-open")),
1037 KStandardGuiItem::cancel());
1038 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1039 if (answer
!= KMessageBox::PrimaryAction
) {
1041 if (answer
!= KMessageBox::Yes
) {
1047 KFileItemList items
;
1048 items
.reserve(indexes
.count());
1050 for (int index
: indexes
) {
1051 KFileItem item
= m_model
->fileItem(index
);
1052 const QUrl
&url
= openItemAsFolderUrl(item
);
1054 if (!url
.isEmpty()) {
1055 // Open folders in new tabs or in new windows depending on the modifier
1056 // The ctrl+shift behavior is ignored because we are handling multiple items
1057 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1058 if (modifiers
& Qt::ShiftModifier
&& !(modifiers
& Qt::ControlModifier
)) {
1059 Q_EMIT
windowRequested(url
);
1061 Q_EMIT
tabRequested(url
);
1068 if (items
.count() == 1) {
1069 Q_EMIT
itemActivated(items
.first());
1070 } else if (items
.count() > 1) {
1071 Q_EMIT
itemsActivated(items
);
1075 void DolphinView::slotItemMiddleClicked(int index
)
1077 const KFileItem
&item
= m_model
->fileItem(index
);
1078 const QUrl
&url
= openItemAsFolderUrl(item
);
1079 const auto modifiers
= QGuiApplication::keyboardModifiers();
1080 if (!url
.isEmpty()) {
1081 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1082 if (modifiers
& Qt::ShiftModifier
) {
1083 Q_EMIT
activeTabRequested(url
);
1085 Q_EMIT
tabRequested(url
);
1087 } else if (isTabsForFilesEnabled()) {
1088 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
1089 if (modifiers
& Qt::ShiftModifier
) {
1090 Q_EMIT
activeTabRequested(item
.url());
1092 Q_EMIT
tabRequested(item
.url());
1097 void DolphinView::slotItemContextMenuRequested(int index
, const QPointF
&pos
)
1099 // Force emit of a selection changed signal before we request the
1100 // context menu, to update the edit-actions first. (See Bug 294013)
1101 if (m_selectionChangedTimer
->isActive()) {
1102 emitSelectionChangedSignal();
1105 const KFileItem item
= m_model
->fileItem(index
);
1106 Q_EMIT
requestContextMenu(pos
.toPoint(), item
, selectedItems(), url());
1109 void DolphinView::slotViewContextMenuRequested(const QPointF
&pos
)
1111 Q_EMIT
requestContextMenu(pos
.toPoint(), KFileItem(), selectedItems(), url());
1114 void DolphinView::slotHeaderContextMenuRequested(const QPointF
&pos
)
1116 ViewProperties
props(viewPropertiesUrl());
1118 QPointer
<QMenu
> menu
= new QMenu(QApplication::activeWindow());
1120 KItemListView
*view
= m_container
->controller()->view();
1121 const QList
<QByteArray
> visibleRolesSet
= view
->visibleRoles();
1123 bool indexingEnabled
= false;
1125 Baloo::IndexerConfig config
;
1126 indexingEnabled
= config
.fileIndexingEnabled();
1130 QMenu
*groupMenu
= nullptr;
1132 // Add all roles to the menu that can be shown or hidden by the user
1133 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
1134 for (const KFileItemModel::RoleInfo
&info
: rolesInfo
) {
1135 if (info
.role
== "text") {
1136 // It should not be possible to hide the "text" role
1140 const QString text
= m_model
->roleDescription(info
.role
);
1141 QAction
*action
= nullptr;
1142 if (info
.group
.isEmpty()) {
1143 action
= menu
->addAction(text
);
1145 if (!groupMenu
|| info
.group
!= groupName
) {
1146 groupName
= info
.group
;
1147 groupMenu
= menu
->addMenu(groupName
);
1150 action
= groupMenu
->addAction(text
);
1153 action
->setCheckable(true);
1154 action
->setChecked(visibleRolesSet
.contains(info
.role
));
1155 action
->setData(info
.role
);
1157 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) || (info
.requiresBaloo
) || (info
.requiresIndexer
&& indexingEnabled
);
1158 action
->setEnabled(enable
);
1161 menu
->addSeparator();
1163 QActionGroup
*widthsGroup
= new QActionGroup(menu
);
1164 const bool autoColumnWidths
= props
.headerColumnWidths().isEmpty();
1166 QAction
*toggleSidePaddingAction
= menu
->addAction(i18nc("@action:inmenu", "Side Padding"));
1167 toggleSidePaddingAction
->setCheckable(true);
1168 toggleSidePaddingAction
->setChecked(view
->header()->sidePadding() > 0);
1170 QAction
*autoAdjustWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
1171 autoAdjustWidthsAction
->setCheckable(true);
1172 autoAdjustWidthsAction
->setChecked(autoColumnWidths
);
1173 autoAdjustWidthsAction
->setActionGroup(widthsGroup
);
1175 QAction
*customWidthsAction
= menu
->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
1176 customWidthsAction
->setCheckable(true);
1177 customWidthsAction
->setChecked(!autoColumnWidths
);
1178 customWidthsAction
->setActionGroup(widthsGroup
);
1180 QAction
*action
= menu
->exec(pos
.toPoint());
1181 if (menu
&& action
) {
1182 KItemListHeader
*header
= view
->header();
1184 if (action
== autoAdjustWidthsAction
) {
1185 // Clear the column-widths from the viewproperties and turn on
1186 // the automatic resizing of the columns
1187 props
.setHeaderColumnWidths(QList
<int>());
1188 header
->setAutomaticColumnResizing(true);
1189 } else if (action
== customWidthsAction
) {
1190 // Apply the current column-widths as custom column-widths and turn
1191 // off the automatic resizing of the columns
1192 QList
<int> columnWidths
;
1193 const auto visibleRoles
= view
->visibleRoles();
1194 columnWidths
.reserve(visibleRoles
.count());
1195 for (const QByteArray
&role
: visibleRoles
) {
1196 columnWidths
.append(header
->columnWidth(role
));
1198 props
.setHeaderColumnWidths(columnWidths
);
1199 header
->setAutomaticColumnResizing(false);
1200 } else if (action
== toggleSidePaddingAction
) {
1201 header
->setSidePadding(toggleSidePaddingAction
->isChecked() ? 20 : 0);
1203 // Show or hide the selected role
1204 const QByteArray selectedRole
= action
->data().toByteArray();
1206 QList
<QByteArray
> visibleRoles
= view
->visibleRoles();
1207 if (action
->isChecked()) {
1208 visibleRoles
.append(selectedRole
);
1210 visibleRoles
.removeOne(selectedRole
);
1213 view
->setVisibleRoles(visibleRoles
);
1214 props
.setVisibleRoles(visibleRoles
);
1216 QList
<int> columnWidths
;
1217 if (!header
->automaticColumnResizing()) {
1218 const auto visibleRoles
= view
->visibleRoles();
1219 columnWidths
.reserve(visibleRoles
.count());
1220 for (const QByteArray
&role
: visibleRoles
) {
1221 columnWidths
.append(header
->columnWidth(role
));
1224 props
.setHeaderColumnWidths(columnWidths
);
1231 void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray
&role
, qreal current
)
1233 const QList
<QByteArray
> visibleRoles
= m_view
->visibleRoles();
1235 ViewProperties
props(viewPropertiesUrl());
1236 QList
<int> columnWidths
= props
.headerColumnWidths();
1237 if (columnWidths
.count() != visibleRoles
.count()) {
1238 columnWidths
.clear();
1239 columnWidths
.reserve(visibleRoles
.count());
1240 const KItemListHeader
*header
= m_view
->header();
1241 for (const QByteArray
&role
: visibleRoles
) {
1242 const int width
= header
->columnWidth(role
);
1243 columnWidths
.append(width
);
1247 const int roleIndex
= visibleRoles
.indexOf(role
);
1248 Q_ASSERT(roleIndex
>= 0 && roleIndex
< columnWidths
.count());
1249 columnWidths
[roleIndex
] = current
;
1251 props
.setHeaderColumnWidths(columnWidths
);
1254 void DolphinView::slotSidePaddingWidthChanged(qreal width
)
1256 ViewProperties
props(viewPropertiesUrl());
1257 DetailsModeSettings::setSidePadding(int(width
));
1258 m_view
->writeSettings();
1261 void DolphinView::slotItemHovered(int index
)
1263 const KFileItem item
= m_model
->fileItem(index
);
1265 if (GeneralSettings::showToolTips() && !m_dragging
) {
1266 QRectF itemRect
= m_container
->controller()->view()->itemContextRect(index
);
1267 const QPoint pos
= m_container
->mapToGlobal(itemRect
.topLeft().toPoint());
1268 itemRect
.moveTo(pos
);
1271 auto nativeParent
= nativeParentWidget();
1273 m_toolTipManager
->showToolTip(item
, itemRect
, nativeParent
->windowHandle());
1278 Q_EMIT
requestItemInfo(item
);
1281 void DolphinView::slotItemUnhovered(int index
)
1285 Q_EMIT
requestItemInfo(KFileItem());
1288 void DolphinView::slotItemDropEvent(int index
, QGraphicsSceneDragDropEvent
*event
)
1291 KFileItem destItem
= m_model
->fileItem(index
);
1292 if (destItem
.isNull() || (!destItem
.isDir() && !destItem
.isDesktopFile())) {
1293 // Use the URL of the view as drop target if the item is no directory
1295 destItem
= m_model
->rootItem();
1298 // The item represents a directory or desktop-file
1299 destUrl
= destItem
.mostLocalUrl();
1302 QDropEvent
dropEvent(event
->pos().toPoint(), event
->possibleActions(), event
->mimeData(), event
->buttons(), event
->modifiers());
1303 dropUrls(destUrl
, &dropEvent
, this);
1308 void DolphinView::dropUrls(const QUrl
&destUrl
, QDropEvent
*dropEvent
, QWidget
*dropWidget
)
1310 KIO::DropJob
*job
= DragAndDropHelper::dropUrls(destUrl
, dropEvent
, dropWidget
);
1313 connect(job
, &KIO::DropJob::result
, this, &DolphinView::slotJobResult
);
1315 if (destUrl
== url()) {
1316 // Mark the dropped urls as selected.
1317 m_clearSelectionBeforeSelectingNewItems
= true;
1318 m_markFirstNewlySelectedItemAsCurrent
= true;
1319 connect(job
, &KIO::DropJob::itemCreated
, this, &DolphinView::slotItemCreated
);
1324 void DolphinView::slotModelChanged(KItemModelBase
*current
, KItemModelBase
*previous
)
1326 if (previous
!= nullptr) {
1327 Q_ASSERT(qobject_cast
<KFileItemModel
*>(previous
));
1328 KFileItemModel
*fileItemModel
= static_cast<KFileItemModel
*>(previous
);
1329 disconnect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1330 m_versionControlObserver
->setModel(nullptr);
1334 Q_ASSERT(qobject_cast
<KFileItemModel
*>(current
));
1335 KFileItemModel
*fileItemModel
= static_cast<KFileItemModel
*>(current
);
1336 connect(fileItemModel
, &KFileItemModel::directoryLoadingCompleted
, this, &DolphinView::slotDirectoryLoadingCompleted
);
1337 m_versionControlObserver
->setModel(fileItemModel
);
1341 void DolphinView::slotMouseButtonPressed(int itemIndex
, Qt::MouseButtons buttons
)
1347 if (buttons
& Qt::BackButton
) {
1348 Q_EMIT
goBackRequested();
1349 } else if (buttons
& Qt::ForwardButton
) {
1350 Q_EMIT
goForwardRequested();
1354 void DolphinView::slotSelectedItemTextPressed(int index
)
1356 if (GeneralSettings::renameInline() && !m_view
->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick
)) {
1357 const KFileItem item
= m_model
->fileItem(index
);
1358 const KFileItemListProperties
capabilities(KFileItemList() << item
);
1359 if (capabilities
.supportsMoving()) {
1360 m_twoClicksRenamingItemUrl
= item
.url();
1361 m_twoClicksRenamingTimer
->start(QApplication::doubleClickInterval());
1366 void DolphinView::slotCopyingDone(KIO::Job
*, const QUrl
&, const QUrl
&to
)
1368 slotItemCreated(to
);
1371 void DolphinView::slotItemCreated(const QUrl
&url
)
1373 if (m_markFirstNewlySelectedItemAsCurrent
) {
1374 markUrlAsCurrent(url
);
1375 m_markFirstNewlySelectedItemAsCurrent
= false;
1377 m_selectedUrls
<< url
;
1380 void DolphinView::slotJobResult(KJob
*job
)
1382 if (job
->error() && job
->error() != KIO::ERR_USER_CANCELED
) {
1383 Q_EMIT
errorMessage(job
->errorString());
1385 if (!m_selectedUrls
.isEmpty()) {
1386 m_selectedUrls
= KDirModel::simplifiedUrlList(m_selectedUrls
);
1390 void DolphinView::slotSelectionChanged(const KItemSet
¤t
, const KItemSet
&previous
)
1392 const int currentCount
= current
.count();
1393 const int previousCount
= previous
.count();
1394 const bool selectionStateChanged
= (currentCount
== 0 && previousCount
> 0) || (currentCount
> 0 && previousCount
== 0);
1396 // If nothing has been selected before and something got selected (or if something
1397 // was selected before and now nothing is selected) the selectionChangedSignal must
1398 // be emitted asynchronously as fast as possible to update the edit-actions.
1399 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
1400 m_selectionChangedTimer
->start();
1403 void DolphinView::emitSelectionChangedSignal()
1405 m_selectionChangedTimer
->stop();
1406 Q_EMIT
selectionChanged(selectedItems());
1409 void DolphinView::slotStatJobResult(KJob
*job
)
1411 int folderCount
= 0;
1413 KIO::filesize_t totalFileSize
= 0;
1414 bool countFileSize
= true;
1416 const auto entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1417 if (entry
.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE
)) {
1418 // We have a precomputed value.
1419 totalFileSize
= static_cast<KIO::filesize_t
>(entry
.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE
));
1420 countFileSize
= false;
1423 const int itemCount
= m_model
->count();
1424 for (int i
= 0; i
< itemCount
; ++i
) {
1425 const KFileItem item
= m_model
->fileItem(i
);
1430 if (countFileSize
) {
1431 totalFileSize
+= item
.size();
1435 emitStatusBarText(folderCount
, fileCount
, totalFileSize
, NoSelection
);
1438 void DolphinView::updateSortRole(const QByteArray
&role
)
1440 ViewProperties
props(viewPropertiesUrl());
1441 props
.setSortRole(role
);
1443 KItemModelBase
*model
= m_container
->controller()->model();
1444 model
->setSortRole(role
);
1446 Q_EMIT
sortRoleChanged(role
);
1449 void DolphinView::updateSortOrder(Qt::SortOrder order
)
1451 ViewProperties
props(viewPropertiesUrl());
1452 props
.setSortOrder(order
);
1454 m_model
->setSortOrder(order
);
1456 Q_EMIT
sortOrderChanged(order
);
1459 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
1461 ViewProperties
props(viewPropertiesUrl());
1462 props
.setSortFoldersFirst(foldersFirst
);
1464 m_model
->setSortDirectoriesFirst(foldersFirst
);
1466 Q_EMIT
sortFoldersFirstChanged(foldersFirst
);
1469 void DolphinView::updateSortHiddenLast(bool hiddenLast
)
1471 ViewProperties
props(viewPropertiesUrl());
1472 props
.setSortHiddenLast(hiddenLast
);
1474 m_model
->setSortHiddenLast(hiddenLast
);
1476 Q_EMIT
sortHiddenLastChanged(hiddenLast
);
1479 QPair
<bool, QString
> DolphinView::pasteInfo() const
1481 const QMimeData
*mimeData
= QApplication::clipboard()->mimeData();
1482 QPair
<bool, QString
> info
;
1483 info
.second
= KIO::pasteActionText(mimeData
, &info
.first
, rootItem());
1487 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1489 m_tabsForFiles
= tabsForFiles
;
1492 bool DolphinView::isTabsForFilesEnabled() const
1494 return m_tabsForFiles
;
1497 bool DolphinView::itemsExpandable() const
1499 return m_mode
== DetailsView
;
1502 bool DolphinView::isExpanded(const KFileItem
&item
) const
1504 Q_ASSERT(item
.isDir());
1505 Q_ASSERT(items().contains(item
));
1506 if (!itemsExpandable()) {
1509 return m_model
->isExpanded(m_model
->index(item
));
1512 void DolphinView::restoreState(QDataStream
&stream
)
1514 // Read the version number of the view state and check if the version is supported.
1515 quint32 version
= 0;
1518 // The version of the view state isn't supported, we can't restore it.
1522 // Restore the current item that had the keyboard focus
1523 stream
>> m_currentItemUrl
;
1525 // Restore the previously selected items
1526 stream
>> m_selectedUrls
;
1528 // Restore the view position
1529 stream
>> m_restoredContentsPosition
;
1531 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1534 m_model
->restoreExpandedDirectories(urls
);
1537 void DolphinView::saveState(QDataStream
&stream
)
1539 stream
<< quint32(1); // View state version
1541 // Save the current item that has the keyboard focus
1542 const int currentIndex
= m_container
->controller()->selectionManager()->currentItem();
1543 if (currentIndex
!= -1) {
1544 KFileItem item
= m_model
->fileItem(currentIndex
);
1545 Q_ASSERT(!item
.isNull()); // If the current index is valid a item must exist
1546 QUrl currentItemUrl
= item
.url();
1547 stream
<< currentItemUrl
;
1552 // Save the selected urls
1553 stream
<< selectedItems().urlList();
1555 // Save view position
1556 const qreal x
= m_container
->horizontalScrollBar()->value();
1557 const qreal y
= m_container
->verticalScrollBar()->value();
1558 stream
<< QPoint(x
, y
);
1560 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
1561 stream
<< m_model
->expandedDirectories();
1564 KFileItem
DolphinView::rootItem() const
1566 return m_model
->rootItem();
1569 void DolphinView::setViewPropertiesContext(const QString
&context
)
1571 m_viewPropertiesContext
= context
;
1574 QString
DolphinView::viewPropertiesContext() const
1576 return m_viewPropertiesContext
;
1579 QUrl
DolphinView::openItemAsFolderUrl(const KFileItem
&item
, const bool browseThroughArchives
)
1581 if (item
.isNull()) {
1585 QUrl url
= item
.targetUrl();
1591 if (item
.isMimeTypeKnown()) {
1592 const QString
&mimetype
= item
.mimetype();
1594 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
1595 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
1596 // zip:/<path>/ when clicking on a zip file, etc.
1597 // The .protocol file specifies the mimetype that the kioslave handles.
1598 // Note that we don't use mimetype inheritance since we don't want to
1599 // open OpenDocument files as zip folders...
1600 const QString
&protocol
= KProtocolManager::protocolForArchiveMimetype(mimetype
);
1601 if (!protocol
.isEmpty()) {
1602 url
.setScheme(protocol
);
1607 if (mimetype
== QLatin1String("application/x-desktop")) {
1608 // Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
1609 KDesktopFile
desktopFile(url
.toLocalFile());
1610 if (desktopFile
.hasLinkType()) {
1611 const QString linkUrl
= desktopFile
.readUrl();
1612 if (!linkUrl
.startsWith(QLatin1String("http"))) {
1613 return QUrl::fromUserInput(linkUrl
);
1622 void DolphinView::resetZoomLevel()
1624 ViewModeSettings settings
{m_mode
};
1625 settings
.useDefaults(true);
1626 const int defaultIconSize
= settings
.iconSize();
1627 settings
.useDefaults(false);
1629 setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(QSize(defaultIconSize
, defaultIconSize
)));
1632 void DolphinView::observeCreatedItem(const QUrl
&url
)
1635 forceUrlsSelection(url
, {url
});
1639 void DolphinView::slotDirectoryRedirection(const QUrl
&oldUrl
, const QUrl
&newUrl
)
1641 if (oldUrl
.matches(url(), QUrl::StripTrailingSlash
)) {
1642 Q_EMIT
redirection(oldUrl
, newUrl
);
1643 m_url
= newUrl
; // #186947
1647 void DolphinView::updateViewState()
1649 if (m_currentItemUrl
!= QUrl()) {
1650 KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
1652 // if there is a selection already, leave it that way
1653 if (!selectionManager
->hasSelection()) {
1654 const int currentIndex
= m_model
->index(m_currentItemUrl
);
1655 if (currentIndex
!= -1) {
1656 selectionManager
->setCurrentItem(currentIndex
);
1658 // scroll to current item and reset the state
1659 if (m_scrollToCurrentItem
) {
1660 m_view
->scrollToItem(currentIndex
);
1661 m_scrollToCurrentItem
= false;
1663 m_currentItemUrl
= QUrl();
1665 selectionManager
->setCurrentItem(0);
1668 m_currentItemUrl
= QUrl();
1672 if (!m_restoredContentsPosition
.isNull()) {
1673 const int x
= m_restoredContentsPosition
.x();
1674 const int y
= m_restoredContentsPosition
.y();
1675 m_restoredContentsPosition
= QPoint();
1677 m_container
->horizontalScrollBar()->setValue(x
);
1678 m_container
->verticalScrollBar()->setValue(y
);
1681 if (!m_selectedUrls
.isEmpty()) {
1682 KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
1684 // if there is a selection already, leave it that way
1685 if (!selectionManager
->hasSelection()) {
1686 if (m_clearSelectionBeforeSelectingNewItems
) {
1687 selectionManager
->clearSelection();
1688 m_clearSelectionBeforeSelectingNewItems
= false;
1691 KItemSet selectedItems
= selectionManager
->selectedItems();
1693 QList
<QUrl
>::iterator it
= m_selectedUrls
.begin();
1694 while (it
!= m_selectedUrls
.end()) {
1695 const int index
= m_model
->index(*it
);
1697 selectedItems
.insert(index
);
1698 it
= m_selectedUrls
.erase(it
);
1704 if (!selectedItems
.isEmpty()) {
1705 selectionManager
->beginAnchoredSelection(selectionManager
->currentItem());
1706 selectionManager
->setSelectedItems(selectedItems
);
1712 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior
)
1714 if (GeneralSettings::showToolTips()) {
1716 m_toolTipManager
->hideToolTip(behavior
);
1720 } else if (m_mode
== DolphinView::IconsView
) {
1721 QToolTip::hideText();
1725 void DolphinView::slotTwoClicksRenamingTimerTimeout()
1727 const KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
1729 // verify that only one item is selected
1730 if (selectionManager
->selectedItems().count() == 1) {
1731 const int index
= selectionManager
->currentItem();
1732 const QUrl fileItemUrl
= m_model
->fileItem(index
).url();
1734 // check if the selected item was the same item that started the twoClicksRenaming
1735 if (fileItemUrl
.isValid() && m_twoClicksRenamingItemUrl
== fileItemUrl
) {
1736 renameSelectedItems();
1741 void DolphinView::slotTrashFileFinished(KJob
*job
)
1743 if (job
->error() == 0) {
1744 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
1745 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1746 Q_EMIT
errorMessage(job
->errorString());
1750 void DolphinView::slotDeleteFileFinished(KJob
*job
)
1752 if (job
->error() == 0) {
1753 Q_EMIT
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1754 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1755 Q_EMIT
errorMessage(job
->errorString());
1759 void DolphinView::slotRenamingResult(KJob
*job
)
1762 KIO::CopyJob
*copyJob
= qobject_cast
<KIO::CopyJob
*>(job
);
1764 const QUrl newUrl
= copyJob
->destUrl();
1765 const int index
= m_model
->index(newUrl
);
1767 QHash
<QByteArray
, QVariant
> data
;
1768 const QUrl oldUrl
= copyJob
->srcUrls().at(0);
1769 data
.insert("text", oldUrl
.fileName());
1770 m_model
->setData(index
, data
);
1775 void DolphinView::slotDirectoryLoadingStarted()
1777 m_loadingState
= LoadingState::Loading
;
1778 updatePlaceholderLabel();
1780 // Disable the writestate temporary until it can be determined in a fast way
1781 // in DolphinView::slotDirectoryLoadingCompleted()
1782 if (m_isFolderWritable
) {
1783 m_isFolderWritable
= false;
1784 Q_EMIT
writeStateChanged(m_isFolderWritable
);
1787 Q_EMIT
directoryLoadingStarted();
1790 void DolphinView::slotDirectoryLoadingCompleted()
1792 m_loadingState
= LoadingState::Completed
;
1794 // Update the view-state. This has to be done asynchronously
1795 // because the view might not be in its final state yet.
1796 QTimer::singleShot(0, this, &DolphinView::updateViewState
);
1798 // Update the placeholder label in case we found that the folder was empty
1801 Q_EMIT
directoryLoadingCompleted();
1803 updatePlaceholderLabel();
1804 updateWritableState();
1807 void DolphinView::slotDirectoryLoadingCanceled()
1809 m_loadingState
= LoadingState::Canceled
;
1811 updatePlaceholderLabel();
1813 Q_EMIT
directoryLoadingCanceled();
1816 void DolphinView::slotItemsChanged()
1818 m_assureVisibleCurrentIndex
= false;
1821 void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current
, Qt::SortOrder previous
)
1824 Q_ASSERT(m_model
->sortOrder() == current
);
1826 ViewProperties
props(viewPropertiesUrl());
1827 props
.setSortOrder(current
);
1829 Q_EMIT
sortOrderChanged(current
);
1832 void DolphinView::slotSortRoleChangedByHeader(const QByteArray
¤t
, const QByteArray
&previous
)
1835 Q_ASSERT(m_model
->sortRole() == current
);
1837 ViewProperties
props(viewPropertiesUrl());
1838 props
.setSortRole(current
);
1840 Q_EMIT
sortRoleChanged(current
);
1843 void DolphinView::slotVisibleRolesChangedByHeader(const QList
<QByteArray
> ¤t
, const QList
<QByteArray
> &previous
)
1846 Q_ASSERT(m_container
->controller()->view()->visibleRoles() == current
);
1848 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
1850 m_visibleRoles
= current
;
1852 ViewProperties
props(viewPropertiesUrl());
1853 props
.setVisibleRoles(m_visibleRoles
);
1855 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
1858 void DolphinView::slotRoleEditingCanceled()
1860 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
, this, &DolphinView::slotRoleEditingFinished
);
1863 void DolphinView::slotRoleEditingFinished(int index
, const QByteArray
&role
, const QVariant
&value
)
1865 disconnect(m_view
, &DolphinItemListView::roleEditingFinished
, this, &DolphinView::slotRoleEditingFinished
);
1867 const KFileItemList items
= selectedItems();
1868 if (items
.count() != 1) {
1872 if (role
== "text") {
1873 const KFileItem oldItem
= items
.first();
1874 const EditResult retVal
= value
.value
<EditResult
>();
1875 const QString newName
= retVal
.newName
;
1876 if (!newName
.isEmpty() && newName
!= oldItem
.text() && newName
!= QLatin1Char('.') && newName
!= QLatin1String("..")) {
1877 const QUrl oldUrl
= oldItem
.url();
1879 QUrl newUrl
= oldUrl
.adjusted(QUrl::RemoveFilename
);
1880 newUrl
.setPath(newUrl
.path() + KIO::encodeFileName(newName
));
1883 //Confirm hiding file/directory by renaming inline
1884 if (!hiddenFilesShown() && newName
.startsWith(QLatin1Char('.')) && !oldItem
.name().startsWith(QLatin1Char('.'))) {
1885 KGuiItem
yesGuiItem(i18nc("@action:button", "Rename and Hide"), QStringLiteral("view-hidden"));
1887 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1889 KMessageBox::questionTwoActions(this,
1892 KMessageBox::questionYesNo(this,
1894 oldItem
.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
1895 "Do you still want to rename it?")
1896 : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
1897 "Do you still want to rename it?"),
1898 oldItem
.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"),
1900 KStandardGuiItem::cancel(),
1901 QStringLiteral("ConfirmHide"));
1903 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1904 if (code
== KMessageBox::SecondaryAction
) {
1906 if (code
== KMessageBox::No
) {
1913 const bool newNameExistsAlready
= (m_model
->index(newUrl
) >= 0);
1914 if (!newNameExistsAlready
&& m_model
->index(oldUrl
) == index
) {
1915 // Only change the data in the model if no item with the new name
1916 // is in the model yet. If there is an item with the new name
1917 // already, calling KIO::CopyJob will open a dialog
1918 // asking for a new name, and KFileItemModel will update the
1919 // data when the dir lister signals that the file name has changed.
1920 QHash
<QByteArray
, QVariant
> data
;
1921 data
.insert(role
, retVal
.newName
);
1922 m_model
->setData(index
, data
);
1925 KIO::Job
*job
= KIO::moveAs(oldUrl
, newUrl
);
1926 KJobWidgets::setWindow(job
, this);
1927 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename
, {oldUrl
}, newUrl
, job
);
1928 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
1930 forceUrlsSelection(newUrl
, {newUrl
});
1932 if (!newNameExistsAlready
) {
1933 // Only connect the result signal if there is no item with the new name
1934 // in the model yet, see bug 328262.
1935 connect(job
, &KJob::result
, this, &DolphinView::slotRenamingResult
);
1938 if (retVal
.direction
!= EditDone
) {
1939 const short indexShift
= retVal
.direction
== EditNext
? 1 : -1;
1940 m_container
->controller()->selectionManager()->setSelected(index
, 1, KItemListSelectionManager::Deselect
);
1941 m_container
->controller()->selectionManager()->setSelected(index
+ indexShift
, 1, KItemListSelectionManager::Select
);
1942 renameSelectedItems();
1947 void DolphinView::loadDirectory(const QUrl
&url
, bool reload
)
1949 if (!url
.isValid()) {
1950 const QString
location(url
.toDisplayString(QUrl::PreferLocalFile
));
1951 if (location
.isEmpty()) {
1952 Q_EMIT
errorMessage(i18nc("@info:status", "The location is empty."));
1954 Q_EMIT
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1960 m_model
->refreshDirectory(url
);
1962 m_model
->loadDirectory(url
);
1966 void DolphinView::applyViewProperties()
1968 const ViewProperties
props(viewPropertiesUrl());
1969 applyViewProperties(props
);
1972 void DolphinView::applyViewProperties(const ViewProperties
&props
)
1974 m_view
->beginTransaction();
1976 const Mode mode
= props
.viewMode();
1977 if (m_mode
!= mode
) {
1978 const Mode previousMode
= m_mode
;
1981 // Changing the mode might result in changing
1982 // the zoom level. Remember the old zoom level so
1983 // that zoomLevelChanged() can get emitted.
1984 const int oldZoomLevel
= m_view
->zoomLevel();
1987 Q_EMIT
modeChanged(m_mode
, previousMode
);
1989 if (m_view
->zoomLevel() != oldZoomLevel
) {
1990 Q_EMIT
zoomLevelChanged(m_view
->zoomLevel(), oldZoomLevel
);
1994 const bool hiddenFilesShown
= props
.hiddenFilesShown();
1995 if (hiddenFilesShown
!= m_model
->showHiddenFiles()) {
1996 m_model
->setShowHiddenFiles(hiddenFilesShown
);
1997 Q_EMIT
hiddenFilesShownChanged(hiddenFilesShown
);
2000 const bool groupedSorting
= props
.groupedSorting();
2001 if (groupedSorting
!= m_model
->groupedSorting()) {
2002 m_model
->setGroupedSorting(groupedSorting
);
2003 Q_EMIT
groupedSortingChanged(groupedSorting
);
2006 const QByteArray sortRole
= props
.sortRole();
2007 if (sortRole
!= m_model
->sortRole()) {
2008 m_model
->setSortRole(sortRole
);
2009 Q_EMIT
sortRoleChanged(sortRole
);
2012 const Qt::SortOrder sortOrder
= props
.sortOrder();
2013 if (sortOrder
!= m_model
->sortOrder()) {
2014 m_model
->setSortOrder(sortOrder
);
2015 Q_EMIT
sortOrderChanged(sortOrder
);
2018 const bool sortFoldersFirst
= props
.sortFoldersFirst();
2019 if (sortFoldersFirst
!= m_model
->sortDirectoriesFirst()) {
2020 m_model
->setSortDirectoriesFirst(sortFoldersFirst
);
2021 Q_EMIT
sortFoldersFirstChanged(sortFoldersFirst
);
2024 const bool sortHiddenLast
= props
.sortHiddenLast();
2025 if (sortHiddenLast
!= m_model
->sortHiddenLast()) {
2026 m_model
->setSortHiddenLast(sortHiddenLast
);
2027 Q_EMIT
sortHiddenLastChanged(sortHiddenLast
);
2030 const QList
<QByteArray
> visibleRoles
= props
.visibleRoles();
2031 if (visibleRoles
!= m_visibleRoles
) {
2032 const QList
<QByteArray
> previousVisibleRoles
= m_visibleRoles
;
2033 m_visibleRoles
= visibleRoles
;
2034 m_view
->setVisibleRoles(visibleRoles
);
2035 Q_EMIT
visibleRolesChanged(m_visibleRoles
, previousVisibleRoles
);
2038 const bool previewsShown
= props
.previewsShown();
2039 if (previewsShown
!= m_view
->previewsShown()) {
2040 const int oldZoomLevel
= zoomLevel();
2042 m_view
->setPreviewsShown(previewsShown
);
2043 Q_EMIT
previewsShownChanged(previewsShown
);
2045 // Changing the preview-state might result in a changed zoom-level
2046 if (oldZoomLevel
!= zoomLevel()) {
2047 Q_EMIT
zoomLevelChanged(zoomLevel(), oldZoomLevel
);
2051 KItemListView
*itemListView
= m_container
->controller()->view();
2052 if (itemListView
->isHeaderVisible()) {
2053 KItemListHeader
*header
= itemListView
->header();
2054 const QList
<int> headerColumnWidths
= props
.headerColumnWidths();
2055 const int rolesCount
= m_visibleRoles
.count();
2056 if (headerColumnWidths
.count() == rolesCount
) {
2057 header
->setAutomaticColumnResizing(false);
2059 QHash
<QByteArray
, qreal
> columnWidths
;
2060 for (int i
= 0; i
< rolesCount
; ++i
) {
2061 columnWidths
.insert(m_visibleRoles
[i
], headerColumnWidths
[i
]);
2063 header
->setColumnWidths(columnWidths
);
2065 header
->setAutomaticColumnResizing(true);
2067 header
->setSidePadding(DetailsModeSettings::sidePadding());
2070 m_view
->endTransaction();
2073 void DolphinView::applyModeToView()
2077 m_view
->setItemLayout(KFileItemListView::IconsLayout
);
2080 m_view
->setItemLayout(KFileItemListView::CompactLayout
);
2083 m_view
->setItemLayout(KFileItemListView::DetailsLayout
);
2091 void DolphinView::pasteToUrl(const QUrl
&url
)
2093 KIO::PasteJob
*job
= KIO::paste(QApplication::clipboard()->mimeData(), url
);
2094 KJobWidgets::setWindow(job
, this);
2095 m_clearSelectionBeforeSelectingNewItems
= true;
2096 m_markFirstNewlySelectedItemAsCurrent
= true;
2097 connect(job
, &KIO::PasteJob::itemCreated
, this, &DolphinView::slotItemCreated
);
2098 connect(job
, &KIO::PasteJob::result
, this, &DolphinView::slotJobResult
);
2101 QList
<QUrl
> DolphinView::simplifiedSelectedUrls() const
2105 const KFileItemList items
= selectedItems();
2106 urls
.reserve(items
.count());
2107 for (const KFileItem
&item
: items
) {
2108 urls
.append(item
.url());
2111 if (itemsExpandable()) {
2112 // TODO: Check if we still need KDirModel for this in KDE 5.0
2113 urls
= KDirModel::simplifiedUrlList(urls
);
2119 QMimeData
*DolphinView::selectionMimeData() const
2121 const KItemListSelectionManager
*selectionManager
= m_container
->controller()->selectionManager();
2122 const KItemSet selectedIndexes
= selectionManager
->selectedItems();
2124 return m_model
->createMimeData(selectedIndexes
);
2127 void DolphinView::updateWritableState()
2129 const bool wasFolderWritable
= m_isFolderWritable
;
2130 m_isFolderWritable
= false;
2132 KFileItem item
= m_model
->rootItem();
2133 if (item
.isNull()) {
2134 // Try to find out if the URL is writable even if the "root item" is
2135 // null, see https://bugs.kde.org/show_bug.cgi?id=330001
2136 item
= KFileItem(url());
2137 item
.setDelayedMimeTypes(true);
2140 KFileItemListProperties
capabilities(KFileItemList() << item
);
2141 m_isFolderWritable
= capabilities
.supportsWriting();
2143 if (m_isFolderWritable
!= wasFolderWritable
) {
2144 Q_EMIT
writeStateChanged(m_isFolderWritable
);
2148 QUrl
DolphinView::viewPropertiesUrl() const
2150 if (m_viewPropertiesContext
.isEmpty()) {
2155 url
.setScheme(m_url
.scheme());
2156 url
.setPath(m_viewPropertiesContext
);
2160 void DolphinView::slotRenameDialogRenamingFinished(const QList
<QUrl
> &urls
)
2162 forceUrlsSelection(urls
.first(), urls
);
2165 void DolphinView::forceUrlsSelection(const QUrl
¤t
, const QList
<QUrl
> &selected
)
2168 m_clearSelectionBeforeSelectingNewItems
= true;
2169 markUrlAsCurrent(current
);
2170 markUrlsAsSelected(selected
);
2173 void DolphinView::copyPathToClipboard()
2175 const KFileItemList list
= selectedItems();
2176 if (list
.isEmpty()) {
2179 const KFileItem
&item
= list
.at(0);
2180 QString path
= item
.localPath();
2181 if (path
.isEmpty()) {
2182 path
= item
.url().toDisplayString();
2184 QClipboard
*clipboard
= QApplication::clipboard();
2185 if (clipboard
== nullptr) {
2188 clipboard
->setText(path
);
2191 void DolphinView::slotIncreaseZoom()
2193 setZoomLevel(zoomLevel() + 1);
2196 void DolphinView::slotDecreaseZoom()
2198 setZoomLevel(zoomLevel() - 1);
2201 void DolphinView::slotSwipeUp()
2203 Q_EMIT
goUpRequested();
2206 void DolphinView::showLoadingPlaceholder()
2208 m_placeholderLabel
->setText(i18n("Loading..."));
2209 m_placeholderLabel
->setVisible(true);
2212 void DolphinView::updatePlaceholderLabel()
2214 m_showLoadingPlaceholderTimer
->stop();
2215 if (itemsCount() > 0) {
2216 m_placeholderLabel
->setVisible(false);
2220 if (m_loadingState
== LoadingState::Loading
) {
2221 m_placeholderLabel
->setVisible(false);
2222 m_showLoadingPlaceholderTimer
->start();
2226 if (m_loadingState
== LoadingState::Canceled
) {
2227 m_placeholderLabel
->setText(i18n("Loading canceled"));
2228 } else if (!nameFilter().isEmpty()) {
2229 m_placeholderLabel
->setText(i18n("No items matching the filter"));
2230 } else if (m_url
.scheme() == QLatin1String("baloosearch") || m_url
.scheme() == QLatin1String("filenamesearch")) {
2231 m_placeholderLabel
->setText(i18n("No items matching the search"));
2232 } else if (m_url
.scheme() == QLatin1String("trash") && m_url
.path() == QLatin1String("/")) {
2233 m_placeholderLabel
->setText(i18n("Trash is empty"));
2234 } else if (m_url
.scheme() == QLatin1String("tags")) {
2235 if (m_url
.path() == QLatin1Char('/')) {
2236 m_placeholderLabel
->setText(i18n("No tags"));
2238 const QString tagName
= m_url
.path().mid(1); // Remove leading /
2239 m_placeholderLabel
->setText(i18n("No files tagged with \"%1\"", tagName
));
2242 } else if (m_url
.scheme() == QLatin1String("recentlyused")) {
2243 m_placeholderLabel
->setText(i18n("No recently used items"));
2244 } else if (m_url
.scheme() == QLatin1String("smb")) {
2245 m_placeholderLabel
->setText(i18n("No shared folders found"));
2246 } else if (m_url
.scheme() == QLatin1String("network")) {
2247 m_placeholderLabel
->setText(i18n("No relevant network resources found"));
2248 } else if (m_url
.scheme() == QLatin1String("mtp") && m_url
.path() == QLatin1String("/")) {
2249 m_placeholderLabel
->setText(i18n("No MTP-compatible devices found"));
2250 } else if (m_url
.scheme() == QLatin1String("afc") && m_url
.path() == QLatin1String("/")) {
2251 m_placeholderLabel
->setText(i18n("No Apple devices found"));
2252 } else if (m_url
.scheme() == QLatin1String("bluetooth")) {
2253 m_placeholderLabel
->setText(i18n("No Bluetooth devices found"));
2255 m_placeholderLabel
->setText(i18n("Folder is empty"));
2258 m_placeholderLabel
->setVisible(true);
2261 void DolphinView::tryShowNameToolTip(QHelpEvent
*event
)
2263 if (!GeneralSettings::showToolTips() && m_mode
== DolphinView::IconsView
) {
2264 const std::optional
<int> index
= m_view
->itemAt(event
->pos());
2266 if (!index
.has_value()) {
2270 // Check whether the filename has been elided
2271 const bool isElided
= m_view
->isElided(index
.value());
2274 const KFileItem item
= m_model
->fileItem(index
.value());
2275 const QString text
= item
.text();
2276 const QPoint pos
= mapToGlobal(event
->pos());
2277 QToolTip::showText(pos
, text
);