]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.cpp
Change window title when searching
[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 QString DolphinViewContainer::currentSearchText() const
249 {
250 return m_searchBox->text();
251 }
252
253 const DolphinStatusBar* DolphinViewContainer::statusBar() const
254 {
255 return m_statusBar;
256 }
257
258 DolphinStatusBar* DolphinViewContainer::statusBar()
259 {
260 return m_statusBar;
261 }
262
263 const KUrlNavigator* DolphinViewContainer::urlNavigator() const
264 {
265 return m_urlNavigator;
266 }
267
268 KUrlNavigator* DolphinViewContainer::urlNavigator()
269 {
270 return m_urlNavigator;
271 }
272
273 const DolphinView* DolphinViewContainer::view() const
274 {
275 return m_view;
276 }
277
278 DolphinView* DolphinViewContainer::view()
279 {
280 return m_view;
281 }
282
283 void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
284 {
285 if (msg.isEmpty()) {
286 return;
287 }
288
289 m_messageWidget->setText(msg);
290
291 switch (type) {
292 case Information: m_messageWidget->setMessageType(KMessageWidget::Information); break;
293 case Warning: m_messageWidget->setMessageType(KMessageWidget::Warning); break;
294 case Error: m_messageWidget->setMessageType(KMessageWidget::Error); break;
295 default:
296 Q_ASSERT(false);
297 break;
298 }
299
300 m_messageWidget->setWordWrap(false);
301 const int unwrappedWidth = m_messageWidget->sizeHint().width();
302 m_messageWidget->setWordWrap(unwrappedWidth > size().width());
303
304 if (m_messageWidget->isVisible()) {
305 m_messageWidget->hide();
306 }
307 m_messageWidget->animatedShow();
308 }
309
310 void DolphinViewContainer::readSettings()
311 {
312 if (GeneralSettings::modifiedStartupSettings()) {
313 // The startup settings should only get applied if they have been
314 // modified by the user. Otherwise keep the (possibly) different current
315 // settings of the URL navigator and the filterbar.
316 m_urlNavigator->setUrlEditable(GeneralSettings::editableUrl());
317 m_urlNavigator->setShowFullPath(GeneralSettings::showFullPath());
318 m_urlNavigator->setHomeUrl(Dolphin::homeUrl());
319 setFilterBarVisible(GeneralSettings::filterBar());
320 }
321
322 m_view->readSettings();
323 m_statusBar->readSettings();
324 }
325
326 bool DolphinViewContainer::isFilterBarVisible() const
327 {
328 return m_filterBar->isVisible();
329 }
330
331 void DolphinViewContainer::setSearchModeEnabled(bool enabled)
332 {
333 if (enabled == isSearchModeEnabled()) {
334 if (enabled && !m_searchBox->hasFocus()) {
335 m_searchBox->setFocus();
336 m_searchBox->selectAll();
337 }
338 return;
339 }
340
341 m_searchBox->setVisible(enabled);
342 m_urlNavigator->setVisible(!enabled);
343
344 if (enabled) {
345 const QUrl& locationUrl = m_urlNavigator->locationUrl();
346 m_searchBox->fromSearchUrl(locationUrl);
347 } else {
348 m_view->setViewPropertiesContext(QString());
349
350 // Restore the URL for the URL navigator. If Dolphin has been
351 // started with a search-URL, the home URL is used as fallback.
352 QUrl url = m_searchBox->searchPath();
353 if (url.isEmpty() || !url.isValid() || isSearchUrl(url)) {
354 url = Dolphin::homeUrl();
355 }
356 m_urlNavigator->setLocationUrl(url);
357 }
358 }
359
360 bool DolphinViewContainer::isSearchModeEnabled() const
361 {
362 return m_searchBox->isVisible();
363 }
364
365 QString DolphinViewContainer::placesText() const
366 {
367 QString text;
368
369 if (isSearchModeEnabled()) {
370 text = i18n("Search for %1 in %2", m_searchBox->text(), m_searchBox->searchPath().fileName());
371 } else {
372 text = url().fileName();
373 if (text.isEmpty()) {
374 text = url().host();
375 }
376 if (text.isEmpty()) {
377 text = url().scheme();
378 }
379 }
380
381 return text;
382 }
383
384 void DolphinViewContainer::reload()
385 {
386 view()->reload();
387 m_messageWidget->hide();
388 }
389
390 void DolphinViewContainer::setUrl(const QUrl& newUrl)
391 {
392 if (newUrl != m_urlNavigator->locationUrl()) {
393 m_urlNavigator->setLocationUrl(newUrl);
394 }
395
396 #ifdef KActivities_FOUND
397 m_activityResourceInstance->setUri(newUrl);
398 #endif
399 }
400
401 void DolphinViewContainer::setFilterBarVisible(bool visible)
402 {
403 Q_ASSERT(m_filterBar);
404 if (visible) {
405 m_filterBar->show();
406 m_filterBar->setFocus();
407 m_filterBar->selectAll();
408 } else {
409 closeFilterBar();
410 }
411 }
412
413 void DolphinViewContainer::delayedStatusBarUpdate()
414 {
415 if (m_statusBarTimer->isActive() && (m_statusBarTimestamp.elapsed() > 2000)) {
416 // No update of the statusbar has been done during the last 2 seconds,
417 // although an update has been requested. Trigger an immediate update.
418 m_statusBarTimer->stop();
419 updateStatusBar();
420 } else {
421 // Invoke updateStatusBar() with a small delay. This assures that
422 // when a lot of delayedStatusBarUpdates() are done in a short time,
423 // no bottleneck is given.
424 m_statusBarTimer->start();
425 }
426 }
427
428 void DolphinViewContainer::updateStatusBar()
429 {
430 m_statusBarTimestamp.start();
431
432 const QString text = m_view->statusBarText();
433 m_statusBar->setDefaultText(text);
434 m_statusBar->resetToDefaultText();
435 }
436
437 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent)
438 {
439 if (m_statusBar->progressText().isEmpty()) {
440 m_statusBar->setProgressText(i18nc("@info:progress", "Loading folder..."));
441 }
442 m_statusBar->setProgress(percent);
443 }
444
445 void DolphinViewContainer::updateDirectorySortingProgress(int percent)
446 {
447 if (m_statusBar->progressText().isEmpty()) {
448 m_statusBar->setProgressText(i18nc("@info:progress", "Sorting..."));
449 }
450 m_statusBar->setProgress(percent);
451 }
452
453 void DolphinViewContainer::slotDirectoryLoadingStarted()
454 {
455 if (isSearchUrl(url())) {
456 // Search KIO-slaves usually don't provide any progress information. Give
457 // a hint to the user that a searching is done:
458 updateStatusBar();
459 m_statusBar->setProgressText(i18nc("@info", "Searching..."));
460 m_statusBar->setProgress(-1);
461 } else {
462 // Trigger an undetermined progress indication. The progress
463 // information in percent will be triggered by the percent() signal
464 // of the directory lister later.
465 updateDirectoryLoadingProgress(-1);
466 }
467 }
468
469 void DolphinViewContainer::slotDirectoryLoadingCompleted()
470 {
471 if (!m_statusBar->progressText().isEmpty()) {
472 m_statusBar->setProgressText(QString());
473 m_statusBar->setProgress(100);
474 }
475
476 if (isSearchUrl(url()) && m_view->itemsCount() == 0) {
477 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
478 // of showing the default status bar information ("0 items") a more helpful information is given:
479 m_statusBar->setText(i18nc("@info:status", "No items found."));
480 } else {
481 updateStatusBar();
482 }
483 }
484
485 void DolphinViewContainer::slotDirectoryLoadingCanceled()
486 {
487 if (!m_statusBar->progressText().isEmpty()) {
488 m_statusBar->setProgressText(QString());
489 m_statusBar->setProgress(100);
490 }
491
492 m_statusBar->setText(QString());
493 }
494
495 void DolphinViewContainer::slotUrlIsFileError(const QUrl& url)
496 {
497 const KFileItem item(url);
498
499 // Find out if the file can be opened in the view (for example, this is the
500 // case if the file is an archive). The mime type must be known for that.
501 item.determineMimeType();
502 const QUrl& folderUrl = DolphinView::openItemAsFolderUrl(item, true);
503 if (!folderUrl.isEmpty()) {
504 setUrl(folderUrl);
505 } else {
506 slotItemActivated(item);
507 }
508 }
509
510 void DolphinViewContainer::slotItemActivated(const KFileItem& item)
511 {
512 // It is possible to activate items on inactive views by
513 // drag & drop operations. Assure that activating an item always
514 // results in an active view.
515 m_view->setActive(true);
516
517 const QUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
518 if (!url.isEmpty()) {
519 setUrl(url);
520 return;
521 }
522
523 KRun *run = new KRun(item.targetUrl(), this);
524 run->setShowScriptExecutionPrompt(true);
525 }
526
527 void DolphinViewContainer::slotItemsActivated(const KFileItemList& items)
528 {
529 Q_ASSERT(items.count() >= 2);
530
531 KFileItemActions fileItemActions(this);
532 fileItemActions.runPreferredApplications(items, QString());
533 }
534
535 void DolphinViewContainer::showItemInfo(const KFileItem& item)
536 {
537 if (item.isNull()) {
538 m_statusBar->resetToDefaultText();
539 } else {
540 m_statusBar->setText(item.getStatusBarInfo());
541 }
542 }
543
544 void DolphinViewContainer::closeFilterBar()
545 {
546 m_filterBar->closeFilterBar();
547 m_view->setFocus();
548 emit showFilterBarChanged(false);
549 }
550
551 void DolphinViewContainer::setNameFilter(const QString& nameFilter)
552 {
553 m_view->setNameFilter(nameFilter);
554 delayedStatusBarUpdate();
555 }
556
557 void DolphinViewContainer::activate()
558 {
559 setActive(true);
560 }
561
562 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl&)
563 {
564 saveViewState();
565 }
566
567 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url)
568 {
569 slotReturnPressed();
570
571 if (KProtocolManager::supportsListing(url)) {
572 setSearchModeEnabled(isSearchUrl(url));
573 m_view->setUrl(url);
574 tryRestoreViewState();
575
576 if (m_autoGrabFocus && isActive() && !isSearchUrl(url)) {
577 // When an URL has been entered, the view should get the focus.
578 // The focus must be requested asynchronously, as changing the URL might create
579 // a new view widget.
580 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus);
581 }
582 } else if (KProtocolManager::isSourceProtocol(url)) {
583 QString app = QStringLiteral("konqueror");
584 if (url.scheme().startsWith(QLatin1String("http"))) {
585 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
586 "Dolphin does not support web pages, the web browser has been launched"),
587 Information);
588
589 const KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "General");
590 const QString browser = config.readEntry("BrowserApplication");
591 if (!browser.isEmpty()) {
592 app = browser;
593 if (app.startsWith('!')) {
594 // a literal command has been configured, remove the '!' prefix
595 app = app.mid(1);
596 }
597 }
598 } else {
599 showMessage(i18nc("@info:status",
600 "Protocol not supported by Dolphin, Konqueror has been launched"),
601 Information);
602 }
603
604 const QString secureUrl = KShell::quoteArg(url.toDisplayString(QUrl::PreferLocalFile));
605 const QString command = app + ' ' + secureUrl;
606 KRun::runCommand(command, app, app, this);
607 } else {
608 showMessage(i18nc("@info:status", "Invalid protocol"), Error);
609 }
610 }
611
612 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl& url)
613 {
614 qCDebug(DolphinDebug) << "slotUrlSelectionRequested: " << url;
615 m_view->markUrlsAsSelected({url});
616 m_view->markUrlAsCurrent(url); // makes the item scroll into view
617 }
618
619 void DolphinViewContainer::redirect(const QUrl& oldUrl, const QUrl& newUrl)
620 {
621 Q_UNUSED(oldUrl);
622 const bool block = m_urlNavigator->signalsBlocked();
623 m_urlNavigator->blockSignals(true);
624
625 // Assure that the location state is reset for redirection URLs. This
626 // allows to skip redirection URLs when going back or forward in the
627 // URL history.
628 m_urlNavigator->saveLocationState(QByteArray());
629 m_urlNavigator->setLocationUrl(newUrl);
630 setSearchModeEnabled(isSearchUrl(newUrl));
631
632 m_urlNavigator->blockSignals(block);
633 }
634
635 void DolphinViewContainer::requestFocus()
636 {
637 m_view->setFocus();
638 }
639
640 void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode completion)
641 {
642 GeneralSettings::setUrlCompletionMode(completion);
643 }
644
645 void DolphinViewContainer::slotReturnPressed()
646 {
647 if (!GeneralSettings::editableUrl()) {
648 m_urlNavigator->setUrlEditable(false);
649 }
650 }
651
652 void DolphinViewContainer::startSearching()
653 {
654 const QUrl url = m_searchBox->urlForSearching();
655 if (url.isValid() && !url.isEmpty()) {
656 m_view->setViewPropertiesContext(QStringLiteral("search"));
657 m_urlNavigator->setLocationUrl(url);
658 }
659 }
660
661 void DolphinViewContainer::closeSearchBox()
662 {
663 setSearchModeEnabled(false);
664 }
665
666 void DolphinViewContainer::stopDirectoryLoading()
667 {
668 m_view->stopLoading();
669 m_statusBar->setProgress(100);
670 }
671
672 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)
673 {
674 m_view->setZoomLevel(zoomLevel);
675 }
676
677 void DolphinViewContainer::showErrorMessage(const QString& msg)
678 {
679 showMessage(msg, Error);
680 }
681
682 bool DolphinViewContainer::isSearchUrl(const QUrl& url) const
683 {
684 return url.scheme().contains(QStringLiteral("search"));
685 }
686
687 void DolphinViewContainer::saveViewState()
688 {
689 QByteArray locationState;
690 QDataStream stream(&locationState, QIODevice::WriteOnly);
691 m_view->saveState(stream);
692 m_urlNavigator->saveLocationState(locationState);
693 }
694
695 void DolphinViewContainer::tryRestoreViewState()
696 {
697 QByteArray locationState = m_urlNavigator->locationState();
698 if (!locationState.isEmpty()) {
699 QDataStream stream(&locationState, QIODevice::ReadOnly);
700 m_view->restoreState(stream);
701 }
702 }