Get one-to-one chat back to work
This commit is contained in:
parent
f5587ac799
commit
9b12b11534
@ -24,5 +24,5 @@ class ChatActivity(Activity):
|
|||||||
if command == 'connect':
|
if command == 'connect':
|
||||||
self.cmd_connect(args)
|
self.cmd_connect(args)
|
||||||
elif command == 'message':
|
elif command == 'message':
|
||||||
self.cmd_mesage(args)
|
self.cmd_message(args)
|
||||||
|
|
||||||
|
@ -3,10 +3,21 @@ from sugar.chat.BuddyChat import BuddyChat
|
|||||||
from sugar.activity import ActivityFactory
|
from sugar.activity import ActivityFactory
|
||||||
from sugar.presence.PresenceService import PresenceService
|
from sugar.presence.PresenceService import PresenceService
|
||||||
from sugar.p2p.Stream import Stream
|
from sugar.p2p.Stream import Stream
|
||||||
|
from sugar.chat.Chat import Chat
|
||||||
|
|
||||||
class ChatController:
|
class ChatController:
|
||||||
def __init__(self, shell):
|
def __init__(self, shell):
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
self._id_to_name = {}
|
||||||
|
self._name_to_chat = {}
|
||||||
|
|
||||||
|
self._shell.connect('activity-closed', self.__activity_closed_cb)
|
||||||
|
|
||||||
|
def __activity_closed_cb(self, shell, activity_id):
|
||||||
|
if self._id_to_name.has_key(activity_id):
|
||||||
|
name = self._id_to_name[activity_id]
|
||||||
|
del self._name_to_chat[name]
|
||||||
|
del self._id_to_name[activity_id]
|
||||||
|
|
||||||
def listen(self):
|
def listen(self):
|
||||||
self._pservice = PresenceService()
|
self._pservice = PresenceService()
|
||||||
@ -18,11 +29,24 @@ class ChatController:
|
|||||||
self._buddy_stream = Stream.new_from_service(self._service)
|
self._buddy_stream = Stream.new_from_service(self._service)
|
||||||
self._buddy_stream.set_data_listener(self._recv_message)
|
self._buddy_stream.set_data_listener(self._recv_message)
|
||||||
|
|
||||||
|
def open_chat_activity(self, buddy):
|
||||||
|
service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
|
||||||
|
if service:
|
||||||
|
activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity')
|
||||||
|
activity.execute('connect', [service.object_path()])
|
||||||
|
self._name_to_chat[buddy.get_name()] = activity
|
||||||
|
self._id_to_name[activity.get_id()] = buddy.get_name()
|
||||||
|
|
||||||
|
def _get_chat_activity(self, buddy):
|
||||||
|
nick = buddy.get_name()
|
||||||
|
if not self._name_to_chat.has_key(nick):
|
||||||
|
self.open_chat_activity(buddy)
|
||||||
|
return self._name_to_chat[nick]
|
||||||
|
|
||||||
def _recv_message(self, address, message):
|
def _recv_message(self, address, message):
|
||||||
[nick, msg] = Chat.deserialize_message(message)
|
[nick, msg] = Chat.deserialize_message(message)
|
||||||
buddy = self._pservice.get_buddy_by_name(nick)
|
buddy = self._pservice.get_buddy_by_name(nick)
|
||||||
if buddy:
|
if buddy:
|
||||||
activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity')
|
activity = self._get_chat_activity(buddy)
|
||||||
service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
|
if activity:
|
||||||
activity.execute('start', service.object_path())
|
activity.execute('message', [message])
|
||||||
activity.execute('message', message)
|
|
||||||
|
@ -109,9 +109,7 @@ class PresenceView(gtk.VBox):
|
|||||||
chat = None
|
chat = None
|
||||||
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)
|
self._shell.get_chat_controller().open_chat_activity(buddy)
|
||||||
activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity')
|
|
||||||
activity.execute('start', [chat_service.object_path()])
|
|
||||||
|
|
||||||
def __buddy_icon_changed_cb(self, buddy):
|
def __buddy_icon_changed_cb(self, buddy):
|
||||||
it = self._get_iter_for_buddy(buddy)
|
it = self._get_iter_for_buddy(buddy)
|
||||||
|
@ -45,8 +45,14 @@ class ShellDbusService(dbus.service.Object):
|
|||||||
def log(self, module_id, message):
|
def log(self, module_id, message):
|
||||||
gobject.idle_add(self.__log_idle, (module_id, message))
|
gobject.idle_add(self.__log_idle, (module_id, message))
|
||||||
|
|
||||||
class Shell:
|
class Shell(gobject.GObject):
|
||||||
|
__gsignals__ = {
|
||||||
|
'activity-closed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([str]))
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, registry):
|
def __init__(self, registry):
|
||||||
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
self._screen = wnck.screen_get_default()
|
self._screen = wnck.screen_get_default()
|
||||||
self._registry = registry
|
self._registry = registry
|
||||||
self._hosts = {}
|
self._hosts = {}
|
||||||
@ -63,8 +69,8 @@ class Shell:
|
|||||||
self._owner = ShellOwner()
|
self._owner = ShellOwner()
|
||||||
self._owner.announce()
|
self._owner.announce()
|
||||||
|
|
||||||
chat_controller = ChatController(self)
|
self._chat_controller = ChatController(self)
|
||||||
chat_controller.listen()
|
self._chat_controller.listen()
|
||||||
|
|
||||||
self._home_window = HomeWindow(self)
|
self._home_window = HomeWindow(self)
|
||||||
self._home_window.show()
|
self._home_window.show()
|
||||||
@ -79,7 +85,11 @@ class Shell:
|
|||||||
def __window_closed_cb(self, screen, window):
|
def __window_closed_cb(self, screen, window):
|
||||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||||
xid = window.get_xid()
|
xid = window.get_xid()
|
||||||
self._hosts[xid] = None
|
|
||||||
|
activity = self._hosts[xid]
|
||||||
|
self.emit('activity-closed', activity.get_id())
|
||||||
|
|
||||||
|
del self._hosts[xid]
|
||||||
|
|
||||||
def get_activity(self, activity_id):
|
def get_activity(self, activity_id):
|
||||||
for host in self._hosts:
|
for host in self._hosts:
|
||||||
@ -156,3 +166,6 @@ class Shell:
|
|||||||
|
|
||||||
def get_registry(self):
|
def get_registry(self):
|
||||||
return self._registry
|
return self._registry
|
||||||
|
|
||||||
|
def get_chat_controller(self):
|
||||||
|
return self._chat_controller
|
||||||
|
@ -61,7 +61,7 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
return self._activity.get_shared()
|
return self._activity.get_shared()
|
||||||
|
|
||||||
@dbus.service.method(ACTIVITY_INTERFACE,
|
@dbus.service.method(ACTIVITY_INTERFACE,
|
||||||
in_signature="sao", out_signature="")
|
in_signature="sas", out_signature="")
|
||||||
def execute(self, command, args):
|
def execute(self, command, args):
|
||||||
self._activity.execute(command, args)
|
self._activity.execute(command, args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user