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
This commit is contained in:
parent
e4cb7f59d3
commit
41b549f7ae
2 changed files with 30 additions and 38 deletions
|
|
@ -746,14 +746,8 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
|
||||
#MISC CALLBACKS#
|
||||
|
||||
def setStatusOnline(self, online=True, show="", statuses={}, profile=C.PROF_KEY_NONE):
|
||||
if not online or not statuses:
|
||||
self.contact_lists[profile].status_bar.setPresenceStatus(show if online else 'unavailable', '')
|
||||
return
|
||||
try:
|
||||
self.contact_lists[profile].status_bar.setPresenceStatus(show, statuses['default'])
|
||||
except (KeyError, TypeError):
|
||||
pass
|
||||
def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
|
||||
self.contact_lists[profile].status_bar.setPresenceStatus(show, status)
|
||||
|
||||
sat = PrimitivusApp()
|
||||
sat.start()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ from sat.core.i18n import _
|
|||
import urwid
|
||||
from urwid_satext import sat_widgets
|
||||
from sat_frontends.quick_frontend.constants import Const as commonConst
|
||||
from sat_frontends.primitivus.constants import Const
|
||||
from sat_frontends.primitivus.constants import Const as C
|
||||
|
||||
|
||||
class StatusBar(urwid.Columns):
|
||||
|
|
@ -32,7 +32,7 @@ class StatusBar(urwid.Columns):
|
|||
status_prefix = urwid.Text('[')
|
||||
status_suffix = urwid.Text(']')
|
||||
self.status = sat_widgets.ClickableText('')
|
||||
self.setPresenceStatus('unavailable', '')
|
||||
self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '')
|
||||
urwid.Columns.__init__(self, [('weight', 1, self.presence), ('weight', 1, status_prefix),
|
||||
('weight', 9, self.status), ('weight', 1, status_suffix)])
|
||||
urwid.connect_signal(self.presence, 'click', self.onPresenceClick)
|
||||
|
|
@ -55,19 +55,20 @@ class StatusBar(urwid.Columns):
|
|||
|
||||
def onChange(self, sender=None, user_data=None):
|
||||
new_value = user_data.get_text()
|
||||
previous = ([key for key in Const.PRESENCE if Const.PRESENCE[key][0] == self.presence.get_text()][0], self.status.get_text())
|
||||
previous = ([key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][0], self.status.get_text())
|
||||
if isinstance(user_data, sat_widgets.ClickableText):
|
||||
new = ([key for key in commonConst.PRESENCE if commonConst.PRESENCE[key] == new_value][0], previous[1])
|
||||
elif isinstance(user_data, sat_widgets.AdvancedEdit):
|
||||
new = (previous[0], new_value[0])
|
||||
if new != previous:
|
||||
for profile in self.host.profiles: # FIXME: for now all the profiles share the same status
|
||||
self.host.bridge.setPresence(show=new[0], statuses={'default': new[1]}, profile_key=profile) # FIXME: manage multilingual statuses
|
||||
self.host.bridge.setPresence(show=new[0], status=new[1], profile_key=profile) # FIXME: manage multilingual statuses
|
||||
self.setPresenceStatus(new[0], new[1])
|
||||
self.host.removePopUp()
|
||||
|
||||
def setPresenceStatus(self, show, status):
|
||||
show_icon, show_attr = Const.PRESENCE.get(show)
|
||||
show_icon, show_attr = C.PRESENCE.get(show)
|
||||
self.presence.set_text(('show_normal', show_icon))
|
||||
self.status.set_text((show_attr, status))
|
||||
if status is not None:
|
||||
self.status.set_text((show_attr, status))
|
||||
self.host.redraw()
|
||||
|
|
|
|||
Loading…
Reference in a new issue