Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-06-26 13:46:27 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-06-26 13:46:27 (GMT)
commit55f8b01e2b29d390604b8a09093ef2e3e353ee7a (patch)
tree11f4d943a092e709b13ac2dcb261dc7922afc43c
parentef15fd0bc70bb7b593ff022b19080891fd60e067 (diff)
Refactored a bit the progress listener and created a session history listener.
-rw-r--r--progresslistener.py96
-rw-r--r--sessionhistory.py61
-rwxr-xr-xwebactivity.py10
-rwxr-xr-xwebtoolbar.py94
4 files changed, 196 insertions, 65 deletions
diff --git a/progresslistener.py b/progresslistener.py
new file mode 100644
index 0000000..087a891
--- /dev/null
+++ b/progresslistener.py
@@ -0,0 +1,96 @@
+# Copyright (C) 2006, Red Hat, Inc.
+# Copyright (C) 2007, One Laptop Per Child
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gobject
+import xpcom
+from xpcom.components import interfaces
+
+class ProgressListener(gobject.GObject):
+ _com_interfaces_ = interfaces.nsIWebProgressListener
+
+ __gsignals__ = {
+ 'location-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+ ([str])),
+ 'loading-start': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+ ([])),
+ 'loading-stop': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+ ([])),
+ 'loading-progress': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+ ([float]))
+ }
+
+ def __init__(self, browser):
+ gobject.GObject.__init__(self)
+
+ self._wrapped_self = xpcom.server.WrapObject(self, interfaces.nsIWebProgressListener)
+ weak_ref = xpcom.client.WeakReference(self._wrapped_self)
+
+ mask = interfaces.nsIWebProgress.NOTIFY_STATE_NETWORK | \
+ interfaces.nsIWebProgress.NOTIFY_STATE_REQUEST | \
+ interfaces.nsIWebProgress.NOTIFY_LOCATION
+ browser.web_progress.addProgressListener(self._wrapped_self, mask)
+
+ self._reset_requests_count()
+
+ def _reset_requests_count(self):
+ self.total_requests = 0
+ self.completed_requests = 0
+
+ def onLocationChange(self, webProgress, request, location):
+ self.emit('location-changed', location.spec)
+
+ def onProgressChange(self, webProgress, request, curSelfProgress,
+ maxSelfProgress, curTotalProgress, maxTotalProgress):
+ pass
+
+ def onSecurityChange(self, webProgress, request, state):
+ pass
+
+ def onStateChange(self, webProgress, request, stateFlags, status):
+ if stateFlags & interfaces.nsIWebProgressListener.STATE_IS_REQUEST:
+ if stateFlags & interfaces.nsIWebProgressListener.STATE_START:
+ self.total_requests += 1
+ elif stateFlags & interfaces.nsIWebProgressListener.STATE_STOP:
+ self.completed_requests += 1
+
+ if stateFlags & interfaces.nsIWebProgressListener.STATE_IS_NETWORK:
+ if stateFlags & interfaces.nsIWebProgressListener.STATE_START:
+ self.emit('loading-start')
+ self._reset_requests_count()
+ elif stateFlags & interfaces.nsIWebProgressListener.STATE_STOP:
+ self.emit('loading-stop')
+
+ if self.total_requests < self.completed_requests:
+ self.emit('loading-progress', 1.0)
+ elif self.total_requests > 0:
+ self.emit('loading-progress', float(self.completed_requests) /
+ float(self.total_requests))
+ else:
+ self.emit('loading-progress', 0.0)
+
+ def onStatusChange(self, webProgress, request, status, message):
+ pass
+
+_progress_listener = None
+
+def init(browser):
+ global _progress_listener
+ _progress_listener = ProgressListener(browser)
+
+def get_instance():
+ global _progress_listener
+ return _progress_listener
diff --git a/sessionhistory.py b/sessionhistory.py
new file mode 100644
index 0000000..566a9ef
--- /dev/null
+++ b/sessionhistory.py
@@ -0,0 +1,61 @@
+# Copyright (C) 2007, One Laptop Per Child
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import logging
+
+import gobject
+import xpcom
+from xpcom.components import interfaces
+
+class HistoryListener(gobject.GObject):
+ _com_interfaces_ = interfaces.nsISHistoryListener
+
+ def __init__(self, browser):
+ gobject.GObject.__init__(self)
+
+ self._wrapped_self = xpcom.server.WrapObject(self, interfaces.nsISHistoryListener)
+ weak_ref = xpcom.client.WeakReference(self._wrapped_self)
+
+ session_history = browser.web_navigation.sessionHistory
+ session_history.addSHistoryListener(self._wrapped_self)
+
+ def OnHistoryGoBack(self, back_uri):
+ return True
+
+ def OnHistoryGoForward(self, forward_uri):
+ return True
+
+ def OnHistoryGotoIndex(self, index, goto_uri):
+ return True
+
+ def OnHistoryNewEntry(self, new_uri):
+ logging.debug(new_uri.spec)
+
+ def OnHistoryPurge(self, num_entries):
+ return True
+
+ def OnHistoryReload(self, reload_uri, reload_flags):
+ return True
+
+_session_history_listener = None
+
+def init(browser):
+ global _session_history_listener
+ _session_history_listener = HistoryListener(browser)
+
+def get_instance():
+ global _session_history_listener
+ return _session_history_listener
diff --git a/webactivity.py b/webactivity.py
index 8ef06e8..949cbd8 100755
--- a/webactivity.py
+++ b/webactivity.py
@@ -33,6 +33,8 @@ import downloadmanager
import promptservice
import securitydialogs
import filepicker
+import sessionhistory
+import progresslistener
_HOMEPAGE = 'http://www.google.com'
@@ -49,7 +51,12 @@ class WebActivity(activity.Activity):
else:
self._browser = Browser()
+ self.set_canvas(self._browser)
+ self._browser.show()
+
downloadmanager.init(self._browser)
+ sessionhistory.init(self._browser)
+ progresslistener.init(self._browser)
toolbox = activity.ActivityToolbox(self)
activity_toolbar = toolbox.get_activity_toolbar()
@@ -61,9 +68,6 @@ class WebActivity(activity.Activity):
self.set_toolbox(toolbox)
toolbox.show()
- self.set_canvas(self._browser)
- self._browser.show()
-
if handle.uri:
self._browser.load_uri(handle.uri)
elif not self._jobject.file_path and not browser:
diff --git a/webtoolbar.py b/webtoolbar.py
index b012808..e52c969 100755
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -1,4 +1,5 @@
# Copyright (C) 2006, Red Hat, Inc.
+# Copyright (C) 2007, One Laptop Per Child
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,6 +17,7 @@
import os
import logging
+from gettext import gettext as _
import gtk
import xpcom
@@ -23,64 +25,16 @@ from xpcom.components import interfaces
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics import AddressEntry
-from gettext import gettext as _
-
-class _ProgressListener:
- _com_interfaces_ = interfaces.nsIWebProgressListener
-
- def __init__(self, toolbar):
- self.toolbar = toolbar
- self._reset_requests_count()
-
- def _reset_requests_count(self):
- self.total_requests = 0
- self.completed_requests = 0
-
- def onLocationChange(self, webProgress, request, location):
- self.toolbar._set_address(location.spec)
- self.toolbar._update_navigation_buttons()
-
- def onProgressChange(self, webProgress, request, curSelfProgress,
- maxSelfProgress, curTotalProgress, maxTotalProgress):
- pass
-
- def onSecurityChange(self, webProgress, request, state):
- pass
-
- def onStateChange(self, webProgress, request, stateFlags, status):
- if stateFlags & interfaces.nsIWebProgressListener.STATE_IS_REQUEST:
- if stateFlags & interfaces.nsIWebProgressListener.STATE_START:
- self.total_requests += 1
- elif stateFlags & interfaces.nsIWebProgressListener.STATE_STOP:
- self.completed_requests += 1
-
- if stateFlags & interfaces.nsIWebProgressListener.STATE_IS_NETWORK:
- if stateFlags & interfaces.nsIWebProgressListener.STATE_START:
- self.toolbar._set_title(None)
- self.toolbar.set_loading(True)
- self.toolbar._update_navigation_buttons()
- self._reset_requests_count()
- elif stateFlags & interfaces.nsIWebProgressListener.STATE_STOP:
- self.toolbar.set_loading(False)
- self.toolbar._update_navigation_buttons()
-
- if self.total_requests < self.completed_requests:
- self.toolbar._set_progress(1.0)
- elif self.total_requests > 0:
- self.toolbar._set_progress(float(self.completed_requests) /
- float(self.total_requests))
- else:
- self.toolbar._set_progress(0.0)
- def onStatusChange(self, webProgress, request, status, message):
- pass
+import sessionhistory
+import progresslistener
class WebToolbar(gtk.Toolbar):
def __init__(self, browser):
gtk.Toolbar.__init__(self)
self._browser = browser
-
+
self._back = ToolButton('go-previous')
self._back.set_tooltip(_('Back'))
self._back.props.sensitive = False
@@ -110,18 +64,34 @@ class WebToolbar(gtk.Toolbar):
self.insert(entry_item, -1)
entry_item.show()
-
- self._listener = xpcom.server.WrapObject(
- _ProgressListener(self), interfaces.nsIWebProgressListener)
- weak_ref = xpcom.client.WeakReference(self._listener)
-
- mask = interfaces.nsIWebProgress.NOTIFY_STATE_NETWORK | \
- interfaces.nsIWebProgress.NOTIFY_STATE_REQUEST | \
- interfaces.nsIWebProgress.NOTIFY_LOCATION
- self._browser.web_progress.addProgressListener(self._listener, mask)
-
+
+ progress_listener = progresslistener.get_instance()
+ progress_listener.connect('location-changed', self._location_changed_cb)
+ progress_listener.connect('loading-start', self._loading_start_cb)
+ progress_listener.connect('loading-stop', self._loading_stop_cb)
+ progress_listener.connect('loading-progress', self._loading_progress_cb)
+
+ session_history = sessionhistory.get_instance()
+ #session_history.connect('location-changed', self._location_changed_cb)
+
self._browser.connect("notify::title", self._title_changed_cb)
+ def _location_changed_cb(self, progress_listener, uri):
+ self._set_address(uri)
+ self._update_navigation_buttons()
+
+ def _loading_start_cb(self, progress_listener):
+ self._set_title(None)
+ self._set_loading(True)
+ self._update_navigation_buttons()
+
+ def _loading_stop_cb(self, progress_listener):
+ self._set_loading(False)
+ self._update_navigation_buttons()
+
+ def _loading_progress_cb(self, progress_listener, progress):
+ self._set_progress(progress)
+
def _set_progress(self, progress):
self._entry.props.progress = progress
@@ -164,7 +134,7 @@ class WebToolbar(gtk.Toolbar):
flags = interfaces.nsIWebNavigation.LOAD_FLAGS_NONE
self._browser.web_navigation.reload(flags)
- def set_loading(self, loading):
+ def _set_loading(self, loading):
self._loading = loading
if self._loading: