comparison browser_side/base_panels.py @ 407:6a6551de4414

browser_side: display chat states (with symbols) for MUC participants
author souliane <souliane@mailoo.org>
date Sun, 16 Mar 2014 21:03:50 +0100
parents 41b8b96f2248
children 9977de10b7da
comparison
equal deleted inserted replaced
406:63f8469b4ad3 407:6a6551de4414
37 from datetime import datetime 37 from datetime import datetime
38 from time import time 38 from time import time
39 39
40 from html_tools import html_sanitize, html_strip, inlineRoot, convertNewLinesToXHTML 40 from html_tools import html_sanitize, html_strip, inlineRoot, convertNewLinesToXHTML
41 41
42 from constants import Const
42 from sat_frontends.tools.strings import addURLToText, addURLToImage 43 from sat_frontends.tools.strings import addURLToText, addURLToImage
43 from sat.core.i18n import _ 44 from sat.core.i18n import _
44 45
45 46
46 class ChatText(HTMLPanel): 47 class ChatText(HTMLPanel):
60 61
61 62
62 class Occupant(HTML): 63 class Occupant(HTML):
63 """Occupant of a MUC room""" 64 """Occupant of a MUC room"""
64 65
65 def __init__(self, nick, special=""): 66 def __init__(self, nick, state=None, special=""):
67 """
68 @param nick: the user nickname
69 @param state: the user chate state (XEP-0085)
70 @param special: a string of symbols (e.g: for activities)
71 """
66 HTML.__init__(self) 72 HTML.__init__(self)
67 self.nick = nick 73 self.nick = nick
74 self._state = state
68 self.special = special 75 self.special = special
69 self._refresh() 76 self._refresh()
70 77
71 def __str__(self): 78 def __str__(self):
72 return self.nick 79 return self.nick
80
81 def setState(self, state):
82 self._state = state
83 self._refresh()
73 84
74 def addSpecial(self, special): 85 def addSpecial(self, special):
75 """@param special: unicode""" 86 """@param special: unicode"""
76 if special not in self.special: 87 if special not in self.special:
77 self.special += special 88 self.special += special
84 for symbol in special: 95 for symbol in special:
85 self.special = self.special.replace(symbol, "") 96 self.special = self.special.replace(symbol, "")
86 self._refresh() 97 self._refresh()
87 98
88 def _refresh(self): 99 def _refresh(self):
100 state = (' %s' % Const.MUC_USER_STATES[self._state]) if self._state else ''
89 special = "" if len(self.special) == 0 else " %s" % self.special 101 special = "" if len(self.special) == 0 else " %s" % self.special
90 self.setHTML("<div class='occupant'>%s%s</div>" % (html_sanitize(self.nick), special)) 102 self.setHTML("<div class='occupant'>%s%s%s</div>" % (html_sanitize(self.nick), special, state))
91 103
92 104
93 class OccupantsList(AbsolutePanel): 105 class OccupantsList(AbsolutePanel):
94 """Panel user to show occupants of a room""" 106 """Panel user to show occupants of a room"""
95 107