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 <KIO/OpenUrlJob>
42 #include <KIO/JobUiDelegate>
43 #include <KLocalizedString>
44 #include <KMessageWidget>
45 #include <KProtocolManager>
47 #include <KUrlComboBox>
48 #include <KUrlNavigator>
51 #include <QLoggingCategory>
55 #include <QVBoxLayout>
56 #include <QDesktopServices>
58 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
61 m_navigatorWidget(nullptr),
62 m_urlNavigator(nullptr),
63 m_emptyTrashButton(nullptr),
65 m_searchModeEnabled(false),
66 m_messageWidget(nullptr),
70 m_statusBarTimer(nullptr),
71 m_statusBarTimestamp(),
73 #ifdef HAVE_KACTIVITIES
74 , m_activityResourceInstance(nullptr)
79 m_topLayout
= new QVBoxLayout(this);
80 m_topLayout
->setSpacing(0);
81 m_topLayout
->setContentsMargins(0, 0, 0, 0);
83 m_navigatorWidget
= new QWidget(this);
84 QHBoxLayout
* navigatorLayout
= new QHBoxLayout(m_navigatorWidget
);
85 navigatorLayout
->setSpacing(0);
86 navigatorLayout
->setContentsMargins(0, 0, 0, 0);
87 m_navigatorWidget
->setWhatsThis(xi18nc("@info:whatsthis location bar",
88 "<para>This line describes the location of the files and folders "
89 "displayed below.</para><para>The name of the currently viewed "
90 "folder can be read at the very right. To the left of it is the "
91 "name of the folder that contains it. The whole line is called "
92 "the <emphasis>path</emphasis> to the current location because "
93 "following these folders from left to right leads here.</para>"
94 "<para>The path is displayed on the <emphasis>location bar</emphasis> "
95 "which is more powerful than one would expect. To learn more "
96 "about the basic and advanced features of the location bar "
97 "<link url='help:/dolphin/location-bar.html'>click here</link>. "
98 "This will open the dedicated page in the Handbook.</para>"));
100 m_urlNavigator
= new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url
, this);
101 connect(m_urlNavigator
, &KUrlNavigator::activated
,
102 this, &DolphinViewContainer::activate
);
103 connect(m_urlNavigator
->editor(), &KUrlComboBox::completionModeChanged
,
104 this, &DolphinViewContainer::saveUrlCompletionMode
);
106 const GeneralSettings
* settings
= GeneralSettings::self();
107 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
108 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
109 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
110 KUrlComboBox
* editor
= m_urlNavigator
->editor();
111 editor
->setCompletionMode(KCompletion::CompletionMode(settings
->urlCompletionMode()));
113 m_emptyTrashButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this);
114 m_emptyTrashButton
->setFlat(true);
115 connect(m_emptyTrashButton
, &QPushButton::clicked
, this, [this]() { Trash::empty(this); });
116 connect(&Trash::instance(), &Trash::emptinessChanged
, m_emptyTrashButton
, &QPushButton::setDisabled
);
117 m_emptyTrashButton
->setDisabled(Trash::isEmpty());
118 m_emptyTrashButton
->hide();
120 m_searchBox
= new DolphinSearchBox(this);
122 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
123 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
124 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
125 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
126 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
127 "<para>This helps you find files and folders. Enter a <emphasis>"
128 "search term</emphasis> and specify search settings with the "
129 "buttons at the bottom:<list><item>Filename/Content: "
130 "Does the item you are looking for contain the search terms "
131 "within its filename or its contents?<nl/>The contents of images, "
132 "audio files and videos will not be searched.</item><item>"
133 "From Here/Everywhere: Do you want to search in this "
134 "folder and its sub-folders or everywhere?</item><item>"
135 "More Options: Click this to search by media type, access "
136 "time or rating.</item><item>More Search Tools: Install other "
137 "means to find an item.</item></list></para>"));
139 m_messageWidget
= new KMessageWidget(this);
140 m_messageWidget
->setCloseButtonVisible(true);
141 m_messageWidget
->hide();
146 // We must be logged in as the root user; show a big scary warning
147 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
151 // Initialize filter bar
152 m_filterBar
= new FilterBar(this);
153 m_filterBar
->setVisible(settings
->filterBar());
155 connect(m_filterBar
, &FilterBar::filterChanged
,
156 this, &DolphinViewContainer::setNameFilter
);
157 connect(m_filterBar
, &FilterBar::closeRequest
,
158 this, &DolphinViewContainer::closeFilterBar
);
159 connect(m_filterBar
, &FilterBar::focusViewRequest
,
160 this, &DolphinViewContainer::requestFocus
);
162 // Initialize the main view
163 m_view
= new DolphinView(url
, this);
164 connect(m_view
, &DolphinView::urlChanged
,
165 m_filterBar
, &FilterBar::slotUrlChanged
);
166 connect(m_view
, &DolphinView::urlChanged
,
167 m_urlNavigator
, &KUrlNavigator::setLocationUrl
);
168 connect(m_view
, &DolphinView::urlChanged
,
169 m_messageWidget
, &KMessageWidget::hide
);
170 connect(m_view
, &DolphinView::writeStateChanged
,
171 this, &DolphinViewContainer::writeStateChanged
);
172 connect(m_view
, &DolphinView::requestItemInfo
,
173 this, &DolphinViewContainer::showItemInfo
);
174 connect(m_view
, &DolphinView::itemActivated
,
175 this, &DolphinViewContainer::slotItemActivated
);
176 connect(m_view
, &DolphinView::itemsActivated
,
177 this, &DolphinViewContainer::slotItemsActivated
);
178 connect(m_view
, &DolphinView::redirection
,
179 this, &DolphinViewContainer::redirect
);
180 connect(m_view
, &DolphinView::directoryLoadingStarted
,
181 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
182 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
183 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
184 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
185 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
186 connect(m_view
, &DolphinView::itemCountChanged
,
187 this, &DolphinViewContainer::delayedStatusBarUpdate
);
188 connect(m_view
, &DolphinView::directoryLoadingProgress
,
189 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
190 connect(m_view
, &DolphinView::directorySortingProgress
,
191 this, &DolphinViewContainer::updateDirectorySortingProgress
);
192 connect(m_view
, &DolphinView::selectionChanged
,
193 this, &DolphinViewContainer::delayedStatusBarUpdate
);
194 connect(m_view
, &DolphinView::errorMessage
,
195 this, &DolphinViewContainer::showErrorMessage
);
196 connect(m_view
, &DolphinView::urlIsFileError
,
197 this, &DolphinViewContainer::slotUrlIsFileError
);
198 connect(m_view
, &DolphinView::activated
,
199 this, &DolphinViewContainer::activate
);
201 connect(m_urlNavigator
, &KUrlNavigator::urlAboutToBeChanged
,
202 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
203 connect(m_urlNavigator
, &KUrlNavigator::urlChanged
,
204 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
205 connect(m_urlNavigator
, &KUrlNavigator::urlSelectionRequested
,
206 this, &DolphinViewContainer::slotUrlSelectionRequested
);
207 connect(m_urlNavigator
, &KUrlNavigator::returnPressed
,
208 this, &DolphinViewContainer::slotReturnPressed
);
209 connect(m_urlNavigator
, &KUrlNavigator::urlsDropped
, this, [=](const QUrl
&destination
, QDropEvent
*event
) {
210 m_view
->dropUrls(destination
, event
, m_urlNavigator
->dropWidget());
213 connect(m_view
, &DolphinView::directoryLoadingCompleted
, this, [this]() {
214 m_emptyTrashButton
->setVisible(m_view
->url().scheme() == QLatin1String("trash"));
217 // Initialize status bar
218 m_statusBar
= new DolphinStatusBar(this);
219 m_statusBar
->setUrl(m_view
->url());
220 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
221 connect(m_view
, &DolphinView::urlChanged
,
222 m_statusBar
, &DolphinStatusBar::setUrl
);
223 connect(m_view
, &DolphinView::zoomLevelChanged
,
224 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
225 connect(m_view
, &DolphinView::infoMessage
,
226 m_statusBar
, &DolphinStatusBar::setText
);
227 connect(m_view
, &DolphinView::operationCompletedMessage
,
228 m_statusBar
, &DolphinStatusBar::setText
);
229 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
230 this, &DolphinViewContainer::stopDirectoryLoading
);
231 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
232 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
234 m_statusBarTimer
= new QTimer(this);
235 m_statusBarTimer
->setSingleShot(true);
236 m_statusBarTimer
->setInterval(300);
237 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
239 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
240 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
241 this, &DolphinViewContainer::delayedStatusBarUpdate
);
243 navigatorLayout
->addWidget(m_urlNavigator
);
244 navigatorLayout
->addWidget(m_emptyTrashButton
);
246 m_topLayout
->addWidget(m_navigatorWidget
);
247 m_topLayout
->addWidget(m_searchBox
);
248 m_topLayout
->addWidget(m_messageWidget
);
249 m_topLayout
->addWidget(m_view
);
250 m_topLayout
->addWidget(m_filterBar
);
251 m_topLayout
->addWidget(m_statusBar
);
253 setSearchModeEnabled(isSearchUrl(url
));
255 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
256 if (view()->mode() == DolphinView::Mode::DetailsView
) {
261 // Initialize kactivities resource instance
263 #ifdef HAVE_KACTIVITIES
264 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
265 m_activityResourceInstance
->setParent(this);
269 DolphinViewContainer::~DolphinViewContainer()
273 QUrl
DolphinViewContainer::url() const
275 return m_view
->url();
278 void DolphinViewContainer::setActive(bool active
)
280 m_searchBox
->setActive(active
);
281 m_urlNavigator
->setActive(active
);
282 m_view
->setActive(active
);
284 #ifdef HAVE_KACTIVITIES
286 m_activityResourceInstance
->notifyFocusedIn();
288 m_activityResourceInstance
->notifyFocusedOut();
293 bool DolphinViewContainer::isActive() const
295 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
296 return m_view
->isActive();
299 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
301 m_autoGrabFocus
= grab
;
304 bool DolphinViewContainer::autoGrabFocus() const
306 return m_autoGrabFocus
;
309 QString
DolphinViewContainer::currentSearchText() const
311 return m_searchBox
->text();
314 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
319 DolphinStatusBar
* DolphinViewContainer::statusBar()
324 const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
326 return m_urlNavigator
;
329 KUrlNavigator
* DolphinViewContainer::urlNavigator()
331 return m_urlNavigator
;
334 const DolphinView
* DolphinViewContainer::view() const
339 DolphinView
* DolphinViewContainer::view()
344 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
350 m_messageWidget
->setText(msg
);
352 // TODO: wrap at arbitrary character positions once QLabel can do this
353 // https://bugreports.qt.io/browse/QTBUG-1276
354 m_messageWidget
->setWordWrap(true);
357 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
358 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
359 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
365 m_messageWidget
->setWordWrap(false);
366 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
367 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
369 if (m_messageWidget
->isVisible()) {
370 m_messageWidget
->hide();
372 m_messageWidget
->animatedShow();
375 void DolphinViewContainer::readSettings()
377 if (GeneralSettings::modifiedStartupSettings()) {
378 // The startup settings should only get applied if they have been
379 // modified by the user. Otherwise keep the (possibly) different current
380 // settings of the URL navigator and the filterbar.
381 m_urlNavigator
->setUrlEditable(GeneralSettings::editableUrl());
382 m_urlNavigator
->setShowFullPath(GeneralSettings::showFullPath());
383 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
384 setFilterBarVisible(GeneralSettings::filterBar());
387 m_view
->readSettings();
388 m_statusBar
->readSettings();
391 bool DolphinViewContainer::isFilterBarVisible() const
393 return m_filterBar
->isVisible();
396 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
398 m_searchBox
->setVisible(enabled
);
399 m_navigatorWidget
->setVisible(!enabled
);
402 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
403 m_searchBox
->fromSearchUrl(locationUrl
);
406 if (enabled
== isSearchModeEnabled()) {
407 if (enabled
&& !m_searchBox
->hasFocus()) {
408 m_searchBox
->setFocus();
409 m_searchBox
->selectAll();
415 m_view
->setViewPropertiesContext(QString());
417 // Restore the URL for the URL navigator. If Dolphin has been
418 // started with a search-URL, the home URL is used as fallback.
419 QUrl url
= m_searchBox
->searchPath();
420 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
421 url
= Dolphin::homeUrl();
423 m_urlNavigator
->setLocationUrl(url
);
426 m_searchModeEnabled
= enabled
;
428 emit
searchModeEnabledChanged(enabled
);
431 bool DolphinViewContainer::isSearchModeEnabled() const
433 return m_searchModeEnabled
;
436 QString
DolphinViewContainer::placesText() const
440 if (isSearchModeEnabled()) {
441 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
443 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
444 if (text
.isEmpty()) {
447 if (text
.isEmpty()) {
448 text
= url().scheme();
455 void DolphinViewContainer::reload()
458 m_messageWidget
->hide();
461 QString
DolphinViewContainer::captionWindowTitle() const
463 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
464 if (!url().isLocalFile()) {
465 return url().adjusted(QUrl::StripTrailingSlash
).toString();
467 return url().adjusted(QUrl::StripTrailingSlash
).path();
469 return DolphinViewContainer::caption();
473 QString
DolphinViewContainer::caption() const
475 if (isSearchModeEnabled()) {
476 if (currentSearchText().isEmpty()){
477 return i18n("Search");
479 return i18n("Search for %1", currentSearchText());
483 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
484 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QUrl(url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?")), 1, Qt::MatchRegExp
);
486 if (!matchedPlaces
.isEmpty()) {
487 return placesModel
->text(matchedPlaces
.first());
491 if (!url().isLocalFile()) {
492 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
494 if (!adjustedUrl
.fileName().isEmpty()) {
495 caption
= adjustedUrl
.fileName();
496 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
497 caption
= adjustedUrl
.path();
498 } else if (!adjustedUrl
.host().isEmpty()) {
499 caption
= adjustedUrl
.host();
501 caption
= adjustedUrl
.toString();
506 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
507 if (fileName
.isEmpty()) {
514 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
516 if (newUrl
!= m_urlNavigator
->locationUrl()) {
517 m_urlNavigator
->setLocationUrl(newUrl
);
520 #ifdef HAVE_KACTIVITIES
521 m_activityResourceInstance
->setUri(newUrl
);
525 void DolphinViewContainer::setFilterBarVisible(bool visible
)
527 Q_ASSERT(m_filterBar
);
529 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
531 m_filterBar
->setFocus();
532 m_filterBar
->selectAll();
538 void DolphinViewContainer::delayedStatusBarUpdate()
540 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
541 // No update of the statusbar has been done during the last 2 seconds,
542 // although an update has been requested. Trigger an immediate update.
543 m_statusBarTimer
->stop();
546 // Invoke updateStatusBar() with a small delay. This assures that
547 // when a lot of delayedStatusBarUpdates() are done in a short time,
548 // no bottleneck is given.
549 m_statusBarTimer
->start();
553 void DolphinViewContainer::updateStatusBar()
555 m_statusBarTimestamp
.start();
557 const QString text
= m_view
->statusBarText();
558 m_statusBar
->setDefaultText(text
);
559 m_statusBar
->resetToDefaultText();
562 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
564 if (m_statusBar
->progressText().isEmpty()) {
565 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
567 m_statusBar
->setProgress(percent
);
570 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
572 if (m_statusBar
->progressText().isEmpty()) {
573 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
575 m_statusBar
->setProgress(percent
);
578 void DolphinViewContainer::slotDirectoryLoadingStarted()
580 if (isSearchUrl(url())) {
581 // Search KIO-slaves usually don't provide any progress information. Give
582 // a hint to the user that a searching is done:
584 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
585 m_statusBar
->setProgress(-1);
587 // Trigger an undetermined progress indication. The progress
588 // information in percent will be triggered by the percent() signal
589 // of the directory lister later.
590 m_statusBar
->setProgressText(QString());
591 updateDirectoryLoadingProgress(-1);
595 void DolphinViewContainer::slotDirectoryLoadingCompleted()
597 if (!m_statusBar
->progressText().isEmpty()) {
598 m_statusBar
->setProgressText(QString());
599 m_statusBar
->setProgress(100);
602 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
603 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
604 // of showing the default status bar information ("0 items") a more helpful information is given:
605 m_statusBar
->setText(i18nc("@info:status", "No items found."));
611 void DolphinViewContainer::slotDirectoryLoadingCanceled()
613 if (!m_statusBar
->progressText().isEmpty()) {
614 m_statusBar
->setProgressText(QString());
615 m_statusBar
->setProgress(100);
618 m_statusBar
->setText(QString());
621 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
623 const KFileItem
item(url
);
625 // Find out if the file can be opened in the view (for example, this is the
626 // case if the file is an archive). The mime type must be known for that.
627 item
.determineMimeType();
628 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
629 if (!folderUrl
.isEmpty()) {
632 slotItemActivated(item
);
636 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
638 // It is possible to activate items on inactive views by
639 // drag & drop operations. Assure that activating an item always
640 // results in an active view.
641 m_view
->setActive(true);
643 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
644 if (!url
.isEmpty()) {
649 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl());
650 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
651 job
->setShowOpenOrExecuteDialog(true);
655 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
657 Q_ASSERT(items
.count() >= 2);
659 KFileItemActions
fileItemActions(this);
660 fileItemActions
.runPreferredApplications(items
, QString());
663 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
666 m_statusBar
->resetToDefaultText();
668 m_statusBar
->setText(item
.getStatusBarInfo());
672 void DolphinViewContainer::closeFilterBar()
674 m_filterBar
->closeFilterBar();
676 emit
showFilterBarChanged(false);
679 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
681 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
682 m_view
->setNameFilter(nameFilter
);
683 delayedStatusBarUpdate();
686 void DolphinViewContainer::activate()
691 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
696 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
700 if (KProtocolManager::supportsListing(url
)) {
701 setSearchModeEnabled(isSearchUrl(url
));
703 tryRestoreViewState();
705 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
706 // When an URL has been entered, the view should get the focus.
707 // The focus must be requested asynchronously, as changing the URL might create
708 // a new view widget.
709 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
711 } else if (KProtocolManager::isSourceProtocol(url
)) {
712 if (url
.scheme().startsWith(QLatin1String("http"))) {
713 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
714 "Dolphin does not support web pages, the web browser has been launched"),
717 showMessage(i18nc("@info:status",
718 "Protocol not supported by Dolphin, default application has been launched"),
722 QDesktopServices::openUrl(url
);
723 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
725 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
729 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
731 m_view
->markUrlsAsSelected({url
});
732 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
735 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
738 const bool block
= m_urlNavigator
->signalsBlocked();
739 m_urlNavigator
->blockSignals(true);
741 // Assure that the location state is reset for redirection URLs. This
742 // allows to skip redirection URLs when going back or forward in the
744 m_urlNavigator
->saveLocationState(QByteArray());
745 m_urlNavigator
->setLocationUrl(newUrl
);
746 setSearchModeEnabled(isSearchUrl(newUrl
));
748 m_urlNavigator
->blockSignals(block
);
751 void DolphinViewContainer::requestFocus()
756 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion
)
758 GeneralSettings::setUrlCompletionMode(completion
);
761 void DolphinViewContainer::slotReturnPressed()
763 if (!GeneralSettings::editableUrl()) {
764 m_urlNavigator
->setUrlEditable(false);
768 void DolphinViewContainer::startSearching()
770 const QUrl url
= m_searchBox
->urlForSearching();
771 if (url
.isValid() && !url
.isEmpty()) {
772 m_view
->setViewPropertiesContext(QStringLiteral("search"));
773 m_urlNavigator
->setLocationUrl(url
);
777 void DolphinViewContainer::closeSearchBox()
779 setSearchModeEnabled(false);
782 void DolphinViewContainer::stopDirectoryLoading()
784 m_view
->stopLoading();
785 m_statusBar
->setProgress(100);
788 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
790 m_view
->setZoomLevel(zoomLevel
);
793 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
795 showMessage(msg
, Error
);
798 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
800 return url
.scheme().contains(QLatin1String("search"));
803 void DolphinViewContainer::saveViewState()
805 QByteArray locationState
;
806 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
807 m_view
->saveState(stream
);
808 m_urlNavigator
->saveLocationState(locationState
);
811 void DolphinViewContainer::tryRestoreViewState()
813 QByteArray locationState
= m_urlNavigator
->locationState();
814 if (!locationState
.isEmpty()) {
815 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
816 m_view
->restoreState(stream
);