comparison frontends/src/primitivus/contact_list.py @ 2015:20fb71b656e3

quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities: - special_extras has been removed - specials handle all entities (bare + full) in a single set
author Goffi <goffi@goffi.org>
date Sun, 24 Jul 2016 17:47:09 +0200
parents 90134b2e3dc4
children f09562b0704d
comparison
equal deleted inserted replaced
2014:0694a2611bad 2015:20fb71b656e3
120 pass 120 pass
121 idx += 1 121 idx += 1
122 122
123 log.debug(u"Not element found for {} in setFocus".format(text)) 123 log.debug(u"Not element found for {} in setFocus".format(text))
124 124
125 def specialResourceVisible(self, entity):
126 """Assure a resource of a special entity is visible and clickable
127
128 Mainly used to display private conversation in MUC rooms
129 @param entity: full jid of the resource to show
130 """
131 assert isinstance(entity, jid.JID)
132 if entity not in self._special_extras:
133 self._special_extras.add(entity)
134 self.update()
135
136 # events 125 # events
137 126
138 def _groupClicked(self, group_wid): 127 def _groupClicked(self, group_wid):
139 group = group_wid.getValue() 128 group = group_wid.getValue()
140 data = self.contact_list.getGroupData(group) 129 data = self.contact_list.getGroupData(group)
161 self.title_dynamic = None 150 self.title_dynamic = None
162 self.host.redraw() # FIXME: should not be necessary 151 self.host.redraw() # FIXME: should not be necessary
163 152
164 # Methods to build the widget 153 # Methods to build the widget
165 154
166 def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append = None): 155 def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append=None, special=False):
167 """Build one contact markup data 156 """Build one contact markup data
168 157
169 @param entity (jid.JID): entity to build 158 @param entity (jid.JID): entity to build
170 @param keys (iterable): value to markup, in preferred order. 159 @param keys (iterable): value to markup, in preferred order.
171 The first available key will be used. 160 The first available key will be used.
175 @param use_bare_jid (bool): if True, use bare jid for selected comparisons 164 @param use_bare_jid (bool): if True, use bare jid for selected comparisons
176 @param with_notifs (bool): if True, show notification count 165 @param with_notifs (bool): if True, show notification count
177 @param with_show_attr (bool): if True, show color corresponding to presence status 166 @param with_show_attr (bool): if True, show color corresponding to presence status
178 @param markup_prepend (list): markup to prepend to the generated one before building the widget 167 @param markup_prepend (list): markup to prepend to the generated one before building the widget
179 @param markup_append (list): markup to append to the generated one before building the widget 168 @param markup_append (list): markup to append to the generated one before building the widget
169 @param special (bool): True if entity is a special one
180 @return (list): markup data are expected by Urwid text widgets 170 @return (list): markup data are expected by Urwid text widgets
181 """ 171 """
182 markup = [] 172 markup = []
183 if use_bare_jid: 173 if use_bare_jid:
184 selected = {entity.bare for entity in self.contact_list._selected} 174 selected = {entity.bare for entity in self.contact_list._selected}
267 for widget in widgets: 257 for widget in widgets:
268 content.append(widget) 258 content.append(widget)
269 259
270 def _buildSpecials(self, content): 260 def _buildSpecials(self, content):
271 """Build the special entities""" 261 """Build the special entities"""
272 specials = list(self.contact_list._specials) 262 specials = sorted(self.contact_list.getSpecials())
273 specials.sort() 263 current = None
274 extra_shown = set()
275 for entity in specials: 264 for entity in specials:
276 # the special widgets 265 if current is not None and current.bare == entity.bare:
277 widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), with_show_attr=False) 266 # nested entity (e.g. MUC private conversations)
278 content.append(widget) 267 widget = self._buildEntityWidget(entity, ('resource',), markup_prepend=' ', special=True)
279 268 else:
280 # resources which must be displayed (e.g. MUC private conversations) 269 # the special widgets
281 extras = [extra for extra in self.contact_list._special_extras if extra.bare == entity.bare] 270 if entity.resource:
282 extras.sort() 271 widget = self._buildEntityWidget(entity, ('resource',), special=True)
283 for extra in extras: 272 else:
284 widget = self._buildEntityWidget(extra, ('resource',), markup_prepend = ' ') 273 widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), with_show_attr=False, special=True)
285 content.append(widget)
286 extra_shown.add(extra)
287
288 # entities which must be visible but not resource of current special entities
289 for extra in self.contact_list._special_extras.difference(extra_shown):
290 widget = self._buildEntityWidget(extra, ('resource',))
291 content.append(widget) 274 content.append(widget)
292 275
293 def _buildList(self): 276 def _buildList(self):
294 """Build the main contact list widget""" 277 """Build the main contact list widget"""
295 content = urwid.SimpleListWalker([]) 278 content = urwid.SimpleListWalker([])