Mercurial > libervia-web
diff src/browser/sat_browser/contact_widget.py @ 660:267761bf7f08 frontends_multi_profiles
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
- ContactPanels become the generic class for all lists of contacts
- OccupantsList will be removed
- need to implements specials icons (e.g. for games) in ContactBox
- ContactBox now manage a display arguments to set which data we want to display
- ContactsPanel.display renamed to setList
- ContactBox style can be changed when instaciating parent ContactsPanel
- muc_contact CSS class is used for list of MUC occupants
Not fully functionnal yet
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Feb 2015 22:53:27 +0100 |
parents | 6d3142b782c3 |
children | 2201ff543a05 |
line wrap: on
line diff
--- a/src/browser/sat_browser/contact_widget.py Fri Feb 27 16:05:28 2015 +0100 +++ b/src/browser/sat_browser/contact_widget.py Fri Feb 27 22:53:27 2015 +0100 @@ -21,6 +21,7 @@ from sat.core.log import getLogger log = getLogger(__name__) +from sat.core import exceptions from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.HTML import HTML from pyjamas.ui.Image import Image @@ -36,19 +37,38 @@ class ContactLabel(HTML): """Display a contact in HTML, selecting best display (jid/nick/etc)""" - def __init__(self, host, jid_): + def __init__(self, host, jid_, display=C.CONTACT_DEFAULT_DISPLAY): # TODO: add a listener for nick changes HTML.__init__(self) self.host = host - self.jid = jid_.bare - self.nick = self.host.contact_lists[C.PROF_KEY_NONE].getCache(self.jid, "nick") + self.jid = jid_ + if "nick" in display: + self.nick = self.host.contact_lists[C.PROF_KEY_NONE].getCache(self.jid, "nick") + self.display = display self.alert = False self.refresh() self.setStyleName('contactLabel') def refresh(self): alert_html = "<strong>(*)</strong> " if self.alert else "" - contact_html = html_tools.html_sanitize(self.nick or unicode(self.jid)) + contact_raw = None + for disp in self.display: + if disp == "jid": + contact_raw = unicode(self.jid) + elif disp == "nick": + contact_raw = self.nick + elif disp == "bare": + contact_raw = unicode(self.jid.bare) + elif disp == "resource": + contact_raw = self.jid.resource + else: + raise exceptions.InternalError(u"Unknown display argument [{}]".format(disp)) + if contact_raw: + break + if not contact_raw: + log.error(u"Counld not find a contact display for jid {jid} (display: {display})".format(jid=self.jid, display=self.display)) + contact_raw = "UNNAMED" + contact_html = html_tools.html_sanitize(contact_raw) html = "%(alert)s%(contact)s" % {'alert': alert_html, 'contact': contact_html} self.setHTML(html) @@ -87,25 +107,25 @@ class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel): - def __init__(self, parent, jid_): + def __init__(self, parent, jid_, style_name=None, display=C.CONTACT_DEFAULT_DISPLAY): """ @param parent (ContactPanel): ContactPanel hosting this box @param jid_ (jid.JID): contact JID """ - VerticalPanel.__init__(self, StyleName='contactBox', VerticalAlignment='middle') + VerticalPanel.__init__(self, StyleName=style_name or 'contactBox', VerticalAlignment='middle') ClickHandler.__init__(self) libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", parent.host) - self.jid = jid_.bare - self.label = ContactLabel(parent.host, self.jid) + self.jid = jid_ + self.label = ContactLabel(parent.host, self.jid, display=display) self.avatar = ContactMenuBar(self, parent.host) if parent.handle_menu else Image() - self.updateAvatar(parent.host.getAvatarURL(self.jid)) + self.updateAvatar(parent.host.getAvatarURL(self.jid.bare)) self.add(self.avatar) self.add(self.label) self.addClickListener(self) def addMenus(self, menu_bar): - menu_bar.addCachedMenus(C.MENU_ROSTER_JID_CONTEXT, {'jid': unicode(self.jid)}) - menu_bar.addCachedMenus(C.MENU_JID_CONTEXT, {'jid': unicode(self.jid)}) + menu_bar.addCachedMenus(C.MENU_ROSTER_JID_CONTEXT, {'jid': unicode(self.jid.bare)}) + menu_bar.addCachedMenus(C.MENU_JID_CONTEXT, {'jid': unicode(self.jid.bare)}) def setAlert(self, alert): """Show a visual indicator @@ -129,7 +149,7 @@ def onClick(self, sender): try: - self.parent.onClick(self.jid) + self.parent.onClick(self.jid.bare) except AttributeError: pass else: