quich frontend, primivius (chat): better avatar handling:
- new getAvatar method in QuickApp which request vCard if avatar if needed and return default avatar is no avatar is found
- frontends based on quick frontend can now specify if they handle avatar or not using AVATARS_HANDLER
- when avatar is updated, occupant widget(s) and all message widget(s) of the concerned entity are updated
This commit is contained in:
parent
42167b6ae9
commit
78750cb265
4 changed files with 42 additions and 7 deletions
|
|
@ -600,7 +600,7 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
|
||||
def onDelete(self):
|
||||
# FIXME: to be checked after refactoring
|
||||
quick_chat.QuickChat.onDelete(self)
|
||||
super(Chat, self).onDelete()
|
||||
if self.type == C.CHAT_GROUP:
|
||||
self.host.removeListener('presence', self.presenceListener)
|
||||
|
||||
|
|
|
|||
|
|
@ -272,7 +272,8 @@ class PrimitivusTopWidget(sat_widgets.FocusPile):
|
|||
|
||||
|
||||
class PrimitivusApp(QuickApp, InputHistory):
|
||||
MB_HANDLE = False
|
||||
MB_HANDLER = False
|
||||
AVATAR_HANDLER = False
|
||||
|
||||
def __init__(self):
|
||||
QuickApp.__init__(self, create_bridge=DBusBridgeFrontend, xmlui=xmlui, check_options=quick_utils.check_options)
|
||||
|
|
|
|||
|
|
@ -186,7 +186,8 @@ class ProfilesManager(object):
|
|||
|
||||
class QuickApp(object):
|
||||
"""This class contain the main methods needed for the frontend"""
|
||||
MB_HANDLE = True # Set to false if the frontend doesn't manage microblog
|
||||
MB_HANDLER = True # Set to False if the frontend doesn't manage microblog
|
||||
AVATARS_HANDLER = True # set to False if avatars are not used
|
||||
|
||||
def __init__(self, create_bridge, xmlui, check_options=None):
|
||||
"""Create a frontend application
|
||||
|
|
@ -670,7 +671,7 @@ class QuickApp(object):
|
|||
"""
|
||||
service_s = jid.JID(service_s)
|
||||
|
||||
if category == C.PS_MICROBLOG and self.MB_HANDLE:
|
||||
if category == C.PS_MICROBLOG and self.MB_HANDLER:
|
||||
if event_type == C.PS_PUBLISH:
|
||||
if not 'content' in data:
|
||||
log.warning("No content found in microblog data")
|
||||
|
|
@ -831,6 +832,17 @@ class QuickApp(object):
|
|||
|
||||
self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
|
||||
|
||||
def getAvatar(self, entity, profile):
|
||||
"""return avatar path for an entity"""
|
||||
contact_list = self.contact_lists[profile]
|
||||
avatar = contact_list.getCache(entity, "avatar")
|
||||
if avatar is None:
|
||||
self.bridge.getCard(unicode(entity), profile)
|
||||
contact_list.setCache(entity, "avatar", "")
|
||||
if not avatar:
|
||||
avatar = self.getDefaultAvatar(entity)
|
||||
return avatar
|
||||
|
||||
def getDefaultAvatar(self, entity=None):
|
||||
"""return default avatar to use with given entity
|
||||
|
||||
|
|
|
|||
|
|
@ -117,8 +117,7 @@ class Message(object):
|
|||
|
||||
@property
|
||||
def avatar(self):
|
||||
contact_list = self.host.contact_lists[self.profile]
|
||||
return contact_list.getCache(self.from_jid, "avatar") or self.host.getDefaultAvatar(self.from_jid)
|
||||
return self.host.getAvatar(self.from_jid, self.profile)
|
||||
|
||||
def getNick(self, entity):
|
||||
"""Return nick of an entity when possible"""
|
||||
|
|
@ -167,7 +166,6 @@ class Message(object):
|
|||
self.message[lang] = u"* " + nick + mess[3:]
|
||||
|
||||
|
||||
|
||||
class Occupant(object):
|
||||
"""Occupant metadata"""
|
||||
|
||||
|
|
@ -216,6 +214,10 @@ class Occupant(object):
|
|||
for w in self.widgets:
|
||||
w.updated(["state"])
|
||||
|
||||
def update(self, key=None):
|
||||
for w in self.widgets:
|
||||
w.update(key)
|
||||
|
||||
|
||||
class QuickChat(quick_widgets.QuickWidget):
|
||||
visible_states = ['chat_state'] # FIXME: to be removed, used only in quick_games
|
||||
|
|
@ -249,6 +251,8 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.subject = subject
|
||||
lt = time.localtime()
|
||||
self.day_change = (lt.tm_year, lt.tm_mon, lt.tm_mday, 0, 0, 0, lt.tm_wday, lt.tm_yday, lt.tm_isdst) # struct_time of day changing time
|
||||
if self.host.AVATARS_HANDLER:
|
||||
self.host.addListener('avatar', self.onAvatar, profiles)
|
||||
|
||||
def postInit(self):
|
||||
"""Method to be called by frontend after widget is initialised
|
||||
|
|
@ -259,6 +263,10 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
if self.subject is not None:
|
||||
self.setSubject(self.subject)
|
||||
|
||||
def onDelete(self):
|
||||
if self.host.AVATARS_HANDLER:
|
||||
self.host.removeListener('avatar', self.onAvatar)
|
||||
|
||||
@property
|
||||
def contact_list(self):
|
||||
return self.host.contact_lists[self.profile]
|
||||
|
|
@ -539,6 +547,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
|
||||
@param entity (jid.JID): entity to update
|
||||
"""
|
||||
# FIXME: to remove ?
|
||||
raise NotImplementedError
|
||||
|
||||
## events ##
|
||||
|
|
@ -561,5 +570,18 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
else:
|
||||
mess_data.status = status
|
||||
|
||||
def onAvatar(self, entity, filename, profile):
|
||||
if self.type == C.CHAT_GROUP:
|
||||
if entity.bare == self.target and entity.resource in self.occupants:
|
||||
self.occupants[entity.resource].update('avatar')
|
||||
for m in self.messages.values():
|
||||
if m.nick == entity.resource:
|
||||
for w in m.widgets:
|
||||
w.update('avatar', filename)
|
||||
else:
|
||||
if entity.bare == self.target.bare:
|
||||
log.info("entity avatar updated")
|
||||
# TODO: call a specific method
|
||||
|
||||
|
||||
quick_widgets.register(QuickChat)
|
||||
|
|
|
|||
Loading…
Reference in a new issue