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>
33 #include <KUrlNavigator>
36 #include <QLoggingCategory>
40 #include <QVBoxLayout>
41 #include <QDesktopServices>
43 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
46 m_urlNavigator
{new DolphinUrlNavigator(url
)},
47 m_urlNavigatorConnected
{nullptr},
49 m_searchModeEnabled(false),
50 m_messageWidget(nullptr),
54 m_statusBarTimer(nullptr),
55 m_statusBarTimestamp(),
57 #ifdef HAVE_KACTIVITIES
58 , m_activityResourceInstance(nullptr)
63 m_topLayout
= new QVBoxLayout(this);
64 m_topLayout
->setSpacing(0);
65 m_topLayout
->setContentsMargins(0, 0, 0, 0);
67 m_searchBox
= new DolphinSearchBox(this);
69 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
70 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
71 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
72 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
73 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
74 "<para>This helps you find files and folders. Enter a <emphasis>"
75 "search term</emphasis> and specify search settings with the "
76 "buttons at the bottom:<list><item>Filename/Content: "
77 "Does the item you are looking for contain the search terms "
78 "within its filename or its contents?<nl/>The contents of images, "
79 "audio files and videos will not be searched.</item><item>"
80 "From Here/Everywhere: Do you want to search in this "
81 "folder and its sub-folders or everywhere?</item><item>"
82 "More Options: Click this to search by media type, access "
83 "time or rating.</item><item>More Search Tools: Install other "
84 "means to find an item.</item></list></para>"));
86 m_messageWidget
= new KMessageWidget(this);
87 m_messageWidget
->setCloseButtonVisible(true);
88 m_messageWidget
->hide();
93 // We must be logged in as the root user; show a big scary warning
94 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
98 // Initialize filter bar
99 m_filterBar
= new FilterBar(this);
100 m_filterBar
->setVisible(GeneralSettings::filterBar());
102 connect(m_filterBar
, &FilterBar::filterChanged
,
103 this, &DolphinViewContainer::setNameFilter
);
104 connect(m_filterBar
, &FilterBar::closeRequest
,
105 this, &DolphinViewContainer::closeFilterBar
);
106 connect(m_filterBar
, &FilterBar::focusViewRequest
,
107 this, &DolphinViewContainer::requestFocus
);
109 // Initialize the main view
110 m_view
= new DolphinView(url
, this);
111 connect(m_view
, &DolphinView::urlChanged
,
112 m_filterBar
, &FilterBar::slotUrlChanged
);
113 connect(m_view
, &DolphinView::urlChanged
,
114 m_messageWidget
, &KMessageWidget::hide
);
115 // m_urlNavigator stays in sync with m_view's location changes and
116 // keeps track of them so going back and forth in the history works.
117 connect(m_view
, &DolphinView::urlChanged
,
118 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
119 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
,
120 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
121 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlAboutToBeChanged
,
122 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
123 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlSelectionRequested
,
124 this, &DolphinViewContainer::slotUrlSelectionRequested
);
125 connect(m_view
, &DolphinView::writeStateChanged
,
126 this, &DolphinViewContainer::writeStateChanged
);
127 connect(m_view
, &DolphinView::requestItemInfo
,
128 this, &DolphinViewContainer::showItemInfo
);
129 connect(m_view
, &DolphinView::itemActivated
,
130 this, &DolphinViewContainer::slotItemActivated
);
131 connect(m_view
, &DolphinView::itemsActivated
,
132 this, &DolphinViewContainer::slotItemsActivated
);
133 connect(m_view
, &DolphinView::redirection
,
134 this, &DolphinViewContainer::redirect
);
135 connect(m_view
, &DolphinView::directoryLoadingStarted
,
136 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
137 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
138 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
139 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
140 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
141 connect(m_view
, &DolphinView::itemCountChanged
,
142 this, &DolphinViewContainer::delayedStatusBarUpdate
);
143 connect(m_view
, &DolphinView::directoryLoadingProgress
,
144 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
145 connect(m_view
, &DolphinView::directorySortingProgress
,
146 this, &DolphinViewContainer::updateDirectorySortingProgress
);
147 connect(m_view
, &DolphinView::selectionChanged
,
148 this, &DolphinViewContainer::delayedStatusBarUpdate
);
149 connect(m_view
, &DolphinView::errorMessage
,
150 this, &DolphinViewContainer::showErrorMessage
);
151 connect(m_view
, &DolphinView::urlIsFileError
,
152 this, &DolphinViewContainer::slotUrlIsFileError
);
153 connect(m_view
, &DolphinView::activated
,
154 this, &DolphinViewContainer::activate
);
156 // Initialize status bar
157 m_statusBar
= new DolphinStatusBar(this);
158 m_statusBar
->setUrl(m_view
->url());
159 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
160 connect(m_view
, &DolphinView::urlChanged
,
161 m_statusBar
, &DolphinStatusBar::setUrl
);
162 connect(m_view
, &DolphinView::zoomLevelChanged
,
163 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
164 connect(m_view
, &DolphinView::infoMessage
,
165 m_statusBar
, &DolphinStatusBar::setText
);
166 connect(m_view
, &DolphinView::operationCompletedMessage
,
167 m_statusBar
, &DolphinStatusBar::setText
);
168 connect(m_view
, &DolphinView::statusBarTextChanged
,
169 m_statusBar
, &DolphinStatusBar::setDefaultText
);
170 connect(m_view
, &DolphinView::statusBarTextChanged
,
171 m_statusBar
, &DolphinStatusBar::resetToDefaultText
);
172 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
173 this, &DolphinViewContainer::stopDirectoryLoading
);
174 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
175 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
177 m_statusBarTimer
= new QTimer(this);
178 m_statusBarTimer
->setSingleShot(true);
179 m_statusBarTimer
->setInterval(300);
180 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
182 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
183 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
184 this, &DolphinViewContainer::delayedStatusBarUpdate
);
186 m_topLayout
->addWidget(m_searchBox
);
187 m_topLayout
->addWidget(m_messageWidget
);
188 m_topLayout
->addWidget(m_view
);
189 m_topLayout
->addWidget(m_filterBar
);
190 m_topLayout
->addWidget(m_statusBar
);
192 setSearchModeEnabled(isSearchUrl(url
));
194 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
195 if (view()->mode() == DolphinView::Mode::DetailsView
) {
200 // Initialize kactivities resource instance
202 #ifdef HAVE_KACTIVITIES
203 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
204 m_activityResourceInstance
->setParent(this);
208 DolphinViewContainer::~DolphinViewContainer()
212 QUrl
DolphinViewContainer::url() const
214 return m_view
->url();
217 void DolphinViewContainer::setActive(bool active
)
219 m_searchBox
->setActive(active
);
220 if (m_urlNavigatorConnected
) {
221 m_urlNavigatorConnected
->setActive(active
);
223 m_view
->setActive(active
);
225 #ifdef HAVE_KACTIVITIES
227 m_activityResourceInstance
->notifyFocusedIn();
229 m_activityResourceInstance
->notifyFocusedOut();
234 bool DolphinViewContainer::isActive() const
236 return m_view
->isActive();
239 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
241 m_autoGrabFocus
= grab
;
244 bool DolphinViewContainer::autoGrabFocus() const
246 return m_autoGrabFocus
;
249 QString
DolphinViewContainer::currentSearchText() const
251 return m_searchBox
->text();
254 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
259 DolphinStatusBar
* DolphinViewContainer::statusBar()
264 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
266 return m_urlNavigatorConnected
;
269 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
271 return m_urlNavigatorConnected
;
274 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
276 return m_urlNavigator
.get();
279 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
281 return m_urlNavigator
.get();
284 const DolphinView
* DolphinViewContainer::view() const
289 DolphinView
* DolphinViewContainer::view()
294 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
296 Q_CHECK_PTR(urlNavigator
);
297 Q_ASSERT(!m_urlNavigatorConnected
);
298 Q_ASSERT(m_urlNavigator
.get() != urlNavigator
);
301 urlNavigator
->setLocationUrl(m_view
->url());
302 if (m_urlNavigatorVisualState
) {
303 urlNavigator
->setVisualState(*m_urlNavigatorVisualState
.get());
304 m_urlNavigatorVisualState
.reset();
306 urlNavigator
->setActive(isActive());
308 // Url changes are still done via m_urlNavigator.
309 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
310 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
311 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
,
312 this, [=](const QUrl
&destination
, QDropEvent
*event
) {
313 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
315 // Aside from these, only visual things need to be connected.
316 connect(m_view
, &DolphinView::urlChanged
,
317 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
318 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
319 this, &DolphinViewContainer::activate
);
321 m_urlNavigatorConnected
= urlNavigator
;
324 void DolphinViewContainer::disconnectUrlNavigator()
326 if (!m_urlNavigatorConnected
) {
330 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
331 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
332 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
334 disconnect(m_view
, &DolphinView::urlChanged
,
335 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
336 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
337 this, &DolphinViewContainer::activate
);
339 m_urlNavigatorVisualState
= m_urlNavigatorConnected
->visualState();
340 m_urlNavigatorConnected
= nullptr;
343 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
349 m_messageWidget
->setText(msg
);
351 // TODO: wrap at arbitrary character positions once QLabel can do this
352 // https://bugreports.qt.io/browse/QTBUG-1276
353 m_messageWidget
->setWordWrap(true);
356 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
357 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
358 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
364 m_messageWidget
->setWordWrap(false);
365 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
366 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
368 if (m_messageWidget
->isVisible()) {
369 m_messageWidget
->hide();
371 m_messageWidget
->animatedShow();
374 void DolphinViewContainer::readSettings()
376 // The startup settings should (only) get applied if they have been
377 // modified by the user. Otherwise keep the (possibly) different current
378 // setting of the filterbar.
379 if (GeneralSettings::modifiedStartupSettings()) {
380 setFilterBarVisible(GeneralSettings::filterBar());
383 m_view
->readSettings();
384 m_statusBar
->readSettings();
387 bool DolphinViewContainer::isFilterBarVisible() const
389 return m_filterBar
->isVisible();
392 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
394 m_searchBox
->setVisible(enabled
);
397 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
398 m_searchBox
->fromSearchUrl(locationUrl
);
401 if (enabled
== isSearchModeEnabled()) {
402 if (enabled
&& !m_searchBox
->hasFocus()) {
403 m_searchBox
->setFocus();
404 m_searchBox
->selectAll();
410 m_view
->setViewPropertiesContext(QString());
412 // Restore the URL for the URL navigator. If Dolphin has been
413 // started with a search-URL, the home URL is used as fallback.
414 QUrl url
= m_searchBox
->searchPath();
415 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
416 url
= Dolphin::homeUrl();
418 m_urlNavigatorConnected
->setLocationUrl(url
);
421 m_searchModeEnabled
= enabled
;
423 Q_EMIT
searchModeEnabledChanged(enabled
);
426 bool DolphinViewContainer::isSearchModeEnabled() const
428 return m_searchModeEnabled
;
431 QString
DolphinViewContainer::placesText() const
435 if (isSearchModeEnabled()) {
436 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
438 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
439 if (text
.isEmpty()) {
442 if (text
.isEmpty()) {
443 text
= url().scheme();
450 void DolphinViewContainer::reload()
453 m_messageWidget
->hide();
456 QString
DolphinViewContainer::captionWindowTitle() const
458 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
459 if (!url().isLocalFile()) {
460 return url().adjusted(QUrl::StripTrailingSlash
).toString();
462 return url().adjusted(QUrl::StripTrailingSlash
).path();
464 return DolphinViewContainer::caption();
468 QString
DolphinViewContainer::caption() const
470 if (isSearchModeEnabled()) {
471 if (currentSearchText().isEmpty()){
472 return i18n("Search");
474 return i18n("Search for %1", currentSearchText());
478 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
479 const QString pattern
= url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?");
480 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QRegularExpression::anchoredPattern(pattern
), 1, Qt::MatchRegularExpression
);
482 if (!matchedPlaces
.isEmpty()) {
483 return placesModel
->text(matchedPlaces
.first());
487 if (!url().isLocalFile()) {
488 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
490 if (!adjustedUrl
.fileName().isEmpty()) {
491 caption
= adjustedUrl
.fileName();
492 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
493 caption
= adjustedUrl
.path();
494 } else if (!adjustedUrl
.host().isEmpty()) {
495 caption
= adjustedUrl
.host();
497 caption
= adjustedUrl
.toString();
502 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
503 if (fileName
.isEmpty()) {
510 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
512 if (newUrl
!= m_urlNavigator
->locationUrl()) {
513 m_urlNavigator
->setLocationUrl(newUrl
);
516 #ifdef HAVE_KACTIVITIES
517 m_activityResourceInstance
->setUri(newUrl
);
521 void DolphinViewContainer::setFilterBarVisible(bool visible
)
523 Q_ASSERT(m_filterBar
);
525 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
527 m_filterBar
->setFocus();
528 m_filterBar
->selectAll();
534 void DolphinViewContainer::delayedStatusBarUpdate()
536 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
537 // No update of the statusbar has been done during the last 2 seconds,
538 // although an update has been requested. Trigger an immediate update.
539 m_statusBarTimer
->stop();
542 // Invoke updateStatusBar() with a small delay. This assures that
543 // when a lot of delayedStatusBarUpdates() are done in a short time,
544 // no bottleneck is given.
545 m_statusBarTimer
->start();
549 void DolphinViewContainer::updateStatusBar()
551 m_statusBarTimestamp
.start();
552 m_view
->requestStatusBarText();
555 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
557 if (m_statusBar
->progressText().isEmpty()) {
558 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
560 m_statusBar
->setProgress(percent
);
563 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
565 if (m_statusBar
->progressText().isEmpty()) {
566 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
568 m_statusBar
->setProgress(percent
);
571 void DolphinViewContainer::slotDirectoryLoadingStarted()
573 if (isSearchUrl(url())) {
574 // Search KIO-slaves usually don't provide any progress information. Give
575 // a hint to the user that a searching is done:
577 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
578 m_statusBar
->setProgress(-1);
580 // Trigger an undetermined progress indication. The progress
581 // information in percent will be triggered by the percent() signal
582 // of the directory lister later.
583 m_statusBar
->setProgressText(QString());
584 updateDirectoryLoadingProgress(-1);
588 void DolphinViewContainer::slotDirectoryLoadingCompleted()
590 if (!m_statusBar
->progressText().isEmpty()) {
591 m_statusBar
->setProgressText(QString());
592 m_statusBar
->setProgress(100);
595 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
596 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
597 // of showing the default status bar information ("0 items") a more helpful information is given:
598 m_statusBar
->setText(i18nc("@info:status", "No items found."));
604 void DolphinViewContainer::slotDirectoryLoadingCanceled()
606 if (!m_statusBar
->progressText().isEmpty()) {
607 m_statusBar
->setProgressText(QString());
608 m_statusBar
->setProgress(100);
611 m_statusBar
->setText(QString());
614 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
616 const KFileItem
item(url
);
618 // Find out if the file can be opened in the view (for example, this is the
619 // case if the file is an archive). The mime type must be known for that.
620 item
.determineMimeType();
621 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
622 if (!folderUrl
.isEmpty()) {
625 slotItemActivated(item
);
629 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
631 // It is possible to activate items on inactive views by
632 // drag & drop operations. Assure that activating an item always
633 // results in an active view.
634 m_view
->setActive(true);
636 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
637 if (!url
.isEmpty()) {
642 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl());
643 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
644 job
->setShowOpenOrExecuteDialog(true);
648 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
650 Q_ASSERT(items
.count() >= 2);
652 KFileItemActions
fileItemActions(this);
653 fileItemActions
.runPreferredApplications(items
, QString());
656 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
659 m_statusBar
->resetToDefaultText();
661 m_statusBar
->setText(item
.getStatusBarInfo());
665 void DolphinViewContainer::closeFilterBar()
667 m_filterBar
->closeFilterBar();
669 Q_EMIT
showFilterBarChanged(false);
672 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
674 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
675 m_view
->setNameFilter(nameFilter
);
676 delayedStatusBarUpdate();
679 void DolphinViewContainer::activate()
684 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
689 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
691 if (m_urlNavigatorConnected
) {
692 m_urlNavigatorConnected
->slotReturnPressed();
695 if (KProtocolManager::supportsListing(url
)) {
696 setSearchModeEnabled(isSearchUrl(url
));
698 tryRestoreViewState();
700 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
701 // When an URL has been entered, the view should get the focus.
702 // The focus must be requested asynchronously, as changing the URL might create
703 // a new view widget.
704 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
706 } else if (KProtocolManager::isSourceProtocol(url
)) {
707 if (url
.scheme().startsWith(QLatin1String("http"))) {
708 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
709 "Dolphin does not support web pages, the web browser has been launched"),
712 showMessage(i18nc("@info:status",
713 "Protocol not supported by Dolphin, default application has been launched"),
717 QDesktopServices::openUrl(url
);
718 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
720 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
721 m_urlNavigator
->goBack();
725 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
727 m_view
->markUrlsAsSelected({url
});
728 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
731 void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
733 disconnect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
734 this, &DolphinViewContainer::slotUrlSelectionRequested
);
737 void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
739 connect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
740 this, &DolphinViewContainer::slotUrlSelectionRequested
);
743 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
746 const bool block
= m_urlNavigator
->signalsBlocked();
747 m_urlNavigator
->blockSignals(true);
749 // Assure that the location state is reset for redirection URLs. This
750 // allows to skip redirection URLs when going back or forward in the
752 m_urlNavigator
->saveLocationState(QByteArray());
753 m_urlNavigator
->setLocationUrl(newUrl
);
754 setSearchModeEnabled(isSearchUrl(newUrl
));
756 m_urlNavigator
->blockSignals(block
);
759 void DolphinViewContainer::requestFocus()
764 void DolphinViewContainer::startSearching()
766 Q_CHECK_PTR(m_urlNavigatorConnected
);
767 const QUrl url
= m_searchBox
->urlForSearching();
768 if (url
.isValid() && !url
.isEmpty()) {
769 m_view
->setViewPropertiesContext(QStringLiteral("search"));
770 m_urlNavigatorConnected
->setLocationUrl(url
);
774 void DolphinViewContainer::closeSearchBox()
776 setSearchModeEnabled(false);
779 void DolphinViewContainer::stopDirectoryLoading()
781 m_view
->stopLoading();
782 m_statusBar
->setProgress(100);
785 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
787 m_view
->setZoomLevel(zoomLevel
);
790 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
792 showMessage(msg
, Error
);
795 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
797 return url
.scheme().contains(QLatin1String("search"));
800 void DolphinViewContainer::saveViewState()
802 QByteArray locationState
;
803 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
804 m_view
->saveState(stream
);
805 m_urlNavigator
->saveLocationState(locationState
);
808 void DolphinViewContainer::tryRestoreViewState()
810 QByteArray locationState
= m_urlNavigator
->locationState();
811 if (!locationState
.isEmpty()) {
812 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
813 m_view
->restoreState(stream
);