--- a/WebBrowser/WebBrowserTabWidget.py Thu Jun 29 18:51:03 2017 +0200 +++ b/WebBrowser/WebBrowserTabWidget.py Thu Jun 29 19:21:52 2017 +0200 @@ -1183,3 +1183,49 @@ """ self.__closedTabsButton.setEnabled(avail) self.__restoreClosedTabAct.setEnabled(avail) + + #################################################### + ## Methods below implement session related functions + #################################################### + + def getSessionData(self): + """ + Public method to populate the session data. + + @return dictionary containing the session data + @rtype dict + """ + sessionData = {} + + # 1. current index + sessionData["CurrentTabIndex"] = self.currentIndex() + + # 2. tab data + sessionData["Tabs"] = [] + for index in range(self.count()): + browser = self.widget(index) + data = browser.page().getSessionData() + sessionData["Tabs"].append(data) + + return sessionData + + def loadFromSessionData(self, sessionData): + """ + Public method to load the session data. + + @param sessionData dictionary containing the session data as + generated by getSessionData() + @type dict + """ + tabCount = self.count() + + # 1. load tab data + if "Tabs" in sessionData: + for data in sessionData["Tabs"]: + browser = self.newBrowser() + browser.page().loadFromSessionData(data) + + # 2. set tab index + if "CurrentTabIndex" in sessionData: + index = tabCount + sessionData["CurrentTabIndex"] + self.setCurrentIndex(index)