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