Mercurial > libervia-backend
diff frontends/src/primitivus/contact_list.py @ 510:886754295efe
quick frontend, primitivus, wix: MUC private messages management
/!\ not fully finished, backend part is not done yet /!\
- as resources are discarded to manage chat windows lists, a pretty dirty hack is done to work around this:
full jid is escaped using a prefix (it becomes invalid and resource is preserved).
- new quick_utils module, with helper methods. escapePrivate and unescapePrivate implementations
- MUC private messages are not managed in Wix yet
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 11 Oct 2012 00:48:35 +0200 |
parents | f98bef71a918 |
children | 62f7f2403093 |
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py Fri Sep 28 00:48:52 2012 +0200 +++ b/frontends/src/primitivus/contact_list.py Thu Oct 11 00:48:35 2012 +0200 @@ -22,6 +22,7 @@ import urwid from urwid_satext import sat_widgets from sat_frontends.quick_frontend.quick_contact_list import QuickContactList +from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate from sat.tools.jid import JID @@ -29,10 +30,10 @@ signals = ['click','change'] def __init__(self, host, on_click=None, on_change=None, user_data=None): + QuickContactList.__init__(self) self.host = host self.selected = None self.groups={} - self.special={} self.alert_jid=set() self.show_status = False self.show_disconnected = False @@ -45,7 +46,6 @@ urwid.connect_signal(self, 'click', on_click, user_data) if on_change: urwid.connect_signal(self, 'change', on_change, user_data) - QuickContactList.__init__(self) def update(self): """Update display, keep focus""" @@ -115,18 +115,23 @@ widgets = [] #list of built widgets for contact in contacts: - jid=JID(contact) - name = self.getCache(jid, 'name') - nick = self.getCache(jid, 'nick') - status = self.getCache(jid, 'status') - show = self.getCache(jid, 'show') - if show == None: - show = "unavailable" - if (not self.show_disconnected and show == "unavailable" - and not contact in self.alert_jid and contact != self.selected): - continue - show_icon, show_attr = const_SHOW_ICON.get(show,('','default')) - contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short) + if contact.startswith(const_PRIVATE_PREFIX): + contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact)) + show_icon = '' + status = '' + else: + jid=JID(contact) + name = self.getCache(jid, 'name') + nick = self.getCache(jid, 'nick') + status = self.getCache(jid, 'status') + show = self.getCache(jid, 'show') + if show == None: + show = "unavailable" + if (not self.show_disconnected and show == "unavailable" + and not contact in self.alert_jid and contact != self.selected): + continue + show_icon, show_attr = const_SHOW_ICON.get(show,('','default')) + contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short) display = [ show_icon + " " , contact_disp] if self.show_status: status_disp = ('status',"\n " + status) if status else "" @@ -147,7 +152,7 @@ def __buildSpecials(self, content): """Build the special entities""" - specials = self.special.keys() + specials = self.specials.keys() specials.sort() for special in specials: jid=JID(special) @@ -168,7 +173,7 @@ content = urwid.SimpleListWalker([]) self.__buildSpecials(content) - if self.special: + if self.specials: content.append(urwid.Divider('=')) group_keys = self.groups.keys() @@ -198,6 +203,7 @@ def clearContacts(self): """clear all the contact list""" + QuickContactList.clearContacts(self) self.groups={} self.selected = None self.unselectAll() @@ -205,7 +211,8 @@ def replace(self, jid, groups=None, attributes=None): """add a contact to the list if doesn't exist, else update it""" - if jid.short in self.special: + QuickContactList.replace(self, jid, groups, attributes) + if jid.short in self.specials: return if not groups: groups = [None] @@ -227,10 +234,10 @@ self.list_wid.changeValues(contacts) self._emit('change')""" - def remove(self, param_jid): + def remove(self, jid): """remove a contact from the list""" + QuickContactList.remove(self, jid) groups_to_remove = [] - jid = JID(param_jid) for group in self.groups: contacts = self.groups[group][1] if jid.short in contacts: @@ -239,10 +246,6 @@ groups_to_remove.append(group) for group in groups_to_remove: del self.groups[group] - try: - del self.special[jid.short] - except KeyError: - pass self.update() def add(self, jid, param_groups=[None]): @@ -254,7 +257,7 @@ @param jid: jid of the entity @param _type: special type (e.g.: "MUC") """ - self.special[special_jid.short] = special_type + QuickContactList.setSpecial(self, special_jid, special_type) if None in self.groups: folded,group_jids = self.groups[None] for group_jid in group_jids: @@ -265,5 +268,5 @@ def updatePresence(self, jid, show, priority, statuses): #XXX: for the moment, we ignore presence updates for special entities - if jid.short not in self.special: + if jid.short not in self.specials: QuickContactList.updatePresence(self, jid, show, priority, statuses)