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') @dbus.service.method('com.redhat.Sugar.BrowserShell')
def open_browser(self, uri, serialized_service=None): def open_browser(self, uri, serialized_service=None):
service = None service = None
if serialized_service is not None: # if serialized_service is not None:
serivce = Service.deserialize(serialized_service) # service = Service.deserialize(serialized_service)
browser = BrowserActivity(uri) browser = BrowserActivity(uri)
self.__browsers.append(browser) self.__browsers.append(browser)
gobject.idle_add(self._start_browser_cb, browser, service) gobject.idle_add(self._start_browser_cb, browser, service)
@dbus.service.method('com.redhat.Sugar.BrowserShell') @dbus.service.method('com.redhat.Sugar.BrowserShell')
def open_browser_from_service_foobar(self, uri, serialized_service): def open_browser_from_service_foobar(self, uri, serialized_service):
serivce = Service.deserialize(serialized_service) service = Service.deserialize(serialized_service)
browser = BrowserActivity(uri) browser = BrowserActivity(uri)
self.__browsers.append(browser) self.__browsers.append(browser)
gobject.idle_add(self._start_browser_cb, browser, service) 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.Emoticons import Emoticons
from sugar.chat.ChatToolbar import ChatToolbar from sugar.chat.ChatToolbar import ChatToolbar
from sugar.chat.ChatEditor import ChatEditor from sugar.chat.ChatEditor import ChatEditor
from sugar.presence.PresenceService import PresenceService
import richtext import richtext
PANGO_SCALE = 1024 # Where is this defined? PANGO_SCALE = 1024 # Where is this defined?
@ -47,7 +48,7 @@ class Chat(gtk.VBox):
self.pack_start(chat_vbox) self.pack_start(chat_vbox)
chat_vbox.show() chat_vbox.show()
self._editor = ChatEditor() self._editor = ChatEditor(self)
toolbar = ChatToolbar(self._editor.get_buffer()) toolbar = ChatToolbar(self._editor.get_buffer())
self.pack_start(toolbar, False) self.pack_start(toolbar, False)
@ -73,17 +74,14 @@ class Chat(gtk.VBox):
def _message_inserted(self): def _message_inserted(self):
gobject.idle_add(self._scroll_chat_view_to_bottom) 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 # 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() icon = buddy.get_icon_pixbuf()
if icon: if icon:
rise = int(icon.get_height() / 4) * -1 rise = int(icon.get_height() / 4) * -1
chat_service = buddy.get_service(Chat.SERVICE_TYPE) hash_string = "%s-%s" % (buddy.get_nick_name(), buddy.get_address())
hash_string = "%s-%s" % (nick, chat_service.get_address())
sha_hash = sha.new() sha_hash = sha.new()
sha_hash.update(hash_string) sha_hash.update(hash_string)
tagname = "buddyicon-%s" % sha_hash.hexdigest() tagname = "buddyicon-%s" % sha_hash.hexdigest()
@ -102,15 +100,15 @@ class Chat(gtk.VBox):
buf.create_tag("nickname", weight=pango.WEIGHT_BOLD) buf.create_tag("nickname", weight=pango.WEIGHT_BOLD)
aniter = buf.get_end_iter() aniter = buf.get_end_iter()
offset = aniter.get_offset() offset = aniter.get_offset()
buf.insert(aniter, " " + nick + ": ") buf.insert(aniter, " " + buddy.get_nick_name() + ": ")
enditer = buf.get_iter_at_offset(offset) enditer = buf.get_iter_at_offset(offset)
buf.apply_tag_by_name("nickname", aniter, enditer) 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) msg = Emoticons.get_instance().replace(msg)
buf = self._chat_view.get_buffer() buf = self._chat_view.get_buffer()
self._insert_buddy(buf, nick) self._insert_buddy(buf, buddy)
serializer = richtext.RichTextSerializer() serializer = richtext.RichTextSerializer()
serializer.deserialize(msg, buf) serializer.deserialize(msg, buf)
@ -188,19 +186,19 @@ class Chat(gtk.VBox):
chunk = self._get_first_richtext_chunk(msg) chunk = self._get_first_richtext_chunk(msg)
if chunk: if chunk:
self._insert_rich_message(buddy.get_nick_name(), chunk) self._insert_rich_message(buddy, chunk)
return return
chunk = self._get_first_sketch_chunk(msg) chunk = self._get_first_sketch_chunk(msg)
if chunk: if chunk:
self._insert_sketch(buddy.get_nick_name(), chunk) self._insert_sketch(buddy, chunk)
return return
def send_sketch(self, svgdata): def send_sketch(self, svgdata):
if not svgdata or not len(svgdata): if not svgdata or not len(svgdata):
return return
self._stream_writer.write(svgdata) 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) self._insert_sketch(owner.get_nick_name(), svgdata)
def send_text_message(self, text): def send_text_message(self, text):
@ -208,5 +206,5 @@ class Chat(gtk.VBox):
if len(text) <= 0: if len(text) <= 0:
return return
self._stream_writer.write(text) self._stream_writer.write(text)
owner = self._controller.get_group().get_owner() owner = PresenceService.get_instance().get_owner()
self._insert_rich_message(owner.get_nick_name(), text) self._insert_rich_message(owner, text)

View File

@ -6,8 +6,10 @@ from sugar.chat.sketchpad.SketchPad import SketchPad
import richtext import richtext
class ChatEditor(gtk.Notebook): class ChatEditor(gtk.Notebook):
def __init__(self): def __init__(self, chat):
gtk.Notebook.__init__(self) gtk.Notebook.__init__(self)
self._chat = chat
self.set_show_tabs(False) self.set_show_tabs(False)
self.set_show_border(False) self.set_show_border(False)
@ -40,7 +42,7 @@ class ChatEditor(gtk.Notebook):
if len(text.strip()) > 0: if len(text.strip()) > 0:
serializer = richtext.RichTextSerializer() serializer = richtext.RichTextSerializer()
text = serializer.serialize(buf) text = serializer.serialize(buf)
self.send_text_message(text) self._chat.send_text_message(text)
buf.set_text("") buf.set_text("")
buf.place_cursor(buf.get_start_iter()) 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._group_stream.set_data_listener(self._group_recv_message)
self._stream_writer = self._group_stream.new_writer() self._stream_writer = self._group_stream.new_writer()
def _group_recv_message(self, buddy, msg): def _group_recv_message(self, address, msg):
self.recv_message(buddy, 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 socket
import traceback import traceback
import random import random
import logging
import network import network
from MostlyReliablePipe import MostlyReliablePipe from MostlyReliablePipe import MostlyReliablePipe
@ -33,7 +34,7 @@ class Stream(object):
def _recv(self, address, data): def _recv(self, address, data):
if self._callback: if self._callback:
self._callback(data) self._callback(address, data)
class UnicastStreamWriter(object): class UnicastStreamWriter(object):
@ -133,6 +134,7 @@ class MulticastStream(Stream):
return self._reader_port return self._reader_port
def _internal_start_reader(self): 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(): if not self._service.get_address():
raise ValueError("service must have a valid address.") raise ValueError("service must have a valid address.")
self._pipe = MostlyReliablePipe('', self._address, self._reader_port, self._pipe = MostlyReliablePipe('', self._address, self._reader_port,
@ -143,7 +145,7 @@ class MulticastStream(Stream):
self._pipe.send(data) self._pipe.send(data)
def _recv_data_cb(self, address, data, user_data=None): 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): def new_writer(self, service=None):
return self return self

View File

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