primitivus: display chat states (with symbols) for MUC participants
This commit is contained in:
parent
73b374f6fc
commit
67d15eb488
7 changed files with 80 additions and 41 deletions
|
|
@ -62,6 +62,16 @@ class Const(object):
|
||||||
|
|
||||||
NO_SECURITY_LIMIT = -1
|
NO_SECURITY_LIMIT = -1
|
||||||
|
|
||||||
#XMLUI
|
# XMLUI
|
||||||
SAT_FORM_PREFIX = "SAT_FORM_"
|
SAT_FORM_PREFIX = "SAT_FORM_"
|
||||||
SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
|
SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
|
||||||
|
|
||||||
|
# MUC
|
||||||
|
ALL_OCCUPANTS = 1
|
||||||
|
MUC_USER_STATES = {
|
||||||
|
"active": u'✔',
|
||||||
|
"inactive": u'☄',
|
||||||
|
"gone": u'✈',
|
||||||
|
"composing": u'✎',
|
||||||
|
"paused": u"⦷"
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ from sat_frontends.quick_frontend.quick_chat import QuickChat
|
||||||
from sat_frontends.primitivus.card_game import CardGame
|
from sat_frontends.primitivus.card_game import CardGame
|
||||||
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
|
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
|
||||||
from sat_frontends.primitivus.xmlui import XMLUI
|
from sat_frontends.primitivus.xmlui import XMLUI
|
||||||
|
from sat_frontends.primitivus.constants import Const
|
||||||
import time
|
import time
|
||||||
from sat.tools.jid import JID
|
from sat.tools.jid import JID
|
||||||
|
|
||||||
|
|
@ -175,21 +176,32 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
||||||
main_widget = self.pile
|
main_widget = self.pile
|
||||||
self._w = main_widget
|
self._w = main_widget
|
||||||
|
|
||||||
def updateChatState(self, state):
|
def updateChatState(self, state, nick=None):
|
||||||
"""Update the chat state of the contact.
|
"""Set the chat state (XEP-0085) of the contact. Leave nick to None
|
||||||
@param state: new state to set
|
to set the state for a one2one conversation, or give a nickname or
|
||||||
|
Const.ALL_OCCUPANTS to set the state of a participant within a MUC.
|
||||||
|
@param state: the new chat state
|
||||||
|
@param nick: None for one2one, the MUC user nick or Const.ALL_OCCUPANTS
|
||||||
"""
|
"""
|
||||||
if (self.type == 'one2one'):
|
if nick:
|
||||||
|
assert(self.type == 'group')
|
||||||
|
occupants = self.occupants if nick == Const.ALL_OCCUPANTS else [nick]
|
||||||
|
options = self.present_wid.getAllValues()
|
||||||
|
for index in xrange(0, len(options)):
|
||||||
|
nick = options[index].value
|
||||||
|
if nick in occupants:
|
||||||
|
options[index] = (nick, '%s %s' % (Const.MUC_USER_STATES[state], nick))
|
||||||
|
self.present_wid.changeValues(options)
|
||||||
|
self.host.redraw()
|
||||||
|
else:
|
||||||
|
assert(self.type == 'one2one')
|
||||||
self.__setSurrendedText(state)
|
self.__setSurrendedText(state)
|
||||||
self.showDecoration()
|
self.showDecoration()
|
||||||
self.host.redraw()
|
self.host.redraw()
|
||||||
elif (self.type == 'group'):
|
|
||||||
# TODO: chat state for groupchat
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _presentClicked(self, list_wid, clicked_wid):
|
def _presentClicked(self, list_wid, clicked_wid):
|
||||||
assert(self.type == 'group')
|
assert(self.type == 'group')
|
||||||
nick = clicked_wid.getValue()
|
nick = clicked_wid.getValue().value
|
||||||
if nick == self.getUserNick():
|
if nick == self.getUserNick():
|
||||||
#We ignore click on our own nick
|
#We ignore click on our own nick
|
||||||
return
|
return
|
||||||
|
|
@ -250,9 +262,9 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
||||||
nick = unicode(param_nick) #FIXME: should be done in DBus bridge
|
nick = unicode(param_nick) #FIXME: should be done in DBus bridge
|
||||||
QuickChat.replaceUser(self, nick, show_info)
|
QuickChat.replaceUser(self, nick, show_info)
|
||||||
presents = self.present_wid.getAllValues()
|
presents = self.present_wid.getAllValues()
|
||||||
if nick not in presents:
|
if nick not in [present.value for present in presents]:
|
||||||
presents.append(nick)
|
presents.append(nick)
|
||||||
presents.sort()
|
presents.sort(cmp=lambda a, b: cmp(a.value if hasattr(a, 'value') else a, b.value if hasattr(b, 'value') else b))
|
||||||
self.present_wid.changeValues(presents)
|
self.present_wid.changeValues(presents)
|
||||||
self.host.redraw()
|
self.host.redraw()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -604,24 +604,6 @@ class PrimitivusApp(QuickApp, InputHistory):
|
||||||
|
|
||||||
#MISC CALLBACKS#
|
#MISC CALLBACKS#
|
||||||
|
|
||||||
def chatStateReceived(self, from_jid_s, state, profile):
|
|
||||||
"""Signal observer to display a contact chat state
|
|
||||||
@param from_jid_s: contact who sent his new state
|
|
||||||
@state: state
|
|
||||||
@profile: current profile
|
|
||||||
"""
|
|
||||||
if not self.check_profile(profile):
|
|
||||||
return
|
|
||||||
|
|
||||||
if from_jid_s == "@ALL@":
|
|
||||||
for win in self.chat_wins:
|
|
||||||
self.chat_wins[win].updateChatState(state)
|
|
||||||
return
|
|
||||||
|
|
||||||
from_bare = JID(from_jid_s).bare
|
|
||||||
if from_bare in self.chat_wins:
|
|
||||||
self.chat_wins[from_bare].updateChatState(state)
|
|
||||||
|
|
||||||
def setStatusOnline(self, online=True, show="", statuses={}):
|
def setStatusOnline(self, online=True, show="", statuses={}):
|
||||||
if not online or not statuses:
|
if not online or not statuses:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -496,6 +496,31 @@ class QuickApp(object):
|
||||||
if room_jid in self.chat_wins:
|
if room_jid in self.chat_wins:
|
||||||
self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestarted(time_left)
|
self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestarted(time_left)
|
||||||
|
|
||||||
|
def chatStateReceived(self, from_jid_s, state, profile):
|
||||||
|
"""Callback when a new chat state is received.
|
||||||
|
@param from_jid_s: JID of the contact who sent his state, or '@ALL@'
|
||||||
|
@param state: new state (string)
|
||||||
|
@profile: current profile
|
||||||
|
"""
|
||||||
|
if not self.check_profile(profile):
|
||||||
|
return
|
||||||
|
|
||||||
|
if from_jid_s == '@ALL@':
|
||||||
|
target = '@ALL@'
|
||||||
|
nick = Const.ALL_OCCUPANTS
|
||||||
|
else:
|
||||||
|
from_jid = JID(from_jid_s)
|
||||||
|
target = from_jid.bare
|
||||||
|
nick = from_jid.resource
|
||||||
|
|
||||||
|
for bare in self.chat_wins.keys():
|
||||||
|
if target == '@ALL' or target == bare:
|
||||||
|
chat_win = self.chat_wins[bare]
|
||||||
|
if chat_win.type == 'one2one':
|
||||||
|
chat_win.updateChatState(state)
|
||||||
|
elif chat_win.type == 'group':
|
||||||
|
chat_win.updateChatState(state, nick=nick)
|
||||||
|
|
||||||
def _subscribe_cb(self, answer, data):
|
def _subscribe_cb(self, answer, data):
|
||||||
entity, profile = data
|
entity, profile = data
|
||||||
if answer:
|
if answer:
|
||||||
|
|
|
||||||
|
|
@ -153,3 +153,12 @@ class QuickChat(object):
|
||||||
#No need to raise an error as game are not mandatory
|
#No need to raise an error as game are not mandatory
|
||||||
warning(_('getGame is not implemented in this frontend'))
|
warning(_('getGame is not implemented in this frontend'))
|
||||||
|
|
||||||
|
def updateChatState(self, state, nick=None):
|
||||||
|
"""Set the chat state (XEP-0085) of the contact. Leave nick to None
|
||||||
|
to set the state for a one2one conversation, or give a nickname or
|
||||||
|
Const.ALL_OCCUPANTS to set the state of a participant within a MUC.
|
||||||
|
@param state: the new chat state
|
||||||
|
@param nick: None for one2one, the MUC user nick or ALL_OCCUPANTS
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -267,10 +267,20 @@ class Chat(wx.Frame, QuickChat):
|
||||||
self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), self.host.profile)
|
self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename), self.host.profile)
|
||||||
|
|
||||||
def onStartTarot(self, e):
|
def onStartTarot(self, e):
|
||||||
debug (_("Starting Tarot game"))
|
debug(_("Starting Tarot game"))
|
||||||
warning (_("FIXME: temporary menu, must be changed"))
|
warning(_("FIXME: temporary menu, must be changed"))
|
||||||
if len(self.occupants) != 4:
|
if len(self.occupants) != 4:
|
||||||
err_dlg = wx.MessageDialog(self, _("You need to be exactly 4 peoples in the room to start a Tarot game"), _("Can't start game"), style = wx.OK | wx.ICON_ERROR) #FIXME: gof: temporary only, need to choose the people with who the game has to be started
|
err_dlg = wx.MessageDialog(self, _("You need to be exactly 4 peoples in the room to start a Tarot game"), _("Can't start game"), style = wx.OK | wx.ICON_ERROR) #FIXME: gof: temporary only, need to choose the people with who the game has to be started
|
||||||
err_dlg.ShowModal()
|
err_dlg.ShowModal()
|
||||||
else:
|
else:
|
||||||
self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)
|
self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)
|
||||||
|
|
||||||
|
def updateChatState(self, state, nick=None):
|
||||||
|
"""Set the chat state (XEP-0085) of the contact. Leave nick to None
|
||||||
|
to set the state for a one2one conversation, or give a nickname or
|
||||||
|
Const.ALL_OCCUPANTS to set the state of a participant within a MUC.
|
||||||
|
@param state: the new chat state
|
||||||
|
@param nick: None for one2one, the MUC user nick or Const.ALL_OCCUPANTS
|
||||||
|
"""
|
||||||
|
#TODO: chat states not implemented yet
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -523,12 +523,3 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
self.Show()
|
self.Show()
|
||||||
self.Raise()
|
self.Raise()
|
||||||
e.Skip()
|
e.Skip()
|
||||||
|
|
||||||
def chatStateReceived(self, from_jid_s, state, profile):
|
|
||||||
"""Signal observer to display a contact chat state
|
|
||||||
@param from_jid_s: contact who sent his new state
|
|
||||||
@state: state
|
|
||||||
@profile: current profile
|
|
||||||
"""
|
|
||||||
print "TODO: chatStateReceived not implemented yet"
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue