quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate

This commit is contained in:
Goffi 2015-02-24 17:14:10 +01:00
commit 8f5b116211
4 changed files with 19 additions and 2 deletions

View file

@ -152,6 +152,9 @@ class ContactList(PrimitivusWidget, QuickContactList):
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):

View file

@ -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 @@ class Const(constants.Const):
WIDGET_RAISE = 'RAISE'
WIDGET_RECREATE = 'RECREATE'
LISTENERS = {'avatar', 'presence'}
LISTENERS = {'avatar', 'nick', 'presence'}

View file

@ -313,6 +313,8 @@ class QuickApp(object):
@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 @@ class QuickApp(object):
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):

View file

@ -75,6 +75,8 @@ class QuickContactList(QuickWidget):
# 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 @@ class QuickContactList(QuickWidget):
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()