Get private chat to show, not working yet

This commit is contained in:
Marco Pesenti Gritti 2006-07-26 15:38:54 +02:00
parent fd6367007a
commit f5b1be244f
4 changed files with 16 additions and 20 deletions

View File

@ -4,6 +4,7 @@ import logging
import gtk import gtk
import gobject import gobject
from gettext import gettext as _
from sugar.activity.Activity import Activity from sugar.activity.Activity import Activity
from sugar.presence import Service from sugar.presence import Service
@ -17,22 +18,14 @@ _CHAT_ACTIVITY_TYPE = "_chat_activity_type._tcp"
class ChatActivity(Activity): class ChatActivity(Activity):
def __init__(self, service): def __init__(self, service):
Activity.__init__(self, _CHAT_ACTIVITY_TYPE) Activity.__init__(self)
self.set_title(_('Private chat'))
self._service = service self._service = service
self._chat = BuddyChat(self._service) self._chat = BuddyChat(self._service)
self.add(self._chat)
def on_connected_to_shell(self):
self.set_tab_text(self._service.get_name())
self.set_can_close(True)
self.set_tab_icon(name = "im")
self.set_show_tab_icon(True)
plug = self.gtk_plug()
plug.add(self._chat)
self._chat.show() self._chat.show()
plug.show()
def recv_message(self, message): def recv_message(self, message):
self._chat.recv_message(message) self._chat.recv_message(message)
@ -45,8 +38,8 @@ class ChatShellDbusService(dbus.service.Object):
dbus.service.Object.__init__(self, bus_name, object_path) dbus.service.Object.__init__(self, bus_name, object_path)
@dbus.service.method('com.redhat.Sugar.ChatShell') @dbus.service.method('com.redhat.Sugar.ChatShell')
def open_chat(self, serialized_service): def open_chat(self, service_path):
self._parent.open_chat(Service.deserialize(serialized_service)) self._parent.open_chat(service_path)
class ChatListener: class ChatListener:
def __init__(self): def __init__(self):
@ -81,7 +74,8 @@ class ChatListener:
logging.error('The buddy %s is not present.' % (nick)) logging.error('The buddy %s is not present.' % (nick))
return return
def open_chat(self, service): def open_chat(self, service_path):
service = self._pservice._new_object(service_path)
chat = ChatActivity(service) chat = ChatActivity(service)
self._chats[service.get_name()] = chat self._chats[service.get_name()] = chat
gobject.idle_add(self._connect_chat, chat) gobject.idle_add(self._connect_chat, chat)

View File

@ -2,3 +2,4 @@
name = Chat name = Chat
id = com.redhat.Sugar.ChatActivity id = com.redhat.Sugar.ChatActivity
python_module = ChatActivity.ChatActivity python_module = ChatActivity.ChatActivity
default_type = _web_olpc._udp

View File

@ -54,12 +54,12 @@ class BuddyDBusHelper(dbus.service.Object):
return icon return icon
@dbus.service.method(BUDDY_DBUS_INTERFACE, @dbus.service.method(BUDDY_DBUS_INTERFACE,
in_signature="", out_signature="o") in_signature="s", out_signature="o")
def getServiceOfType(self, stype): def getServiceOfType(self, stype):
service = self._parent.get_service_of_type(stype) service = self._parent.get_service_of_type(stype)
if not service: if not service:
raise NotFoundError("Not found") raise NotFoundError("Not found")
return service return service.object_path()
@dbus.service.method(BUDDY_DBUS_INTERFACE, @dbus.service.method(BUDDY_DBUS_INTERFACE,
in_signature="", out_signature="ao") in_signature="", out_signature="ao")
@ -213,6 +213,7 @@ class Buddy(object):
for service in self._services.values(): for service in self._services.values():
if service.get_type() == stype and service.get_activity_id() == actid: if service.get_type() == stype and service.get_activity_id() == actid:
return service return service
if self._services.has_key(stype): if self._services.has_key(stype):
return self._services[stype] return self._services[stype]
return None return None

View File

@ -110,12 +110,12 @@ class PresenceView(gtk.VBox):
buddy = view.get_model().get_value(aniter, self._MODEL_COL_BUDDY) buddy = view.get_model().get_value(aniter, self._MODEL_COL_BUDDY)
if buddy: if buddy:
chat_service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE) chat_service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
print chat_service
if chat_service: if chat_service:
bus = dbus.SessionBus() bus = dbus.SessionBus()
proxy_obj = bus.get_object('com.redhat.Sugar.Chat', '/com/redhat/Sugar/Chat') proxy_obj = bus.get_object('com.redhat.Sugar.Chat', '/com/redhat/Sugar/Chat')
chat_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.ChatShell') chat_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.ChatShell')
serialized_service = Service.serialize(chat_service) chat_shell.open_chat(chat_service.object_path())
chat_shell.open_chat(serialized_service)
else: else:
print 'Could not find buddy chat' print 'Could not find buddy chat'