Load the current page when joining an active.

Get back page sharing to work.
This commit is contained in:
Marco Pesenti Gritti 2006-07-26 18:00:28 +02:00
parent e1928878f9
commit d778d45b13
4 changed files with 29 additions and 21 deletions

View File

@ -57,19 +57,22 @@ class BrowserActivity(Activity):
vbox.show()
self._pservice = PresenceService()
self._pservice.connect('service-appeared', self._service_appeared_cb)
# Join the shared activity if we were started from one
if self._initial_service:
logging.debug("BrowserActivity joining shared activity %s" %
self._initial_service.get_activity_id())
self._pservice.join_shared_activity(self._initial_service)
if service:
service.connect('service-appeared', self._service_appeared_cb)
services = service.get_services_of_type('_web_olpc._udp')
if len(services) > 0:
self._notif_service = services[0]
services = service.get_services_of_type(LocalModel.SERVICE_TYPE)
if len(services) > 0:
self._model_service = services[0]
if self._notif_service and self._model_service:
self._listen_to_model()
def _service_appeared_cb(self, pservice, service):
# Make sure the service is for our activity
if service.get_activity_id() != self._activity_id:
return
if service.get_type() == self._default_type:
self._notif_service = service
elif service.get_type() == LocalModel.SERVICE_TYPE:
@ -77,8 +80,12 @@ class BrowserActivity(Activity):
self._model_service = service
if not self._model and self._notif_service and self._model_service:
self._model = RemoteModel(self._model_service, self._notif_service)
self._model.add_listener(self.__shared_location_changed_cb)
self._listen_to_model()
def _listen_to_model(self):
self._model = RemoteModel(self._model_service, self._notif_service)
self._model.add_listener(self.__shared_location_changed_cb)
self._go_to_shared_location()
def _update_shared_location(self):
address = self.embed.get_address()
@ -90,9 +97,12 @@ class BrowserActivity(Activity):
if action_id == 'set_shared_location':
self._update_shared_location()
elif action_id == 'goto_shared_location':
address = self._model.get_value("address")
self.embed.load_address(address)
self._notif_bar.hide()
self._go_to_shared_location()
def _go_to_shared_location(self):
address = self._model.get_value("address")
self.embed.load_address(address)
self._notif_bar.hide()
def set_mode(self, mode):
self._mode = mode
@ -125,7 +135,6 @@ class BrowserActivity(Activity):
self.set_title(embed.get_title())
def __shared_location_changed_cb(self, model, key):
self.set_has_changes(True)
self._notify_shared_location_change()
def _notify_shared_location_change(self):

View File

@ -584,7 +584,7 @@ class PresenceService(object):
real_name = Service.compose_service_name(owner_nick, activity_id)
if address and type(address) != type(u""):
raise ValueError("address must be a unicode string.")
if address == None or not len(address):
if address == None and stype.endswith('_udp'):
# Use random currently unassigned multicast address
address = u"232.%d.%d.%d" % (random.randint(0, 254), random.randint(1, 254),
random.randint(1, 254))

View File

@ -12,8 +12,8 @@ from sugar import theme
theme.setup()
lw = LogWriter(sys.argv[1])
lw.start()
#lw = LogWriter(sys.argv[1])
#lw.start()
if len(sys.argv) == 4:
Activity.register_factory(sys.argv[1], sys.argv[2], sys.argv[3])

View File

@ -38,8 +38,7 @@ class LocalModel(AbstractModel):
def _setup_service(self):
service = self._pservice.share_activity(self._activity,
stype = LocalModel.SERVICE_TYPE,
address = '')
stype = LocalModel.SERVICE_TYPE)
self._setup_server(service)
# FIXME this is duplicated with StreamReader