From 978cc1edf77fc88c6c80c75694f96e2848c02ef1 Mon Sep 17 00:00:00 2001 From: Lucian Branescu Mihaila Date: Wed, 06 Oct 2010 13:22:48 +0000 Subject: Fix history on resume. The code is a bit hacky because of xulrunner limitations. I plan to make this code nicer when we move to webkit. --- 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 20616a4..290011e 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 -- cgit v0.9.1