WebBrowser/WebBrowserPage.py

changeset 5777
2c4441d65ee3
parent 5774
a559df54a729
child 5780
79d06c98c5c9
--- a/WebBrowser/WebBrowserPage.py	Thu Jun 29 18:51:03 2017 +0200
+++ b/WebBrowser/WebBrowserPage.py	Thu Jun 29 19:21:52 2017 +0200
@@ -405,9 +405,40 @@
         sessionData["History"] = str(
             historyArray.toBase64(QByteArray.Base64UrlEncoding),
             encoding="ascii")
+        sessionData["HistoryIndex"] = self.history().currentItemIndex()
         
         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
+        """
+        # 1. page history
+        if "History" in sessionData:
+            historyArray = QByteArray.fromBase64(
+                sessionData["History"].encode("ascii"),
+                QByteArray.Base64UrlEncoding)
+            stream = QDataStream(historyArray, QIODevice.ReadOnly)
+            stream >> self.history()
+            
+            if "HistoryIndex" in sessionData:
+                item = self.history().itemAt(sessionData["HistoryIndex"])
+                if item is not None:
+                    self.history().goToItem(item)
+        
+        # 2. zoom factor
+        if "ZoomFactor" in sessionData:
+            self.setZoomFactor(sessionData["ZoomFactor"])
+        
+        # 3. scroll position
+        if "ScrollPosition" in sessionData:
+            scrollPos = sessionData["ScrollPosition"]
+            self.scrollTo(QPointF(scrollPos["x"], scrollPos["y"]))
+    
     ##################################################
     ## Methods below implement compatibility functions
     ##################################################

eric ide

mercurial