1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

WebTab: Add sessionData property

This commit is contained in:
David Rosca 2018-02-04 12:01:29 +01:00
parent 62264501e2
commit 095e0ff517
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 24 additions and 2 deletions

View File

@ -36,7 +36,7 @@
#include <QTimer> #include <QTimer>
#include <QSplitter> #include <QSplitter>
static const int savedTabVersion = 5; static const int savedTabVersion = 6;
WebTab::SavedTab::SavedTab() WebTab::SavedTab::SavedTab()
: isPinned(false) : isPinned(false)
@ -60,6 +60,8 @@ WebTab::SavedTab::SavedTab(WebTab* webTab)
for (WebTab *child : children) { for (WebTab *child : children) {
childTabs.append(child->tabIndex()); childTabs.append(child->tabIndex());
} }
sessionData = webTab->sessionData();
} }
bool WebTab::SavedTab::isValid() const bool WebTab::SavedTab::isValid() const
@ -77,6 +79,7 @@ void WebTab::SavedTab::clear()
zoomLevel = qzSettings->defaultZoomLevel; zoomLevel = qzSettings->defaultZoomLevel;
parentTab = -1; parentTab = -1;
childTabs.clear(); childTabs.clear();
sessionData.clear();
} }
QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab) QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab)
@ -90,6 +93,7 @@ QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab)
stream << tab.zoomLevel; stream << tab.zoomLevel;
stream << tab.parentTab; stream << tab.parentTab;
stream << tab.childTabs; stream << tab.childTabs;
stream << tab.sessionData;
return stream; return stream;
} }
@ -120,6 +124,9 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
if (version >= 5) if (version >= 5)
stream >> tab.childTabs; stream >> tab.childTabs;
if (version >= 6)
stream >> tab.sessionData;
tab.icon = QIcon(pixmap); tab.icon = QIcon(pixmap);
return stream; return stream;
@ -498,6 +505,16 @@ QVector<WebTab*> WebTab::childTabs() const
return m_childTabs; return m_childTabs;
} }
QHash<QString, QVariant> WebTab::sessionData() const
{
return m_sessionData;
}
void WebTab::setSessionData(const QString &key, const QVariant &value)
{
m_sessionData[key] = value;
}
bool WebTab::isRestored() const bool WebTab::isRestored() const
{ {
return !m_savedTab.isValid(); return !m_savedTab.isValid();
@ -508,6 +525,7 @@ void WebTab::restoreTab(const WebTab::SavedTab &tab)
Q_ASSERT(m_tabBar); Q_ASSERT(m_tabBar);
setPinned(tab.isPinned); setPinned(tab.isPinned);
m_sessionData = tab.sessionData;
if (!isPinned() && qzSettings->loadTabsOnActivation) { if (!isPinned() && qzSettings->loadTabsOnActivation) {
m_savedTab = tab; m_savedTab = tab;

View File

@ -48,6 +48,7 @@ public:
int zoomLevel; int zoomLevel;
int parentTab; int parentTab;
QVector<int> childTabs; QVector<int> childTabs;
QHash<QString, QVariant> sessionData;
SavedTab(); SavedTab();
SavedTab(WebTab* webTab); SavedTab(WebTab* webTab);
@ -73,9 +74,11 @@ public:
WebTab *parentTab() const; WebTab *parentTab() const;
void setParentTab(WebTab *tab); void setParentTab(WebTab *tab);
void addChildTab(WebTab *tab, int index = -1); void addChildTab(WebTab *tab, int index = -1);
QVector<WebTab*> childTabs() const; QVector<WebTab*> childTabs() const;
QHash<QString, QVariant> sessionData() const;
void setSessionData(const QString &key, const QVariant &value);
QUrl url() const; QUrl url() const;
QString title(bool allowEmpty = false) const; QString title(bool allowEmpty = false) const;
QIcon icon(bool allowNull = false) const; QIcon icon(bool allowNull = false) const;
@ -160,6 +163,7 @@ private:
WebTab *m_parentTab = nullptr; WebTab *m_parentTab = nullptr;
QVector<WebTab*> m_childTabs; QVector<WebTab*> m_childTabs;
QHash<QString, QVariant> m_sessionData;
SavedTab m_savedTab; SavedTab m_savedTab;
bool m_isPinned = false; bool m_isPinned = false;