changeset 607:537649f6a2d0 frontends_multi_profiles

browser side (blog, contact list): use of new listener mechanism to update avatar
author Goffi <goffi@goffi.org>
date Mon, 09 Feb 2015 21:56:30 +0100
parents 7af8f4ab3675
children ea27925ef2a8
files src/browser/sat_browser/blog.py src/browser/sat_browser/contact_list.py
diffstat 2 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/sat_browser/blog.py	Mon Feb 09 21:55:16 2015 +0100
+++ b/src/browser/sat_browser/blog.py	Mon Feb 09 21:56:30 2015 +0100
@@ -374,6 +374,7 @@
         self.vpanel = VerticalPanel()
         self.vpanel.setStyleName('microblogPanel')
         self.setWidget(self.vpanel)
+        host.addListerner('avatar', self.onAvatarUpdate)
 
     def __str__(self):
         return u"Blog Widget [target: {}, profile: {}]".format(self.target, self.profile)
@@ -382,6 +383,21 @@
     def target(self):
         return tuple(self.accepted_groups)
 
+    def onDelete(self):
+        quick_widgets.QuickWidget.onDelete(self)
+        self.host.removeListener('avatar', self.onAvatarUpdate)
+
+    def onAvatarUpdate(self, jid_, hash_, profile):
+        """Called on avatar update events
+
+        @param jid_: jid of the entity with updated avatar
+        @param hash_: hash of the avatar
+        @param profile: should be C.PROF_KEY_NONE
+        """
+        whoami = self.host.profiles[self.profile].whoami.bare
+        if self.isJidAccepted(jid_) or jid_.bare  == whoami.bare:
+            self.updateValue('avatar', jid_, hash_)
+
     def refresh(self):
         """Refresh the display of this widget. If the unibox is disabled,
         display the 'New message' button or an empty bubble on top of the panel"""
--- a/src/browser/sat_browser/contact_list.py	Mon Feb 09 21:55:16 2015 +0100
+++ b/src/browser/sat_browser/contact_list.py	Mon Feb 09 21:56:30 2015 +0100
@@ -335,11 +335,16 @@
         self.add(self.scroll_panel)
         self.setStyleName('contactList')
         Window.addWindowResizeListener(self)
+        host.addListerner('avatar', self.onAvatarUpdate)
 
     @property
     def profile(self):
         return C.PROF_KEY_NONE
 
+    def onDelete(self):
+        QuickContactList.onDelete(self)
+        self.host.removeListener('avatar', self.onAvatarUpdate)
+
     def update(self):
         ### GROUPS ###
         _keys = self._groups.keys()
@@ -535,6 +540,15 @@
         """
         self._contacts_panel.updateAvatar(jid_s, url)
 
+    def onAvatarUpdate(self, jid_, hash_, profile):
+        """Called on avatar update events
+
+        @param jid_: jid of the entity with updated avatar
+        @param hash_: hash of the avatar
+        @param profile: should be C.PROF_KEY_NONE
+        """
+        self._contacts_panel.updateAvatar(jid_, self.host.getAvatarURL(jid_))
+
     def hasVisibleMembers(self, group):
         """Tell if the given group actually has visible members