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