Forgot to commit changes... This breaks one-to-one chat,

I'm going to fix it.
This commit is contained in:
Marco Pesenti Gritti 2006-07-06 15:59:48 +02:00
parent e8acfd6be3
commit 85ff44db1c
6 changed files with 89 additions and 30 deletions

View File

@ -23,11 +23,12 @@ class BrowserActivity(Activity):
FOLLOWING = 2 FOLLOWING = 2
LEADING = 3 LEADING = 3
def __init__(self, uri, mode = SOLO): def __init__(self, args):
Activity.__init__(self, _BROWSER_ACTIVITY_TYPE) Activity.__init__(self, _BROWSER_ACTIVITY_TYPE)
self.uri = uri
self._mode = mode
self.uri = args[0]
self._mode = BrowserActivity.SOLO
self._share_service = None self._share_service = None
self._model_service = None self._model_service = None
self._notif_service = None self._notif_service = None

View File

@ -1,2 +1,3 @@
[Activity] [Activity]
python_class = browser name = com.redhat.Sugar.BrowserActivity
class = BrowserActivity.BrowserActivity

View File

@ -1,2 +1,3 @@
[Activity] [Activity]
python_class = ChatActivity name = com.redhat.Sugar.ChatActivity
class = ChatActivity.ChatActivity

View File

@ -2,7 +2,6 @@ import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
import pango import pango
import dbus
import cgi import cgi
import xml.sax.saxutils import xml.sax.saxutils
import gobject import gobject
@ -10,6 +9,7 @@ import socket
from google import google from google import google
from sugar.presence.PresenceService import PresenceService from sugar.presence.PresenceService import PresenceService
from sugar.activity import Activity
from gettext import gettext as _ from gettext import gettext as _
@ -150,23 +150,11 @@ class ActivitiesView(gtk.TreeView):
self._owner = owner self._owner = owner
def _row_activated_cb(self, treeview, path, column): def _row_activated_cb(self, treeview, path, column):
bus = dbus.SessionBus()
proxy_obj = bus.get_object('com.redhat.Sugar.Browser', '/com/redhat/Sugar/Browser')
browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
model = self.get_model() model = self.get_model()
address = model.get_value(model.get_iter(path), _COLUMN_ADDRESS) address = model.get_value(model.get_iter(path), _COLUMN_ADDRESS)
service = model.get_value(model.get_iter(path), _COLUMN_SERVICE) service = model.get_value(model.get_iter(path), _COLUMN_SERVICE)
print 'Activated row %s' % address Activity.create('com.redhat.Sugar.BrowserActivity', service, [ address ])
if service is None:
browser_shell.open_browser(address)
else:
if not self._owner:
raise RuntimeError("We don't have an owner yet!")
serialized_service = service.serialize(self._owner)
browser_shell.open_browser(address, serialized_service)
class StartPage(gtk.HBox): class StartPage(gtk.HBox):
def __init__(self, ac_signal_object): def __init__(self, ac_signal_object):

View File

@ -8,6 +8,7 @@ import gtk
from shell import Shell from shell import Shell
from sugar import env from sugar import env
from sugar.activity import Activity
class Session: class Session:
def __init__(self): def __init__(self):
@ -42,19 +43,20 @@ class Session:
def _run_activity(self, activity_dir): def _run_activity(self, activity_dir):
env.add_to_python_path(activity_dir) env.add_to_python_path(activity_dir)
activities = []
for filename in os.listdir(activity_dir): for filename in os.listdir(activity_dir):
if filename.endswith(".activity"): if filename.endswith(".activity"):
path = os.path.join(activity_dir, filename) path = os.path.join(activity_dir, filename)
cp = ConfigParser() cp = ConfigParser()
cp.read([path]) cp.read([path])
python_class = cp.get('Activity', "python_class")
activities.append(python_class)
for activity in activities: activity_name = cp.get('Activity', "name")
args = [ 'python', '-m', activity ] activity_class = cp.get('Activity', "class")
args = [ 'python', '-m', 'sugar/activity/Activity' ]
args.append(activity_name)
args.append(activity_class)
pid = os.spawnvp(os.P_NOWAIT, 'python', args) pid = os.spawnvp(os.P_NOWAIT, 'python', args)
self._activity_processes[activity] = pid self._activity_processes[activity_name] = pid
def _shell_close_cb(self, shell): def _shell_close_cb(self, shell):
self.shutdown() self.shutdown()

View File

@ -1,4 +1,5 @@
# -*- tab-width: 4; indent-tabs-mode: t -*- import sys
import imp
import dbus import dbus
import dbus.service import dbus.service
@ -21,6 +22,68 @@ ON_LOST_FOCUS_CB = "lost_focus"
ON_GOT_FOCUS_CB = "got_focus" ON_GOT_FOCUS_CB = "got_focus"
ON_PUBLISH_CB = "publish" ON_PUBLISH_CB = "publish"
def get_path(activity_name):
"""Returns the activity path"""
return '/' + activity_name.replace('.', '/')
def get_factory(activity_name):
"""Returns the activity factory"""
return activity_name + '.Factory'
class ActivityFactory(dbus.service.Object):
"""Dbus service that takes care of creating new instances of an activity"""
def __init__(self, activity_name, activity_class):
splitted_module = activity_class.rsplit('.', 1)
module_name = splitted_module[0]
class_name = splitted_module[1]
(fp, pathname, description) = imp.find_module(module_name)
module = imp.load_module(module_name, fp, pathname, description)
self._class = getattr(module, class_name)
bus = dbus.SessionBus()
factory = get_factory(activity_name)
bus_name = dbus.service.BusName(factory, bus = bus)
dbus.service.Object.__init__(self, bus_name, get_path(factory))
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
def create_with_service(self, serialized_service, args):
service = None
if serialized_service is not None:
service = Service.deserialize(serialized_service)
activity = self._class(args)
gobject.idle_add(self._start_activity_cb, activity, service)
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
def create(self, args):
self.create_with_service(None, args)
def _start_activity_cb(self, activity, service):
activity.connect_to_shell(service)
def create(activity_name, service = None, args = None):
"""Create a new activity from his name."""
bus = dbus.SessionBus()
factory_name = get_factory(activity_name)
factory_path = get_path(factory_name)
proxy_obj = bus.get_object(factory_name, factory_path)
factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory")
if service:
serialized_service = service.serialize(service)
factory.create_with_service(serialized_service, args)
else:
factory.create(args)
def main(activity_name, activity_class):
"""Starts the activity main loop."""
factory = ActivityFactory(activity_name, activity_class)
gtk.main()
class ActivityDbusService(dbus.service.Object): class ActivityDbusService(dbus.service.Object):
"""Base dbus service object that each Activity uses to export dbus methods. """Base dbus service object that each Activity uses to export dbus methods.
@ -335,3 +398,6 @@ class Activity(object):
def on_close_from_user(self): def on_close_from_user(self):
"""Triggered when this Activity is closed by the user.""" """Triggered when this Activity is closed by the user."""
pass pass
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])