2 * SPDX-FileCopyrightText: 2007 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "dolphinviewcontainer.h"
9 #include "dolphin_generalsettings.h"
10 #include "dolphindebug.h"
11 #include "dolphinplacesmodelsingleton.h"
12 #include "filterbar/filterbar.h"
14 #include "search/dolphinsearchbox.h"
15 #include "statusbar/dolphinstatusbar.h"
16 #include "views/viewmodecontroller.h"
17 #include "views/viewproperties.h"
18 #include "dolphin_detailsmodesettings.h"
20 #ifdef HAVE_KACTIVITIES
21 #include <KActivities/ResourceInstance>
23 #include <KFileItemActions>
24 #include <KFilePlacesModel>
25 #include <KIO/PreviewJob>
26 #include <KIO/OpenUrlJob>
27 #include <KIO/JobUiDelegate>
28 #include <KLocalizedString>
29 #include <KMessageWidget>
30 #include <KProtocolManager>
32 #include <KUrlComboBox>
35 #include <QGuiApplication>
36 #include <QLoggingCategory>
40 #include <QVBoxLayout>
41 #include <QDesktopServices>
43 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
46 m_urlNavigator
{new DolphinUrlNavigator(url
)},
47 m_urlNavigatorConnected
{nullptr},
49 m_searchModeEnabled(false),
50 m_messageWidget(nullptr),
54 m_statusBarTimer(nullptr),
55 m_statusBarTimestamp(),
57 #ifdef HAVE_KACTIVITIES
58 , m_activityResourceInstance(nullptr)
63 m_topLayout
= new QVBoxLayout(this);
64 m_topLayout
->setSpacing(0);
65 m_topLayout
->setContentsMargins(0, 0, 0, 0);
67 m_searchBox
= new DolphinSearchBox(this);
69 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
70 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
71 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
72 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
73 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
74 "<para>This helps you find files and folders. Enter a <emphasis>"
75 "search term</emphasis> and specify search settings with the "
76 "buttons at the bottom:<list><item>Filename/Content: "
77 "Does the item you are looking for contain the search terms "
78 "within its filename or its contents?<nl/>The contents of images, "
79 "audio files and videos will not be searched.</item><item>"
80 "From Here/Everywhere: Do you want to search in this "
81 "folder and its sub-folders or everywhere?</item><item>"
82 "More Options: Click this to search by media type, access "
83 "time or rating.</item><item>More Search Tools: Install other "
84 "means to find an item.</item></list></para>"));
86 m_messageWidget
= new KMessageWidget(this);
87 m_messageWidget
->setCloseButtonVisible(true);
88 m_messageWidget
->hide();
93 // We must be logged in as the root user; show a big scary warning
94 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
98 // Initialize filter bar
99 m_filterBar
= new FilterBar(this);
100 m_filterBar
->setVisible(GeneralSettings::filterBar());
102 connect(m_filterBar
, &FilterBar::filterChanged
,
103 this, &DolphinViewContainer::setNameFilter
);
104 connect(m_filterBar
, &FilterBar::closeRequest
,
105 this, &DolphinViewContainer::closeFilterBar
);
106 connect(m_filterBar
, &FilterBar::focusViewRequest
,
107 this, &DolphinViewContainer::requestFocus
);
109 // Initialize the main view
110 m_view
= new DolphinView(url
, this);
111 connect(m_view
, &DolphinView::urlChanged
,
112 m_filterBar
, &FilterBar::slotUrlChanged
);
113 connect(m_view
, &DolphinView::urlChanged
,
114 m_messageWidget
, &KMessageWidget::hide
);
115 // m_urlNavigator stays in sync with m_view's location changes and
116 // keeps track of them so going back and forth in the history works.
117 connect(m_view
, &DolphinView::urlChanged
,
118 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
119 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlChanged
,
120 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
121 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlAboutToBeChanged
,
122 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
123 connect(m_urlNavigator
.get(), &DolphinUrlNavigator::urlSelectionRequested
,
124 this, &DolphinViewContainer::slotUrlSelectionRequested
);
125 connect(m_view
, &DolphinView::writeStateChanged
,
126 this, &DolphinViewContainer::writeStateChanged
);
127 connect(m_view
, &DolphinView::requestItemInfo
,
128 this, &DolphinViewContainer::showItemInfo
);
129 connect(m_view
, &DolphinView::itemActivated
,
130 this, &DolphinViewContainer::slotItemActivated
);
131 connect(m_view
, &DolphinView::itemsActivated
,
132 this, &DolphinViewContainer::slotItemsActivated
);
133 connect(m_view
, &DolphinView::redirection
,
134 this, &DolphinViewContainer::redirect
);
135 connect(m_view
, &DolphinView::directoryLoadingStarted
,
136 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
137 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
138 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
139 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
140 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
141 connect(m_view
, &DolphinView::itemCountChanged
,
142 this, &DolphinViewContainer::delayedStatusBarUpdate
);
143 connect(m_view
, &DolphinView::directoryLoadingProgress
,
144 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
145 connect(m_view
, &DolphinView::directorySortingProgress
,
146 this, &DolphinViewContainer::updateDirectorySortingProgress
);
147 connect(m_view
, &DolphinView::selectionChanged
,
148 this, &DolphinViewContainer::delayedStatusBarUpdate
);
149 connect(m_view
, &DolphinView::errorMessage
,
150 this, &DolphinViewContainer::showErrorMessage
);
151 connect(m_view
, &DolphinView::urlIsFileError
,
152 this, &DolphinViewContainer::slotUrlIsFileError
);
153 connect(m_view
, &DolphinView::activated
,
154 this, &DolphinViewContainer::activate
);
155 connect(m_view
, &DolphinView::hiddenFilesShownChanged
,
156 this, &DolphinViewContainer::slotHiddenFilesShownChanged
);
157 connect(m_view
, &DolphinView::sortHiddenLastChanged
,
158 this, &DolphinViewContainer::slotSortHiddenLastChanged
);
160 // Initialize status bar
161 m_statusBar
= new DolphinStatusBar(this);
162 m_statusBar
->setUrl(m_view
->url());
163 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
164 connect(m_view
, &DolphinView::urlChanged
,
165 m_statusBar
, &DolphinStatusBar::setUrl
);
166 connect(m_view
, &DolphinView::zoomLevelChanged
,
167 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
168 connect(m_view
, &DolphinView::infoMessage
,
169 m_statusBar
, &DolphinStatusBar::setText
);
170 connect(m_view
, &DolphinView::operationCompletedMessage
,
171 m_statusBar
, &DolphinStatusBar::setText
);
172 connect(m_view
, &DolphinView::statusBarTextChanged
,
173 m_statusBar
, &DolphinStatusBar::setDefaultText
);
174 connect(m_view
, &DolphinView::statusBarTextChanged
,
175 m_statusBar
, &DolphinStatusBar::resetToDefaultText
);
176 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
177 this, &DolphinViewContainer::stopDirectoryLoading
);
178 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
179 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
181 m_statusBarTimer
= new QTimer(this);
182 m_statusBarTimer
->setSingleShot(true);
183 m_statusBarTimer
->setInterval(300);
184 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
186 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
187 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
188 this, &DolphinViewContainer::delayedStatusBarUpdate
);
190 m_topLayout
->addWidget(m_searchBox
);
191 m_topLayout
->addWidget(m_messageWidget
);
192 m_topLayout
->addWidget(m_view
);
193 m_topLayout
->addWidget(m_filterBar
);
194 m_topLayout
->addWidget(m_statusBar
);
196 setSearchModeEnabled(isSearchUrl(url
));
198 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
199 if (view()->mode() == DolphinView::Mode::DetailsView
) {
204 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
205 connect(placesModel
, &KFilePlacesModel::dataChanged
,
206 this, &DolphinViewContainer::slotPlacesModelChanged
);
207 connect(placesModel
, &KFilePlacesModel::rowsInserted
,
208 this, &DolphinViewContainer::slotPlacesModelChanged
);
209 connect(placesModel
, &KFilePlacesModel::rowsRemoved
,
210 this, &DolphinViewContainer::slotPlacesModelChanged
);
212 connect(this, &DolphinViewContainer::searchModeEnabledChanged
,
213 this, &DolphinViewContainer::captionChanged
);
215 // Initialize kactivities resource instance
217 #ifdef HAVE_KACTIVITIES
218 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
219 m_activityResourceInstance
->setParent(this);
223 DolphinViewContainer::~DolphinViewContainer()
227 QUrl
DolphinViewContainer::url() const
229 return m_view
->url();
232 void DolphinViewContainer::setActive(bool active
)
234 m_searchBox
->setActive(active
);
235 if (m_urlNavigatorConnected
) {
236 m_urlNavigatorConnected
->setActive(active
);
238 m_view
->setActive(active
);
240 #ifdef HAVE_KACTIVITIES
242 m_activityResourceInstance
->notifyFocusedIn();
244 m_activityResourceInstance
->notifyFocusedOut();
249 bool DolphinViewContainer::isActive() const
251 return m_view
->isActive();
254 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
256 m_autoGrabFocus
= grab
;
259 bool DolphinViewContainer::autoGrabFocus() const
261 return m_autoGrabFocus
;
264 QString
DolphinViewContainer::currentSearchText() const
266 return m_searchBox
->text();
269 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
274 DolphinStatusBar
* DolphinViewContainer::statusBar()
279 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
281 return m_urlNavigatorConnected
;
284 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
286 return m_urlNavigatorConnected
;
289 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
291 return m_urlNavigator
.get();
294 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
296 return m_urlNavigator
.get();
299 const DolphinView
* DolphinViewContainer::view() const
304 DolphinView
* DolphinViewContainer::view()
309 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
311 Q_CHECK_PTR(urlNavigator
);
312 Q_ASSERT(!m_urlNavigatorConnected
);
313 Q_ASSERT(m_urlNavigator
.get() != urlNavigator
);
316 urlNavigator
->setLocationUrl(m_view
->url());
317 urlNavigator
->setShowHiddenFolders(m_view
->hiddenFilesShown());
318 urlNavigator
->setSortHiddenFoldersLast(m_view
->sortHiddenLast());
319 if (m_urlNavigatorVisualState
) {
320 urlNavigator
->setVisualState(*m_urlNavigatorVisualState
.get());
321 m_urlNavigatorVisualState
.reset();
323 urlNavigator
->setActive(isActive());
325 // Url changes are still done via m_urlNavigator.
326 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
327 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
328 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
,
329 this, [=](const QUrl
&destination
, QDropEvent
*event
) {
330 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
332 // Aside from these, only visual things need to be connected.
333 connect(m_view
, &DolphinView::urlChanged
,
334 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
335 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
336 this, &DolphinViewContainer::activate
);
338 m_urlNavigatorConnected
= urlNavigator
;
341 void DolphinViewContainer::disconnectUrlNavigator()
343 if (!m_urlNavigatorConnected
) {
347 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
348 m_urlNavigator
.get(), &DolphinUrlNavigator::setLocationUrl
);
349 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
351 disconnect(m_view
, &DolphinView::urlChanged
,
352 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
353 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
354 this, &DolphinViewContainer::activate
);
356 m_urlNavigatorVisualState
= m_urlNavigatorConnected
->visualState();
357 m_urlNavigatorConnected
= nullptr;
360 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
366 m_messageWidget
->setText(msg
);
368 // TODO: wrap at arbitrary character positions once QLabel can do this
369 // https://bugreports.qt.io/browse/QTBUG-1276
370 m_messageWidget
->setWordWrap(true);
373 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
374 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
375 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
381 m_messageWidget
->setWordWrap(false);
382 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
383 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
385 if (m_messageWidget
->isVisible()) {
386 m_messageWidget
->hide();
388 m_messageWidget
->animatedShow();
391 void DolphinViewContainer::readSettings()
393 // The startup settings should (only) get applied if they have been
394 // modified by the user. Otherwise keep the (possibly) different current
395 // setting of the filterbar.
396 if (GeneralSettings::modifiedStartupSettings()) {
397 setFilterBarVisible(GeneralSettings::filterBar());
400 m_view
->readSettings();
401 m_statusBar
->readSettings();
404 bool DolphinViewContainer::isFilterBarVisible() const
406 return m_filterBar
->isVisible();
409 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
411 m_searchBox
->setVisible(enabled
);
414 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
415 m_searchBox
->fromSearchUrl(locationUrl
);
418 if (enabled
== isSearchModeEnabled()) {
419 if (enabled
&& !m_searchBox
->hasFocus()) {
420 m_searchBox
->setFocus();
421 m_searchBox
->selectAll();
427 m_view
->setViewPropertiesContext(QString());
429 // Restore the URL for the URL navigator. If Dolphin has been
430 // started with a search-URL, the home URL is used as fallback.
431 QUrl url
= m_searchBox
->searchPath();
432 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
433 url
= Dolphin::homeUrl();
435 m_urlNavigatorConnected
->setLocationUrl(url
);
438 m_searchModeEnabled
= enabled
;
440 Q_EMIT
searchModeEnabledChanged(enabled
);
443 bool DolphinViewContainer::isSearchModeEnabled() const
445 return m_searchModeEnabled
;
448 QString
DolphinViewContainer::placesText() const
452 if (isSearchModeEnabled()) {
453 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
455 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
456 if (text
.isEmpty()) {
459 if (text
.isEmpty()) {
460 text
= url().scheme();
467 void DolphinViewContainer::reload()
470 m_messageWidget
->hide();
473 QString
DolphinViewContainer::captionWindowTitle() const
475 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
476 if (!url().isLocalFile()) {
477 return url().adjusted(QUrl::StripTrailingSlash
).toString();
479 return url().adjusted(QUrl::StripTrailingSlash
).path();
481 return DolphinViewContainer::caption();
485 QString
DolphinViewContainer::caption() const
487 if (isSearchModeEnabled()) {
488 if (currentSearchText().isEmpty()){
489 return i18n("Search");
491 return i18n("Search for %1", currentSearchText());
495 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
496 const QString pattern
= url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?");
497 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QRegularExpression::anchoredPattern(pattern
), 1, Qt::MatchRegularExpression
);
499 if (!matchedPlaces
.isEmpty()) {
500 return placesModel
->text(matchedPlaces
.first());
504 if (!url().isLocalFile()) {
505 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
507 if (!adjustedUrl
.fileName().isEmpty()) {
508 caption
= adjustedUrl
.fileName();
509 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
510 caption
= adjustedUrl
.path();
511 } else if (!adjustedUrl
.host().isEmpty()) {
512 caption
= adjustedUrl
.host();
514 caption
= adjustedUrl
.toString();
519 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
520 if (fileName
.isEmpty()) {
527 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
529 if (newUrl
!= m_urlNavigator
->locationUrl()) {
530 m_urlNavigator
->setLocationUrl(newUrl
);
533 #ifdef HAVE_KACTIVITIES
534 m_activityResourceInstance
->setUri(newUrl
);
538 void DolphinViewContainer::setFilterBarVisible(bool visible
)
540 Q_ASSERT(m_filterBar
);
542 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
544 m_filterBar
->setFocus();
545 m_filterBar
->selectAll();
551 void DolphinViewContainer::delayedStatusBarUpdate()
553 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
554 // No update of the statusbar has been done during the last 2 seconds,
555 // although an update has been requested. Trigger an immediate update.
556 m_statusBarTimer
->stop();
559 // Invoke updateStatusBar() with a small delay. This assures that
560 // when a lot of delayedStatusBarUpdates() are done in a short time,
561 // no bottleneck is given.
562 m_statusBarTimer
->start();
566 void DolphinViewContainer::updateStatusBar()
568 m_statusBarTimestamp
.start();
569 m_view
->requestStatusBarText();
572 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
574 if (m_statusBar
->progressText().isEmpty()) {
575 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
577 m_statusBar
->setProgress(percent
);
580 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
582 if (m_statusBar
->progressText().isEmpty()) {
583 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
585 m_statusBar
->setProgress(percent
);
588 void DolphinViewContainer::slotDirectoryLoadingStarted()
590 if (isSearchUrl(url())) {
591 // Search KIO-slaves usually don't provide any progress information. Give
592 // a hint to the user that a searching is done:
594 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
595 m_statusBar
->setProgress(-1);
597 // Trigger an undetermined progress indication. The progress
598 // information in percent will be triggered by the percent() signal
599 // of the directory lister later.
600 m_statusBar
->setProgressText(QString());
601 updateDirectoryLoadingProgress(-1);
605 void DolphinViewContainer::slotDirectoryLoadingCompleted()
607 if (!m_statusBar
->progressText().isEmpty()) {
608 m_statusBar
->setProgressText(QString());
609 m_statusBar
->setProgress(100);
612 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
613 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
614 // of showing the default status bar information ("0 items") a more helpful information is given:
615 m_statusBar
->setText(i18nc("@info:status", "No items found."));
621 void DolphinViewContainer::slotDirectoryLoadingCanceled()
623 if (!m_statusBar
->progressText().isEmpty()) {
624 m_statusBar
->setProgressText(QString());
625 m_statusBar
->setProgress(100);
628 m_statusBar
->setText(QString());
631 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
633 const KFileItem
item(url
);
635 // Find out if the file can be opened in the view (for example, this is the
636 // case if the file is an archive). The mime type must be known for that.
637 item
.determineMimeType();
638 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
639 if (!folderUrl
.isEmpty()) {
642 slotItemActivated(item
);
646 void DolphinViewContainer::slotItemActivated(const KFileItem
&item
)
648 // It is possible to activate items on inactive views by
649 // drag & drop operations. Assure that activating an item always
650 // results in an active view.
651 m_view
->setActive(true);
653 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
654 if (!url
.isEmpty()) {
655 const auto modifiers
= QGuiApplication::keyboardModifiers();
656 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
657 if (modifiers
& Qt::ControlModifier
&& modifiers
& Qt::ShiftModifier
) {
658 Q_EMIT
activeTabRequested(url
);
659 } else if (modifiers
& Qt::ControlModifier
) {
660 Q_EMIT
tabRequested(url
);
661 } else if (modifiers
& Qt::ShiftModifier
) {
662 Dolphin::openNewWindow({KFilePlacesModel::convertedUrl(url
)}, this);
669 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl());
670 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoWarningHandlingEnabled
, this));
671 job
->setShowOpenOrExecuteDialog(true);
672 connect(job
, &KIO::OpenUrlJob::finished
, this, &DolphinViewContainer::slotOpenUrlFinished
);
676 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
678 Q_ASSERT(items
.count() >= 2);
680 KFileItemActions
fileItemActions(this);
681 fileItemActions
.runPreferredApplications(items
);
684 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
687 m_statusBar
->resetToDefaultText();
689 m_statusBar
->setText(item
.getStatusBarInfo());
693 void DolphinViewContainer::closeFilterBar()
695 m_filterBar
->closeFilterBar();
697 Q_EMIT
showFilterBarChanged(false);
700 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
702 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
703 m_view
->setNameFilter(nameFilter
);
704 delayedStatusBarUpdate();
707 void DolphinViewContainer::activate()
712 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
717 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
719 if (m_urlNavigatorConnected
) {
720 m_urlNavigatorConnected
->slotReturnPressed();
723 if (KProtocolManager::supportsListing(url
)) {
724 setSearchModeEnabled(isSearchUrl(url
));
726 tryRestoreViewState();
728 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
729 // When an URL has been entered, the view should get the focus.
730 // The focus must be requested asynchronously, as changing the URL might create
731 // a new view widget.
732 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
734 } else if (KProtocolManager::isSourceProtocol(url
)) {
735 if (url
.scheme().startsWith(QLatin1String("http"))) {
736 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
737 "Dolphin does not support web pages, the web browser has been launched"),
740 showMessage(i18nc("@info:status",
741 "Protocol not supported by Dolphin, default application has been launched"),
745 QDesktopServices::openUrl(url
);
746 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
748 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
749 m_urlNavigator
->goBack();
753 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
755 m_view
->markUrlsAsSelected({url
});
756 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
759 void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
761 disconnect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
762 this, &DolphinViewContainer::slotUrlSelectionRequested
);
765 void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
767 connect(m_urlNavigator
.get(), &KUrlNavigator::urlSelectionRequested
,
768 this, &DolphinViewContainer::slotUrlSelectionRequested
);
771 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
774 const bool block
= m_urlNavigator
->signalsBlocked();
775 m_urlNavigator
->blockSignals(true);
777 // Assure that the location state is reset for redirection URLs. This
778 // allows to skip redirection URLs when going back or forward in the
780 m_urlNavigator
->saveLocationState(QByteArray());
781 m_urlNavigator
->setLocationUrl(newUrl
);
782 setSearchModeEnabled(isSearchUrl(newUrl
));
784 m_urlNavigator
->blockSignals(block
);
787 void DolphinViewContainer::requestFocus()
792 void DolphinViewContainer::startSearching()
794 Q_CHECK_PTR(m_urlNavigatorConnected
);
795 const QUrl url
= m_searchBox
->urlForSearching();
796 if (url
.isValid() && !url
.isEmpty()) {
797 m_view
->setViewPropertiesContext(QStringLiteral("search"));
798 m_urlNavigatorConnected
->setLocationUrl(url
);
802 void DolphinViewContainer::closeSearchBox()
804 setSearchModeEnabled(false);
807 void DolphinViewContainer::stopDirectoryLoading()
809 m_view
->stopLoading();
810 m_statusBar
->setProgress(100);
813 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
815 m_view
->setZoomLevel(zoomLevel
);
818 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
820 showMessage(msg
, Error
);
823 void DolphinViewContainer::slotPlacesModelChanged()
825 if (!GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
826 Q_EMIT
captionChanged();
830 void DolphinViewContainer::slotHiddenFilesShownChanged(bool showHiddenFiles
)
832 if (m_urlNavigatorConnected
) {
833 m_urlNavigatorConnected
->setShowHiddenFolders(showHiddenFiles
);
837 void DolphinViewContainer::slotSortHiddenLastChanged(bool hiddenLast
)
839 if (m_urlNavigatorConnected
) {
840 m_urlNavigatorConnected
->setSortHiddenFoldersLast(hiddenLast
);
844 void DolphinViewContainer::slotOpenUrlFinished(KJob
*job
)
846 if (job
->error() && job
->error() != KIO::ERR_USER_CANCELED
) {
847 showErrorMessage(job
->errorString());
851 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
853 return url
.scheme().contains(QLatin1String("search"));
856 void DolphinViewContainer::saveViewState()
858 QByteArray locationState
;
859 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
860 m_view
->saveState(stream
);
861 m_urlNavigator
->saveLocationState(locationState
);
864 void DolphinViewContainer::tryRestoreViewState()
866 QByteArray locationState
= m_urlNavigator
->locationState();
867 if (!locationState
.isEmpty()) {
868 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
869 m_view
->restoreState(stream
);