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