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