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