From d50001dc6f26b31e39689a20a6540ad4f2e525ba Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Fri, 06 Jan 2012 14:22:48 +0000 Subject: Global history for URL autocompletion in URL entry The sqlite backend to store the global history is maintained. There are two fields in the database that are left unused: bookmark and gecko_flags. Signed-off-by: Manuel QuiƱones Acked-by: Simon Schampijer --- (limited to 'browser.py') diff --git a/browser.py b/browser.py index 0ff0b77..aad54a7 100644 --- a/browser.py +++ b/browser.py @@ -34,6 +34,7 @@ from sugar3.graphics import style from sugar3.graphics.icon import Icon from widgets import BrowserNotebook +import globalhistory _ZOOM_AMOUNT = 0.1 _LIBRARY_PATH = '/usr/share/library-common/index.html' @@ -357,6 +358,11 @@ class Browser(WebKit.WebView): def __init__(self): WebKit.WebView.__init__(self) + # Reference to the global history and callbacks to handle it: + self._global_history = globalhistory.get_global_history() + self.connect('notify::load-status', self.__load_status_changed_cb) + self.connect('notify::title', self.__title_changed_cb) + def get_history(self): """Return the browsing history of this browser.""" back_forward_list = self.get_back_forward_list() @@ -429,6 +435,22 @@ class Browser(WebKit.WebView): def open_new_tab(self, url): self.emit('new-tab', url) + def __load_status_changed_cb(self, widget, param): + """Add the url to the global history or update it.""" + status = widget.get_load_status() + if status <= WebKit.LoadStatus.COMMITTED: + uri = self.get_uri() + self._global_history.add_page(uri) + + def __title_changed_cb(self, widget, param): + """Update title in global history.""" + uri = self.get_uri() + if self.props.title is not None: + title = self.props.title + if not isinstance(title, unicode): + title = unicode(title, 'utf-8') + self._global_history.set_page_title(uri, title) + class PopupDialog(Gtk.Window): def __init__(self): -- cgit v0.9.1