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
8 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)

View file

@ -98,6 +98,7 @@ class Const(object):
PRESENCE_SHOW_XA = 'xa'
PRESENCE_SHOW = 'show'
PRESENCE_STATUSES = 'statuses'
PRESENCE_STATUSES_DEFAULT = 'default'
PRESENCE_PRIORITY = 'priority'

View file

@ -603,8 +603,7 @@ class SAT(service.Service):
self.profiles[profile].presence.available(to_jid, show, statuses, priority)
#XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not broadcasted to generating resource)
if '' in statuses:
statuses['default'] = statuses['']
del statuses['']
statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop('')
self.bridge.presenceUpdate(self.profiles[profile].jid.full(), show,
int(priority), statuses, profile)

View file

@ -315,8 +315,7 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
statuses = {}
if None in statuses: # we only want string keys
statuses["default"] = statuses[None]
del statuses[None]
statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None)
self.host.memory.setPresenceStatus(entity, show or "",
int(priority), statuses,
@ -334,8 +333,7 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
statuses = {}
if None in statuses: # we only want string keys
statuses["default"] = statuses[None]
del statuses[None]
statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None)
self.host.memory.setPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile)
if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile):
@ -356,16 +354,14 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
# default for us is None for wokkel
# so we must temporarily switch to wokkel's convention...
if 'default' in statuses:
statuses[None] = statuses['default']
del statuses['default']
if C.PRESENCE_STATUSES_DEFAULT in statuses:
statuses[None] = statuses.pop(C.PRESENCE_STATUSES_DEFAULT)
presence_elt = xmppim.AvailablePresence(entity, show, statuses, priority)
# ... before switching back
if None in statuses:
statuses['default'] = statuses[None]
del statuses[None]
statuses['default'] = statuses.pop(None)
if not self.host.trigger.point("presence_available", presence_elt, self.parent):
return

View file

@ -734,7 +734,7 @@ class SatMUCClient (muc.MUCClient):
self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile)
def userUpdatedStatus(self, room, user, show, status):
self.host.bridge.presenceUpdate(room.roomJID.userhost() + '/' + user.nick, show or '', 0, {'default': status or ''}, self.parent.profile)
self.host.bridge.presenceUpdate(room.roomJID.userhost() + '/' + user.nick, show or '', 0, {C.PRESENCE_STATUSES_DEFAULT: status or ''}, self.parent.profile)
def receivedGroupChat(self, room, user, body):
log.debug(u'receivedGroupChat: room=%s user=%s body=%s' % (room.roomJID.full(), user, body))