Add signal listener functionality to the DS #1197 (silbe)

This commit is contained in:
Simon Schampijer 2010-01-24 17:53:32 +01:00
parent a6df826d33
commit e1d4afe13e
2 changed files with 27 additions and 9 deletions

View File

@ -30,6 +30,7 @@ from sugar.presence import presenceservice
from sugar.activity.activityhandle import ActivityHandle from sugar.activity.activityhandle import ActivityHandle
from sugar import util from sugar import util
from sugar import env from sugar import env
from sugar.datastore import datastore
from errno import EEXIST, ENOSPC from errno import EEXIST, ENOSPC
@ -42,10 +43,6 @@ _SHELL_SERVICE = "org.laptop.Shell"
_SHELL_PATH = "/org/laptop/Shell" _SHELL_PATH = "/org/laptop/Shell"
_SHELL_IFACE = "org.laptop.Shell" _SHELL_IFACE = "org.laptop.Shell"
_DS_SERVICE = "org.laptop.sugar.DataStore"
_DS_INTERFACE = "org.laptop.sugar.DataStore"
_DS_PATH = "/org/laptop/sugar/DataStore"
_ACTIVITY_FACTORY_INTERFACE = "org.laptop.ActivityFactory" _ACTIVITY_FACTORY_INTERFACE = "org.laptop.ActivityFactory"
# helper method to close all filedescriptors # helper method to close all filedescriptors
@ -211,13 +208,9 @@ class ActivityCreationHandler(gobject.GObject):
self._shell = dbus.Interface(bus_object, _SHELL_IFACE) self._shell = dbus.Interface(bus_object, _SHELL_IFACE)
if handle.activity_id is not None and handle.object_id is None: if handle.activity_id is not None and handle.object_id is None:
datastore = dbus.Interface(
bus.get_object(_DS_SERVICE, _DS_PATH), _DS_INTERFACE)
datastore.find({'activity_id': self._handle.activity_id}, datastore.find({'activity_id': self._handle.activity_id},
[],
reply_handler=self._find_object_reply_handler, reply_handler=self._find_object_reply_handler,
error_handler=self._find_object_error_handler, error_handler=self._find_object_error_handler)
byte_arrays=True)
else: else:
self._launch_activity() self._launch_activity()

View File

@ -33,6 +33,7 @@ import dbus.glib
from sugar import env from sugar import env
from sugar import mime from sugar import mime
from sugar import dispatch
DS_DBUS_SERVICE = "org.laptop.sugar.DataStore" DS_DBUS_SERVICE = "org.laptop.sugar.DataStore"
DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore" DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
@ -50,9 +51,33 @@ def _get_data_store():
_data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE, _data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE,
DS_DBUS_PATH), DS_DBUS_PATH),
DS_DBUS_INTERFACE) DS_DBUS_INTERFACE)
_data_store.connect_to_signal('Created', __datastore_created_cb)
_data_store.connect_to_signal('Deleted', __datastore_deleted_cb)
_data_store.connect_to_signal('Updated', __datastore_updated_cb)
return _data_store return _data_store
def __datastore_created_cb(object_id):
metadata = _get_data_store().get_properties(object_id, byte_arrays=True)
updated.send(None, object_id=object_id, metadata=metadata)
def __datastore_updated_cb(object_id):
metadata = _get_data_store().get_properties(object_id, byte_arrays=True)
updated.send(None, object_id=object_id, metadata=metadata)
def __datastore_deleted_cb(object_id):
deleted.send(None, object_id=object_id)
created = dispatch.Signal()
deleted = dispatch.Signal()
updated = dispatch.Signal()
_get_data_store()
class DSMetadata(gobject.GObject): class DSMetadata(gobject.GObject):
"""A representation of the metadata associated with a DS entry.""" """A representation of the metadata associated with a DS entry."""
__gsignals__ = { __gsignals__ = {