comparison frontends/quick_frontend/quick_chat.py @ 190:31632472e857

quick_frontend, wix, primitivus: informations in chat window - user joined/left information - messages starting with /me are managed
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 21:42:30 +0800
parents 80661755ea8d
children 9face609f83c
comparison
equal deleted inserted replaced
189:757518d05833 190:31632472e857
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"))
58 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 58 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
59 len_before = len(self.occupants)
59 self.occupants.add(nick) 60 self.occupants.add(nick)
61 if len_before != len(self.occupants):
62 self.printInfo("=> %s has joined the room" % nick)
60 63
61 def setUserNick(self, nick): 64 def setUserNick(self, nick):
62 """Set the nick of the user, usefull for e.g. change the color of the user""" 65 """Set the nick of the user, usefull for e.g. change the color of the user"""
63 self.nick = nick 66 self.nick = nick
64 67
67 debug(_("Removing user %s") % nick) 70 debug(_("Removing user %s") % nick)
68 if self.type != "group": 71 if self.type != "group":
69 error (_("[INTERNAL] trying to remove user for a non group chat window")) 72 error (_("[INTERNAL] trying to remove user for a non group chat window"))
70 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 73 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
71 self.occupants.remove(nick) 74 self.occupants.remove(nick)
75 self.printInfo("=> %s has left the room" % nick)
72 76
73 def setSubject(self, subject): 77 def setSubject(self, subject):
74 """Set title for a group chat""" 78 """Set title for a group chat"""
75 debug(_("Setting subject to %s") % subject) 79 debug(_("Setting subject to %s") % subject)
76 if self.type != "group": 80 if self.type != "group":
86 for stamp in stamps: 90 for stamp in stamps:
87 self.printMessage(JID(history[stamp][0]), history[stamp][1], profile, stamp) 91 self.printMessage(JID(history[stamp][0]), history[stamp][1], profile, stamp)
88 if keep_last: ##FIXME hack for sortilege 92 if keep_last: ##FIXME hack for sortilege
89 self.last_history = stamps[-1] if stamps else None 93 self.last_history = stamps[-1] if stamps else None
90 94
95 def _get_nick(self, jid):
96 """Return nick of this jid when possible"""
97 return jid.resource if self.type == "group" else (self.host.CM.getAttr(jid,'nick') or self.host.CM.getAttr(jid,'name') or jid.node)
98
91 def printMessage(self, from_jid, msg, profile, timestamp): 99 def printMessage(self, from_jid, msg, profile, timestamp):
92 """Print message in chat window. Must be implemented by child class""" 100 """Print message in chat window. Must be implemented by child class"""
101 jid=JID(from_jid)
102 nick = self._get_nick(jid)
103 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
104 if msg.startswith('/me '):
105 self.printInfo('* %s %s' % (nick, msg[4:]),type='me')
106 return
107 return jid, nick, mymess
108
109 def printInfo(self, msg, type='normal'):
110 """Print general info
111 @param msg: message to print
112 @type: one of:
113 normal: general info like "toto has joined the room"
114 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
115 """
93 raise NotImplementedError 116 raise NotImplementedError
117
94 118
95 def startGame(self, game_type, referee, players): 119 def startGame(self, game_type, referee, players):
96 """Configure the chat window to start a game""" 120 """Configure the chat window to start a game"""
97 #No need to raise an error as game are not mandatory 121 #No need to raise an error as game are not mandatory
98 warning(_('startGame is not implemented in this frontend')) 122 warning(_('startGame is not implemented in this frontend'))