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 #ifdef HAVE_KACTIVITIES
34 #include <KActivities/ResourceInstance>
36 #include <KFileItemActions>
37 #include <KFilePlacesModel>
38 #include <KIO/PreviewJob>
39 #include <KLocalizedString>
40 #include <KMessageWidget>
41 #include <KProtocolManager>
44 #include <KUrlComboBox>
45 #include <KUrlNavigator>
48 #include <QLoggingCategory>
52 #include <QVBoxLayout>
53 #include <QDesktopServices>
55 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
58 m_navigatorWidget(nullptr),
59 m_urlNavigator(nullptr),
60 m_emptyTrashButton(nullptr),
62 m_searchModeEnabled(false),
63 m_messageWidget(nullptr),
67 m_statusBarTimer(nullptr),
68 m_statusBarTimestamp(),
70 #ifdef HAVE_KACTIVITIES
71 , m_activityResourceInstance(nullptr)
76 m_topLayout
= new QVBoxLayout(this);
77 m_topLayout
->setSpacing(0);
78 m_topLayout
->setContentsMargins(0, 0, 0, 0);
80 m_navigatorWidget
= new QWidget(this);
81 QHBoxLayout
* navigatorLayout
= new QHBoxLayout(m_navigatorWidget
);
82 navigatorLayout
->setSpacing(0);
83 navigatorLayout
->setContentsMargins(0, 0, 0, 0);
84 m_navigatorWidget
->setWhatsThis(xi18nc("@info:whatsthis location bar",
85 "<para>This line describes the location of the files and folders "
86 "displayed below.</para><para>The name of the currently viewed "
87 "folder can be read at the very right. To the left of it is the "
88 "name of the folder that contains it. The whole line is called "
89 "the <emphasis>path</emphasis> to the current location because "
90 "following these folders from left to right leads here.</para>"
91 "<para>The path is displayed on the <emphasis>location bar</emphasis> "
92 "which is more powerful than one would expect. To learn more "
93 "about the basic and advanced features of the location bar "
94 "<link url='help:/dolphin/location-bar.html'>click here</link>. "
95 "This will open the dedicated page in the Handbook.</para>"));
97 m_urlNavigator
= new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url
, this);
98 connect(m_urlNavigator
, &KUrlNavigator::activated
,
99 this, &DolphinViewContainer::activate
);
100 connect(m_urlNavigator
->editor(), &KUrlComboBox::completionModeChanged
,
101 this, &DolphinViewContainer::saveUrlCompletionMode
);
103 const GeneralSettings
* settings
= GeneralSettings::self();
104 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
105 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
106 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
107 KUrlComboBox
* editor
= m_urlNavigator
->editor();
108 editor
->setCompletionMode(KCompletion::CompletionMode(settings
->urlCompletionMode()));
110 m_emptyTrashButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this);
111 m_emptyTrashButton
->setFlat(true);
112 connect(m_emptyTrashButton
, &QPushButton::clicked
, this, [this]() { Trash::empty(this); });
113 connect(&Trash::instance(), &Trash::emptinessChanged
, m_emptyTrashButton
, &QPushButton::setDisabled
);
114 m_emptyTrashButton
->setDisabled(Trash::isEmpty());
115 m_emptyTrashButton
->hide();
117 m_searchBox
= new DolphinSearchBox(this);
119 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
120 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
121 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
122 connect(m_searchBox
, &DolphinSearchBox::returnPressed
, this, &DolphinViewContainer::requestFocus
);
123 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
124 "<para>This helps you find files and folders. Enter a <emphasis>"
125 "search term</emphasis> and specify search settings with the "
126 "buttons at the bottom:<list><item>Filename/Content: "
127 "Does the item you are looking for contain the search terms "
128 "within its filename or its contents?<nl/>The contents of images, "
129 "audio files and videos will not be searched.</item><item>"
130 "From Here/Everywhere: Do you want to search in this "
131 "folder and its sub-folders or everywhere?</item><item>"
132 "More Options: Click this to search by media type, access "
133 "time or rating.</item><item>More Search Tools: Install other "
134 "means to find an item.</item></list></para>"));
136 m_messageWidget
= new KMessageWidget(this);
137 m_messageWidget
->setCloseButtonVisible(true);
138 m_messageWidget
->hide();
143 // We must be logged in as the root user; show a big scary warning
144 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
148 // Initialize filter bar
149 m_filterBar
= new FilterBar(this);
150 m_filterBar
->setVisible(settings
->filterBar());
152 connect(m_filterBar
, &FilterBar::filterChanged
,
153 this, &DolphinViewContainer::setNameFilter
);
154 connect(m_filterBar
, &FilterBar::closeRequest
,
155 this, &DolphinViewContainer::closeFilterBar
);
156 connect(m_filterBar
, &FilterBar::focusViewRequest
,
157 this, &DolphinViewContainer::requestFocus
);
159 // Initialize the main view
160 m_view
= new DolphinView(url
, this);
161 connect(m_view
, &DolphinView::urlChanged
,
162 m_filterBar
, &FilterBar::slotUrlChanged
);
163 connect(m_view
, &DolphinView::urlChanged
,
164 m_urlNavigator
, &KUrlNavigator::setLocationUrl
);
165 connect(m_view
, &DolphinView::urlChanged
,
166 m_messageWidget
, &KMessageWidget::hide
);
167 connect(m_view
, &DolphinView::writeStateChanged
,
168 this, &DolphinViewContainer::writeStateChanged
);
169 connect(m_view
, &DolphinView::requestItemInfo
,
170 this, &DolphinViewContainer::showItemInfo
);
171 connect(m_view
, &DolphinView::itemActivated
,
172 this, &DolphinViewContainer::slotItemActivated
);
173 connect(m_view
, &DolphinView::itemsActivated
,
174 this, &DolphinViewContainer::slotItemsActivated
);
175 connect(m_view
, &DolphinView::redirection
,
176 this, &DolphinViewContainer::redirect
);
177 connect(m_view
, &DolphinView::directoryLoadingStarted
,
178 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
179 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
180 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
181 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
182 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
183 connect(m_view
, &DolphinView::itemCountChanged
,
184 this, &DolphinViewContainer::delayedStatusBarUpdate
);
185 connect(m_view
, &DolphinView::directoryLoadingProgress
,
186 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
187 connect(m_view
, &DolphinView::directorySortingProgress
,
188 this, &DolphinViewContainer::updateDirectorySortingProgress
);
189 connect(m_view
, &DolphinView::selectionChanged
,
190 this, &DolphinViewContainer::delayedStatusBarUpdate
);
191 connect(m_view
, &DolphinView::errorMessage
,
192 this, &DolphinViewContainer::showErrorMessage
);
193 connect(m_view
, &DolphinView::urlIsFileError
,
194 this, &DolphinViewContainer::slotUrlIsFileError
);
195 connect(m_view
, &DolphinView::activated
,
196 this, &DolphinViewContainer::activate
);
198 connect(m_urlNavigator
, &KUrlNavigator::urlAboutToBeChanged
,
199 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
200 connect(m_urlNavigator
, &KUrlNavigator::urlChanged
,
201 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
202 connect(m_urlNavigator
, &KUrlNavigator::urlSelectionRequested
,
203 this, &DolphinViewContainer::slotUrlSelectionRequested
);
204 connect(m_urlNavigator
, &KUrlNavigator::returnPressed
,
205 this, &DolphinViewContainer::slotReturnPressed
);
206 connect(m_urlNavigator
, &KUrlNavigator::urlsDropped
, this, [=](const QUrl
&destination
, QDropEvent
*event
) {
207 m_view
->dropUrls(destination
, event
, m_urlNavigator
->dropWidget());
210 connect(m_view
, &DolphinView::directoryLoadingCompleted
, this, [this]() {
211 m_emptyTrashButton
->setVisible(m_view
->url().scheme() == QLatin1String("trash"));
214 // Initialize status bar
215 m_statusBar
= new DolphinStatusBar(this);
216 m_statusBar
->setUrl(m_view
->url());
217 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
218 connect(m_view
, &DolphinView::urlChanged
,
219 m_statusBar
, &DolphinStatusBar::setUrl
);
220 connect(m_view
, &DolphinView::zoomLevelChanged
,
221 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
222 connect(m_view
, &DolphinView::infoMessage
,
223 m_statusBar
, &DolphinStatusBar::setText
);
224 connect(m_view
, &DolphinView::operationCompletedMessage
,
225 m_statusBar
, &DolphinStatusBar::setText
);
226 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
227 this, &DolphinViewContainer::stopDirectoryLoading
);
228 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
229 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
231 m_statusBarTimer
= new QTimer(this);
232 m_statusBarTimer
->setSingleShot(true);
233 m_statusBarTimer
->setInterval(300);
234 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
236 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
237 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
238 this, &DolphinViewContainer::delayedStatusBarUpdate
);
240 navigatorLayout
->addWidget(m_urlNavigator
);
241 navigatorLayout
->addWidget(m_emptyTrashButton
);
243 m_topLayout
->addWidget(m_navigatorWidget
);
244 m_topLayout
->addWidget(m_searchBox
);
245 m_topLayout
->addWidget(m_messageWidget
);
246 m_topLayout
->addWidget(m_view
);
247 m_topLayout
->addWidget(m_filterBar
);
248 m_topLayout
->addWidget(m_statusBar
);
250 setSearchModeEnabled(isSearchUrl(url
));
252 // Initialize kactivities resource instance
254 #ifdef HAVE_KACTIVITIES
255 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
256 m_activityResourceInstance
->setParent(this);
260 DolphinViewContainer::~DolphinViewContainer()
264 QUrl
DolphinViewContainer::url() const
266 return m_view
->url();
269 void DolphinViewContainer::setActive(bool active
)
271 m_searchBox
->setActive(active
);
272 m_urlNavigator
->setActive(active
);
273 m_view
->setActive(active
);
275 #ifdef HAVE_KACTIVITIES
277 m_activityResourceInstance
->notifyFocusedIn();
279 m_activityResourceInstance
->notifyFocusedOut();
284 bool DolphinViewContainer::isActive() const
286 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
287 return m_view
->isActive();
290 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
292 m_autoGrabFocus
= grab
;
295 bool DolphinViewContainer::autoGrabFocus() const
297 return m_autoGrabFocus
;
300 QString
DolphinViewContainer::currentSearchText() const
302 return m_searchBox
->text();
305 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
310 DolphinStatusBar
* DolphinViewContainer::statusBar()
315 const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
317 return m_urlNavigator
;
320 KUrlNavigator
* DolphinViewContainer::urlNavigator()
322 return m_urlNavigator
;
325 const DolphinView
* DolphinViewContainer::view() const
330 DolphinView
* DolphinViewContainer::view()
335 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
341 m_messageWidget
->setText(msg
);
343 // TODO: wrap at arbitrary character positions once QLabel can do this
344 // https://bugreports.qt.io/browse/QTBUG-1276
345 m_messageWidget
->setWordWrap(true);
348 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
349 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
350 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
356 m_messageWidget
->setWordWrap(false);
357 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
358 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
360 if (m_messageWidget
->isVisible()) {
361 m_messageWidget
->hide();
363 m_messageWidget
->animatedShow();
366 void DolphinViewContainer::readSettings()
368 if (GeneralSettings::modifiedStartupSettings()) {
369 // The startup settings should only get applied if they have been
370 // modified by the user. Otherwise keep the (possibly) different current
371 // settings of the URL navigator and the filterbar.
372 m_urlNavigator
->setUrlEditable(GeneralSettings::editableUrl());
373 m_urlNavigator
->setShowFullPath(GeneralSettings::showFullPath());
374 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
375 setFilterBarVisible(GeneralSettings::filterBar());
378 m_view
->readSettings();
379 m_statusBar
->readSettings();
382 bool DolphinViewContainer::isFilterBarVisible() const
384 return m_filterBar
->isVisible();
387 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
389 m_searchBox
->setVisible(enabled
);
390 m_navigatorWidget
->setVisible(!enabled
);
393 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
394 m_searchBox
->fromSearchUrl(locationUrl
);
397 if (enabled
== isSearchModeEnabled()) {
398 if (enabled
&& !m_searchBox
->hasFocus()) {
399 m_searchBox
->setFocus();
400 m_searchBox
->selectAll();
406 m_view
->setViewPropertiesContext(QString());
408 // Restore the URL for the URL navigator. If Dolphin has been
409 // started with a search-URL, the home URL is used as fallback.
410 QUrl url
= m_searchBox
->searchPath();
411 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
412 url
= Dolphin::homeUrl();
414 m_urlNavigator
->setLocationUrl(url
);
417 m_searchModeEnabled
= enabled
;
419 emit
searchModeEnabledChanged(enabled
);
422 bool DolphinViewContainer::isSearchModeEnabled() const
424 return m_searchModeEnabled
;
427 QString
DolphinViewContainer::placesText() const
431 if (isSearchModeEnabled()) {
432 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
434 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
435 if (text
.isEmpty()) {
438 if (text
.isEmpty()) {
439 text
= url().scheme();
446 void DolphinViewContainer::reload()
449 m_messageWidget
->hide();
452 QString
DolphinViewContainer::caption() const
454 if (isSearchModeEnabled()) {
455 if (currentSearchText().isEmpty()){
456 return i18n("Search");
458 return i18n("Search for %1", currentSearchText());
462 if (GeneralSettings::showFullPathInTitlebar()) {
463 if (!url().isLocalFile()) {
464 return url().adjusted(QUrl::StripTrailingSlash
).toString();
466 return url().adjusted(QUrl::StripTrailingSlash
).path();
469 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
470 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QUrl(url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?")), 1, Qt::MatchRegExp
);
472 if (!matchedPlaces
.isEmpty()) {
473 return placesModel
->text(matchedPlaces
.first());
477 if (!url().isLocalFile()) {
478 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
480 if (!adjustedUrl
.fileName().isEmpty()) {
481 caption
= adjustedUrl
.fileName();
482 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
483 caption
= adjustedUrl
.path();
484 } else if (!adjustedUrl
.host().isEmpty()) {
485 caption
= adjustedUrl
.host();
487 caption
= adjustedUrl
.toString();
492 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
493 if (fileName
.isEmpty()) {
500 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
502 if (newUrl
!= m_urlNavigator
->locationUrl()) {
503 m_urlNavigator
->setLocationUrl(newUrl
);
506 #ifdef HAVE_KACTIVITIES
507 m_activityResourceInstance
->setUri(newUrl
);
511 void DolphinViewContainer::setFilterBarVisible(bool visible
)
513 Q_ASSERT(m_filterBar
);
515 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
517 m_filterBar
->setFocus();
518 m_filterBar
->selectAll();
524 void DolphinViewContainer::delayedStatusBarUpdate()
526 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
527 // No update of the statusbar has been done during the last 2 seconds,
528 // although an update has been requested. Trigger an immediate update.
529 m_statusBarTimer
->stop();
532 // Invoke updateStatusBar() with a small delay. This assures that
533 // when a lot of delayedStatusBarUpdates() are done in a short time,
534 // no bottleneck is given.
535 m_statusBarTimer
->start();
539 void DolphinViewContainer::updateStatusBar()
541 m_statusBarTimestamp
.start();
543 const QString text
= m_view
->statusBarText();
544 m_statusBar
->setDefaultText(text
);
545 m_statusBar
->resetToDefaultText();
548 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
550 if (m_statusBar
->progressText().isEmpty()) {
551 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
553 m_statusBar
->setProgress(percent
);
556 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
558 if (m_statusBar
->progressText().isEmpty()) {
559 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
561 m_statusBar
->setProgress(percent
);
564 void DolphinViewContainer::slotDirectoryLoadingStarted()
566 if (isSearchUrl(url())) {
567 // Search KIO-slaves usually don't provide any progress information. Give
568 // a hint to the user that a searching is done:
570 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
571 m_statusBar
->setProgress(-1);
573 // Trigger an undetermined progress indication. The progress
574 // information in percent will be triggered by the percent() signal
575 // of the directory lister later.
576 m_statusBar
->setProgressText(QString());
577 updateDirectoryLoadingProgress(-1);
581 void DolphinViewContainer::slotDirectoryLoadingCompleted()
583 if (!m_statusBar
->progressText().isEmpty()) {
584 m_statusBar
->setProgressText(QString());
585 m_statusBar
->setProgress(100);
588 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
589 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
590 // of showing the default status bar information ("0 items") a more helpful information is given:
591 m_statusBar
->setText(i18nc("@info:status", "No items found."));
597 void DolphinViewContainer::slotDirectoryLoadingCanceled()
599 if (!m_statusBar
->progressText().isEmpty()) {
600 m_statusBar
->setProgressText(QString());
601 m_statusBar
->setProgress(100);
604 m_statusBar
->setText(QString());
607 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
609 const KFileItem
item(url
);
611 // Find out if the file can be opened in the view (for example, this is the
612 // case if the file is an archive). The mime type must be known for that.
613 item
.determineMimeType();
614 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
615 if (!folderUrl
.isEmpty()) {
618 slotItemActivated(item
);
622 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
624 // It is possible to activate items on inactive views by
625 // drag & drop operations. Assure that activating an item always
626 // results in an active view.
627 m_view
->setActive(true);
629 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
630 if (!url
.isEmpty()) {
635 KRun
*run
= new KRun(item
.targetUrl(), this);
636 run
->setShowScriptExecutionPrompt(true);
639 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
641 Q_ASSERT(items
.count() >= 2);
643 KFileItemActions
fileItemActions(this);
644 fileItemActions
.runPreferredApplications(items
, QString());
647 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
650 m_statusBar
->resetToDefaultText();
652 m_statusBar
->setText(item
.getStatusBarInfo());
656 void DolphinViewContainer::closeFilterBar()
658 m_filterBar
->closeFilterBar();
660 emit
showFilterBarChanged(false);
663 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
665 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
666 m_view
->setNameFilter(nameFilter
);
667 delayedStatusBarUpdate();
670 void DolphinViewContainer::activate()
675 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
680 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
684 if (KProtocolManager::supportsListing(url
)) {
685 setSearchModeEnabled(isSearchUrl(url
));
687 tryRestoreViewState();
689 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
690 // When an URL has been entered, the view should get the focus.
691 // The focus must be requested asynchronously, as changing the URL might create
692 // a new view widget.
693 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
695 } else if (KProtocolManager::isSourceProtocol(url
)) {
696 if (url
.scheme().startsWith(QLatin1String("http"))) {
697 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
698 "Dolphin does not support web pages, the web browser has been launched"),
701 showMessage(i18nc("@info:status",
702 "Protocol not supported by Dolphin, default application has been launched"),
706 QDesktopServices::openUrl(url
);
707 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
709 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
713 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
715 m_view
->markUrlsAsSelected({url
});
716 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
719 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
722 const bool block
= m_urlNavigator
->signalsBlocked();
723 m_urlNavigator
->blockSignals(true);
725 // Assure that the location state is reset for redirection URLs. This
726 // allows to skip redirection URLs when going back or forward in the
728 m_urlNavigator
->saveLocationState(QByteArray());
729 m_urlNavigator
->setLocationUrl(newUrl
);
730 setSearchModeEnabled(isSearchUrl(newUrl
));
732 m_urlNavigator
->blockSignals(block
);
735 void DolphinViewContainer::requestFocus()
740 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion
)
742 GeneralSettings::setUrlCompletionMode(completion
);
745 void DolphinViewContainer::slotReturnPressed()
747 if (!GeneralSettings::editableUrl()) {
748 m_urlNavigator
->setUrlEditable(false);
752 void DolphinViewContainer::startSearching()
754 const QUrl url
= m_searchBox
->urlForSearching();
755 if (url
.isValid() && !url
.isEmpty()) {
756 m_view
->setViewPropertiesContext(QStringLiteral("search"));
757 m_urlNavigator
->setLocationUrl(url
);
761 void DolphinViewContainer::closeSearchBox()
763 setSearchModeEnabled(false);
766 void DolphinViewContainer::stopDirectoryLoading()
768 m_view
->stopLoading();
769 m_statusBar
->setProgress(100);
772 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
774 m_view
->setZoomLevel(zoomLevel
);
777 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
779 showMessage(msg
, Error
);
782 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
784 return url
.scheme().contains(QLatin1String("search"));
787 void DolphinViewContainer::saveViewState()
789 QByteArray locationState
;
790 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
791 m_view
->saveState(stream
);
792 m_urlNavigator
->saveLocationState(locationState
);
795 void DolphinViewContainer::tryRestoreViewState()
797 QByteArray locationState
= m_urlNavigator
->locationState();
798 if (!locationState
.isEmpty()) {
799 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
800 m_view
->restoreState(stream
);