Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar

Conflicts:

	services/presence/server_plugin.py
This commit is contained in:
Simon McVittie
2007-05-16 12:30:49 +01:00
6 changed files with 93 additions and 35 deletions
+45 -18
View File
@@ -622,7 +622,10 @@ class ServerPlugin(gobject.GObject):
def cleanup(self):
"""If we still have a connection, disconnect it"""
if self._conn:
self._conn[CONN_INTERFACE].Disconnect()
try:
self._conn[CONN_INTERFACE].Disconnect()
except:
pass
self._conn = None
self._conn_status = CONNECTION_STATUS_DISCONNECTED
@@ -670,10 +673,16 @@ class ServerPlugin(gobject.GObject):
reply_handler=lambda *args: self._contact_online_activities_cb(handle, *args),
error_handler=lambda *args: self._contact_online_activities_error_cb(handle, *args))
def _contact_online_aliases_error_cb(self, handle, err):
def _contact_online_aliases_error_cb(self, handle, props, retry, err):
"""Handle failure to retrieve given user's alias/information"""
_logger.debug("Handle %s - Error getting nickname: %s" % (handle, err))
self._contact_offline(handle)
if retry:
_logger.debug("Handle %s - Error getting nickname (will retry): %s" % (handle, err))
self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle],
reply_handler=lambda *args: self._contact_online_aliases_cb(handle, props, *args),
error_handler=lambda *args: self._contact_online_aliases_error_cb(handle, props, False, *args))
else:
_logger.debug("Handle %s - Error getting nickname: %s" % (handle, err))
self._contact_offline(handle)
def _contact_online_properties_cb(self, handle, props):
"""Handle failure to retrieve given user's alias/information"""
@@ -691,12 +700,23 @@ class ServerPlugin(gobject.GObject):
self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle],
reply_handler=lambda *args: self._contact_online_aliases_cb(handle, props, *args),
error_handler=lambda *args: self._contact_online_aliases_error_cb(handle, *args))
def _contact_online_properties_error_cb(self, handle, err):
"""Handle error retrieving property-set for a user (handle)"""
_logger.debug("Handle %s - Error getting properties: %s" % (handle, err))
self._contact_offline(handle)
error_handler=lambda *args: self._contact_online_aliases_error_cb(handle, props, True, *args))
def _contact_online_request_properties(self, handle, tries):
self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle,
reply_handler=lambda *args: self._contact_online_properties_cb(handle, *args),
error_handler=lambda *args: self._contact_online_properties_error_cb(handle, tries, *args))
return False
def _contact_online_properties_error_cb(self, handle, tries, err):
"""Handle error retrieving property-set for a user (handle)"""
if tries <= 3:
_logger.debug("Handle %s - Error getting properties (will retry): %s" % (handle, err))
tries += 1
gobject.timeout_add(1000, self._contact_online_request_properties, handle, tries)
else:
_logger.debug("Handle %s - Error getting properties: %s" % (handle, err))
self._contact_offline(handle)
def _contact_online(self, handle):
"""Handle a contact coming online"""
@@ -715,9 +735,7 @@ class ServerPlugin(gobject.GObject):
# are handled locally
return
self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle,
reply_handler=lambda *args: self._contact_online_properties_cb(handle, *args),
error_handler=lambda *args: self._contact_online_properties_error_cb(handle, *args))
self._contact_online_request_properties(handle, 1)
def _subscribe_members_changed_cb(self, added, removed, local_pending,
remote_pending, actor, reason):
@@ -765,6 +783,15 @@ class ServerPlugin(gobject.GObject):
elif status in ["offline", "invisible"]:
self._contact_offline(handle)
def _request_avatar_cb(self, handle, new_avatar_token, avatar, mime_type):
jid = self._online_contacts[handle]
if not jid:
logging.debug("Handle %s not valid yet..." % handle)
return
icon = ''.join(map(chr, avatar))
self._icon_cache.store_icon(jid, new_avatar_token, icon)
self.emit("avatar-updated", handle, icon)
def _avatar_updated_cb(self, handle, new_avatar_token):
"""Handle update of given user (handle)'s avatar"""
if handle == self._conn[CONN_INTERFACE].GetSelfHandle():
@@ -784,11 +811,11 @@ class ServerPlugin(gobject.GObject):
icon = self._icon_cache.get_icon(jid, new_avatar_token)
if not icon:
# cache miss
avatar, mime_type = self._conn[CONN_INTERFACE_AVATARS].RequestAvatar(handle)
icon = ''.join(map(chr, avatar))
self._icon_cache.store_icon(jid, new_avatar_token, icon)
self.emit("avatar-updated", handle, icon)
self._conn[CONN_INTERFACE_AVATARS].RequestAvatar(handle,
reply_handler=lambda *args: self._request_avatar_cb(handle, new_avatar_token, *args),
error_handler=lambda *args: self._log_error_cb("getting avatar", *args))
else:
self.emit("avatar-updated", handle, icon)
def _alias_changed_cb(self, aliases):
"""Handle update of aliases for all users"""