From bf1ac8ee9b2edcf9e90f74bae7f392c1b3c318b2 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Tue, 12 Aug 2014 09:17:41 +0200 Subject: Always clear DolphinView's m_currentItemUrl member in updateViewState() Before this patch, we still kept the URL in m_currentItemUrl if the URL was not found in the model. This could cause problems the next time updateViewState() was called, because the current index would then be set to 0, which could cause other issues. For example, all items between the first item in the view and a folder which was expanded in Details View could be selected. In principle, it is possible that updateViewState() is called multiple times if many large files are being pasted in the view, but since the item which should be made the current item (and which the view should be scrolled to) should always be the first pasted item, this change will most likely not cause any other problems. BUG: 329377 REVIEW: 119703 FIXED-IN: 4.14.0 --- src/views/dolphinview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/views/dolphinview.cpp') diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index c1f585da9..02b8815e0 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1289,11 +1289,11 @@ void DolphinView::updateViewState() m_view->scrollToItem(currentIndex); m_scrollToCurrentItem = false; } - - m_currentItemUrl = KUrl(); } else { selectionManager->setCurrentItem(0); } + + m_currentItemUrl = KUrl(); } if (!m_restoredContentsPosition.isNull()) { -- cgit v1.3 From 2d2d55f3df09614e6b7cf267771b52a04dcb5e28 Mon Sep 17 00:00:00 2001 From: Emmanuel Pescosta Date: Wed, 20 Aug 2014 23:06:39 +0200 Subject: Save the view states in addition to the view urls and splitter state in DolphinTabPage. Also added version numbers to view and tab state. REVIEW: 119792 --- src/dolphintabpage.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++ src/dolphintabpage.h | 9 ++++++++ src/dolphintabwidget.cpp | 13 ++++++++--- src/views/dolphinview.cpp | 10 +++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) (limited to 'src/views/dolphinview.cpp') diff --git a/src/dolphintabpage.cpp b/src/dolphintabpage.cpp index 3d1ba5a3e..f7000ea66 100644 --- a/src/dolphintabpage.cpp +++ b/src/dolphintabpage.cpp @@ -171,14 +171,18 @@ QByteArray DolphinTabPage::saveState() const QByteArray state; QDataStream stream(&state, QIODevice::WriteOnly); + stream << quint32(2); // Tab state version + stream << m_splitViewEnabled; stream << m_primaryViewContainer->url(); stream << m_primaryViewContainer->urlNavigator()->isUrlEditable(); + m_primaryViewContainer->view()->saveState(stream); if (m_splitViewEnabled) { stream << m_secondaryViewContainer->url(); stream << m_secondaryViewContainer->urlNavigator()->isUrlEditable(); + m_secondaryViewContainer->view()->saveState(stream); } stream << m_primaryViewActive; @@ -196,6 +200,58 @@ void DolphinTabPage::restoreState(const QByteArray& state) QByteArray sd = state; QDataStream stream(&sd, QIODevice::ReadOnly); + // Read the version number of the tab state and check if the version is supported. + quint32 version = 0; + stream >> version; + if (version != 2) { + // The version of the tab state isn't supported, we can't restore it. + return; + } + + bool isSplitViewEnabled = false; + stream >> isSplitViewEnabled; + setSplitViewEnabled(isSplitViewEnabled); + + KUrl primaryUrl; + stream >> primaryUrl; + m_primaryViewContainer->setUrl(primaryUrl); + bool primaryUrlEditable; + stream >> primaryUrlEditable; + m_primaryViewContainer->urlNavigator()->setUrlEditable(primaryUrlEditable); + m_primaryViewContainer->view()->restoreState(stream); + + if (isSplitViewEnabled) { + KUrl secondaryUrl; + stream >> secondaryUrl; + m_secondaryViewContainer->setUrl(secondaryUrl); + bool secondaryUrlEditable; + stream >> secondaryUrlEditable; + m_secondaryViewContainer->urlNavigator()->setUrlEditable(secondaryUrlEditable); + m_secondaryViewContainer->view()->restoreState(stream); + } + + stream >> m_primaryViewActive; + if (m_primaryViewActive) { + m_primaryViewContainer->setActive(true); + } else { + Q_ASSERT(m_splitViewEnabled); + m_secondaryViewContainer->setActive(true); + } + + QByteArray splitterState; + stream >> splitterState; + m_splitter->restoreState(splitterState); +} + +void DolphinTabPage::restoreStateV1(const QByteArray& state) +{ + if (state.isEmpty()) { + return; + } + + QByteArray sd = state; + QDataStream stream(&sd, QIODevice::ReadOnly); + bool isSplitViewEnabled = false; stream >> isSplitViewEnabled; setSplitViewEnabled(isSplitViewEnabled); diff --git a/src/dolphintabpage.h b/src/dolphintabpage.h index de5a58915..2a406f4a9 100644 --- a/src/dolphintabpage.h +++ b/src/dolphintabpage.h @@ -120,6 +120,15 @@ public: */ void restoreState(const QByteArray& state); + /** + * Restores all tab related properties (urls, splitter layout, ...) from + * the given \a state. + * + * @deprecated The first tab state version has no version number, we keep + * this method to restore old states (<= Dolphin 4.14.x). + */ + void restoreStateV1(const QByteArray& state); + signals: void activeViewChanged(DolphinViewContainer* viewContainer); void activeViewUrlChanged(const KUrl& url); diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index 76d4b8d48..b1b2d858f 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -72,7 +72,7 @@ void DolphinTabWidget::saveProperties(KConfigGroup& group) const for (int i = 0; i < tabCount; ++i) { const DolphinTabPage* tabPage = tabPageAt(i); - group.writeEntry("Tab " % QString::number(i), tabPage->saveState()); + group.writeEntry("Tab Data " % QString::number(i), tabPage->saveState()); } } @@ -83,8 +83,15 @@ void DolphinTabWidget::readProperties(const KConfigGroup& group) if (i >= count()) { openNewActivatedTab(); } - const QByteArray state = group.readEntry("Tab " % QString::number(i), QByteArray()); - tabPageAt(i)->restoreState(state); + if (group.hasKey("Tab Data " % QString::number(i))) { + // Tab state created with Dolphin > 4.14.x + const QByteArray state = group.readEntry("Tab Data " % QString::number(i), QByteArray()); + tabPageAt(i)->restoreState(state); + } else { + // Tab state created with Dolphin <= 4.14.x + const QByteArray state = group.readEntry("Tab " % QString::number(i), QByteArray()); + tabPageAt(i)->restoreStateV1(state); + } } const int index = group.readEntry("Active Tab Index", 0); diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 02b8815e0..1de973bd5 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1167,6 +1167,14 @@ bool DolphinView::itemsExpandable() const void DolphinView::restoreState(QDataStream& stream) { + // Read the version number of the view state and check if the version is supported. + quint32 version = 0; + stream >> version; + if (version != 1) { + // The version of the view state isn't supported, we can't restore it. + return; + } + // Restore the current item that had the keyboard focus stream >> m_currentItemUrl; @@ -1181,6 +1189,8 @@ void DolphinView::restoreState(QDataStream& stream) void DolphinView::saveState(QDataStream& stream) { + stream << quint32(1); // View state version + // Save the current item that has the keyboard focus const int currentIndex = m_container->controller()->selectionManager()->currentItem(); if (currentIndex != -1) { -- cgit v1.3