From e1d4afe13e3b49f01083a00ca4b83cc4011829d8 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Sun, 24 Jan 2010 17:53:32 +0100 Subject: [PATCH] Add signal listener functionality to the DS #1197 (silbe) --- src/sugar/activity/activityfactory.py | 11 ++--------- src/sugar/datastore/datastore.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/sugar/activity/activityfactory.py b/src/sugar/activity/activityfactory.py index c1955723..eda7d9a9 100644 --- a/src/sugar/activity/activityfactory.py +++ b/src/sugar/activity/activityfactory.py @@ -30,6 +30,7 @@ from sugar.presence import presenceservice from sugar.activity.activityhandle import ActivityHandle from sugar import util from sugar import env +from sugar.datastore import datastore from errno import EEXIST, ENOSPC @@ -42,10 +43,6 @@ _SHELL_SERVICE = "org.laptop.Shell" _SHELL_PATH = "/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" # helper method to close all filedescriptors @@ -211,13 +208,9 @@ class ActivityCreationHandler(gobject.GObject): self._shell = dbus.Interface(bus_object, _SHELL_IFACE) 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}, - [], reply_handler=self._find_object_reply_handler, - error_handler=self._find_object_error_handler, - byte_arrays=True) + error_handler=self._find_object_error_handler) else: self._launch_activity() diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py index cea2265d..66e29ed7 100644 --- a/src/sugar/datastore/datastore.py +++ b/src/sugar/datastore/datastore.py @@ -33,6 +33,7 @@ import dbus.glib from sugar import env from sugar import mime +from sugar import dispatch DS_DBUS_SERVICE = "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, DS_DBUS_PATH), 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 +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): """A representation of the metadata associated with a DS entry.""" __gsignals__ = {