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