Mercurial > libervia-web
changeset 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 | 8e7d4de56e75 |
children | 2664fe93ceb3 |
files | src/browser/public/libervia.css src/browser/sat_browser/chat.py src/browser/sat_browser/constants.py src/browser/sat_browser/contact_list.py src/browser/sat_browser/contact_panel.py src/browser/sat_browser/contact_widget.py |
diffstat | 6 files changed, 69 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/public/libervia.css Fri Feb 27 16:05:28 2015 +0100 +++ b/src/browser/public/libervia.css Fri Feb 27 22:53:27 2015 +0100 @@ -539,6 +539,14 @@ background-color: rgb(175, 175, 175); } +/* Contacts in MUC */ + +.muc_contact { + border-radius: 5px; + background: #EDEDED; + margin: 2px; +} + /* START - contact presence status */ .contactLabel-connected { color: #3c7e0c; @@ -1023,7 +1031,7 @@ white-space: nowrap; } -.occupantsList { +.occupantsPanel { border-right: 2px dotted #ddd; margin-left: 5px; margin-right: 10px;
--- a/src/browser/sat_browser/chat.py Fri Feb 27 16:05:28 2015 +0100 +++ b/src/browser/sat_browser/chat.py Fri Feb 27 22:53:27 2015 +0100 @@ -98,9 +98,9 @@ chat_area = HorizontalPanel() chat_area.setStyleName('chatArea') if type_ == C.CHAT_GROUP: - self.occupants_list = contact_panel.OccupantsList() - self.occupants_initialised = False - chat_area.add(self.occupants_list) + self.occupants_panel = contact_panel.ContactsPanel(self, contacts_style="muc_contact", contacts_display=('resource',)) + self.occupants_panel.setStyleName("occupantsPanel") + chat_area.add(self.occupants_panel) self._body.add(chat_area) self.content = AbsolutePanel() self.content.setStyleName('chatContent') @@ -205,25 +205,24 @@ def setPresents(self, nicks): """Set the users presents in this room @param occupants: list of nicks (string)""" - for nick in nicks: - self.occupants_list.addOccupant(nick) - self.occupants_initialised = True + self.occupants_panel.setList([jid.JID(u"%s/%s" % (self.target,nick)) for nick in nicks]) # def userJoined(self, nick, data): - # if self.occupants_list.getOccupantBox(nick): + # if self.occupants_panel.getOccupantBox(nick): # return # user is already displayed - # self.occupants_list.addOccupant(nick) + # self.occupants_panel.addOccupant(nick) # if self.occupants_initialised: # self.printInfo("=> %s has joined the room" % nick) # def userLeft(self, nick, data): - # self.occupants_list.removeOccupant(nick) + # self.occupants_panel.removeOccupant(nick) # self.printInfo("<= %s has left the room" % nick) def changeUserNick(self, old_nick, new_nick): - assert(self.type == C.CHAT_GROUP) - self.occupants_list.removeOccupant(old_nick) - self.occupants_list.addOccupant(new_nick) + assert self.type == C.CHAT_GROUP + # FIXME + # self.occupants_panel.removeOccupant(old_nick) + # self.occupants_panel.addOccupant(new_nick) self.printInfo(_("%(old_nick)s is now known as %(new_nick)s") % {'old_nick': old_nick, 'new_nick': new_nick}) # def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT): @@ -286,7 +285,7 @@ if game_type not in classes.keys(): return # unknown game attr = game_type.lower() - self.occupants_list.updateSpecials(players, SYMBOLS[attr]) + # self.occupants_panel.updateSpecials(players, SYMBOLS[attr]) # FIXME if waiting or not self.nick in players: return # waiting for player or not playing attr = "%s_panel" % attr @@ -313,14 +312,15 @@ @param state: the new chat state @param nick: ignored for one2one, otherwise the MUC user nick or C.ALL_OCCUPANTS """ + return # FIXME if self.type == C.CHAT_GROUP: assert(nick) if nick == C.ALL_OCCUPANTS: - occupants = self.occupants_list.occupants_list.keys() + occupants = self.occupants_panel.occupants_panel.keys() else: - occupants = [nick] if nick in self.occupants_list.occupants_list else [] + occupants = [nick] if nick in self.occupants_panel.occupants_panel else [] for occupant in occupants: - self.occupants_list.occupants_list[occupant].setState(state) + self.occupants_panel.occupants_panel[occupant].setState(state) else: self._state = state self.refreshTitle() @@ -337,10 +337,11 @@ """Set connection status @param jid_s (str): JID userhost as unicode """ + raise Exception("should not be there") # FIXME assert(jid_s == self.target.bare) if self.type != C.CHAT_GROUP: return - box = self.occupants_list.getOccupantBox(resource) + box = self.occupants_panel.getOccupantBox(resource) if box: contact_list.setPresenceStyle(box, availability)
--- a/src/browser/sat_browser/constants.py Fri Feb 27 16:05:28 2015 +0100 +++ b/src/browser/sat_browser/constants.py Fri Feb 27 22:53:27 2015 +0100 @@ -37,3 +37,5 @@ WEB_PANEL_DEFAULT_URL = "http://salut-a-toi.org" WEB_PANEL_SCHEMES = {'http', 'https', 'ftp', 'file'} + + CONTACT_DEFAULT_DISPLAY=('bare', 'nick')
--- a/src/browser/sat_browser/contact_list.py Fri Feb 27 16:05:28 2015 +0100 +++ b/src/browser/sat_browser/contact_list.py Fri Feb 27 22:53:27 2015 +0100 @@ -230,7 +230,7 @@ to_show = [jid_ for jid_ in self._cache.keys() if self.entityToShow(jid_) and jid_!=self.whoami.bare] to_show.sort() - self._contacts_panel.display(to_show) + self._contacts_panel.setList(to_show) for jid_ in self._alerts: self._contacts_panel.setState(jid_, "messageWaiting", True)
--- a/src/browser/sat_browser/contact_panel.py Fri Feb 27 16:05:28 2015 +0100 +++ b/src/browser/sat_browser/contact_panel.py Fri Feb 27 22:53:27 2015 +0100 @@ -82,7 +82,7 @@ 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): + def __init__(self, parent, on_click=None, handle_menu=True, contacts_style=None, contacts_display=C.CONTACT_DEFAULT_DISPLAY): """ @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) @@ -97,8 +97,11 @@ if on_click is not None: self.onClick = on_click - def display(self, jids): - """Display a contact in the list. + self.contacts_style=contacts_style + self.contacts_display = contacts_display + + def setList(self, jids): + """set all contacts in the list in one shot. @param jids (list[jid.JID]): jids to display (the order is kept) @param name (unicode): optional name of the contact @@ -131,7 +134,7 @@ try: return self._contacts[contact_jid.bare] except KeyError: - box = contact_widget.ContactBox(self, contact_jid) + box = contact_widget.ContactBox(self, contact_jid, style_name=self.contacts_style, display=self.contacts_display) self._contacts[contact_jid.bare] = box return box
--- 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: