comparison 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
comparison
equal deleted inserted replaced
659:8e7d4de56e75 660:267761bf7f08
19 19
20 import pyjd # this is dummy in pyjs 20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 23
24 from sat.core import exceptions
24 from pyjamas.ui.VerticalPanel import VerticalPanel 25 from pyjamas.ui.VerticalPanel import VerticalPanel
25 from pyjamas.ui.HTML import HTML 26 from pyjamas.ui.HTML import HTML
26 from pyjamas.ui.Image import Image 27 from pyjamas.ui.Image import Image
27 from pyjamas.ui.ClickListener import ClickHandler 28 from pyjamas.ui.ClickListener import ClickHandler
28 from constants import Const as C 29 from constants import Const as C
34 35
35 36
36 class ContactLabel(HTML): 37 class ContactLabel(HTML):
37 """Display a contact in HTML, selecting best display (jid/nick/etc)""" 38 """Display a contact in HTML, selecting best display (jid/nick/etc)"""
38 39
39 def __init__(self, host, jid_): 40 def __init__(self, host, jid_, display=C.CONTACT_DEFAULT_DISPLAY):
40 # TODO: add a listener for nick changes 41 # TODO: add a listener for nick changes
41 HTML.__init__(self) 42 HTML.__init__(self)
42 self.host = host 43 self.host = host
43 self.jid = jid_.bare 44 self.jid = jid_
44 self.nick = self.host.contact_lists[C.PROF_KEY_NONE].getCache(self.jid, "nick") 45 if "nick" in display:
46 self.nick = self.host.contact_lists[C.PROF_KEY_NONE].getCache(self.jid, "nick")
47 self.display = display
45 self.alert = False 48 self.alert = False
46 self.refresh() 49 self.refresh()
47 self.setStyleName('contactLabel') 50 self.setStyleName('contactLabel')
48 51
49 def refresh(self): 52 def refresh(self):
50 alert_html = "<strong>(*)</strong>&nbsp;" if self.alert else "" 53 alert_html = "<strong>(*)</strong>&nbsp;" if self.alert else ""
51 contact_html = html_tools.html_sanitize(self.nick or unicode(self.jid)) 54 contact_raw = None
55 for disp in self.display:
56 if disp == "jid":
57 contact_raw = unicode(self.jid)
58 elif disp == "nick":
59 contact_raw = self.nick
60 elif disp == "bare":
61 contact_raw = unicode(self.jid.bare)
62 elif disp == "resource":
63 contact_raw = self.jid.resource
64 else:
65 raise exceptions.InternalError(u"Unknown display argument [{}]".format(disp))
66 if contact_raw:
67 break
68 if not contact_raw:
69 log.error(u"Counld not find a contact display for jid {jid} (display: {display})".format(jid=self.jid, display=self.display))
70 contact_raw = "UNNAMED"
71 contact_html = html_tools.html_sanitize(contact_raw)
52 html = "%(alert)s%(contact)s" % {'alert': alert_html, 72 html = "%(alert)s%(contact)s" % {'alert': alert_html,
53 'contact': contact_html} 73 'contact': contact_html}
54 self.setHTML(html) 74 self.setHTML(html)
55 75
56 def updateNick(self, new_nick): 76 def updateNick(self, new_nick):
85 self.items[0].setHTML('<img src="%s" />' % url) 105 self.items[0].setHTML('<img src="%s" />' % url)
86 106
87 107
88 class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel): 108 class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel):
89 109
90 def __init__(self, parent, jid_): 110 def __init__(self, parent, jid_, style_name=None, display=C.CONTACT_DEFAULT_DISPLAY):
91 """ 111 """
92 @param parent (ContactPanel): ContactPanel hosting this box 112 @param parent (ContactPanel): ContactPanel hosting this box
93 @param jid_ (jid.JID): contact JID 113 @param jid_ (jid.JID): contact JID
94 """ 114 """
95 VerticalPanel.__init__(self, StyleName='contactBox', VerticalAlignment='middle') 115 VerticalPanel.__init__(self, StyleName=style_name or 'contactBox', VerticalAlignment='middle')
96 ClickHandler.__init__(self) 116 ClickHandler.__init__(self)
97 libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", parent.host) 117 libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", parent.host)
98 self.jid = jid_.bare 118 self.jid = jid_
99 self.label = ContactLabel(parent.host, self.jid) 119 self.label = ContactLabel(parent.host, self.jid, display=display)
100 self.avatar = ContactMenuBar(self, parent.host) if parent.handle_menu else Image() 120 self.avatar = ContactMenuBar(self, parent.host) if parent.handle_menu else Image()
101 self.updateAvatar(parent.host.getAvatarURL(self.jid)) 121 self.updateAvatar(parent.host.getAvatarURL(self.jid.bare))
102 self.add(self.avatar) 122 self.add(self.avatar)
103 self.add(self.label) 123 self.add(self.label)
104 self.addClickListener(self) 124 self.addClickListener(self)
105 125
106 def addMenus(self, menu_bar): 126 def addMenus(self, menu_bar):
107 menu_bar.addCachedMenus(C.MENU_ROSTER_JID_CONTEXT, {'jid': unicode(self.jid)}) 127 menu_bar.addCachedMenus(C.MENU_ROSTER_JID_CONTEXT, {'jid': unicode(self.jid.bare)})
108 menu_bar.addCachedMenus(C.MENU_JID_CONTEXT, {'jid': unicode(self.jid)}) 128 menu_bar.addCachedMenus(C.MENU_JID_CONTEXT, {'jid': unicode(self.jid.bare)})
109 129
110 def setAlert(self, alert): 130 def setAlert(self, alert):
111 """Show a visual indicator 131 """Show a visual indicator
112 132
113 @param alert: True if alert indicator show be shown""" 133 @param alert: True if alert indicator show be shown"""
127 """ 147 """
128 self.label.updateNick(new_nick) 148 self.label.updateNick(new_nick)
129 149
130 def onClick(self, sender): 150 def onClick(self, sender):
131 try: 151 try:
132 self.parent.onClick(self.jid) 152 self.parent.onClick(self.jid.bare)
133 except AttributeError: 153 except AttributeError:
134 pass 154 pass
135 else: 155 else:
136 self.setAlert(False) 156 self.setAlert(False)