From 7db372cc1cdc2d2c19af83c9566b14fa406a73a2 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 21 Feb 2007 16:53:44 +0000 Subject: Make bundle registry a singleton. Get the object path from the registry. --- (limited to 'sugar/activity') diff --git a/sugar/activity/ActivityFactory.py b/sugar/activity/ActivityFactory.py index 8ecb4c8..ec45fbe 100644 --- a/sugar/activity/ActivityFactory.py +++ b/sugar/activity/ActivityFactory.py @@ -25,6 +25,7 @@ import gobject import gtk from sugar.presence.PresenceService import PresenceService +from sugar.activity import bundleregistry from sugar.activity.bundle import Bundle from sugar import logger @@ -90,14 +91,14 @@ class ActivityCreationHandler(gobject.GObject): ([gobject.TYPE_PYOBJECT])) } - def __init__(self, activity_name): + def __init__(self, service_name): gobject.GObject.__init__(self) - bus = dbus.SessionBus() - factory_name = activity_name - factory_path = get_path(factory_name) + registry = bundleregistry.get_registry() + bundle = registry.get_bundle(service_name) - proxy_obj = bus.get_object(factory_name, factory_path) + bus = dbus.SessionBus() + proxy_obj = bus.get_object(service_name, bundle.get_object_path()) factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory") factory.create(reply_handler=self._reply_handler, error_handler=self._error_handler) @@ -113,9 +114,9 @@ class ActivityCreationHandler(gobject.GObject): logging.debug("Couldn't create activity: %s" % err) self.emit('error', err) -def create(activity_name): +def create(service_name): """Create a new activity from its name.""" - return ActivityCreationHandler(activity_name) + return ActivityCreationHandler(service_name) def start_factory(activity_class, bundle_path): """Start the activity factory.""" diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py index c7675de..8c17958 100644 --- a/sugar/activity/bundle.py +++ b/sugar/activity/bundle.py @@ -71,6 +71,10 @@ class Bundle: """Get the activity service name""" return self._service_name + def get_object_path(self): + """Get the path to the service object""" + return '/' + self._service_name.replace('.', '/') + def get_default_type(self): """Get the type of the main network service which tracks presence and provides info about the activity, for example the title.""" diff --git a/sugar/activity/bundleregistry.py b/sugar/activity/bundleregistry.py index 22a84e1..ccf3b79 100644 --- a/sugar/activity/bundleregistry.py +++ b/sugar/activity/bundleregistry.py @@ -73,3 +73,14 @@ class BundleRegistry(gobject.GObject): return True else: return False + +def get_registry(): + return _bundle_registry + +_bundle_registry = BundleRegistry() + +for path in env.get_data_dirs(): + bundles_path = os.path.join(path, 'activities') + _bundle_registry.add_search_path(bundles_path) + +_bundle_registry.add_search_path(env.get_user_activities_dir()) -- cgit v0.9.1