Ticket #2383: 0001-fix-2383-Browse-history-not-right-when-resuming-V2.patch

File 0001-fix-2383-Browse-history-not-right-when-resuming-V2.patch, 4.7 KB (added by godiard, 10 years ago)
  • browser.py

    From 81c6acc3bf9c5780cc2df987e6fd4d7e8b266331 Mon Sep 17 00:00:00 2001
    From: Gonzalo Odiard <godiard@sugarlabs.org>
    Date: Tue, 5 Oct 2010 07:59:02 -0300
    Subject: [PATCH] fix #2383 - Browse: history not right when resuming
    
    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 b class TabLabel(gtk.HBox): 
    252252        browser.connect('notify::title', self.__title_changed_cb)
    253253
    254254    def __location_changed_cb(self, progress_listener, pspec):
    255         uri = progress_listener.location
    256         cls = components.classes['@mozilla.org/intl/texttosuburi;1']
    257         texttosuburi = cls.getService(interfaces.nsITextToSubURI)
    258         ui_uri = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
    259 
    260         self._label.set_text(ui_uri)
     255        self._label.set_text(self._browser.get_url_from_nsiuri(progress_listener.location))
    261256
    262257    def __title_changed_cb(self, browser, pspec):
    263258        self._label.set_text(browser.props.title)
    class Browser(WebView): 
    300295
    301296        self.emit('is-setup')
    302297
     298
     299    def get_url_from_nsiuri(self, uri):
     300        """
     301        get a nsIURI object and return a string with the url
     302        """
     303        cls = components.classes['@mozilla.org/intl/texttosuburi;1']
     304        texttosuburi = cls.getService(interfaces.nsITextToSubURI)
     305        return texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
     306
    303307    def get_session(self):
    304308        return sessionstore.get_session(self)
    305309
  • webactivity.py

    diff --git a/webactivity.py b/webactivity.py
    index bba1032..1bc0439 100644
    a b class WebActivity(activity.Activity): 
    423423                              'list of multiple uris by now.')
    424424        else:
    425425            self._tabbed_view.props.current_browser.load_uri(file_path)
     426        self._load_urls()
     427
     428    def _load_urls(self):
     429        if self.model.data['currents'] != None:
     430            first = True
     431            for current_tab in self.model.data['currents']:
     432                if first:
     433                    browser = self._tabbed_view.current_browser
     434                    first = False
     435                else:
     436                    browser = Browser()
     437                    self._tabbed_view._append_tab(browser)
     438                browser.load_uri(current_tab['url'])
    426439
    427440    def write_file(self, file_path):
    428441        if not self.metadata['mime_type']:
    class WebActivity(activity.Activity): 
    439452            self.model.data['history'] = self._tabbed_view.get_session()
    440453            self.model.data['current_tab'] = self._tabbed_view.get_current_page()
    441454
     455            self.model.data['currents'] = []
     456            for n in range(0, self._tabbed_view.get_n_pages()):
     457                n_browser = self._tabbed_view.get_nth_page(n)
     458                if n_browser != None:
     459                    ui_uri = browser.get_url_from_nsiuri(browser.progress.location)
     460                    self.model.data['currents'].append({'title':browser.props.title,'url':ui_uri})
     461
    442462            f = open(file_path, 'w')
    443463            try:
    444464                logging.debug('########## writing %s' % self.model.serialize())
    class WebActivity(activity.Activity): 
    491511        ''' take screenshot and add link info to the model '''
    492512
    493513        browser = self._tabbed_view.props.current_browser
    494         uri = browser.progress.location
    495         cls = components.classes['@mozilla.org/intl/texttosuburi;1']
    496         texttosuburi = cls.getService(components.interfaces.nsITextToSubURI)
    497         ui_uri = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
     514        ui_uri = browser.get_url_from_nsiuri(browser.progress.location)
    498515
    499516        for link in self.model.data['shared_links']:
    500517            if link['hash'] == sha.new(ui_uri).hexdigest():
  • webtoolbar.py

    diff --git a/webtoolbar.py b/webtoolbar.py
    index 69a3c8e..032ca96 100644
    a b class PrimaryToolbar(ToolbarBox): 
    366366
    367367    def _set_address(self, uri):
    368368        if uri is not None:
    369             cls = components.classes['@mozilla.org/intl/texttosuburi;1']
    370             texttosuburi = cls.getService(interfaces.nsITextToSubURI)
    371             ui_uri = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
     369            ui_uri = self._browser.get_url_from_nsiuri(uri)
    372370        else:
    373371            ui_uri = None
    374372        self.entry.props.address = ui_uri