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