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