More work on the chat. Fix terminal api

This commit is contained in:
Marco Pesenti Gritti 2006-08-09 15:53:10 +02:00
parent a9a65f42df
commit 95d9b7fe8e
8 changed files with 53 additions and 33 deletions

View File

@ -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)

View File

@ -2,4 +2,3 @@
name = Chat
id = com.redhat.Sugar.ChatActivity
python_module = chat.ChatActivity.ChatActivity
default_type = _chat_activity._tcp

View File

@ -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")

View File

@ -1,5 +1,4 @@
[Activity]
name = Terminal
id = org.sugar.Terminal
default_type = _terminal_olpc._udp
python_module = terminal.TerminalActivity.TerminalActivity

View File

@ -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)

View File

@ -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)

View File

@ -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')

View File

@ -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