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): |
252 | 252 | browser.connect('notify::title', self.__title_changed_cb) |
253 | 253 | |
254 | 254 | 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)) |
261 | 256 | |
262 | 257 | def __title_changed_cb(self, browser, pspec): |
263 | 258 | self._label.set_text(browser.props.title) |
… |
… |
class Browser(WebView): |
300 | 295 | |
301 | 296 | self.emit('is-setup') |
302 | 297 | |
| 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 | |
303 | 307 | def get_session(self): |
304 | 308 | return sessionstore.get_session(self) |
305 | 309 | |
diff --git a/webactivity.py b/webactivity.py
index bba1032..1bc0439 100644
a
|
b
|
class WebActivity(activity.Activity): |
423 | 423 | 'list of multiple uris by now.') |
424 | 424 | else: |
425 | 425 | 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']) |
426 | 439 | |
427 | 440 | def write_file(self, file_path): |
428 | 441 | if not self.metadata['mime_type']: |
… |
… |
class WebActivity(activity.Activity): |
439 | 452 | self.model.data['history'] = self._tabbed_view.get_session() |
440 | 453 | self.model.data['current_tab'] = self._tabbed_view.get_current_page() |
441 | 454 | |
| 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 | |
442 | 462 | f = open(file_path, 'w') |
443 | 463 | try: |
444 | 464 | logging.debug('########## writing %s' % self.model.serialize()) |
… |
… |
class WebActivity(activity.Activity): |
491 | 511 | ''' take screenshot and add link info to the model ''' |
492 | 512 | |
493 | 513 | 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) |
498 | 515 | |
499 | 516 | for link in self.model.data['shared_links']: |
500 | 517 | if link['hash'] == sha.new(ui_uri).hexdigest(): |
diff --git a/webtoolbar.py b/webtoolbar.py
index 69a3c8e..032ca96 100644
a
|
b
|
class PrimaryToolbar(ToolbarBox): |
366 | 366 | |
367 | 367 | def _set_address(self, uri): |
368 | 368 | 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) |
372 | 370 | else: |
373 | 371 | ui_uri = None |
374 | 372 | self.entry.props.address = ui_uri |