Mercurial > libervia-web
diff src/browser/sat_browser/base_panels.py @ 647:e0021d571eef frontends_multi_profiles
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Feb 2015 13:10:46 +0100 |
parents | 32dbbc941123 |
children |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_panels.py Wed Feb 25 19:44:10 2015 +0100 +++ b/src/browser/sat_browser/base_panels.py Thu Feb 26 13:10:46 2015 +0100 @@ -22,6 +22,7 @@ log = getLogger(__name__) from sat.core.i18n import _ from sat_frontends.tools import strings +from sat_frontends.tools import jid from pyjamas.ui.AbsolutePanel import AbsolutePanel from pyjamas.ui.VerticalPanel import VerticalPanel @@ -39,9 +40,11 @@ from pyjamas import DOM import html_tools +import base_widget from constants import Const as C + class Occupant(HTML): """Occupant of a MUC room""" @@ -84,6 +87,90 @@ self.setHTML("%s%s%s" % (html_tools.html_sanitize(self.nick), special, state)) +class ContactsPanel(VerticalPanel): + """ContactList graphic representation + + Special features like popup menu panel or changing the contact states must be done in a sub-class. + """ + + def __init__(self, parent, on_click=None, handle_menu=True): + """ + @param on_click (callable): click callback (used if ContactBox is created) + @param handle_menu (bool): if True, bind a popup menu to the avatar (used if ContactBox is created) + """ # FIXME + VerticalPanel.__init__(self) + self._parent = parent + self.host = parent.host + self._contacts = {} # entity jid to ContactBox map + self.click_listener = None + self.handle_menu = handle_menu + + if on_click is not None: + self.onClick = on_click + + def display(self, jids): + """Display a contact in the list. + + @param jids (list[jid.JID]): jids to display (the order is kept) + @param name (unicode): optional name of the contact + """ + # FIXME: we do a full clear and add boxes after, we should only remove recently hidden boxes and add new ones, and re-order + current = [box.jid for box in self.children if isinstance(box, base_widget.ContactBox)] + if current == jids: + # the display doesn't change + return + self.clear() + for jid_ in jids: + assert isinstance(jid_, jid.JID) + box = self.getContactBox(jid_) + VerticalPanel.append(self, box) + + def isContactPresent(self, contact_jid): + """Return True if a contact is present in the panel""" + return contact_jid in self._contacts + + def getContacts(self): + return self._contacts + + def getContactBox(self, contact_jid): + """get the Contactbox of a contact + + if the Contactbox doesn't exists, it will be created + @param contact_jid (jid.JID): the contact + @return: ContactBox instance + """ + try: + return self._contacts[contact_jid.bare] + except KeyError: + box = base_widget.ContactBox(self, contact_jid) + self._contacts[contact_jid.bare] = box + return box + + def updateAvatar(self, jid_, url): + """Update the avatar of the given contact + + @param jid_ (jid.JID): contact jid + @param url (unicode): image url + """ + try: + self.getContactBox(jid_).updateAvatar(url) + except TypeError: + pass + + def updateNick(self, jid_, new_nick): + """Update the avatar of the given contact + + @param jid_ (jid.JID): contact jid + @param new_nick (unicode): new nick of the contact + """ + try: + self.getContactBox(jid_).updateNick(new_nick) + except TypeError: + pass + + + +# FIXME: must be removed and ContactsPanel must be used instead class OccupantsList(AbsolutePanel): """Panel user to show occupants of a room"""