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.
This commit is contained in:
Emmanuel Pescosta 2017-02-18 20:34:02 +01:00
parent ccb3658b3a
commit 41b0e42973
No known key found for this signature in database
GPG key ID: 67C7A6C81D838246
4 changed files with 20 additions and 52 deletions

View file

@ -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);
}
}

View file

@ -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;

View file

@ -585,7 +585,6 @@ void DolphinView::setUrl(const QUrl& url)
clearSelection();
emit urlAboutToBeChanged(url);
m_url = url;
hideToolTip();

View file

@ -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);