More chat fixes

This commit is contained in:
Marco Pesenti Gritti 2006-05-05 12:14:46 -04:00
parent 7d77d89df6
commit 4bd94b0019
2 changed files with 20 additions and 11 deletions

View File

@ -10,7 +10,6 @@ pygtk.require('2.0')
import gtk, gobject import gtk, gobject
import sys import sys
import socket
try: try:
import activity import activity
@ -21,7 +20,6 @@ except ImportError:
import BuddyList import BuddyList
import richtext import richtext
import xmlrpclib
import p2p import p2p
class Chat(activity.Activity): class Chat(activity.Activity):
@ -173,23 +171,22 @@ class BuddyChat(Chat):
def _start(self): def _start(self):
group = p2p.Group.get_instance() group = p2p.Group.get_instance()
input_pipe = InputPipe(group, "buddy-chat") self._output_pipe = p2p.OutputPipe(group, self._buddy, "buddy-chat")
input_pipe.listen(self.recv_message)
self._output_pipe = OutputPipe(group, "buddy-chat")
def activity_on_connected_to_shell(self): def activity_on_connected_to_shell(self):
Chat.activity_on_connected_to_shell(self) Chat.activity_on_connected_to_shell(self)
self.activity_set_can_close(True) self.activity_set_can_close(True)
self.activity_set_tab_icon_name("im") self.activity_set_tab_icon_name("im")
self.activity_show_icon(True) self.activity_show_icon(True)
self._start()
def recv_message(self, sender, msg): def recv_message(self, sender, msg):
Chat.recv_message(self, self._buddy, msg) Chat.recv_message(self, self._buddy, msg)
def send_message(self, text): def send_message(self, text):
if len(text) > 0: if len(text) > 0:
self._output_pipe.send(self._buddy, text) success = self._output_pipe.send(text)
self._local_message(success, msg) self._local_message(success, text)
def activity_on_close_from_user(self): def activity_on_close_from_user(self):
Chat.activity_on_close_from_user(self) Chat.activity_on_close_from_user(self)
@ -220,6 +217,9 @@ class GroupChat(Chat):
input_pipe.listen(self.recv_message) input_pipe.listen(self.recv_message)
self._output_pipe = p2p.BroadcastOutputPipe(group, "group-chat") self._output_pipe = p2p.BroadcastOutputPipe(group, "group-chat")
input_pipe = p2p.InputPipe(group, "buddy-chat")
input_pipe.listen(self._buddy_recv_message)
def _create_sidebar(self): def _create_sidebar(self):
vbox = gtk.VBox(False, 6) vbox = gtk.VBox(False, 6)
@ -338,6 +338,14 @@ class GroupChat(Chat):
self._insert_rich_message(buddy.nick(), msg) self._insert_rich_message(buddy.nick(), msg)
self._controller.notify_new_message(self, None) self._controller.notify_new_message(self, None)
def _buddy_recv_message(self, sender, msg):
chat = buddy.chat()
if not chat:
chat = BuddyChat(self._parent, buddy)
buddy.set_chat(chat)
chat.activity_connect_to_shell()
chat.recv_message(message)
def run(self): def run(self):
try: try:
gtk.main() gtk.main()

View File

@ -1,5 +1,7 @@
import os import os
import pwd import pwd
import xmlrpclib
import socket
import presence import presence
import BuddyList import BuddyList
@ -88,12 +90,11 @@ class Group:
def send(self, buddy, pipe_id, msg): def send(self, buddy, pipe_id, msg):
addr = "http://%s:%d" % (buddy.address(), buddy.port()) addr = "http://%s:%d" % (buddy.address(), buddy.port())
peer = xmlrpclib.ServerProxy(addr) peer = xmlrpclib.ServerProxy(addr)
msg = text
success = True success = True
try: try:
peer.message(self._serialize_msg(pipe_id, msg)) peer.message(self._serialize_msg(pipe_id, msg))
except (socket.error, xmlrpclib.Fault), e: except (socket.error, xmlrpclib.Fault), e:
msg = str(e) print str(e)
success = False success = False
return success return success
@ -137,14 +138,14 @@ class OutputPipe(AbstractOutputPipe):
self._buddy = buddy self._buddy = buddy
def send(self, msg): def send(self, msg):
self._group.send(self._buddy, self._pipe_id, msg) return self._group.send(self._buddy, self._pipe_id, msg)
class BroadcastOutputPipe(AbstractOutputPipe): class BroadcastOutputPipe(AbstractOutputPipe):
def __init__(self, group, pipe_id=None): def __init__(self, group, pipe_id=None):
AbstractOutputPipe.__init__(self, group, pipe_id) AbstractOutputPipe.__init__(self, group, pipe_id)
def send(self, msg): def send(self, msg):
self._group.broadcast(self._pipe_id, msg) return self._group.broadcast(self._pipe_id, msg)
class InputPipe(AbstractPipe): class InputPipe(AbstractPipe):
def __init__(self, group, pipe_id=None): def __init__(self, group, pipe_id=None):