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