More work on the chat. Fix terminal api
This commit is contained in:
parent
a9a65f42df
commit
95d9b7fe8e
@ -2,16 +2,27 @@ from gettext import gettext as _
|
|||||||
|
|
||||||
from sugar.activity.Activity import Activity
|
from sugar.activity.Activity import Activity
|
||||||
from sugar.chat.BuddyChat import BuddyChat
|
from sugar.chat.BuddyChat import BuddyChat
|
||||||
|
from sugar.presence.PresenceService import PresenceService
|
||||||
|
|
||||||
class ChatActivity(Activity):
|
class ChatActivity(Activity):
|
||||||
def __init__(self, service):
|
def __init__(self):
|
||||||
Activity.__init__(self)
|
Activity.__init__(self)
|
||||||
self.set_title(_('Private chat'))
|
self.set_title(_('Private chat'))
|
||||||
|
|
||||||
self._service = service
|
def cmd_connect(self, args):
|
||||||
self._chat = BuddyChat(self._service)
|
pservice = PresenceService()
|
||||||
|
service = pservice.get(args[0])
|
||||||
|
|
||||||
|
self._chat = BuddyChat(service)
|
||||||
self.add(self._chat)
|
self.add(self._chat)
|
||||||
self._chat.show()
|
self._chat.show()
|
||||||
|
|
||||||
def recv_message(self, message):
|
def cmd_message(self, args):
|
||||||
self._chat.recv_message(message)
|
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)
|
||||||
|
|
||||||
|
@ -2,4 +2,3 @@
|
|||||||
name = Chat
|
name = Chat
|
||||||
id = com.redhat.Sugar.ChatActivity
|
id = com.redhat.Sugar.ChatActivity
|
||||||
python_module = chat.ChatActivity.ChatActivity
|
python_module = chat.ChatActivity.ChatActivity
|
||||||
default_type = _chat_activity._tcp
|
|
||||||
|
@ -51,8 +51,8 @@ class Terminal(gtk.HBox):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class TerminalActivity(Activity):
|
class TerminalActivity(Activity):
|
||||||
def __init__(self, service):
|
def __init__(self):
|
||||||
Activity.__init__(self, service)
|
Activity.__init__(self)
|
||||||
|
|
||||||
self.set_title("Terminal")
|
self.set_title("Terminal")
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
[Activity]
|
[Activity]
|
||||||
name = Terminal
|
name = Terminal
|
||||||
id = org.sugar.Terminal
|
id = org.sugar.Terminal
|
||||||
default_type = _terminal_olpc._udp
|
|
||||||
python_module = terminal.TerminalActivity.TerminalActivity
|
python_module = terminal.TerminalActivity.TerminalActivity
|
||||||
|
@ -4,16 +4,17 @@ 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
|
||||||
|
|
||||||
class ChatListener:
|
class ChatController:
|
||||||
def __init__(self):
|
def __init__(self, shell):
|
||||||
self._chats = {}
|
self._shell = shell
|
||||||
|
|
||||||
|
def listen(self):
|
||||||
self._pservice = PresenceService()
|
self._pservice = PresenceService()
|
||||||
self._pservice.register_service_type(BuddyChat.SERVICE_TYPE)
|
|
||||||
|
|
||||||
def start(self):
|
self._pservice.register_service_type(BuddyChat.SERVICE_TYPE)
|
||||||
self._service = self._pservice.register_service(env.get_nick_name(),
|
self._service = self._pservice.register_service(env.get_nick_name(),
|
||||||
BuddyChat.SERVICE_TYPE)
|
BuddyChat.SERVICE_TYPE)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@ -21,9 +22,7 @@ class ChatListener:
|
|||||||
[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')
|
||||||
service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
|
service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
|
||||||
self.open_chat(service)
|
activity.execute('start', service.object_path())
|
||||||
#chat.recv_message(message)
|
activity.execute('message', message)
|
||||||
|
|
||||||
def open_chat(self, service):
|
|
||||||
ActivityFactory.create("com.redhat.Sugar.ChatActivity")
|
|
@ -110,14 +110,8 @@ 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
|
activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity')
|
||||||
if chat_service:
|
#activity.execute('start', [chat_service.object_path()])
|
||||||
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'
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -15,7 +15,7 @@ from ConsoleWindow import ConsoleWindow
|
|||||||
from Owner import ShellOwner
|
from Owner import ShellOwner
|
||||||
from sugar.presence.PresenceService import PresenceService
|
from sugar.presence.PresenceService import PresenceService
|
||||||
from ActivityHost import ActivityHost
|
from ActivityHost import ActivityHost
|
||||||
from ChatListener import ChatListener
|
from ChatController import ChatController
|
||||||
from sugar.activity import ActivityFactory
|
from sugar.activity import ActivityFactory
|
||||||
|
|
||||||
class ShellDbusService(dbus.service.Object):
|
class ShellDbusService(dbus.service.Object):
|
||||||
@ -62,8 +62,8 @@ class Shell:
|
|||||||
self._owner = ShellOwner()
|
self._owner = ShellOwner()
|
||||||
self._owner.announce()
|
self._owner.announce()
|
||||||
|
|
||||||
chat_listener = ChatListener()
|
chat_controller = ChatController(self)
|
||||||
chat_listener.start()
|
chat_controller.listen()
|
||||||
|
|
||||||
self._home_window = HomeWindow(self)
|
self._home_window = HomeWindow(self)
|
||||||
self._home_window.show()
|
self._home_window.show()
|
||||||
@ -81,6 +81,12 @@ class Shell:
|
|||||||
xid = window.get_xid()
|
xid = window.get_xid()
|
||||||
self._hosts[xid] = None
|
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):
|
def get_current_activity(self):
|
||||||
window = self._screen.get_active_window()
|
window = self._screen.get_active_window()
|
||||||
if window:
|
if window:
|
||||||
@ -135,7 +141,10 @@ class Shell:
|
|||||||
activity = ActivityFactory.create(activity_name)
|
activity = ActivityFactory.create(activity_name)
|
||||||
info = self._registry.get_activity_from_id(activity_name)
|
info = self._registry.get_activity_from_id(activity_name)
|
||||||
if info:
|
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
|
return activity
|
||||||
else:
|
else:
|
||||||
logging.error('No such activity in the directory')
|
logging.error('No such activity in the directory')
|
||||||
|
@ -60,6 +60,11 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
"""Returns True if the activity is shared on the mesh."""
|
"""Returns True if the activity is shared on the mesh."""
|
||||||
return self._activity.get_shared()
|
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):
|
class Activity(gtk.Window):
|
||||||
"""Base Activity class that all other Activities derive from."""
|
"""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._service = self._pservice.share_activity(self,
|
||||||
self._default_type, properties)
|
self._default_type, properties)
|
||||||
self._shared = True
|
self._shared = True
|
||||||
|
|
||||||
|
def execute(self, command, args):
|
||||||
|
"""Execute the given command with args"""
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user