From 95d9b7fe8e7cbde413ef5f937cc1dda2b7fa8813 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 9 Aug 2006 15:53:10 +0200 Subject: [PATCH] More work on the chat. Fix terminal api --- activities/chat/ChatActivity.py | 21 +++++++++++++----- activities/chat/chat.activity | 1 - activities/terminal/TerminalActivity.py | 4 ++-- activities/terminal/terminal.activity | 1 - shell/{ChatListener.py => ChatController.py} | 23 ++++++++++---------- shell/PresenceView.py | 10 ++------- shell/Shell.py | 17 +++++++++++---- sugar/activity/Activity.py | 9 ++++++++ 8 files changed, 53 insertions(+), 33 deletions(-) rename shell/{ChatListener.py => ChatController.py} (74%) diff --git a/activities/chat/ChatActivity.py b/activities/chat/ChatActivity.py index ab661d12..4661eb5c 100644 --- a/activities/chat/ChatActivity.py +++ b/activities/chat/ChatActivity.py @@ -2,16 +2,27 @@ from gettext import gettext as _ from sugar.activity.Activity import Activity from sugar.chat.BuddyChat import BuddyChat +from sugar.presence.PresenceService import PresenceService class ChatActivity(Activity): - def __init__(self, service): + def __init__(self): Activity.__init__(self) self.set_title(_('Private chat')) - self._service = service - self._chat = BuddyChat(self._service) + def cmd_connect(self, args): + pservice = PresenceService() + service = pservice.get(args[0]) + + self._chat = BuddyChat(service) self.add(self._chat) self._chat.show() - def recv_message(self, message): - self._chat.recv_message(message) + def cmd_message(self, args): + self._chat.recv_message(args[0]) + + def execute(self, command, args): + if command == 'connect': + self.cmd_connect(args) + elif command == 'message': + self.cmd_mesage(args) + diff --git a/activities/chat/chat.activity b/activities/chat/chat.activity index b42ba8a0..9726f389 100644 --- a/activities/chat/chat.activity +++ b/activities/chat/chat.activity @@ -2,4 +2,3 @@ name = Chat id = com.redhat.Sugar.ChatActivity python_module = chat.ChatActivity.ChatActivity -default_type = _chat_activity._tcp diff --git a/activities/terminal/TerminalActivity.py b/activities/terminal/TerminalActivity.py index 0c1fde1a..e2e02ed3 100644 --- a/activities/terminal/TerminalActivity.py +++ b/activities/terminal/TerminalActivity.py @@ -51,8 +51,8 @@ class Terminal(gtk.HBox): pass class TerminalActivity(Activity): - def __init__(self, service): - Activity.__init__(self, service) + def __init__(self): + Activity.__init__(self) self.set_title("Terminal") diff --git a/activities/terminal/terminal.activity b/activities/terminal/terminal.activity index 5421e6f5..1f3e1e57 100644 --- a/activities/terminal/terminal.activity +++ b/activities/terminal/terminal.activity @@ -1,5 +1,4 @@ [Activity] name = Terminal id = org.sugar.Terminal -default_type = _terminal_olpc._udp python_module = terminal.TerminalActivity.TerminalActivity diff --git a/shell/ChatListener.py b/shell/ChatController.py similarity index 74% rename from shell/ChatListener.py rename to shell/ChatController.py index 6c0f6de7..65bd8c6f 100644 --- a/shell/ChatListener.py +++ b/shell/ChatController.py @@ -4,16 +4,17 @@ from sugar.activity import ActivityFactory from sugar.presence.PresenceService import PresenceService from sugar.p2p.Stream import Stream -class ChatListener: - def __init__(self): - self._chats = {} - - self._pservice = PresenceService() - self._pservice.register_service_type(BuddyChat.SERVICE_TYPE) +class ChatController: + def __init__(self, shell): + self._shell = shell - def start(self): + def listen(self): + self._pservice = PresenceService() + + self._pservice.register_service_type(BuddyChat.SERVICE_TYPE) self._service = self._pservice.register_service(env.get_nick_name(), BuddyChat.SERVICE_TYPE) + self._buddy_stream = Stream.new_from_service(self._service) self._buddy_stream.set_data_listener(self._recv_message) @@ -21,9 +22,7 @@ class ChatListener: [nick, msg] = Chat.deserialize_message(message) buddy = self._pservice.get_buddy_by_name(nick) if buddy: + activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity') service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE) - self.open_chat(service) - #chat.recv_message(message) - - def open_chat(self, service): - ActivityFactory.create("com.redhat.Sugar.ChatActivity") + activity.execute('start', service.object_path()) + activity.execute('message', message) diff --git a/shell/PresenceView.py b/shell/PresenceView.py index 05397354..4ecb7990 100644 --- a/shell/PresenceView.py +++ b/shell/PresenceView.py @@ -110,14 +110,8 @@ class PresenceView(gtk.VBox): buddy = view.get_model().get_value(aniter, self._MODEL_COL_BUDDY) if buddy: chat_service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE) - print chat_service - if chat_service: - bus = dbus.SessionBus() - 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.open_chat(chat_service.object_path()) - else: - print 'Could not find buddy chat' + activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity') + #activity.execute('start', [chat_service.object_path()]) def __buddy_icon_changed_cb(self, buddy): it = self._get_iter_for_buddy(buddy) diff --git a/shell/Shell.py b/shell/Shell.py index 55b8902e..a2398099 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -15,7 +15,7 @@ from ConsoleWindow import ConsoleWindow from Owner import ShellOwner from sugar.presence.PresenceService import PresenceService from ActivityHost import ActivityHost -from ChatListener import ChatListener +from ChatController import ChatController from sugar.activity import ActivityFactory class ShellDbusService(dbus.service.Object): @@ -62,8 +62,8 @@ class Shell: self._owner = ShellOwner() self._owner.announce() - chat_listener = ChatListener() - chat_listener.start() + chat_controller = ChatController(self) + chat_controller.listen() self._home_window = HomeWindow(self) self._home_window.show() @@ -81,6 +81,12 @@ class Shell: xid = window.get_xid() self._hosts[xid] = None + def get_activity(self, activity_id): + for host in self._hosts: + if host.get_id() == activity_id: + return host + return None + def get_current_activity(self): window = self._screen.get_active_window() if window: @@ -135,7 +141,10 @@ class Shell: activity = ActivityFactory.create(activity_name) info = self._registry.get_activity_from_id(activity_name) if info: - activity.set_default_type(info.get_default_type()) + default_type = info.get_default_type() + if default_type != None: + activity.set_default_type(default_type) + activity.execute('test', []) return activity else: logging.error('No such activity in the directory') diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py index 46848a42..ec745b29 100644 --- a/sugar/activity/Activity.py +++ b/sugar/activity/Activity.py @@ -60,6 +60,11 @@ class ActivityDbusService(dbus.service.Object): """Returns True if the activity is shared on the mesh.""" return self._activity.get_shared() + @dbus.service.method(ACTIVITY_INTERFACE, + in_signature="sao", out_signature="") + def execute(self, command, args): + self._activity.execute(command, args) + class Activity(gtk.Window): """Base Activity class that all other Activities derive from.""" @@ -133,3 +138,7 @@ class Activity(gtk.Window): self._service = self._pservice.share_activity(self, self._default_type, properties) self._shared = True + + def execute(self, command, args): + """Execute the given command with args""" + pass