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