1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinviewcontainer.h"
22 #include "dolphin_generalsettings.h"
23 #include "dolphinplacesmodelsingleton.h"
24 #include "dolphindebug.h"
25 #include "filterbar/filterbar.h"
27 #include "search/dolphinsearchbox.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "trash/dolphintrash.h"
30 #include "views/viewmodecontroller.h"
31 #include "views/viewproperties.h"
33 #ifdef HAVE_KACTIVITIES
34 #include <KActivities/ResourceInstance>
36 #include <KFileItemActions>
37 #include <KFilePlacesModel>
38 #include <KIO/PreviewJob>
39 #include <KLocalizedString>
40 #include <KMessageWidget>
41 #include <KProtocolManager>
44 #include <KUrlComboBox>
45 #include <KUrlNavigator>
48 #include <QLoggingCategory>
52 #include <QVBoxLayout>
54 DolphinViewContainer::DolphinViewContainer(const QUrl
& url
, QWidget
* parent
) :
57 m_navigatorWidget(nullptr),
58 m_urlNavigator(nullptr),
59 m_emptyTrashButton(nullptr),
61 m_searchModeEnabled(false),
62 m_messageWidget(nullptr),
66 m_statusBarTimer(nullptr),
67 m_statusBarTimestamp(),
69 #ifdef HAVE_KACTIVITIES
70 , m_activityResourceInstance(nullptr)
75 m_topLayout
= new QVBoxLayout(this);
76 m_topLayout
->setSpacing(0);
77 m_topLayout
->setContentsMargins(0, 0, 0, 0);
79 m_navigatorWidget
= new QWidget(this);
80 QHBoxLayout
* navigatorLayout
= new QHBoxLayout(m_navigatorWidget
);
81 navigatorLayout
->setSpacing(0);
82 navigatorLayout
->setContentsMargins(0, 0, 0, 0);
83 m_navigatorWidget
->setWhatsThis(xi18nc("@info:whatsthis location bar",
84 "<para>This line describes the location of the files and folders "
85 "displayed below.</para><para>The name of the currently viewed "
86 "folder can be read at the very right. To the left of it is the "
87 "name of the folder that contains it. The whole line is called "
88 "the <emphasis>path</emphasis> to the current location because "
89 "following these folders from left to right leads here.</para>"
90 "<para>The path is displayed on the <emphasis>location bar</emphasis> "
91 "which is more powerful than one would expect. To learn more "
92 "about the basic and advanced features of the location bar "
93 "<link url='help:/dolphin/location-bar.html'>click here</link>. "
94 "This will open the dedicated page in the Handbook.</para>"));
96 m_urlNavigator
= new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url
, this);
97 connect(m_urlNavigator
, &KUrlNavigator::activated
,
98 this, &DolphinViewContainer::activate
);
99 connect(m_urlNavigator
->editor(), &KUrlComboBox::completionModeChanged
,
100 this, &DolphinViewContainer::saveUrlCompletionMode
);
102 const GeneralSettings
* settings
= GeneralSettings::self();
103 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
104 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
105 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
106 KUrlComboBox
* editor
= m_urlNavigator
->editor();
107 editor
->setCompletionMode(KCompletion::CompletionMode(settings
->urlCompletionMode()));
109 m_emptyTrashButton
= new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this);
110 m_emptyTrashButton
->setFlat(true);
111 connect(m_emptyTrashButton
, &QPushButton::clicked
, this, [this]() { Trash::empty(this); });
112 connect(&Trash::instance(), &Trash::emptinessChanged
, m_emptyTrashButton
, &QPushButton::setDisabled
);
113 m_emptyTrashButton
->setDisabled(Trash::isEmpty());
114 m_emptyTrashButton
->hide();
116 m_searchBox
= new DolphinSearchBox(this);
118 connect(m_searchBox
, &DolphinSearchBox::activated
, this, &DolphinViewContainer::activate
);
119 connect(m_searchBox
, &DolphinSearchBox::closeRequest
, this, &DolphinViewContainer::closeSearchBox
);
120 connect(m_searchBox
, &DolphinSearchBox::searchRequest
, this, &DolphinViewContainer::startSearching
);
121 connect(m_searchBox
, &DolphinSearchBox::returnPressed
, this, &DolphinViewContainer::requestFocus
);
122 m_searchBox
->setWhatsThis(xi18nc("@info:whatsthis findbar",
123 "<para>This helps you find files and folders. Enter a <emphasis>"
124 "search term</emphasis> and specify search settings with the "
125 "buttons at the bottom:<list><item>Filename/Content: "
126 "Does the item you are looking for contain the search terms "
127 "within its filename or its contents?<nl/>The contents of images, "
128 "audio files and videos will not be searched.</item><item>"
129 "From Here/Everywhere: Do you want to search in this "
130 "folder and its sub-folders or everywhere?</item><item>"
131 "More Options: Click this to search by media type, access "
132 "time or rating.</item><item>More Search Tools: Install other "
133 "means to find an item.</item></list></para>"));
135 m_messageWidget
= new KMessageWidget(this);
136 m_messageWidget
->setCloseButtonVisible(true);
137 m_messageWidget
->hide();
142 // We must be logged in as the root user; show a big scary warning
143 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning
);
147 // Initialize filter bar
148 m_filterBar
= new FilterBar(this);
149 m_filterBar
->setVisible(settings
->filterBar());
151 connect(m_filterBar
, &FilterBar::filterChanged
,
152 this, &DolphinViewContainer::setNameFilter
);
153 connect(m_filterBar
, &FilterBar::closeRequest
,
154 this, &DolphinViewContainer::closeFilterBar
);
155 connect(m_filterBar
, &FilterBar::focusViewRequest
,
156 this, &DolphinViewContainer::requestFocus
);
158 // Initialize the main view
159 m_view
= new DolphinView(url
, this);
160 connect(m_view
, &DolphinView::urlChanged
,
161 m_filterBar
, &FilterBar::slotUrlChanged
);
162 connect(m_view
, &DolphinView::urlChanged
,
163 m_urlNavigator
, &KUrlNavigator::setLocationUrl
);
164 connect(m_view
, &DolphinView::urlChanged
,
165 m_messageWidget
, &KMessageWidget::hide
);
166 connect(m_view
, &DolphinView::writeStateChanged
,
167 this, &DolphinViewContainer::writeStateChanged
);
168 connect(m_view
, &DolphinView::requestItemInfo
,
169 this, &DolphinViewContainer::showItemInfo
);
170 connect(m_view
, &DolphinView::itemActivated
,
171 this, &DolphinViewContainer::slotItemActivated
);
172 connect(m_view
, &DolphinView::itemsActivated
,
173 this, &DolphinViewContainer::slotItemsActivated
);
174 connect(m_view
, &DolphinView::redirection
,
175 this, &DolphinViewContainer::redirect
);
176 connect(m_view
, &DolphinView::directoryLoadingStarted
,
177 this, &DolphinViewContainer::slotDirectoryLoadingStarted
);
178 connect(m_view
, &DolphinView::directoryLoadingCompleted
,
179 this, &DolphinViewContainer::slotDirectoryLoadingCompleted
);
180 connect(m_view
, &DolphinView::directoryLoadingCanceled
,
181 this, &DolphinViewContainer::slotDirectoryLoadingCanceled
);
182 connect(m_view
, &DolphinView::itemCountChanged
,
183 this, &DolphinViewContainer::delayedStatusBarUpdate
);
184 connect(m_view
, &DolphinView::directoryLoadingProgress
,
185 this, &DolphinViewContainer::updateDirectoryLoadingProgress
);
186 connect(m_view
, &DolphinView::directorySortingProgress
,
187 this, &DolphinViewContainer::updateDirectorySortingProgress
);
188 connect(m_view
, &DolphinView::selectionChanged
,
189 this, &DolphinViewContainer::delayedStatusBarUpdate
);
190 connect(m_view
, &DolphinView::errorMessage
,
191 this, &DolphinViewContainer::showErrorMessage
);
192 connect(m_view
, &DolphinView::urlIsFileError
,
193 this, &DolphinViewContainer::slotUrlIsFileError
);
194 connect(m_view
, &DolphinView::activated
,
195 this, &DolphinViewContainer::activate
);
197 connect(m_urlNavigator
, &KUrlNavigator::urlAboutToBeChanged
,
198 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged
);
199 connect(m_urlNavigator
, &KUrlNavigator::urlChanged
,
200 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged
);
201 connect(m_urlNavigator
, &KUrlNavigator::urlSelectionRequested
,
202 this, &DolphinViewContainer::slotUrlSelectionRequested
);
203 connect(m_urlNavigator
, &KUrlNavigator::returnPressed
,
204 this, &DolphinViewContainer::slotReturnPressed
);
205 connect(m_urlNavigator
, &KUrlNavigator::urlsDropped
, this, [=](const QUrl
&destination
, QDropEvent
*event
) {
206 m_view
->dropUrls(destination
, event
, m_urlNavigator
->dropWidget());
209 connect(m_view
, &DolphinView::directoryLoadingCompleted
, this, [this]() {
210 m_emptyTrashButton
->setVisible(m_view
->url().scheme() == QLatin1String("trash"));
213 // Initialize status bar
214 m_statusBar
= new DolphinStatusBar(this);
215 m_statusBar
->setUrl(m_view
->url());
216 m_statusBar
->setZoomLevel(m_view
->zoomLevel());
217 connect(m_view
, &DolphinView::urlChanged
,
218 m_statusBar
, &DolphinStatusBar::setUrl
);
219 connect(m_view
, &DolphinView::zoomLevelChanged
,
220 m_statusBar
, &DolphinStatusBar::setZoomLevel
);
221 connect(m_view
, &DolphinView::infoMessage
,
222 m_statusBar
, &DolphinStatusBar::setText
);
223 connect(m_view
, &DolphinView::operationCompletedMessage
,
224 m_statusBar
, &DolphinStatusBar::setText
);
225 connect(m_statusBar
, &DolphinStatusBar::stopPressed
,
226 this, &DolphinViewContainer::stopDirectoryLoading
);
227 connect(m_statusBar
, &DolphinStatusBar::zoomLevelChanged
,
228 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged
);
230 m_statusBarTimer
= new QTimer(this);
231 m_statusBarTimer
->setSingleShot(true);
232 m_statusBarTimer
->setInterval(300);
233 connect(m_statusBarTimer
, &QTimer::timeout
, this, &DolphinViewContainer::updateStatusBar
);
235 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
236 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
237 this, &DolphinViewContainer::delayedStatusBarUpdate
);
239 navigatorLayout
->addWidget(m_urlNavigator
);
240 navigatorLayout
->addWidget(m_emptyTrashButton
);
242 m_topLayout
->addWidget(m_navigatorWidget
);
243 m_topLayout
->addWidget(m_searchBox
);
244 m_topLayout
->addWidget(m_messageWidget
);
245 m_topLayout
->addWidget(m_view
);
246 m_topLayout
->addWidget(m_filterBar
);
247 m_topLayout
->addWidget(m_statusBar
);
249 setSearchModeEnabled(isSearchUrl(url
));
251 // Initialize kactivities resource instance
253 #ifdef HAVE_KACTIVITIES
254 m_activityResourceInstance
= new KActivities::ResourceInstance(window()->winId(), url
);
255 m_activityResourceInstance
->setParent(this);
259 DolphinViewContainer::~DolphinViewContainer()
263 QUrl
DolphinViewContainer::url() const
265 return m_view
->url();
268 void DolphinViewContainer::setActive(bool active
)
270 m_searchBox
->setActive(active
);
271 m_urlNavigator
->setActive(active
);
272 m_view
->setActive(active
);
274 #ifdef HAVE_KACTIVITIES
276 m_activityResourceInstance
->notifyFocusedIn();
278 m_activityResourceInstance
->notifyFocusedOut();
283 bool DolphinViewContainer::isActive() const
285 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
286 return m_view
->isActive();
289 void DolphinViewContainer::setAutoGrabFocus(bool grab
)
291 m_autoGrabFocus
= grab
;
294 bool DolphinViewContainer::autoGrabFocus() const
296 return m_autoGrabFocus
;
299 QString
DolphinViewContainer::currentSearchText() const
301 return m_searchBox
->text();
304 const DolphinStatusBar
* DolphinViewContainer::statusBar() const
309 DolphinStatusBar
* DolphinViewContainer::statusBar()
314 const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
316 return m_urlNavigator
;
319 KUrlNavigator
* DolphinViewContainer::urlNavigator()
321 return m_urlNavigator
;
324 const DolphinView
* DolphinViewContainer::view() const
329 DolphinView
* DolphinViewContainer::view()
334 void DolphinViewContainer::showMessage(const QString
& msg
, MessageType type
)
340 m_messageWidget
->setText(msg
);
342 // TODO: wrap at arbitrary character positions once QLabel can do this
343 // https://bugreports.qt.io/browse/QTBUG-1276
344 m_messageWidget
->setWordWrap(true);
347 case Information
: m_messageWidget
->setMessageType(KMessageWidget::Information
); break;
348 case Warning
: m_messageWidget
->setMessageType(KMessageWidget::Warning
); break;
349 case Error
: m_messageWidget
->setMessageType(KMessageWidget::Error
); break;
355 m_messageWidget
->setWordWrap(false);
356 const int unwrappedWidth
= m_messageWidget
->sizeHint().width();
357 m_messageWidget
->setWordWrap(unwrappedWidth
> size().width());
359 if (m_messageWidget
->isVisible()) {
360 m_messageWidget
->hide();
362 m_messageWidget
->animatedShow();
365 void DolphinViewContainer::readSettings()
367 if (GeneralSettings::modifiedStartupSettings()) {
368 // The startup settings should only get applied if they have been
369 // modified by the user. Otherwise keep the (possibly) different current
370 // settings of the URL navigator and the filterbar.
371 m_urlNavigator
->setUrlEditable(GeneralSettings::editableUrl());
372 m_urlNavigator
->setShowFullPath(GeneralSettings::showFullPath());
373 m_urlNavigator
->setHomeUrl(Dolphin::homeUrl());
374 setFilterBarVisible(GeneralSettings::filterBar());
377 m_view
->readSettings();
378 m_statusBar
->readSettings();
381 bool DolphinViewContainer::isFilterBarVisible() const
383 return m_filterBar
->isVisible();
386 void DolphinViewContainer::setSearchModeEnabled(bool enabled
)
388 if (enabled
== isSearchModeEnabled()) {
389 if (enabled
&& !m_searchBox
->hasFocus()) {
390 m_searchBox
->setFocus();
391 m_searchBox
->selectAll();
396 m_searchBox
->setVisible(enabled
);
397 m_navigatorWidget
->setVisible(!enabled
);
400 const QUrl
& locationUrl
= m_urlNavigator
->locationUrl();
401 m_searchBox
->fromSearchUrl(locationUrl
);
403 m_view
->setViewPropertiesContext(QString());
405 // Restore the URL for the URL navigator. If Dolphin has been
406 // started with a search-URL, the home URL is used as fallback.
407 QUrl url
= m_searchBox
->searchPath();
408 if (url
.isEmpty() || !url
.isValid() || isSearchUrl(url
)) {
409 url
= Dolphin::homeUrl();
411 m_urlNavigator
->setLocationUrl(url
);
414 m_searchModeEnabled
= enabled
;
416 emit
searchModeEnabledChanged(enabled
);
419 bool DolphinViewContainer::isSearchModeEnabled() const
421 return m_searchModeEnabled
;
424 QString
DolphinViewContainer::placesText() const
428 if (isSearchModeEnabled()) {
429 text
= i18n("Search for %1 in %2", m_searchBox
->text(), m_searchBox
->searchPath().fileName());
431 text
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
432 if (text
.isEmpty()) {
435 if (text
.isEmpty()) {
436 text
= url().scheme();
443 void DolphinViewContainer::reload()
446 m_messageWidget
->hide();
449 QString
DolphinViewContainer::caption() const
451 if (GeneralSettings::showFullPathInTitlebar()) {
452 if (!url().isLocalFile()) {
453 return url().adjusted(QUrl::StripTrailingSlash
).toString();
455 return url().adjusted(QUrl::StripTrailingSlash
).path();
458 KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
459 const auto& matchedPlaces
= placesModel
->match(placesModel
->index(0,0), KFilePlacesModel::UrlRole
, url(), 1, Qt::MatchExactly
);
461 if (!matchedPlaces
.isEmpty()) {
462 return placesModel
->text(matchedPlaces
.first());
465 if (isSearchModeEnabled()) {
466 if (currentSearchText().isEmpty()){
467 return i18n("Search");
469 return i18n("Search for %1", currentSearchText());
473 if (!url().isLocalFile()) {
474 QUrl adjustedUrl
= url().adjusted(QUrl::StripTrailingSlash
);
476 if (!adjustedUrl
.fileName().isEmpty()) {
477 caption
= adjustedUrl
.fileName();
478 } else if (!adjustedUrl
.path().isEmpty() && adjustedUrl
.path() != "/") {
479 caption
= adjustedUrl
.path();
480 } else if (!adjustedUrl
.host().isEmpty()) {
481 caption
= adjustedUrl
.host();
483 caption
= adjustedUrl
.toString();
488 QString fileName
= url().adjusted(QUrl::StripTrailingSlash
).fileName();
489 if (fileName
.isEmpty()) {
496 void DolphinViewContainer::setUrl(const QUrl
& newUrl
)
498 if (newUrl
!= m_urlNavigator
->locationUrl()) {
499 m_urlNavigator
->setLocationUrl(newUrl
);
502 #ifdef HAVE_KACTIVITIES
503 m_activityResourceInstance
->setUri(newUrl
);
507 void DolphinViewContainer::setFilterBarVisible(bool visible
)
509 Q_ASSERT(m_filterBar
);
512 m_filterBar
->setFocus();
513 m_filterBar
->selectAll();
519 void DolphinViewContainer::delayedStatusBarUpdate()
521 if (m_statusBarTimer
->isActive() && (m_statusBarTimestamp
.elapsed() > 2000)) {
522 // No update of the statusbar has been done during the last 2 seconds,
523 // although an update has been requested. Trigger an immediate update.
524 m_statusBarTimer
->stop();
527 // Invoke updateStatusBar() with a small delay. This assures that
528 // when a lot of delayedStatusBarUpdates() are done in a short time,
529 // no bottleneck is given.
530 m_statusBarTimer
->start();
534 void DolphinViewContainer::updateStatusBar()
536 m_statusBarTimestamp
.start();
538 const QString text
= m_view
->statusBarText();
539 m_statusBar
->setDefaultText(text
);
540 m_statusBar
->resetToDefaultText();
543 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent
)
545 if (m_statusBar
->progressText().isEmpty()) {
546 m_statusBar
->setProgressText(i18nc("@info:progress", "Loading folder..."));
548 m_statusBar
->setProgress(percent
);
551 void DolphinViewContainer::updateDirectorySortingProgress(int percent
)
553 if (m_statusBar
->progressText().isEmpty()) {
554 m_statusBar
->setProgressText(i18nc("@info:progress", "Sorting..."));
556 m_statusBar
->setProgress(percent
);
559 void DolphinViewContainer::slotDirectoryLoadingStarted()
561 if (isSearchUrl(url())) {
562 // Search KIO-slaves usually don't provide any progress information. Give
563 // a hint to the user that a searching is done:
565 m_statusBar
->setProgressText(i18nc("@info", "Searching..."));
566 m_statusBar
->setProgress(-1);
568 // Trigger an undetermined progress indication. The progress
569 // information in percent will be triggered by the percent() signal
570 // of the directory lister later.
571 m_statusBar
->setProgressText(QString());
572 updateDirectoryLoadingProgress(-1);
576 void DolphinViewContainer::slotDirectoryLoadingCompleted()
578 if (!m_statusBar
->progressText().isEmpty()) {
579 m_statusBar
->setProgressText(QString());
580 m_statusBar
->setProgress(100);
583 if (isSearchUrl(url()) && m_view
->itemsCount() == 0) {
584 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
585 // of showing the default status bar information ("0 items") a more helpful information is given:
586 m_statusBar
->setText(i18nc("@info:status", "No items found."));
592 void DolphinViewContainer::slotDirectoryLoadingCanceled()
594 if (!m_statusBar
->progressText().isEmpty()) {
595 m_statusBar
->setProgressText(QString());
596 m_statusBar
->setProgress(100);
599 m_statusBar
->setText(QString());
602 void DolphinViewContainer::slotUrlIsFileError(const QUrl
& url
)
604 const KFileItem
item(url
);
606 // Find out if the file can be opened in the view (for example, this is the
607 // case if the file is an archive). The mime type must be known for that.
608 item
.determineMimeType();
609 const QUrl
& folderUrl
= DolphinView::openItemAsFolderUrl(item
, true);
610 if (!folderUrl
.isEmpty()) {
613 slotItemActivated(item
);
617 void DolphinViewContainer::slotItemActivated(const KFileItem
& item
)
619 // It is possible to activate items on inactive views by
620 // drag & drop operations. Assure that activating an item always
621 // results in an active view.
622 m_view
->setActive(true);
624 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
, GeneralSettings::browseThroughArchives());
625 if (!url
.isEmpty()) {
630 KRun
*run
= new KRun(item
.targetUrl(), this);
631 run
->setShowScriptExecutionPrompt(true);
634 void DolphinViewContainer::slotItemsActivated(const KFileItemList
& items
)
636 Q_ASSERT(items
.count() >= 2);
638 KFileItemActions
fileItemActions(this);
639 fileItemActions
.runPreferredApplications(items
, QString());
642 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
645 m_statusBar
->resetToDefaultText();
647 m_statusBar
->setText(item
.getStatusBarInfo());
651 void DolphinViewContainer::closeFilterBar()
653 m_filterBar
->closeFilterBar();
655 emit
showFilterBarChanged(false);
658 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
660 m_view
->setNameFilter(nameFilter
);
661 delayedStatusBarUpdate();
664 void DolphinViewContainer::activate()
669 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&)
674 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl
& url
)
678 if (KProtocolManager::supportsListing(url
)) {
679 setSearchModeEnabled(isSearchUrl(url
));
681 tryRestoreViewState();
683 if (m_autoGrabFocus
&& isActive() && !isSearchUrl(url
)) {
684 // When an URL has been entered, the view should get the focus.
685 // The focus must be requested asynchronously, as changing the URL might create
686 // a new view widget.
687 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus
);
689 } else if (KProtocolManager::isSourceProtocol(url
)) {
690 QString app
= QStringLiteral("konqueror");
691 if (url
.scheme().startsWith(QLatin1String("http"))) {
692 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
693 "Dolphin does not support web pages, the web browser has been launched"),
696 const KConfigGroup
config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "General");
697 const QString browser
= config
.readEntry("BrowserApplication");
698 if (!browser
.isEmpty()) {
700 if (app
.startsWith('!')) {
701 // a literal command has been configured, remove the '!' prefix
706 showMessage(i18nc("@info:status",
707 "Protocol not supported by Dolphin, Konqueror has been launched"),
711 const QString secureUrl
= KShell::quoteArg(url
.toDisplayString(QUrl::PreferLocalFile
));
712 const QString command
= app
+ ' ' + secureUrl
;
713 KRun::runCommand(command
, app
, app
, this);
715 showMessage(i18nc("@info:status", "Invalid protocol"), Error
);
719 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl
& url
)
721 m_view
->markUrlsAsSelected({url
});
722 m_view
->markUrlAsCurrent(url
); // makes the item scroll into view
725 void DolphinViewContainer::redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
)
728 const bool block
= m_urlNavigator
->signalsBlocked();
729 m_urlNavigator
->blockSignals(true);
731 // Assure that the location state is reset for redirection URLs. This
732 // allows to skip redirection URLs when going back or forward in the
734 m_urlNavigator
->saveLocationState(QByteArray());
735 m_urlNavigator
->setLocationUrl(newUrl
);
736 setSearchModeEnabled(isSearchUrl(newUrl
));
738 m_urlNavigator
->blockSignals(block
);
741 void DolphinViewContainer::requestFocus()
746 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion
)
748 GeneralSettings::setUrlCompletionMode(completion
);
751 void DolphinViewContainer::slotReturnPressed()
753 if (!GeneralSettings::editableUrl()) {
754 m_urlNavigator
->setUrlEditable(false);
758 void DolphinViewContainer::startSearching()
760 const QUrl url
= m_searchBox
->urlForSearching();
761 if (url
.isValid() && !url
.isEmpty()) {
762 m_view
->setViewPropertiesContext(QStringLiteral("search"));
763 m_urlNavigator
->setLocationUrl(url
);
767 void DolphinViewContainer::closeSearchBox()
769 setSearchModeEnabled(false);
772 void DolphinViewContainer::stopDirectoryLoading()
774 m_view
->stopLoading();
775 m_statusBar
->setProgress(100);
778 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel
)
780 m_view
->setZoomLevel(zoomLevel
);
783 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
785 showMessage(msg
, Error
);
788 bool DolphinViewContainer::isSearchUrl(const QUrl
& url
) const
790 return url
.scheme().contains(QStringLiteral("search"));
793 void DolphinViewContainer::saveViewState()
795 QByteArray locationState
;
796 QDataStream
stream(&locationState
, QIODevice::WriteOnly
);
797 m_view
->saveState(stream
);
798 m_urlNavigator
->saveLocationState(locationState
);
801 void DolphinViewContainer::tryRestoreViewState()
803 QByteArray locationState
= m_urlNavigator
->locationState();
804 if (!locationState
.isEmpty()) {
805 QDataStream
stream(&locationState
, QIODevice::ReadOnly
);
806 m_view
->restoreState(stream
);