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::focusViewRequest
, 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::captionWindowTitle() const
454 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
455 if (!url().isLocalFile()) {
456 return url().adjusted(QUrl::StripTrailingSlash
).toString();
458 return url().adjusted(QUrl::StripTrailingSlash
).path();
460 return DolphinViewContainer::caption();
464 QString
DolphinViewContainer::caption() const
466 if (isSearchModeEnabled()) {
467 if (currentSearchText().isEmpty()){
468 return i18n("Search");
470 return i18n("Search for %1", currentSearchText());
474 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
475 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QUrl(url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?")), 1, Qt::MatchRegExp
);
477 if (!matchedPlaces
.isEmpty()) {
478 return placesModel
->text(matchedPlaces
.first());
482 if (!url().isLocalFile()) {
483 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
485 if (!adjustedUrl
.fileName().isEmpty()) {
486 caption
= adjustedUrl
.fileName();
487 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
488 caption
= adjustedUrl
.path();
489 } else if (!adjustedUrl
.host().isEmpty()) {
490 caption
= adjustedUrl
.host();
492 caption
= adjustedUrl
.toString();
497 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
498 if (fileName
.isEmpty()) {
505 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
507 if (newUrl
!= m_urlNavigator
->locationUrl()) {
508 m_urlNavigator
->setLocationUrl(newUrl
);
511 #ifdef HAVE_KACTIVITIES
512 m_activityResourceInstance
->setUri(newUrl
);
516 void DolphinViewContainer::setFilterBarVisible(bool visible
)
518 Q_ASSERT(m_filterBar
);
520 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
522 m_filterBar
->setFocus();
523 m_filterBar
->selectAll();
529 void DolphinViewContainer::delayedStatusBarUpdate()
531 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
532 // No update of the statusbar has been done during the last 2 seconds,
533 // although an update has been requested. Trigger an immediate update.
534 m_statusBarTimer
->stop();
537 // Invoke updateStatusBar() with a small delay. This assures that
538 // when a lot of delayedStatusBarUpdates() are done in a short time,
539 // no bottleneck is given.
540 m_statusBarTimer
->start();
544 void DolphinViewContainer::updateStatusBar()
546 m_statusBarTimestamp
.start();
548 const QString text
= m_view
->statusBarText();
549 m_statusBar
->setDefaultText(text
);
550 m_statusBar
->resetToDefaultText();
553 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
555 if (m_statusBar
->progressText().isEmpty()) {
556 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
558 m_statusBar
->setProgress(percent
);
561 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
563 if (m_statusBar
->progressText().isEmpty()) {
564 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
566 m_statusBar
->setProgress(percent
);
569 void DolphinViewContainer::slotDirectoryLoadingStarted()
571 if (isSearchUrl(url())) {
572 // Search KIO-slaves usually don't provide any progress information. Give
573 // a hint to the user that a searching is done:
575 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
576 m_statusBar
->setProgress(-1);
578 // Trigger an undetermined progress indication. The progress
579 // information in percent will be triggered by the percent() signal
580 // of the directory lister later.
581 m_statusBar
->setProgressText(QString());
582 updateDirectoryLoadingProgress(-1);
586 void DolphinViewContainer::slotDirectoryLoadingCompleted()
588 if (!m_statusBar
->progressText().isEmpty()) {
589 m_statusBar
->setProgressText(QString());
590 m_statusBar
->setProgress(100);
593 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
594 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
595 // of showing the default status bar information ("0 items") a more helpful information is given:
596 m_statusBar
->setText(i18nc("@info:status", "No items found."));
602 void DolphinViewContainer::slotDirectoryLoadingCanceled()
604 if (!m_statusBar
->progressText().isEmpty()) {
605 m_statusBar
->setProgressText(QString());
606 m_statusBar
->setProgress(100);
609 m_statusBar
->setText(QString());
612 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
614 const KFileItem
item(url
);
616 // Find out if the file can be opened in the view (for example, this is the
617 // case if the file is an archive). The mime type must be known for that.
618 item
.determineMimeType();
619 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
620 if (!folderUrl
.isEmpty()) {
623 slotItemActivated(item
);
627 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
629 // It is possible to activate items on inactive views by
630 // drag & drop operations. Assure that activating an item always
631 // results in an active view.
632 m_view
->setActive(true);
634 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
635 if (!url
.isEmpty()) {
640 KRun
*run
= new KRun(item
.targetUrl(), this);
641 run
->setShowScriptExecutionPrompt(true);
644 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
646 Q_ASSERT(items
.count() >= 2);
648 KFileItemActions
fileItemActions(this);
649 fileItemActions
.runPreferredApplications(items
, QString());
652 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
655 m_statusBar
->resetToDefaultText();
657 m_statusBar
->setText(item
.getStatusBarInfo());
661 void DolphinViewContainer::closeFilterBar()
663 m_filterBar
->closeFilterBar();
665 emit
showFilterBarChanged(false);
668 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
670 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
671 m_view
->setNameFilter(nameFilter
);
672 delayedStatusBarUpdate();
675 void DolphinViewContainer::activate()
680 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
685 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
689 if (KProtocolManager::supportsListing(url
)) {
690 setSearchModeEnabled(isSearchUrl(url
));
692 tryRestoreViewState();
694 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
695 // When an URL has been entered, the view should get the focus.
696 // The focus must be requested asynchronously, as changing the URL might create
697 // a new view widget.
698 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
700 } else if (KProtocolManager::isSourceProtocol(url
)) {
701 if (url
.scheme().startsWith(QLatin1String("http"))) {
702 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
703 "Dolphin does not support web pages, the web browser has been launched"),
706 showMessage(i18nc("@info:status",
707 "Protocol not supported by Dolphin, default application has been launched"),
711 QDesktopServices::openUrl(url
);
712 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
714 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
718 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
720 m_view
->markUrlsAsSelected({url
});
721 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
724 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
727 const bool block
= m_urlNavigator
->signalsBlocked();
728 m_urlNavigator
->blockSignals(true);
730 // Assure that the location state is reset for redirection URLs. This
731 // allows to skip redirection URLs when going back or forward in the
733 m_urlNavigator
->saveLocationState(QByteArray());
734 m_urlNavigator
->setLocationUrl(newUrl
);
735 setSearchModeEnabled(isSearchUrl(newUrl
));
737 m_urlNavigator
->blockSignals(block
);
740 void DolphinViewContainer::requestFocus()
745 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion
)
747 GeneralSettings::setUrlCompletionMode(completion
);
750 void DolphinViewContainer::slotReturnPressed()
752 if (!GeneralSettings::editableUrl()) {
753 m_urlNavigator
->setUrlEditable(false);
757 void DolphinViewContainer::startSearching()
759 const QUrl url
= m_searchBox
->urlForSearching();
760 if (url
.isValid() && !url
.isEmpty()) {
761 m_view
->setViewPropertiesContext(QStringLiteral("search"));
762 m_urlNavigator
->setLocationUrl(url
);
766 void DolphinViewContainer::closeSearchBox()
768 setSearchModeEnabled(false);
771 void DolphinViewContainer::stopDirectoryLoading()
773 m_view
->stopLoading();
774 m_statusBar
->setProgress(100);
777 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
779 m_view
->setZoomLevel(zoomLevel
);
782 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
784 showMessage(msg
, Error
);
787 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
789 return url
.scheme().contains(QLatin1String("search"));
792 void DolphinViewContainer::saveViewState()
794 QByteArray locationState
;
795 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
796 m_view
->saveState(stream
);
797 m_urlNavigator
->saveLocationState(locationState
);
800 void DolphinViewContainer::tryRestoreViewState()
802 QByteArray locationState
= m_urlNavigator
->locationState();
803 if (!locationState
.isEmpty()) {
804 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
805 m_view
->restoreState(stream
);