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:
souliane 2015-04-20 16:39:38 +02:00
commit 41b549f7ae
4 changed files with 30 additions and 38 deletions

View file

@ -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()

View file

@ -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()

View file

@ -96,11 +96,11 @@ class ProfileManager(object):
contact_list.setCache(jid.JID(entity), key, value)
if not self.bridge.isConnected(self.profile):
self.host.setStatusOnline(False, profile=self.profile)
self.host.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=self.profile)
else:
self.host.setStatusOnline(True, profile=self.profile)
contact_list.fill()
self.host.setPresenceStatus(profile=self.profile)
#The waiting subscription requests
self.bridge.getWaitingSub(self.profile, callback=self._plug_profile_gotWaitingSub)
@ -125,7 +125,6 @@ class ProfileManager(object):
#Presence must be requested after rooms are filled
self.host.bridge.getPresenceStatuses(self.profile, callback=self._plug_profile_gotPresences)
def _plug_profile_gotPresences(self, presences):
def gotEntityData(data, contact):
for key in ('avatar', 'nick'):
@ -443,13 +442,13 @@ class QuickApp(object):
def connectedHandler(self, profile):
"""called when the connection is made"""
log.debug(_("Connected"))
self.setStatusOnline(True, profile=profile)
self.setPresenceStatus(profile=profile)
def disconnectedHandler(self, profile):
"""called when the connection is closed"""
log.debug(_("Disconnected"))
self.contact_lists[profile].clearContacts()
self.setStatusOnline(False, profile=profile)
self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
def newContactHandler(self, JabberId, attributes, groups, profile):
entity = jid.JID(JabberId)
@ -505,20 +504,22 @@ class QuickApp(object):
assert alert_type in ['INFO', 'ERROR']
self.showDialog(unicode(msg), unicode(title), alert_type.lower())
def setStatusOnline(self, online=True, show="", statuses={}, profile=C.PROF_KEY_NONE):
def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
raise NotImplementedError
def presenceUpdateHandler(self, entity_s, show, priority, statuses, profile):
log.debug(_(u"presence update for %(entity)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]")
% {'entity': entity_s, C.PRESENCE_SHOW: show, C.PRESENCE_PRIORITY: priority, C.PRESENCE_STATUSES: statuses, 'profile': profile})
% {'entity': entity_s, C.PRESENCE_SHOW: show, C.PRESENCE_PRIORITY: priority, C.PRESENCE_STATUSES: statuses, 'profile': profile})
entity = jid.JID(entity_s)
if entity == self.profiles[profile].whoami:
if show == "unavailable":
self.setStatusOnline(False, profile=profile)
if show == C.PRESENCE_UNAVAILABLE:
self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
else:
self.setStatusOnline(True, show, statuses, profile=profile)
# FIXME: try to retrieve user language status before fallback to default
status = statuses.get(C.PRESENCE_STATUSES_DEFAULT, None)
self.setPresenceStatus(show, status, profile=profile)
return
# #FIXME: must be moved in a plugin

View file

@ -175,7 +175,7 @@ class QuickContactList(QuickWidget):
if name == 'status': # XXX: we get the first status for 'status' key
# TODO: manage main language for statuses
return cache[C.PRESENCE_STATUSES].get('default', '')
return cache[C.PRESENCE_STATUSES].get(C.PRESENCE_STATUSES_DEFAULT, '')
return cache[name]
except KeyError:
@ -330,7 +330,7 @@ class QuickContactList(QuickWidget):
else:
alerts = {alert.bare for alert in self._alerts}
selected = {selected.bare for selected in self._selected}
return ((show is not None and show != "unavailable")
return ((show is not None and show != C.PRESENCE_UNAVAILABLE)
or self.show_disconnected
or entity in alerts
or entity in selected)