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 sys
import socket
try:
import activity
@ -21,7 +20,6 @@ except ImportError:
import BuddyList
import richtext
import xmlrpclib
import p2p
class Chat(activity.Activity):
@ -173,23 +171,22 @@ class BuddyChat(Chat):
def _start(self):
group = p2p.Group.get_instance()
input_pipe = InputPipe(group, "buddy-chat")
input_pipe.listen(self.recv_message)
self._output_pipe = OutputPipe(group, "buddy-chat")
self._output_pipe = p2p.OutputPipe(group, self._buddy, "buddy-chat")
def activity_on_connected_to_shell(self):
Chat.activity_on_connected_to_shell(self)
self.activity_set_can_close(True)
self.activity_set_tab_icon_name("im")
self.activity_show_icon(True)
self._start()
def recv_message(self, sender, msg):
Chat.recv_message(self, self._buddy, msg)
def send_message(self, text):
if len(text) > 0:
self._output_pipe.send(self._buddy, text)
self._local_message(success, msg)
success = self._output_pipe.send(text)
self._local_message(success, text)
def 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)
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):
vbox = gtk.VBox(False, 6)
@ -338,6 +338,14 @@ class GroupChat(Chat):
self._insert_rich_message(buddy.nick(), msg)
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):
try:
gtk.main()

View File

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