comparison frontends/src/primitivus/contact_list.py @ 1972:02d21a589be2

quick_frontend, primitivus: notifications refactoring replaced old "alerts" system by a more generic one which use listeners and can activate callbacks on notification click.
author Goffi <goffi@goffi.org>
date Mon, 27 Jun 2016 22:36:22 +0200
parents 011eff37e21d
children a9908e751c42
comparison
equal deleted inserted replaced
1971:9421e721d5e2 1972:02d21a589be2
142 142
143 def _contactClicked(self, use_bare_jid, contact_wid, selected): 143 def _contactClicked(self, use_bare_jid, contact_wid, selected):
144 """Method called when a contact is clicked 144 """Method called when a contact is clicked
145 145
146 @param use_bare_jid: True if use_bare_jid is set in self._buildEntityWidget. 146 @param use_bare_jid: True if use_bare_jid is set in self._buildEntityWidget.
147 If True, all jids in self._alerts with the same bare jid has contact_wid.data will be removed
148 @param contact_wid: widget of the contact, must have the entity set in data attribute 147 @param contact_wid: widget of the contact, must have the entity set in data attribute
149 @param selected: boolean returned by the widget, telling if it is selected 148 @param selected: boolean returned by the widget, telling if it is selected
150 """ 149 """
151 entity = contact_wid.data 150 entity = contact_wid.data
152 self.contact_list.removeAlerts(entity, use_bare_jid)
153 self.host.modeHint(C.MODE_INSERTION) 151 self.host.modeHint(C.MODE_INSERTION)
154 self._emit('click', entity) 152 self._emit('click', entity)
155 153
156 # Methods to build the widget 154 # Methods to build the widget
157 155
158 def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_alert=True, with_show_attr=True, markup_prepend=None, markup_append = None): 156 def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append = None):
159 """Build one contact markup data 157 """Build one contact markup data
160 158
161 @param entity (jid.JID): entity to build 159 @param entity (jid.JID): entity to build
162 @param keys (iterable): value to markup, in preferred order. 160 @param keys (iterable): value to markup, in preferred order.
163 The first available key will be used. 161 The first available key will be used.
164 If key starts with "cache_", it will be checked in cache, 162 If key starts with "cache_", it will be checked in cache,
165 else, getattr will be done on entity with the key (e.g. getattr(entity, 'node')). 163 else, getattr will be done on entity with the key (e.g. getattr(entity, 'node')).
166 If nothing full or keys is None, full entity is used. 164 If nothing full or keys is None, full entity is used.
167 @param use_bare_jid (bool): if True, use bare jid for alerts and selected comparisons 165 @param use_bare_jid (bool): if True, use bare jid for selected comparisons
168 @param with_alert (bool): if True, show alert if entity is in self._alerts 166 @param with_notifs (bool): if True, show notification count
169 @param with_show_attr (bool): if True, show color corresponding to presence status 167 @param with_show_attr (bool): if True, show color corresponding to presence status
170 @param markup_prepend (list): markup to prepend to the generated one before building the widget 168 @param markup_prepend (list): markup to prepend to the generated one before building the widget
171 @param markup_append (list): markup to append to the generated one before building the widget 169 @param markup_append (list): markup to append to the generated one before building the widget
172 @return (list): markup data are expected by Urwid text widgets 170 @return (list): markup data are expected by Urwid text widgets
173 """ 171 """
197 show_icon, entity_attr = C.PRESENCE.get(show, ('', 'default')) 195 show_icon, entity_attr = C.PRESENCE.get(show, ('', 'default'))
198 markup.insert(0, u"{} ".format(show_icon)) 196 markup.insert(0, u"{} ".format(show_icon))
199 else: 197 else:
200 entity_attr = 'default' 198 entity_attr = 'default'
201 199
202 alerts_count = len(self.contact_list.getAlerts(entity, use_bare_jid=use_bare_jid)) 200 notifs = self.host.getNotifs(entity.bare, profile=self.profile)
203 if with_alert and alerts_count: 201 if notifs:
204 entity_attr = 'alert' 202 entity_attr = 'cl_notifs'
205 header = C.ALERT_HEADER % alerts_count 203 header = u'({}) '.format(len(notifs))
206 else: 204 else:
207 header = '' 205 header = u''
208 206
209 markup.append((entity_attr, entity_txt)) 207 markup.append((entity_attr, entity_txt))
210 if markup_prepend: 208 if markup_prepend:
211 markup.insert(0, markup_prepend) 209 markup.insert(0, markup_prepend)
212 if markup_append: 210 if markup_append: