comparison frontends/src/primitivus/status.py @ 1417:176de79c8c39

core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus": - remove parameter "online" (can be guess from "presence" value) - process "statuses" dict in quick_frontend, so this method can get a simple unicode "status" - add C.PRESENCE_STATUSES_DEFAULT to define the key to use for fallback status
author souliane <souliane@mailoo.org>
date Mon, 20 Apr 2015 16:39:38 +0200
parents 069ad98b360d
children b06047e1c1fb
comparison
equal deleted inserted replaced
1416:a419da93afef 1417:176de79c8c39
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 import urwid 21 import urwid
22 from urwid_satext import sat_widgets 22 from urwid_satext import sat_widgets
23 from sat_frontends.quick_frontend.constants import Const as commonConst 23 from sat_frontends.quick_frontend.constants import Const as commonConst
24 from sat_frontends.primitivus.constants import Const 24 from sat_frontends.primitivus.constants import Const as C
25 25
26 26
27 class StatusBar(urwid.Columns): 27 class StatusBar(urwid.Columns):
28 28
29 def __init__(self, host): 29 def __init__(self, host):
30 self.host = host 30 self.host = host
31 self.presence = sat_widgets.ClickableText('') 31 self.presence = sat_widgets.ClickableText('')
32 status_prefix = urwid.Text('[') 32 status_prefix = urwid.Text('[')
33 status_suffix = urwid.Text(']') 33 status_suffix = urwid.Text(']')
34 self.status = sat_widgets.ClickableText('') 34 self.status = sat_widgets.ClickableText('')
35 self.setPresenceStatus('unavailable', '') 35 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '')
36 urwid.Columns.__init__(self, [('weight', 1, self.presence), ('weight', 1, status_prefix), 36 urwid.Columns.__init__(self, [('weight', 1, self.presence), ('weight', 1, status_prefix),
37 ('weight', 9, self.status), ('weight', 1, status_suffix)]) 37 ('weight', 9, self.status), ('weight', 1, status_suffix)])
38 urwid.connect_signal(self.presence, 'click', self.onPresenceClick) 38 urwid.connect_signal(self.presence, 'click', self.onPresenceClick)
39 urwid.connect_signal(self.status, 'click', self.onStatusClick) 39 urwid.connect_signal(self.status, 'click', self.onStatusClick)
40 40
53 cancel_cb=self.host.removePopUp, ok_cb=self.onChange) 53 cancel_cb=self.host.removePopUp, ok_cb=self.onChange)
54 self.host.showPopUp(pop_up_widget) 54 self.host.showPopUp(pop_up_widget)
55 55
56 def onChange(self, sender=None, user_data=None): 56 def onChange(self, sender=None, user_data=None):
57 new_value = user_data.get_text() 57 new_value = user_data.get_text()
58 previous = ([key for key in Const.PRESENCE if Const.PRESENCE[key][0] == self.presence.get_text()][0], self.status.get_text()) 58 previous = ([key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][0], self.status.get_text())
59 if isinstance(user_data, sat_widgets.ClickableText): 59 if isinstance(user_data, sat_widgets.ClickableText):
60 new = ([key for key in commonConst.PRESENCE if commonConst.PRESENCE[key] == new_value][0], previous[1]) 60 new = ([key for key in commonConst.PRESENCE if commonConst.PRESENCE[key] == new_value][0], previous[1])
61 elif isinstance(user_data, sat_widgets.AdvancedEdit): 61 elif isinstance(user_data, sat_widgets.AdvancedEdit):
62 new = (previous[0], new_value[0]) 62 new = (previous[0], new_value[0])
63 if new != previous: 63 if new != previous:
64 for profile in self.host.profiles: # FIXME: for now all the profiles share the same status 64 for profile in self.host.profiles: # FIXME: for now all the profiles share the same status
65 self.host.bridge.setPresence(show=new[0], statuses={'default': new[1]}, profile_key=profile) # FIXME: manage multilingual statuses 65 self.host.bridge.setPresence(show=new[0], status=new[1], profile_key=profile) # FIXME: manage multilingual statuses
66 self.setPresenceStatus(new[0], new[1]) 66 self.setPresenceStatus(new[0], new[1])
67 self.host.removePopUp() 67 self.host.removePopUp()
68 68
69 def setPresenceStatus(self, show, status): 69 def setPresenceStatus(self, show, status):
70 show_icon, show_attr = Const.PRESENCE.get(show) 70 show_icon, show_attr = C.PRESENCE.get(show)
71 self.presence.set_text(('show_normal', show_icon)) 71 self.presence.set_text(('show_normal', show_icon))
72 self.status.set_text((show_attr, status)) 72 if status is not None:
73 self.status.set_text((show_attr, status))
73 self.host.redraw() 74 self.host.redraw()