Mercurial > libervia-web
comparison src/browser/sat_browser/contact.py @ 479:c21ea1fe3593
browser side: small refactoring to prepare displaying avatars in the contact panel
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 14 Jun 2014 19:10:51 +0200 |
parents | 97c72fe4a5f2 |
children | 50b286866739 |
comparison
equal
deleted
inserted
replaced
478:992b900ab876 | 479:c21ea1fe3593 |
---|---|
36 import base_widget | 36 import base_widget |
37 import panels | 37 import panels |
38 import html_tools | 38 import html_tools |
39 | 39 |
40 | 40 |
41 def setPresenceStyle(element, presence, base_style="contact"): | 41 def setPresenceStyle(widget, presence, base_style="contactLabel"): |
42 """ | 42 """ |
43 Set the CSS style of a contact's element according to its presence. | 43 Set the CSS style of a contact's element according to its presence. |
44 @param item: the UI element of the contact | 44 |
45 @param presence: a value in ("", "chat", "away", "dnd", "xa"). | 45 @param widget (Widget): the UI element of the contact |
46 @param base_style: the base name of the style to apply | 46 @param presence (str): a value in ("", "chat", "away", "dnd", "xa"). |
47 @param base_style (str): the base name of the style to apply | |
47 """ | 48 """ |
48 if not hasattr(element, 'presence_style'): | 49 if not hasattr(widget, 'presence_style'): |
49 element.presence_style = None | 50 widget.presence_style = None |
50 style = '%s-%s' % (base_style, presence or 'connected') | 51 style = '%s-%s' % (base_style, presence or 'connected') |
51 if style == element.presence_style: | 52 if style == widget.presence_style: |
52 return | 53 return |
53 if element.presence_style is not None: | 54 if widget.presence_style is not None: |
54 element.removeStyleName(element.presence_style) | 55 widget.removeStyleName(widget.presence_style) |
55 element.addStyleName(style) | 56 widget.addStyleName(style) |
56 element.presence_style = style | 57 widget.presence_style = style |
57 | 58 |
58 | 59 |
59 class GroupLabel(base_widget.DragLabel, Label, ClickHandler): | 60 class GroupLabel(base_widget.DragLabel, Label, ClickHandler): |
60 def __init__(self, host, group): | 61 def __init__(self, host, group): |
61 self.group = group | 62 self.group = group |
75 HTML.__init__(self) | 76 HTML.__init__(self) |
76 self.host = host | 77 self.host = host |
77 self.name = name or jid | 78 self.name = name or jid |
78 self.waiting = False | 79 self.waiting = False |
79 self.jid = jid | 80 self.jid = jid |
80 self._fill() | 81 self.refresh() |
81 self.setStyleName('contact') | 82 self.setStyleName('contactLabel') |
82 base_widget.DragLabel.__init__(self, jid, "CONTACT") | 83 base_widget.DragLabel.__init__(self, jid, "CONTACT") |
83 if handleClick: | 84 if handleClick: |
84 ClickHandler.__init__(self) | 85 ClickHandler.__init__(self) |
85 self.addClickListener(self) | 86 self.addClickListener(self) |
86 | 87 |
87 def _fill(self): | 88 def refresh(self): |
88 if self.waiting: | 89 if self.waiting: |
89 _wait_html = "<b>(*)</b> " | 90 wait_html = "<b>(*)</b> " |
90 self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html, | 91 self.setHTML("%(wait)s%(name)s" % {'wait': wait_html, |
91 'name': html_tools.html_sanitize(self.name)}) | 92 'name': html_tools.html_sanitize(self.name)}) |
92 | 93 |
93 def setMessageWaiting(self, waiting): | 94 def setMessageWaiting(self, waiting): |
94 """Show a visual indicator if message are waiting | 95 """Show a visual indicator if message are waiting |
96 | |
95 @param waiting: True if message are waiting""" | 97 @param waiting: True if message are waiting""" |
96 self.waiting = waiting | 98 self.waiting = waiting |
97 self._fill() | 99 self.refresh() |
98 | 100 |
99 def onClick(self, sender): | 101 def onClick(self, sender): |
100 self.host.getOrCreateLiberviaWidget(panels.ChatPanel, self.jid) | 102 self.host.getOrCreateLiberviaWidget(panels.ChatPanel, self.jid) |
101 | 103 |
102 | 104 |
133 VerticalPanel.__init__(self) | 135 VerticalPanel.__init__(self) |
134 self.host = host | 136 self.host = host |
135 self.contacts = [] | 137 self.contacts = [] |
136 self.handleClick = handleClick | 138 self.handleClick = handleClick |
137 | 139 |
138 def add(self, jid, name=None, item_cb=None): | 140 def add(self, jid, name=None, add_item_cb=None): |
141 """Add a contact to the list. | |
142 | |
143 @param jid (str): JID of the contact | |
144 @param name (str): optional name of the contact | |
145 @param add_item_cb (method): to be called on the contact's widget after it's been added to the list | |
146 """ | |
139 if jid in self.contacts: | 147 if jid in self.contacts: |
140 return | 148 return |
141 index = 0 | 149 index = 0 |
142 for contact_ in self.contacts: | 150 for contact_ in self.contacts: |
143 if contact_ > jid: | 151 if contact_ > jid: |
145 index += 1 | 153 index += 1 |
146 self.contacts.insert(index, jid) | 154 self.contacts.insert(index, jid) |
147 _item = ContactLabel(self.host, jid, name, handleClick=self.handleClick) | 155 _item = ContactLabel(self.host, jid, name, handleClick=self.handleClick) |
148 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") | 156 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
149 VerticalPanel.insert(self, _item, index) | 157 VerticalPanel.insert(self, _item, index) |
150 if item_cb is not None: | 158 if add_item_cb: |
151 item_cb(_item) | 159 add_item_cb(box) |
152 | 160 |
153 def remove(self, jid): | 161 def remove(self, jid): |
154 wid = self.getContactLabel(jid) | 162 wid = self.getContactLabel(jid) |
155 if not wid: | 163 if not wid: |
156 return | 164 return |
202 """Add a contact | 210 """Add a contact |
203 | 211 |
204 @param jid_s (str): JID as unicode | 212 @param jid_s (str): JID as unicode |
205 @param name (str): nickname | 213 @param name (str): nickname |
206 """ | 214 """ |
207 def item_cb(item): | 215 GenericContactList.add(self, jid_s, name, add_item_cb=lambda item: self.context_menu.registerRightClickSender(item)) |
208 self.context_menu.registerRightClickSender(item) | |
209 GenericContactList.add(self, jid_s, name, item_cb) | |
210 | 216 |
211 def setState(self, jid, type_, state): | 217 def setState(self, jid, type_, state): |
212 """Change the appearance of the contact, according to the state | 218 """Change the appearance of the contact, according to the state |
213 @param jid: jid which need to change state | 219 @param jid: jid which need to change state |
214 @param type_: one of availability, messageWaiting | 220 @param type_: one of availability, messageWaiting |
262 self.vPanel.add(_title) | 268 self.vPanel.add(_title) |
263 self.vPanel.add(self._groupList) | 269 self.vPanel.add(self._groupList) |
264 self.vPanel.add(self._contact_list) | 270 self.vPanel.add(self._contact_list) |
265 self.scroll_panel.add(self.vPanel) | 271 self.scroll_panel.add(self.vPanel) |
266 self.add(self.scroll_panel) | 272 self.add(self.scroll_panel) |
267 self.setStyleName('contactBox') | 273 self.setStyleName('contactPanel') |
268 Window.addWindowResizeListener(self) | 274 Window.addWindowResizeListener(self) |
269 | 275 |
270 def onWindowResized(self, width, height): | 276 def onWindowResized(self, width, height): |
271 contact_panel_elt = self.getElement() | 277 contact_panel_elt = self.getElement() |
272 classname = 'widgetsPanel' if isinstance(self.getParent().getParent(), panels.UniBoxPanel) else'gwt-TabBar' | 278 classname = 'widgetsPanel' if isinstance(self.getParent().getParent(), panels.UniBoxPanel) else'gwt-TabBar' |