]> 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(slotUrlChanged()));
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 const KUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
486 if (!url.isEmpty()) {
487 m_view->setUrl(url);
488 return;
489 }
490
491 item.run();
492 }
493
494 void DolphinViewContainer::slotItemsActivated(const KFileItemList& items)
495 {
496 Q_ASSERT(items.count() >= 2);
497
498 KFileItemActions fileItemActions(this);
499 fileItemActions.runPreferredApplications(items, QString());
500 }
501
502 void DolphinViewContainer::showItemInfo(const KFileItem& item)
503 {
504 if (item.isNull()) {
505 m_statusBar->resetToDefaultText();
506 } else {
507 const QString text = item.isDir() ? item.text() : item.getStatusBarInfo();
508 m_statusBar->setText(text);
509 }
510 }
511
512 void DolphinViewContainer::closeFilterBar()
513 {
514 m_filterBar->closeFilterBar();
515 m_view->setFocus();
516 emit showFilterBarChanged(false);
517 }
518
519 void DolphinViewContainer::setNameFilter(const QString& nameFilter)
520 {
521 m_view->setNameFilter(nameFilter);
522 delayedStatusBarUpdate();
523 }
524
525 void DolphinViewContainer::activate()
526 {
527 setActive(true);
528 }
529
530 void DolphinViewContainer::slotViewUrlAboutToBeChanged(const KUrl& url)
531 {
532 // URL changes of the view can happen in two ways:
533 // 1. The URL navigator gets changed and will trigger the view to update its URL
534 // 2. The URL of the view gets changed and will trigger the URL navigator to update
535 // its URL (e.g. by clicking on an item)
536 // In this scope the view-state may only get saved in case 2:
537 if (url != m_urlNavigator->locationUrl()) {
538 saveViewState();
539 }
540 }
541
542 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const KUrl& url)
543 {
544 // URL changes of the view can happen in two ways:
545 // 1. The URL navigator gets changed and will trigger the view to update its URL
546 // 2. The URL of the view gets changed and will trigger the URL navigator to update
547 // its URL (e.g. by clicking on an item)
548 // In this scope the view-state may only get saved in case 1:
549 if (url != m_view->url()) {
550 saveViewState();
551 }
552 }
553
554 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
555 {
556 slotReturnPressed();
557
558 if (KProtocolManager::supportsListing(url)) {
559 setSearchModeEnabled(isSearchUrl(url));
560 m_view->setUrl(url);
561
562 if (m_autoGrabFocus && isActive() && !isSearchUrl(url)) {
563 // When an URL has been entered, the view should get the focus.
564 // The focus must be requested asynchronously, as changing the URL might create
565 // a new view widget.
566 QTimer::singleShot(0, this, SLOT(requestFocus()));
567 }
568 } else if (KProtocolManager::isSourceProtocol(url)) {
569 QString app = "konqueror";
570 if (url.protocol().startsWith(QLatin1String("http"))) {
571 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
572 "Dolphin does not support web pages, the web browser has been launched"),
573 Information);
574
575 const KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
576 const QString browser = config.readEntry("BrowserApplication");
577 if (!browser.isEmpty()) {
578 app = browser;
579 if (app.startsWith('!')) {
580 // a literal command has been configured, remove the '!' prefix
581 app = app.mid(1);
582 }
583 }
584 } else {
585 showMessage(i18nc("@info:status",
586 "Protocol not supported by Dolphin, Konqueror has been launched"),
587 Information);
588 }
589
590 const QString secureUrl = KShell::quoteArg(url.pathOrUrl());
591 const QString command = app + ' ' + secureUrl;
592 KRun::runCommand(command, app, app, this);
593 } else {
594 showMessage(i18nc("@info:status", "Invalid protocol"), Error);
595 }
596 }
597
598 void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
599 {
600 QString error;
601 DragAndDropHelper::dropUrls(KFileItem(), destination, event, error);
602 if (!error.isEmpty()) {
603 showMessage(error, Error);
604 }
605 }
606
607 void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
608 {
609 Q_UNUSED(oldUrl);
610 const bool block = m_urlNavigator->signalsBlocked();
611 m_urlNavigator->blockSignals(true);
612
613 // Assure that the location state is reset for redirection URLs. This
614 // allows to skip redirection URLs when going back or forward in the
615 // URL history.
616 m_urlNavigator->saveLocationState(QByteArray());
617 m_urlNavigator->setLocationUrl(newUrl);
618 setSearchModeEnabled(isSearchUrl(newUrl));
619
620 m_urlNavigator->blockSignals(block);
621 }
622
623 void DolphinViewContainer::requestFocus()
624 {
625 m_view->setFocus();
626 }
627
628 void DolphinViewContainer::saveUrlCompletionMode(KGlobalSettings::Completion completion)
629 {
630 GeneralSettings::setUrlCompletionMode(completion);
631 }
632
633 void DolphinViewContainer::slotHistoryChanged()
634 {
635 QByteArray locationState = m_urlNavigator->locationState();
636 if (!locationState.isEmpty()) {
637 QDataStream stream(&locationState, QIODevice::ReadOnly);
638 m_view->restoreState(stream);
639 }
640 }
641
642 void DolphinViewContainer::slotReturnPressed()
643 {
644 if (!GeneralSettings::editableUrl()) {
645 m_urlNavigator->setUrlEditable(false);
646 }
647 }
648
649 void DolphinViewContainer::startSearching()
650 {
651 const KUrl url = m_searchBox->urlForSearching();
652 if (url.isValid() && !url.isEmpty()) {
653 m_view->setViewPropertiesContext("search");
654 m_urlNavigator->setLocationUrl(url);
655 }
656 }
657
658 void DolphinViewContainer::closeSearchBox()
659 {
660 setSearchModeEnabled(false);
661 }
662
663 void DolphinViewContainer::stopDirectoryLoading()
664 {
665 m_view->stopLoading();
666 m_statusBar->setProgress(100);
667 }
668
669 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)
670 {
671 m_view->setZoomLevel(zoomLevel);
672 }
673
674 void DolphinViewContainer::showErrorMessage(const QString& msg)
675 {
676 showMessage(msg, Error);
677 }
678
679 bool DolphinViewContainer::isSearchUrl(const KUrl& url) const
680 {
681 const QString protocol = url.protocol();
682 return protocol.contains("search") || (protocol == QLatin1String("nepomuk"));
683 }
684
685 void DolphinViewContainer::saveViewState()
686 {
687 QByteArray locationState;
688 QDataStream stream(&locationState, QIODevice::WriteOnly);
689 m_view->saveState(stream);
690 m_urlNavigator->saveLocationState(locationState);
691 }
692
693 #include "dolphinviewcontainer.moc"