From b4d4d9eb21adb3bf8a391fdd84e8148ccf8c6fad Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 19 May 2006 18:05:59 -0400 Subject: [PATCH] Merge --- sugar/browser/browser.py | 2 +- sugar/chat/chat.py | 22 ++++++++++++++-------- sugar/chat/richtext.py | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/sugar/browser/browser.py b/sugar/browser/browser.py index b0a55bfc..cec6e096 100755 --- a/sugar/browser/browser.py +++ b/sugar/browser/browser.py @@ -251,7 +251,7 @@ class BrowserActivity(activity.Activity): escaped_title = saxutils.escape(self.embed.get_title()) escaped_address = saxutils.escape(address) - chat_shell.send_message('' + escaped_title + '') def __title_cb(self, embed): diff --git a/sugar/chat/chat.py b/sugar/chat/chat.py index 04b8401d..9fab3af9 100755 --- a/sugar/chat/chat.py +++ b/sugar/chat/chat.py @@ -140,7 +140,7 @@ class Chat(activity.Activity): serializer = richtext.RichTextSerializer() text = serializer.serialize(buf) - self.send_message(text) + self.send_text_message(text) buf.set_text("") buf.place_cursor(buf.get_start_iter()) @@ -186,9 +186,6 @@ class Chat(activity.Activity): print "act %d: in activity_on_got_focus" % self.activity_get_id() # FIXME self._controller.notify_activate(self) - def recv_message(self, buddy, msg): - self._insert_rich_message(buddy.get_nick_name(), msg) - def _insert_rich_message(self, nick, msg): buf = self._chat_view.get_buffer() aniter = buf.get_end_iter() @@ -200,7 +197,16 @@ class Chat(activity.Activity): aniter = buf.get_end_iter() buf.insert(aniter, "\n") - def send_message(self, text): + def _insert_sketch(self, sketch): + """Insert a sketch object into the chat buffer.""" + pass + + def recv_message(self, buddy, msg): + """Insert a remote chat message into the chat buffer.""" + self._insert_rich_message(buddy.get_nick_name(), msg) + + def send_text_message(self, text): + """Send a chat message and insert it into the local buffer.""" if len(text) <= 0: return self._stream_writer.write(text) @@ -402,7 +408,7 @@ class GroupChat(Chat): self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_active_chat) def _group_recv_message(self, buddy, msg): - Chat.recv_message(self, buddy, msg) + self.recv_message(buddy, msg) self._controller.notify_new_message(self, None) def _buddy_recv_message(self, buddy, msg): @@ -436,8 +442,8 @@ class ChatShell(dbus.service.Object): self._group_chat.activity_connect_to_shell() @dbus.service.method('com.redhat.Sugar.ChatShell') - def send_message(self, message): - self._group_chat.send_message(message) + def send_text_message(self, message): + self._group_chat.send_text_message(message) if len(sys.argv) > 1 and sys.argv[1] == "--console": sys.stdout = LogWriter("Chat") diff --git a/sugar/chat/richtext.py b/sugar/chat/richtext.py index ecb15c2e..543e431e 100644 --- a/sugar/chat/richtext.py +++ b/sugar/chat/richtext.py @@ -209,8 +209,16 @@ class RichTextHandler(xml.sax.handler.ContentHandler): self.buf = buf self.serializer = serializer self.tags = [] + self._in_richtext = False + self._done = False def startElement(self, name, attrs): + # Look for, and only start parsing after 'richtext' + if not self._in_richtext and name == "richtext": + self._in_richtext = True + if not self._in_richtext: + return + if name != "richtext": tag = self.serializer.deserialize_element(name, attrs) self.tags.append(tag) @@ -230,8 +238,12 @@ class RichTextHandler(xml.sax.handler.ContentHandler): "link", "link-address") def endElement(self, name): - if name != "richtext": - self.tags.pop() + if not self._done and self._in_richtext: + if name != "richtext": + self.tags.pop() + if name == "richtext": + self._done = True + self._in_richtext = False class RichTextSerializer: def __init__(self):