Mercurial > libervia-backend
diff frontends/src/primitivus/contact_list.py @ 1938:011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 18 Apr 2016 18:31:13 +0200 |
parents | 2daf7b4c6756 |
children | 02d21a589be2 |
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py Sun Apr 17 18:07:55 2016 +0200 +++ b/frontends/src/primitivus/contact_list.py Mon Apr 18 18:31:13 2016 +0200 @@ -28,13 +28,18 @@ from sat_frontends.tools import jid from sat.core import log as logging log = logging.getLogger(__name__) +from sat_frontends.quick_frontend import quick_widgets class ContactList(PrimitivusWidget, QuickContactList): + PROFILES_MULTIPLE=False + PROFILES_ALLOW_NONE=False signals = ['click','change'] + # FIXME: Only single profile is managed so far - def __init__(self, host, on_click=None, on_change=None, user_data=None, profile=None): - QuickContactList.__init__(self, host, profile) + def __init__(self, host, target, on_click=None, on_change=None, user_data=None, profiles=None): + QuickContactList.__init__(self, host, profiles) + self.contact_list = self.host.contact_lists[self.profile] #we now build the widget self.status_bar = StatusBar(host) @@ -45,8 +50,9 @@ if on_change: urwid.connect_signal(self, 'change', on_change, user_data) - def update(self): + def update(self, entities=None, type_=None, profile=None): """Update display, keep focus""" + # FIXME: full update is done each time, must handle entities, type_ and profile widget, position = self.frame.body.get_focus() self.frame.body = self._buildList() if position: @@ -65,15 +71,22 @@ (key == a_key['FOCUS_DOWN'] and self.frame.focus_position == 'footer')): return key if key == a_key['STATUS_HIDE']: #user wants to (un)hide contacts' statuses - self.show_status = not self.show_status + self.contact_list.show_status = not self.contact_list.show_status self.update() elif key == a_key['DISCONNECTED_HIDE']: #user wants to (un)hide disconnected contacts - self.host.bridge.setParam(C.SHOW_OFFLINE_CONTACTS, C.boolConst(not self.show_disconnected), "General", profile_key=self.profile) + self.host.bridge.setParam(C.SHOW_OFFLINE_CONTACTS, C.boolConst(not self.contact_list.show_disconnected), "General", profile_key=self.profile) elif key == a_key['RESOURCES_HIDE']: #user wants to (un)hide contacts resources - self.showResources(not self.show_resources) + self.contact_list.showResources(not self.contact_list.show_resources) self.update() return super(ContactList, self).keypress(size, key) + # QuickWidget methods + + @staticmethod + def getWidgetHash(target, profiles): + profiles = sorted(profiles) + return tuple(profiles) + # modify the contact list def setFocus(self, text, select=False): @@ -122,7 +135,7 @@ def _groupClicked(self, group_wid): group = group_wid.getValue() - data = self.getGroupData(group) + data = self.contact_list.getGroupData(group) data[C.GROUP_DATA_FOLDED] = not data.setdefault(C.GROUP_DATA_FOLDED, False) self.setFocus(group) self.update() @@ -136,13 +149,10 @@ @param selected: boolean returned by the widget, telling if it is selected """ entity = contact_wid.data - self.removeAlerts(entity, use_bare_jid) + self.contact_list.removeAlerts(entity, use_bare_jid) self.host.modeHint(C.MODE_INSERTION) self._emit('click', entity) - def onNickUpdate(self, entity, new_nick, profile): - self.update() - # Methods to build the widget def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_alert=True, with_show_attr=True, markup_prepend=None, markup_append = None): @@ -163,13 +173,13 @@ """ markup = [] if use_bare_jid: - selected = {entity.bare for entity in self._selected} + selected = {entity.bare for entity in self.contact_list._selected} else: - selected = self._selected + selected = self.contact_list._selected if keys is None: entity_txt = entity else: - cache = self.getCache(entity) + cache = self.contact_list.getCache(entity) for key in keys: if key.startswith('cache_'): entity_txt = cache.get(key[6:]) @@ -181,7 +191,7 @@ entity_txt = entity if with_show_attr: - show = self.getCache(entity, C.PRESENCE_SHOW) + show = self.contact_list.getCache(entity, C.PRESENCE_SHOW) if show is None: show = C.PRESENCE_UNAVAILABLE show_icon, entity_attr = C.PRESENCE.get(show, ('', 'default')) @@ -189,7 +199,7 @@ else: entity_attr = 'default' - alerts_count = self.getAlerts(entity, use_bare_jid=use_bare_jid) + alerts_count = len(self.contact_list.getAlerts(entity, use_bare_jid=use_bare_jid)) if with_alert and alerts_count: entity_attr = 'alert' header = C.ALERT_HEADER % alerts_count @@ -221,22 +231,22 @@ widgets = [] # list of built widgets for entity in entities: - if entity in self._specials or not self.entityToShow(entity): + if entity in self.contact_list._specials or not self.contact_list.entityToShow(entity): continue markup_extra = [] - if self.show_resources: - for resource in self.getCache(entity, C.CONTACT_RESOURCES): + if self.contact_list.show_resources: + for resource in self.contact_list.getCache(entity, C.CONTACT_RESOURCES): resource_disp = ('resource_main' if resource == self.getCache(entity, C.CONTACT_MAIN_RESOURCE) else 'resource', "\n " + resource) markup_extra.append(resource_disp) - if self.show_status: - status = self.getCache(jid.JID('%s/%s' % (entity, resource)), 'status') + if self.contact_list.show_status: + status = self.contact_list.getCache(jid.JID('%s/%s' % (entity, resource)), 'status') status_disp = ('status', "\n " + status) if status else "" markup_extra.append(status_disp) else: - if self.show_status: - status = self.getCache(entity, 'status') + if self.contact_list.show_status: + status = self.contact_list.getCache(entity, 'status') status_disp = ('status', "\n " + status) if status else "" markup_extra.append(status_disp) widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), use_bare_jid=True, markup_append=markup_extra) @@ -249,7 +259,7 @@ def _buildSpecials(self, content): """Build the special entities""" - specials = list(self._specials) + specials = list(self.contact_list._specials) specials.sort() extra_shown = set() for entity in specials: @@ -258,7 +268,7 @@ content.append(widget) # resources which must be displayed (e.g. MUC private conversations) - extras = [extra for extra in self._special_extras if extra.bare == entity.bare] + 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 = ' ') @@ -266,7 +276,7 @@ extra_shown.add(extra) # entities which must be visible but not resource of current special entities - for extra in self._special_extras.difference(extra_shown): + for extra in self.contact_list._special_extras.difference(extra_shown): widget = self._buildEntityWidget(extra, ('resource',)) content.append(widget) @@ -275,25 +285,27 @@ content = urwid.SimpleListWalker([]) self._buildSpecials(content) - if self._specials: + if self.contact_list._specials: content.append(urwid.Divider('=')) - groups = list(self._groups) + groups = list(self.contact_list._groups) groups.sort(key=lambda x: x.lower() if x else x) for group in groups: - data = self.getGroupData(group) + data = self.contact_list.getGroupData(group) folded = data.get(C.GROUP_DATA_FOLDED, False) jids = list(data['jids']) - if group is not None and (self.anyEntityToShow(jids) or self.show_empty_groups): + if group is not None and (self.contact_list.anyEntityToShow(jids) or self.contact_list.show_empty_groups): header = '[-]' if not folded else '[+]' widget = sat_widgets.ClickableText(group, header=header + ' ') content.append(widget) urwid.connect_signal(widget, 'click', self._groupClicked) if not folded: self._buildEntities(content, jids) - not_in_roster = set(self._cache).difference(self._roster).difference(self._specials).difference((self.whoami.bare,)) + not_in_roster = set(self.contact_list._cache).difference(self.contact_list._roster).difference(self.contact_list._specials).difference((self.contact_list.whoami.bare,)) if not_in_roster: content.append(urwid.Divider('-')) self._buildEntities(content, not_in_roster) return urwid.ListBox(content) + +quick_widgets.register(QuickContactList, ContactList)