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 --- 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): diff --git a/globalhistory.py b/globalhistory.py index 1ec0a72..e93cdab 100644 --- a/globalhistory.py +++ b/globalhistory.py @@ -16,65 +16,34 @@ from datetime import datetime -from xpcom import components -from xpcom.components import interfaces -from xpcom.server.factory import Factory - import places +_global_history = None -class GlobalHistory: - _com_interfaces_ = interfaces.nsIGlobalHistory, \ - interfaces.nsIGlobalHistory2, \ - interfaces.nsIGlobalHistory3 - - cid = '{2a53cf28-c48e-4a01-ba18-3d3fef3e2985}' - description = 'Sugar Global History' +class GlobalHistory(object): def __init__(self): self._store = places.get_store() - def addPage(self, url): - self.addURI(url, False, True, None) - - def isVisited(self, uri): - place = self._store.lookup_place(uri.spec) - return place != None - - def addURI(self, uri, redirect, toplevel, referrer): - place = self._store.lookup_place(uri.spec) + def add_page(self, uri): + place = self._store.lookup_place(uri) if place: place.visits += 1 place.last_visit = datetime.now() self._store.update_place(place) else: - place = places.Place(uri.spec) + place = places.Place(uri) self._store.add_place(place) - def setPageTitle(self, uri, title): - place = self._store.lookup_place(uri.spec) + def set_page_title(self, uri, title): + place = self._store.lookup_place(uri) if place: place.title = title self._store.update_place(place) - def addDocumentRedirect(self, old_channel, new_channel, flags, toplevel): - pass - - def getURIGeckoFlags(self, uri): - place = self._store.lookup_place(uri.spec) - if place: - return place.gecko_flags - else: - return 0 - - def setURIGeckoFlags(self, uri, flags): - place = self._store.lookup_place(uri.spec) - if place: - place.gecko_flags = flags - self._store.update_place(place) - -components.registrar.registerFactory(GlobalHistory.cid, - GlobalHistory.description, - '@mozilla.org/browser/global-history;2', - Factory(GlobalHistory)) +def get_global_history(): + global _global_history + if _global_history == None: + _global_history = GlobalHistory() + return _global_history diff --git a/places.py b/places.py index 90956fe..8b98c79 100644 --- a/places.py +++ b/places.py @@ -46,6 +46,9 @@ class SqliteStore(object): cursor.execute('select * from sqlite_master where name == "places"') if cursor.fetchone() == None: + # Create table to store the visited places. Note that + # bookmark and gecko_flags fields aren't used anymore in + # WebKit port, but are kept for backwards compatibility. cursor.execute("""create table places ( uri text, title text, diff --git a/webactivity.py b/webactivity.py index 3d741d9..092a8e3 100644 --- a/webactivity.py +++ b/webactivity.py @@ -160,7 +160,6 @@ from viewtoolbar import ViewToolbar # import downloadmanager # TODO: make the registration clearer SL #3087 -# import globalhistory # pylint: disable=W0611 # import filepicker # pylint: disable=W0611 from model import Model diff --git a/webtoolbar.py b/webtoolbar.py index c0e1396..461fc5c 100644 --- a/webtoolbar.py +++ b/webtoolbar.py @@ -127,16 +127,16 @@ class WebEntry(iconentry.IconEntry): return len(list_store) > 0 def _search_popup(self): - entry_x, entry_y = self.window.get_origin() - entry_w, entry_h = self.size_request() + miss, window_x, window_y = self.props.window.get_origin() + entry_allocation = self.get_allocation() - x = entry_x + entry_h / 2 - y = entry_y + entry_h - width = self.allocation.width - entry_h - height = Gdk.Screen.height() / 3 + search_x = window_x + entry_allocation.x + search_y = window_y + entry_allocation.y + entry_allocation.height + search_width = entry_allocation.width + search_height = Gdk.Screen.height() / 3 - self._search_window.move(x, y) - self._search_window.resize(width, height) + self._search_window.move(search_x, search_y) + self._search_window.resize(search_width, search_height) self._search_window.show() def _search_popdown(self): -- cgit v0.9.1