2007-08-08 18:08:07 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
# Copyright (C) 2007 One Laptop Per Child
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
import dbus
|
|
|
|
import dbus.service
|
|
|
|
|
|
|
|
import bundleregistry
|
|
|
|
|
|
|
|
_ACTIVITY_REGISTRY_SERVICE_NAME = 'org.laptop.ActivityRegistry'
|
|
|
|
_ACTIVITY_REGISTRY_IFACE = 'org.laptop.ActivityRegistry'
|
|
|
|
_ACTIVITY_REGISTRY_PATH = '/org/laptop/ActivityRegistry'
|
|
|
|
|
|
|
|
class ActivityRegistry(dbus.service.Object):
|
|
|
|
def __init__(self):
|
|
|
|
bus = dbus.SessionBus()
|
|
|
|
bus_name = dbus.service.BusName(_ACTIVITY_REGISTRY_SERVICE_NAME, bus=bus)
|
|
|
|
dbus.service.Object.__init__(self, bus_name, _ACTIVITY_REGISTRY_PATH)
|
|
|
|
|
|
|
|
bundle_registry = bundleregistry.get_registry()
|
|
|
|
bundle_registry.connect('bundle-added', self._bundle_added_cb)
|
2007-10-04 21:59:23 +02:00
|
|
|
bundle_registry.connect('bundle-removed', self._bundle_removed_cb)
|
2007-08-08 18:08:07 +02:00
|
|
|
|
|
|
|
@dbus.service.method(_ACTIVITY_REGISTRY_IFACE,
|
|
|
|
in_signature='s', out_signature='b')
|
|
|
|
def AddBundle(self, bundle_path):
|
|
|
|
'''Register the activity bundle with the global registry
|
|
|
|
|
2007-10-04 21:18:51 +02:00
|
|
|
bundle_path -- path to the root directory of the activity bundle,
|
2007-08-08 18:08:07 +02:00
|
|
|
that is, the directory with activity/activity.info as a
|
|
|
|
child of the directory.
|
|
|
|
|
|
|
|
The bundleregistry.BundleRegistry is responsible for setting
|
|
|
|
up a set of d-bus service mappings for each available activity.
|
|
|
|
'''
|
|
|
|
registry = bundleregistry.get_registry()
|
|
|
|
return registry.add_bundle(bundle_path)
|
|
|
|
|
2007-10-04 21:59:23 +02:00
|
|
|
@dbus.service.method(_ACTIVITY_REGISTRY_IFACE,
|
|
|
|
in_signature='s', out_signature='b')
|
|
|
|
def RemoveBundle(self, bundle_path):
|
|
|
|
'''Unregister the activity bundle with the global registry
|
|
|
|
|
|
|
|
bundle_path -- path to the activity bundle root directory
|
|
|
|
'''
|
|
|
|
registry = bundleregistry.get_registry()
|
|
|
|
return registry.remove_bundle(bundle_path)
|
|
|
|
|
2007-08-09 18:10:16 +02:00
|
|
|
@dbus.service.method(_ACTIVITY_REGISTRY_IFACE,
|
|
|
|
in_signature='', out_signature='aa{sv}')
|
|
|
|
def GetActivities(self):
|
|
|
|
result = []
|
|
|
|
registry = bundleregistry.get_registry()
|
|
|
|
for bundle in registry:
|
|
|
|
result.append(self._bundle_to_dict(bundle))
|
|
|
|
return result
|
|
|
|
|
2007-08-08 18:08:07 +02:00
|
|
|
@dbus.service.method(_ACTIVITY_REGISTRY_IFACE,
|
|
|
|
in_signature='s', out_signature='a{sv}')
|
|
|
|
def GetActivity(self, service_name):
|
|
|
|
registry = bundleregistry.get_registry()
|
|
|
|
bundle = registry.get_bundle(service_name)
|
|
|
|
if not bundle:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
return self._bundle_to_dict(bundle)
|
|
|
|
|
|
|
|
@dbus.service.method(_ACTIVITY_REGISTRY_IFACE,
|
|
|
|
in_signature='s', out_signature='aa{sv}')
|
|
|
|
def FindActivity(self, name):
|
|
|
|
result = []
|
|
|
|
key = name.lower()
|
|
|
|
|
|
|
|
for bundle in bundleregistry.get_registry():
|
|
|
|
name = bundle.get_name().lower()
|
|
|
|
service_name = bundle.get_service_name().lower()
|
|
|
|
if name.find(key) != -1 or service_name.find(key) != -1:
|
|
|
|
result.append(self._bundle_to_dict(bundle))
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
@dbus.service.method(_ACTIVITY_REGISTRY_IFACE,
|
|
|
|
in_signature='s', out_signature='aa{sv}')
|
|
|
|
def GetActivitiesForType(self, mime_type):
|
|
|
|
result = []
|
|
|
|
registry = bundleregistry.get_registry()
|
|
|
|
for bundle in registry.get_activities_for_type(mime_type):
|
|
|
|
result.append(self._bundle_to_dict(bundle))
|
|
|
|
return result
|
|
|
|
|
|
|
|
@dbus.service.signal(_ACTIVITY_REGISTRY_IFACE, signature='a{sv}')
|
|
|
|
def ActivityAdded(self, activity_info):
|
|
|
|
pass
|
|
|
|
|
2007-10-04 21:59:23 +02:00
|
|
|
@dbus.service.signal(_ACTIVITY_REGISTRY_IFACE, signature='a{sv}')
|
|
|
|
def ActivityRemoved(self, activity_info):
|
|
|
|
pass
|
|
|
|
|
2007-08-08 18:08:07 +02:00
|
|
|
def _bundle_to_dict(self, bundle):
|
|
|
|
return {'name': bundle.get_name(),
|
|
|
|
'icon': bundle.get_icon(),
|
|
|
|
'service_name': bundle.get_service_name(),
|
2007-08-09 18:10:16 +02:00
|
|
|
'path': bundle.get_path(),
|
|
|
|
'show_launcher': bundle.get_show_launcher()}
|
2007-08-08 18:08:07 +02:00
|
|
|
|
|
|
|
def _bundle_added_cb(self, bundle_registry, bundle):
|
|
|
|
self.ActivityAdded(self._bundle_to_dict(bundle))
|
|
|
|
|
2007-10-04 21:59:23 +02:00
|
|
|
def _bundle_removed_cb(self, bundle_registry, bundle):
|
|
|
|
self.ActivityRemoved(self._bundle_to_dict(bundle))
|
|
|
|
|
2007-08-08 18:08:07 +02:00
|
|
|
_instance = None
|
|
|
|
|
|
|
|
def get_instance():
|
|
|
|
global _instance
|
|
|
|
if not _instance:
|
|
|
|
_instance = ActivityRegistry()
|
|
|
|
return _instance
|
|
|
|
|