[rygel] tracker: Container classes deal with item factories



commit bb12e5763423de60603b25c2c5c053f8ea507817
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Nov 30 19:52:33 2009 +0200

    tracker: Container classes deal with item factories
    
    Container classes should deal with item factories instead of categories.

 src/plugins/tracker/rygel-tracker-keywords.vala    |    3 +-
 .../tracker/rygel-tracker-metadata-values.vala     |   25 ++++++++-------
 .../tracker/rygel-tracker-root-container.vala      |   10 +++---
 .../tracker/rygel-tracker-search-container.vala    |   31 ++++++-------------
 4 files changed, 29 insertions(+), 40 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-keywords.vala b/src/plugins/tracker/rygel-tracker-keywords.vala
index 84f73e1..48043a2 100644
--- a/src/plugins/tracker/rygel-tracker-keywords.vala
+++ b/src/plugins/tracker/rygel-tracker-keywords.vala
@@ -31,12 +31,11 @@ using Gee;
 public class Rygel.TrackerKeywords : Rygel.TrackerMetadataValues {
     /* class-wide constants */
     private const string TITLE = "Tags";
-    private const string CATEGORY = "nmm:Photo";
     private const string[] KEY_CHAIN = { "nao:hasTag", "nao:prefLabel", null };
 
     public TrackerKeywords (string         id,
                             MediaContainer parent) {
-        base (id, parent, TITLE, CATEGORY, KEY_CHAIN);
+        base (id, parent, TITLE, new TrackerImageItemFactory (), KEY_CHAIN);
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-metadata-values.vala b/src/plugins/tracker/rygel-tracker-metadata-values.vala
index 2bd834c..62d6a57 100644
--- a/src/plugins/tracker/rygel-tracker-metadata-values.vala
+++ b/src/plugins/tracker/rygel-tracker-metadata-values.vala
@@ -34,7 +34,7 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
     private const string RESOURCES_PATH = "/org/freedesktop/Tracker1/Resources";
     private const string ITEM_VARIABLE = "?item";
 
-    private string category;
+    private TrackerItemFactory item_factory;
 
     // In tracker 0.7, we might don't get values of keys in place so you need a
     // chain of keys to reach to final destination. For instances:
@@ -43,14 +43,14 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
 
     private TrackerResourcesIface resources;
 
-    public TrackerMetadataValues (string         id,
-                                  MediaContainer parent,
-                                  string         title,
-                                  string         category,
-                                  string[]       key_chain) {
+    public TrackerMetadataValues (string             id,
+                                  MediaContainer     parent,
+                                  string             title,
+                                  TrackerItemFactory item_factory,
+                                  string[]           key_chain) {
         base (id, parent, title);
 
-        this.category = category;
+        this.item_factory = item_factory;
         this.key_chain = key_chain;
 
         try {
@@ -88,10 +88,11 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
                                                     false));
         }
 
-        mandatory.insert (0, new TrackerQueryTriplet (ITEM_VARIABLE,
-                                                      "a",
-                                                      this.category,
-                                                      false));
+        mandatory.insert (0, new TrackerQueryTriplet (
+                                        ITEM_VARIABLE,
+                                        "a",
+                                        this.item_factory.category,
+                                        false));
 
         // Variables to select from query
         var selected = new ArrayList<string> ();
@@ -136,7 +137,7 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
             var container = new TrackerSearchContainer (value,
                                                         this,
                                                         value,
-                                                        this.category,
+                                                        this.item_factory,
                                                         child_mandatory,
                                                         null);
 
diff --git a/src/plugins/tracker/rygel-tracker-root-container.vala b/src/plugins/tracker/rygel-tracker-root-container.vala
index d9ed139..5cef18c 100644
--- a/src/plugins/tracker/rygel-tracker-root-container.vala
+++ b/src/plugins/tracker/rygel-tracker-root-container.vala
@@ -37,17 +37,17 @@ public class Rygel.TrackerRootContainer : Rygel.SimpleContainer {
                                         "16",
                                         this,
                                         "Pictures",
-                                        TrackerImageItemFactory.CATEGORY));
+                                        new TrackerImageItemFactory ()));
         this.add_child (new TrackerSearchContainer (
                                         "14",
                                         this,
                                         "Music",
-                                        TrackerMusicItemFactory.CATEGORY));
+                                        new TrackerMusicItemFactory ()));
         this.add_child (new TrackerSearchContainer (
                                         "15",
                                         this,
                                         "Videos",
-                                        TrackerVideoItemFactory.CATEGORY));
+                                        new TrackerVideoItemFactory ()));
 
         var key_chain = new string[] { "nmm:performer",
                                        "nmm:artistName",
@@ -56,7 +56,7 @@ public class Rygel.TrackerRootContainer : Rygel.SimpleContainer {
                                         "17",
                                         this,
                                         "Artists",
-                                        TrackerMusicItemFactory.CATEGORY,
+                                        new TrackerMusicItemFactory (),
                                         key_chain));
 
         key_chain = new string[] { "nmm:musicAlbum", "nmm:albumTitle", null };
@@ -64,7 +64,7 @@ public class Rygel.TrackerRootContainer : Rygel.SimpleContainer {
                                         "18",
                                         this,
                                         "Albums",
-                                        TrackerMusicItemFactory.CATEGORY,
+                                        new TrackerMusicItemFactory (),
                                         key_chain));
 
         this.add_child (new TrackerKeywords ("19", this));
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index 279afc4..55d8c47 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -36,19 +36,19 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
     private const string ITEM_VARIABLE = "?item";
 
     public TrackerQuery query;
-    public string category;
+    public TrackerItemFactory item_factory;
 
     private TrackerResourcesIface resources;
 
     public TrackerSearchContainer (string                id,
                                    MediaContainer        parent,
                                    string                title,
-                                   string                category,
+                                   TrackerItemFactory    item_factory,
                                    TrackerQueryTriplets? mandatory = null,
                                    ArrayList<string>?    filters = null) {
         base (id, parent, title, 0);
 
-        this.category = category;
+        this.item_factory = item_factory;
 
         var variables = new ArrayList<string> ();
         variables.add (ITEM_VARIABLE);
@@ -62,7 +62,7 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
 
         our_mandatory.add (new TrackerQueryTriplet (ITEM_VARIABLE,
                                                     "a",
-                                                    category,
+                                                    item_factory.category,
                                                     false));
 
         var optional = new TrackerQueryTriplets ();
@@ -112,7 +112,7 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
             this.updated ();
         } catch (GLib.Error error) {
             critical ("error getting item count under category '%s': %s",
-                      this.category,
+                      this.item_factory.category,
                       error.message);
 
             return;
@@ -240,22 +240,11 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
                                     throws GLib.Error {
         var id = this.id + ":" + uri;
 
-        TrackerItemFactory factory;
-        if (this.category == TrackerVideoItemFactory.CATEGORY) {
-            factory = new TrackerVideoItemFactory ();
-        } else if (this.category == TrackerImageItemFactory.CATEGORY) {
-            factory = new TrackerImageItemFactory ();
-        } else if (this.category == TrackerMusicItemFactory.CATEGORY) {
-            factory = new TrackerMusicItemFactory ();
-        } else {
-            return null;
-        }
-
-        return factory.create (id,
-                               uri,
-                               this,
-                               null,
-                               metadata);
+        return this.item_factory.create (id,
+                                         uri,
+                                         this,
+                                         null,
+                                         metadata);
     }
 
     // Returns the URI and the ID of the parent this item belongs to, or null



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