From d150ac40cc3a6a22111131799528c8090a356ee1 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 29 Oct 2006 18:05:09 +0000 Subject: More work on bundles support --- diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py index cb8747b..350666d 100644 --- a/shell/model/ShellModel.py +++ b/shell/model/ShellModel.py @@ -15,6 +15,8 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from sugar.presence import PresenceService +from sugar.activity.bundleregistry import BundleRegistry +from sugar import env from model.Friends import Friends from model.MeshModel import MeshModel from model.Owner import ShellOwner @@ -28,9 +30,16 @@ class ShellModel: self._owner = ShellOwner() self._owner.announce() + self._friends = Friends() self._mesh = MeshModel() + self._bundle_registry = BundleRegistry() + self._bundle_registry.add_search_path(env.get_bundles_path()) + + def get_bundle_registry(self): + return self._bundle_registry + def get_mesh(self): return self._mesh diff --git a/shell/view/frame/ActivitiesBox.py b/shell/view/frame/ActivitiesBox.py index 985ee8c..06f102c 100644 --- a/shell/view/frame/ActivitiesBox.py +++ b/shell/view/frame/ActivitiesBox.py @@ -55,14 +55,18 @@ class ActivitiesBox(hippo.CanvasBox): hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_HORIZONTAL) self._shell = shell + self._shell_model = self._shell.get_model() self._invite_to_item = {} - self._invites = self._shell.get_model().get_invites() + self._invites = self._shell_model.get_invites() registry = conf.get_activity_registry() for activity in registry.list_activities(): if activity.get_show_launcher(): self.add_activity(activity) + for bundle in self._shell_model.get_bundle_registry(): + self.add_activity(bundle) + for invite in self._invites: self.add_invite(invite) self._invites.connect('invite-added', self._invite_added_cb) diff --git a/sugar/activity/__init__.py b/sugar/activity/__init__.py index cc34df2..959c0a1 100644 --- a/sugar/activity/__init__.py +++ b/sugar/activity/__init__.py @@ -16,10 +16,3 @@ def get_default_type(activity_type): splitted_id = activity_type.split('.') splitted_id.reverse() return '_' + '_'.join(splitted_id) + '._udp' - -from sugar.activity.bundleregistry import BundleRegistry - -_bundle_registry = BundleRegistry() - -def get_bundle_registry(): - return _bundle_registry diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py index ddf968f..07ff544 100644 --- a/sugar/activity/bundle.py +++ b/sugar/activity/bundle.py @@ -41,7 +41,7 @@ class Bundle: def get_service_name(self): """Get the activity service name""" - return self._id + return self._service_name def get_icon(self): """Get the activity icon name""" diff --git a/sugar/activity/bundleregistry.py b/sugar/activity/bundleregistry.py index f28b681..4acf6dd 100644 --- a/sugar/activity/bundleregistry.py +++ b/sugar/activity/bundleregistry.py @@ -1,3 +1,5 @@ +import os + from sugar.activity.bundle import Bundle class BundleRegistry: @@ -14,19 +16,23 @@ class BundleRegistry: else: return None - def append_search_path(self, path): - """Append a directory to the bundles search path""" + def add_search_path(self, path): + """Add a directory to the bundles search path""" self._search_path.append(path) self._scan_directory(path) def __iter__(self): - return self._bundles.values() + return self._bundles.values().__iter__() def _scan_directory(self, path): - for bundle_dir in os.listdir(path): - if os.path.isdir(bundle_dir): - info_path = os.path.join(bundle_dir, activity_info) - if os.path.isfile(info_path): - bundle = Bundle(info_path) - if bundle.is_valid(): - self._bundles.append(bundle) + for f in os.listdir(path): + bundle_dir = os.path.join(path, f) + if os.path.isdir(bundle_dir) and bundle_dir.endswith('.activity'): + self._add_bundle(bundle_dir) + + def _add_bundle(self, bundle_dir): + info_path = os.path.join(bundle_dir, 'activity.info') + if os.path.isfile(info_path): + bundle = Bundle(info_path) + if bundle.is_valid(): + self._bundles[bundle.get_service_name()] = bundle diff --git a/sugar/env.py b/sugar/env.py index 65081fc..2109c2d 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -53,3 +53,6 @@ def get_services_dir(): def get_dbus_config(): return sugar_dbus_config + +def get_bundles_path(): + return os.path.join(get_profile_path(), 'bundles') -- cgit v0.9.1