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