Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/sugar-install-bundle3
-rw-r--r--shell/shellservice.py11
-rw-r--r--sugar/activity/registry.py28
-rw-r--r--sugar/objects/objecttype.py23
4 files changed, 61 insertions, 4 deletions
diff --git a/bin/sugar-install-bundle b/bin/sugar-install-bundle
index 883dbfb..3cce4cb 100755
--- a/bin/sugar-install-bundle
+++ b/bin/sugar-install-bundle
@@ -3,6 +3,9 @@ import sys
from sugar.activity.bundle import Bundle
+from dbus.mainloop.glib import DBusGMainLoop
+DBusGMainLoop(set_as_default=True)
+
bundle = Bundle(sys.argv[1])
bundle.install()
diff --git a/shell/shellservice.py b/shell/shellservice.py
index b4c96ff..c612d6e 100644
--- a/shell/shellservice.py
+++ b/shell/shellservice.py
@@ -56,6 +56,9 @@ class ShellService(dbus.service.Object):
self._home_model.connect('active-activity-changed',
self._cur_activity_changed_cb)
+ bundle_registry = bundleregistry.get_registry()
+ bundle_registry.connect('bundle-added', self._bundle_added_cb)
+
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(_DBUS_SERVICE, bus=bus)
dbus.service.Object.__init__(self, bus_name, _DBUS_PATH)
@@ -121,6 +124,10 @@ class ShellService(dbus.service.Object):
return result
+ @dbus.service.signal(_DBUS_ACTIVITY_REGISTRY_IFACE, signature="a{sv}")
+ def ActivityAdded(self, activity_info):
+ pass
+
@dbus.service.signal(_DBUS_OWNER_IFACE, signature="s")
def ColorChanged(self, color):
pass
@@ -158,3 +165,7 @@ class ShellService(dbus.service.Object):
'icon': bundle.get_icon(),
'service_name': bundle.get_service_name(),
'path': bundle.get_path()}
+
+ def _bundle_added_cb(self, bundle_registry, bundle):
+ self.ActivityAdded(self._bundle_to_dict(bundle))
+
diff --git a/sugar/activity/registry.py b/sugar/activity/registry.py
index 171f740..b19abee 100644
--- a/sugar/activity/registry.py
+++ b/sugar/activity/registry.py
@@ -15,6 +15,8 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
+import logging
+
import dbus
_SHELL_SERVICE = "org.laptop.Shell"
@@ -39,6 +41,11 @@ class ActivityRegistry(object):
bus = dbus.SessionBus()
bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH)
self._registry = dbus.Interface(bus_object, _REGISTRY_IFACE)
+ self._registry.connect_to_signal('ActivityAdded', self._activity_added_cb)
+
+ # Two caches fo saving some travel across dbus.
+ self._service_name_to_activity_info = {}
+ self._mime_type_to_activities = {}
def _convert_info_list(self, info_list):
result = []
@@ -49,16 +56,33 @@ class ActivityRegistry(object):
return result
def get_activity(self, service_name):
+ if self._service_name_to_activity_info.has_key(service_name):
+ return self._service_name_to_activity_info[service_name]
+
info_dict = self._registry.GetActivity(service_name)
- return _activity_info_from_dict(info_dict)
+ activity_info = _activity_info_from_dict(info_dict)
+
+ self._service_name_to_activity_info[service_name] = activity_info
+ return activity_info
def find_activity(self, name):
info_list = self._registry.FindActivity(name)
return self._convert_info_list(info_list)
def get_activities_for_type(self, mime_type):
+ if self._mime_type_to_activities.has_key(mime_type):
+ return self._mime_type_to_activities[mime_type]
+
info_list = self._registry.GetActivitiesForType(mime_type)
- return self._convert_info_list(info_list)
+ activities = self._convert_info_list(info_list)
+
+ self._mime_type_to_activities[mime_type] = activities
+ return activities
+
+ def _activity_added_cb(self, bundle):
+ logging.debug('ActivityRegistry._activity_added_cb: flushing caches')
+ self._service_name_to_activity_info.clear()
+ self._mime_type_to_activities.clear()
_registry = None
diff --git a/sugar/objects/objecttype.py b/sugar/objects/objecttype.py
index dd2da54..a819216 100644
--- a/sugar/objects/objecttype.py
+++ b/sugar/objects/objecttype.py
@@ -36,20 +36,39 @@ class ObjectType(object):
self.name = name
self.icon = icon
self.mime_types = mime_types
+
+ self._type_id_to_type = {}
+ self._mime_type_to_type = {}
class ObjectTypeRegistry(object):
def __init__(self):
bus = dbus.SessionBus()
bus_object = bus.get_object(_SERVICE, _PATH)
self._registry = dbus.Interface(bus_object, _IFACE)
+
+ # Two caches fo saving some travel across dbus.
+ self._type_id_to_type = {}
+ self._mime_type_to_type = {}
def get_type(self, type_id):
+ if self._type_id_to_type.has_key(type_id):
+ return self._type_id_to_type[type_id]
+
type_dict = self._registry.GetType(type_id)
- return _object_type_from_dict(type_dict)
+ object_type = _object_type_from_dict(type_dict)
+
+ self._type_id_to_type[type_id] = object_type
+ return object_type
def get_type_for_mime(self, mime_type):
+ if self._mime_type_to_type.has_key(mime_type):
+ return self._mime_type_to_type[mime_type]
+
type_dict = self._registry.GetTypeForMIME(mime_type)
- return _object_type_from_dict(type_dict)
+ object_type = _object_type_from_dict(type_dict)
+
+ self._mime_type_to_type[mime_type] = object_type
+ return object_type
_registry = None