From 41b0e4297313b6549f9178c77c30101a42b0525f Mon Sep 17 00:00:00 2001 From: Emmanuel Pescosta Date: Sat, 18 Feb 2017 20:34:02 +0100 Subject: [PATCH] Restore the view state after the URL of the DolphinView has been changed, as stated in the documentation of KUrlNavigator::saveLocationState. The historyChanged signal of the KUrlNavigator is emitted before the urlChanged signal and so the view state restoring happens before the view URL has been changed. This makes it impossible to save and restore the selected URLs, because DolphinView::setUrl clears the list of selected items (which has been restored right before). This changes removes the history changed slot and restores the view state after the setUrl call. --- src/dolphinviewcontainer.cpp | 50 ++++++++++-------------------------- src/dolphinviewcontainer.h | 14 +++++----- src/views/dolphinview.cpp | 1 - src/views/dolphinview.h | 7 ----- 4 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 2ea5b7e00e..72ced931b7 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -122,8 +122,6 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : this, &DolphinViewContainer::updateDirectorySortingProgress); connect(m_view, &DolphinView::selectionChanged, this, &DolphinViewContainer::delayedStatusBarUpdate); - connect(m_view, &DolphinView::urlAboutToBeChanged, - this, &DolphinViewContainer::slotViewUrlAboutToBeChanged); connect(m_view, &DolphinView::errorMessage, this, &DolphinViewContainer::showErrorMessage); connect(m_view, &DolphinView::urlIsFileError, @@ -135,8 +133,6 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged); connect(m_urlNavigator, &KUrlNavigator::urlChanged, this, &DolphinViewContainer::slotUrlNavigatorLocationChanged); - connect(m_urlNavigator, &KUrlNavigator::historyChanged, - this, &DolphinViewContainer::slotHistoryChanged); connect(m_urlNavigator, &KUrlNavigator::returnPressed, this, &DolphinViewContainer::slotReturnPressed); connect(m_urlNavigator, &KUrlNavigator::urlsDropped, @@ -489,7 +485,7 @@ void DolphinViewContainer::slotUrlIsFileError(const QUrl& url) item.determineMimeType(); const QUrl& folderUrl = DolphinView::openItemAsFolderUrl(item, true); if (!folderUrl.isEmpty()) { - m_view->setUrl(folderUrl); + setUrl(folderUrl); } else { slotItemActivated(item); } @@ -504,7 +500,7 @@ void DolphinViewContainer::slotItemActivated(const KFileItem& item) const QUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives()); if (!url.isEmpty()) { - m_view->setUrl(url); + setUrl(url); return; } @@ -547,28 +543,9 @@ void DolphinViewContainer::activate() setActive(true); } -void DolphinViewContainer::slotViewUrlAboutToBeChanged(const QUrl& url) +void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl&) { - // URL changes of the view can happen in two ways: - // 1. The URL navigator gets changed and will trigger the view to update its URL - // 2. The URL of the view gets changed and will trigger the URL navigator to update - // its URL (e.g. by clicking on an item) - // In this scope the view-state may only get saved in case 2: - if (url != m_urlNavigator->locationUrl()) { - saveViewState(); - } -} - -void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl& url) -{ - // URL changes of the view can happen in two ways: - // 1. The URL navigator gets changed and will trigger the view to update its URL - // 2. The URL of the view gets changed and will trigger the URL navigator to update - // its URL (e.g. by clicking on an item) - // In this scope the view-state may only get saved in case 1: - if (url != m_view->url()) { - saveViewState(); - } + saveViewState(); } void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url) @@ -578,6 +555,7 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url) if (KProtocolManager::supportsListing(url)) { setSearchModeEnabled(isSearchUrl(url)); m_view->setUrl(url); + tryRestoreViewState(); if (m_autoGrabFocus && isActive() && !isSearchUrl(url)) { // When an URL has been entered, the view should get the focus. @@ -641,15 +619,6 @@ void DolphinViewContainer::saveUrlCompletionMode(KCompletion::CompletionMode com GeneralSettings::setUrlCompletionMode(completion); } -void DolphinViewContainer::slotHistoryChanged() -{ - QByteArray locationState = m_urlNavigator->locationState(); - if (!locationState.isEmpty()) { - QDataStream stream(&locationState, QIODevice::ReadOnly); - m_view->restoreState(stream); - } -} - void DolphinViewContainer::slotReturnPressed() { if (!GeneralSettings::editableUrl()) { @@ -699,3 +668,12 @@ void DolphinViewContainer::saveViewState() m_view->saveState(stream); m_urlNavigator->saveLocationState(locationState); } + +void DolphinViewContainer::tryRestoreViewState() +{ + QByteArray locationState = m_urlNavigator->locationState(); + if (!locationState.isEmpty()) { + QDataStream stream(&locationState, QIODevice::ReadOnly); + m_view->restoreState(stream); + } +} diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 0b6a76d5ea..e50386ab63 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -244,12 +244,6 @@ private slots: */ void activate(); - /** - * Is invoked if the signal urlAboutToBeChanged() from the DolphinView - * is emitted. Tries to save the view-state. - */ - void slotViewUrlAboutToBeChanged(const QUrl& url); - /** * Is invoked if the signal urlAboutToBeChanged() from the URL navigator * is emitted. Tries to save the view-state. @@ -278,8 +272,6 @@ private slots: */ void saveUrlCompletionMode(KCompletion::CompletionMode completion); - void slotHistoryChanged(); - void slotReturnPressed(); /** @@ -313,6 +305,12 @@ private: */ void saveViewState(); + /** + * Restores the state of the current view iff the URL navigator contains a + * non-empty location state. + */ + void tryRestoreViewState(); + private: QVBoxLayout* m_topLayout; KUrlNavigator* m_urlNavigator; diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 9728e58c3e..c7267cee0d 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -585,7 +585,6 @@ void DolphinView::setUrl(const QUrl& url) clearSelection(); - emit urlAboutToBeChanged(url); m_url = url; hideToolTip(); diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index fbe3a6376f..5e69fd37bb 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -378,13 +378,6 @@ signals: */ void activated(); - /** - * Is emitted if the URL of the view will be changed to \a url. - * After the URL has been changed the signal urlChanged() will - * be emitted. - */ - void urlAboutToBeChanged(const QUrl& url); - /** Is emitted if the URL of the view has been changed to \a url. */ void urlChanged(const QUrl& url);