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