2 * SPDX-FileCopyrightText: 2007 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "dolphinviewcontainer.h"
9 #include "dolphin_generalsettings.h"
10 #include "dolphindebug.h"
11 #include "dolphinplacesmodelsingleton.h"
12 #include "filterbar/filterbar.h"
14 #include "search/dolphinsearchbox.h"
15 #include "selectionmode/topbar.h"
16 #include "statusbar/dolphinstatusbar.h"
17 #include "views/viewmodecontroller.h"
18 #include "views/viewproperties.h"
19 #include "dolphin_detailsmodesettings.h"
21 #include <KActionCollection>
23 #include <KActivities/ResourceInstance>
25 #include <KFileItemActions>
26 #include <KFilePlacesModel>
27 #include <KIO/PreviewJob>
28 #include <KIO/OpenUrlJob>
29 #include <KIO/JobUiDelegate>
30 #include <KLocalizedString>
31 #include <KMessageWidget>
32 #include <KProtocolManager>
34 #include <KUrlComboBox>
37 #include <QGridLayout>
38 #include <QGuiApplication>
39 #include <QLoggingCategory>
43 #include <QDesktopServices>
45 // An overview of the widgets contained by this ViewContainer
46 struct LayoutStructure
{
48 int messageWidget
= 1;
49 int selectionModeTopBar
= 2;
51 int selectionModeBottomBar
= 4;
55 constexpr LayoutStructure positionFor
;
57 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
60 m_urlNavigator
{new DolphinUrlNavigator(url
)},
61 m_urlNavigatorConnected
{nullptr},
63 m_searchModeEnabled(false),
64 m_messageWidget(nullptr),
65 m_selectionModeTopBar
{nullptr},
68 m_selectionModeBottomBar
{nullptr},
70 m_statusBarTimer(nullptr),
71 m_statusBarTimestamp(),
74 , m_activityResourceInstance(nullptr)
79 m_topLayout
= new QGridLayout(this);
80 m_topLayout
->setSpacing(0);
81 m_topLayout
->setContentsMargins(0, 0, 0, 0);
83 m_searchBox
= new DolphinSearchBox(this);
85 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
86 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
87 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
88 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
89 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
90 "<para>This helps you find files and folders. Enter a <emphasis>"
91 "search term</emphasis> and specify search settings with the "
92 "buttons at the bottom:<list><item>Filename/Content: "
93 "Does the item you are looking for contain the search terms "
94 "within its filename or its contents?<nl/>The contents of images, "
95 "audio files and videos will not be searched.</item><item>"
96 "From Here/Everywhere: Do you want to search in this "
97 "folder and its sub-folders or everywhere?</item><item>"
98 "More Options: Click this to search by media type, access "
99 "time or rating.</item><item>More Search Tools: Install other "
100 "means to find an item.</item></list></para>"));
102 m_messageWidget
= new KMessageWidget(this);
103 m_messageWidget
->setCloseButtonVisible(true);
104 m_messageWidget
->hide();
109 // We must be logged in as the root user; show a big scary warning
110 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
114 // Initialize filter bar
115 m_filterBar
= new FilterBar(this);
116 m_filterBar
->setVisible(GeneralSettings::filterBar());
118 connect(m_filterBar
, &FilterBar::filterChanged
,
119 this, &DolphinViewContainer::setNameFilter
);
120 connect(m_filterBar
, &FilterBar::closeRequest
,
121 this, &DolphinViewContainer::closeFilterBar
);
122 connect(m_filterBar
, &FilterBar::focusViewRequest
,
123 this, &DolphinViewContainer::requestFocus
);
125 // Initialize the main view
126 m_view
= new DolphinView(url
, this);
127 connect(m_view
, &DolphinView::urlChanged
,
128 m_filterBar
, &FilterBar::slotUrlChanged
);
129 connect(m_view
, &DolphinView::urlChanged
,
130 m_messageWidget
, &KMessageWidget::hide
);
131 // m_urlNavigator stays in sync with m_view's location changes and
132 // keeps track of them so going back and forth in the history works.
133 connect(m_view
, &DolphinView::urlChanged
,
134 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
135 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
,
136 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
137 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlAboutToBeChanged
,
138 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
139 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlSelectionRequested
,
140 this, &DolphinViewContainer::slotUrlSelectionRequested
);
141 connect(m_view
, &DolphinView::writeStateChanged
,
142 this, &DolphinViewContainer::writeStateChanged
);
143 connect(m_view
, &DolphinView::requestItemInfo
,
144 this, &DolphinViewContainer::showItemInfo
);
145 connect(m_view
, &DolphinView::itemActivated
,
146 this, &DolphinViewContainer::slotItemActivated
);
147 connect(m_view
, &DolphinView::itemsActivated
,
148 this, &DolphinViewContainer::slotItemsActivated
);
149 connect(m_view
, &DolphinView::redirection
,
150 this, &DolphinViewContainer::redirect
);
151 connect(m_view
, &DolphinView::directoryLoadingStarted
,
152 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
153 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
154 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
155 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
156 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
157 connect(m_view
, &DolphinView::itemCountChanged
,
158 this, &DolphinViewContainer::delayedStatusBarUpdate
);
159 connect(m_view
, &DolphinView::directoryLoadingProgress
,
160 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
161 connect(m_view
, &DolphinView::directorySortingProgress
,
162 this, &DolphinViewContainer::updateDirectorySortingProgress
);
163 connect(m_view
, &DolphinView::selectionChanged
,
164 this, &DolphinViewContainer::delayedStatusBarUpdate
);
165 connect(m_view
, &DolphinView::errorMessage
,
166 this, &DolphinViewContainer::showErrorMessage
);
167 connect(m_view
, &DolphinView::urlIsFileError
,
168 this, &DolphinViewContainer::slotUrlIsFileError
);
169 connect(m_view
, &DolphinView::activated
,
170 this, &DolphinViewContainer::activate
);
171 connect(m_view
, &DolphinView::hiddenFilesShownChanged
,
172 this, &DolphinViewContainer::slotHiddenFilesShownChanged
);
173 connect(m_view
, &DolphinView::sortHiddenLastChanged
,
174 this, &DolphinViewContainer::slotSortHiddenLastChanged
);
176 // Initialize status bar
177 m_statusBar
= new DolphinStatusBar(this);
178 m_statusBar
->setUrl(m_view
->url());
179 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
180 connect(m_view
, &DolphinView::urlChanged
,
181 m_statusBar
, &DolphinStatusBar::setUrl
);
182 connect(m_view
, &DolphinView::zoomLevelChanged
,
183 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
184 connect(m_view
, &DolphinView::infoMessage
,
185 m_statusBar
, &DolphinStatusBar::setText
);
186 connect(m_view
, &DolphinView::operationCompletedMessage
,
187 m_statusBar
, &DolphinStatusBar::setText
);
188 connect(m_view
, &DolphinView::statusBarTextChanged
,
189 m_statusBar
, &DolphinStatusBar::setDefaultText
);
190 connect(m_view
, &DolphinView::statusBarTextChanged
,
191 m_statusBar
, &DolphinStatusBar::resetToDefaultText
);
192 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
193 this, &DolphinViewContainer::stopDirectoryLoading
);
194 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
195 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
197 m_statusBarTimer
= new QTimer(this);
198 m_statusBarTimer
->setSingleShot(true);
199 m_statusBarTimer
->setInterval(300);
200 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
202 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
203 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
204 this, &DolphinViewContainer::delayedStatusBarUpdate
);
206 m_topLayout
->addWidget(m_searchBox
, positionFor
.searchBox
, 0);
207 m_topLayout
->addWidget(m_messageWidget
, positionFor
.messageWidget
, 0);
208 m_topLayout
->addWidget(m_view
, positionFor
.view
, 0);
209 m_topLayout
->addWidget(m_filterBar
, positionFor
.filterBar
, 0);
210 m_topLayout
->addWidget(m_statusBar
, positionFor
.statusBar
, 0);
212 setSearchModeEnabled(isSearchUrl(url
));
214 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
215 if (view()->viewMode() == DolphinView::Mode::DetailsView
) {
220 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
221 connect(placesModel
, &KFilePlacesModel::dataChanged
,
222 this, &DolphinViewContainer::slotPlacesModelChanged
);
223 connect(placesModel
, &KFilePlacesModel::rowsInserted
,
224 this, &DolphinViewContainer::slotPlacesModelChanged
);
225 connect(placesModel
, &KFilePlacesModel::rowsRemoved
,
226 this, &DolphinViewContainer::slotPlacesModelChanged
);
228 connect(this, &DolphinViewContainer::searchModeEnabledChanged
,
229 this, &DolphinViewContainer::captionChanged
);
231 // Initialize kactivities resource instance
234 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
235 m_activityResourceInstance
->setParent(this);
239 DolphinViewContainer::~DolphinViewContainer()
243 QUrl
DolphinViewContainer::url() const
245 return m_view
->url();
248 void DolphinViewContainer::setActive(bool active
)
250 m_searchBox
->setActive(active
);
251 if (m_urlNavigatorConnected
) {
252 m_urlNavigatorConnected
->setActive(active
);
254 m_view
->setActive(active
);
258 m_activityResourceInstance
->notifyFocusedIn();
260 m_activityResourceInstance
->notifyFocusedOut();
265 bool DolphinViewContainer::isActive() const
267 return m_view
->isActive();
270 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
272 m_autoGrabFocus
= grab
;
275 bool DolphinViewContainer::autoGrabFocus() const
277 return m_autoGrabFocus
;
280 QString
DolphinViewContainer::currentSearchText() const
282 return m_searchBox
->text();
285 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
290 DolphinStatusBar
* DolphinViewContainer::statusBar()
295 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
297 return m_urlNavigatorConnected
;
300 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
302 return m_urlNavigatorConnected
;
305 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
307 return m_urlNavigator
.get();
310 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
312 return m_urlNavigator
.get();
315 const DolphinView
* DolphinViewContainer::view() const
320 DolphinView
* DolphinViewContainer::view()
325 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
327 Q_CHECK_PTR(urlNavigator
);
328 Q_ASSERT(!m_urlNavigatorConnected
);
329 Q_ASSERT(m_urlNavigator
.get() != urlNavigator
);
332 urlNavigator
->setLocationUrl(m_view
->url());
333 urlNavigator
->setShowHiddenFolders(m_view
->hiddenFilesShown());
334 urlNavigator
->setSortHiddenFoldersLast(m_view
->sortHiddenLast());
335 if (m_urlNavigatorVisualState
) {
336 urlNavigator
->setVisualState(*m_urlNavigatorVisualState
.get());
337 m_urlNavigatorVisualState
.reset();
339 urlNavigator
->setActive(isActive());
341 // Url changes are still done via m_urlNavigator.
342 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
343 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
344 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
,
345 this, [=](const QUrl
&destination
, QDropEvent
*event
) {
346 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
348 // Aside from these, only visual things need to be connected.
349 connect(m_view
, &DolphinView::urlChanged
,
350 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
351 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
352 this, &DolphinViewContainer::activate
);
354 m_urlNavigatorConnected
= urlNavigator
;
357 void DolphinViewContainer::disconnectUrlNavigator()
359 if (!m_urlNavigatorConnected
) {
363 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
364 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
365 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
367 disconnect(m_view
, &DolphinView::urlChanged
,
368 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
369 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
370 this, &DolphinViewContainer::activate
);
372 m_urlNavigatorVisualState
= m_urlNavigatorConnected
->visualState();
373 m_urlNavigatorConnected
= nullptr;
376 void DolphinViewContainer::setSelectionModeEnabled(bool enabled
, KActionCollection
*actionCollection
, SelectionMode::BottomBar::Contents bottomBarContents
)
378 const bool wasEnabled
= m_view
->selectionMode();
379 m_view
->setSelectionModeEnabled(enabled
);
383 return; // nothing to do here
385 Q_CHECK_PTR(m_selectionModeTopBar
); // there is no point in disabling selectionMode when it wasn't even enabled once.
386 Q_CHECK_PTR(m_selectionModeBottomBar
);
387 m_selectionModeTopBar
->setVisible(false, WithAnimation
);
388 m_selectionModeBottomBar
->setVisible(false, WithAnimation
);
389 Q_EMIT
selectionModeChanged(false);
393 if (!m_selectionModeTopBar
) {
394 // Changing the location will disable selection mode.
395 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
, this, [this]() {
396 setSelectionModeEnabled(false);
399 m_selectionModeTopBar
= new SelectionMode::TopBar(this); // will be created hidden
400 connect(m_selectionModeTopBar
, &SelectionMode::TopBar::selectionModeLeavingRequested
, this, [this]() {
401 setSelectionModeEnabled(false);
403 m_topLayout
->addWidget(m_selectionModeTopBar
, positionFor
.selectionModeTopBar
, 0);
406 if (!m_selectionModeBottomBar
) {
407 m_selectionModeBottomBar
= new SelectionMode::BottomBar(actionCollection
, this);
408 connect(m_view
, &DolphinView::selectionChanged
, this, [this](const KFileItemList
&selection
) {
409 m_selectionModeBottomBar
->slotSelectionChanged(selection
, m_view
->url());
411 connect(m_selectionModeBottomBar
, &SelectionMode::BottomBar::error
, this, [this](const QString
&errorMessage
) {
412 showErrorMessage(errorMessage
);
414 connect(m_selectionModeBottomBar
, &SelectionMode::BottomBar::selectionModeLeavingRequested
, this, [this]() {
415 setSelectionModeEnabled(false);
417 m_topLayout
->addWidget(m_selectionModeBottomBar
, positionFor
.selectionModeBottomBar
, 0);
419 m_selectionModeBottomBar
->resetContents(bottomBarContents
);
420 if (bottomBarContents
== SelectionMode::BottomBar::GeneralContents
) {
421 m_selectionModeBottomBar
->slotSelectionChanged(m_view
->selectedItems(), m_view
->url());
425 m_selectionModeTopBar
->setVisible(true, WithAnimation
);
426 m_selectionModeBottomBar
->setVisible(true, WithAnimation
);
427 Q_EMIT
selectionModeChanged(true);
431 bool DolphinViewContainer::isSelectionModeEnabled() const
433 const bool isEnabled
= m_view
->selectionMode();
435 // We can't assert that the bars are invisible only because the selection mode is disabled because the hide animation might still be playing.
436 && (!m_selectionModeBottomBar
|| !m_selectionModeBottomBar
->isEnabled() ||
437 !m_selectionModeBottomBar
->isVisible() || m_selectionModeBottomBar
->contents() == SelectionMode::BottomBar::PasteContents
))
439 && m_selectionModeTopBar
&& m_selectionModeTopBar
->isVisible()
440 // The bottom bar is either visible or was hidden because it has nothing to show in GeneralContents mode e.g. because no items are selected.
441 && m_selectionModeBottomBar
442 && (m_selectionModeBottomBar
->isVisible() || m_selectionModeBottomBar
->contents() == SelectionMode::BottomBar::GeneralContents
)));
446 void DolphinViewContainer::slotSplitTabDisabled()
448 if (m_selectionModeBottomBar
) {
449 m_selectionModeBottomBar
->slotSplitTabDisabled();
454 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
460 m_messageWidget
->setText(msg
);
462 // TODO: wrap at arbitrary character positions once QLabel can do this
463 // https://bugreports.qt.io/browse/QTBUG-1276
464 m_messageWidget
->setWordWrap(true);
467 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
468 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
469 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
475 m_messageWidget
->setWordWrap(false);
476 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
477 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
479 if (m_messageWidget
->isVisible()) {
480 m_messageWidget
->hide();
482 m_messageWidget
->animatedShow();
485 void DolphinViewContainer::readSettings()
487 // The startup settings should (only) get applied if they have been
488 // modified by the user. Otherwise keep the (possibly) different current
489 // setting of the filterbar.
490 if (GeneralSettings::modifiedStartupSettings()) {
491 setFilterBarVisible(GeneralSettings::filterBar());
494 m_view
->readSettings();
495 m_statusBar
->readSettings();
498 bool DolphinViewContainer::isFilterBarVisible() const
500 return m_filterBar
->isVisible();
503 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
505 m_searchBox
->setVisible(enabled
);
508 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
509 m_searchBox
->fromSearchUrl(locationUrl
);
512 if (enabled
== isSearchModeEnabled()) {
513 if (enabled
&& !m_searchBox
->hasFocus()) {
514 m_searchBox
->setFocus();
515 m_searchBox
->selectAll();
521 m_view
->setViewPropertiesContext(QString());
523 // Restore the URL for the URL navigator. If Dolphin has been
524 // started with a search-URL, the home URL is used as fallback.
525 QUrl url
= m_searchBox
->searchPath();
526 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
527 url
= Dolphin::homeUrl();
529 m_urlNavigatorConnected
->setLocationUrl(url
);
532 m_searchModeEnabled
= enabled
;
534 Q_EMIT
searchModeEnabledChanged(enabled
);
537 bool DolphinViewContainer::isSearchModeEnabled() const
539 return m_searchModeEnabled
;
542 QString
DolphinViewContainer::placesText() const
546 if (isSearchModeEnabled()) {
547 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
549 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
550 if (text
.isEmpty()) {
553 if (text
.isEmpty()) {
554 text
= url().scheme();
561 void DolphinViewContainer::reload()
564 m_messageWidget
->hide();
567 QString
DolphinViewContainer::captionWindowTitle() const
569 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
570 if (!url().isLocalFile()) {
571 return url().adjusted(QUrl::StripTrailingSlash
).toString();
573 return url().adjusted(QUrl::StripTrailingSlash
).path();
575 return DolphinViewContainer::caption();
579 QString
DolphinViewContainer::caption() const
581 if (isSearchModeEnabled()) {
582 if (currentSearchText().isEmpty()){
583 return i18n("Search");
585 return i18n("Search for %1", currentSearchText());
589 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
590 const QString pattern
= url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?");
591 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QRegularExpression::anchoredPattern(pattern
), 1, Qt::MatchRegularExpression
);
593 if (!matchedPlaces
.isEmpty()) {
594 return placesModel
->text(matchedPlaces
.first());
598 if (!url().isLocalFile()) {
599 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
601 if (!adjustedUrl
.fileName().isEmpty()) {
602 caption
= adjustedUrl
.fileName();
603 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
604 caption
= adjustedUrl
.path();
605 } else if (!adjustedUrl
.host().isEmpty()) {
606 caption
= adjustedUrl
.host();
608 caption
= adjustedUrl
.toString();
613 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
614 if (fileName
.isEmpty()) {
621 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
623 if (newUrl
!= m_urlNavigator
->locationUrl()) {
624 m_urlNavigator
->setLocationUrl(newUrl
);
628 m_activityResourceInstance
->setUri(newUrl
);
632 void DolphinViewContainer::setFilterBarVisible(bool visible
)
634 Q_ASSERT(m_filterBar
);
636 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
638 m_filterBar
->setFocus();
639 m_filterBar
->selectAll();
645 void DolphinViewContainer::delayedStatusBarUpdate()
647 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
648 // No update of the statusbar has been done during the last 2 seconds,
649 // although an update has been requested. Trigger an immediate update.
650 m_statusBarTimer
->stop();
653 // Invoke updateStatusBar() with a small delay. This assures that
654 // when a lot of delayedStatusBarUpdates() are done in a short time,
655 // no bottleneck is given.
656 m_statusBarTimer
->start();
660 void DolphinViewContainer::updateStatusBar()
662 m_statusBarTimestamp
.start();
663 m_view
->requestStatusBarText();
666 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
668 if (m_statusBar
->progressText().isEmpty()) {
669 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
671 m_statusBar
->setProgress(percent
);
674 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
676 if (m_statusBar
->progressText().isEmpty()) {
677 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
679 m_statusBar
->setProgress(percent
);
682 void DolphinViewContainer::slotDirectoryLoadingStarted()
684 if (isSearchUrl(url())) {
685 // Search KIO-slaves usually don't provide any progress information. Give
686 // a hint to the user that a searching is done:
688 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
689 m_statusBar
->setProgress(-1);
691 // Trigger an undetermined progress indication. The progress
692 // information in percent will be triggered by the percent() signal
693 // of the directory lister later.
694 m_statusBar
->setProgressText(QString());
695 updateDirectoryLoadingProgress(-1);
699 void DolphinViewContainer::slotDirectoryLoadingCompleted()
701 if (!m_statusBar
->progressText().isEmpty()) {
702 m_statusBar
->setProgressText(QString());
703 m_statusBar
->setProgress(100);
706 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
707 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
708 // of showing the default status bar information ("0 items") a more helpful information is given:
709 m_statusBar
->setText(i18nc("@info:status", "No items found."));
715 void DolphinViewContainer::slotDirectoryLoadingCanceled()
717 if (!m_statusBar
->progressText().isEmpty()) {
718 m_statusBar
->setProgressText(QString());
719 m_statusBar
->setProgress(100);
722 m_statusBar
->setText(QString());
725 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
727 const KFileItem
item(url
);
729 // Find out if the file can be opened in the view (for example, this is the
730 // case if the file is an archive). The mime type must be known for that.
731 item
.determineMimeType();
732 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
733 if (!folderUrl
.isEmpty()) {
736 slotItemActivated(item
);
740 void DolphinViewContainer::slotItemActivated(const KFileItem
&item
)
742 // It is possible to activate items on inactive views by
743 // drag & drop operations. Assure that activating an item always
744 // results in an active view.
745 m_view
->setActive(true);
747 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
748 if (!url
.isEmpty()) {
749 const auto modifiers
= QGuiApplication::keyboardModifiers();
750 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
751 if (modifiers
& Qt::ControlModifier
&& modifiers
& Qt::ShiftModifier
) {
752 Q_EMIT
activeTabRequested(url
);
753 } else if (modifiers
& Qt::ControlModifier
) {
754 Q_EMIT
tabRequested(url
);
755 } else if (modifiers
& Qt::ShiftModifier
) {
756 Dolphin::openNewWindow({KFilePlacesModel::convertedUrl(url
)}, this);
763 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl(), item
.mimetype());
764 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoWarningHandlingEnabled
, this));
765 job
->setShowOpenOrExecuteDialog(true);
766 connect(job
, &KIO::OpenUrlJob::finished
, this, &DolphinViewContainer::slotOpenUrlFinished
);
770 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
772 Q_ASSERT(items
.count() >= 2);
774 KFileItemActions
fileItemActions(this);
775 fileItemActions
.runPreferredApplications(items
);
778 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
781 m_statusBar
->resetToDefaultText();
783 m_statusBar
->setText(item
.getStatusBarInfo());
787 void DolphinViewContainer::closeFilterBar()
789 m_filterBar
->closeFilterBar();
791 Q_EMIT
showFilterBarChanged(false);
794 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
796 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
797 m_view
->setNameFilter(nameFilter
);
798 delayedStatusBarUpdate();
801 void DolphinViewContainer::activate()
806 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
811 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
813 if (m_urlNavigatorConnected
) {
814 m_urlNavigatorConnected
->slotReturnPressed();
817 if (KProtocolManager::supportsListing(url
)) {
818 setSearchModeEnabled(isSearchUrl(url
));
820 tryRestoreViewState();
822 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
823 // When an URL has been entered, the view should get the focus.
824 // The focus must be requested asynchronously, as changing the URL might create
825 // a new view widget.
826 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
828 } else if (KProtocolManager::isSourceProtocol(url
)) {
829 if (url
.scheme().startsWith(QLatin1String("http"))) {
830 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
831 "Dolphin does not support web pages, the web browser has been launched"),
834 showMessage(i18nc("@info:status",
835 "Protocol not supported by Dolphin, default application has been launched"),
839 QDesktopServices::openUrl(url
);
840 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
842 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
843 m_urlNavigator
->goBack();
847 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
849 m_view
->markUrlsAsSelected({url
});
850 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
853 void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
855 disconnect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
856 this, &DolphinViewContainer::slotUrlSelectionRequested
);
859 void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
861 connect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
862 this, &DolphinViewContainer::slotUrlSelectionRequested
);
865 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
868 const bool block
= m_urlNavigator
->signalsBlocked();
869 m_urlNavigator
->blockSignals(true);
871 // Assure that the location state is reset for redirection URLs. This
872 // allows to skip redirection URLs when going back or forward in the
874 m_urlNavigator
->saveLocationState(QByteArray());
875 m_urlNavigator
->setLocationUrl(newUrl
);
876 setSearchModeEnabled(isSearchUrl(newUrl
));
878 m_urlNavigator
->blockSignals(block
);
881 void DolphinViewContainer::requestFocus()
886 void DolphinViewContainer::startSearching()
888 Q_CHECK_PTR(m_urlNavigatorConnected
);
889 const QUrl url
= m_searchBox
->urlForSearching();
890 if (url
.isValid() && !url
.isEmpty()) {
891 m_view
->setViewPropertiesContext(QStringLiteral("search"));
892 m_urlNavigatorConnected
->setLocationUrl(url
);
896 void DolphinViewContainer::closeSearchBox()
898 setSearchModeEnabled(false);
901 void DolphinViewContainer::stopDirectoryLoading()
903 m_view
->stopLoading();
904 m_statusBar
->setProgress(100);
907 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
909 m_view
->setZoomLevel(zoomLevel
);
912 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
914 showMessage(msg
, Error
);
917 void DolphinViewContainer::slotPlacesModelChanged()
919 if (!GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
920 Q_EMIT
captionChanged();
924 void DolphinViewContainer::slotHiddenFilesShownChanged(bool showHiddenFiles
)
926 if (m_urlNavigatorConnected
) {
927 m_urlNavigatorConnected
->setShowHiddenFolders(showHiddenFiles
);
931 void DolphinViewContainer::slotSortHiddenLastChanged(bool hiddenLast
)
933 if (m_urlNavigatorConnected
) {
934 m_urlNavigatorConnected
->setSortHiddenFoldersLast(hiddenLast
);
938 void DolphinViewContainer::slotOpenUrlFinished(KJob
*job
)
940 if (job
->error() && job
->error() != KIO::ERR_USER_CANCELED
) {
941 showErrorMessage(job
->errorString());
945 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
947 return url
.scheme().contains(QLatin1String("search"));
950 void DolphinViewContainer::saveViewState()
952 QByteArray locationState
;
953 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
954 m_view
->saveState(stream
);
955 m_urlNavigator
->saveLocationState(locationState
);
958 void DolphinViewContainer::tryRestoreViewState()
960 QByteArray locationState
= m_urlNavigator
->locationState();
961 if (!locationState
.isEmpty()) {
962 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
963 m_view
->restoreState(stream
);