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, &DolphinViewContainer::updateDirectorySortingProgress);
connect(m_view, &DolphinView::selectionChanged,
this, &DolphinViewContainer::delayedStatusBarUpdate);
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,
connect(m_view, &DolphinView::errorMessage,
this, &DolphinViewContainer::showErrorMessage);
connect(m_view, &DolphinView::urlIsFileError,
this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
connect(m_urlNavigator, &KUrlNavigator::urlChanged,
this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
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,
connect(m_urlNavigator, &KUrlNavigator::returnPressed,
this, &DolphinViewContainer::slotReturnPressed);
connect(m_urlNavigator, &KUrlNavigator::urlsDropped,
item.determineMimeType();
const QUrl& folderUrl = DolphinView::openItemAsFolderUrl(item, true);
if (!folderUrl.isEmpty()) {
item.determineMimeType();
const QUrl& folderUrl = DolphinView::openItemAsFolderUrl(item, true);
if (!folderUrl.isEmpty()) {
- m_view->setUrl(folderUrl);
} else {
slotItemActivated(item);
}
} else {
slotItemActivated(item);
}
const QUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
if (!url.isEmpty()) {
const QUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
if (!url.isEmpty()) {
-void DolphinViewContainer::slotViewUrlAboutToBeChanged(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 2:
- if (url != m_urlNavigator->locationUrl()) {
- saveViewState();
- }
-}
-
-void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(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 1:
- if (url != m_view->url()) {
- saveViewState();
- }
}
void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url)
}
void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url)
if (KProtocolManager::supportsListing(url)) {
setSearchModeEnabled(isSearchUrl(url));
m_view->setUrl(url);
if (KProtocolManager::supportsListing(url)) {
setSearchModeEnabled(isSearchUrl(url));
m_view->setUrl(url);
if (m_autoGrabFocus && isActive() && !isSearchUrl(url)) {
// When an URL has been entered, the view should get the focus.
if (m_autoGrabFocus && isActive() && !isSearchUrl(url)) {
// When an URL has been entered, the view should get the focus.
GeneralSettings::setUrlCompletionMode(completion);
}
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()) {
void DolphinViewContainer::slotReturnPressed()
{
if (!GeneralSettings::editableUrl()) {
m_view->saveState(stream);
m_urlNavigator->saveLocationState(locationState);
}
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);
+ }
+}
- /**
- * 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.
/**
* Is invoked if the signal urlAboutToBeChanged() from the URL navigator
* is emitted. Tries to save the view-state.
*/
void saveUrlCompletionMode(KCompletion::CompletionMode completion);
*/
void saveUrlCompletionMode(KCompletion::CompletionMode completion);
- void slotHistoryChanged();
-
void slotReturnPressed();
/**
void slotReturnPressed();
/**
+ /**
+ * 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;
private:
QVBoxLayout* m_topLayout;
KUrlNavigator* m_urlNavigator;
- emit urlAboutToBeChanged(url);
m_url = url;
hideToolTip();
m_url = url;
hideToolTip();
- /**
- * 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);
/** Is emitted if the URL of the view has been changed to \a url. */
void urlChanged(const QUrl& url);