diff options
author | Manuel Quiñones <manuq@laptop.org> | 2011-11-02 17:42:13 (GMT) |
---|---|---|
committer | Manuel Quiñones <manuq@laptop.org> | 2011-11-03 01:38:44 (GMT) |
commit | 95e47aa4e2b355f7ddd1296a164e2b348b0dbeaa (patch) | |
tree | 70968ce6fa72c28a7a7947b20273a86c96bba646 | |
parent | 399c51f34dda3be0936da65bafcf45a49a45feaf (diff) |
Restore session store functionality
This introduces a bug when restoring the session: it's adding the
latest page twice.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
-rw-r--r-- | browser.py | 3 | ||||
-rw-r--r-- | sessionstore.py | 45 |
2 files changed, 18 insertions, 30 deletions
@@ -179,7 +179,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) + window_browser = self.get_nth_page(index) + browser = window_browser.get_child() tab_sessions.append(sessionstore.get_session(browser)) return tab_sessions diff --git a/sessionstore.py b/sessionstore.py index 674f4fe..c1287a9 100644 --- a/sessionstore.py +++ b/sessionstore.py @@ -18,32 +18,32 @@ # http://lxr.mozilla.org/seamonkey/source/browser/components/sessionstore import logging +from gi.repository import WebKit def get_session(browser): - return '' - 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) + # FIXME: this is adding the latest page twice: + browser.load_uri(session_history.get_current_item().get_uri()) else: browser.load_uri('about:blank') def _get_history(history): - logging.debug('%r', history.count) 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) @@ -51,21 +51,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) |