Ticket #1765: 1765_sync_ds_0.84.patch

File 1765_sync_ds_0.84.patch, 2.4 KB (added by erikos, 11 years ago)
  • src/sugar/datastore/datastore.py

    diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py
    index d174bd4..38ec8f3 100644
    a b import tempfile 
    2727import gobject
    2828import gconf
    2929import gio
     30import dbus
    3031
    3132from sugar import env
    3233from sugar.datastore import dbus_helpers
    3334from sugar import mime
    3435
     36DS_DBUS_SERVICE = "org.laptop.sugar.DataStore"
     37DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
     38DS_DBUS_PATH = "/org/laptop/sugar/DataStore"
     39
     40_data_store = None
     41
     42def _get_data_store():
     43    global _data_store
     44
     45    if not _data_store:
     46        _bus = dbus.SessionBus()
     47        _data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE,
     48                                                     DS_DBUS_PATH),
     49                                     DS_DBUS_INTERFACE)
     50    return _data_store
     51
     52
    3553class DSMetadata(gobject.GObject):
    3654    __gsignals__ = {
    3755        'updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
    class DSMetadata(gobject.GObject): 
    83101        else:
    84102            return default
    85103
     104    def update(self, properties):
     105        """Update all of the metadata"""
     106        for (key, value) in properties.items():
     107            self[key] = value
     108
     109
    86110class DSObject(object):
    87111    def __init__(self, object_id, metadata=None, file_path=None):
    88         self.object_id = object_id
     112        self.set_object_id(object_id)
    89113        self._metadata = metadata
    90114        self._file_path = file_path
    91115        self._destroyed = False
    92116        self._owns_file = False
    93117
     118    def get_object_id(self):
     119        return self._object_id
     120
     121    def set_object_id(self, object_id):
     122        if object_id is not None:
     123            _get_data_store().connect_to_signal('Updated',
     124                                                self.__object_updated_cb,
     125                                                arg0=object_id)
     126        self._object_id = object_id
     127
     128    object_id = property(get_object_id, set_object_id)
     129
     130    def __object_updated_cb(self, object_id):
     131        properties = _get_data_store().get_properties(self.object_id,
     132                                                      byte_arrays=True)
     133        self._metadata.update(properties)
     134
    94135    def get_metadata(self):
    95136        if self._metadata is None and not self.object_id is None:
    96137            metadata = DSMetadata(dbus_helpers.get_properties(self.object_id))