diff --git a/services/presence2/buddy.py b/services/presence2/buddy.py index e74c1b1a..1b51ae8e 100644 --- a/services/presence2/buddy.py +++ b/services/presence2/buddy.py @@ -161,7 +161,7 @@ class Buddy(dbus.service.Object): def _set_color(self, color): self._color = color - def set_properties(self, prop): + def set_properties(self, properties): if "name" in properties.keys(): self._set_name(properties["name"]) if "color" in properties.keys(): diff --git a/services/presence2/presenceservice.py b/services/presence2/presenceservice.py index 9dee12f9..f3739e38 100644 --- a/services/presence2/presenceservice.py +++ b/services/presence2/presenceservice.py @@ -78,8 +78,9 @@ class PresenceService(dbus.service.Object): def _server_status_cb(self, plugin, status, reason): pass - def _contact_online(self, tp, handle, key): + def _contact_online(self, tp, handle, props): new_buddy = False + key = props['key'] buddy = self._buddies.get(key) if not buddy: @@ -99,6 +100,7 @@ class PresenceService(dbus.service.Object): if new_buddy: self.BuddyAppeared(buddy.object_path()) + buddy.set_properties(props) def _contact_offline(self, tp, handle): buddy = self._handles[tp].pop(handle) diff --git a/services/presence2/server_plugin.py b/services/presence2/server_plugin.py index bc7f9473..02623a68 100644 --- a/services/presence2/server_plugin.py +++ b/services/presence2/server_plugin.py @@ -194,10 +194,11 @@ class ServerPlugin(gobject.GObject): # hack self._conn._valid_interfaces.add(CONN_INTERFACE_ALIASING) - if CONN_INTERFACE_ALIASING in self._conn: - aliases = self._conn[CONN_INTERFACE_ALIASING].RequestAliases(subscribe_handles) - else: - aliases = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, subscribe_handles) + self._conn[CONN_INTERFACE_ALIASING].connect_to_signal('AliasesChanged', self._alias_changed_cb) + #if CONN_INTERFACE_ALIASING in self._conn: + # aliases = self._conn[CONN_INTERFACE_ALIASING].RequestAliases(subscribe_handles) + #else: + # aliases = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, subscribe_handles) #for handle, alias in zip(subscribe_handles, aliases): # print alias @@ -225,9 +226,12 @@ class ServerPlugin(gobject.GObject): props = {} props['color'] = profile.get_color().to_string() props['key'] = profile.get_pubkey() - props['nick'] = profile.get_nick_name() self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props) + name = profile.get_nick_name() + self_handle = self._conn[CONN_INTERFACE].GetSelfHandle() + self._conn[CONN_INTERFACE_ALIASING].SetAliases( {self_handle : name} ) + types, minw, minh, maxw, maxh, maxsize = self._conn[CONN_INTERFACE_AVATARS].GetAvatarRequirements() if not "image/jpeg" in types: print "server does not accept JPEG format avatars." @@ -287,17 +291,17 @@ class ServerPlugin(gobject.GObject): if str(e).startswith("org.freedesktop.DBus.Error.NoReply"): raise InvalidBuddyError("couldn't get properties") + name = self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0] + if not props.has_key('color'): raise InvalidBuddyError("no color") - if not props.has_key('nick'): - raise InvalidBuddyError("no nick name") if not props.has_key('key'): raise InvalidBuddyError("no key") - - key = props['key'] + if not name: + raise InvalidBuddyError("no name") self._online_contacts.add(handle) - self.emit("contact-online", handle, key) + self.emit("contact-online", handle, props) def _presence_update_cb(self, presence): for handle in presence: @@ -328,6 +332,14 @@ class ServerPlugin(gobject.GObject): self.emit("avatar-updated", handle, icon) + def _alias_changed_cb(self, aliases): + print "alias changed cb" + for handle, alias in aliases: + name = self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0] + print "new alias", handle, alias, name + prop = {'name': name} + self._properties_changed_cb(handle, prop) + def _properties_changed_cb(self, contact, properties): self.emit("properties-changed", contact, properties)