[Sugar-devel] [PATCH] fix #2383 - Browse: history not right when resuming

godiard at sugarlabs.org godiard at sugarlabs.org
Tue Oct 5 17:22:07 EDT 2010


From: Gonzalo Odiard <godiard at sugarlabs.org>

Previously Browse does not saved the current tabs opened, saved
the history and assumes the last url in the history is the current.

V1 -> V2 : load_urls is a private method now, and create a function
to eliminate duplicated code
---
 browser.py     |   16 ++++++++++------
 webactivity.py |   25 +++++++++++++++++++++----
 webtoolbar.py  |    4 +---
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/browser.py b/browser.py
index ece81d1..8e1dab5 100644
--- a/browser.py
+++ b/browser.py
@@ -252,12 +252,7 @@ class TabLabel(gtk.HBox):
         browser.connect('notify::title', self.__title_changed_cb)
 
     def __location_changed_cb(self, progress_listener, pspec):
-        uri = progress_listener.location
-        cls = components.classes['@mozilla.org/intl/texttosuburi;1']
-        texttosuburi = cls.getService(interfaces.nsITextToSubURI)
-        ui_uri = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
-
-        self._label.set_text(ui_uri)
+        self._label.set_text(self._browser.get_url_from_nsiuri(progress_listener.location))
 
     def __title_changed_cb(self, browser, pspec):
         self._label.set_text(browser.props.title)
@@ -300,6 +295,15 @@ class Browser(WebView):
 
         self.emit('is-setup')
 
+
+    def get_url_from_nsiuri(self, uri):
+        """
+        get a nsIURI object and return a string with the url
+        """
+        cls = components.classes['@mozilla.org/intl/texttosuburi;1']
+        texttosuburi = cls.getService(interfaces.nsITextToSubURI)
+        return texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
+
     def get_session(self):
         return sessionstore.get_session(self)
 
diff --git a/webactivity.py b/webactivity.py
index bba1032..1bc0439 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -423,6 +423,19 @@ class WebActivity(activity.Activity):
                               'list of multiple uris by now.')
         else:
             self._tabbed_view.props.current_browser.load_uri(file_path)
+        self._load_urls()
+
+    def _load_urls(self):
+        if self.model.data['currents'] != None:
+            first = True
+            for current_tab in self.model.data['currents']:
+                if first:
+                    browser = self._tabbed_view.current_browser
+                    first = False
+                else:
+                    browser = Browser()
+                    self._tabbed_view._append_tab(browser)
+                browser.load_uri(current_tab['url'])
 
     def write_file(self, file_path):
         if not self.metadata['mime_type']:
@@ -439,6 +452,13 @@ class WebActivity(activity.Activity):
             self.model.data['history'] = self._tabbed_view.get_session()
             self.model.data['current_tab'] = self._tabbed_view.get_current_page()
 
+            self.model.data['currents'] = []
+            for n in range(0, self._tabbed_view.get_n_pages()):
+                n_browser = self._tabbed_view.get_nth_page(n)
+                if n_browser != None:
+                    ui_uri = browser.get_url_from_nsiuri(browser.progress.location)
+                    self.model.data['currents'].append({'title':browser.props.title,'url':ui_uri})
+
             f = open(file_path, 'w')
             try:
                 logging.debug('########## writing %s' % self.model.serialize())
@@ -491,10 +511,7 @@ class WebActivity(activity.Activity):
         ''' take screenshot and add link info to the model '''
 
         browser = self._tabbed_view.props.current_browser
-        uri = browser.progress.location
-        cls = components.classes['@mozilla.org/intl/texttosuburi;1']
-        texttosuburi = cls.getService(components.interfaces.nsITextToSubURI)
-        ui_uri = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
+        ui_uri = browser.get_url_from_nsiuri(browser.progress.location)
 
         for link in self.model.data['shared_links']:
             if link['hash'] == sha.new(ui_uri).hexdigest():
diff --git a/webtoolbar.py b/webtoolbar.py
index 69a3c8e..032ca96 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -366,9 +366,7 @@ class PrimaryToolbar(ToolbarBox):
 
     def _set_address(self, uri):
         if uri is not None:
-            cls = components.classes['@mozilla.org/intl/texttosuburi;1']
-            texttosuburi = cls.getService(interfaces.nsITextToSubURI)
-            ui_uri = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
+            ui_uri = self._browser.get_url_from_nsiuri(uri)
         else:
             ui_uri = None
         self.entry.props.address = ui_uri
-- 
1.7.2.3



More information about the Sugar-devel mailing list