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
This commit is contained in:
Goffi 2016-07-24 17:47:09 +02:00
commit 57daef07a7
2 changed files with 31 additions and 61 deletions

View file

@ -553,7 +553,7 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
super(Chat, self)._onHistoryPrinted()
def onPrivateCreated(self, widget):
self.host.contact_lists[widget.profile].specialResourceVisible(widget.target)
self.host.contact_lists[widget.profile].setSpecial(widget.target, C.CONTACT_SPECIAL_GROUP)
def onSelected(self):
self.focus_marker_set = False

View file

@ -122,17 +122,6 @@ class ContactList(PrimitivusWidget, QuickContactList):
log.debug(u"Not element found for {} in setFocus".format(text))
def specialResourceVisible(self, entity):
"""Assure a resource of a special entity is visible and clickable
Mainly used to display private conversation in MUC rooms
@param entity: full jid of the resource to show
"""
assert isinstance(entity, jid.JID)
if entity not in self._special_extras:
self._special_extras.add(entity)
self.update()
# events
def _groupClicked(self, group_wid):
@ -163,7 +152,7 @@ class ContactList(PrimitivusWidget, QuickContactList):
# Methods to build the widget
def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append = None):
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):
"""Build one contact markup data
@param entity (jid.JID): entity to build
@ -177,6 +166,7 @@ class ContactList(PrimitivusWidget, QuickContactList):
@param with_show_attr (bool): if True, show color corresponding to presence status
@param markup_prepend (list): markup to prepend to the generated one before building the widget
@param markup_append (list): markup to append to the generated one before building the widget
@param special (bool): True if entity is a special one
@return (list): markup data are expected by Urwid text widgets
"""
markup = []
@ -269,25 +259,18 @@ class ContactList(PrimitivusWidget, QuickContactList):
def _buildSpecials(self, content):
"""Build the special entities"""
specials = list(self.contact_list._specials)
specials.sort()
extra_shown = set()
specials = sorted(self.contact_list.getSpecials())
current = None
for entity in specials:
# the special widgets
widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), with_show_attr=False)
content.append(widget)
# resources which must be displayed (e.g. MUC private conversations)
extras = [extra for extra in self.contact_list._special_extras if extra.bare == entity.bare]
extras.sort()
for extra in extras:
widget = self._buildEntityWidget(extra, ('resource',), markup_prepend = ' ')
content.append(widget)
extra_shown.add(extra)
# entities which must be visible but not resource of current special entities
for extra in self.contact_list._special_extras.difference(extra_shown):
widget = self._buildEntityWidget(extra, ('resource',))
if current is not None and current.bare == entity.bare:
# nested entity (e.g. MUC private conversations)
widget = self._buildEntityWidget(entity, ('resource',), markup_prepend=' ', special=True)
else:
# the special widgets
if entity.resource:
widget = self._buildEntityWidget(entity, ('resource',), special=True)
else:
widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), with_show_attr=False, special=True)
content.append(widget)
def _buildList(self):