Make bundle registry a singleton. Get the object path from the registry.

This commit is contained in:
Marco Pesenti Gritti 2007-02-21 17:53:44 +01:00
parent f5b13b716e
commit 7db372cc1c
7 changed files with 33 additions and 26 deletions

View File

@ -18,6 +18,7 @@ import gobject
from sugar.graphics.iconcolor import IconColor
from sugar.presence import PresenceService
from sugar.activity import bundleregistry
from model.BuddyModel import BuddyModel
class ActivityModel:
@ -53,12 +54,12 @@ class MeshModel(gobject.GObject):
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
}
def __init__(self, bundle_registry):
def __init__(self):
gobject.GObject.__init__(self)
self._activities = {}
self._buddies = {}
self._bundle_registry = bundle_registry
self._bundle_registry = bundleregistry.get_registry()
self._pservice = PresenceService.get_instance()
self._pservice.connect("service-appeared",

View File

@ -44,8 +44,6 @@ class ShellModel(gobject.GObject):
self._current_activity = None
self._state = self.STATE_RUNNING
self._bundle_registry = BundleRegistry()
PresenceService.start()
self._pservice = PresenceService.get_instance()
@ -53,16 +51,10 @@ class ShellModel(gobject.GObject):
self._owner.announce()
self._friends = Friends()
self._mesh = MeshModel(self._bundle_registry)
self._home = HomeModel(self._bundle_registry)
self._mesh = MeshModel()
self._home = HomeModel()
self._devices = DevicesModel()
for path in env.get_data_dirs():
bundles_path = os.path.join(path, 'activities')
self._bundle_registry.add_search_path(bundles_path)
self._bundle_registry.add_search_path(env.get_user_activities_dir())
def do_set_property(self, pspec, value):
if pspec.name == 'state':
self._state = value
@ -71,9 +63,6 @@ class ShellModel(gobject.GObject):
if pspec.name == 'state':
return self._state
def get_bundle_registry(self):
return self._bundle_registry
def get_mesh(self):
return self._mesh

View File

@ -21,7 +21,7 @@ import wnck
import dbus
from model.homeactivity import HomeActivity
from sugar.activity import Activity
from sugar.activity import bundleregistry
_ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
_ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
@ -43,11 +43,11 @@ class HomeModel(gobject.GObject):
([gobject.TYPE_PYOBJECT]))
}
def __init__(self, bundle_registry):
def __init__(self):
gobject.GObject.__init__(self)
self._activities = {}
self._bundle_registry = bundle_registry
self._bundle_registry = bundleregistry.get_registry()
self._current_activity = None
screen = wnck.screen_get_default()

View File

@ -21,6 +21,7 @@ from sugar.graphics import units
from sugar.graphics.iconcolor import IconColor
from sugar.graphics.iconbutton import IconButton
from sugar.presence import PresenceService
from sugar.activity import bundleregistry
from sugar import profile
class ActivityButton(IconButton):
@ -63,7 +64,7 @@ class ActivitiesBox(hippo.CanvasBox):
self._invite_to_item = {}
self._invites = self._shell_model.get_invites()
bundle_registry = self._shell_model.get_bundle_registry()
bundle_registry = bundleregistry.get_registry()
for bundle in bundle_registry:
if bundle.get_show_launcher():
self.add_activity(bundle)

View File

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

View File

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

View File

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