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/selectionmodetopbar.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>
47 // An overview of the widgets contained by this ViewContainer
48 struct LayoutStructure
{
50 int messageWidget
= 1;
51 int selectionModeTopBar
= 2;
53 int selectionModeBottomBar
= 4;
57 constexpr LayoutStructure positionFor
;
59 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
62 m_urlNavigator
{new DolphinUrlNavigator(url
)},
63 m_urlNavigatorConnected
{nullptr},
65 m_searchModeEnabled(false),
66 m_messageWidget(nullptr),
67 m_selectionModeTopBar
{nullptr},
70 m_selectionModeBottomBar
{nullptr},
72 m_statusBarTimer(nullptr),
73 m_statusBarTimestamp(),
76 , m_activityResourceInstance(nullptr)
81 m_topLayout
= new QGridLayout(this);
82 m_topLayout
->setSpacing(0);
83 m_topLayout
->setContentsMargins(0, 0, 0, 0);
85 m_searchBox
= new DolphinSearchBox(this);
87 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
88 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
89 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
90 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
91 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
92 "<para>This helps you find files and folders. Enter a <emphasis>"
93 "search term</emphasis> and specify search settings with the "
94 "buttons at the bottom:<list><item>Filename/Content: "
95 "Does the item you are looking for contain the search terms "
96 "within its filename or its contents?<nl/>The contents of images, "
97 "audio files and videos will not be searched.</item><item>"
98 "From Here/Everywhere: Do you want to search in this "
99 "folder and its sub-folders or everywhere?</item><item>"
100 "More Options: Click this to search by media type, access "
101 "time or rating.</item><item>More Search Tools: Install other "
102 "means to find an item.</item></list></para>"));
104 m_messageWidget
= new KMessageWidget(this);
105 m_messageWidget
->setCloseButtonVisible(true);
106 m_messageWidget
->hide();
111 // We must be logged in as the root user; show a big scary warning
112 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
116 // Initialize filter bar
117 m_filterBar
= new FilterBar(this);
118 m_filterBar
->setVisible(GeneralSettings::filterBar());
120 connect(m_filterBar
, &FilterBar::filterChanged
,
121 this, &DolphinViewContainer::setNameFilter
);
122 connect(m_filterBar
, &FilterBar::closeRequest
,
123 this, &DolphinViewContainer::closeFilterBar
);
124 connect(m_filterBar
, &FilterBar::focusViewRequest
,
125 this, &DolphinViewContainer::requestFocus
);
127 // Initialize the main view
128 m_view
= new DolphinView(url
, this);
129 connect(m_view
, &DolphinView::urlChanged
,
130 m_filterBar
, &FilterBar::slotUrlChanged
);
131 connect(m_view
, &DolphinView::urlChanged
,
132 m_messageWidget
, &KMessageWidget::hide
);
133 // m_urlNavigator stays in sync with m_view's location changes and
134 // keeps track of them so going back and forth in the history works.
135 connect(m_view
, &DolphinView::urlChanged
,
136 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
137 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
,
138 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
139 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlAboutToBeChanged
,
140 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
141 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlSelectionRequested
,
142 this, &DolphinViewContainer::slotUrlSelectionRequested
);
143 connect(m_view
, &DolphinView::writeStateChanged
,
144 this, &DolphinViewContainer::writeStateChanged
);
145 connect(m_view
, &DolphinView::requestItemInfo
,
146 this, &DolphinViewContainer::showItemInfo
);
147 connect(m_view
, &DolphinView::itemActivated
,
148 this, &DolphinViewContainer::slotItemActivated
);
149 connect(m_view
, &DolphinView::itemsActivated
,
150 this, &DolphinViewContainer::slotItemsActivated
);
151 connect(m_view
, &DolphinView::redirection
,
152 this, &DolphinViewContainer::redirect
);
153 connect(m_view
, &DolphinView::directoryLoadingStarted
,
154 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
155 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
156 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
157 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
158 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
159 connect(m_view
, &DolphinView::itemCountChanged
,
160 this, &DolphinViewContainer::delayedStatusBarUpdate
);
161 connect(m_view
, &DolphinView::directoryLoadingProgress
,
162 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
163 connect(m_view
, &DolphinView::directorySortingProgress
,
164 this, &DolphinViewContainer::updateDirectorySortingProgress
);
165 connect(m_view
, &DolphinView::selectionChanged
,
166 this, &DolphinViewContainer::delayedStatusBarUpdate
);
167 connect(m_view
, &DolphinView::errorMessage
,
168 this, &DolphinViewContainer::showErrorMessage
);
169 connect(m_view
, &DolphinView::urlIsFileError
,
170 this, &DolphinViewContainer::slotUrlIsFileError
);
171 connect(m_view
, &DolphinView::activated
,
172 this, &DolphinViewContainer::activate
);
173 connect(m_view
, &DolphinView::hiddenFilesShownChanged
,
174 this, &DolphinViewContainer::slotHiddenFilesShownChanged
);
175 connect(m_view
, &DolphinView::sortHiddenLastChanged
,
176 this, &DolphinViewContainer::slotSortHiddenLastChanged
);
178 // Initialize status bar
179 m_statusBar
= new DolphinStatusBar(this);
180 m_statusBar
->setUrl(m_view
->url());
181 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
182 connect(m_view
, &DolphinView::urlChanged
,
183 m_statusBar
, &DolphinStatusBar::setUrl
);
184 connect(m_view
, &DolphinView::zoomLevelChanged
,
185 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
186 connect(m_view
, &DolphinView::infoMessage
,
187 m_statusBar
, &DolphinStatusBar::setText
);
188 connect(m_view
, &DolphinView::operationCompletedMessage
,
189 m_statusBar
, &DolphinStatusBar::setText
);
190 connect(m_view
, &DolphinView::statusBarTextChanged
,
191 m_statusBar
, &DolphinStatusBar::setDefaultText
);
192 connect(m_view
, &DolphinView::statusBarTextChanged
,
193 m_statusBar
, &DolphinStatusBar::resetToDefaultText
);
194 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
195 this, &DolphinViewContainer::stopDirectoryLoading
);
196 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
197 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
199 m_statusBarTimer
= new QTimer(this);
200 m_statusBarTimer
->setSingleShot(true);
201 m_statusBarTimer
->setInterval(300);
202 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
204 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
205 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
206 this, &DolphinViewContainer::delayedStatusBarUpdate
);
208 m_topLayout
->addWidget(m_searchBox
, positionFor
.searchBox
, 0);
209 m_topLayout
->addWidget(m_messageWidget
, positionFor
.messageWidget
, 0);
210 m_topLayout
->addWidget(m_view
, positionFor
.view
, 0);
211 m_topLayout
->addWidget(m_filterBar
, positionFor
.filterBar
, 0);
212 m_topLayout
->addWidget(m_statusBar
, positionFor
.statusBar
, 0);
214 setSearchModeEnabled(isSearchUrl(url
));
216 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
217 if (view()->viewMode() == DolphinView::Mode::DetailsView
) {
222 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
223 connect(placesModel
, &KFilePlacesModel::dataChanged
,
224 this, &DolphinViewContainer::slotPlacesModelChanged
);
225 connect(placesModel
, &KFilePlacesModel::rowsInserted
,
226 this, &DolphinViewContainer::slotPlacesModelChanged
);
227 connect(placesModel
, &KFilePlacesModel::rowsRemoved
,
228 this, &DolphinViewContainer::slotPlacesModelChanged
);
230 connect(this, &DolphinViewContainer::searchModeEnabledChanged
,
231 this, &DolphinViewContainer::captionChanged
);
233 // Initialize kactivities resource instance
236 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
237 m_activityResourceInstance
->setParent(this);
241 DolphinViewContainer::~DolphinViewContainer()
245 QUrl
DolphinViewContainer::url() const
247 return m_view
->url();
250 void DolphinViewContainer::setActive(bool active
)
252 m_searchBox
->setActive(active
);
253 if (m_urlNavigatorConnected
) {
254 m_urlNavigatorConnected
->setActive(active
);
256 m_view
->setActive(active
);
260 m_activityResourceInstance
->notifyFocusedIn();
262 m_activityResourceInstance
->notifyFocusedOut();
267 bool DolphinViewContainer::isActive() const
269 return m_view
->isActive();
272 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
274 m_autoGrabFocus
= grab
;
277 bool DolphinViewContainer::autoGrabFocus() const
279 return m_autoGrabFocus
;
282 QString
DolphinViewContainer::currentSearchText() const
284 return m_searchBox
->text();
287 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
292 DolphinStatusBar
* DolphinViewContainer::statusBar()
297 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
299 return m_urlNavigatorConnected
;
302 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
304 return m_urlNavigatorConnected
;
307 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
309 return m_urlNavigator
.get();
312 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
314 return m_urlNavigator
.get();
317 const DolphinView
* DolphinViewContainer::view() const
322 DolphinView
* DolphinViewContainer::view()
327 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
329 Q_CHECK_PTR(urlNavigator
);
330 Q_ASSERT(!m_urlNavigatorConnected
);
331 Q_ASSERT(m_urlNavigator
.get() != urlNavigator
);
334 urlNavigator
->setLocationUrl(m_view
->url());
335 urlNavigator
->setShowHiddenFolders(m_view
->hiddenFilesShown());
336 urlNavigator
->setSortHiddenFoldersLast(m_view
->sortHiddenLast());
337 if (m_urlNavigatorVisualState
) {
338 urlNavigator
->setVisualState(*m_urlNavigatorVisualState
.get());
339 m_urlNavigatorVisualState
.reset();
341 urlNavigator
->setActive(isActive());
343 // Url changes are still done via m_urlNavigator.
344 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
345 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
346 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
,
347 this, [=](const QUrl
&destination
, QDropEvent
*event
) {
348 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
350 // Aside from these, only visual things need to be connected.
351 connect(m_view
, &DolphinView::urlChanged
,
352 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
353 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
354 this, &DolphinViewContainer::activate
);
356 m_urlNavigatorConnected
= urlNavigator
;
359 void DolphinViewContainer::disconnectUrlNavigator()
361 if (!m_urlNavigatorConnected
) {
365 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
366 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
367 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
369 disconnect(m_view
, &DolphinView::urlChanged
,
370 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
371 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
372 this, &DolphinViewContainer::activate
);
374 m_urlNavigatorVisualState
= m_urlNavigatorConnected
->visualState();
375 m_urlNavigatorConnected
= nullptr;
378 void DolphinViewContainer::setSelectionModeEnabled(bool enabled
, KActionCollection
*actionCollection
, SelectionModeBottomBar::Contents bottomBarContents
)
380 std::cout
<< "DolphinViewContainer::setSelectionModeEnabled(" << enabled
<< ", " << bottomBarContents
<< ")\n";
381 const bool wasEnabled
= m_view
->selectionMode();
382 m_view
->setSelectionMode(enabled
);
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
);
390 Q_EMIT
selectionModeChanged(false);
395 if (!m_selectionModeTopBar
) {
396 // Changing the location will disable selection mode.
397 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
, this, [this]() {
398 setSelectionModeEnabled(false);
401 m_selectionModeTopBar
= new SelectionModeTopBar(this); // will be created hidden
402 connect(m_selectionModeTopBar
, &SelectionModeTopBar::leaveSelectionModeRequested
, this, [this]() {
403 setSelectionModeEnabled(false);
405 m_topLayout
->addWidget(m_selectionModeTopBar
, positionFor
.selectionModeTopBar
, 0);
408 if (!m_selectionModeBottomBar
) {
409 m_selectionModeBottomBar
= new SelectionModeBottomBar(actionCollection
, this);
410 connect(m_view
, &DolphinView::selectionChanged
, this, [this](const KFileItemList
&selection
) {
411 m_selectionModeBottomBar
->slotSelectionChanged(selection
, m_view
->url());
414 connect(m_selectionModeBottomBar
, &SelectionModeBottomBar::error
, this, [this](const QString
&errorMessage
) {
415 showErrorMessage(errorMessage
);
417 connect(m_selectionModeBottomBar
, &SelectionModeBottomBar::leaveSelectionModeRequested
, this, [this]() {
418 setSelectionModeEnabled(false);
420 m_topLayout
->addWidget(m_selectionModeBottomBar
, positionFor
.selectionModeBottomBar
, 0);
422 m_selectionModeBottomBar
->resetContents(bottomBarContents
);
423 if (bottomBarContents
== SelectionModeBottomBar::GeneralContents
) {
424 m_selectionModeBottomBar
->slotSelectionChanged(m_view
->selectedItems(), m_view
->url());
428 m_selectionModeTopBar
->setVisible(true, WithAnimation
);
429 m_selectionModeBottomBar
->setVisible(true, WithAnimation
);
430 Q_EMIT
selectionModeChanged(true);
434 bool DolphinViewContainer::isSelectionModeEnabled() const
436 const bool isEnabled
= m_view
->selectionMode();
437 Q_ASSERT( !isEnabled
// We cannot assert the invisibility of the bars because of the hide animation.
438 || ( isEnabled
&& m_selectionModeTopBar
&& m_selectionModeTopBar
->isVisible() && m_selectionModeBottomBar
&& m_selectionModeBottomBar
->isVisible()));
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
);