From 15febc6620e16aa3e782b81dc3908383b2c86e35 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 13 Apr 2007 15:05:21 -0400 Subject: [PATCH 1/5] Correctly handle blank activity list --- services/presence/server_plugin.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/presence/server_plugin.py b/services/presence/server_plugin.py index 053e9925..a07c10ba 100644 --- a/services/presence/server_plugin.py +++ b/services/presence/server_plugin.py @@ -444,10 +444,6 @@ class ServerPlugin(gobject.GObject): del self._online_contacts[handle] def _contact_online_activities_cb(self, handle, activities): - if not activities or not len(activities): - logging.debug("Handle %s - No activities" % handle) - self._contact_offline(handle) - return self._buddy_activities_changed_cb(handle, activities) def _contact_online_activities_error_cb(self, handle, err): From 94431a66ebab35e02d16224cd3700cc7ac1f2a7a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 13 Apr 2007 15:15:09 -0400 Subject: [PATCH 2/5] Ensure local activities emit ActivityAppeared signal when shared --- services/presence/presenceservice.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/presence/presenceservice.py b/services/presence/presenceservice.py index 426780ff..9c7b7ede 100644 --- a/services/presence/presenceservice.py +++ b/services/presence/presenceservice.py @@ -321,6 +321,12 @@ class PresenceService(dbus.service.Object): self._activities[actid] = activity activity._share(callbacks) + # local activities are valid at creation by definition, but we can't + # connect to the activity's validity-changed signal until its already + # issued the signal, which happens in the activity's constructor + # for local activities. + self._activity_validity_changed_cb(activity, activity.props.valid) + def _activity_validity_changed_cb(self, activity, valid): if valid: self.ActivityAppeared(activity.object_path()) From 5015beaaa6fe21600398b7f9d66955a441f87f8e Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 13 Apr 2007 15:37:12 -0400 Subject: [PATCH 3/5] Clean up activity join/leave debug messages --- services/presence/presenceservice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/presence/presenceservice.py b/services/presence/presenceservice.py index 9c7b7ede..b848c825 100644 --- a/services/presence/presenceservice.py +++ b/services/presence/presenceservice.py @@ -201,7 +201,7 @@ class PresenceService(dbus.service.Object): activities_joined = new_activities - old_activities for act in activities_joined: - logging.debug("Buddy", contact_handle, "joined", act) + logging.debug("Handle %s joined activity %s" % (contact_handle, act)) activity = self._activities.get(act) if not activity: # new activity, can fail @@ -213,7 +213,7 @@ class PresenceService(dbus.service.Object): activities_left = old_activities - new_activities for act in activities_left: - logging.debug("Buddy", contact_handle, "left", act) + logging.debug("Handle %s left activity %s" % (contact_handle, act)) activity = self._activities.get(act) if not activity: continue From 182de3af1cd0c9a54199a9bd26c054f14aa5c817 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 13 Apr 2007 15:41:19 -0400 Subject: [PATCH 4/5] Remove test code --- services/presence/presenceservice.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/services/presence/presenceservice.py b/services/presence/presenceservice.py index b848c825..9fa34834 100644 --- a/services/presence/presenceservice.py +++ b/services/presence/presenceservice.py @@ -159,20 +159,7 @@ class PresenceService(dbus.service.Object): return None activity.connect("validity-changed", self._activity_validity_changed_cb) - self._activities[activity_id] = activity - - # FIXME - # Use values from the network - #import random - #names = ["Tommy", "Susie", "Jill", "Bryan", "Nathan", "Sophia", "Haley", "Jimmy"] - #name = names[random.randint(0, len(names) - 1)] - #activity.props.name = "Chat with %s" % name - #activity.props.type = "org.laptop.Sugar.Chat" - #from sugar.graphics import xocolor - #color = xocolor.XoColor().to_string() - #activity.props.color = color - return activity def _remove_activity(self, activity): From f169628cbdf980d09c0993e6cab2a6637283ac95 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 13 Apr 2007 15:42:54 -0400 Subject: [PATCH 5/5] Query non-local activity properties on discovery --- services/presence/activity.py | 4 ++++ services/presence/server_plugin.py | 28 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/services/presence/activity.py b/services/presence/activity.py index 1c1e5c8d..3638a96f 100644 --- a/services/presence/activity.py +++ b/services/presence/activity.py @@ -82,6 +82,10 @@ class Activity(DBusGObject): if self.props.local and not self.props.valid: raise RuntimeError("local activities require color, type, and name") + # If not yet valid, query activity properties + if not self.props.valid: + tp.update_activity_properties(self._id) + def do_get_property(self, pspec): if pspec.name == "id": return self._id diff --git a/services/presence/server_plugin.py b/services/presence/server_plugin.py index a07c10ba..5180692f 100644 --- a/services/presence/server_plugin.py +++ b/services/presence/server_plugin.py @@ -293,7 +293,7 @@ class ServerPlugin(gobject.GObject): img_data = _get_buddy_icon_at_size(icon_data, min(maxw, 96), min(maxh, 96), maxsize) self._conn[CONN_INTERFACE_AVATARS].SetAvatar(img_data, "image/jpeg", reply_handler=self._set_self_avatar_cb, - error_handler=lambda *args: self._log_error_cb("avatar", *args)) + error_handler=lambda *args: self._log_error_cb("setting avatar", *args)) def _join_activity_create_channel_cb(self, activity_id, signal, handle, userdata, chan_path): channel = Channel(self._conn._dbus_object._named_service, chan_path) @@ -340,7 +340,7 @@ class ServerPlugin(gobject.GObject): pass def _log_error_cb(self, msg, err): - logging.debug("Error setting %s: %s" % (msg, err)) + logging.debug("Error %s: %s" % (msg, err)) def _set_self_olpc_properties(self, set_key=False): props = {} @@ -349,19 +349,19 @@ class ServerPlugin(gobject.GObject): props['key'] = dbus.ByteArray(self._owner.props.key) self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props, reply_handler=self._ignore_success_cb, - error_handler=lambda *args: self._log_error_cb("properties", *args)) + error_handler=lambda *args: self._log_error_cb("setting properties", *args)) def _set_self_alias(self): alias = self._owner.props.nick self_handle = self._conn[CONN_INTERFACE].GetSelfHandle() self._conn[CONN_INTERFACE_ALIASING].SetAliases({self_handle : alias}, reply_handler=self._ignore_success_cb, - error_handler=lambda *args: self._log_error_cb("alias", *args)) + error_handler=lambda *args: self._log_error_cb("setting alias", *args)) def _set_self_activities(self): self._conn[CONN_INTERFACE_BUDDY_INFO].SetActivities(self._joined_activities, reply_handler=self._ignore_success_cb, - error_handler=lambda *args: self._log_error_cb("activities", *args)) + error_handler=lambda *args: self._log_error_cb("setting activities", *args)) def _set_self_current_activity(self): cur_activity = self._owner.props.current_activity @@ -378,7 +378,7 @@ class ServerPlugin(gobject.GObject): self._conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity, cur_activity_handle, reply_handler=self._ignore_success_cb, - error_handler=lambda *args: self._log_error_cb("current activity", *args)) + error_handler=lambda *args: self._log_error_cb("setting current activity", *args)) def _get_handle_for_activity(self, activity_id): for (act, handle) in self._joined_activities: @@ -594,16 +594,26 @@ class ServerPlugin(gobject.GObject): channel_type in [CHANNEL_TYPE_TEXT, CHANNEL_TYPE_STREAMED_MEDIA]: self.emit("private-invitation", object_path) + def update_activity_properties(self, act_id): + handle = self._activities.get(act_id) + if not handle: + raise RuntimeError("Unknown activity %s: couldn't find handle.") + + self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].GetProperties(handle, + reply_handler=lambda *args: self._activity_properties_changed_cb(handle, *args), + error_handler=lambda *args: self._log_error_cb("getting activity properties", *args)) + def set_activity_properties(self, act_id, props): handle = self._activities.get(act_id) if not handle: - logging.debug("set_activity_properties: handle unknown") - return + raise RuntimeError("Unknown activity %s: couldn't find handle.") + self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].SetProperties(handle, props, reply_handler=self._ignore_success_cb, - error_handler=lambda *args: self._log_error_cb("activity properties", *args)) + error_handler=lambda *args: self._log_error_cb("setting activity properties", *args)) def _activity_properties_changed_cb(self, room, properties): for act_id, act_handle in self._activities.items(): if room == act_handle: self.emit("activity-properties-changed", act_id, properties) + return