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