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