[rygel] tracker: Update containers on changes to subjects



commit a9023dac9c89818549546ed1b1f865792400c704
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Dec 23 16:05:26 2009 +0200

    tracker: Update containers on changes to subjects
    
    For the moment we are only doing this in MetadataValues but since all
    top-level containers are instances of MetadataValues (or subclass), we
    are safe.

 .../tracker/rygel-tracker-item-factory.vala        |    5 +++-
 .../tracker/rygel-tracker-metadata-values.vala     |   26 +++++++++++++++++--
 .../tracker/rygel-tracker-music-item-factory.vala  |    2 +-
 .../rygel-tracker-picture-item-factory.vala        |    2 +-
 .../tracker/rygel-tracker-search-container.vala    |    3 --
 .../tracker/rygel-tracker-video-item-factory.vala  |    2 +-
 6 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-item-factory.vala b/src/plugins/tracker/rygel-tracker-item-factory.vala
index acbb9c9..3f27f7a 100644
--- a/src/plugins/tracker/rygel-tracker-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-item-factory.vala
@@ -39,13 +39,16 @@ public abstract class Rygel.TrackerItemFactory {
 
     public string category;
     public string upnp_class;
+    public string resources_class_path;
 
     public ArrayList<ArrayList<string>> key_chains;
 
     public TrackerItemFactory (string category,
-                               string upnp_class) {
+                               string upnp_class,
+                               string resources_class_path) {
         this.category = category;
         this.upnp_class = upnp_class;
+        this.resources_class_path = resources_class_path;
 
         this.key_chains = new ArrayList<ArrayList<string>> ();
 
diff --git a/src/plugins/tracker/rygel-tracker-metadata-values.vala b/src/plugins/tracker/rygel-tracker-metadata-values.vala
index 7c9d4f9..315cfbb 100644
--- a/src/plugins/tracker/rygel-tracker-metadata-values.vala
+++ b/src/plugins/tracker/rygel-tracker-metadata-values.vala
@@ -48,6 +48,7 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
     public FilterFunc filter_func;
 
     private TrackerResourcesIface resources;
+    private TrackerResourcesClassIface resources_class;
 
     public TrackerMetadataValues (string             id,
                                   MediaContainer     parent,
@@ -78,9 +79,14 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
         }
 
         this.fetch_metadata_values.begin ();
+
+        this.hook_to_changes ();
     }
 
     private async void fetch_metadata_values () {
+        // First thing, clear the existing hierarchy, if any
+        this.clear ();
+
         int i;
         var mandatory = new TrackerQueryTriplets ();
 
@@ -123,9 +129,6 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
 
         string[,] values;
         try {
-            /* FIXME: We need to hook to some tracker signals to keep
-             *        this field up2date at all times
-             */
             values = yield query.execute (this.resources);
         } catch (DBus.Error error) {
             critical ("error getting all values for '%s': %s",
@@ -186,6 +189,23 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
         this.resources = connection.get_object (TRACKER_SERVICE,
                                                 RESOURCES_PATH)
                                                 as TrackerResourcesIface;
+        this.resources_class = connection.get_object (
+                                        TRACKER_SERVICE,
+                                        this.item_factory.resources_class_path)
+                                        as TrackerResourcesClassIface;
+    }
+
+    private void hook_to_changes () {
+        // For any changes in subjects, just recreate hierarchy
+        this.resources_class.subjects_added.connect ((subjects) => {
+            this.fetch_metadata_values.begin ();
+        });
+        this.resources_class.subjects_removed.connect ((subjects) => {
+            this.fetch_metadata_values.begin ();
+        });
+        this.resources_class.subjects_changed.connect ((before, after) => {
+            this.fetch_metadata_values.begin ();
+        });
     }
 
     private bool is_child_id_unique (string child_id) {
diff --git a/src/plugins/tracker/rygel-tracker-music-item-factory.vala b/src/plugins/tracker/rygel-tracker-music-item-factory.vala
index 99b4712..a10d2e3 100644
--- a/src/plugins/tracker/rygel-tracker-music-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-music-item-factory.vala
@@ -39,7 +39,7 @@ public class Rygel.TrackerMusicItemFactory : Rygel.TrackerItemFactory {
     private const string CATEGORY = "nmm:MusicPiece";
 
     public TrackerMusicItemFactory () {
-        base (CATEGORY, MediaItem.MUSIC_CLASS);
+        base (CATEGORY, MediaItem.MUSIC_CLASS, MUSIC_RESOURCES_CLASS_PATH);
 
         for (var i = this.key_chains.size; i < MusicMetadata.LAST_KEY; i++) {
             this.key_chains.add (new ArrayList<string> ());
diff --git a/src/plugins/tracker/rygel-tracker-picture-item-factory.vala b/src/plugins/tracker/rygel-tracker-picture-item-factory.vala
index 737b5a2..d5abebe 100644
--- a/src/plugins/tracker/rygel-tracker-picture-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-picture-item-factory.vala
@@ -37,7 +37,7 @@ public class Rygel.TrackerPictureItemFactory : Rygel.TrackerItemFactory {
     private const string CATEGORY = "nmm:Photo";
 
     public TrackerPictureItemFactory () {
-        base (CATEGORY, MediaItem.IMAGE_CLASS);
+        base (CATEGORY, MediaItem.IMAGE_CLASS, PHOTO_RESOURCES_CLASS_PATH);
 
         for (var i = this.key_chains.size; i < PictureMetadata.LAST_KEY; i++) {
             this.key_chains.add (new ArrayList<string> ());
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index a30d875..3224d01 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -96,9 +96,6 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
         try {
             this.create_proxies ();
 
-            /* FIXME: We need to hook to some tracker signals to keep
-             *        this field up2date at all times
-             */
             this.get_children_count.begin ();
         } catch (DBus.Error error) {
             critical ("Failed to connect to session bus: %s\n", error.message);
diff --git a/src/plugins/tracker/rygel-tracker-video-item-factory.vala b/src/plugins/tracker/rygel-tracker-video-item-factory.vala
index 680381e..cb1accf 100644
--- a/src/plugins/tracker/rygel-tracker-video-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-video-item-factory.vala
@@ -38,7 +38,7 @@ public class Rygel.TrackerVideoItemFactory : Rygel.TrackerItemFactory {
     private const string CATEGORY = "nmm:Video";
 
     public TrackerVideoItemFactory () {
-        base (CATEGORY, MediaItem.VIDEO_CLASS);
+        base (CATEGORY, MediaItem.VIDEO_CLASS, VIDEO_RESOURCES_CLASS_PATH);
 
         for (var i = this.key_chains.size; i < VideoMetadata.LAST_KEY; i++) {
             this.key_chains.add (new ArrayList<string> ());



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]