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 "dolphinplacesmodelsingleton.h"
11 #include "dolphindebug.h"
12 #include "filterbar/filterbar.h"
14 #include "search/dolphinsearchbox.h"
15 #include "statusbar/dolphinstatusbar.h"
16 #include "trash/dolphintrash.h"
17 #include "views/viewmodecontroller.h"
18 #include "views/viewproperties.h"
19 #include "dolphin_detailsmodesettings.h"
20 #include "views/dolphinview.h"
22 #ifdef HAVE_KACTIVITIES
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>
35 #include <KUrlNavigator>
38 #include <QLoggingCategory>
42 #include <QVBoxLayout>
43 #include <QDesktopServices>
45 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
48 m_navigatorWidget(nullptr),
49 m_urlNavigator(nullptr),
50 m_emptyTrashButton(nullptr),
52 m_searchModeEnabled(false),
53 m_messageWidget(nullptr),
57 m_statusBarTimer(nullptr),
58 m_statusBarTimestamp(),
60 #ifdef HAVE_KACTIVITIES
61 , m_activityResourceInstance(nullptr)
66 m_topLayout
= new QVBoxLayout(this);
67 m_topLayout
->setSpacing(0);
68 m_topLayout
->setContentsMargins(0, 0, 0, 0);
70 m_navigatorWidget
= new QWidget(this);
71 QHBoxLayout
* navigatorLayout
= new QHBoxLayout(m_navigatorWidget
);
72 navigatorLayout
->setSpacing(0);
73 navigatorLayout
->setContentsMargins(0, 0, 0, 0);
74 m_navigatorWidget
->setWhatsThis(xi18nc("@info:whatsthis location bar",
75 "<para>This line describes the location of the files and folders "
76 "displayed below.</para><para>The name of the currently viewed "
77 "folder can be read at the very right. To the left of it is the "
78 "name of the folder that contains it. The whole line is called "
79 "the <emphasis>path</emphasis> to the current location because "
80 "following these folders from left to right leads here.</para>"
81 "<para>The path is displayed on the <emphasis>location bar</emphasis> "
82 "which is more powerful than one would expect. To learn more "
83 "about the basic and advanced features of the location bar "
84 "<link url='help:/dolphin/location-bar.html'>click here</link>. "
85 "This will open the dedicated page in the Handbook.</para>"));
87 m_urlNavigator
= new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url
, this);
88 connect(m_urlNavigator
, &KUrlNavigator::activated
,
89 this, &DolphinViewContainer::activate
);
90 connect(m_urlNavigator
->editor(), &KUrlComboBox::completionModeChanged
,
91 this, &DolphinViewContainer::saveUrlCompletionMode
);
93 const GeneralSettings
* settings
= GeneralSettings::self();
94 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
95 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
96 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
97 KUrlComboBox
* editor
= m_urlNavigator
->editor();
98 editor
->setCompletionMode(KCompletion::CompletionMode(settings
->urlCompletionMode()));
100 m_emptyTrashButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this);
101 m_emptyTrashButton
->setFlat(true);
102 connect(m_emptyTrashButton
, &QPushButton::clicked
, this, [this]() { Trash::empty(this); });
103 connect(&Trash::instance(), &Trash::emptinessChanged
, m_emptyTrashButton
, &QPushButton::setDisabled
);
104 m_emptyTrashButton
->setDisabled(Trash::isEmpty());
105 m_emptyTrashButton
->hide();
107 m_searchBox
= new DolphinSearchBox(this);
109 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
110 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
111 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
112 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
113 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
114 "<para>This helps you find files and folders. Enter a <emphasis>"
115 "search term</emphasis> and specify search settings with the "
116 "buttons at the bottom:<list><item>Filename/Content: "
117 "Does the item you are looking for contain the search terms "
118 "within its filename or its contents?<nl/>The contents of images, "
119 "audio files and videos will not be searched.</item><item>"
120 "From Here/Everywhere: Do you want to search in this "
121 "folder and its sub-folders or everywhere?</item><item>"
122 "More Options: Click this to search by media type, access "
123 "time or rating.</item><item>More Search Tools: Install other "
124 "means to find an item.</item></list></para>"));
126 m_messageWidget
= new KMessageWidget(this);
127 m_messageWidget
->setCloseButtonVisible(true);
128 m_messageWidget
->hide();
133 // We must be logged in as the root user; show a big scary warning
134 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
138 // Initialize filter bar
139 m_filterBar
= new FilterBar(this);
140 m_filterBar
->setVisible(settings
->filterBar());
142 connect(m_filterBar
, &FilterBar::filterChanged
,
143 this, &DolphinViewContainer::setNameFilter
);
144 connect(m_filterBar
, &FilterBar::closeRequest
,
145 this, &DolphinViewContainer::closeFilterBar
);
146 connect(m_filterBar
, &FilterBar::focusViewRequest
,
147 this, &DolphinViewContainer::requestFocus
);
149 // Initialize the main view
150 m_view
= new DolphinView(url
, this);
151 connect(m_view
, &DolphinView::urlChanged
,
152 m_filterBar
, &FilterBar::slotUrlChanged
);
153 connect(m_view
, &DolphinView::urlChanged
,
154 m_urlNavigator
, &KUrlNavigator::setLocationUrl
);
155 connect(m_view
, &DolphinView::urlChanged
,
156 m_messageWidget
, &KMessageWidget::hide
);
157 connect(m_view
, &DolphinView::writeStateChanged
,
158 this, &DolphinViewContainer::writeStateChanged
);
159 connect(m_view
, &DolphinView::requestItemInfo
,
160 this, &DolphinViewContainer::showItemInfo
);
161 connect(m_view
, &DolphinView::itemActivated
,
162 this, &DolphinViewContainer::slotItemActivated
);
163 connect(m_view
, &DolphinView::itemsActivated
,
164 this, &DolphinViewContainer::slotItemsActivated
);
165 connect(m_view
, &DolphinView::redirection
,
166 this, &DolphinViewContainer::redirect
);
167 connect(m_view
, &DolphinView::directoryLoadingStarted
,
168 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
169 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
170 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
171 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
172 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
173 connect(m_view
, &DolphinView::itemCountChanged
,
174 this, &DolphinViewContainer::delayedStatusBarUpdate
);
175 connect(m_view
, &DolphinView::directoryLoadingProgress
,
176 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
177 connect(m_view
, &DolphinView::directorySortingProgress
,
178 this, &DolphinViewContainer::updateDirectorySortingProgress
);
179 connect(m_view
, &DolphinView::selectionChanged
,
180 this, &DolphinViewContainer::delayedStatusBarUpdate
);
181 connect(m_view
, &DolphinView::errorMessage
,
182 this, &DolphinViewContainer::showErrorMessage
);
183 connect(m_view
, &DolphinView::urlIsFileError
,
184 this, &DolphinViewContainer::slotUrlIsFileError
);
185 connect(m_view
, &DolphinView::activated
,
186 this, &DolphinViewContainer::activate
);
188 connect(m_urlNavigator
, &KUrlNavigator::urlAboutToBeChanged
,
189 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
190 connect(m_urlNavigator
, &KUrlNavigator::urlChanged
,
191 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
192 connect(m_urlNavigator
, &KUrlNavigator::urlSelectionRequested
,
193 this, &DolphinViewContainer::slotUrlSelectionRequested
);
194 connect(m_urlNavigator
, &KUrlNavigator::returnPressed
,
195 this, &DolphinViewContainer::slotReturnPressed
);
196 connect(m_urlNavigator
, &KUrlNavigator::urlsDropped
, this, [=](const QUrl
&destination
, QDropEvent
*event
) {
197 m_view
->dropUrls(destination
, event
, m_urlNavigator
->dropWidget());
200 connect(m_view
, &DolphinView::directoryLoadingCompleted
, this, [this]() {
201 m_emptyTrashButton
->setVisible(m_view
->url().scheme() == QLatin1String("trash"));
204 // Initialize status bar
205 m_statusBar
= new DolphinStatusBar(this);
206 m_statusBar
->setUrl(m_view
->url());
207 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
208 connect(m_view
, &DolphinView::urlChanged
,
209 m_statusBar
, &DolphinStatusBar::setUrl
);
210 connect(m_view
, &DolphinView::zoomLevelChanged
,
211 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
212 connect(m_view
, &DolphinView::infoMessage
,
213 m_statusBar
, &DolphinStatusBar::setText
);
214 connect(m_view
, &DolphinView::operationCompletedMessage
,
215 m_statusBar
, &DolphinStatusBar::setText
);
216 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
217 this, &DolphinViewContainer::stopDirectoryLoading
);
218 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
219 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
221 m_statusBarTimer
= new QTimer(this);
222 m_statusBarTimer
->setSingleShot(true);
223 m_statusBarTimer
->setInterval(300);
224 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
226 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
227 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
228 this, &DolphinViewContainer::delayedStatusBarUpdate
);
230 navigatorLayout
->addWidget(m_urlNavigator
);
231 navigatorLayout
->addWidget(m_emptyTrashButton
);
233 m_topLayout
->addWidget(m_navigatorWidget
);
234 m_topLayout
->addWidget(m_searchBox
);
235 m_topLayout
->addWidget(m_messageWidget
);
236 m_topLayout
->addWidget(m_view
);
237 m_topLayout
->addWidget(m_filterBar
);
238 m_topLayout
->addWidget(m_statusBar
);
240 setSearchModeEnabled(isSearchUrl(url
));
242 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
243 if (view()->mode() == DolphinView::Mode::DetailsView
) {
248 // Initialize kactivities resource instance
250 #ifdef HAVE_KACTIVITIES
251 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
252 m_activityResourceInstance
->setParent(this);
256 DolphinViewContainer::~DolphinViewContainer()
260 QUrl
DolphinViewContainer::url() const
262 return m_view
->url();
265 void DolphinViewContainer::setActive(bool active
)
267 m_searchBox
->setActive(active
);
268 m_urlNavigator
->setActive(active
);
269 m_view
->setActive(active
);
271 #ifdef HAVE_KACTIVITIES
273 m_activityResourceInstance
->notifyFocusedIn();
275 m_activityResourceInstance
->notifyFocusedOut();
280 bool DolphinViewContainer::isActive() const
282 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
283 return m_view
->isActive();
286 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
288 m_autoGrabFocus
= grab
;
291 bool DolphinViewContainer::autoGrabFocus() const
293 return m_autoGrabFocus
;
296 QString
DolphinViewContainer::currentSearchText() const
298 return m_searchBox
->text();
301 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
306 DolphinStatusBar
* DolphinViewContainer::statusBar()
311 const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
313 return m_urlNavigator
;
316 KUrlNavigator
* DolphinViewContainer::urlNavigator()
318 return m_urlNavigator
;
321 const DolphinView
* DolphinViewContainer::view() const
326 DolphinView
* DolphinViewContainer::view()
331 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
337 m_messageWidget
->setText(msg
);
339 // TODO: wrap at arbitrary character positions once QLabel can do this
340 // https://bugreports.qt.io/browse/QTBUG-1276
341 m_messageWidget
->setWordWrap(true);
344 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
345 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
346 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
352 m_messageWidget
->setWordWrap(false);
353 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
354 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
356 if (m_messageWidget
->isVisible()) {
357 m_messageWidget
->hide();
359 m_messageWidget
->animatedShow();
362 void DolphinViewContainer::readSettings()
364 if (GeneralSettings::modifiedStartupSettings()) {
365 // The startup settings should only get applied if they have been
366 // modified by the user. Otherwise keep the (possibly) different current
367 // settings of the URL navigator and the filterbar.
368 m_urlNavigator
->setUrlEditable(GeneralSettings::editableUrl());
369 m_urlNavigator
->setShowFullPath(GeneralSettings::showFullPath());
370 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
371 setFilterBarVisible(GeneralSettings::filterBar());
374 m_view
->readSettings();
375 m_statusBar
->readSettings();
378 bool DolphinViewContainer::isFilterBarVisible() const
380 return m_filterBar
->isVisible();
383 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
385 m_searchBox
->setVisible(enabled
);
386 m_navigatorWidget
->setVisible(!enabled
);
389 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
390 m_searchBox
->fromSearchUrl(locationUrl
);
393 if (enabled
== isSearchModeEnabled()) {
394 if (enabled
&& !m_searchBox
->hasFocus()) {
395 m_searchBox
->setFocus();
396 m_searchBox
->selectAll();
402 m_view
->setViewPropertiesContext(QString());
404 // Restore the URL for the URL navigator. If Dolphin has been
405 // started with a search-URL, the home URL is used as fallback.
406 QUrl url
= m_searchBox
->searchPath();
407 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
408 url
= Dolphin::homeUrl();
410 m_urlNavigator
->setLocationUrl(url
);
413 m_searchModeEnabled
= enabled
;
415 emit
searchModeEnabledChanged(enabled
);
418 bool DolphinViewContainer::isSearchModeEnabled() const
420 return m_searchModeEnabled
;
423 QString
DolphinViewContainer::placesText() const
427 if (isSearchModeEnabled()) {
428 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
430 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
431 if (text
.isEmpty()) {
434 if (text
.isEmpty()) {
435 text
= url().scheme();
442 void DolphinViewContainer::reload()
445 m_messageWidget
->hide();
448 QString
DolphinViewContainer::captionWindowTitle() const
450 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
451 if (!url().isLocalFile()) {
452 return url().adjusted(QUrl::StripTrailingSlash
).toString();
454 return url().adjusted(QUrl::StripTrailingSlash
).path();
456 return DolphinViewContainer::caption();
460 QString
DolphinViewContainer::caption() const
462 if (isSearchModeEnabled()) {
463 if (currentSearchText().isEmpty()){
464 return i18n("Search");
466 return i18n("Search for %1", currentSearchText());
470 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
471 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QUrl(url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?")), 1, Qt::MatchRegExp
);
473 if (!matchedPlaces
.isEmpty()) {
474 return placesModel
->text(matchedPlaces
.first());
478 if (!url().isLocalFile()) {
479 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
481 if (!adjustedUrl
.fileName().isEmpty()) {
482 caption
= adjustedUrl
.fileName();
483 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
484 caption
= adjustedUrl
.path();
485 } else if (!adjustedUrl
.host().isEmpty()) {
486 caption
= adjustedUrl
.host();
488 caption
= adjustedUrl
.toString();
493 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
494 if (fileName
.isEmpty()) {
501 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
503 if (newUrl
!= m_urlNavigator
->locationUrl()) {
504 m_urlNavigator
->setLocationUrl(newUrl
);
507 #ifdef HAVE_KACTIVITIES
508 m_activityResourceInstance
->setUri(newUrl
);
512 void DolphinViewContainer::setFilterBarVisible(bool visible
)
514 Q_ASSERT(m_filterBar
);
516 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
518 m_filterBar
->setFocus();
519 m_filterBar
->selectAll();
525 void DolphinViewContainer::delayedStatusBarUpdate()
527 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
528 // No update of the statusbar has been done during the last 2 seconds,
529 // although an update has been requested. Trigger an immediate update.
530 m_statusBarTimer
->stop();
533 // Invoke updateStatusBar() with a small delay. This assures that
534 // when a lot of delayedStatusBarUpdates() are done in a short time,
535 // no bottleneck is given.
536 m_statusBarTimer
->start();
540 void DolphinViewContainer::updateStatusBar()
542 m_statusBarTimestamp
.start();
544 const QString text
= m_view
->statusBarText();
545 m_statusBar
->setDefaultText(text
);
546 m_statusBar
->resetToDefaultText();
549 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
551 if (m_statusBar
->progressText().isEmpty()) {
552 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
554 m_statusBar
->setProgress(percent
);
557 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
559 if (m_statusBar
->progressText().isEmpty()) {
560 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
562 m_statusBar
->setProgress(percent
);
565 void DolphinViewContainer::slotDirectoryLoadingStarted()
567 if (isSearchUrl(url())) {
568 // Search KIO-slaves usually don't provide any progress information. Give
569 // a hint to the user that a searching is done:
571 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
572 m_statusBar
->setProgress(-1);
574 // Trigger an undetermined progress indication. The progress
575 // information in percent will be triggered by the percent() signal
576 // of the directory lister later.
577 m_statusBar
->setProgressText(QString());
578 updateDirectoryLoadingProgress(-1);
582 void DolphinViewContainer::slotDirectoryLoadingCompleted()
584 if (!m_statusBar
->progressText().isEmpty()) {
585 m_statusBar
->setProgressText(QString());
586 m_statusBar
->setProgress(100);
589 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
590 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
591 // of showing the default status bar information ("0 items") a more helpful information is given:
592 m_statusBar
->setText(i18nc("@info:status", "No items found."));
598 void DolphinViewContainer::slotDirectoryLoadingCanceled()
600 if (!m_statusBar
->progressText().isEmpty()) {
601 m_statusBar
->setProgressText(QString());
602 m_statusBar
->setProgress(100);
605 m_statusBar
->setText(QString());
608 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
610 const KFileItem
item(url
);
612 // Find out if the file can be opened in the view (for example, this is the
613 // case if the file is an archive). The mime type must be known for that.
614 item
.determineMimeType();
615 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
616 if (!folderUrl
.isEmpty()) {
619 slotItemActivated(item
);
623 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
625 // It is possible to activate items on inactive views by
626 // drag & drop operations. Assure that activating an item always
627 // results in an active view.
628 m_view
->setActive(true);
630 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
631 if (!url
.isEmpty()) {
636 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl());
637 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
638 job
->setShowOpenOrExecuteDialog(true);
642 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
644 Q_ASSERT(items
.count() >= 2);
646 KFileItemActions
fileItemActions(this);
647 fileItemActions
.runPreferredApplications(items
, QString());
650 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
653 m_statusBar
->resetToDefaultText();
655 m_statusBar
->setText(item
.getStatusBarInfo());
659 void DolphinViewContainer::closeFilterBar()
661 m_filterBar
->closeFilterBar();
663 emit
showFilterBarChanged(false);
666 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
668 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
669 m_view
->setNameFilter(nameFilter
);
670 delayedStatusBarUpdate();
673 void DolphinViewContainer::activate()
678 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
683 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
687 if (KProtocolManager::supportsListing(url
)) {
688 setSearchModeEnabled(isSearchUrl(url
));
690 tryRestoreViewState();
692 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
693 // When an URL has been entered, the view should get the focus.
694 // The focus must be requested asynchronously, as changing the URL might create
695 // a new view widget.
696 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
698 } else if (KProtocolManager::isSourceProtocol(url
)) {
699 if (url
.scheme().startsWith(QLatin1String("http"))) {
700 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
701 "Dolphin does not support web pages, the web browser has been launched"),
704 showMessage(i18nc("@info:status",
705 "Protocol not supported by Dolphin, default application has been launched"),
709 QDesktopServices::openUrl(url
);
710 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
712 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
716 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
718 m_view
->markUrlsAsSelected({url
});
719 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
722 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
725 const bool block
= m_urlNavigator
->signalsBlocked();
726 m_urlNavigator
->blockSignals(true);
728 // Assure that the location state is reset for redirection URLs. This
729 // allows to skip redirection URLs when going back or forward in the
731 m_urlNavigator
->saveLocationState(QByteArray());
732 m_urlNavigator
->setLocationUrl(newUrl
);
733 setSearchModeEnabled(isSearchUrl(newUrl
));
735 m_urlNavigator
->blockSignals(block
);
738 void DolphinViewContainer::requestFocus()
743 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion
)
745 GeneralSettings::setUrlCompletionMode(completion
);
748 void DolphinViewContainer::slotReturnPressed()
750 if (!GeneralSettings::editableUrl()) {
751 m_urlNavigator
->setUrlEditable(false);
755 void DolphinViewContainer::startSearching()
757 const QUrl url
= m_searchBox
->urlForSearching();
758 if (url
.isValid() && !url
.isEmpty()) {
759 m_view
->setViewPropertiesContext(QStringLiteral("search"));
760 m_urlNavigator
->setLocationUrl(url
);
764 void DolphinViewContainer::closeSearchBox()
766 setSearchModeEnabled(false);
769 void DolphinViewContainer::stopDirectoryLoading()
771 m_view
->stopLoading();
772 m_statusBar
->setProgress(100);
775 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
777 m_view
->setZoomLevel(zoomLevel
);
780 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
782 showMessage(msg
, Error
);
785 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
787 return url
.scheme().contains(QLatin1String("search"));
790 void DolphinViewContainer::saveViewState()
792 QByteArray locationState
;
793 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
794 m_view
->saveState(stream
);
795 m_urlNavigator
->saveLocationState(locationState
);
798 void DolphinViewContainer::tryRestoreViewState()
800 QByteArray locationState
= m_urlNavigator
->locationState();
801 if (!locationState
.isEmpty()) {
802 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
803 m_view
->restoreState(stream
);