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"
32 #include "dolphin_detailsmodesettings.h"
33 #include "views/dolphinview.h"
35 #ifdef HAVE_KACTIVITIES
36 #include <KActivities/ResourceInstance>
38 #include <KFileItemActions>
39 #include <KFilePlacesModel>
40 #include <KIO/PreviewJob>
41 #include <KLocalizedString>
42 #include <KMessageWidget>
43 #include <KProtocolManager>
46 #include <KUrlComboBox>
47 #include <KUrlNavigator>
50 #include <QLoggingCategory>
54 #include <QVBoxLayout>
55 #include <QDesktopServices>
57 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
60 m_navigatorWidget(nullptr),
61 m_urlNavigator(nullptr),
62 m_emptyTrashButton(nullptr),
64 m_searchModeEnabled(false),
65 m_messageWidget(nullptr),
69 m_statusBarTimer(nullptr),
70 m_statusBarTimestamp(),
72 #ifdef HAVE_KACTIVITIES
73 , m_activityResourceInstance(nullptr)
78 m_topLayout
= new QVBoxLayout(this);
79 m_topLayout
->setSpacing(0);
80 m_topLayout
->setContentsMargins(0, 0, 0, 0);
82 m_navigatorWidget
= new QWidget(this);
83 QHBoxLayout
* navigatorLayout
= new QHBoxLayout(m_navigatorWidget
);
84 navigatorLayout
->setSpacing(0);
85 navigatorLayout
->setContentsMargins(0, 0, 0, 0);
86 m_navigatorWidget
->setWhatsThis(xi18nc("@info:whatsthis location bar",
87 "<para>This line describes the location of the files and folders "
88 "displayed below.</para><para>The name of the currently viewed "
89 "folder can be read at the very right. To the left of it is the "
90 "name of the folder that contains it. The whole line is called "
91 "the <emphasis>path</emphasis> to the current location because "
92 "following these folders from left to right leads here.</para>"
93 "<para>The path is displayed on the <emphasis>location bar</emphasis> "
94 "which is more powerful than one would expect. To learn more "
95 "about the basic and advanced features of the location bar "
96 "<link url='help:/dolphin/location-bar.html'>click here</link>. "
97 "This will open the dedicated page in the Handbook.</para>"));
99 m_urlNavigator
= new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url
, this);
100 connect(m_urlNavigator
, &KUrlNavigator::activated
,
101 this, &DolphinViewContainer::activate
);
102 connect(m_urlNavigator
->editor(), &KUrlComboBox::completionModeChanged
,
103 this, &DolphinViewContainer::saveUrlCompletionMode
);
105 const GeneralSettings
* settings
= GeneralSettings::self();
106 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
107 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
108 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
109 KUrlComboBox
* editor
= m_urlNavigator
->editor();
110 editor
->setCompletionMode(KCompletion::CompletionMode(settings
->urlCompletionMode()));
112 m_emptyTrashButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this);
113 m_emptyTrashButton
->setFlat(true);
114 connect(m_emptyTrashButton
, &QPushButton::clicked
, this, [this]() { Trash::empty(this); });
115 connect(&Trash::instance(), &Trash::emptinessChanged
, m_emptyTrashButton
, &QPushButton::setDisabled
);
116 m_emptyTrashButton
->setDisabled(Trash::isEmpty());
117 m_emptyTrashButton
->hide();
119 m_searchBox
= new DolphinSearchBox(this);
121 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
122 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
123 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
124 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
125 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
126 "<para>This helps you find files and folders. Enter a <emphasis>"
127 "search term</emphasis> and specify search settings with the "
128 "buttons at the bottom:<list><item>Filename/Content: "
129 "Does the item you are looking for contain the search terms "
130 "within its filename or its contents?<nl/>The contents of images, "
131 "audio files and videos will not be searched.</item><item>"
132 "From Here/Everywhere: Do you want to search in this "
133 "folder and its sub-folders or everywhere?</item><item>"
134 "More Options: Click this to search by media type, access "
135 "time or rating.</item><item>More Search Tools: Install other "
136 "means to find an item.</item></list></para>"));
138 m_messageWidget
= new KMessageWidget(this);
139 m_messageWidget
->setCloseButtonVisible(true);
140 m_messageWidget
->hide();
145 // We must be logged in as the root user; show a big scary warning
146 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
150 // Initialize filter bar
151 m_filterBar
= new FilterBar(this);
152 m_filterBar
->setVisible(settings
->filterBar());
154 connect(m_filterBar
, &FilterBar::filterChanged
,
155 this, &DolphinViewContainer::setNameFilter
);
156 connect(m_filterBar
, &FilterBar::closeRequest
,
157 this, &DolphinViewContainer::closeFilterBar
);
158 connect(m_filterBar
, &FilterBar::focusViewRequest
,
159 this, &DolphinViewContainer::requestFocus
);
161 // Initialize the main view
162 m_view
= new DolphinView(url
, this);
163 connect(m_view
, &DolphinView::urlChanged
,
164 m_filterBar
, &FilterBar::slotUrlChanged
);
165 connect(m_view
, &DolphinView::urlChanged
,
166 m_urlNavigator
, &KUrlNavigator::setLocationUrl
);
167 connect(m_view
, &DolphinView::urlChanged
,
168 m_messageWidget
, &KMessageWidget::hide
);
169 connect(m_view
, &DolphinView::writeStateChanged
,
170 this, &DolphinViewContainer::writeStateChanged
);
171 connect(m_view
, &DolphinView::requestItemInfo
,
172 this, &DolphinViewContainer::showItemInfo
);
173 connect(m_view
, &DolphinView::itemActivated
,
174 this, &DolphinViewContainer::slotItemActivated
);
175 connect(m_view
, &DolphinView::itemsActivated
,
176 this, &DolphinViewContainer::slotItemsActivated
);
177 connect(m_view
, &DolphinView::redirection
,
178 this, &DolphinViewContainer::redirect
);
179 connect(m_view
, &DolphinView::directoryLoadingStarted
,
180 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
181 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
182 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
183 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
184 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
185 connect(m_view
, &DolphinView::itemCountChanged
,
186 this, &DolphinViewContainer::delayedStatusBarUpdate
);
187 connect(m_view
, &DolphinView::directoryLoadingProgress
,
188 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
189 connect(m_view
, &DolphinView::directorySortingProgress
,
190 this, &DolphinViewContainer::updateDirectorySortingProgress
);
191 connect(m_view
, &DolphinView::selectionChanged
,
192 this, &DolphinViewContainer::delayedStatusBarUpdate
);
193 connect(m_view
, &DolphinView::errorMessage
,
194 this, &DolphinViewContainer::showErrorMessage
);
195 connect(m_view
, &DolphinView::urlIsFileError
,
196 this, &DolphinViewContainer::slotUrlIsFileError
);
197 connect(m_view
, &DolphinView::activated
,
198 this, &DolphinViewContainer::activate
);
200 connect(m_urlNavigator
, &KUrlNavigator::urlAboutToBeChanged
,
201 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
202 connect(m_urlNavigator
, &KUrlNavigator::urlChanged
,
203 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
204 connect(m_urlNavigator
, &KUrlNavigator::urlSelectionRequested
,
205 this, &DolphinViewContainer::slotUrlSelectionRequested
);
206 connect(m_urlNavigator
, &KUrlNavigator::returnPressed
,
207 this, &DolphinViewContainer::slotReturnPressed
);
208 connect(m_urlNavigator
, &KUrlNavigator::urlsDropped
, this, [=](const QUrl
&destination
, QDropEvent
*event
) {
209 m_view
->dropUrls(destination
, event
, m_urlNavigator
->dropWidget());
212 connect(m_view
, &DolphinView::directoryLoadingCompleted
, this, [this]() {
213 m_emptyTrashButton
->setVisible(m_view
->url().scheme() == QLatin1String("trash"));
216 // Initialize status bar
217 m_statusBar
= new DolphinStatusBar(this);
218 m_statusBar
->setUrl(m_view
->url());
219 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
220 connect(m_view
, &DolphinView::urlChanged
,
221 m_statusBar
, &DolphinStatusBar::setUrl
);
222 connect(m_view
, &DolphinView::zoomLevelChanged
,
223 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
224 connect(m_view
, &DolphinView::infoMessage
,
225 m_statusBar
, &DolphinStatusBar::setText
);
226 connect(m_view
, &DolphinView::operationCompletedMessage
,
227 m_statusBar
, &DolphinStatusBar::setText
);
228 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
229 this, &DolphinViewContainer::stopDirectoryLoading
);
230 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
231 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
233 m_statusBarTimer
= new QTimer(this);
234 m_statusBarTimer
->setSingleShot(true);
235 m_statusBarTimer
->setInterval(300);
236 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
238 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
239 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
240 this, &DolphinViewContainer::delayedStatusBarUpdate
);
242 navigatorLayout
->addWidget(m_urlNavigator
);
243 navigatorLayout
->addWidget(m_emptyTrashButton
);
245 m_topLayout
->addWidget(m_navigatorWidget
);
246 m_topLayout
->addWidget(m_searchBox
);
247 m_topLayout
->addWidget(m_messageWidget
);
248 m_topLayout
->addWidget(m_view
);
249 m_topLayout
->addWidget(m_filterBar
);
250 m_topLayout
->addWidget(m_statusBar
);
252 setSearchModeEnabled(isSearchUrl(url
));
254 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
255 if (view()->mode() == DolphinView::Mode::DetailsView
) {
260 // Initialize kactivities resource instance
262 #ifdef HAVE_KACTIVITIES
263 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
264 m_activityResourceInstance
->setParent(this);
268 DolphinViewContainer::~DolphinViewContainer()
272 QUrl
DolphinViewContainer::url() const
274 return m_view
->url();
277 void DolphinViewContainer::setActive(bool active
)
279 m_searchBox
->setActive(active
);
280 m_urlNavigator
->setActive(active
);
281 m_view
->setActive(active
);
283 #ifdef HAVE_KACTIVITIES
285 m_activityResourceInstance
->notifyFocusedIn();
287 m_activityResourceInstance
->notifyFocusedOut();
292 bool DolphinViewContainer::isActive() const
294 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
295 return m_view
->isActive();
298 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
300 m_autoGrabFocus
= grab
;
303 bool DolphinViewContainer::autoGrabFocus() const
305 return m_autoGrabFocus
;
308 QString
DolphinViewContainer::currentSearchText() const
310 return m_searchBox
->text();
313 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
318 DolphinStatusBar
* DolphinViewContainer::statusBar()
323 const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
325 return m_urlNavigator
;
328 KUrlNavigator
* DolphinViewContainer::urlNavigator()
330 return m_urlNavigator
;
333 const DolphinView
* DolphinViewContainer::view() const
338 DolphinView
* DolphinViewContainer::view()
343 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
349 m_messageWidget
->setText(msg
);
351 // TODO: wrap at arbitrary character positions once QLabel can do this
352 // https://bugreports.qt.io/browse/QTBUG-1276
353 m_messageWidget
->setWordWrap(true);
356 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
357 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
358 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
364 m_messageWidget
->setWordWrap(false);
365 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
366 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
368 if (m_messageWidget
->isVisible()) {
369 m_messageWidget
->hide();
371 m_messageWidget
->animatedShow();
374 void DolphinViewContainer::readSettings()
376 if (GeneralSettings::modifiedStartupSettings()) {
377 // The startup settings should only get applied if they have been
378 // modified by the user. Otherwise keep the (possibly) different current
379 // settings of the URL navigator and the filterbar.
380 m_urlNavigator
->setUrlEditable(GeneralSettings::editableUrl());
381 m_urlNavigator
->setShowFullPath(GeneralSettings::showFullPath());
382 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
383 setFilterBarVisible(GeneralSettings::filterBar());
386 m_view
->readSettings();
387 m_statusBar
->readSettings();
390 bool DolphinViewContainer::isFilterBarVisible() const
392 return m_filterBar
->isVisible();
395 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
397 m_searchBox
->setVisible(enabled
);
398 m_navigatorWidget
->setVisible(!enabled
);
401 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
402 m_searchBox
->fromSearchUrl(locationUrl
);
405 if (enabled
== isSearchModeEnabled()) {
406 if (enabled
&& !m_searchBox
->hasFocus()) {
407 m_searchBox
->setFocus();
408 m_searchBox
->selectAll();
414 m_view
->setViewPropertiesContext(QString());
416 // Restore the URL for the URL navigator. If Dolphin has been
417 // started with a search-URL, the home URL is used as fallback.
418 QUrl url
= m_searchBox
->searchPath();
419 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
420 url
= Dolphin::homeUrl();
422 m_urlNavigator
->setLocationUrl(url
);
425 m_searchModeEnabled
= enabled
;
427 emit
searchModeEnabledChanged(enabled
);
430 bool DolphinViewContainer::isSearchModeEnabled() const
432 return m_searchModeEnabled
;
435 QString
DolphinViewContainer::placesText() const
439 if (isSearchModeEnabled()) {
440 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
442 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
443 if (text
.isEmpty()) {
446 if (text
.isEmpty()) {
447 text
= url().scheme();
454 void DolphinViewContainer::reload()
457 m_messageWidget
->hide();
460 QString
DolphinViewContainer::captionWindowTitle() const
462 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
463 if (!url().isLocalFile()) {
464 return url().adjusted(QUrl::StripTrailingSlash
).toString();
466 return url().adjusted(QUrl::StripTrailingSlash
).path();
468 return DolphinViewContainer::caption();
472 QString
DolphinViewContainer::caption() const
474 if (isSearchModeEnabled()) {
475 if (currentSearchText().isEmpty()){
476 return i18n("Search");
478 return i18n("Search for %1", currentSearchText());
482 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
483 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QUrl(url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?")), 1, Qt::MatchRegExp
);
485 if (!matchedPlaces
.isEmpty()) {
486 return placesModel
->text(matchedPlaces
.first());
490 if (!url().isLocalFile()) {
491 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
493 if (!adjustedUrl
.fileName().isEmpty()) {
494 caption
= adjustedUrl
.fileName();
495 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
496 caption
= adjustedUrl
.path();
497 } else if (!adjustedUrl
.host().isEmpty()) {
498 caption
= adjustedUrl
.host();
500 caption
= adjustedUrl
.toString();
505 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
506 if (fileName
.isEmpty()) {
513 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
515 if (newUrl
!= m_urlNavigator
->locationUrl()) {
516 m_urlNavigator
->setLocationUrl(newUrl
);
519 #ifdef HAVE_KACTIVITIES
520 m_activityResourceInstance
->setUri(newUrl
);
524 void DolphinViewContainer::setFilterBarVisible(bool visible
)
526 Q_ASSERT(m_filterBar
);
528 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
530 m_filterBar
->setFocus();
531 m_filterBar
->selectAll();
537 void DolphinViewContainer::delayedStatusBarUpdate()
539 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
540 // No update of the statusbar has been done during the last 2 seconds,
541 // although an update has been requested. Trigger an immediate update.
542 m_statusBarTimer
->stop();
545 // Invoke updateStatusBar() with a small delay. This assures that
546 // when a lot of delayedStatusBarUpdates() are done in a short time,
547 // no bottleneck is given.
548 m_statusBarTimer
->start();
552 void DolphinViewContainer::updateStatusBar()
554 m_statusBarTimestamp
.start();
556 const QString text
= m_view
->statusBarText();
557 m_statusBar
->setDefaultText(text
);
558 m_statusBar
->resetToDefaultText();
561 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
563 if (m_statusBar
->progressText().isEmpty()) {
564 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
566 m_statusBar
->setProgress(percent
);
569 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
571 if (m_statusBar
->progressText().isEmpty()) {
572 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
574 m_statusBar
->setProgress(percent
);
577 void DolphinViewContainer::slotDirectoryLoadingStarted()
579 if (isSearchUrl(url())) {
580 // Search KIO-slaves usually don't provide any progress information. Give
581 // a hint to the user that a searching is done:
583 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
584 m_statusBar
->setProgress(-1);
586 // Trigger an undetermined progress indication. The progress
587 // information in percent will be triggered by the percent() signal
588 // of the directory lister later.
589 m_statusBar
->setProgressText(QString());
590 updateDirectoryLoadingProgress(-1);
594 void DolphinViewContainer::slotDirectoryLoadingCompleted()
596 if (!m_statusBar
->progressText().isEmpty()) {
597 m_statusBar
->setProgressText(QString());
598 m_statusBar
->setProgress(100);
601 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
602 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
603 // of showing the default status bar information ("0 items") a more helpful information is given:
604 m_statusBar
->setText(i18nc("@info:status", "No items found."));
610 void DolphinViewContainer::slotDirectoryLoadingCanceled()
612 if (!m_statusBar
->progressText().isEmpty()) {
613 m_statusBar
->setProgressText(QString());
614 m_statusBar
->setProgress(100);
617 m_statusBar
->setText(QString());
620 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
622 const KFileItem
item(url
);
624 // Find out if the file can be opened in the view (for example, this is the
625 // case if the file is an archive). The mime type must be known for that.
626 item
.determineMimeType();
627 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
628 if (!folderUrl
.isEmpty()) {
631 slotItemActivated(item
);
635 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
637 // It is possible to activate items on inactive views by
638 // drag & drop operations. Assure that activating an item always
639 // results in an active view.
640 m_view
->setActive(true);
642 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
643 if (!url
.isEmpty()) {
648 KRun
*run
= new KRun(item
.targetUrl(), this);
649 run
->setShowScriptExecutionPrompt(true);
652 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
654 Q_ASSERT(items
.count() >= 2);
656 KFileItemActions
fileItemActions(this);
657 fileItemActions
.runPreferredApplications(items
, QString());
660 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
663 m_statusBar
->resetToDefaultText();
665 m_statusBar
->setText(item
.getStatusBarInfo());
669 void DolphinViewContainer::closeFilterBar()
671 m_filterBar
->closeFilterBar();
673 emit
showFilterBarChanged(false);
676 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
678 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
679 m_view
->setNameFilter(nameFilter
);
680 delayedStatusBarUpdate();
683 void DolphinViewContainer::activate()
688 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
693 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
697 if (KProtocolManager::supportsListing(url
)) {
698 setSearchModeEnabled(isSearchUrl(url
));
700 tryRestoreViewState();
702 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
703 // When an URL has been entered, the view should get the focus.
704 // The focus must be requested asynchronously, as changing the URL might create
705 // a new view widget.
706 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
708 } else if (KProtocolManager::isSourceProtocol(url
)) {
709 if (url
.scheme().startsWith(QLatin1String("http"))) {
710 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
711 "Dolphin does not support web pages, the web browser has been launched"),
714 showMessage(i18nc("@info:status",
715 "Protocol not supported by Dolphin, default application has been launched"),
719 QDesktopServices::openUrl(url
);
720 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
722 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
726 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
728 m_view
->markUrlsAsSelected({url
});
729 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
732 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
735 const bool block
= m_urlNavigator
->signalsBlocked();
736 m_urlNavigator
->blockSignals(true);
738 // Assure that the location state is reset for redirection URLs. This
739 // allows to skip redirection URLs when going back or forward in the
741 m_urlNavigator
->saveLocationState(QByteArray());
742 m_urlNavigator
->setLocationUrl(newUrl
);
743 setSearchModeEnabled(isSearchUrl(newUrl
));
745 m_urlNavigator
->blockSignals(block
);
748 void DolphinViewContainer::requestFocus()
753 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion
)
755 GeneralSettings::setUrlCompletionMode(completion
);
758 void DolphinViewContainer::slotReturnPressed()
760 if (!GeneralSettings::editableUrl()) {
761 m_urlNavigator
->setUrlEditable(false);
765 void DolphinViewContainer::startSearching()
767 const QUrl url
= m_searchBox
->urlForSearching();
768 if (url
.isValid() && !url
.isEmpty()) {
769 m_view
->setViewPropertiesContext(QStringLiteral("search"));
770 m_urlNavigator
->setLocationUrl(url
);
774 void DolphinViewContainer::closeSearchBox()
776 setSearchModeEnabled(false);
779 void DolphinViewContainer::stopDirectoryLoading()
781 m_view
->stopLoading();
782 m_statusBar
->setProgress(100);
785 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
787 m_view
->setZoomLevel(zoomLevel
);
790 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
792 showMessage(msg
, Error
);
795 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
797 return url
.scheme().contains(QLatin1String("search"));
800 void DolphinViewContainer::saveViewState()
802 QByteArray locationState
;
803 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
804 m_view
->saveState(stream
);
805 m_urlNavigator
->saveLocationState(locationState
);
808 void DolphinViewContainer::tryRestoreViewState()
810 QByteArray locationState
= m_urlNavigator
->locationState();
811 if (!locationState
.isEmpty()) {
812 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
813 m_view
->restoreState(stream
);