Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_chat.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | beaf6bec2fcd |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
23 from sat.tools.jid import JID | 23 from sat.tools.jid import JID |
24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate | 24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate |
25 | 25 |
26 | 26 |
27 class QuickChat(): | 27 class QuickChat(): |
28 | 28 |
29 def __init__(self, target, host, type='one2one'): | 29 def __init__(self, target, host, type='one2one'): |
30 self.target = target | 30 self.target = target |
31 self.host = host | 31 self.host = host |
32 self.type = type | 32 self.type = type |
33 self.id = "" | 33 self.id = "" |
47 debug (_("Adding users %s to room") % nicks) | 47 debug (_("Adding users %s to room") % nicks) |
48 if self.type != "group": | 48 if self.type != "group": |
49 error (_("[INTERNAL] trying to set presents nicks for a non group chat window")) | 49 error (_("[INTERNAL] trying to set presents nicks for a non group chat window")) |
50 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here | 50 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here |
51 self.occupants.update(nicks) | 51 self.occupants.update(nicks) |
52 | 52 |
53 def replaceUser(self, nick, show_info=True): | 53 def replaceUser(self, nick, show_info=True): |
54 """Add user if it is not in the group list""" | 54 """Add user if it is not in the group list""" |
55 debug (_("Replacing user %s") % nick) | 55 debug (_("Replacing user %s") % nick) |
56 if self.type != "group": | 56 if self.type != "group": |
57 error (_("[INTERNAL] trying to replace user for a non group chat window")) | 57 error (_("[INTERNAL] trying to replace user for a non group chat window")) |
75 """Set the nick of the user, usefull for e.g. change the color of the user""" | 75 """Set the nick of the user, usefull for e.g. change the color of the user""" |
76 self.nick = nick | 76 self.nick = nick |
77 | 77 |
78 def getUserNick(self): | 78 def getUserNick(self): |
79 return unicode(self.nick) | 79 return unicode(self.nick) |
80 | 80 |
81 def changeUserNick(self, old_nick, new_nick): | 81 def changeUserNick(self, old_nick, new_nick): |
82 """Change nick of a user in group list""" | 82 """Change nick of a user in group list""" |
83 debug(_("Changing nick of user %(old_nick)s to %(new_nick)s") % {"old_nick": old_nick, "new_nick": new_nick}) | 83 debug(_("Changing nick of user %(old_nick)s to %(new_nick)s") % {"old_nick": old_nick, "new_nick": new_nick}) |
84 if self.type != "group": | 84 if self.type != "group": |
85 error (_("[INTERNAL] trying to change user nick for a non group chat window")) | 85 error (_("[INTERNAL] trying to change user nick for a non group chat window")) |
97 | 97 |
98 def historyPrint(self, size=20, profile='@NONE@'): | 98 def historyPrint(self, size=20, profile='@NONE@'): |
99 """Print the initial history""" | 99 """Print the initial history""" |
100 debug (_("now we print history")) | 100 debug (_("now we print history")) |
101 def onHistory(history): | 101 def onHistory(history): |
102 for line in history: | 102 for line in history: |
103 timestamp, from_jid, to_jid, message, _type = line | 103 timestamp, from_jid, to_jid, message, _type = line |
104 if ((self.type == 'group' and _type != 'groupchat') or | 104 if ((self.type == 'group' and _type != 'groupchat') or |
105 (self.type == 'one2one' and _type == 'groupchat')): | 105 (self.type == 'one2one' and _type == 'groupchat')): |
106 continue | 106 continue |
107 self.printMessage(JID(from_jid), message, profile, timestamp) | 107 self.printMessage(JID(from_jid), message, profile, timestamp) |
108 | 108 |
109 def onHistoryError(err): | 109 def onHistoryError(err): |
110 error (_("Can't get history")) | 110 error (_("Can't get history")) |
111 | 111 |
112 if self.target.startswith(const_PRIVATE_PREFIX): | 112 if self.target.startswith(const_PRIVATE_PREFIX): |
113 target = unescapePrivate(self.target) | 113 target = unescapePrivate(self.target) |
121 if self.target.startswith(const_PRIVATE_PREFIX): | 121 if self.target.startswith(const_PRIVATE_PREFIX): |
122 unescaped = unescapePrivate(self.target) | 122 unescaped = unescapePrivate(self.target) |
123 if jid.startswith(const_PRIVATE_PREFIX) or unescaped.short == jid.short: | 123 if jid.startswith(const_PRIVATE_PREFIX) or unescaped.short == jid.short: |
124 return unescaped.resource | 124 return unescaped.resource |
125 return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node) | 125 return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node) |
126 | 126 |
127 def printMessage(self, from_jid, msg, profile, timestamp = ''): | 127 def printMessage(self, from_jid, msg, profile, timestamp = ''): |
128 """Print message in chat window. Must be implemented by child class""" | 128 """Print message in chat window. Must be implemented by child class""" |
129 jid=JID(from_jid) | 129 jid=JID(from_jid) |
130 nick = self._get_nick(jid) | 130 nick = self._get_nick(jid) |
131 mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user | 131 mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user |
132 if msg.startswith('/me '): | 132 if msg.startswith('/me '): |
133 self.printInfo('* %s %s' % (nick, msg[4:]),type='me', timestamp=timestamp) | 133 self.printInfo('* %s %s' % (nick, msg[4:]),type='me', timestamp=timestamp) |
134 return | 134 return |
135 return jid, nick, mymess | 135 return jid, nick, mymess |
141 normal: general info like "toto has joined the room" | 141 normal: general info like "toto has joined the room" |
142 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | 142 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" |
143 """ | 143 """ |
144 raise NotImplementedError | 144 raise NotImplementedError |
145 | 145 |
146 | 146 |
147 def startGame(self, game_type, referee, players): | 147 def startGame(self, game_type, referee, players): |
148 """Configure the chat window to start a game""" | 148 """Configure the chat window to start a game""" |
149 #No need to raise an error as game are not mandatory | 149 #No need to raise an error as game are not mandatory |
150 warning(_('startGame is not implemented in this frontend')) | 150 warning(_('startGame is not implemented in this frontend')) |
151 | 151 |
152 def getGame(self, game_type): | 152 def getGame(self, game_type): |
153 """Return class managing the game type""" | 153 """Return class managing the game type""" |
154 #No need to raise an error as game are not mandatory | 154 #No need to raise an error as game are not mandatory |
155 warning(_('getGame is not implemented in this frontend')) | 155 warning(_('getGame is not implemented in this frontend')) |