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 "trash/dolphintrash.h"
17 #include "views/viewmodecontroller.h"
18 #include "views/viewproperties.h"
19 #include "dolphin_detailsmodesettings.h"
21 #ifdef HAVE_KACTIVITIES
22 #include <KActivities/ResourceInstance>
24 #include <KFileItemActions>
25 #include <KFilePlacesModel>
26 #include <KIO/PreviewJob>
27 #include <KIO/OpenUrlJob>
28 #include <KIO/JobUiDelegate>
29 #include <KLocalizedString>
30 #include <KMessageWidget>
31 #include <KProtocolManager>
33 #include <KUrlComboBox>
34 #include <KUrlNavigator>
37 #include <QLoggingCategory>
41 #include <QVBoxLayout>
42 #include <QDesktopServices>
44 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
47 m_navigatorWidget(nullptr),
48 m_urlNavigator(nullptr),
49 m_urlNavigatorConnected(nullptr),
50 m_emptyTrashButton(nullptr),
52 m_searchModeEnabled(false),
53 m_messageWidget(nullptr),
57 m_statusBarTimer(nullptr),
58 m_statusBarTimestamp(),
60 #ifdef HAVE_KACTIVITIES
61 , m_activityResourceInstance(nullptr)
66 m_topLayout
= new QVBoxLayout(this);
67 m_topLayout
->setSpacing(0);
68 m_topLayout
->setContentsMargins(0, 0, 0, 0);
70 m_navigatorWidget
= new QWidget(this);
71 m_navigatorWidget
->setVisible(false);
72 QHBoxLayout
* navigatorLayout
= new QHBoxLayout(m_navigatorWidget
);
73 navigatorLayout
->setSpacing(0);
74 navigatorLayout
->setContentsMargins(0, 0, 0, 0);
75 m_urlNavigator
= new DolphinUrlNavigator(url
, m_navigatorWidget
);
77 m_emptyTrashButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this);
78 m_emptyTrashButton
->setFlat(true);
79 connect(m_emptyTrashButton
, &QPushButton::clicked
, this, [this]() { Trash::empty(this); });
80 connect(&Trash::instance(), &Trash::emptinessChanged
, m_emptyTrashButton
, &QPushButton::setDisabled
);
81 m_emptyTrashButton
->setDisabled(Trash::isEmpty());
82 m_emptyTrashButton
->hide();
84 m_searchBox
= new DolphinSearchBox(this);
86 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
87 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
88 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
89 connect(m_searchBox
, &DolphinSearchBox::focusViewRequest
, this, &DolphinViewContainer::requestFocus
);
90 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
91 "<para>This helps you find files and folders. Enter a <emphasis>"
92 "search term</emphasis> and specify search settings with the "
93 "buttons at the bottom:<list><item>Filename/Content: "
94 "Does the item you are looking for contain the search terms "
95 "within its filename or its contents?<nl/>The contents of images, "
96 "audio files and videos will not be searched.</item><item>"
97 "From Here/Everywhere: Do you want to search in this "
98 "folder and its sub-folders or everywhere?</item><item>"
99 "More Options: Click this to search by media type, access "
100 "time or rating.</item><item>More Search Tools: Install other "
101 "means to find an item.</item></list></para>"));
103 m_messageWidget
= new KMessageWidget(this);
104 m_messageWidget
->setCloseButtonVisible(true);
105 m_messageWidget
->hide();
110 // We must be logged in as the root user; show a big scary warning
111 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
115 // Initialize filter bar
116 m_filterBar
= new FilterBar(this);
117 m_filterBar
->setVisible(GeneralSettings::filterBar());
119 connect(m_filterBar
, &FilterBar::filterChanged
,
120 this, &DolphinViewContainer::setNameFilter
);
121 connect(m_filterBar
, &FilterBar::closeRequest
,
122 this, &DolphinViewContainer::closeFilterBar
);
123 connect(m_filterBar
, &FilterBar::focusViewRequest
,
124 this, &DolphinViewContainer::requestFocus
);
126 // Initialize the main view
127 m_view
= new DolphinView(url
, this);
128 connect(m_view
, &DolphinView::urlChanged
,
129 m_filterBar
, &FilterBar::slotUrlChanged
);
130 connect(m_view
, &DolphinView::urlChanged
,
131 m_messageWidget
, &KMessageWidget::hide
);
132 // m_urlNavigator stays in sync with m_view's location changes and
133 // keeps track of them so going back and forth in the history works.
134 connect(m_view
, &DolphinView::urlChanged
,
135 m_urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
136 connect(m_urlNavigator
, &DolphinUrlNavigator::urlChanged
,
137 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
138 connect(m_view
, &DolphinView::writeStateChanged
,
139 this, &DolphinViewContainer::writeStateChanged
);
140 connect(m_view
, &DolphinView::requestItemInfo
,
141 this, &DolphinViewContainer::showItemInfo
);
142 connect(m_view
, &DolphinView::itemActivated
,
143 this, &DolphinViewContainer::slotItemActivated
);
144 connect(m_view
, &DolphinView::itemsActivated
,
145 this, &DolphinViewContainer::slotItemsActivated
);
146 connect(m_view
, &DolphinView::redirection
,
147 this, &DolphinViewContainer::redirect
);
148 connect(m_view
, &DolphinView::directoryLoadingStarted
,
149 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
150 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
151 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
152 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
153 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
154 connect(m_view
, &DolphinView::itemCountChanged
,
155 this, &DolphinViewContainer::delayedStatusBarUpdate
);
156 connect(m_view
, &DolphinView::directoryLoadingProgress
,
157 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
158 connect(m_view
, &DolphinView::directorySortingProgress
,
159 this, &DolphinViewContainer::updateDirectorySortingProgress
);
160 connect(m_view
, &DolphinView::selectionChanged
,
161 this, &DolphinViewContainer::delayedStatusBarUpdate
);
162 connect(m_view
, &DolphinView::errorMessage
,
163 this, &DolphinViewContainer::showErrorMessage
);
164 connect(m_view
, &DolphinView::urlIsFileError
,
165 this, &DolphinViewContainer::slotUrlIsFileError
);
166 connect(m_view
, &DolphinView::activated
,
167 this, &DolphinViewContainer::activate
);
169 connect(m_view
, &DolphinView::directoryLoadingCompleted
, this, [this]() {
170 m_emptyTrashButton
->setVisible(m_view
->url().scheme() == QLatin1String("trash"));
173 // Initialize status bar
174 m_statusBar
= new DolphinStatusBar(this);
175 m_statusBar
->setUrl(m_view
->url());
176 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
177 connect(m_view
, &DolphinView::urlChanged
,
178 m_statusBar
, &DolphinStatusBar::setUrl
);
179 connect(m_view
, &DolphinView::zoomLevelChanged
,
180 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
181 connect(m_view
, &DolphinView::infoMessage
,
182 m_statusBar
, &DolphinStatusBar::setText
);
183 connect(m_view
, &DolphinView::operationCompletedMessage
,
184 m_statusBar
, &DolphinStatusBar::setText
);
185 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
186 this, &DolphinViewContainer::stopDirectoryLoading
);
187 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
188 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
190 m_statusBarTimer
= new QTimer(this);
191 m_statusBarTimer
->setSingleShot(true);
192 m_statusBarTimer
->setInterval(300);
193 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
195 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
196 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
197 this, &DolphinViewContainer::delayedStatusBarUpdate
);
199 navigatorLayout
->addWidget(m_urlNavigator
);
200 navigatorLayout
->addWidget(m_emptyTrashButton
);
202 m_topLayout
->addWidget(m_navigatorWidget
);
203 m_topLayout
->addWidget(m_searchBox
);
204 m_topLayout
->addWidget(m_messageWidget
);
205 m_topLayout
->addWidget(m_view
);
206 m_topLayout
->addWidget(m_filterBar
);
207 m_topLayout
->addWidget(m_statusBar
);
209 if (!GeneralSettings::locationInToolbar()) {
210 connectToInternalUrlNavigator();
212 setSearchModeEnabled(isSearchUrl(url
));
214 connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged
, this, [=]() {
215 if (view()->mode() == DolphinView::Mode::DetailsView
) {
220 // Initialize kactivities resource instance
222 #ifdef HAVE_KACTIVITIES
223 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
224 m_activityResourceInstance
->setParent(this);
228 DolphinViewContainer::~DolphinViewContainer()
232 QUrl
DolphinViewContainer::url() const
234 return m_view
->url();
237 void DolphinViewContainer::setActive(bool active
)
239 m_searchBox
->setActive(active
);
240 m_urlNavigator
->setActive(active
);
241 m_view
->setActive(active
);
243 #ifdef HAVE_KACTIVITIES
245 m_activityResourceInstance
->notifyFocusedIn();
247 m_activityResourceInstance
->notifyFocusedOut();
252 bool DolphinViewContainer::isActive() const
254 Q_ASSERT(!m_urlNavigatorConnected
|| m_urlNavigatorConnected
->isActive() == m_view
->isActive());
255 return m_view
->isActive();
258 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
260 m_autoGrabFocus
= grab
;
263 bool DolphinViewContainer::autoGrabFocus() const
265 return m_autoGrabFocus
;
268 QString
DolphinViewContainer::currentSearchText() const
270 return m_searchBox
->text();
273 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
278 DolphinStatusBar
* DolphinViewContainer::statusBar()
283 const DolphinUrlNavigator
* DolphinViewContainer::urlNavigator() const
285 return m_urlNavigatorConnected
;
288 DolphinUrlNavigator
* DolphinViewContainer::urlNavigator()
290 return m_urlNavigatorConnected
;
293 const DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory() const
295 return m_urlNavigator
;
298 DolphinUrlNavigator
*DolphinViewContainer::urlNavigatorInternalWithHistory()
300 return m_urlNavigator
;
303 const DolphinView
* DolphinViewContainer::view() const
308 DolphinView
* DolphinViewContainer::view()
313 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
)
315 Q_CHECK_PTR(urlNavigator
);
316 Q_ASSERT(!m_urlNavigatorConnected
);
319 m_urlNavigatorConnected
= urlNavigator
;
321 // m_urlNavigator is already connected through urlChanged signals.
322 if (urlNavigator
!= m_urlNavigator
) {
323 urlNavigator
->setLocationUrl(m_view
->url());
324 connect(m_view
, &DolphinView::urlChanged
,
325 urlNavigator
, &DolphinUrlNavigator::setLocationUrl
);
326 connect(urlNavigator
, &DolphinUrlNavigator::urlChanged
,
327 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
330 connect(urlNavigator
, &DolphinUrlNavigator::activated
,
331 this, &DolphinViewContainer::activate
);
332 connect(urlNavigator
, &DolphinUrlNavigator::urlAboutToBeChanged
,
333 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
334 connect(urlNavigator
, &DolphinUrlNavigator::urlSelectionRequested
,
335 this, &DolphinViewContainer::slotUrlSelectionRequested
);
336 connect(urlNavigator
, &DolphinUrlNavigator::urlsDropped
, this, [=](const QUrl
&destination
, QDropEvent
*event
) {
337 m_view
->dropUrls(destination
, event
, urlNavigator
->dropWidget());
340 updateNavigatorWidgetVisibility();
343 void DolphinViewContainer::disconnectUrlNavigator()
345 if (!m_urlNavigatorConnected
) {
349 // m_urlNavigator stays connected through the urlChanged signals.
350 if (m_urlNavigatorConnected
!= m_urlNavigator
) {
351 disconnect(m_view
, &DolphinView::urlChanged
,
352 m_urlNavigatorConnected
, &DolphinUrlNavigator::setLocationUrl
);
353 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlChanged
,
354 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
357 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::activated
,
358 this, &DolphinViewContainer::activate
);
359 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlAboutToBeChanged
,
360 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
361 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlSelectionRequested
,
362 this, &DolphinViewContainer::slotUrlSelectionRequested
);
363 disconnect(m_urlNavigatorConnected
, &DolphinUrlNavigator::urlsDropped
,
366 m_urlNavigatorConnected
= nullptr;
367 updateNavigatorWidgetVisibility();
370 KMessageWidget
*DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
373 return m_messageWidget
;
375 for (auto action
: m_messageWidget
->actions()) {
376 m_messageWidget
->removeAction(action
);
379 m_messageWidget
->setText(msg
);
381 // TODO: wrap at arbitrary character positions once QLabel can do this
382 // https://bugreports.qt.io/browse/QTBUG-1276
383 m_messageWidget
->setWordWrap(true);
386 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
387 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
388 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
394 m_messageWidget
->setWordWrap(false);
395 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
396 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
398 if (m_messageWidget
->isVisible()) {
399 m_messageWidget
->hide();
401 m_messageWidget
->animatedShow();
402 return m_messageWidget
;
405 void DolphinViewContainer::readSettings()
407 // The startup settings should (only) get applied if they have been
408 // modified by the user. Otherwise keep the (possibly) different current
409 // setting of the filterbar.
410 if (GeneralSettings::modifiedStartupSettings()) {
411 setFilterBarVisible(GeneralSettings::filterBar());
414 m_view
->readSettings();
415 m_statusBar
->readSettings();
418 bool DolphinViewContainer::isFilterBarVisible() const
420 return m_filterBar
->isVisible();
423 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
425 m_searchBox
->setVisible(enabled
);
426 updateNavigatorWidgetVisibility();
429 const QUrl
& locationUrl
= m_urlNavigatorConnected
->locationUrl();
430 m_searchBox
->fromSearchUrl(locationUrl
);
433 if (enabled
== isSearchModeEnabled()) {
434 if (enabled
&& !m_searchBox
->hasFocus()) {
435 m_searchBox
->setFocus();
436 m_searchBox
->selectAll();
442 m_view
->setViewPropertiesContext(QString());
444 // Restore the URL for the URL navigator. If Dolphin has been
445 // started with a search-URL, the home URL is used as fallback.
446 QUrl url
= m_searchBox
->searchPath();
447 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
448 url
= Dolphin::homeUrl();
450 m_urlNavigatorConnected
->setLocationUrl(url
);
453 m_searchModeEnabled
= enabled
;
455 Q_EMIT
searchModeEnabledChanged(enabled
);
458 bool DolphinViewContainer::isSearchModeEnabled() const
460 return m_searchModeEnabled
;
463 QString
DolphinViewContainer::placesText() const
467 if (isSearchModeEnabled()) {
468 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
470 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
471 if (text
.isEmpty()) {
474 if (text
.isEmpty()) {
475 text
= url().scheme();
482 void DolphinViewContainer::reload()
485 m_messageWidget
->hide();
488 QString
DolphinViewContainer::captionWindowTitle() const
490 if (GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
491 if (!url().isLocalFile()) {
492 return url().adjusted(QUrl::StripTrailingSlash
).toString();
494 return url().adjusted(QUrl::StripTrailingSlash
).path();
496 return DolphinViewContainer::caption();
500 QString
DolphinViewContainer::caption() const
502 if (isSearchModeEnabled()) {
503 if (currentSearchText().isEmpty()){
504 return i18n("Search");
506 return i18n("Search for %1", currentSearchText());
510 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
511 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, QUrl(url().adjusted(QUrl::StripTrailingSlash
).toString(QUrl::FullyEncoded
).append("/?")), 1, Qt::MatchRegExp
);
513 if (!matchedPlaces
.isEmpty()) {
514 return placesModel
->text(matchedPlaces
.first());
518 if (!url().isLocalFile()) {
519 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
521 if (!adjustedUrl
.fileName().isEmpty()) {
522 caption
= adjustedUrl
.fileName();
523 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
524 caption
= adjustedUrl
.path();
525 } else if (!adjustedUrl
.host().isEmpty()) {
526 caption
= adjustedUrl
.host();
528 caption
= adjustedUrl
.toString();
533 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
534 if (fileName
.isEmpty()) {
541 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
543 Q_CHECK_PTR(m_urlNavigatorConnected
);
544 if (newUrl
!= m_urlNavigatorConnected
->locationUrl()) {
545 m_urlNavigatorConnected
->setLocationUrl(newUrl
);
548 #ifdef HAVE_KACTIVITIES
549 m_activityResourceInstance
->setUri(newUrl
);
553 void DolphinViewContainer::setFilterBarVisible(bool visible
)
555 Q_ASSERT(m_filterBar
);
557 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
559 m_filterBar
->setFocus();
560 m_filterBar
->selectAll();
566 void DolphinViewContainer::delayedStatusBarUpdate()
568 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
569 // No update of the statusbar has been done during the last 2 seconds,
570 // although an update has been requested. Trigger an immediate update.
571 m_statusBarTimer
->stop();
574 // Invoke updateStatusBar() with a small delay. This assures that
575 // when a lot of delayedStatusBarUpdates() are done in a short time,
576 // no bottleneck is given.
577 m_statusBarTimer
->start();
581 void DolphinViewContainer::updateStatusBar()
583 m_statusBarTimestamp
.start();
585 const QString text
= m_view
->statusBarText();
586 m_statusBar
->setDefaultText(text
);
587 m_statusBar
->resetToDefaultText();
590 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
592 if (m_statusBar
->progressText().isEmpty()) {
593 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
595 m_statusBar
->setProgress(percent
);
598 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
600 if (m_statusBar
->progressText().isEmpty()) {
601 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
603 m_statusBar
->setProgress(percent
);
606 void DolphinViewContainer::updateNavigatorWidgetVisibility()
608 if (m_urlNavigatorConnected
== m_urlNavigator
&& !m_searchBox
->isVisible()) {
609 m_navigatorWidget
->setVisible(true);
611 m_navigatorWidget
->setVisible(false);
615 void DolphinViewContainer::slotDirectoryLoadingStarted()
617 if (isSearchUrl(url())) {
618 // Search KIO-slaves usually don't provide any progress information. Give
619 // a hint to the user that a searching is done:
621 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
622 m_statusBar
->setProgress(-1);
624 // Trigger an undetermined progress indication. The progress
625 // information in percent will be triggered by the percent() signal
626 // of the directory lister later.
627 m_statusBar
->setProgressText(QString());
628 updateDirectoryLoadingProgress(-1);
632 void DolphinViewContainer::slotDirectoryLoadingCompleted()
634 if (!m_statusBar
->progressText().isEmpty()) {
635 m_statusBar
->setProgressText(QString());
636 m_statusBar
->setProgress(100);
639 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
640 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
641 // of showing the default status bar information ("0 items") a more helpful information is given:
642 m_statusBar
->setText(i18nc("@info:status", "No items found."));
648 void DolphinViewContainer::slotDirectoryLoadingCanceled()
650 if (!m_statusBar
->progressText().isEmpty()) {
651 m_statusBar
->setProgressText(QString());
652 m_statusBar
->setProgress(100);
655 m_statusBar
->setText(QString());
658 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
660 const KFileItem
item(url
);
662 // Find out if the file can be opened in the view (for example, this is the
663 // case if the file is an archive). The mime type must be known for that.
664 item
.determineMimeType();
665 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
666 if (!folderUrl
.isEmpty()) {
669 slotItemActivated(item
);
673 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
675 // It is possible to activate items on inactive views by
676 // drag & drop operations. Assure that activating an item always
677 // results in an active view.
678 m_view
->setActive(true);
680 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
681 if (!url
.isEmpty()) {
686 KIO::OpenUrlJob
*job
= new KIO::OpenUrlJob(item
.targetUrl());
687 job
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
688 job
->setShowOpenOrExecuteDialog(true);
692 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
694 Q_ASSERT(items
.count() >= 2);
696 KFileItemActions
fileItemActions(this);
697 fileItemActions
.runPreferredApplications(items
, QString());
700 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
703 m_statusBar
->resetToDefaultText();
705 m_statusBar
->setText(item
.getStatusBarInfo());
709 void DolphinViewContainer::closeFilterBar()
711 m_filterBar
->closeFilterBar();
713 Q_EMIT
showFilterBarChanged(false);
716 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
718 m_view
->hideToolTip(ToolTipManager::HideBehavior::Instantly
);
719 m_view
->setNameFilter(nameFilter
);
720 delayedStatusBarUpdate();
723 void DolphinViewContainer::activate()
728 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
733 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
735 if (m_urlNavigatorConnected
) {
736 m_urlNavigatorConnected
->slotReturnPressed();
739 if (KProtocolManager::supportsListing(url
)) {
740 setSearchModeEnabled(isSearchUrl(url
));
742 tryRestoreViewState();
744 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
745 // When an URL has been entered, the view should get the focus.
746 // The focus must be requested asynchronously, as changing the URL might create
747 // a new view widget.
748 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
750 } else if (KProtocolManager::isSourceProtocol(url
)) {
751 if (url
.scheme().startsWith(QLatin1String("http"))) {
752 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
753 "Dolphin does not support web pages, the web browser has been launched"),
756 showMessage(i18nc("@info:status",
757 "Protocol not supported by Dolphin, default application has been launched"),
761 QDesktopServices::openUrl(url
);
762 redirect(QUrl(), m_urlNavigator
->locationUrl(1));
764 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
765 m_urlNavigator
->goBack();
769 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
771 m_view
->markUrlsAsSelected({url
});
772 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
775 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
778 const bool block
= m_urlNavigator
->signalsBlocked();
779 m_urlNavigator
->blockSignals(true);
781 // Assure that the location state is reset for redirection URLs. This
782 // allows to skip redirection URLs when going back or forward in the
784 m_urlNavigator
->saveLocationState(QByteArray());
785 m_urlNavigator
->setLocationUrl(newUrl
);
786 setSearchModeEnabled(isSearchUrl(newUrl
));
788 m_urlNavigator
->blockSignals(block
);
791 void DolphinViewContainer::requestFocus()
796 void DolphinViewContainer::startSearching()
798 Q_CHECK_PTR(m_urlNavigatorConnected
);
799 const QUrl url
= m_searchBox
->urlForSearching();
800 if (url
.isValid() && !url
.isEmpty()) {
801 m_view
->setViewPropertiesContext(QStringLiteral("search"));
802 m_urlNavigatorConnected
->setLocationUrl(url
);
806 void DolphinViewContainer::closeSearchBox()
808 setSearchModeEnabled(false);
811 void DolphinViewContainer::stopDirectoryLoading()
813 m_view
->stopLoading();
814 m_statusBar
->setProgress(100);
817 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
819 m_view
->setZoomLevel(zoomLevel
);
822 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
824 showMessage(msg
, Error
);
827 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
829 return url
.scheme().contains(QLatin1String("search"));
832 void DolphinViewContainer::saveViewState()
834 QByteArray locationState
;
835 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
836 m_view
->saveState(stream
);
837 m_urlNavigator
->saveLocationState(locationState
);
840 void DolphinViewContainer::tryRestoreViewState()
842 QByteArray locationState
= m_urlNavigator
->locationState();
843 if (!locationState
.isEmpty()) {
844 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
845 m_view
->restoreState(stream
);