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;
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);
*/
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);
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());
}
}
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);
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;
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) {