1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinviewcontainer.h"
22 #include "dolphin_generalsettings.h"
23 #include "dolphinplacesmodelsingleton.h"
24 #include "dolphindebug.h"
25 #include "filterbar/filterbar.h"
27 #include "search/dolphinsearchbox.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "trash/dolphintrash.h"
30 #include "views/viewmodecontroller.h"
31 #include "views/viewproperties.h"
33 #include <KFileItemActions>
34 #include <KFilePlacesModel>
35 #include <KIO/PreviewJob>
36 #include <KLocalizedString>
37 #include <KMessageWidget>
38 #include <KProtocolManager>
41 #include <KUrlComboBox>
42 #include <KUrlNavigator>
43 #include <kio_version.h>
46 #include <QLoggingCategory>
50 #include <QVBoxLayout>
52 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
55 m_navigatorWidget(nullptr),
56 m_urlNavigator(nullptr),
57 m_emptyTrashButton(nullptr),
59 m_searchModeEnabled(false),
60 m_messageWidget(nullptr),
64 m_statusBarTimer(nullptr),
65 m_statusBarTimestamp(),
67 #ifdef KActivities_FOUND
68 , m_activityResourceInstance(0)
73 m_topLayout
= new QVBoxLayout(this);
74 m_topLayout
->setSpacing(0);
75 m_topLayout
->setMargin(0);
77 m_navigatorWidget
= new QWidget(this);
78 QHBoxLayout
* navigatorLayout
= new QHBoxLayout(m_navigatorWidget
);
79 navigatorLayout
->setSpacing(0);
80 navigatorLayout
->setMargin(0);
82 m_urlNavigator
= new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url
, this);
83 connect(m_urlNavigator
, &KUrlNavigator::activated
,
84 this, &DolphinViewContainer::activate
);
85 connect(m_urlNavigator
->editor(), &KUrlComboBox::completionModeChanged
,
86 this, &DolphinViewContainer::saveUrlCompletionMode
);
88 const GeneralSettings
* settings
= GeneralSettings::self();
89 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
90 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
91 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
92 KUrlComboBox
* editor
= m_urlNavigator
->editor();
93 editor
->setCompletionMode(KCompletion::CompletionMode(settings
->urlCompletionMode()));
95 m_emptyTrashButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this);
96 m_emptyTrashButton
->setFlat(true);
97 connect(m_emptyTrashButton
, &QPushButton::clicked
, this, [this]() { Trash::empty(this); });
98 connect(&Trash::instance(), &Trash::emptinessChanged
, m_emptyTrashButton
, &QPushButton::setDisabled
);
99 m_emptyTrashButton
->setDisabled(Trash::isEmpty());
100 m_emptyTrashButton
->hide();
102 m_searchBox
= new DolphinSearchBox(this);
104 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
105 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
106 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
107 connect(m_searchBox
, &DolphinSearchBox::returnPressed
, this, &DolphinViewContainer::requestFocus
);
109 m_messageWidget
= new KMessageWidget(this);
110 m_messageWidget
->setCloseButtonVisible(true);
111 m_messageWidget
->hide();
116 // We must be logged in as the root user; show a big scary warning
117 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
121 m_view
= new DolphinView(url
, this);
122 connect(m_view
, &DolphinView::urlChanged
,
123 m_urlNavigator
, &KUrlNavigator::setLocationUrl
);
124 connect(m_view
, &DolphinView::urlChanged
,
125 m_messageWidget
, &KMessageWidget::hide
);
126 connect(m_view
, &DolphinView::writeStateChanged
,
127 this, &DolphinViewContainer::writeStateChanged
);
128 connect(m_view
, &DolphinView::requestItemInfo
,
129 this, &DolphinViewContainer::showItemInfo
);
130 connect(m_view
, &DolphinView::itemActivated
,
131 this, &DolphinViewContainer::slotItemActivated
);
132 connect(m_view
, &DolphinView::itemsActivated
,
133 this, &DolphinViewContainer::slotItemsActivated
);
134 connect(m_view
, &DolphinView::redirection
,
135 this, &DolphinViewContainer::redirect
);
136 connect(m_view
, &DolphinView::directoryLoadingStarted
,
137 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
138 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
139 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
140 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
141 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
142 connect(m_view
, &DolphinView::itemCountChanged
,
143 this, &DolphinViewContainer::delayedStatusBarUpdate
);
144 connect(m_view
, &DolphinView::directoryLoadingProgress
,
145 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
146 connect(m_view
, &DolphinView::directorySortingProgress
,
147 this, &DolphinViewContainer::updateDirectorySortingProgress
);
148 connect(m_view
, &DolphinView::selectionChanged
,
149 this, &DolphinViewContainer::delayedStatusBarUpdate
);
150 connect(m_view
, &DolphinView::errorMessage
,
151 this, &DolphinViewContainer::showErrorMessage
);
152 connect(m_view
, &DolphinView::urlIsFileError
,
153 this, &DolphinViewContainer::slotUrlIsFileError
);
154 connect(m_view
, &DolphinView::activated
,
155 this, &DolphinViewContainer::activate
);
157 connect(m_urlNavigator
, &KUrlNavigator::urlAboutToBeChanged
,
158 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
159 connect(m_urlNavigator
, &KUrlNavigator::urlChanged
,
160 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
161 connect(m_urlNavigator
, &KUrlNavigator::urlSelectionRequested
,
162 this, &DolphinViewContainer::slotUrlSelectionRequested
);
163 connect(m_urlNavigator
, &KUrlNavigator::returnPressed
,
164 this, &DolphinViewContainer::slotReturnPressed
);
165 connect(m_urlNavigator
, &KUrlNavigator::urlsDropped
, this, [=](const QUrl
&destination
, QDropEvent
*event
) {
166 m_view
->dropUrls(destination
, event
, m_urlNavigator
->dropWidget());
169 connect(m_view
, &DolphinView::directoryLoadingCompleted
, this, [this]() {
170 m_emptyTrashButton
->setVisible(m_view
->url().scheme() == QLatin1String("trash"));
173 // Initialize status bar
174 m_statusBar
= new DolphinStatusBar(this);
175 m_statusBar
->setUrl(m_view
->url());
176 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
177 connect(m_view
, &DolphinView::urlChanged
,
178 m_statusBar
, &DolphinStatusBar::setUrl
);
179 connect(m_view
, &DolphinView::zoomLevelChanged
,
180 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
181 connect(m_view
, &DolphinView::infoMessage
,
182 m_statusBar
, &DolphinStatusBar::setText
);
183 connect(m_view
, &DolphinView::operationCompletedMessage
,
184 m_statusBar
, &DolphinStatusBar::setText
);
185 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
186 this, &DolphinViewContainer::stopDirectoryLoading
);
187 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
188 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
190 m_statusBarTimer
= new QTimer(this);
191 m_statusBarTimer
->setSingleShot(true);
192 m_statusBarTimer
->setInterval(300);
193 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
195 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
196 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
197 this, &DolphinViewContainer::delayedStatusBarUpdate
);
199 // Initialize filter bar
200 m_filterBar
= new FilterBar(this);
201 m_filterBar
->setVisible(settings
->filterBar());
202 connect(m_filterBar
, &FilterBar::filterChanged
,
203 this, &DolphinViewContainer::setNameFilter
);
204 connect(m_filterBar
, &FilterBar::closeRequest
,
205 this, &DolphinViewContainer::closeFilterBar
);
206 connect(m_filterBar
, &FilterBar::focusViewRequest
,
207 this, &DolphinViewContainer::requestFocus
);
208 connect(m_view
, &DolphinView::urlChanged
,
209 m_filterBar
, &FilterBar::slotUrlChanged
);
211 navigatorLayout
->addWidget(m_urlNavigator
);
212 navigatorLayout
->addWidget(m_emptyTrashButton
);
214 m_topLayout
->addWidget(m_navigatorWidget
);
215 m_topLayout
->addWidget(m_searchBox
);
216 m_topLayout
->addWidget(m_messageWidget
);
217 m_topLayout
->addWidget(m_view
);
218 m_topLayout
->addWidget(m_filterBar
);
219 m_topLayout
->addWidget(m_statusBar
);
221 setSearchModeEnabled(isSearchUrl(url
));
223 // Initialize kactivities resource instance
225 #ifdef KActivities_FOUND
226 m_activityResourceInstance
= new KActivities::ResourceInstance(
227 window()->winId(), url
);
228 m_activityResourceInstance
->setParent(this);
232 DolphinViewContainer::~DolphinViewContainer()
236 QUrl
DolphinViewContainer::url() const
238 return m_view
->url();
241 void DolphinViewContainer::setActive(bool active
)
243 m_searchBox
->setActive(active
);
244 m_urlNavigator
->setActive(active
);
245 m_view
->setActive(active
);
247 #ifdef KActivities_FOUND
249 m_activityResourceInstance
->notifyFocusedIn();
251 m_activityResourceInstance
->notifyFocusedOut();
256 bool DolphinViewContainer::isActive() const
258 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
259 return m_view
->isActive();
262 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
264 m_autoGrabFocus
= grab
;
267 bool DolphinViewContainer::autoGrabFocus() const
269 return m_autoGrabFocus
;
272 QString
DolphinViewContainer::currentSearchText() const
274 return m_searchBox
->text();
277 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
282 DolphinStatusBar
* DolphinViewContainer::statusBar()
287 const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
289 return m_urlNavigator
;
292 KUrlNavigator
* DolphinViewContainer::urlNavigator()
294 return m_urlNavigator
;
297 const DolphinView
* DolphinViewContainer::view() const
302 DolphinView
* DolphinViewContainer::view()
307 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
313 m_messageWidget
->setText(msg
);
315 // TODO: wrap at arbitrary character positions once QLabel can do this
316 // https://bugreports.qt.io/browse/QTBUG-1276
317 m_messageWidget
->setWordWrap(true);
320 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
321 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
322 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
328 m_messageWidget
->setWordWrap(false);
329 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
330 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
332 if (m_messageWidget
->isVisible()) {
333 m_messageWidget
->hide();
335 m_messageWidget
->animatedShow();
338 void DolphinViewContainer::readSettings()
340 if (GeneralSettings::modifiedStartupSettings()) {
341 // The startup settings should only get applied if they have been
342 // modified by the user. Otherwise keep the (possibly) different current
343 // settings of the URL navigator and the filterbar.
344 m_urlNavigator
->setUrlEditable(GeneralSettings::editableUrl());
345 m_urlNavigator
->setShowFullPath(GeneralSettings::showFullPath());
346 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
347 setFilterBarVisible(GeneralSettings::filterBar());
350 m_view
->readSettings();
351 m_statusBar
->readSettings();
354 bool DolphinViewContainer::isFilterBarVisible() const
356 return m_filterBar
->isVisible();
359 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
361 if (enabled
== isSearchModeEnabled()) {
362 if (enabled
&& !m_searchBox
->hasFocus()) {
363 m_searchBox
->setFocus();
364 m_searchBox
->selectAll();
369 m_searchBox
->setVisible(enabled
);
370 m_navigatorWidget
->setVisible(!enabled
);
373 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
374 m_searchBox
->fromSearchUrl(locationUrl
);
376 m_view
->setViewPropertiesContext(QString());
378 // Restore the URL for the URL navigator. If Dolphin has been
379 // started with a search-URL, the home URL is used as fallback.
380 QUrl url
= m_searchBox
->searchPath();
381 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
382 url
= Dolphin::homeUrl();
384 m_urlNavigator
->setLocationUrl(url
);
387 m_searchModeEnabled
= enabled
;
390 bool DolphinViewContainer::isSearchModeEnabled() const
392 return m_searchModeEnabled
;
395 QString
DolphinViewContainer::placesText() const
399 if (isSearchModeEnabled()) {
400 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
402 text
= url().fileName();
403 if (text
.isEmpty()) {
406 if (text
.isEmpty()) {
407 text
= url().scheme();
414 void DolphinViewContainer::reload()
417 m_messageWidget
->hide();
420 QString
DolphinViewContainer::caption() const
422 if (GeneralSettings::showFullPathInTitlebar()) {
423 if (!url().isLocalFile()) {
424 return url().adjusted(QUrl::StripTrailingSlash
).toString();
426 return url().adjusted(QUrl::StripTrailingSlash
).path();
429 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
430 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, url(), 1, Qt::MatchExactly
);
432 if (!matchedPlaces
.isEmpty()) {
433 return placesModel
->text(matchedPlaces
.first());
436 if (isSearchModeEnabled()) {
437 if (currentSearchText().isEmpty()){
438 return i18n("Search");
440 return i18n("Search for %1", currentSearchText());
444 if (!url().isLocalFile()) {
445 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
447 if (!adjustedUrl
.fileName().isEmpty()) {
448 caption
= adjustedUrl
.fileName();
449 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
450 caption
= adjustedUrl
.path();
451 } else if (!adjustedUrl
.host().isEmpty()) {
452 caption
= adjustedUrl
.host();
454 caption
= adjustedUrl
.toString();
459 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
460 if (fileName
.isEmpty()) {
467 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
469 if (newUrl
!= m_urlNavigator
->locationUrl()) {
470 m_urlNavigator
->setLocationUrl(newUrl
);
473 #ifdef KActivities_FOUND
474 m_activityResourceInstance
->setUri(newUrl
);
478 void DolphinViewContainer::setFilterBarVisible(bool visible
)
480 Q_ASSERT(m_filterBar
);
483 m_filterBar
->setFocus();
484 m_filterBar
->selectAll();
490 void DolphinViewContainer::delayedStatusBarUpdate()
492 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
493 // No update of the statusbar has been done during the last 2 seconds,
494 // although an update has been requested. Trigger an immediate update.
495 m_statusBarTimer
->stop();
498 // Invoke updateStatusBar() with a small delay. This assures that
499 // when a lot of delayedStatusBarUpdates() are done in a short time,
500 // no bottleneck is given.
501 m_statusBarTimer
->start();
505 void DolphinViewContainer::updateStatusBar()
507 m_statusBarTimestamp
.start();
509 const QString text
= m_view
->statusBarText();
510 m_statusBar
->setDefaultText(text
);
511 m_statusBar
->resetToDefaultText();
514 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
516 if (m_statusBar
->progressText().isEmpty()) {
517 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
519 m_statusBar
->setProgress(percent
);
522 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
524 if (m_statusBar
->progressText().isEmpty()) {
525 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
527 m_statusBar
->setProgress(percent
);
530 void DolphinViewContainer::slotDirectoryLoadingStarted()
532 if (isSearchUrl(url())) {
533 // Search KIO-slaves usually don't provide any progress information. Give
534 // a hint to the user that a searching is done:
536 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
537 m_statusBar
->setProgress(-1);
539 // Trigger an undetermined progress indication. The progress
540 // information in percent will be triggered by the percent() signal
541 // of the directory lister later.
542 updateDirectoryLoadingProgress(-1);
546 void DolphinViewContainer::slotDirectoryLoadingCompleted()
548 if (!m_statusBar
->progressText().isEmpty()) {
549 m_statusBar
->setProgressText(QString());
550 m_statusBar
->setProgress(100);
553 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
554 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
555 // of showing the default status bar information ("0 items") a more helpful information is given:
556 m_statusBar
->setText(i18nc("@info:status", "No items found."));
562 void DolphinViewContainer::slotDirectoryLoadingCanceled()
564 if (!m_statusBar
->progressText().isEmpty()) {
565 m_statusBar
->setProgressText(QString());
566 m_statusBar
->setProgress(100);
569 m_statusBar
->setText(QString());
572 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
574 const KFileItem
item(url
);
576 // Find out if the file can be opened in the view (for example, this is the
577 // case if the file is an archive). The mime type must be known for that.
578 item
.determineMimeType();
579 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
580 if (!folderUrl
.isEmpty()) {
583 slotItemActivated(item
);
587 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
589 // It is possible to activate items on inactive views by
590 // drag & drop operations. Assure that activating an item always
591 // results in an active view.
592 m_view
->setActive(true);
594 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
595 if (!url
.isEmpty()) {
600 KRun
*run
= new KRun(item
.targetUrl(), this);
601 run
->setShowScriptExecutionPrompt(true);
604 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
606 Q_ASSERT(items
.count() >= 2);
608 KFileItemActions
fileItemActions(this);
609 fileItemActions
.runPreferredApplications(items
, QString());
612 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
615 m_statusBar
->resetToDefaultText();
617 m_statusBar
->setText(item
.getStatusBarInfo());
621 void DolphinViewContainer::closeFilterBar()
623 m_filterBar
->closeFilterBar();
625 emit
showFilterBarChanged(false);
628 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
630 m_view
->setNameFilter(nameFilter
);
631 delayedStatusBarUpdate();
634 void DolphinViewContainer::activate()
639 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
644 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
648 if (KProtocolManager::supportsListing(url
)) {
649 setSearchModeEnabled(isSearchUrl(url
));
651 tryRestoreViewState();
653 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
654 // When an URL has been entered, the view should get the focus.
655 // The focus must be requested asynchronously, as changing the URL might create
656 // a new view widget.
657 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
659 } else if (KProtocolManager::isSourceProtocol(url
)) {
660 QString app
= QStringLiteral("konqueror");
661 if (url
.scheme().startsWith(QLatin1String("http"))) {
662 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
663 "Dolphin does not support web pages, the web browser has been launched"),
666 const KConfigGroup
config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "General");
667 const QString browser
= config
.readEntry("BrowserApplication");
668 if (!browser
.isEmpty()) {
670 if (app
.startsWith('!')) {
671 // a literal command has been configured, remove the '!' prefix
676 showMessage(i18nc("@info:status",
677 "Protocol not supported by Dolphin, Konqueror has been launched"),
681 const QString secureUrl
= KShell::quoteArg(url
.toDisplayString(QUrl::PreferLocalFile
));
682 const QString command
= app
+ ' ' + secureUrl
;
683 KRun::runCommand(command
, app
, app
, this);
685 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
689 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
691 m_view
->markUrlsAsSelected({url
});
692 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
695 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
698 const bool block
= m_urlNavigator
->signalsBlocked();
699 m_urlNavigator
->blockSignals(true);
701 // Assure that the location state is reset for redirection URLs. This
702 // allows to skip redirection URLs when going back or forward in the
704 m_urlNavigator
->saveLocationState(QByteArray());
705 m_urlNavigator
->setLocationUrl(newUrl
);
706 setSearchModeEnabled(isSearchUrl(newUrl
));
708 m_urlNavigator
->blockSignals(block
);
711 void DolphinViewContainer::requestFocus()
716 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion
)
718 GeneralSettings::setUrlCompletionMode(completion
);
721 void DolphinViewContainer::slotReturnPressed()
723 if (!GeneralSettings::editableUrl()) {
724 m_urlNavigator
->setUrlEditable(false);
728 void DolphinViewContainer::startSearching()
730 const QUrl url
= m_searchBox
->urlForSearching();
731 if (url
.isValid() && !url
.isEmpty()) {
732 m_view
->setViewPropertiesContext(QStringLiteral("search"));
733 m_urlNavigator
->setLocationUrl(url
);
737 void DolphinViewContainer::closeSearchBox()
739 setSearchModeEnabled(false);
742 void DolphinViewContainer::stopDirectoryLoading()
744 m_view
->stopLoading();
745 m_statusBar
->setProgress(100);
748 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
750 m_view
->setZoomLevel(zoomLevel
);
753 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
755 showMessage(msg
, Error
);
758 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
760 return url
.scheme().contains(QStringLiteral("search"));
763 void DolphinViewContainer::saveViewState()
765 QByteArray locationState
;
766 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
767 m_view
->saveState(stream
);
768 m_urlNavigator
->saveLocationState(locationState
);
771 void DolphinViewContainer::tryRestoreViewState()
773 QByteArray locationState
= m_urlNavigator
->locationState();
774 if (!locationState
.isEmpty()) {
775 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
776 m_view
->restoreState(stream
);