|
|
|
@ -12,7 +12,6 @@ import gtk, gobject
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import pwd
|
|
|
|
|
import gc
|
|
|
|
|
import socket
|
|
|
|
|
|
|
|
|
|
import activity
|
|
|
|
@ -25,47 +24,153 @@ import xmlrpclib
|
|
|
|
|
|
|
|
|
|
from sugar_globals import *
|
|
|
|
|
|
|
|
|
|
class Chat(object):
|
|
|
|
|
def __init__(self, parent, view, label):
|
|
|
|
|
self._parent = parent
|
|
|
|
|
self._buffer = richtext.RichTextBuffer()
|
|
|
|
|
self._view = view
|
|
|
|
|
self._label = label
|
|
|
|
|
|
|
|
|
|
def activate(self, label):
|
|
|
|
|
self._view.set_buffer(self._buffer)
|
|
|
|
|
self._label.set_text(label)
|
|
|
|
|
class Chat(activity.Activity):
|
|
|
|
|
def __init__(self, controller):
|
|
|
|
|
self._controller = controller
|
|
|
|
|
activity.Activity.__init__(self)
|
|
|
|
|
|
|
|
|
|
def activity_on_connected_to_shell(self):
|
|
|
|
|
self.activity_set_tab_text(self._act_name)
|
|
|
|
|
self._plug = self.activity_get_gtk_plug()
|
|
|
|
|
self._ui_setup(self._plug)
|
|
|
|
|
self._plug.show_all()
|
|
|
|
|
|
|
|
|
|
def _create_chat(self):
|
|
|
|
|
chat_vbox = gtk.VBox()
|
|
|
|
|
chat_vbox.set_spacing(6)
|
|
|
|
|
|
|
|
|
|
sw = gtk.ScrolledWindow()
|
|
|
|
|
sw.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
|
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
|
|
|
|
|
self._chat_view = richtext.RichTextView()
|
|
|
|
|
self._chat_view.connect("link-clicked", self.__link_clicked_cb)
|
|
|
|
|
self._chat_view.set_editable(False)
|
|
|
|
|
sw.add(self._chat_view)
|
|
|
|
|
self._chat_view.show()
|
|
|
|
|
chat_vbox.pack_start(sw)
|
|
|
|
|
sw.show()
|
|
|
|
|
|
|
|
|
|
rich_buf = richtext.RichTextBuffer()
|
|
|
|
|
chat_view_sw = gtk.ScrolledWindow()
|
|
|
|
|
chat_view_sw.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
|
chat_view_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
|
self._editor = richtext.RichTextView(rich_buf)
|
|
|
|
|
self._editor.connect("key-press-event", self.__key_press_event_cb)
|
|
|
|
|
self._editor.set_size_request(-1, 50)
|
|
|
|
|
chat_view_sw.add(self._editor)
|
|
|
|
|
self._editor.show()
|
|
|
|
|
|
|
|
|
|
chat_vbox.pack_start(chat_view_sw, False)
|
|
|
|
|
chat_view_sw.show()
|
|
|
|
|
|
|
|
|
|
return chat_vbox, rich_buf
|
|
|
|
|
|
|
|
|
|
def _ui_setup(self, base):
|
|
|
|
|
vbox = gtk.VBox(False, 6)
|
|
|
|
|
|
|
|
|
|
self._hbox = gtk.HBox(False, 12)
|
|
|
|
|
self._hbox.set_border_width(12)
|
|
|
|
|
|
|
|
|
|
[chat_vbox, buffer] = self._create_chat()
|
|
|
|
|
self._hbox.pack_start(chat_vbox)
|
|
|
|
|
chat_vbox.show()
|
|
|
|
|
|
|
|
|
|
vbox.pack_start(self._hbox)
|
|
|
|
|
self._hbox.show()
|
|
|
|
|
|
|
|
|
|
toolbar = self._create_toolbar(buffer)
|
|
|
|
|
vbox.pack_start(toolbar, False)
|
|
|
|
|
toolbar.show()
|
|
|
|
|
|
|
|
|
|
base.add(vbox)
|
|
|
|
|
vbox.show()
|
|
|
|
|
|
|
|
|
|
def __link_clicked_cb(self, view, address):
|
|
|
|
|
self._browser_shell.open_browser(address)
|
|
|
|
|
|
|
|
|
|
def __key_press_event_cb(self, text_view, event):
|
|
|
|
|
if event.keyval == gtk.keysyms.Return:
|
|
|
|
|
buf = text_view.get_buffer()
|
|
|
|
|
|
|
|
|
|
serializer = richtext.RichTextSerializer()
|
|
|
|
|
text = serializer.serialize(buf)
|
|
|
|
|
self.send_message(text)
|
|
|
|
|
|
|
|
|
|
buf.set_text("")
|
|
|
|
|
buf.place_cursor(buf.get_start_iter())
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def _create_toolbar(self, rich_buf):
|
|
|
|
|
toolbar = richtext.RichTextToolbar(rich_buf)
|
|
|
|
|
|
|
|
|
|
item = gtk.MenuToolButton(None, "Links")
|
|
|
|
|
item.set_menu(gtk.Menu())
|
|
|
|
|
item.connect("show-menu", self.__show_link_menu_cb)
|
|
|
|
|
toolbar.insert(item, -1)
|
|
|
|
|
item.show()
|
|
|
|
|
|
|
|
|
|
return toolbar
|
|
|
|
|
|
|
|
|
|
def __link_activate_cb(self, item, link):
|
|
|
|
|
buf = self._editor.get_buffer()
|
|
|
|
|
buf.append_link(link['title'], link['address'])
|
|
|
|
|
|
|
|
|
|
def __show_link_menu_cb(self, button):
|
|
|
|
|
menu = gtk.Menu()
|
|
|
|
|
|
|
|
|
|
links = self._browser_shell.get_links()
|
|
|
|
|
|
|
|
|
|
for link in links:
|
|
|
|
|
item = gtk.MenuItem(link['title'], False)
|
|
|
|
|
item.connect("activate", self.__link_activate_cb, link)
|
|
|
|
|
menu.append(item)
|
|
|
|
|
item.show()
|
|
|
|
|
|
|
|
|
|
button.set_menu(menu)
|
|
|
|
|
|
|
|
|
|
def activity_on_close_from_user(self):
|
|
|
|
|
print "act %d: in activity_on_close_from_user"%self.activity_get_id()
|
|
|
|
|
self.activity_shutdown()
|
|
|
|
|
|
|
|
|
|
def activity_on_lost_focus(self):
|
|
|
|
|
print "act %d: in activity_on_lost_focus"%self.activity_get_id()
|
|
|
|
|
|
|
|
|
|
def activity_on_got_focus(self):
|
|
|
|
|
print "act %d: in activity_on_got_focus"%self.activity_get_id()
|
|
|
|
|
self._controller.notify_activate(self)
|
|
|
|
|
|
|
|
|
|
def recv_message(self, buddy, msg):
|
|
|
|
|
self._insert_rich_message(buddy.nick(), msg)
|
|
|
|
|
self._parent.notify_new_message(self, buddy)
|
|
|
|
|
self._controller.notify_new_message(self, buddy)
|
|
|
|
|
|
|
|
|
|
def _insert_rich_message(self, nick, msg):
|
|
|
|
|
aniter = self._buffer.get_end_iter()
|
|
|
|
|
self._buffer.insert(aniter, nick + ": ")
|
|
|
|
|
buffer = self._chat_view.get_buffer()
|
|
|
|
|
aniter = buffer.get_end_iter()
|
|
|
|
|
buffer.insert(aniter, nick + ": ")
|
|
|
|
|
|
|
|
|
|
serializer = richtext.RichTextSerializer()
|
|
|
|
|
serializer.deserialize(msg, self._buffer)
|
|
|
|
|
serializer.deserialize(msg, buffer)
|
|
|
|
|
|
|
|
|
|
aniter = self._buffer.get_end_iter()
|
|
|
|
|
self._buffer.insert(aniter, "\n")
|
|
|
|
|
aniter = buffer.get_end_iter()
|
|
|
|
|
buffer.insert(aniter, "\n")
|
|
|
|
|
|
|
|
|
|
def _local_message(self, success, text):
|
|
|
|
|
if not success:
|
|
|
|
|
message = "Error: %s\n" % text
|
|
|
|
|
aniter = self._buffer.get_end_iter()
|
|
|
|
|
self._buffer.insert(aniter, message)
|
|
|
|
|
buffer = self._chat_view.get_buffer()
|
|
|
|
|
aniter = buffer.get_end_iter()
|
|
|
|
|
buffer.insert(aniter, message)
|
|
|
|
|
else:
|
|
|
|
|
(nick, realname) = self._parent.local_name()
|
|
|
|
|
(nick, realname) = self._controller.local_name()
|
|
|
|
|
self._insert_rich_message(nick, text)
|
|
|
|
|
|
|
|
|
|
class BuddyChat(Chat):
|
|
|
|
|
def __init__(self, parent, buddy, view, label):
|
|
|
|
|
def __init__(self, controller, buddy):
|
|
|
|
|
self._buddy = buddy
|
|
|
|
|
Chat.__init__(self, parent, view, label)
|
|
|
|
|
|
|
|
|
|
def activate(self):
|
|
|
|
|
Chat.activate(self, self._buddy.nick())
|
|
|
|
|
self._act_name = "Chat: %s" % buddy.nick()
|
|
|
|
|
Chat.__init__(self, controller)
|
|
|
|
|
|
|
|
|
|
def recv_message(self, msg):
|
|
|
|
|
Chat.recv_message(self, self._buddy, msg)
|
|
|
|
@ -84,35 +189,9 @@ class BuddyChat(Chat):
|
|
|
|
|
success = False
|
|
|
|
|
self._local_message(success, msg)
|
|
|
|
|
|
|
|
|
|
class GroupChat(Chat):
|
|
|
|
|
def __init__(self, parent, view, label):
|
|
|
|
|
Chat.__init__(self, parent, view, label)
|
|
|
|
|
self._gc_controller = network.GroupChatController('224.0.0.221', 6666, self._recv_group_message)
|
|
|
|
|
self._gc_controller.start()
|
|
|
|
|
|
|
|
|
|
def activate(self):
|
|
|
|
|
Chat.activate(self, "Group Chat")
|
|
|
|
|
|
|
|
|
|
def send_message(self, text):
|
|
|
|
|
if len(text) > 0:
|
|
|
|
|
self._gc_controller.send_msg(text)
|
|
|
|
|
self._local_message(True, text)
|
|
|
|
|
|
|
|
|
|
def recv_message(self, buddy, msg):
|
|
|
|
|
self._insert_rich_message(buddy.nick(), msg)
|
|
|
|
|
self._parent.notify_new_message(self, None)
|
|
|
|
|
|
|
|
|
|
def _recv_group_message(self, msg):
|
|
|
|
|
buddy = self._parent.find_buddy_by_address(msg['addr'])
|
|
|
|
|
if buddy:
|
|
|
|
|
self.recv_message(buddy, msg['data'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatRequestHandler(object):
|
|
|
|
|
def __init__(self, parent, chat_view, chat_label):
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
|
self._parent = parent
|
|
|
|
|
self._chat_view = chat_view
|
|
|
|
|
self._chat_label = chat_label
|
|
|
|
|
|
|
|
|
|
def message(self, message):
|
|
|
|
|
client_address = network.get_authinfo()
|
|
|
|
@ -120,21 +199,22 @@ class ChatRequestHandler(object):
|
|
|
|
|
if buddy:
|
|
|
|
|
chat = buddy.chat()
|
|
|
|
|
if not chat:
|
|
|
|
|
chat = BuddyChat(self._parent, buddy, self._chat_view, self._chat_label)
|
|
|
|
|
chat = BuddyChat(self._parent, buddy)
|
|
|
|
|
buddy.set_chat(chat)
|
|
|
|
|
chat.activity_connect_to_shell()
|
|
|
|
|
chat.recv_message(message)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
class ChatActivity(activity.Activity):
|
|
|
|
|
class GroupChat(Chat):
|
|
|
|
|
|
|
|
|
|
_MODEL_COL_NICK = 0
|
|
|
|
|
_MODEL_COL_ICON = 1
|
|
|
|
|
_MODEL_COL_BUDDY = 2
|
|
|
|
|
|
|
|
|
|
_CHAT_SERVER_PORT = 6666
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
activity.Activity.__init__(self)
|
|
|
|
|
self._act_name = "Chat"
|
|
|
|
|
self._active_chat_buddy = None
|
|
|
|
|
self._pannounce = presence.PresenceAnnounce()
|
|
|
|
|
|
|
|
|
|
(self._nick, self._realname) = self._get_name()
|
|
|
|
@ -144,44 +224,9 @@ class ChatActivity(activity.Activity):
|
|
|
|
|
|
|
|
|
|
bus = dbus.SessionBus()
|
|
|
|
|
proxy_obj = bus.get_object('com.redhat.Sugar.Browser', '/com/redhat/Sugar/Browser')
|
|
|
|
|
self.browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
|
|
|
|
|
|
|
|
|
|
def __link_clicked_cb(self, view, address):
|
|
|
|
|
self.browser_shell.open_browser(address)
|
|
|
|
|
self._browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
|
|
|
|
|
|
|
|
|
|
def _create_chat(self):
|
|
|
|
|
chat_vbox = gtk.VBox()
|
|
|
|
|
chat_vbox.set_spacing(6)
|
|
|
|
|
|
|
|
|
|
self._chat_label = gtk.Label()
|
|
|
|
|
chat_vbox.pack_start(self._chat_label, False)
|
|
|
|
|
# Do we actually need this label?
|
|
|
|
|
# self._chat_label.show()
|
|
|
|
|
|
|
|
|
|
sw = gtk.ScrolledWindow()
|
|
|
|
|
sw.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
|
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
|
|
|
|
|
self._chat_view = richtext.RichTextView()
|
|
|
|
|
self._chat_view.connect("link-clicked", self.__link_clicked_cb)
|
|
|
|
|
sw.add(self._chat_view)
|
|
|
|
|
self._chat_view.show()
|
|
|
|
|
chat_vbox.pack_start(sw)
|
|
|
|
|
sw.show()
|
|
|
|
|
|
|
|
|
|
rich_buf = richtext.RichTextBuffer()
|
|
|
|
|
chat_view_sw = gtk.ScrolledWindow()
|
|
|
|
|
chat_view_sw.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
|
chat_view_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
|
self._editor = richtext.RichTextView(rich_buf)
|
|
|
|
|
self._editor.connect("key-press-event", self.__key_press_event_cb)
|
|
|
|
|
self._editor.set_size_request(-1, 50)
|
|
|
|
|
chat_view_sw.add(self._editor)
|
|
|
|
|
self._editor.show()
|
|
|
|
|
|
|
|
|
|
chat_vbox.pack_start(chat_view_sw, False)
|
|
|
|
|
chat_view_sw.show()
|
|
|
|
|
|
|
|
|
|
return chat_vbox, rich_buf
|
|
|
|
|
Chat.__init__(self, self)
|
|
|
|
|
|
|
|
|
|
def _create_sidebar(self):
|
|
|
|
|
vbox = gtk.VBox(False, 6)
|
|
|
|
@ -190,7 +235,7 @@ class ChatActivity(activity.Activity):
|
|
|
|
|
label.set_alignment(0.0, 0.5)
|
|
|
|
|
vbox.pack_start(label, False)
|
|
|
|
|
label.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._buddy_list_model = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT)
|
|
|
|
|
|
|
|
|
|
self._pixbuf_active_chat = gtk.gdk.pixbuf_new_from_file(data_dir + "/bubbleOutline.png")
|
|
|
|
@ -225,123 +270,39 @@ class ChatActivity(activity.Activity):
|
|
|
|
|
vbox.pack_start(sw)
|
|
|
|
|
sw.show()
|
|
|
|
|
|
|
|
|
|
button_box = gtk.VButtonBox()
|
|
|
|
|
button_box.set_border_width(18)
|
|
|
|
|
|
|
|
|
|
talk_alone_button = gtk.Button("Talk alone")
|
|
|
|
|
button_box.pack_start(talk_alone_button)
|
|
|
|
|
talk_alone_button.show()
|
|
|
|
|
|
|
|
|
|
vbox.pack_start(button_box, False)
|
|
|
|
|
button_box.show()
|
|
|
|
|
|
|
|
|
|
return vbox
|
|
|
|
|
|
|
|
|
|
def _create_toolbar(self, rich_buf):
|
|
|
|
|
toolbar = richtext.RichTextToolbar(rich_buf)
|
|
|
|
|
|
|
|
|
|
item = gtk.MenuToolButton(None, "Links")
|
|
|
|
|
item.set_menu(gtk.Menu())
|
|
|
|
|
item.connect("show-menu", self.__show_link_menu_cb)
|
|
|
|
|
toolbar.insert(item, -1)
|
|
|
|
|
item.show()
|
|
|
|
|
|
|
|
|
|
return toolbar
|
|
|
|
|
|
|
|
|
|
def __link_activate_cb(self, item, link):
|
|
|
|
|
buf = self._editor.get_buffer()
|
|
|
|
|
buf.append_link(link['title'], link['address'])
|
|
|
|
|
|
|
|
|
|
def __show_link_menu_cb(self, button):
|
|
|
|
|
menu = gtk.Menu()
|
|
|
|
|
|
|
|
|
|
links = self.browser_shell.get_links()
|
|
|
|
|
|
|
|
|
|
for link in links:
|
|
|
|
|
item = gtk.MenuItem(link['title'], False)
|
|
|
|
|
item.connect("activate", self.__link_activate_cb, link)
|
|
|
|
|
menu.append(item)
|
|
|
|
|
item.show()
|
|
|
|
|
|
|
|
|
|
button.set_menu(menu)
|
|
|
|
|
|
|
|
|
|
def _ui_setup(self, plug):
|
|
|
|
|
vbox = gtk.VBox(False, 6)
|
|
|
|
|
|
|
|
|
|
hbox = gtk.HBox(False, 12)
|
|
|
|
|
hbox.set_border_width(12)
|
|
|
|
|
def _ui_setup(self, base):
|
|
|
|
|
Chat._ui_setup(self, base)
|
|
|
|
|
|
|
|
|
|
[chat, rich_buf] = self._create_chat()
|
|
|
|
|
hbox.pack_start(chat)
|
|
|
|
|
chat.show()
|
|
|
|
|
|
|
|
|
|
sidebar = self._create_sidebar()
|
|
|
|
|
hbox.pack_start(sidebar, False)
|
|
|
|
|
self._hbox.pack_start(sidebar, False)
|
|
|
|
|
sidebar.show()
|
|
|
|
|
|
|
|
|
|
vbox.pack_start(hbox)
|
|
|
|
|
hbox.show()
|
|
|
|
|
|
|
|
|
|
toolbar = self._create_toolbar(rich_buf)
|
|
|
|
|
vbox.pack_start(toolbar, False);
|
|
|
|
|
toolbar.show()
|
|
|
|
|
|
|
|
|
|
self._group_chat = GroupChat(self, self._chat_view, self._chat_label)
|
|
|
|
|
aniter = self._buddy_list_model.append(None)
|
|
|
|
|
self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, "Group",
|
|
|
|
|
self._MODEL_COL_ICON, self._pixbuf_active_chat, self._MODEL_COL_BUDDY, None)
|
|
|
|
|
self._activate_chat_for_buddy(None)
|
|
|
|
|
|
|
|
|
|
plug.add(vbox)
|
|
|
|
|
vbox.show()
|
|
|
|
|
|
|
|
|
|
def __key_press_event_cb(self, text_view, event):
|
|
|
|
|
if event.keyval == gtk.keysyms.Return:
|
|
|
|
|
buf = text_view.get_buffer()
|
|
|
|
|
chat = self._get_active_chat()
|
|
|
|
|
|
|
|
|
|
serializer = richtext.RichTextSerializer()
|
|
|
|
|
text = serializer.serialize(buf)
|
|
|
|
|
chat.send_message(text)
|
|
|
|
|
|
|
|
|
|
buf.set_text("")
|
|
|
|
|
buf.place_cursor(buf.get_start_iter())
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
self._plug.show_all()
|
|
|
|
|
|
|
|
|
|
def _start(self):
|
|
|
|
|
self._buddy_list.start()
|
|
|
|
|
self._pannounce.register_service(self._realname, 6666, presence.OLPC_CHAT_SERVICE,
|
|
|
|
|
self._pannounce.register_service(self._realname, self._CHAT_SERVER_PORT, presence.OLPC_CHAT_SERVICE,
|
|
|
|
|
name = self._nick, realname = self._realname)
|
|
|
|
|
|
|
|
|
|
# Create the P2P chat XMLRPC server
|
|
|
|
|
self._p2p_req_handler = ChatRequestHandler(self, self._chat_view, self._chat_label)
|
|
|
|
|
self._p2p_server = network.GlibXMLRPCServer(("", 6666))
|
|
|
|
|
self._p2p_req_handler = ChatRequestHandler(self)
|
|
|
|
|
self._p2p_server = network.GlibXMLRPCServer(("", self._CHAT_SERVER_PORT))
|
|
|
|
|
self._p2p_server.register_instance(self._p2p_req_handler)
|
|
|
|
|
|
|
|
|
|
self._gc_controller = network.GroupChatController('224.0.0.221', 6666, self._recv_group_message)
|
|
|
|
|
self._gc_controller.start()
|
|
|
|
|
|
|
|
|
|
def activity_on_connected_to_shell(self):
|
|
|
|
|
print "act %d: in activity_on_connected_to_shell" % self.activity_get_id()
|
|
|
|
|
self.activity_set_tab_text(self._act_name)
|
|
|
|
|
self._plug = self.activity_get_gtk_plug()
|
|
|
|
|
self._ui_setup(self._plug)
|
|
|
|
|
self._plug.show()
|
|
|
|
|
Chat.activity_on_connected_to_shell(self)
|
|
|
|
|
aniter = self._buddy_list_model.append(None)
|
|
|
|
|
self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, "Group",
|
|
|
|
|
self._MODEL_COL_ICON, self._pixbuf_active_chat, self._MODEL_COL_BUDDY, None)
|
|
|
|
|
self._start()
|
|
|
|
|
|
|
|
|
|
def activity_on_disconnected_from_shell(self):
|
|
|
|
|
print "act %d: in activity_on_disconnected_from_shell"%self.activity_get_id()
|
|
|
|
|
print "act %d: Shell disappeared..."%self.activity_get_id()
|
|
|
|
|
Chat.activity_on_disconnected_from_shell(self)
|
|
|
|
|
gtk.main_quit()
|
|
|
|
|
gc.collect()
|
|
|
|
|
|
|
|
|
|
def activity_on_close_from_user(self):
|
|
|
|
|
print "act %d: in activity_on_close_from_user"%self.activity_get_id()
|
|
|
|
|
self.activity_shutdown()
|
|
|
|
|
|
|
|
|
|
def activity_on_lost_focus(self):
|
|
|
|
|
print "act %d: in activity_on_lost_focus"%self.activity_get_id()
|
|
|
|
|
|
|
|
|
|
def activity_on_got_focus(self):
|
|
|
|
|
print "act %d: in activity_on_got_focus"%self.activity_get_id()
|
|
|
|
|
|
|
|
|
|
def _get_name(self):
|
|
|
|
|
ent = pwd.getpwuid(os.getuid())
|
|
|
|
@ -364,9 +325,9 @@ class ChatActivity(activity.Activity):
|
|
|
|
|
chat = None
|
|
|
|
|
buddy = self._buddy_list_model.get_value(aniter, self._MODEL_COL_BUDDY)
|
|
|
|
|
if buddy and not buddy.chat():
|
|
|
|
|
chat = BuddyChat(self, buddy, self._chat_view, self._chat_label)
|
|
|
|
|
chat = BuddyChat(self, buddy)
|
|
|
|
|
buddy.set_chat(chat)
|
|
|
|
|
self._activate_chat_for_buddy(buddy)
|
|
|
|
|
chat.activity_connect_to_shell()
|
|
|
|
|
|
|
|
|
|
def _on_buddy_presence_event(self, action, buddy):
|
|
|
|
|
if action == BuddyList.ACTION_BUDDY_ADDED:
|
|
|
|
@ -387,9 +348,12 @@ class ChatActivity(activity.Activity):
|
|
|
|
|
aniter = self._buddy_list_model.iter_next(aniter)
|
|
|
|
|
|
|
|
|
|
def notify_new_message(self, chat, buddy):
|
|
|
|
|
if chat != self._get_active_chat():
|
|
|
|
|
aniter = self._get_iter_for_buddy(buddy)
|
|
|
|
|
self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_new_message)
|
|
|
|
|
aniter = self._get_iter_for_buddy(buddy)
|
|
|
|
|
self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_new_message)
|
|
|
|
|
|
|
|
|
|
def notify_activate(self, chat):
|
|
|
|
|
aniter = self._get_iter_for_buddy(buddy)
|
|
|
|
|
self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_active_chat)
|
|
|
|
|
|
|
|
|
|
def find_buddy_by_address(self, address):
|
|
|
|
|
return self._buddy_list.find_buddy_by_address(address)
|
|
|
|
@ -397,33 +361,19 @@ class ChatActivity(activity.Activity):
|
|
|
|
|
def local_name(self):
|
|
|
|
|
return (self._nick, self._realname)
|
|
|
|
|
|
|
|
|
|
def _activate_chat_for_buddy(self, buddy):
|
|
|
|
|
self._active_chat_buddy = buddy
|
|
|
|
|
|
|
|
|
|
# Clear the "new message" icon when the user activates the chat
|
|
|
|
|
aniter = self._get_iter_for_buddy(buddy)
|
|
|
|
|
# Select the row in the list
|
|
|
|
|
if aniter:
|
|
|
|
|
selection = self._buddy_list_view.get_selection()
|
|
|
|
|
selection.select_iter(aniter)
|
|
|
|
|
icon = self._buddy_list_model.get_value(aniter, self._MODEL_COL_ICON)
|
|
|
|
|
if icon == self._pixbuf_new_message:
|
|
|
|
|
self._buddy_list_model.set_value(aniter, self._MODEL_COL_ICON, self._pixbuf_active_chat)
|
|
|
|
|
|
|
|
|
|
# Actually activate the chat
|
|
|
|
|
chat = self._group_chat
|
|
|
|
|
if self._active_chat_buddy:
|
|
|
|
|
chat = buddy.chat()
|
|
|
|
|
chat.activate()
|
|
|
|
|
def send_message(self, text):
|
|
|
|
|
if len(text) > 0:
|
|
|
|
|
self._gc_controller.send_msg(text)
|
|
|
|
|
self._local_message(True, text)
|
|
|
|
|
|
|
|
|
|
def _on_main_window_delete(self, widget, *args):
|
|
|
|
|
self.quit()
|
|
|
|
|
def recv_message(self, buddy, msg):
|
|
|
|
|
self._insert_rich_message(buddy.nick(), msg)
|
|
|
|
|
self._parent.notify_new_message(self, None)
|
|
|
|
|
|
|
|
|
|
def _get_active_chat(self):
|
|
|
|
|
chat = self._group_chat
|
|
|
|
|
if self._active_chat_buddy:
|
|
|
|
|
chat = self._active_chat_buddy.chat()
|
|
|
|
|
return chat
|
|
|
|
|
def _recv_group_message(self, msg):
|
|
|
|
|
buddy = self.find_buddy_by_address(msg['addr'])
|
|
|
|
|
if buddy:
|
|
|
|
|
self.recv_message(buddy, msg['data'])
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
try:
|
|
|
|
@ -432,7 +382,7 @@ class ChatActivity(activity.Activity):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
app = ChatActivity()
|
|
|
|
|
app = GroupChat()
|
|
|
|
|
app.activity_connect_to_shell()
|
|
|
|
|
app.run()
|
|
|
|
|
|
|
|
|
|