]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.cpp
port Dolphin from KUrl to QUrl
[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 <QTimer>
24 #include <QMimeData>
25 #include <QVBoxLayout>
26
27 #include <KFileItemActions>
28 #include <KFilePlacesModel>
29 #include <KLocalizedString>
30 #include <KIO/NetAccess>
31 #include <KIO/PreviewJob>
32 #include <KMessageWidget>
33 #include <konq_operations.h>
34 #include <KShell>
35 #include <QUrl>
36 #include <KUrlComboBox>
37 #include <KUrlNavigator>
38 #include <KRun>
39
40 #ifdef KActivities_FOUND
41 #endif
42
43 #include "dolphin_generalsettings.h"
44 #include "filterbar/filterbar.h"
45 #include "search/dolphinsearchbox.h"
46 #include "statusbar/dolphinstatusbar.h"
47 #include "views/draganddrophelper.h"
48 #include "views/viewmodecontroller.h"
49 #include "views/viewproperties.h"
50
51 DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
52 QWidget(parent),
53 m_topLayout(0),
54 m_urlNavigator(0),
55 m_searchBox(0),
56 m_messageWidget(0),
57 m_view(0),
58 m_filterBar(0),
59 m_statusBar(0),
60 m_statusBarTimer(0),
61 m_statusBarTimestamp(),
62 m_autoGrabFocus(true),
63 m_dropDestination(),
64 m_dropEvent(0)
65 #ifdef KActivities_FOUND
66 , m_activityResourceInstance(0)
67 #endif
68 {
69 hide();
70
71 m_topLayout = new QVBoxLayout(this);
72 m_topLayout->setSpacing(0);
73 m_topLayout->setMargin(0);
74
75 m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this);
76 connect(m_urlNavigator, &KUrlNavigator::urlsDropped,
77 this, &DolphinViewContainer::dropUrls);
78 connect(m_urlNavigator, &KUrlNavigator::activated,
79 this, &DolphinViewContainer::activate);
80 connect(m_urlNavigator->editor(), &KUrlComboBox::completionModeChanged,
81 this, &DolphinViewContainer::saveUrlCompletionMode);
82
83 const GeneralSettings* settings = GeneralSettings::self();
84 m_urlNavigator->setUrlEditable(settings->editableUrl());
85 m_urlNavigator->setShowFullPath(settings->showFullPath());
86 m_urlNavigator->setHomeUrl(QUrl::fromLocalFile(settings->homeUrl()));
87 KUrlComboBox* editor = m_urlNavigator->editor();
88 editor->setCompletionMode(KCompletion::CompletionMode(settings->urlCompletionMode()));
89
90 m_searchBox = new DolphinSearchBox(this);
91 m_searchBox->hide();
92 connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate);
93 connect(m_searchBox, &DolphinSearchBox::closeRequest, this, &DolphinViewContainer::closeSearchBox);
94 connect(m_searchBox, &DolphinSearchBox::searchRequest, this, &DolphinViewContainer::startSearching);
95 connect(m_searchBox, &DolphinSearchBox::returnPressed, this, &DolphinViewContainer::requestFocus);
96
97 m_messageWidget = new KMessageWidget(this);
98 m_messageWidget->setCloseButtonVisible(true);
99 m_messageWidget->hide();
100
101 m_view = new DolphinView(url, this);
102 connect(m_view, &DolphinView::urlChanged,
103 m_urlNavigator, &KUrlNavigator::setUrl);
104 connect(m_view, &DolphinView::urlChanged,
105 m_messageWidget, &KMessageWidget::hide);
106 connect(m_view, &DolphinView::directoryLoadingCompleted,
107 m_messageWidget, &KMessageWidget::hide);
108 connect(m_view, &DolphinView::writeStateChanged,
109 this, &DolphinViewContainer::writeStateChanged);
110 connect(m_view, &DolphinView::requestItemInfo,
111 this, &DolphinViewContainer::showItemInfo);
112 connect(m_view, &DolphinView::itemActivated,
113 this, &DolphinViewContainer::slotItemActivated);
114 connect(m_view, &DolphinView::itemsActivated,
115 this, &DolphinViewContainer::slotItemsActivated);
116 connect(m_view, &DolphinView::redirection,
117 this, &DolphinViewContainer::redirect);
118 connect(m_view, &DolphinView::directoryLoadingStarted,
119 this, &DolphinViewContainer::slotDirectoryLoadingStarted);
120 connect(m_view, &DolphinView::directoryLoadingCompleted,
121 this, &DolphinViewContainer::slotDirectoryLoadingCompleted);
122 connect(m_view, &DolphinView::directoryLoadingCanceled,
123 this, &DolphinViewContainer::slotDirectoryLoadingCanceled);
124 connect(m_view, &DolphinView::itemCountChanged,
125 this, &DolphinViewContainer::delayedStatusBarUpdate);
126 connect(m_view, &DolphinView::directoryLoadingProgress,
127 this, &DolphinViewContainer::updateDirectoryLoadingProgress);
128 connect(m_view, &DolphinView::directorySortingProgress,
129 this, &DolphinViewContainer::updateDirectorySortingProgress);
130 connect(m_view, &DolphinView::selectionChanged,
131 this, &DolphinViewContainer::delayedStatusBarUpdate);
132 connect(m_view, &DolphinView::urlAboutToBeChanged,
133 this, &DolphinViewContainer::slotViewUrlAboutToBeChanged);
134 connect(m_view, &DolphinView::errorMessage,
135 this, &DolphinViewContainer::showErrorMessage);
136 connect(m_view, &DolphinView::urlIsFileError,
137 this, &DolphinViewContainer::slotUrlIsFileError);
138 connect(m_view, &DolphinView::activated,
139 this, &DolphinViewContainer::activate);
140
141 connect(m_urlNavigator, &KUrlNavigator::urlAboutToBeChanged,
142 this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
143 connect(m_urlNavigator, &KUrlNavigator::urlChanged,
144 this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
145 connect(m_urlNavigator, &KUrlNavigator::historyChanged,
146 this, &DolphinViewContainer::slotHistoryChanged);
147 connect(m_urlNavigator, &KUrlNavigator::returnPressed,
148 this, &DolphinViewContainer::slotReturnPressed);
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 const DolphinStatusBar* DolphinViewContainer::statusBar() const
247 {
248 return m_statusBar;
249 }
250
251 DolphinStatusBar* DolphinViewContainer::statusBar()
252 {
253 return m_statusBar;
254 }
255
256 const KUrlNavigator* DolphinViewContainer::urlNavigator() const
257 {
258 return m_urlNavigator;
259 }
260
261 KUrlNavigator* DolphinViewContainer::urlNavigator()
262 {
263 return m_urlNavigator;
264 }
265
266 const DolphinView* DolphinViewContainer::view() const
267 {
268 return m_view;
269 }
270
271 DolphinView* DolphinViewContainer::view()
272 {
273 return m_view;
274 }
275
276 void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
277 {
278 if (msg.isEmpty()) {
279 return;
280 }
281
282 m_messageWidget->setText(msg);
283
284 switch (type) {
285 case Information: m_messageWidget->setMessageType(KMessageWidget::Information); break;
286 case Warning: m_messageWidget->setMessageType(KMessageWidget::Warning); break;
287 case Error: m_messageWidget->setMessageType(KMessageWidget::Error); break;
288 default:
289 Q_ASSERT(false);
290 break;
291 }
292
293 m_messageWidget->setWordWrap(false);
294 const int unwrappedWidth = m_messageWidget->sizeHint().width();
295 m_messageWidget->setWordWrap(unwrappedWidth > size().width());
296
297 if (m_messageWidget->isVisible()) {
298 m_messageWidget->hide();
299 }
300 m_messageWidget->animatedShow();
301 }
302
303 void DolphinViewContainer::readSettings()
304 {
305 if (GeneralSettings::modifiedStartupSettings()) {
306 // The startup settings should only get applied if they have been
307 // modified by the user. Otherwise keep the (possibly) different current
308 // settings of the URL navigator and the filterbar.
309 m_urlNavigator->setUrlEditable(GeneralSettings::editableUrl());
310 m_urlNavigator->setShowFullPath(GeneralSettings::showFullPath());
311 m_urlNavigator->setHomeUrl(QUrl::fromLocalFile(GeneralSettings::homeUrl()));
312 setFilterBarVisible(GeneralSettings::filterBar());
313 }
314
315 m_view->readSettings();
316 m_statusBar->readSettings();
317 }
318
319 bool DolphinViewContainer::isFilterBarVisible() const
320 {
321 return m_filterBar->isVisible();
322 }
323
324 void DolphinViewContainer::setSearchModeEnabled(bool enabled)
325 {
326 if (enabled == isSearchModeEnabled()) {
327 if (enabled && !m_searchBox->hasFocus()) {
328 m_searchBox->setFocus();
329 m_searchBox->selectAll();
330 }
331 return;
332 }
333
334 m_searchBox->setVisible(enabled);
335 m_urlNavigator->setVisible(!enabled);
336
337 if (enabled) {
338 const QUrl& locationUrl = m_urlNavigator->locationUrl();
339 m_searchBox->fromSearchUrl(locationUrl);
340 } else {
341 m_view->setViewPropertiesContext(QString());
342
343 // Restore the URL for the URL navigator. If Dolphin has been
344 // started with a search-URL, the home URL is used as fallback.
345 QUrl url = m_searchBox->searchPath();
346 if (url.isEmpty() || !url.isValid() || isSearchUrl(url)) {
347 url = QUrl::fromLocalFile(GeneralSettings::self()->homeUrl());
348 }
349 m_urlNavigator->setLocationUrl(url);
350 }
351 }
352
353 bool DolphinViewContainer::isSearchModeEnabled() const
354 {
355 return m_searchBox->isVisible();
356 }
357
358 QString DolphinViewContainer::placesText() const
359 {
360 QString text;
361
362 if (isSearchModeEnabled()) {
363 text = m_searchBox->searchPath().fileName() + QLatin1String(": ") + m_searchBox->text();
364 } else {
365 text = url().fileName();
366 if (text.isEmpty()) {
367 text = url().host();
368 }
369 }
370
371 return text;
372 }
373
374 void DolphinViewContainer::setUrl(const QUrl& newUrl)
375 {
376 if (newUrl != m_urlNavigator->locationUrl()) {
377 m_urlNavigator->setLocationUrl(newUrl);
378 }
379
380 #ifdef KActivities_FOUND
381 m_activityResourceInstance->setUri(newUrl);
382 #endif
383 }
384
385 void DolphinViewContainer::setFilterBarVisible(bool visible)
386 {
387 Q_ASSERT(m_filterBar);
388 if (visible) {
389 m_filterBar->show();
390 m_filterBar->setFocus();
391 m_filterBar->selectAll();
392 } else {
393 closeFilterBar();
394 }
395 }
396
397 void DolphinViewContainer::delayedStatusBarUpdate()
398 {
399 if (m_statusBarTimer->isActive() && (m_statusBarTimestamp.elapsed() > 2000)) {
400 // No update of the statusbar has been done during the last 2 seconds,
401 // although an update has been requested. Trigger an immediate update.
402 m_statusBarTimer->stop();
403 updateStatusBar();
404 } else {
405 // Invoke updateStatusBar() with a small delay. This assures that
406 // when a lot of delayedStatusBarUpdates() are done in a short time,
407 // no bottleneck is given.
408 m_statusBarTimer->start();
409 }
410 }
411
412 void DolphinViewContainer::updateStatusBar()
413 {
414 m_statusBarTimestamp.start();
415
416 const QString text = m_view->statusBarText();
417 m_statusBar->setDefaultText(text);
418 m_statusBar->resetToDefaultText();
419 }
420
421 void DolphinViewContainer::updateDirectoryLoadingProgress(int percent)
422 {
423 if (m_statusBar->progressText().isEmpty()) {
424 m_statusBar->setProgressText(i18nc("@info:progress", "Loading folder..."));
425 }
426 m_statusBar->setProgress(percent);
427 }
428
429 void DolphinViewContainer::updateDirectorySortingProgress(int percent)
430 {
431 if (m_statusBar->progressText().isEmpty()) {
432 m_statusBar->setProgressText(i18nc("@info:progress", "Sorting..."));
433 }
434 m_statusBar->setProgress(percent);
435 }
436
437 void DolphinViewContainer::slotDirectoryLoadingStarted()
438 {
439 if (isSearchUrl(url())) {
440 // Search KIO-slaves usually don't provide any progress information. Give
441 // a hint to the user that a searching is done:
442 updateStatusBar();
443 m_statusBar->setProgressText(i18nc("@info", "Searching..."));
444 m_statusBar->setProgress(-1);
445 } else {
446 // Trigger an undetermined progress indication. The progress
447 // information in percent will be triggered by the percent() signal
448 // of the directory lister later.
449 updateDirectoryLoadingProgress(-1);
450 }
451 }
452
453 void DolphinViewContainer::slotDirectoryLoadingCompleted()
454 {
455 if (!m_statusBar->progressText().isEmpty()) {
456 m_statusBar->setProgressText(QString());
457 m_statusBar->setProgress(100);
458 }
459
460 if (isSearchUrl(url()) && m_view->itemsCount() == 0) {
461 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
462 // of showing the default status bar information ("0 items") a more helpful information is given:
463 m_statusBar->setText(i18nc("@info:status", "No items found."));
464 } else {
465 updateStatusBar();
466 }
467 }
468
469 void DolphinViewContainer::slotDirectoryLoadingCanceled()
470 {
471 if (!m_statusBar->progressText().isEmpty()) {
472 m_statusBar->setProgressText(QString());
473 m_statusBar->setProgress(100);
474 }
475
476 m_statusBar->setText(QString());
477 }
478
479 void DolphinViewContainer::slotUrlIsFileError(const QUrl& url)
480 {
481 const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
482
483 // Find out if the file can be opened in the view (for example, this is the
484 // case if the file is an archive). The mime type must be known for that.
485 item.determineMimeType();
486 const QUrl& folderUrl = DolphinView::openItemAsFolderUrl(item, true);
487 if (!folderUrl.isEmpty()) {
488 m_view->setUrl(folderUrl);
489 } else {
490 slotItemActivated(item);
491 }
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 QUrl& 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 QUrl& 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 QUrl& 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 QUrl& 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.scheme().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.toDisplayString(QUrl::PreferLocalFile));
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 QUrl& 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 QUrl& oldUrl, const QUrl& 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 QUrl 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 QUrl& url) const
721 {
722 return url.scheme().contains("search");
723 }
724
725 void DolphinViewContainer::saveViewState()
726 {
727 QByteArray locationState;
728 QDataStream stream(&locationState, QIODevice::WriteOnly);
729 m_view->saveState(stream);
730 m_urlNavigator->saveLocationState(locationState);
731 }