[Sugar-devel] [PATCH 3/4] Restore session store

Manuel Quiñones manuq at laptop.org
Tue Nov 29 23:41:42 EST 2011


Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 browser.py      |    6 ++++--
 sessionstore.py |   48 +++++++++++++++++-------------------------------
 webactivity.py  |    4 +++-
 3 files changed, 24 insertions(+), 34 deletions(-)

diff --git a/browser.py b/browser.py
index f3c3f50..320cb62 100644
--- a/browser.py
+++ b/browser.py
@@ -30,8 +30,9 @@ from sugar3.activity import activity
 from sugar3.graphics import style
 from sugar3.graphics.icon import Icon
 
+import sessionstore
+
 # FIXME
-# import sessionstore
 # from palettes import ContentInvoker
 # from sessionhistory import HistoryListener
 # from progresslistener import ProgressListener
@@ -288,7 +289,8 @@ class TabbedView(BrowserNotebook):
     def get_session(self):
         tab_sessions = []
         for index in xrange(0, self.get_n_pages()):
-            browser = self.get_nth_page(index)
+            scrolled_window = self.get_nth_page(index)
+            browser = scrolled_window.get_child()
             tab_sessions.append(sessionstore.get_session(browser))
         return tab_sessions
 
diff --git a/sessionstore.py b/sessionstore.py
index 73edb24..d347d6d 100644
--- a/sessionstore.py
+++ b/sessionstore.py
@@ -18,35 +18,34 @@
 # http://lxr.mozilla.org/seamonkey/source/browser/components/sessionstore
 
 import logging
-
-from xpcom import components
-from xpcom.components import interfaces
+from gi.repository import WebKit
 
 
 def get_session(browser):
-    session_history = browser.web_navigation.sessionHistory
-
-    if session_history.count == 0:
+    session_history = browser.get_back_forward_list()
+    if session_history.get_back_length() == 0:
         return ''
     return _get_history(session_history)
 
 
 def set_session(browser, data):
-    _set_history(browser.web_navigation.sessionHistory, data)
+    session_history = browser.get_back_forward_list()
+    _set_history(session_history, data)
 
     if data:
-        browser.web_navigation.gotoIndex(len(data) - 1)
+        browser.load_uri(session_history.get_current_item().get_uri())
+        session_history.go_back()
     else:
         browser.load_uri('about:blank')
 
 
 def _get_history(history):
-    logging.debug('%r', history.count)
+    logging.debug('history count: %r', history.get_back_length())
     entries_dest = []
-    for i in range(0, history.count):
-        entry_orig = history.getEntryAtIndex(i, False)
-        entry_dest = {'url':    entry_orig.URI.spec,
-                      'title':  entry_orig.title}
+    for i in reversed(range(history.get_back_length())):
+        entry_orig = history.get_nth_item(i * -1)
+        entry_dest = {'url': entry_orig.get_uri(),
+                      'title': entry_orig.get_title()}
 
         entries_dest.append(entry_dest)
 
@@ -54,21 +53,8 @@ def _get_history(history):
 
 
 def _set_history(history, history_data):
-    history_internal = history.queryInterface(interfaces.nsISHistoryInternal)
-
-    if history_internal.count > 0:
-        history_internal.purgeHistory(history_internal.count)
-
-    for entry_dict in history_data:
-        logging.debug('entry_dict: %r', entry_dict)
-        entry_class = components.classes[ \
-                "@mozilla.org/browser/session-history-entry;1"]
-        entry = entry_class.createInstance(interfaces.nsISHEntry)
-
-        io_service_class = components.classes[ \
-                "@mozilla.org/network/io-service;1"]
-        io_service = io_service_class.getService(interfaces.nsIIOService)
-        entry.setURI(io_service.newURI(entry_dict['url'], None, None))
-        entry.setTitle(entry_dict['title'])
-
-        history_internal.addEntry(entry, True)
+    history.clear()
+    for entry in history_data:
+        uri, title = entry['url'], entry['title']
+        history_item = WebKit.WebHistoryItem.new_with_data(uri, title)
+        history.add_item(history_item)
diff --git a/webactivity.py b/webactivity.py
index 2efa70e..723817a 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -437,6 +437,7 @@ class WebActivity(activity.Activity):
             for n in range(0, self._tabbed_view.get_n_pages()):
                 n_browser = self._tabbed_view.get_nth_page(n)
                 if n_browser != None:
+                    continue  # FIXME
                     nsiuri = n_browser.progress.location
                     ui_uri = n_browser.get_url_from_nsiuri(nsiuri)
                     history_index = n_browser.get_history_index()
@@ -578,7 +579,8 @@ class WebActivity(activity.Activity):
     def can_close(self):
         if self._force_close:
             return True
-        elif downloadmanager.can_quit():
+        # FIXME
+        elif True:  #downloadmanager.can_quit():
             return True
         else:
             alert = Alert()
-- 
1.7.7.3



More information about the Sugar-devel mailing list