comparison browser_side/panels.py @ 35:d43d6e4b9dc8

room user joining/leaving
author Goffi <goffi@goffi.org>
date Mon, 16 May 2011 18:19:35 +0200
parents ed935f763cc8
children 1d406077b49b
comparison
equal deleted inserted replaced
34:ed935f763cc8 35:d43d6e4b9dc8
421 class Occupant(HTML): 421 class Occupant(HTML):
422 """Occupant of a MUC room""" 422 """Occupant of a MUC room"""
423 423
424 def __init__(self, nick): 424 def __init__(self, nick):
425 self.nick = nick 425 self.nick = nick
426 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) 426 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick))
427
428 def __str__(self):
429 return nick
427 430
428 class OccupantsList(AbsolutePanel): 431 class OccupantsList(AbsolutePanel):
429 """Panel user to show occupants of a room""" 432 """Panel user to show occupants of a room"""
430 433
431 def __init__(self): 434 def __init__(self):
432 AbsolutePanel.__init__(self) 435 AbsolutePanel.__init__(self)
436 self.occupants_list = {}
433 self.setStyleName('occupantsList') 437 self.setStyleName('occupantsList')
434 self.occupants = set()
435 #self.setHeight('100%')
436 438
437 def addOccupant(self, nick): 439 def addOccupant(self, nick):
438 _occupant = Occupant(nick) 440 _occupant = Occupant(nick)
439 print "addOccupant: nick", nick 441 self.occupants_list[nick] = _occupant
440 print _occupant 442 self.add(_occupant)
441 self.occupants.add(_occupant) 443
442 self.add(_occupant) 444 def removeOccupant(self, nick):
443 445 try:
444 class ChatPanel(DropCell, ClickHandler, SimplePanel): 446 self.remove(self.occupants_list[nick])
447 except KeyError:
448 print "ERROR: trying to remove an unexisting nick"
449
450 def clear(self):
451 self.occupants_list.clear()
452 AbsolutePanel.clear(self)
453
454 class ChatPanel(DropCell, ClickHandler, ScrollPanelWrapper):
445 455
446 def __init__(self, host, target, type='one2one'): 456 def __init__(self, host, target, type='one2one'):
447 """Panel used for conversation (one 2 one or group chat) 457 """Panel used for conversation (one 2 one or group chat)
448 @param host: SatWebFrontend instance 458 @param host: SatWebFrontend instance
449 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) 459 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room)
450 @param type: one2one for simple conversation, group for MUC""" 460 @param type: one2one for simple conversation, group for MUC"""
451 SimplePanel.__init__(self) 461 ScrollPanelWrapper.__init__(self)
452 DropCell.__init__(self) 462 DropCell.__init__(self)
453 ClickHandler.__init__(self) 463 ClickHandler.__init__(self)
454 self.vpanel = VerticalPanel() 464 self.vpanel = VerticalPanel()
455 self.vpanel.setSize('100%','100%') 465 self.vpanel.setSize('100%','100%')
456 self.host = host 466 self.host = host
493 self.nick = nick 503 self.nick = nick
494 504
495 def setPresents(self, nicks): 505 def setPresents(self, nicks):
496 """Set the users presents in this room 506 """Set the users presents in this room
497 @param occupants: list of nicks (string)""" 507 @param occupants: list of nicks (string)"""
508 self.occupants_list.clear()
498 for nick in nicks: 509 for nick in nicks:
499 self.occupants_list.addOccupant(nick) 510 self.occupants_list.addOccupant(nick)
511
512 def userJoined(self, nick, data):
513 print "userJoined:", nick, data
514 self.occupants_list.addOccupant(nick)
515 self.printInfo("=> %s has joined the room" % nick)
516
517 def userLeft(self, nick, data):
518 print "userLeft:", nick, data
519 self.occupants_list.removeOccupant(nick)
520 self.printInfo("<= %s has left the room" % nick)
500 521
501 def historyPrint(self, size=20): 522 def historyPrint(self, size=20):
502 """Print the initial history""" 523 """Print the initial history"""
503 def getHistoryCB(history): 524 def getHistoryCB(history):
504 stamps=history.keys() 525 stamps=history.keys()
505 stamps.sort() 526 stamps.sort()
506 for stamp in stamps: 527 for stamp in stamps:
507 self.printMessage(history[stamp][0], history[stamp][1], stamp) 528 self.printMessage(history[stamp][0], history[stamp][1], stamp)
508 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, str(self.target), 20) 529 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, str(self.target), 20)
509 530
531 def printInfo(self, msg, type='normal'):
532 """Print general info
533 @param msg: message to print
534 @type: one of:
535 normal: general info like "toto has joined the room"
536 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
537 """
538 _wid = Label(msg)
539 if type == 'normal':
540 _wid.setStyleName('chatTextInfo')
541 elif type == 'me':
542 _wid.setStyleName('chatTextMe')
543 else:
544 _wid.setStyleName('chatTextInfo')
545 self.content.add(_wid)
546
547
510 def printMessage(self, from_jid, msg, timestamp=None): 548 def printMessage(self, from_jid, msg, timestamp=None):
511 """Print message in chat window. Must be implemented by child class""" 549 """Print message in chat window. Must be implemented by child class"""
512 _jid=JID(from_jid) 550 _jid=JID(from_jid)
513 nick = _jid.node if self.type=='one2one' else _jid.resource 551 nick = _jid.node if self.type=='one2one' else _jid.resource
514 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user 552 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user
515 """if msg.startswith('/me '): 553 if msg.startswith('/me '):
516 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') 554 self.printInfo('* %s %s' % (nick, msg[4:]),type='me')
517 return""" 555 return
518 self.content.add(ChatText(timestamp, nick, mymess, msg)) 556 self.content.add(ChatText(timestamp, nick, mymess, msg))
519 self.content_scroll.scrollToBottom() 557 self.content_scroll.scrollToBottom()
520 558
521 class MainDiscussionPanel(HorizontalPanel): 559 class MainDiscussionPanel(HorizontalPanel):
522 560