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