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