Mercurial > libervia-backend
comparison frontends/src/primitivus/contact_list.py @ 1229:03661d1b216a
primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 06 Oct 2014 12:44:58 +0200 |
parents | f36d7068a44b |
children | 3abc6563a0d2 |
comparison
equal
deleted
inserted
replaced
1228:2e1b4e7c8eb8 | 1229:03661d1b216a |
---|---|
22 from urwid_satext import sat_widgets | 22 from urwid_satext import sat_widgets |
23 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList | 23 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList |
24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate | 24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate |
25 from sat_frontends.tools.jid import JID | 25 from sat_frontends.tools.jid import JID |
26 from sat_frontends.primitivus.status import StatusBar | 26 from sat_frontends.primitivus.status import StatusBar |
27 from sat_frontends.primitivus.constants import Const | 27 from sat_frontends.primitivus.constants import Const as C |
28 from sat_frontends.primitivus.keys import action_key_map as a_key | 28 from sat_frontends.primitivus.keys import action_key_map as a_key |
29 from sat.core import log as logging | 29 from sat.core import log as logging |
30 log = logging.getLogger(__name__) | 30 log = logging.getLogger(__name__) |
31 | 31 |
32 | 32 |
39 self.selected = None | 39 self.selected = None |
40 self.groups={} | 40 self.groups={} |
41 self.alert_jid=set() | 41 self.alert_jid=set() |
42 self.show_status = False | 42 self.show_status = False |
43 self.show_disconnected = False | 43 self.show_disconnected = False |
44 self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=host.profile, callback=self.showOfflineContacts) | |
44 | 45 |
45 #we now build the widget | 46 #we now build the widget |
46 self.host.status_bar = StatusBar(host) | 47 self.host.status_bar = StatusBar(host) |
47 self.frame = sat_widgets.FocusFrame(self.__buildList(), None, self.host.status_bar) | 48 self.frame = sat_widgets.FocusFrame(self.__buildList(), None, self.host.status_bar) |
48 self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts"))) | 49 self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts"))) |
75 return key | 76 return key |
76 if key == a_key['STATUS_HIDE']: #user wants to (un)hide contacts' statuses | 77 if key == a_key['STATUS_HIDE']: #user wants to (un)hide contacts' statuses |
77 self.show_status = not self.show_status | 78 self.show_status = not self.show_status |
78 self.update() | 79 self.update() |
79 elif key == a_key['DISCONNECTED_HIDE']: #user wants to (un)hide disconnected contacts | 80 elif key == a_key['DISCONNECTED_HIDE']: #user wants to (un)hide disconnected contacts |
80 self.show_disconnected = not self.show_disconnected | 81 self.host.bridge.setParam(C.SHOW_OFFLINE_CONTACTS, C.str(not self.show_disconnected), "General", profile_key=self.host.profile) |
81 self.update() | |
82 return super(ContactList, self).keypress(size, key) | 82 return super(ContactList, self).keypress(size, key) |
83 | 83 |
84 def __contains__(self, jid): | 84 def __contains__(self, jid): |
85 for group in self.groups: | 85 for group in self.groups: |
86 if jid.bare in self.groups[group][1]: | 86 if jid.bare in self.groups[group][1]: |
98 try: | 98 try: |
99 if isinstance(widget, sat_widgets.ClickableText): | 99 if isinstance(widget, sat_widgets.ClickableText): |
100 # contact group | 100 # contact group |
101 value = widget.getValue() | 101 value = widget.getValue() |
102 elif isinstance(widget, sat_widgets.SelectableText): | 102 elif isinstance(widget, sat_widgets.SelectableText): |
103 if widget.data.startswith(Const.PRIVATE_PREFIX): | 103 if widget.data.startswith(C.PRIVATE_PREFIX): |
104 # muc private dialog | 104 # muc private dialog |
105 value = widget.getValue() | 105 value = widget.getValue() |
106 else: | 106 else: |
107 # contact or muc | 107 # contact or muc |
108 value = widget.data | 108 value = widget.data |
148 contacts = list(param_contacts) | 148 contacts = list(param_contacts) |
149 | 149 |
150 widgets = [] #list of built widgets | 150 widgets = [] #list of built widgets |
151 | 151 |
152 for contact in contacts: | 152 for contact in contacts: |
153 if contact.startswith(Const.PRIVATE_PREFIX): | 153 if contact.startswith(C.PRIVATE_PREFIX): |
154 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact)) | 154 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact)) |
155 show_icon = '' | 155 show_icon = '' |
156 status = '' | 156 status = '' |
157 else: | 157 else: |
158 jid=JID(contact) | 158 jid=JID(contact) |
163 if show == None: | 163 if show == None: |
164 show = "unavailable" | 164 show = "unavailable" |
165 if (not self.show_disconnected and show == "unavailable" | 165 if (not self.show_disconnected and show == "unavailable" |
166 and not contact in self.alert_jid and contact != self.selected): | 166 and not contact in self.alert_jid and contact != self.selected): |
167 continue | 167 continue |
168 show_icon, show_attr = Const.PRESENCE.get(show, ('', 'default')) | 168 show_icon, show_attr = C.PRESENCE.get(show, ('', 'default')) |
169 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare) | 169 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare) |
170 display = [ show_icon + " " , contact_disp] | 170 display = [ show_icon + " " , contact_disp] |
171 if self.show_status: | 171 if self.show_status: |
172 status_disp = ('status',"\n " + status) if status else "" | 172 status_disp = ('status',"\n " + status) if status else "" |
173 display.append(status_disp) | 173 display.append(status_disp) |
317 | 317 |
318 def updatePresence(self, jid, show, priority, statuses): | 318 def updatePresence(self, jid, show, priority, statuses): |
319 #XXX: for the moment, we ignore presence updates for special entities | 319 #XXX: for the moment, we ignore presence updates for special entities |
320 if jid.bare not in self.specials: | 320 if jid.bare not in self.specials: |
321 QuickContactList.updatePresence(self, jid, show, priority, statuses) | 321 QuickContactList.updatePresence(self, jid, show, priority, statuses) |
322 | |
323 def showOfflineContacts(self, show): | |
324 show = C.bool(show) | |
325 if self.show_disconnected == show: | |
326 return | |
327 self.show_disconnected = show | |
328 self.update() |