]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.cpp
Remove unused #include
[dolphin.git] / src / dolphinviewcontainer.cpp
1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "dolphinviewcontainer.h"
21
22 #include "dolphin_generalsettings.h"
23 #include "dolphindebug.h"
24 #include "filterbar/filterbar.h"
25 #include "global.h"
26 #include "search/dolphinsearchbox.h"
27 #include "statusbar/dolphinstatusbar.h"
28 #include "views/viewmodecontroller.h"
29 #include "views/viewproperties.h"
30
31 #include <KFileItemActions>
32 #include <KFilePlacesModel>
33 #include <KIO/PreviewJob>
34 #include <KLocalizedString>
35 #include <KMessageWidget>
36 #include <KProtocolManager>
37 #include <KRun>
38 #include <KShell>
39 #include <KUrlComboBox>
40 #include <KUrlNavigator>
41 #include <kio_version.h>
42
43 #include <QDropEvent>
44 #include <QLoggingCategory>
45 #include <QMimeData>
46 #include <QTimer>
47 #include <QUrl>
48 #include <QVBoxLayout>
49
50 DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
51 QWidget(parent),
52 m_topLayout(nullptr),
53 m_urlNavigator(nullptr),
54 m_searchBox(nullptr),
55 m_messageWidget(nullptr),
56 m_view(nullptr),
57 m_filterBar(nullptr),
58 m_statusBar(nullptr),
59 m_statusBarTimer(nullptr),
60 m_statusBarTimestamp(),
61 m_autoGrabFocus(true)
62 #ifdef KActivities_FOUND
63 , m_activityResourceInstance(0)
64 #endif
65 {
66 hide();
67
68 m_topLayout = new QVBoxLayout(this);
69 m_topLayout->setSpacing(0);
70 m_topLayout->setMargin(0);
71
72 m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this);
73 connect(m_urlNavigator, &KUrlNavigator::activated,
74 this, &DolphinViewContainer::activate);
75 connect(m_urlNavigator->editor(), &KUrlComboBox::completionModeChanged,
76 this, &DolphinViewContainer::saveUrlCompletionMode);
77
78 const GeneralSettings* settings = GeneralSettings::self();
79 m_urlNavigator->setUrlEditable(settings->editableUrl());
80 m_urlNavigator->setShowFullPath(settings->showFullPath());
81 m_urlNavigator->setHomeUrl(Dolphin::homeUrl());
82 KUrlComboBox* editor = m_urlNavigator->editor();
83 editor->setCompletionMode(KCompletion::CompletionMode(settings->urlCompletionMode()));
84
85 m_searchBox = new DolphinSearchBox(this);
86 m_searchBox->hide();
87 connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate);
88 connect(m_searchBox, &DolphinSearchBox::closeRequest, this, &DolphinViewContainer::closeSearchBox);
89 connect(m_searchBox, &DolphinSearchBox::searchRequest, this, &DolphinViewContainer::startSearching);
90 connect(m_searchBox, &DolphinSearchBox::returnPressed, this, &DolphinViewContainer::requestFocus);
91
92 m_messageWidget = new KMessageWidget(this);
93 m_messageWidget->setCloseButtonVisible(true);
94 m_messageWidget->hide();
95
96 m_view = new DolphinView(url, this);
97 connect(m_view, &DolphinView::urlChanged,
98 m_urlNavigator, &KUrlNavigator::setLocationUrl);
99 connect(m_view, &DolphinView::urlChanged,
100 m_messageWidget, &KMessageWidget::hide);
101 connect(m_view, &DolphinView::writeStateChanged,
102 this, &DolphinViewContainer::writeStateChanged);
103 connect(m_view, &DolphinView::requestItemInfo,
104 this, &DolphinViewContainer::showItemInfo);
105 connect(m_view, &DolphinView::itemActivated,
106 this, &DolphinViewContainer::slotItemActivated);
107 connect(m_view, &DolphinView::itemsActivated,
108 this, &DolphinViewContainer::slotItemsActivated);
109 connect(m_view, &DolphinView::redirection,
110 this, &DolphinViewContainer::redirect);
111 connect(m_view, &DolphinView::directoryLoadingStarted,
112 this, &DolphinViewContainer::slotDirectoryLoadingStarted);
113 connect(m_view, &DolphinView::directoryLoadingCompleted,
114 this, &DolphinViewContainer::slotDirectoryLoadingCompleted);
115 connect(m_view, &DolphinView::directoryLoadingCanceled,
116 this, &DolphinViewContainer::slotDirectoryLoadingCanceled);
117 connect(m_view, &DolphinView::itemCountChanged,
118 this, &DolphinViewContainer::delayedStatusBarUpdate);
119 connect(m_view, &DolphinView::directoryLoadingProgress,
120 this, &DolphinViewContainer::updateDirectoryLoadingProgress);
121 connect(m_view, &DolphinView::directorySortingProgress,
122 this, &DolphinViewContainer::updateDirectorySortingProgress);
123 connect(m_view, &DolphinView::selectionChanged,
124 this, &DolphinViewContainer::delayedStatusBarUpdate);
125 connect(m_view, &DolphinView::errorMessage,
126 this, &DolphinViewContainer::showErrorMessage);
127 connect(m_view, &DolphinView::urlIsFileError,
128 this, &DolphinViewContainer::slotUrlIsFileError);
129 connect(m_view, &DolphinView::activated,
130 this, &DolphinViewContainer::activate);
131
132 connect(m_urlNavigator, &KUrlNavigator::urlAboutToBeChanged,
133 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
134 connect(m_urlNavigator, &KUrlNavigator::urlChanged,
135 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
136 connect(m_urlNavigator, &KUrlNavigator::urlSelectionRequested,
137 this, &DolphinViewContainer::slotUrlSelectionRequested);
138 connect(m_urlNavigator, &KUrlNavigator::returnPressed,
139 this, &DolphinViewContainer::slotReturnPressed);
140 connect(m_urlNavigator, &KUrlNavigator::urlsDropped, this, [=](const QUrl &destination, QDropEvent *event) {
141 #if KIO_VERSION >= QT_VERSION_CHECK(5, 37, 0)
142 m_view->dropUrls(destination, event, m_urlNavigator->dropWidget());
143 #else
144 // TODO: remove as soon as we can hard-depend of KF5 >= 5.37
145 m_view->dropUrls(destination, event, m_view);
146 #endif
147 });
148
149 // Initialize status bar
150 m_statusBar = new DolphinStatusBar(this);
151 m_statusBar->setUrl(m_view->url());
152 m_statusBar->setZoomLevel(m_view->zoomLevel());
153 connect(m_view, &DolphinView::urlChanged,
154 m_statusBar, &DolphinStatusBar::setUrl);
155 connect(m_view, &DolphinView::zoomLevelChanged,
156 m_statusBar, &DolphinStatusBar::setZoomLevel);
157 connect(m_view, &DolphinView::infoMessage,
158 m_statusBar, &DolphinStatusBar::setText);
159 connect(m_view, &DolphinView::operationCompletedMessage,
160 m_statusBar, &DolphinStatusBar::setText);
161 connect(m_statusBar, &DolphinStatusBar::stopPressed,
162 this, &DolphinViewContainer::stopDirectoryLoading);
163 connect(m_statusBar, &DolphinStatusBar::zoomLevelChanged,
164 this, &DolphinViewContainer::slotStatusBarZoomLevelChanged);
165
166 m_statusBarTimer = new QTimer(this);
167 m_statusBarTimer->setSingleShot(true);
168 m_statusBarTimer->setInterval(300);
169 connect(m_statusBarTimer, &QTimer::timeout, this, &DolphinViewContainer::updateStatusBar);
170
171 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
172 connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished,
173 this, &DolphinViewContainer::delayedStatusBarUpdate);
174
175 // Initialize filter bar
176 m_filterBar = new FilterBar(this);
177 m_filterBar->setVisible(settings->filterBar());
178 connect(m_filterBar, &FilterBar::filterChanged,
179 this, &DolphinViewContainer::setNameFilter);
180 connect(m_filterBar, &FilterBar::closeRequest,
181 this, &DolphinViewContainer::closeFilterBar);
182 connect(m_filterBar, &FilterBar::focusViewRequest,
183 this, &DolphinViewContainer::requestFocus);
184 connect(m_view, &DolphinView::urlChanged,
185 m_filterBar, &FilterBar::slotUrlChanged);
186
187 m_topLayout->addWidget(m_urlNavigator);
188 m_topLayout->addWidget(m_searchBox);
189 m_topLayout->addWidget(m_messageWidget);
190 m_topLayout->addWidget(m_view);
191 m_topLayout->addWidget(m_filterBar);
192 m_topLayout->addWidget(m_statusBar);
193
194 setSearchModeEnabled(isSearchUrl(url));
195
196 // Initialize kactivities resource instance
197
198 #ifdef KActivities_FOUND
199 m_activityResourceInstance = new KActivities::ResourceInstance(
200 window()->winId(), url);
201 m_activityResourceInstance->setParent(this);
202 #endif
203 }
204
205 DolphinViewContainer::~DolphinViewContainer()
206 {
207 }
208
209 QUrl DolphinViewContainer::url() const
210 {
211 return m_view->url();
212 }
213
214 void DolphinViewContainer::setActive(bool active)
215 {
216 m_searchBox->setActive(active);
217 m_urlNavigator->setActive(active);
218 m_view->setActive(active);
219
220 #ifdef KActivities_FOUND
221 if (active) {
222 m_activityResourceInstance->notifyFocusedIn();
223 } else {
224 m_activityResourceInstance->notifyFocusedOut();
225 }
226 #endif
227 }
228
229 bool DolphinViewContainer::isActive() const
230 {
231 Q_ASSERT(m_view->isActive() == m_urlNavigator->isActive());
232 return m_view->isActive();
233 }
234
235 void DolphinViewContainer::setAutoGrabFocus(bool grab)
236 {
237 m_autoGrabFocus = grab;
238 }
239
240 bool DolphinViewContainer::autoGrabFocus() const
241 {
242 return m_autoGrabFocus;
243 }
244
245 QString DolphinViewContainer::currentSearchText() const
246 {
247 return m_searchBox->text();
248 }
249
250 const DolphinStatusBar* DolphinViewContainer::statusBar() const
251 {
252 return m_statusBar;
253 }
254
255 DolphinStatusBar* DolphinViewContainer::statusBar()
256 {
257 return m_statusBar;
258 }
259
260 const KUrlNavigator* DolphinViewContainer::urlNavigator() const
261 {
262 return m_urlNavigator;
263 }
264
265 KUrlNavigator* DolphinViewContainer::urlNavigator()
266 {
267 return m_urlNavigator;
268 }
269
270 const DolphinView* DolphinViewContainer::view() const
271 {
272 return m_view;
273 }
274
275 DolphinView* DolphinViewContainer::view()
276 {
277 return m_view;
278 }
279
280 void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
281 {
282 if (msg.isEmpty()) {
283 return;
284 }
285
286 m_messageWidget->setText(msg);
287
288 switch (type) {
289 case Information: m_messageWidget->setMessageType(KMessageWidget::Information); break;
290 case Warning: m_messageWidget->setMessageType(KMessageWidget::Warning); break;
291 case Error: m_messageWidget->setMessageType(KMessageWidget::Error); break;
292 default:
293 Q_ASSERT(false);
294 break;
295 }
296
297 m_messageWidget->setWordWrap(false);
298 const int unwrappedWidth = m_messageWidget->sizeHint().width();
299 m_messageWidget->setWordWrap(unwrappedWidth > size().width());
300
301 if (m_messageWidget->isVisible()) {
302 m_messageWidget->hide();
303 }
304 m_messageWidget->animatedShow();
305 }
306
307 void DolphinViewContainer::readSettings()
308 {
309 if (GeneralSettings::modifiedStartupSettings()) {
310 // The startup settings should only get applied if they have been
311 // modified by the user. Otherwise keep the (possibly) different current
312 // settings of the URL navigator and the filterbar.
313 m_urlNavigator->setUrlEditable(GeneralSettings::editableUrl());
314 m_urlNavigator->setShowFullPath(GeneralSettings::showFullPath());
315 m_urlNavigator->setHomeUrl(Dolphin::homeUrl());
316 setFilterBarVisible(GeneralSettings::filterBar());
317 }
318
319 m_view->readSettings();
320 m_statusBar->readSettings();
321 }
322
323 bool DolphinViewContainer::isFilterBarVisible() const
324 {
325 return m_filterBar->isVisible();
326 }
327
328 void DolphinViewContainer::setSearchModeEnabled(bool enabled)
329 {
330 if (enabled == isSearchModeEnabled()) {
331 if (enabled && !m_searchBox->hasFocus()) {
332 m_searchBox->setFocus();
333 m_searchBox->selectAll();
334 }
335 return;
336 }
337
338 m_searchBox->setVisible(enabled);
339 m_urlNavigator->setVisible(!enabled);
340
341 if (enabled) {
342 const QUrl& locationUrl = m_urlNavigator->locationUrl();
343 m_searchBox->fromSearchUrl(locationUrl);
344 } else {
345 m_view->setViewPropertiesContext(QString());
346
347 // Restore the URL for the URL navigator. If Dolphin has been
348 // started with a search-URL, the home URL is used as fallback.
349 QUrl url = m_searchBox->searchPath();
350 if (url.isEmpty() || !url.isValid() || isSearchUrl(url)) {
351 url = Dolphin::homeUrl();
352 }
353 m_urlNavigator->setLocationUrl(url);
354 }
355 }
356
357 bool DolphinViewContainer::isSearchModeEnabled() const
358 {
359 return m_searchBox->isVisible();
360 }
361
362 QString DolphinViewContainer::placesText() const
363 {
364 QString text;
365
366 if (isSearchModeEnabled()) {
367 text = i18n("Search for %1 in %2", m_searchBox->text(), m_searchBox->searchPath().fileName());
368 } else {
369 text = url().fileName();
370 if (text.isEmpty()) {
371 text = url().host();
372 }
373 if (text.isEmpty()) {
374 text = url().scheme();
375 }
376 }
377
378 return text;
379 }
380
381 void DolphinViewContainer::reload()
382 {
383 view()->reload();
384 m_messageWidget->hide();
385 }
386
387 void DolphinViewContainer::setUrl(const QUrl& newUrl)
388 {
389 if (newUrl != m_urlNavigator->locationUrl()) {
390 m_urlNavigator->setLocationUrl(newUrl);
391 }
392
393 #ifdef KActivities_FOUND
394 m_activityResourceInstance->setUri(newUrl);
395 #endif
396 }
397
398 void DolphinViewContainer::setFilterBarVisible(bool visible)
399 {
400 Q_ASSERT(m_filterBar);
401 if (visible) {
402 m_filterBar->show();
403 m_filterBar->setFocus();
404 m_filterBar->selectAll();
405 } else {
406 closeFilterBar();
407 }
408 }
409
410 void DolphinViewContainer::delayedStatusBarUpdate()
411 {
412 if (m_statusBarTimer->isActive() && (m_statusBarTimestamp.elapsed() > 2000)) {
413 // No update of the statusbar has been done during the last 2 seconds,
414 // although an update has been requested. Trigger an immediate update.
415 m_statusBarTimer->stop();
416 updateStatusBar();
417 } else {
418 // Invoke updateStatusBar() with a small delay. This assures that
419 // when a lot of delayedStatusBarUpdates() are done in a short time,
420 // no bottleneck is given.
421 m_statusBarTimer->start();
422 }
423 }
424
425 void DolphinViewContainer::updateStatusBar()
426 {
427 m_statusBarTimestamp.start();
428
429 const QString text = m_view->statusBarText();
430 m_statusBar->setDefaultText(text);
431 m_statusBar->resetToDefaultText();
432 }
433
434 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent)
435 {
436 if (m_statusBar->progressText().isEmpty()) {
437 m_statusBar->setProgressText(i18nc("@info:progress", "Loading folder..."));
438 }
439 m_statusBar->setProgress(percent);
440 }
441
442 void DolphinViewContainer::updateDirectorySortingProgress(int percent)
443 {
444 if (m_statusBar->progressText().isEmpty()) {
445 m_statusBar->setProgressText(i18nc("@info:progress", "Sorting..."));
446 }
447 m_statusBar->setProgress(percent);
448 }
449
450 void DolphinViewContainer::slotDirectoryLoadingStarted()
451 {
452 if (isSearchUrl(url())) {
453 // Search KIO-slaves usually don't provide any progress information. Give
454 // a hint to the user that a searching is done:
455 updateStatusBar();
456 m_statusBar->setProgressText(i18nc("@info", "Searching..."));
457 m_statusBar->setProgress(-1);
458 } else {
459 // Trigger an undetermined progress indication. The progress
460 // information in percent will be triggered by the percent() signal
461 // of the directory lister later.
462 updateDirectoryLoadingProgress(-1);
463 }
464 }
465
466 void DolphinViewContainer::slotDirectoryLoadingCompleted()
467 {
468 if (!m_statusBar->progressText().isEmpty()) {
469 m_statusBar->setProgressText(QString());
470 m_statusBar->setProgress(100);
471 }
472
473 if (isSearchUrl(url()) && m_view->itemsCount() == 0) {
474 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
475 // of showing the default status bar information ("0 items") a more helpful information is given:
476 m_statusBar->setText(i18nc("@info:status", "No items found."));
477 } else {
478 updateStatusBar();
479 }
480 }
481
482 void DolphinViewContainer::slotDirectoryLoadingCanceled()
483 {
484 if (!m_statusBar->progressText().isEmpty()) {
485 m_statusBar->setProgressText(QString());
486 m_statusBar->setProgress(100);
487 }
488
489 m_statusBar->setText(QString());
490 }
491
492 void DolphinViewContainer::slotUrlIsFileError(const QUrl& url)
493 {
494 const KFileItem item(url);
495
496 // Find out if the file can be opened in the view (for example, this is the
497 // case if the file is an archive). The mime type must be known for that.
498 item.determineMimeType();
499 const QUrl& folderUrl = DolphinView::openItemAsFolderUrl(item, true);
500 if (!folderUrl.isEmpty()) {
501 setUrl(folderUrl);
502 } else {
503 slotItemActivated(item);
504 }
505 }
506
507 void DolphinViewContainer::slotItemActivated(const KFileItem& item)
508 {
509 // It is possible to activate items on inactive views by
510 // drag & drop operations. Assure that activating an item always
511 // results in an active view.
512 m_view->setActive(true);
513
514 const QUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
515 if (!url.isEmpty()) {
516 setUrl(url);
517 return;
518 }
519
520 KRun *run = new KRun(item.targetUrl(), this);
521 run->setShowScriptExecutionPrompt(true);
522 }
523
524 void DolphinViewContainer::slotItemsActivated(const KFileItemList& items)
525 {
526 Q_ASSERT(items.count() >= 2);
527
528 KFileItemActions fileItemActions(this);
529 fileItemActions.runPreferredApplications(items, QString());
530 }
531
532 void DolphinViewContainer::showItemInfo(const KFileItem& item)
533 {
534 if (item.isNull()) {
535 m_statusBar->resetToDefaultText();
536 } else {
537 m_statusBar->setText(item.getStatusBarInfo());
538 }
539 }
540
541 void DolphinViewContainer::closeFilterBar()
542 {
543 m_filterBar->closeFilterBar();
544 m_view->setFocus();
545 emit showFilterBarChanged(false);
546 }
547
548 void DolphinViewContainer::setNameFilter(const QString& nameFilter)
549 {
550 m_view->setNameFilter(nameFilter);
551 delayedStatusBarUpdate();
552 }
553
554 void DolphinViewContainer::activate()
555 {
556 setActive(true);
557 }
558
559 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl&)
560 {
561 saveViewState();
562 }
563
564 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url)
565 {
566 slotReturnPressed();
567
568 if (KProtocolManager::supportsListing(url)) {
569 setSearchModeEnabled(isSearchUrl(url));
570 m_view->setUrl(url);
571 tryRestoreViewState();
572
573 if (m_autoGrabFocus && isActive() && !isSearchUrl(url)) {
574 // When an URL has been entered, the view should get the focus.
575 // The focus must be requested asynchronously, as changing the URL might create
576 // a new view widget.
577 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus);
578 }
579 } else if (KProtocolManager::isSourceProtocol(url)) {
580 QString app = QStringLiteral("konqueror");
581 if (url.scheme().startsWith(QLatin1String("http"))) {
582 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
583 "Dolphin does not support web pages, the web browser has been launched"),
584 Information);
585
586 const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "General");
587 const QString browser = config.readEntry("BrowserApplication");
588 if (!browser.isEmpty()) {
589 app = browser;
590 if (app.startsWith('!')) {
591 // a literal command has been configured, remove the '!' prefix
592 app = app.mid(1);
593 }
594 }
595 } else {
596 showMessage(i18nc("@info:status",
597 "Protocol not supported by Dolphin, Konqueror has been launched"),
598 Information);
599 }
600
601 const QString secureUrl = KShell::quoteArg(url.toDisplayString(QUrl::PreferLocalFile));
602 const QString command = app + ' ' + secureUrl;
603 KRun::runCommand(command, app, app, this);
604 } else {
605 showMessage(i18nc("@info:status", "Invalid protocol"), Error);
606 }
607 }
608
609 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl& url)
610 {
611 qCDebug(DolphinDebug) << "slotUrlSelectionRequested: " << url;
612 m_view->markUrlsAsSelected({url});
613 m_view->markUrlAsCurrent(url); // makes the item scroll into view
614 }
615
616 void DolphinViewContainer::redirect(const QUrl& oldUrl, const QUrl& newUrl)
617 {
618 Q_UNUSED(oldUrl);
619 const bool block = m_urlNavigator->signalsBlocked();
620 m_urlNavigator->blockSignals(true);
621
622 // Assure that the location state is reset for redirection URLs. This
623 // allows to skip redirection URLs when going back or forward in the
624 // URL history.
625 m_urlNavigator->saveLocationState(QByteArray());
626 m_urlNavigator->setLocationUrl(newUrl);
627 setSearchModeEnabled(isSearchUrl(newUrl));
628
629 m_urlNavigator->blockSignals(block);
630 }
631
632 void DolphinViewContainer::requestFocus()
633 {
634 m_view->setFocus();
635 }
636
637 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion)
638 {
639 GeneralSettings::setUrlCompletionMode(completion);
640 }
641
642 void DolphinViewContainer::slotReturnPressed()
643 {
644 if (!GeneralSettings::editableUrl()) {
645 m_urlNavigator->setUrlEditable(false);
646 }
647 }
648
649 void DolphinViewContainer::startSearching()
650 {
651 const QUrl url = m_searchBox->urlForSearching();
652 if (url.isValid() && !url.isEmpty()) {
653 m_view->setViewPropertiesContext(QStringLiteral("search"));
654 m_urlNavigator->setLocationUrl(url);
655 }
656 }
657
658 void DolphinViewContainer::closeSearchBox()
659 {
660 setSearchModeEnabled(false);
661 }
662
663 void DolphinViewContainer::stopDirectoryLoading()
664 {
665 m_view->stopLoading();
666 m_statusBar->setProgress(100);
667 }
668
669 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)
670 {
671 m_view->setZoomLevel(zoomLevel);
672 }
673
674 void DolphinViewContainer::showErrorMessage(const QString& msg)
675 {
676 showMessage(msg, Error);
677 }
678
679 bool DolphinViewContainer::isSearchUrl(const QUrl& url) const
680 {
681 return url.scheme().contains(QStringLiteral("search"));
682 }
683
684 void DolphinViewContainer::saveViewState()
685 {
686 QByteArray locationState;
687 QDataStream stream(&locationState, QIODevice::WriteOnly);
688 m_view->saveState(stream);
689 m_urlNavigator->saveLocationState(locationState);
690 }
691
692 void DolphinViewContainer::tryRestoreViewState()
693 {
694 QByteArray locationState = m_urlNavigator->locationState();
695 if (!locationState.isEmpty()) {
696 QDataStream stream(&locationState, QIODevice::ReadOnly);
697 m_view->restoreState(stream);
698 }
699 }