From aaaa946098d351806c776eed7c3069ecd421b83a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 11 Jun 2007 22:33:58 +0000 Subject: Use RequestAvatars rather than RequestAvatar, for increased asynchronousness --- diff --git a/src/buddy.py b/src/buddy.py index 96698c8..82e6b2a 100644 --- a/src/buddy.py +++ b/src/buddy.py @@ -601,29 +601,24 @@ class Buddy(ExportedGObject): except AttributeError: self._valid = False - def update_avatar(self, tp, new_avatar_token): + def update_avatar(self, tp, new_avatar_token, icon=None, mime_type=None): """Handle update of the avatar""" conn = tp.get_connection() handle, identifier = self._handles[tp] - icon = buddy_icon_cache.get_icon(conn.object_path, identifier, - new_avatar_token) - if not icon: - # cache miss - def got_avatar(avatar, mime_type): - icon = str(icon) - buddy_icon_cache.store_icon(conn.object_path, identifier, - new_avatar_token, icon) - if self._icon != icon: - self._icon = icon - self.IconChanged(self._icon) - - conn[CONN_INTERFACE_AVATARS].RequestAvatar(handle, - reply_handler=got_avatar, - error_handler=lambda e: - _logger.warning('Error getting avatar for %r: %s', - self, e), - byte_arrays=True) + if icon is None: + icon = buddy_icon_cache.get_icon(conn.object_path, identifier, + new_avatar_token) + else: + buddy_icon_cache.store_icon(conn.object_path, identifier, + new_avatar_token, icon) + + if icon is None: + # this was AvatarUpdated not AvatarRetrieved, and then we got a + # cache miss - request an AvatarRetrieved signal so we can get the + # actual icon + conn[CONN_INTERFACE_AVATARS].RequestAvatars([handle], + ignore_reply=True) else: if self._icon != icon: self._icon = icon @@ -831,7 +826,7 @@ class GenericOwner(Buddy): """Customisation point: handle the registration of the owner""" raise RuntimeError("Subclasses must implement") - def update_avatar(self, tp, new_avatar_token): + def update_avatar(self, tp, new_avatar_token, icon=None, mime_type=None): # This should never get called because Owner avatar changes are # driven by the Sugar shell, but just in case: _logger.warning('GenericOwner.update_avatar() should not be called') diff --git a/src/presenceservice.py b/src/presenceservice.py index 28c4e53..5fac8a9 100644 --- a/src/presenceservice.py +++ b/src/presenceservice.py @@ -203,6 +203,13 @@ class PresenceService(ExportedGObject): conn.object_path) if CONN_INTERFACE_AVATARS in conn: + def avatar_retrieved(contact, avatar_token, avatar, mime_type): + self._avatar_updated(tp, contact, avatar_token, avatar, + mime_type) + m = conn[CONN_INTERFACE_AVATARS].connect_to_signal( + 'AvatarRetrieved', avatar_retrieved) + self._conn_matches[conn].append(m) + def avatar_updated(contact, avatar_token): self._avatar_updated(tp, contact, avatar_token) m = conn[CONN_INTERFACE_AVATARS].connect_to_signal('AvatarUpdated', @@ -302,11 +309,12 @@ class PresenceService(ExportedGObject): self._next_object_id = self._next_object_id + 1 return self._next_object_id - def _avatar_updated(self, tp, handle, new_avatar_token): + def _avatar_updated(self, tp, handle, new_avatar_token, avatar=None, + mime_type=None): buddy = self._handles_buddies[tp].get(handle) if buddy is not None and buddy is not self._owner: _logger.debug("Buddy %s icon updated" % buddy.props.nick) - buddy.update_avatar(tp, new_avatar_token) + buddy.update_avatar(tp, new_avatar_token, avatar, mime_type) def _buddy_properties_changed(self, tp, handle, properties): buddy = self._handles_buddies[tp].get(handle) -- cgit v0.9.1