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 "statusbar/dolphinstatusbar.h"
16 #include "views/viewmodecontroller.h"
17 #include "views/viewproperties.h"
18 #include "dolphin_detailsmodesettings.h"
20 #ifdef HAVE_KACTIVITIES
21 #include <KActivities/ResourceInstance>
23 #include <KFileItemActions>
24 #include <KFilePlacesModel>
25 #include <KIO/PreviewJob>
26 #include <KIO/OpenUrlJob>
27 #include <KIO/JobUiDelegate>
28 #include <KLocalizedString>
29 #include <KMessageWidget>
30 #include <KProtocolManager>
32 #include <KUrlComboBox>
35 #include <QLoggingCategory>
39 #include <QVBoxLayout>
40 #include <QDesktopServices>
42 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
45 m_urlNavigator
{new DolphinUrlNavigator(url
)},
46 m_urlNavigatorConnected
{nullptr},
48 m_searchModeEnabled(false),
49 m_messageWidget(nullptr),
53 m_statusBarTimer(nullptr),
54 m_statusBarTimestamp(),
56 #ifdef HAVE_KACTIVITIES
57 , m_activityResourceInstance(nullptr)
62 m_topLayout
= new QVBoxLayout(this);
63 m_topLayout
->setSpacing(0);
64 m_topLayout
->setContentsMargins(0, 0, 0, 0);
66 m_searchBox
= new DolphinSearchBox(this);
68 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
69 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
70 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
71 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
72 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
73 "<para>This helps you find files and folders. Enter a <emphasis>"
74 "search term</emphasis> and specify search settings with the "
75 "buttons at the bottom:<list><item>Filename/Content: "
76 "Does the item you are looking for contain the search terms "
77 "within its filename or its contents?<nl/>The contents of images, "
78 "audio files and videos will not be searched.</item><item>"
79 "From Here/Everywhere: Do you want to search in this "
80 "folder and its sub-folders or everywhere?</item><item>"
81 "More Options: Click this to search by media type, access "
82 "time or rating.</item><item>More Search Tools: Install other "
83 "means to find an item.</item></list></para>"));
85 m_messageWidget
= new KMessageWidget(this);
86 m_messageWidget
->setCloseButtonVisible(true);
87 m_messageWidget
->hide();
92 // We must be logged in as the root user; show a big scary warning
93 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
97 // Initialize filter bar
98 m_filterBar
= new FilterBar(this);
99 m_filterBar
->setVisible(GeneralSettings::filterBar());
101 connect(m_filterBar
, &FilterBar::filterChanged
,
102 this, &DolphinViewContainer::setNameFilter
);
103 connect(m_filterBar
, &FilterBar::closeRequest
,
104 this, &DolphinViewContainer::closeFilterBar
);
105 connect(m_filterBar
, &FilterBar::focusViewRequest
,
106 this, &DolphinViewContainer::requestFocus
);
108 // Initialize the main view
109 m_view
= new DolphinView(url
, this);
110 connect(m_view
, &DolphinView::urlChanged
,
111 m_filterBar
, &FilterBar::slotUrlChanged
);
112 connect(m_view
, &DolphinView::urlChanged
,
113 m_messageWidget
, &KMessageWidget::hide
);
114 // m_urlNavigator stays in sync with m_view's location changes and
115 // keeps track of them so going back and forth in the history works.
116 connect(m_view
, &DolphinView::urlChanged
,
117 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
118 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
,
119 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
120 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlAboutToBeChanged
,
121 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
122 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlSelectionRequested
,
123 this, &DolphinViewContainer::slotUrlSelectionRequested
);
124 connect(m_view
, &DolphinView::writeStateChanged
,
125 this, &DolphinViewContainer::writeStateChanged
);
126 connect(m_view
, &DolphinView::requestItemInfo
,
127 this, &DolphinViewContainer::showItemInfo
);
128 connect(m_view
, &DolphinView::itemActivated
,
129 this, &DolphinViewContainer::slotItemActivated
);
130 connect(m_view
, &DolphinView::itemsActivated
,
131 this, &DolphinViewContainer::slotItemsActivated
);
132 connect(m_view
, &DolphinView::redirection
,
133 this, &DolphinViewContainer::redirect
);
134 connect(m_view
, &DolphinView::directoryLoadingStarted
,
135 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
136 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
137 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
138 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
139 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
140 connect(m_view
, &DolphinView::itemCountChanged
,
141 this, &DolphinViewContainer::delayedStatusBarUpdate
);
142 connect(m_view
, &DolphinView::directoryLoadingProgress
,
143 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
144 connect(m_view
, &DolphinView::directorySortingProgress
,
145 this, &DolphinViewContainer::updateDirectorySortingProgress
);
146 connect(m_view
, &DolphinView::selectionChanged
,
147 this, &DolphinViewContainer::delayedStatusBarUpdate
);
148 connect(m_view
, &DolphinView::errorMessage
,
149 this, &DolphinViewContainer::showErrorMessage
);
150 connect(m_view
, &DolphinView::urlIsFileError
,
151 this, &DolphinViewContainer::slotUrlIsFileError
);
152 connect(m_view
, &DolphinView::activated
,
153 this, &DolphinViewContainer::activate
);
155 // Initialize status bar
156 m_statusBar
= new DolphinStatusBar(this);
157 m_statusBar
->setUrl(m_view
->url());
158 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
159 connect(m_view
, &DolphinView::urlChanged
,
160 m_statusBar
, &DolphinStatusBar::setUrl
);
161 connect(m_view
, &DolphinView::zoomLevelChanged
,
162 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
163 connect(m_view
, &DolphinView::infoMessage
,
164 m_statusBar
, &DolphinStatusBar::setText
);
165 connect(m_view
, &DolphinView::operationCompletedMessage
,
166 m_statusBar
, &DolphinStatusBar::setText
);
167 connect(m_view
, &DolphinView::statusBarTextChanged
,
168 m_statusBar
, &DolphinStatusBar::setDefaultText
);
169 connect(m_view
, &DolphinView::statusBarTextChanged
,
170 m_statusBar
, &DolphinStatusBar::resetToDefaultText
);
171 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
172 this, &DolphinViewContainer::stopDirectoryLoading
);
173 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
174 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
176 m_statusBarTimer
= new QTimer(this);
177 m_statusBarTimer
->setSingleShot(true);
178 m_statusBarTimer
->setInterval(300);
179 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
181 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
182 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
183 this, &DolphinViewContainer::delayedStatusBarUpdate
);
185 m_topLayout
->addWidget(m_searchBox
);
186 m_topLayout
->addWidget(m_messageWidget
);
187 m_topLayout
->addWidget(m_view
);
188 m_topLayout
->addWidget(m_filterBar
);
189 m_topLayout
->addWidget(m_statusBar
);
191 setSearchModeEnabled(isSearchUrl(url
));
193 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
194 if (view()->mode() == DolphinView::Mode::DetailsView
) {
199 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
200 connect(placesModel
, &KFilePlacesModel::dataChanged
,
201 this, &DolphinViewContainer::slotPlacesModelChanged
);
202 connect(placesModel
, &KFilePlacesModel::rowsInserted
,
203 this, &DolphinViewContainer::slotPlacesModelChanged
);
204 connect(placesModel
, &KFilePlacesModel::rowsRemoved
,
205 this, &DolphinViewContainer::slotPlacesModelChanged
);
207 connect(this, &DolphinViewContainer::searchModeEnabledChanged
,
208 this, &DolphinViewContainer::captionChanged
);
210 // Initialize kactivities resource instance
212 #ifdef HAVE_KACTIVITIES
213 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
214 m_activityResourceInstance
->setParent(this);
218 DolphinViewContainer::~DolphinViewContainer()
222 QUrl
DolphinViewContainer::url() const
224 return m_view
->url();
227 void DolphinViewContainer::setActive(bool active
)
229 m_searchBox
->setActive(active
);
230 if (m_urlNavigatorConnected
) {
231 m_urlNavigatorConnected
->setActive(active
);
233 m_view
->setActive(active
);
235 #ifdef HAVE_KACTIVITIES
237 m_activityResourceInstance
->notifyFocusedIn();
239 m_activityResourceInstance
->notifyFocusedOut();
244 bool DolphinViewContainer::isActive() const
246 return m_view
->isActive();
249 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
251 m_autoGrabFocus
= grab
;
254 bool DolphinViewContainer::autoGrabFocus() const
256 return m_autoGrabFocus
;
259 QString
DolphinViewContainer::currentSearchText() const
261 return m_searchBox
->text();
264 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
269 DolphinStatusBar
* DolphinViewContainer::statusBar()
274 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
276 return m_urlNavigatorConnected
;
279 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
281 return m_urlNavigatorConnected
;
284 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
286 return m_urlNavigator
.get();
289 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
291 return m_urlNavigator
.get();
294 const DolphinView
* DolphinViewContainer::view() const
299 DolphinView
* DolphinViewContainer::view()
304 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
306 Q_CHECK_PTR(urlNavigator
);
307 Q_ASSERT(!m_urlNavigatorConnected
);
308 Q_ASSERT(m_urlNavigator
.get() != urlNavigator
);
311 urlNavigator
->setLocationUrl(m_view
->url());
312 if (m_urlNavigatorVisualState
) {
313 urlNavigator
->setVisualState(*m_urlNavigatorVisualState
.get());
314 m_urlNavigatorVisualState
.reset();
316 urlNavigator
->setActive(isActive());
318 // Url changes are still done via m_urlNavigator.
319 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
320 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
321 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
,
322 this, [=](const QUrl
&destination
, QDropEvent
*event
) {
323 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
325 // Aside from these, only visual things need to be connected.
326 connect(m_view
, &DolphinView::urlChanged
,
327 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
328 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
329 this, &DolphinViewContainer::activate
);
331 m_urlNavigatorConnected
= urlNavigator
;
334 void DolphinViewContainer::disconnectUrlNavigator()
336 if (!m_urlNavigatorConnected
) {
340 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
341 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
342 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
344 disconnect(m_view
, &DolphinView::urlChanged
,
345 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
346 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
347 this, &DolphinViewContainer::activate
);
349 m_urlNavigatorVisualState
= m_urlNavigatorConnected
->visualState();
350 m_urlNavigatorConnected
= nullptr;
353 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
359 m_messageWidget
->setText(msg
);
361 // TODO: wrap at arbitrary character positions once QLabel can do this
362 // https://bugreports.qt.io/browse/QTBUG-1276
363 m_messageWidget
->setWordWrap(true);
366 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
367 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
368 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
374 m_messageWidget
->setWordWrap(false);
375 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
376 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
378 if (m_messageWidget
->isVisible()) {
379 m_messageWidget
->hide();
381 m_messageWidget
->animatedShow();
384 void DolphinViewContainer::readSettings()
386 // The startup settings should (only) get applied if they have been
387 // modified by the user. Otherwise keep the (possibly) different current
388 // setting of the filterbar.
389 if (GeneralSettings::modifiedStartupSettings()) {
390 setFilterBarVisible(GeneralSettings::filterBar());
393 m_view
->readSettings();
394 m_statusBar
->readSettings();
397 bool DolphinViewContainer::isFilterBarVisible() const
399 return m_filterBar
->isVisible();
402 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
404 m_searchBox
->setVisible(enabled
);
407 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
408 m_searchBox
->fromSearchUrl(locationUrl
);
411 if (enabled
== isSearchModeEnabled()) {
412 if (enabled
&& !m_searchBox
->hasFocus()) {
413 m_searchBox
->setFocus();
414 m_searchBox
->selectAll();
420 m_view
->setViewPropertiesContext(QString());
422 // Restore the URL for the URL navigator. If Dolphin has been
423 // started with a search-URL, the home URL is used as fallback.
424 QUrl url
= m_searchBox
->searchPath();
425 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
426 url
= Dolphin::homeUrl();
428 m_urlNavigatorConnected
->setLocationUrl(url
);
431 m_searchModeEnabled
= enabled
;
433 Q_EMIT
searchModeEnabledChanged(enabled
);
436 bool DolphinViewContainer::isSearchModeEnabled() const
438 return m_searchModeEnabled
;
441 QString
DolphinViewContainer::placesText() const
445 if (isSearchModeEnabled()) {
446 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
448 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
449 if (text
.isEmpty()) {
452 if (text
.isEmpty()) {
453 text
= url().scheme();
460 void DolphinViewContainer::reload()
463 m_messageWidget
->hide();
466 QString
DolphinViewContainer::captionWindowTitle() const
468 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
469 if (!url().isLocalFile()) {
470 return url().adjusted(QUrl::StripTrailingSlash
).toString();
472 return url().adjusted(QUrl::StripTrailingSlash
).path();
474 return DolphinViewContainer::caption();
478 QString
DolphinViewContainer::caption() const
480 if (isSearchModeEnabled()) {
481 if (currentSearchText().isEmpty()){
482 return i18n("Search");
484 return i18n("Search for %1", currentSearchText());
488 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
489 const QString pattern
= url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?");
490 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QRegularExpression::anchoredPattern(pattern
), 1, Qt::MatchRegularExpression
);
492 if (!matchedPlaces
.isEmpty()) {
493 return placesModel
->text(matchedPlaces
.first());
497 if (!url().isLocalFile()) {
498 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
500 if (!adjustedUrl
.fileName().isEmpty()) {
501 caption
= adjustedUrl
.fileName();
502 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
503 caption
= adjustedUrl
.path();
504 } else if (!adjustedUrl
.host().isEmpty()) {
505 caption
= adjustedUrl
.host();
507 caption
= adjustedUrl
.toString();
512 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
513 if (fileName
.isEmpty()) {
520 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
522 if (newUrl
!= m_urlNavigator
->locationUrl()) {
523 m_urlNavigator
->setLocationUrl(newUrl
);
526 #ifdef HAVE_KACTIVITIES
527 m_activityResourceInstance
->setUri(newUrl
);
531 void DolphinViewContainer::setFilterBarVisible(bool visible
)
533 Q_ASSERT(m_filterBar
);
535 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
537 m_filterBar
->setFocus();
538 m_filterBar
->selectAll();
544 void DolphinViewContainer::delayedStatusBarUpdate()
546 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
547 // No update of the statusbar has been done during the last 2 seconds,
548 // although an update has been requested. Trigger an immediate update.
549 m_statusBarTimer
->stop();
552 // Invoke updateStatusBar() with a small delay. This assures that
553 // when a lot of delayedStatusBarUpdates() are done in a short time,
554 // no bottleneck is given.
555 m_statusBarTimer
->start();
559 void DolphinViewContainer::updateStatusBar()
561 m_statusBarTimestamp
.start();
562 m_view
->requestStatusBarText();
565 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
567 if (m_statusBar
->progressText().isEmpty()) {
568 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
570 m_statusBar
->setProgress(percent
);
573 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
575 if (m_statusBar
->progressText().isEmpty()) {
576 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
578 m_statusBar
->setProgress(percent
);
581 void DolphinViewContainer::slotDirectoryLoadingStarted()
583 if (isSearchUrl(url())) {
584 // Search KIO-slaves usually don't provide any progress information. Give
585 // a hint to the user that a searching is done:
587 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
588 m_statusBar
->setProgress(-1);
590 // Trigger an undetermined progress indication. The progress
591 // information in percent will be triggered by the percent() signal
592 // of the directory lister later.
593 m_statusBar
->setProgressText(QString());
594 updateDirectoryLoadingProgress(-1);
598 void DolphinViewContainer::slotDirectoryLoadingCompleted()
600 if (!m_statusBar
->progressText().isEmpty()) {
601 m_statusBar
->setProgressText(QString());
602 m_statusBar
->setProgress(100);
605 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
606 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
607 // of showing the default status bar information ("0 items") a more helpful information is given:
608 m_statusBar
->setText(i18nc("@info:status", "No items found."));
614 void DolphinViewContainer::slotDirectoryLoadingCanceled()
616 if (!m_statusBar
->progressText().isEmpty()) {
617 m_statusBar
->setProgressText(QString());
618 m_statusBar
->setProgress(100);
621 m_statusBar
->setText(QString());
624 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
626 const KFileItem
item(url
);
628 // Find out if the file can be opened in the view (for example, this is the
629 // case if the file is an archive). The mime type must be known for that.
630 item
.determineMimeType();
631 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
632 if (!folderUrl
.isEmpty()) {
635 slotItemActivated(item
);
639 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
641 // It is possible to activate items on inactive views by
642 // drag & drop operations. Assure that activating an item always
643 // results in an active view.
644 m_view
->setActive(true);
646 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
647 if (!url
.isEmpty()) {
652 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl());
653 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
654 job
->setShowOpenOrExecuteDialog(true);
658 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
660 Q_ASSERT(items
.count() >= 2);
662 KFileItemActions
fileItemActions(this);
663 fileItemActions
.runPreferredApplications(items
, QString());
666 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
669 m_statusBar
->resetToDefaultText();
671 m_statusBar
->setText(item
.getStatusBarInfo());
675 void DolphinViewContainer::closeFilterBar()
677 m_filterBar
->closeFilterBar();
679 Q_EMIT
showFilterBarChanged(false);
682 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
684 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
685 m_view
->setNameFilter(nameFilter
);
686 delayedStatusBarUpdate();
689 void DolphinViewContainer::activate()
694 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
699 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
701 if (m_urlNavigatorConnected
) {
702 m_urlNavigatorConnected
->slotReturnPressed();
705 if (KProtocolManager::supportsListing(url
)) {
706 setSearchModeEnabled(isSearchUrl(url
));
708 tryRestoreViewState();
710 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
711 // When an URL has been entered, the view should get the focus.
712 // The focus must be requested asynchronously, as changing the URL might create
713 // a new view widget.
714 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
716 } else if (KProtocolManager::isSourceProtocol(url
)) {
717 if (url
.scheme().startsWith(QLatin1String("http"))) {
718 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
719 "Dolphin does not support web pages, the web browser has been launched"),
722 showMessage(i18nc("@info:status",
723 "Protocol not supported by Dolphin, default application has been launched"),
727 QDesktopServices::openUrl(url
);
728 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
730 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
731 m_urlNavigator
->goBack();
735 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
737 m_view
->markUrlsAsSelected({url
});
738 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
741 void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
743 disconnect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
744 this, &DolphinViewContainer::slotUrlSelectionRequested
);
747 void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
749 connect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
750 this, &DolphinViewContainer::slotUrlSelectionRequested
);
753 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
756 const bool block
= m_urlNavigator
->signalsBlocked();
757 m_urlNavigator
->blockSignals(true);
759 // Assure that the location state is reset for redirection URLs. This
760 // allows to skip redirection URLs when going back or forward in the
762 m_urlNavigator
->saveLocationState(QByteArray());
763 m_urlNavigator
->setLocationUrl(newUrl
);
764 setSearchModeEnabled(isSearchUrl(newUrl
));
766 m_urlNavigator
->blockSignals(block
);
769 void DolphinViewContainer::requestFocus()
774 void DolphinViewContainer::startSearching()
776 Q_CHECK_PTR(m_urlNavigatorConnected
);
777 const QUrl url
= m_searchBox
->urlForSearching();
778 if (url
.isValid() && !url
.isEmpty()) {
779 m_view
->setViewPropertiesContext(QStringLiteral("search"));
780 m_urlNavigatorConnected
->setLocationUrl(url
);
784 void DolphinViewContainer::closeSearchBox()
786 setSearchModeEnabled(false);
789 void DolphinViewContainer::stopDirectoryLoading()
791 m_view
->stopLoading();
792 m_statusBar
->setProgress(100);
795 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
797 m_view
->setZoomLevel(zoomLevel
);
800 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
802 showMessage(msg
, Error
);
805 void DolphinViewContainer::slotPlacesModelChanged()
807 if (!GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
808 Q_EMIT
captionChanged();
812 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
814 return url
.scheme().contains(QLatin1String("search"));
817 void DolphinViewContainer::saveViewState()
819 QByteArray locationState
;
820 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
821 m_view
->saveState(stream
);
822 m_urlNavigator
->saveLocationState(locationState
);
825 void DolphinViewContainer::tryRestoreViewState()
827 QByteArray locationState
= m_urlNavigator
->locationState();
828 if (!locationState
.isEmpty()) {
829 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
830 m_view
->restoreState(stream
);