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/JobUiDelegate>
28 #include <KIO/OpenUrlJob>
29 #include <KLocalizedString>
30 #include <KMessageWidget>
31 #include <KProtocolManager>
34 #include <QDesktopServices>
36 #include <QGridLayout>
37 #include <QGuiApplication>
41 // An overview of the widgets contained by this ViewContainer
42 struct LayoutStructure
{
44 int messageWidget
= 1;
45 int selectionModeTopBar
= 2;
47 int selectionModeBottomBar
= 4;
51 constexpr LayoutStructure positionFor
;
53 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
56 m_urlNavigator
{new DolphinUrlNavigator(url
)},
57 m_urlNavigatorConnected
{nullptr},
59 m_searchModeEnabled(false),
60 m_messageWidget(nullptr),
61 m_selectionModeTopBar
{nullptr},
64 m_selectionModeBottomBar
{nullptr},
66 m_statusBarTimer(nullptr),
67 m_statusBarTimestamp(),
70 , m_activityResourceInstance(nullptr)
75 m_topLayout
= new QGridLayout(this);
76 m_topLayout
->setSpacing(0);
77 m_topLayout
->setContentsMargins(0, 0, 0, 0);
79 m_searchBox
= new DolphinSearchBox(this);
81 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
82 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
83 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
84 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
85 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
86 "<para>This helps you find files and folders. Enter a <emphasis>"
87 "search term</emphasis> and specify search settings with the "
88 "buttons at the bottom:<list><item>Filename/Content: "
89 "Does the item you are looking for contain the search terms "
90 "within its filename or its contents?<nl/>The contents of images, "
91 "audio files and videos will not be searched.</item><item>"
92 "From Here/Everywhere: Do you want to search in this "
93 "folder and its sub-folders or everywhere?</item><item>"
94 "More Options: Click this to search by media type, access "
95 "time or rating.</item><item>More Search Tools: Install other "
96 "means to find an item.</item></list></para>"));
98 m_messageWidget
= new KMessageWidget(this);
99 m_messageWidget
->setCloseButtonVisible(true);
100 m_messageWidget
->hide();
105 // We must be logged in as the root user; show a big scary warning
106 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
110 // Initialize filter bar
111 m_filterBar
= new FilterBar(this);
112 m_filterBar
->setVisible(GeneralSettings::filterBar());
114 connect(m_filterBar
, &FilterBar::filterChanged
,
115 this, &DolphinViewContainer::setNameFilter
);
116 connect(m_filterBar
, &FilterBar::closeRequest
,
117 this, &DolphinViewContainer::closeFilterBar
);
118 connect(m_filterBar
, &FilterBar::focusViewRequest
,
119 this, &DolphinViewContainer::requestFocus
);
121 // Initialize the main view
122 m_view
= new DolphinView(url
, this);
123 connect(m_view
, &DolphinView::urlChanged
,
124 m_filterBar
, &FilterBar::slotUrlChanged
);
125 connect(m_view
, &DolphinView::urlChanged
,
126 m_messageWidget
, &KMessageWidget::hide
);
127 // m_urlNavigator stays in sync with m_view's location changes and
128 // keeps track of them so going back and forth in the history works.
129 connect(m_view
, &DolphinView::urlChanged
,
130 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
131 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
,
132 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
133 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlAboutToBeChanged
,
134 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
135 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlSelectionRequested
,
136 this, &DolphinViewContainer::slotUrlSelectionRequested
);
137 connect(m_view
, &DolphinView::writeStateChanged
,
138 this, &DolphinViewContainer::writeStateChanged
);
139 connect(m_view
, &DolphinView::requestItemInfo
,
140 this, &DolphinViewContainer::showItemInfo
);
141 connect(m_view
, &DolphinView::itemActivated
,
142 this, &DolphinViewContainer::slotItemActivated
);
143 connect(m_view
, &DolphinView::itemsActivated
,
144 this, &DolphinViewContainer::slotItemsActivated
);
145 connect(m_view
, &DolphinView::redirection
,
146 this, &DolphinViewContainer::redirect
);
147 connect(m_view
, &DolphinView::directoryLoadingStarted
,
148 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
149 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
150 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
151 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
152 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
153 connect(m_view
, &DolphinView::itemCountChanged
,
154 this, &DolphinViewContainer::delayedStatusBarUpdate
);
155 connect(m_view
, &DolphinView::directoryLoadingProgress
,
156 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
157 connect(m_view
, &DolphinView::directorySortingProgress
,
158 this, &DolphinViewContainer::updateDirectorySortingProgress
);
159 connect(m_view
, &DolphinView::selectionChanged
,
160 this, &DolphinViewContainer::delayedStatusBarUpdate
);
161 connect(m_view
, &DolphinView::errorMessage
,
162 this, &DolphinViewContainer::showErrorMessage
);
163 connect(m_view
, &DolphinView::urlIsFileError
,
164 this, &DolphinViewContainer::slotUrlIsFileError
);
165 connect(m_view
, &DolphinView::activated
,
166 this, &DolphinViewContainer::activate
);
167 connect(m_view
, &DolphinView::hiddenFilesShownChanged
,
168 this, &DolphinViewContainer::slotHiddenFilesShownChanged
);
169 connect(m_view
, &DolphinView::sortHiddenLastChanged
,
170 this, &DolphinViewContainer::slotSortHiddenLastChanged
);
172 // Initialize status bar
173 m_statusBar
= new DolphinStatusBar(this);
174 m_statusBar
->setUrl(m_view
->url());
175 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
176 connect(m_view
, &DolphinView::urlChanged
,
177 m_statusBar
, &DolphinStatusBar::setUrl
);
178 connect(m_view
, &DolphinView::zoomLevelChanged
,
179 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
180 connect(m_view
, &DolphinView::infoMessage
,
181 m_statusBar
, &DolphinStatusBar::setText
);
182 connect(m_view
, &DolphinView::operationCompletedMessage
,
183 m_statusBar
, &DolphinStatusBar::setText
);
184 connect(m_view
, &DolphinView::statusBarTextChanged
,
185 m_statusBar
, &DolphinStatusBar::setDefaultText
);
186 connect(m_view
, &DolphinView::statusBarTextChanged
,
187 m_statusBar
, &DolphinStatusBar::resetToDefaultText
);
188 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
189 this, &DolphinViewContainer::stopDirectoryLoading
);
190 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
191 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
193 m_statusBarTimer
= new QTimer(this);
194 m_statusBarTimer
->setSingleShot(true);
195 m_statusBarTimer
->setInterval(300);
196 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
198 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
199 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
200 this, &DolphinViewContainer::delayedStatusBarUpdate
);
202 m_topLayout
->addWidget(m_searchBox
, positionFor
.searchBox
, 0);
203 m_topLayout
->addWidget(m_messageWidget
, positionFor
.messageWidget
, 0);
204 m_topLayout
->addWidget(m_view
, positionFor
.view
, 0);
205 m_topLayout
->addWidget(m_filterBar
, positionFor
.filterBar
, 0);
206 m_topLayout
->addWidget(m_statusBar
, positionFor
.statusBar
, 0);
208 setSearchModeEnabled(isSearchUrl(url
));
210 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
211 if (view()->viewMode() == DolphinView::Mode::DetailsView
) {
216 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
217 connect(placesModel
, &KFilePlacesModel::dataChanged
,
218 this, &DolphinViewContainer::slotPlacesModelChanged
);
219 connect(placesModel
, &KFilePlacesModel::rowsInserted
,
220 this, &DolphinViewContainer::slotPlacesModelChanged
);
221 connect(placesModel
, &KFilePlacesModel::rowsRemoved
,
222 this, &DolphinViewContainer::slotPlacesModelChanged
);
224 connect(this, &DolphinViewContainer::searchModeEnabledChanged
,
225 this, &DolphinViewContainer::captionChanged
);
227 // Initialize kactivities resource instance
230 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
231 m_activityResourceInstance
->setParent(this);
235 DolphinViewContainer::~DolphinViewContainer()
239 QUrl
DolphinViewContainer::url() const
241 return m_view
->url();
244 void DolphinViewContainer::setActive(bool active
)
246 m_searchBox
->setActive(active
);
247 if (m_urlNavigatorConnected
) {
248 m_urlNavigatorConnected
->setActive(active
);
250 m_view
->setActive(active
);
254 m_activityResourceInstance
->notifyFocusedIn();
256 m_activityResourceInstance
->notifyFocusedOut();
261 bool DolphinViewContainer::isActive() const
263 return m_view
->isActive();
266 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
268 m_autoGrabFocus
= grab
;
271 bool DolphinViewContainer::autoGrabFocus() const
273 return m_autoGrabFocus
;
276 QString
DolphinViewContainer::currentSearchText() const
278 return m_searchBox
->text();
281 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
286 DolphinStatusBar
* DolphinViewContainer::statusBar()
291 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
293 return m_urlNavigatorConnected
;
296 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
298 return m_urlNavigatorConnected
;
301 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
303 return m_urlNavigator
.get();
306 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
308 return m_urlNavigator
.get();
311 const DolphinView
* DolphinViewContainer::view() const
316 DolphinView
* DolphinViewContainer::view()
321 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
323 Q_CHECK_PTR(urlNavigator
);
324 Q_ASSERT(!m_urlNavigatorConnected
);
325 Q_ASSERT(m_urlNavigator
.get() != urlNavigator
);
328 urlNavigator
->setLocationUrl(m_view
->url());
329 urlNavigator
->setShowHiddenFolders(m_view
->hiddenFilesShown());
330 urlNavigator
->setSortHiddenFoldersLast(m_view
->sortHiddenLast());
331 if (m_urlNavigatorVisualState
) {
332 urlNavigator
->setVisualState(*m_urlNavigatorVisualState
.get());
333 m_urlNavigatorVisualState
.reset();
335 urlNavigator
->setActive(isActive());
337 // Url changes are still done via m_urlNavigator.
338 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
339 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
340 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
,
341 this, [=](const QUrl
&destination
, QDropEvent
*event
) {
342 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
344 // Aside from these, only visual things need to be connected.
345 connect(m_view
, &DolphinView::urlChanged
,
346 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
347 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
348 this, &DolphinViewContainer::activate
);
350 m_urlNavigatorConnected
= urlNavigator
;
353 void DolphinViewContainer::disconnectUrlNavigator()
355 if (!m_urlNavigatorConnected
) {
359 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
360 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
361 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
363 disconnect(m_view
, &DolphinView::urlChanged
,
364 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
365 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
366 this, &DolphinViewContainer::activate
);
368 m_urlNavigatorVisualState
= m_urlNavigatorConnected
->visualState();
369 m_urlNavigatorConnected
= nullptr;
372 void DolphinViewContainer::setSelectionModeEnabled(bool enabled
, KActionCollection
*actionCollection
, SelectionMode::BottomBar::Contents bottomBarContents
)
374 const bool wasEnabled
= m_view
->selectionMode();
375 m_view
->setSelectionModeEnabled(enabled
);
379 return; // nothing to do here
381 Q_CHECK_PTR(m_selectionModeTopBar
); // there is no point in disabling selectionMode when it wasn't even enabled once.
382 Q_CHECK_PTR(m_selectionModeBottomBar
);
383 m_selectionModeTopBar
->setVisible(false, WithAnimation
);
384 m_selectionModeBottomBar
->setVisible(false, WithAnimation
);
385 Q_EMIT
selectionModeChanged(false);
389 if (!m_selectionModeTopBar
) {
390 // Changing the location will disable selection mode.
391 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
, this, [this]() {
392 setSelectionModeEnabled(false);
395 m_selectionModeTopBar
= new SelectionMode::TopBar(this); // will be created hidden
396 connect(m_selectionModeTopBar
, &SelectionMode::TopBar::selectionModeLeavingRequested
, this, [this]() {
397 setSelectionModeEnabled(false);
399 m_topLayout
->addWidget(m_selectionModeTopBar
, positionFor
.selectionModeTopBar
, 0);
402 if (!m_selectionModeBottomBar
) {
403 m_selectionModeBottomBar
= new SelectionMode::BottomBar(actionCollection
, this);
404 connect(m_view
, &DolphinView::selectionChanged
, this, [this](const KFileItemList
&selection
) {
405 m_selectionModeBottomBar
->slotSelectionChanged(selection
, m_view
->url());
407 connect(m_selectionModeBottomBar
, &SelectionMode::BottomBar::error
, this, [this](const QString
&errorMessage
) {
408 showErrorMessage(errorMessage
);
410 connect(m_selectionModeBottomBar
, &SelectionMode::BottomBar::selectionModeLeavingRequested
, this, [this]() {
411 setSelectionModeEnabled(false);
413 m_topLayout
->addWidget(m_selectionModeBottomBar
, positionFor
.selectionModeBottomBar
, 0);
415 m_selectionModeBottomBar
->resetContents(bottomBarContents
);
416 if (bottomBarContents
== SelectionMode::BottomBar::GeneralContents
) {
417 m_selectionModeBottomBar
->slotSelectionChanged(m_view
->selectedItems(), m_view
->url());
421 m_selectionModeTopBar
->setVisible(true, WithAnimation
);
422 m_selectionModeBottomBar
->setVisible(true, WithAnimation
);
423 Q_EMIT
selectionModeChanged(true);
427 bool DolphinViewContainer::isSelectionModeEnabled() const
429 const bool isEnabled
= m_view
->selectionMode();
431 // We can't assert that the bars are invisible only because the selection mode is disabled because the hide animation might still be playing.
432 && (!m_selectionModeBottomBar
|| !m_selectionModeBottomBar
->isEnabled() ||
433 !m_selectionModeBottomBar
->isVisible() || m_selectionModeBottomBar
->contents() == SelectionMode::BottomBar::PasteContents
))
435 && m_selectionModeTopBar
&& m_selectionModeTopBar
->isVisible()
436 // 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.
437 && m_selectionModeBottomBar
438 && (m_selectionModeBottomBar
->isVisible() || m_selectionModeBottomBar
->contents() == SelectionMode::BottomBar::GeneralContents
)));
442 void DolphinViewContainer::slotSplitTabDisabled()
444 if (m_selectionModeBottomBar
) {
445 m_selectionModeBottomBar
->slotSplitTabDisabled();
450 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
456 m_messageWidget
->setText(msg
);
458 // TODO: wrap at arbitrary character positions once QLabel can do this
459 // https://bugreports.qt.io/browse/QTBUG-1276
460 m_messageWidget
->setWordWrap(true);
463 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
464 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
465 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
471 m_messageWidget
->setWordWrap(false);
472 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
473 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
475 if (m_messageWidget
->isVisible()) {
476 m_messageWidget
->hide();
478 m_messageWidget
->animatedShow();
481 void DolphinViewContainer::readSettings()
483 // The startup settings should (only) get applied if they have been
484 // modified by the user. Otherwise keep the (possibly) different current
485 // setting of the filterbar.
486 if (GeneralSettings::modifiedStartupSettings()) {
487 setFilterBarVisible(GeneralSettings::filterBar());
490 m_view
->readSettings();
491 m_statusBar
->readSettings();
494 bool DolphinViewContainer::isFilterBarVisible() const
496 return m_filterBar
->isVisible();
499 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
501 m_searchBox
->setVisible(enabled
);
504 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
505 m_searchBox
->fromSearchUrl(locationUrl
);
508 if (enabled
== isSearchModeEnabled()) {
509 if (enabled
&& !m_searchBox
->hasFocus()) {
510 m_searchBox
->setFocus();
511 m_searchBox
->selectAll();
517 m_view
->setViewPropertiesContext(QString());
519 // Restore the URL for the URL navigator. If Dolphin has been
520 // started with a search-URL, the home URL is used as fallback.
521 QUrl url
= m_searchBox
->searchPath();
522 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
523 url
= Dolphin::homeUrl();
525 m_urlNavigatorConnected
->setLocationUrl(url
);
528 m_searchModeEnabled
= enabled
;
530 Q_EMIT
searchModeEnabledChanged(enabled
);
533 bool DolphinViewContainer::isSearchModeEnabled() const
535 return m_searchModeEnabled
;
538 QString
DolphinViewContainer::placesText() const
542 if (isSearchModeEnabled()) {
543 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
545 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
546 if (text
.isEmpty()) {
549 if (text
.isEmpty()) {
550 text
= url().scheme();
557 void DolphinViewContainer::reload()
560 m_messageWidget
->hide();
563 QString
DolphinViewContainer::captionWindowTitle() const
565 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
566 if (!url().isLocalFile()) {
567 return url().adjusted(QUrl::StripTrailingSlash
).toString();
569 return url().adjusted(QUrl::StripTrailingSlash
).path();
571 return DolphinViewContainer::caption();
575 QString
DolphinViewContainer::caption() const
577 if (isSearchModeEnabled()) {
578 if (currentSearchText().isEmpty()){
579 return i18n("Search");
581 return i18n("Search for %1", currentSearchText());
585 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
586 const QString pattern
= url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?");
587 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QRegularExpression::anchoredPattern(pattern
), 1, Qt::MatchRegularExpression
);
589 if (!matchedPlaces
.isEmpty()) {
590 return placesModel
->text(matchedPlaces
.first());
594 if (!url().isLocalFile()) {
595 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
597 if (!adjustedUrl
.fileName().isEmpty()) {
598 caption
= adjustedUrl
.fileName();
599 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
600 caption
= adjustedUrl
.path();
601 } else if (!adjustedUrl
.host().isEmpty()) {
602 caption
= adjustedUrl
.host();
604 caption
= adjustedUrl
.toString();
609 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
610 if (fileName
.isEmpty()) {
617 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
619 if (newUrl
!= m_urlNavigator
->locationUrl()) {
620 m_urlNavigator
->setLocationUrl(newUrl
);
624 m_activityResourceInstance
->setUri(newUrl
);
628 void DolphinViewContainer::setFilterBarVisible(bool visible
)
630 Q_ASSERT(m_filterBar
);
632 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
634 m_filterBar
->setFocus();
635 m_filterBar
->selectAll();
641 void DolphinViewContainer::delayedStatusBarUpdate()
643 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
644 // No update of the statusbar has been done during the last 2 seconds,
645 // although an update has been requested. Trigger an immediate update.
646 m_statusBarTimer
->stop();
649 // Invoke updateStatusBar() with a small delay. This assures that
650 // when a lot of delayedStatusBarUpdates() are done in a short time,
651 // no bottleneck is given.
652 m_statusBarTimer
->start();
656 void DolphinViewContainer::updateStatusBar()
658 m_statusBarTimestamp
.start();
659 m_view
->requestStatusBarText();
662 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
664 if (m_statusBar
->progressText().isEmpty()) {
665 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
667 m_statusBar
->setProgress(percent
);
670 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
672 if (m_statusBar
->progressText().isEmpty()) {
673 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
675 m_statusBar
->setProgress(percent
);
678 void DolphinViewContainer::slotDirectoryLoadingStarted()
680 if (isSearchUrl(url())) {
681 // Search KIO-slaves usually don't provide any progress information. Give
682 // a hint to the user that a searching is done:
684 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
685 m_statusBar
->setProgress(-1);
687 // Trigger an undetermined progress indication. The progress
688 // information in percent will be triggered by the percent() signal
689 // of the directory lister later.
690 m_statusBar
->setProgressText(QString());
691 updateDirectoryLoadingProgress(-1);
695 void DolphinViewContainer::slotDirectoryLoadingCompleted()
697 if (!m_statusBar
->progressText().isEmpty()) {
698 m_statusBar
->setProgressText(QString());
699 m_statusBar
->setProgress(100);
702 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
703 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
704 // of showing the default status bar information ("0 items") a more helpful information is given:
705 m_statusBar
->setText(i18nc("@info:status", "No items found."));
711 void DolphinViewContainer::slotDirectoryLoadingCanceled()
713 if (!m_statusBar
->progressText().isEmpty()) {
714 m_statusBar
->setProgressText(QString());
715 m_statusBar
->setProgress(100);
718 m_statusBar
->setText(QString());
721 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
723 const KFileItem
item(url
);
725 // Find out if the file can be opened in the view (for example, this is the
726 // case if the file is an archive). The mime type must be known for that.
727 item
.determineMimeType();
728 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
729 if (!folderUrl
.isEmpty()) {
732 slotItemActivated(item
);
736 void DolphinViewContainer::slotItemActivated(const KFileItem
&item
)
738 // It is possible to activate items on inactive views by
739 // drag & drop operations. Assure that activating an item always
740 // results in an active view.
741 m_view
->setActive(true);
743 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
744 if (!url
.isEmpty()) {
745 const auto modifiers
= QGuiApplication::keyboardModifiers();
746 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
747 if (modifiers
& Qt::ControlModifier
&& modifiers
& Qt::ShiftModifier
) {
748 Q_EMIT
activeTabRequested(url
);
749 } else if (modifiers
& Qt::ControlModifier
) {
750 Q_EMIT
tabRequested(url
);
751 } else if (modifiers
& Qt::ShiftModifier
) {
752 Dolphin::openNewWindow({KFilePlacesModel::convertedUrl(url
)}, this);
759 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl(), item
.mimetype());
760 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoWarningHandlingEnabled
, this));
761 job
->setShowOpenOrExecuteDialog(true);
762 connect(job
, &KIO::OpenUrlJob::finished
, this, &DolphinViewContainer::slotOpenUrlFinished
);
766 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
768 Q_ASSERT(items
.count() >= 2);
770 KFileItemActions
fileItemActions(this);
771 fileItemActions
.runPreferredApplications(items
);
774 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
777 m_statusBar
->resetToDefaultText();
779 m_statusBar
->setText(item
.getStatusBarInfo());
783 void DolphinViewContainer::closeFilterBar()
785 m_filterBar
->closeFilterBar();
787 Q_EMIT
showFilterBarChanged(false);
790 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
792 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
793 m_view
->setNameFilter(nameFilter
);
794 delayedStatusBarUpdate();
797 void DolphinViewContainer::activate()
802 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
807 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
809 if (m_urlNavigatorConnected
) {
810 m_urlNavigatorConnected
->slotReturnPressed();
813 if (KProtocolManager::supportsListing(url
)) {
814 setSearchModeEnabled(isSearchUrl(url
));
816 tryRestoreViewState();
818 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
819 // When an URL has been entered, the view should get the focus.
820 // The focus must be requested asynchronously, as changing the URL might create
821 // a new view widget.
822 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
824 } else if (KProtocolManager::isSourceProtocol(url
)) {
825 if (url
.scheme().startsWith(QLatin1String("http"))) {
826 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
827 "Dolphin does not support web pages, the web browser has been launched"),
830 showMessage(i18nc("@info:status",
831 "Protocol not supported by Dolphin, default application has been launched"),
835 QDesktopServices::openUrl(url
);
836 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
838 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
839 m_urlNavigator
->goBack();
843 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
845 m_view
->markUrlsAsSelected({url
});
846 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
849 void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
851 disconnect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
852 this, &DolphinViewContainer::slotUrlSelectionRequested
);
855 void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
857 connect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
858 this, &DolphinViewContainer::slotUrlSelectionRequested
);
861 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
864 const bool block
= m_urlNavigator
->signalsBlocked();
865 m_urlNavigator
->blockSignals(true);
867 // Assure that the location state is reset for redirection URLs. This
868 // allows to skip redirection URLs when going back or forward in the
870 m_urlNavigator
->saveLocationState(QByteArray());
871 m_urlNavigator
->setLocationUrl(newUrl
);
872 setSearchModeEnabled(isSearchUrl(newUrl
));
874 m_urlNavigator
->blockSignals(block
);
877 void DolphinViewContainer::requestFocus()
882 void DolphinViewContainer::startSearching()
884 Q_CHECK_PTR(m_urlNavigatorConnected
);
885 const QUrl url
= m_searchBox
->urlForSearching();
886 if (url
.isValid() && !url
.isEmpty()) {
887 m_view
->setViewPropertiesContext(QStringLiteral("search"));
888 m_urlNavigatorConnected
->setLocationUrl(url
);
892 void DolphinViewContainer::closeSearchBox()
894 setSearchModeEnabled(false);
897 void DolphinViewContainer::stopDirectoryLoading()
899 m_view
->stopLoading();
900 m_statusBar
->setProgress(100);
903 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
905 m_view
->setZoomLevel(zoomLevel
);
908 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
910 showMessage(msg
, Error
);
913 void DolphinViewContainer::slotPlacesModelChanged()
915 if (!GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
916 Q_EMIT
captionChanged();
920 void DolphinViewContainer::slotHiddenFilesShownChanged(bool showHiddenFiles
)
922 if (m_urlNavigatorConnected
) {
923 m_urlNavigatorConnected
->setShowHiddenFolders(showHiddenFiles
);
927 void DolphinViewContainer::slotSortHiddenLastChanged(bool hiddenLast
)
929 if (m_urlNavigatorConnected
) {
930 m_urlNavigatorConnected
->setSortHiddenFoldersLast(hiddenLast
);
934 void DolphinViewContainer::slotOpenUrlFinished(KJob
*job
)
936 if (job
->error() && job
->error() != KIO::ERR_USER_CANCELED
) {
937 showErrorMessage(job
->errorString());
941 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
943 return url
.scheme().contains(QLatin1String("search"));
946 void DolphinViewContainer::saveViewState()
948 QByteArray locationState
;
949 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
950 m_view
->saveState(stream
);
951 m_urlNavigator
->saveLocationState(locationState
);
954 void DolphinViewContainer::tryRestoreViewState()
956 QByteArray locationState
= m_urlNavigator
->locationState();
957 if (!locationState
.isEmpty()) {
958 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
959 m_view
->restoreState(stream
);