From 40483bb8561895241675018f4a7c4a78368b1f24 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 19 Jun 2006 15:10:37 -0400 Subject: [PATCH 1/3] Don't share an activity if it's name doesn't match our owner's nickname --- sugar/presence/PresenceService.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sugar/presence/PresenceService.py b/sugar/presence/PresenceService.py index 7063b413..dc563b26 100644 --- a/sugar/presence/PresenceService.py +++ b/sugar/presence/PresenceService.py @@ -514,6 +514,8 @@ class PresenceService(gobject.GObject): raise RuntimeError("presence service must be started first.") rs_name = service.get_name() + if self.get_owner() and rs_name != self.get_owner().get_nick_name(): + raise RuntimeError("Tried to register a service that didn't have Owner nick as the service name!") rs_stype = service.get_full_type() rs_port = service.get_port() rs_props = service.get_properties() From e7f9a0a72827dfdd175d2e25d1472654bcb552b7 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 19 Jun 2006 15:12:24 -0400 Subject: [PATCH 2/3] When serializing an activity, allow using the owner's nick name for the service name --- sugar/presence/Service.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sugar/presence/Service.py b/sugar/presence/Service.py index e1232f68..e3885adc 100644 --- a/sugar/presence/Service.py +++ b/sugar/presence/Service.py @@ -143,9 +143,12 @@ class Service(object): if uid and not self._properties.has_key(_ACTIVITY_UID_TAG): self._properties[_ACTIVITY_UID_TAG] = uid - def serialize(self): + def serialize(self, owner=None): sdict = {} - sdict['name'] = dbus.Variant(self._name) + if owner is not None: + sdict['name'] = dbus.Variant(owner.get_nick_name()) + else: + sdict['name'] = dbus.Variant(self._name) sdict['full_stype'] = dbus.Variant(self._full_stype) sdict['activity_stype'] = dbus.Variant(self._activity_stype) sdict['domain'] = dbus.Variant(self._domain) From 028f033344962f7a481adcf48aeecce9349b13d6 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 19 Jun 2006 15:12:56 -0400 Subject: [PATCH 3/3] Need to change the activity service's name to the owners name before passing it along to the new activity that we're going to join. --- sugar/shell/StartPage.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/sugar/shell/StartPage.py b/sugar/shell/StartPage.py index 518315ed..5251b0ed 100644 --- a/sugar/shell/StartPage.py +++ b/sugar/shell/StartPage.py @@ -92,6 +92,8 @@ class ActivitiesModel(gtk.ListStore): class ActivitiesView(gtk.TreeView): def __init__(self, model): gtk.TreeView.__init__(self, model) + + self._owner = None self.set_headers_visible(False) @@ -130,7 +132,10 @@ class ActivitiesView(gtk.TreeView): cell.set_property('markup', markup) cell.set_property('ellipsize', pango.ELLIPSIZE_END) - + + def set_owner(self, owner): + self._owner = owner + def _row_activated_cb(self, treeview, path, column): bus = dbus.SessionBus() proxy_obj = bus.get_object('com.redhat.Sugar.Browser', '/com/redhat/Sugar/Browser') @@ -145,7 +150,9 @@ class ActivitiesView(gtk.TreeView): if service is None: browser_shell.open_browser(address) else: - serialized_service = service.serialize() + if not self._owner: + raise RuntimeError("We don't have an owner yet!") + serialized_service = service.serialize(self._owner) browser_shell.open_browser(address, serialized_service) class StartPage(gtk.HBox): @@ -161,6 +168,8 @@ class StartPage(gtk.HBox): self._pservice = PresenceService.get_instance() self._pservice.connect("activity-announced", self._on_activity_announced_cb) self._pservice.connect("new-service-adv", self._on_new_service_adv_cb) + self._pservice.connect("buddy-appeared", self._on_buddy_appeared_cb) + self._pservice.connect("buddy-disappeared", self._on_buddy_disappeared_cb) self._pservice.start() self._pservice.track_service_type(BrowserActivity._BROWSER_ACTIVITY_TYPE) @@ -222,6 +231,7 @@ class StartPage(gtk.HBox): self._activities_model = ActivitiesModel() + owner = self._pservice.get_owner() self._activities = ActivitiesView(self._activities_model) sw.add(self._activities) self._activities.show() @@ -245,6 +255,14 @@ class StartPage(gtk.HBox): if activity_id: self._pservice.track_service_type(short_stype) + def _on_buddy_appeared_cb(self, pservice, buddy): + if buddy.is_owner(): + self._activities.set_owner(buddy) + + def _on_buddy_disappeared_cb(self, pservice, buddy): + if buddy.is_owner() and self._owner == buddy: + self._activities.set_owner(None) + def _on_activity_announced_cb(self, pservice, service, buddy): print "Found new activity with type %s" % service.get_full_type() self._activities_model.add_activity(buddy, service)