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