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 // Initialize kactivities resource instance
201 #ifdef HAVE_KACTIVITIES
202 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
203 m_activityResourceInstance
->setParent(this);
207 DolphinViewContainer::~DolphinViewContainer()
211 QUrl
DolphinViewContainer::url() const
213 return m_view
->url();
216 void DolphinViewContainer::setActive(bool active
)
218 m_searchBox
->setActive(active
);
219 if (m_urlNavigatorConnected
) {
220 m_urlNavigatorConnected
->setActive(active
);
222 m_view
->setActive(active
);
224 #ifdef HAVE_KACTIVITIES
226 m_activityResourceInstance
->notifyFocusedIn();
228 m_activityResourceInstance
->notifyFocusedOut();
233 bool DolphinViewContainer::isActive() const
235 return m_view
->isActive();
238 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
240 m_autoGrabFocus
= grab
;
243 bool DolphinViewContainer::autoGrabFocus() const
245 return m_autoGrabFocus
;
248 QString
DolphinViewContainer::currentSearchText() const
250 return m_searchBox
->text();
253 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
258 DolphinStatusBar
* DolphinViewContainer::statusBar()
263 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
265 return m_urlNavigatorConnected
;
268 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
270 return m_urlNavigatorConnected
;
273 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
275 return m_urlNavigator
.get();
278 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
280 return m_urlNavigator
.get();
283 const DolphinView
* DolphinViewContainer::view() const
288 DolphinView
* DolphinViewContainer::view()
293 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
295 Q_CHECK_PTR(urlNavigator
);
296 Q_ASSERT(!m_urlNavigatorConnected
);
297 Q_ASSERT(m_urlNavigator
.get() != urlNavigator
);
300 urlNavigator
->setLocationUrl(m_view
->url());
301 if (m_urlNavigatorVisualState
) {
302 urlNavigator
->setVisualState(*m_urlNavigatorVisualState
.get());
303 m_urlNavigatorVisualState
.reset();
305 urlNavigator
->setActive(isActive());
307 // Url changes are still done via m_urlNavigator.
308 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
309 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
310 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
,
311 this, [=](const QUrl
&destination
, QDropEvent
*event
) {
312 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
314 // Aside from these, only visual things need to be connected.
315 connect(m_view
, &DolphinView::urlChanged
,
316 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
317 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
318 this, &DolphinViewContainer::activate
);
320 m_urlNavigatorConnected
= urlNavigator
;
323 void DolphinViewContainer::disconnectUrlNavigator()
325 if (!m_urlNavigatorConnected
) {
329 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
330 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
331 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
333 disconnect(m_view
, &DolphinView::urlChanged
,
334 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
335 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
336 this, &DolphinViewContainer::activate
);
338 m_urlNavigatorVisualState
= m_urlNavigatorConnected
->visualState();
339 m_urlNavigatorConnected
= nullptr;
342 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
348 m_messageWidget
->setText(msg
);
350 // TODO: wrap at arbitrary character positions once QLabel can do this
351 // https://bugreports.qt.io/browse/QTBUG-1276
352 m_messageWidget
->setWordWrap(true);
355 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
356 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
357 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
363 m_messageWidget
->setWordWrap(false);
364 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
365 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
367 if (m_messageWidget
->isVisible()) {
368 m_messageWidget
->hide();
370 m_messageWidget
->animatedShow();
373 void DolphinViewContainer::readSettings()
375 // The startup settings should (only) get applied if they have been
376 // modified by the user. Otherwise keep the (possibly) different current
377 // setting of the filterbar.
378 if (GeneralSettings::modifiedStartupSettings()) {
379 setFilterBarVisible(GeneralSettings::filterBar());
382 m_view
->readSettings();
383 m_statusBar
->readSettings();
386 bool DolphinViewContainer::isFilterBarVisible() const
388 return m_filterBar
->isVisible();
391 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
393 m_searchBox
->setVisible(enabled
);
396 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
397 m_searchBox
->fromSearchUrl(locationUrl
);
400 if (enabled
== isSearchModeEnabled()) {
401 if (enabled
&& !m_searchBox
->hasFocus()) {
402 m_searchBox
->setFocus();
403 m_searchBox
->selectAll();
409 m_view
->setViewPropertiesContext(QString());
411 // Restore the URL for the URL navigator. If Dolphin has been
412 // started with a search-URL, the home URL is used as fallback.
413 QUrl url
= m_searchBox
->searchPath();
414 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
415 url
= Dolphin::homeUrl();
417 m_urlNavigatorConnected
->setLocationUrl(url
);
420 m_searchModeEnabled
= enabled
;
422 Q_EMIT
searchModeEnabledChanged(enabled
);
425 bool DolphinViewContainer::isSearchModeEnabled() const
427 return m_searchModeEnabled
;
430 QString
DolphinViewContainer::placesText() const
434 if (isSearchModeEnabled()) {
435 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
437 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
438 if (text
.isEmpty()) {
441 if (text
.isEmpty()) {
442 text
= url().scheme();
449 void DolphinViewContainer::reload()
452 m_messageWidget
->hide();
455 QString
DolphinViewContainer::captionWindowTitle() const
457 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
458 if (!url().isLocalFile()) {
459 return url().adjusted(QUrl::StripTrailingSlash
).toString();
461 return url().adjusted(QUrl::StripTrailingSlash
).path();
463 return DolphinViewContainer::caption();
467 QString
DolphinViewContainer::caption() const
469 if (isSearchModeEnabled()) {
470 if (currentSearchText().isEmpty()){
471 return i18n("Search");
473 return i18n("Search for %1", currentSearchText());
477 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
478 const QString pattern
= url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?");
479 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QRegularExpression::anchoredPattern(pattern
), 1, Qt::MatchRegularExpression
);
481 if (!matchedPlaces
.isEmpty()) {
482 return placesModel
->text(matchedPlaces
.first());
486 if (!url().isLocalFile()) {
487 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
489 if (!adjustedUrl
.fileName().isEmpty()) {
490 caption
= adjustedUrl
.fileName();
491 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
492 caption
= adjustedUrl
.path();
493 } else if (!adjustedUrl
.host().isEmpty()) {
494 caption
= adjustedUrl
.host();
496 caption
= adjustedUrl
.toString();
501 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
502 if (fileName
.isEmpty()) {
509 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
511 if (newUrl
!= m_urlNavigator
->locationUrl()) {
512 m_urlNavigator
->setLocationUrl(newUrl
);
515 #ifdef HAVE_KACTIVITIES
516 m_activityResourceInstance
->setUri(newUrl
);
520 void DolphinViewContainer::setFilterBarVisible(bool visible
)
522 Q_ASSERT(m_filterBar
);
524 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
526 m_filterBar
->setFocus();
527 m_filterBar
->selectAll();
533 void DolphinViewContainer::delayedStatusBarUpdate()
535 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
536 // No update of the statusbar has been done during the last 2 seconds,
537 // although an update has been requested. Trigger an immediate update.
538 m_statusBarTimer
->stop();
541 // Invoke updateStatusBar() with a small delay. This assures that
542 // when a lot of delayedStatusBarUpdates() are done in a short time,
543 // no bottleneck is given.
544 m_statusBarTimer
->start();
548 void DolphinViewContainer::updateStatusBar()
550 m_statusBarTimestamp
.start();
551 m_view
->requestStatusBarText();
554 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
556 if (m_statusBar
->progressText().isEmpty()) {
557 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
559 m_statusBar
->setProgress(percent
);
562 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
564 if (m_statusBar
->progressText().isEmpty()) {
565 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
567 m_statusBar
->setProgress(percent
);
570 void DolphinViewContainer::slotDirectoryLoadingStarted()
572 if (isSearchUrl(url())) {
573 // Search KIO-slaves usually don't provide any progress information. Give
574 // a hint to the user that a searching is done:
576 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
577 m_statusBar
->setProgress(-1);
579 // Trigger an undetermined progress indication. The progress
580 // information in percent will be triggered by the percent() signal
581 // of the directory lister later.
582 m_statusBar
->setProgressText(QString());
583 updateDirectoryLoadingProgress(-1);
587 void DolphinViewContainer::slotDirectoryLoadingCompleted()
589 if (!m_statusBar
->progressText().isEmpty()) {
590 m_statusBar
->setProgressText(QString());
591 m_statusBar
->setProgress(100);
594 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
595 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
596 // of showing the default status bar information ("0 items") a more helpful information is given:
597 m_statusBar
->setText(i18nc("@info:status", "No items found."));
603 void DolphinViewContainer::slotDirectoryLoadingCanceled()
605 if (!m_statusBar
->progressText().isEmpty()) {
606 m_statusBar
->setProgressText(QString());
607 m_statusBar
->setProgress(100);
610 m_statusBar
->setText(QString());
613 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
615 const KFileItem
item(url
);
617 // Find out if the file can be opened in the view (for example, this is the
618 // case if the file is an archive). The mime type must be known for that.
619 item
.determineMimeType();
620 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
621 if (!folderUrl
.isEmpty()) {
624 slotItemActivated(item
);
628 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
630 // It is possible to activate items on inactive views by
631 // drag & drop operations. Assure that activating an item always
632 // results in an active view.
633 m_view
->setActive(true);
635 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
636 if (!url
.isEmpty()) {
641 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl());
642 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
643 job
->setShowOpenOrExecuteDialog(true);
647 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
649 Q_ASSERT(items
.count() >= 2);
651 KFileItemActions
fileItemActions(this);
652 fileItemActions
.runPreferredApplications(items
, QString());
655 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
658 m_statusBar
->resetToDefaultText();
660 m_statusBar
->setText(item
.getStatusBarInfo());
664 void DolphinViewContainer::closeFilterBar()
666 m_filterBar
->closeFilterBar();
668 Q_EMIT
showFilterBarChanged(false);
671 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
673 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
674 m_view
->setNameFilter(nameFilter
);
675 delayedStatusBarUpdate();
678 void DolphinViewContainer::activate()
683 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
688 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
690 if (m_urlNavigatorConnected
) {
691 m_urlNavigatorConnected
->slotReturnPressed();
694 if (KProtocolManager::supportsListing(url
)) {
695 setSearchModeEnabled(isSearchUrl(url
));
697 tryRestoreViewState();
699 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
700 // When an URL has been entered, the view should get the focus.
701 // The focus must be requested asynchronously, as changing the URL might create
702 // a new view widget.
703 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
705 } else if (KProtocolManager::isSourceProtocol(url
)) {
706 if (url
.scheme().startsWith(QLatin1String("http"))) {
707 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
708 "Dolphin does not support web pages, the web browser has been launched"),
711 showMessage(i18nc("@info:status",
712 "Protocol not supported by Dolphin, default application has been launched"),
716 QDesktopServices::openUrl(url
);
717 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
719 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
720 m_urlNavigator
->goBack();
724 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
726 m_view
->markUrlsAsSelected({url
});
727 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
730 void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
732 disconnect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
733 this, &DolphinViewContainer::slotUrlSelectionRequested
);
736 void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
738 connect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
739 this, &DolphinViewContainer::slotUrlSelectionRequested
);
742 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
745 const bool block
= m_urlNavigator
->signalsBlocked();
746 m_urlNavigator
->blockSignals(true);
748 // Assure that the location state is reset for redirection URLs. This
749 // allows to skip redirection URLs when going back or forward in the
751 m_urlNavigator
->saveLocationState(QByteArray());
752 m_urlNavigator
->setLocationUrl(newUrl
);
753 setSearchModeEnabled(isSearchUrl(newUrl
));
755 m_urlNavigator
->blockSignals(block
);
758 void DolphinViewContainer::requestFocus()
763 void DolphinViewContainer::startSearching()
765 Q_CHECK_PTR(m_urlNavigatorConnected
);
766 const QUrl url
= m_searchBox
->urlForSearching();
767 if (url
.isValid() && !url
.isEmpty()) {
768 m_view
->setViewPropertiesContext(QStringLiteral("search"));
769 m_urlNavigatorConnected
->setLocationUrl(url
);
773 void DolphinViewContainer::closeSearchBox()
775 setSearchModeEnabled(false);
778 void DolphinViewContainer::stopDirectoryLoading()
780 m_view
->stopLoading();
781 m_statusBar
->setProgress(100);
784 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
786 m_view
->setZoomLevel(zoomLevel
);
789 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
791 showMessage(msg
, Error
);
794 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
796 return url
.scheme().contains(QLatin1String("search"));
799 void DolphinViewContainer::saveViewState()
801 QByteArray locationState
;
802 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
803 m_view
->saveState(stream
);
804 m_urlNavigator
->saveLocationState(locationState
);
807 void DolphinViewContainer::tryRestoreViewState()
809 QByteArray locationState
= m_urlNavigator
->locationState();
810 if (!locationState
.isEmpty()) {
811 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
812 m_view
->restoreState(stream
);