Ticket #1358: 0001_Sync_metadata_with_activity_1358.patch

File 0001_Sync_metadata_with_activity_1358.patch, 1.8 KB (added by erikos, 9 years ago)

Sync the metadata with the activity

  • src/sugar/activity/activity.py

    diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py
    index d4892d0..710dde5 100644
    a b class Activity(Window, gtk.Container): 
    356356            # https://dev.laptop.org/ticket/3071
    357357            datastore.write(self._jobject)
    358358
     359        self._jobject.add_update_listener()
     360
    359361    def get_active(self):
    360362        return self._active
    361363
  • src/sugar/datastore/datastore.py

    diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py
    index 9502ad5..80dfc00 100644
    a b class DSMetadata(gobject.GObject): 
    129129        else:
    130130            return default
    131131
     132    def update(self, properties):
     133        """Update all of the metadata"""
     134        for (key, value) in properties.items():
     135            self[key] = value
     136
    132137
    133138class DSObject(object):
    134139    """A representation of a DS entry."""
    class DSObject(object): 
    140145        self._destroyed = False
    141146        self._owns_file = False
    142147
     148        if self.object_id is not None:
     149            self.add_update_listener()
     150
     151    def add_update_listener(self):
     152        _get_data_store().connect_to_signal('Updated',
     153                                            self.__object_updated_cb,
     154                                            arg0=self.object_id)
     155
     156    def __object_updated_cb(self, object_id):
     157        properties = _get_data_store().get_properties(self.object_id,
     158                                                      byte_arrays=True)
     159        self._metadata.update(properties)
     160
    143161    def get_metadata(self):
    144162        if self._metadata is None and not self.object_id is None:
    145163            properties = _get_data_store().get_properties(self.object_id)