Get chat back to work. Well except it get very confused

if users have the same ip address.

Dan I commented out the service deserialization in BrowserShell
because it was not really working (also there was a few typos in
that code)
This commit is contained in:
Marco Pesenti Gritti 2006-06-18 03:00:23 -04:00
parent bc43e25e10
commit 51ea9eedba
6 changed files with 31 additions and 24 deletions

View File

@ -37,15 +37,15 @@ class BrowserShell(dbus.service.Object):
@dbus.service.method('com.redhat.Sugar.BrowserShell')
def open_browser(self, uri, serialized_service=None):
service = None
if serialized_service is not None:
serivce = Service.deserialize(serialized_service)
# if serialized_service is not None:
# service = Service.deserialize(serialized_service)
browser = BrowserActivity(uri)
self.__browsers.append(browser)
gobject.idle_add(self._start_browser_cb, browser, service)
@dbus.service.method('com.redhat.Sugar.BrowserShell')
def open_browser_from_service_foobar(self, uri, serialized_service):
serivce = Service.deserialize(serialized_service)
service = Service.deserialize(serialized_service)
browser = BrowserActivity(uri)
self.__browsers.append(browser)
gobject.idle_add(self._start_browser_cb, browser, service)

View File

@ -13,6 +13,7 @@ import gtk, gobject, pango
from sugar.chat.Emoticons import Emoticons
from sugar.chat.ChatToolbar import ChatToolbar
from sugar.chat.ChatEditor import ChatEditor
from sugar.presence.PresenceService import PresenceService
import richtext
PANGO_SCALE = 1024 # Where is this defined?
@ -47,7 +48,7 @@ class Chat(gtk.VBox):
self.pack_start(chat_vbox)
chat_vbox.show()
self._editor = ChatEditor()
self._editor = ChatEditor(self)
toolbar = ChatToolbar(self._editor.get_buffer())
self.pack_start(toolbar, False)
@ -73,17 +74,14 @@ class Chat(gtk.VBox):
def _message_inserted(self):
gobject.idle_add(self._scroll_chat_view_to_bottom)
self.set_has_changes(True)
def _insert_buddy(self, buf, nick):
def _insert_buddy(self, buf, buddy):
# Stuff in the buddy icon, if we have one for this buddy
buddy = self._controller.get_group().get_buddy(nick)
icon = buddy.get_icon_pixbuf()
if icon:
rise = int(icon.get_height() / 4) * -1
chat_service = buddy.get_service(Chat.SERVICE_TYPE)
hash_string = "%s-%s" % (nick, chat_service.get_address())
hash_string = "%s-%s" % (buddy.get_nick_name(), buddy.get_address())
sha_hash = sha.new()
sha_hash.update(hash_string)
tagname = "buddyicon-%s" % sha_hash.hexdigest()
@ -102,15 +100,15 @@ class Chat(gtk.VBox):
buf.create_tag("nickname", weight=pango.WEIGHT_BOLD)
aniter = buf.get_end_iter()
offset = aniter.get_offset()
buf.insert(aniter, " " + nick + ": ")
buf.insert(aniter, " " + buddy.get_nick_name() + ": ")
enditer = buf.get_iter_at_offset(offset)
buf.apply_tag_by_name("nickname", aniter, enditer)
def _insert_rich_message(self, nick, msg):
def _insert_rich_message(self, buddy, msg):
msg = Emoticons.get_instance().replace(msg)
buf = self._chat_view.get_buffer()
self._insert_buddy(buf, nick)
self._insert_buddy(buf, buddy)
serializer = richtext.RichTextSerializer()
serializer.deserialize(msg, buf)
@ -188,19 +186,19 @@ class Chat(gtk.VBox):
chunk = self._get_first_richtext_chunk(msg)
if chunk:
self._insert_rich_message(buddy.get_nick_name(), chunk)
self._insert_rich_message(buddy, chunk)
return
chunk = self._get_first_sketch_chunk(msg)
if chunk:
self._insert_sketch(buddy.get_nick_name(), chunk)
self._insert_sketch(buddy, chunk)
return
def send_sketch(self, svgdata):
if not svgdata or not len(svgdata):
return
self._stream_writer.write(svgdata)
owner = self._controller.get_group().get_owner()
owner = PresenceService.get_instance().get_owner()
self._insert_sketch(owner.get_nick_name(), svgdata)
def send_text_message(self, text):
@ -208,5 +206,5 @@ class Chat(gtk.VBox):
if len(text) <= 0:
return
self._stream_writer.write(text)
owner = self._controller.get_group().get_owner()
self._insert_rich_message(owner.get_nick_name(), text)
owner = PresenceService.get_instance().get_owner()
self._insert_rich_message(owner, text)

View File

@ -6,9 +6,11 @@ from sugar.chat.sketchpad.SketchPad import SketchPad
import richtext
class ChatEditor(gtk.Notebook):
def __init__(self):
def __init__(self, chat):
gtk.Notebook.__init__(self)
self._chat = chat
self.set_show_tabs(False)
self.set_show_border(False)
self.set_size_request(-1, 70)
@ -40,7 +42,7 @@ class ChatEditor(gtk.Notebook):
if len(text.strip()) > 0:
serializer = richtext.RichTextSerializer()
text = serializer.serialize(buf)
self.send_text_message(text)
self._chat.send_text_message(text)
buf.set_text("")
buf.place_cursor(buf.get_start_iter())

View File

@ -37,5 +37,10 @@ class GroupChat(Chat):
self._group_stream.set_data_listener(self._group_recv_message)
self._stream_writer = self._group_stream.new_writer()
def _group_recv_message(self, buddy, msg):
self.recv_message(buddy, msg)
def _group_recv_message(self, address, msg):
pservice = PresenceService.get_instance()
buddy = pservice.get_buddy_by_address(address)
if buddy:
self.recv_message(buddy, msg)
else:
logging.error('Cannot map %s to a buddy.' % (address))

View File

@ -2,6 +2,7 @@ import xmlrpclib
import socket
import traceback
import random
import logging
import network
from MostlyReliablePipe import MostlyReliablePipe
@ -33,7 +34,7 @@ class Stream(object):
def _recv(self, address, data):
if self._callback:
self._callback(data)
self._callback(address, data)
class UnicastStreamWriter(object):
@ -133,6 +134,7 @@ class MulticastStream(Stream):
return self._reader_port
def _internal_start_reader(self):
logging.debug('Start multicast stream, address %s, port %d' % (self._address, self._reader_port))
if not self._service.get_address():
raise ValueError("service must have a valid address.")
self._pipe = MostlyReliablePipe('', self._address, self._reader_port,
@ -143,7 +145,7 @@ class MulticastStream(Stream):
self._pipe.send(data)
def _recv_data_cb(self, address, data, user_data=None):
self._recv(address, data)
self._recv(address[0], data)
def new_writer(self, service=None):
return self

View File

@ -575,7 +575,7 @@ class PresenceService(gobject.GObject):
def get_buddy_by_address(self, address):
for buddy in self._buddies.values():
if buddy.get_address == address:
if buddy.get_address() == address:
return buddy
return None