comparison src/browser/sat_browser/contact_list.py @ 684:e876f493dccc

browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation: - some MUC handlers are no more needed, the presence handler is enough - move the chat states logic to quick_frontend - display MUC games symbols - remove classes contact_list.ContactsPanel, contact_panel.Occupant and contact_panel.OccupantsList - move buildPresenceStyle and setPresenceStyle to html_tools - fixes games menu callback
author souliane <souliane@mailoo.org>
date Wed, 18 Mar 2015 10:17:04 +0100
parents a90cc8fc9605
children 9877607c719a
comparison
equal deleted inserted replaced
683:801eb94aa869 684:e876f493dccc
34 import contact_panel 34 import contact_panel
35 import blog 35 import blog
36 import chat 36 import chat
37 37
38 unicode = str # XXX: pyjama doesn't manage unicode 38 unicode = str # XXX: pyjama doesn't manage unicode
39
40
41 def buildPresenceStyle(presence, base_style=None):
42 """Return the CSS classname to be used for displaying the given presence information.
43
44 @param presence (unicode): presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
45 @param base_style (unicode): base classname
46 @return: unicode
47 """
48 if not base_style:
49 base_style = "contactLabel"
50 return '%s-%s' % (base_style, presence or 'connected')
51
52
53 def setPresenceStyle(widget, presence, base_style=None):
54 """
55 Set the CSS style of a contact's element according to its presence.
56
57 @param widget (Widget): the UI element of the contact
58 @param presence (unicode): a value in ("", "chat", "away", "dnd", "xa").
59 @param base_style (unicode): the base name of the style to apply
60 """
61 if not hasattr(widget, 'presence_style'):
62 widget.presence_style = None
63 style = buildPresenceStyle(presence, base_style)
64 if style == widget.presence_style:
65 return
66 if widget.presence_style is not None:
67 widget.removeStyleName(widget.presence_style)
68 widget.addStyleName(style)
69 widget.presence_style = style
70 39
71 40
72 class GroupLabel(libervia_widget.DragLabel, Label, ClickHandler): 41 class GroupLabel(libervia_widget.DragLabel, Label, ClickHandler):
73 def __init__(self, host, group): 42 def __init__(self, host, group):
74 """ 43 """
130 99
131 def getGroups(self): 100 def getGroups(self):
132 return self._groups 101 return self._groups
133 102
134 103
135 class ContactsPanel(contact_panel.ContactsPanel):
136 """The contact list that is displayed on the left side."""
137
138 def __init__(self, host):
139
140 def on_click(contact_jid):
141 self.host.displayWidget(chat.Chat, contact_jid, type_=C.CHAT_ONE2ONE)
142
143 contact_panel.ContactsPanel.__init__(self, host, contacts_click=on_click,
144 contacts_menus=(C.MENU_JID_CONTEXT, C.MENU_ROSTER_JID_CONTEXT))
145
146 def setState(self, jid_, type_, state):
147 """Change the appearance of the contact, according to the state
148
149 @param jid_ (jid.JID): jid.JID which need to change state
150 @param type_ (unicode): one of "availability", "messageWaiting"
151 @param state:
152 - for messageWaiting type:
153 True if message are waiting
154 - for availability type:
155 C.PRESENCE_UNAVAILABLE or None if not connected, else presence like RFC6121 #4.7.2.1"""
156 assert type_ in ('availability', 'messageWaiting')
157 contact_box = self.getContactBox(jid_)
158 if type_ == 'availability':
159 if state is None:
160 state = C.PRESENCE_UNAVAILABLE
161 setPresenceStyle(contact_box.label, state)
162 elif type_ == 'messageWaiting':
163 contact_box.setAlert(state)
164
165
166 class ContactTitleLabel(libervia_widget.DragLabel, Label, ClickHandler): 104 class ContactTitleLabel(libervia_widget.DragLabel, Label, ClickHandler):
167 105
168 def __init__(self, host, text): 106 def __init__(self, host, text):
169 Label.__init__(self, text) # , Element=DOM.createElement('div') 107 Label.__init__(self, text) # , Element=DOM.createElement('div')
170 self.setStyleName('contactTitle') 108 self.setStyleName('contactTitle')
185 self.host = host 123 self.host = host
186 self.scroll_panel = ScrollPanel() 124 self.scroll_panel = ScrollPanel()
187 self.vPanel = VerticalPanel() 125 self.vPanel = VerticalPanel()
188 _title = ContactTitleLabel(host, 'Contacts') 126 _title = ContactTitleLabel(host, 'Contacts')
189 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") 127 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer")
190 self._contacts_panel = ContactsPanel(host) 128
129 def on_click(contact_jid):
130 self.host.displayWidget(chat.Chat, contact_jid, type_=C.CHAT_ONE2ONE)
131
132 self._contacts_panel = contact_panel.ContactsPanel(host, contacts_click=on_click, contacts_menus=(C.MENU_JID_CONTEXT, C.MENU_ROSTER_JID_CONTEXT))
191 self._contacts_panel.setStyleName('contactPanel') # FIXME: style doesn't exists ! 133 self._contacts_panel.setStyleName('contactPanel') # FIXME: style doesn't exists !
192 self._group_panel = GroupPanel(self) 134 self._group_panel = GroupPanel(self)
193 135
194 self.vPanel.add(_title) 136 self.vPanel.add(_title)
195 self.vPanel.add(self._group_panel) 137 self.vPanel.add(self._group_panel)
233 to_show.sort() 175 to_show.sort()
234 176
235 self._contacts_panel.setList(to_show) 177 self._contacts_panel.setList(to_show)
236 178
237 for jid_ in self._alerts: 179 for jid_ in self._alerts:
238 self._contacts_panel.setState(jid_, "messageWaiting", True) 180 self._contacts_panel.getContactBox(jid_).setAlert(True)
239 181
240 def remove(self, entity): 182 def remove(self, entity):
241 # FIXME: SimplePanel and QuickContactList both have a 'remove' method 183 # FIXME: SimplePanel and QuickContactList both have a 'remove' method
242 QuickContactList.remove(self, entity) 184 QuickContactList.remove(self, entity)
243 185
428 """ 370 """
429 return C.bool(self.host.getCachedParam('General', C.SHOW_EMPTY_GROUPS)) 371 return C.bool(self.host.getCachedParam('General', C.SHOW_EMPTY_GROUPS))
430 372
431 def onPresenceUpdate(self, entity, show, priority, statuses, profile): 373 def onPresenceUpdate(self, entity, show, priority, statuses, profile):
432 QuickContactList.onPresenceUpdate(self, entity, show, priority, statuses, profile) 374 QuickContactList.onPresenceUpdate(self, entity, show, priority, statuses, profile)
433 entity_bare = entity.bare 375 self._contacts_panel.setPresence(entity, show)
434 show = self.getCache(entity_bare, C.PRESENCE_SHOW) # we use cache to have the show nformation of main resource only
435 self._contacts_panel.setState(entity_bare, "availability", show)
436 self.update() # FIXME: should update the list without rebuilding it all
437 376
438 # def updateVisibility(self, jids, groups): 377 # def updateVisibility(self, jids, groups):
439 # """Set the widgets visibility for the given contacts and groups 378 # """Set the widgets visibility for the given contacts and groups
440 379
441 # @param jids (list[unicode]): list of JID 380 # @param jids (list[unicode]): list of JID