comparison frontends/src/primitivus/chat.py @ 907:cd02f5ef30df

primitivus: display chat states (with symbols) for MUC participants
author souliane <souliane@mailoo.org>
date Mon, 17 Mar 2014 13:24:55 +0100
parents f3513c8cc2e6
children b12706d164d7
comparison
equal deleted inserted replaced
906:1cbae66fa725 907:cd02f5ef30df
23 from urwid_satext.files_management import FileDialog 23 from urwid_satext.files_management import FileDialog
24 from sat_frontends.quick_frontend.quick_chat import QuickChat 24 from sat_frontends.quick_frontend.quick_chat import QuickChat
25 from sat_frontends.primitivus.card_game import CardGame 25 from sat_frontends.primitivus.card_game import CardGame
26 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate 26 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
27 from sat_frontends.primitivus.xmlui import XMLUI 27 from sat_frontends.primitivus.xmlui import XMLUI
28 from sat_frontends.primitivus.constants import Const
28 import time 29 import time
29 from sat.tools.jid import JID 30 from sat.tools.jid import JID
30 31
31 32
32 class ChatText(urwid.FlowWidget): 33 class ChatText(urwid.FlowWidget):
173 main_widget = self.__getDecoration(self.pile) 174 main_widget = self.__getDecoration(self.pile)
174 else: 175 else:
175 main_widget = self.pile 176 main_widget = self.pile
176 self._w = main_widget 177 self._w = main_widget
177 178
178 def updateChatState(self, state): 179 def updateChatState(self, state, nick=None):
179 """Update the chat state of the contact. 180 """Set the chat state (XEP-0085) of the contact. Leave nick to None
180 @param state: new state to set 181 to set the state for a one2one conversation, or give a nickname or
181 """ 182 Const.ALL_OCCUPANTS to set the state of a participant within a MUC.
182 if (self.type == 'one2one'): 183 @param state: the new chat state
184 @param nick: None for one2one, the MUC user nick or Const.ALL_OCCUPANTS
185 """
186 if nick:
187 assert(self.type == 'group')
188 occupants = self.occupants if nick == Const.ALL_OCCUPANTS else [nick]
189 options = self.present_wid.getAllValues()
190 for index in xrange(0, len(options)):
191 nick = options[index].value
192 if nick in occupants:
193 options[index] = (nick, '%s %s' % (Const.MUC_USER_STATES[state], nick))
194 self.present_wid.changeValues(options)
195 self.host.redraw()
196 else:
197 assert(self.type == 'one2one')
183 self.__setSurrendedText(state) 198 self.__setSurrendedText(state)
184 self.showDecoration() 199 self.showDecoration()
185 self.host.redraw() 200 self.host.redraw()
186 elif (self.type == 'group'):
187 # TODO: chat state for groupchat
188 pass
189 201
190 def _presentClicked(self, list_wid, clicked_wid): 202 def _presentClicked(self, list_wid, clicked_wid):
191 assert(self.type == 'group') 203 assert(self.type == 'group')
192 nick = clicked_wid.getValue() 204 nick = clicked_wid.getValue().value
193 if nick == self.getUserNick(): 205 if nick == self.getUserNick():
194 #We ignore click on our own nick 206 #We ignore click on our own nick
195 return 207 return
196 #we have a click on a nick, we add the private conversation to the contact_list 208 #we have a click on a nick, we add the private conversation to the contact_list
197 full_jid = JID("%s/%s" % (self.target.bare, nick)) 209 full_jid = JID("%s/%s" % (self.target.bare, nick))
248 def replaceUser(self, param_nick, show_info=True): 260 def replaceUser(self, param_nick, show_info=True):
249 """Add user if it is not in the group list""" 261 """Add user if it is not in the group list"""
250 nick = unicode(param_nick) #FIXME: should be done in DBus bridge 262 nick = unicode(param_nick) #FIXME: should be done in DBus bridge
251 QuickChat.replaceUser(self, nick, show_info) 263 QuickChat.replaceUser(self, nick, show_info)
252 presents = self.present_wid.getAllValues() 264 presents = self.present_wid.getAllValues()
253 if nick not in presents: 265 if nick not in [present.value for present in presents]:
254 presents.append(nick) 266 presents.append(nick)
255 presents.sort() 267 presents.sort(cmp=lambda a, b: cmp(a.value if hasattr(a, 'value') else a, b.value if hasattr(b, 'value') else b))
256 self.present_wid.changeValues(presents) 268 self.present_wid.changeValues(presents)
257 self.host.redraw() 269 self.host.redraw()
258 270
259 def removeUser(self, param_nick, show_info=True): 271 def removeUser(self, param_nick, show_info=True):
260 """Remove a user from the group list""" 272 """Remove a user from the group list"""