changeset 1342:e31a07a5614d frontends_multi_profiles

quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
author Goffi <goffi@goffi.org>
date Tue, 24 Feb 2015 17:14:10 +0100
parents 6dbeb2ef966c
children ec9e58357a07
files frontends/src/primitivus/contact_list.py frontends/src/quick_frontend/constants.py frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_contact_list.py
diffstat 4 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py	Tue Feb 24 17:01:33 2015 +0100
+++ b/frontends/src/primitivus/contact_list.py	Tue Feb 24 17:14:10 2015 +0100
@@ -152,6 +152,9 @@
         super(ContactList, self).onPresenceUpdate(entity, show, priority, statuses, profile)
         self.update()
 
+    def onNickUpdate(self, entity, new_nick, profile):
+        self.update()
+
     # Methods to build the widget
 
     def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_alert=True, with_show_attr=True, markup_prepend=None, markup_append = None):
--- a/frontends/src/quick_frontend/constants.py	Tue Feb 24 17:01:33 2015 +0100
+++ b/frontends/src/quick_frontend/constants.py	Tue Feb 24 17:14:10 2015 +0100
@@ -18,7 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from sat.core import constants
-from sat.core.i18n import _, D_
+from sat.core.i18n import _
 from collections import OrderedDict  # only available from python 2.7
 
 
@@ -71,4 +71,4 @@
     WIDGET_RAISE = 'RAISE'
     WIDGET_RECREATE = 'RECREATE'
 
-    LISTENERS = {'avatar', 'presence'}
+    LISTENERS = {'avatar', 'nick', 'presence'}
--- a/frontends/src/quick_frontend/quick_app.py	Tue Feb 24 17:01:33 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Tue Feb 24 17:14:10 2015 +0100
@@ -313,6 +313,8 @@
         @param type_: type of event, can be:
             - avatar: called when avatar data is updated
                       args: (entity, avatar file, profile)
+            - nick: called when nick data is updated
+                      args: (entity, new_nick, profile)
             - presence: called when a presence is received
                          args: (entity, show, priority, statuses, profile)
         @param callback: method to call on event
@@ -685,6 +687,7 @@
         if key == "nick":
             if entity in self.contact_lists[profile]:
                 self.contact_lists[profile].setCache(entity, 'nick', value)
+                self.callListeners('nick', entity, value, profile=profile)
         elif key == "avatar":
             if entity in self.contact_lists[profile]:
                 def gotFilename(filename):
--- a/frontends/src/quick_frontend/quick_contact_list.py	Tue Feb 24 17:01:33 2015 +0100
+++ b/frontends/src/quick_frontend/quick_contact_list.py	Tue Feb 24 17:14:10 2015 +0100
@@ -75,6 +75,8 @@
         # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
         self.presenceListener = self.onPresenceUpdate
         self.host.addListener('presence', self.presenceListener, [profile])
+        self.nickListener = self.onNickUpdate
+        self.host.addListener('nick', self.nickListener, [profile])
 
     def __contains__(self, entity):
         """Check if entity is in contact list
@@ -399,6 +401,15 @@
             priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY])
             cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
 
+    def onNickUpdate(self, entity, new_nick, profile):
+        """Update entity's nick
+
+        @param entity(jid.JID): entity updated
+        @param new_nick(unicode): new nick of the entity
+        @param profile: %(doc_profile)s
+        """
+        raise NotImplementedError # Must be implemented by frontends
+
     def unselectAll(self):
         """Unselect all contacts"""
         self._selected.clear()