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