[rygel] tracker: Introduce "Albums" and "Artists" containers



commit d11608396f84264bcf0357069eb8a7b2bd7bbf8a
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Sep 17 18:01:53 2009 +0300

    tracker: Introduce "Albums" and "Artists" containers
    
    Right now these containers just provide an empty container for each
    album or artist. Next step is to populate these containers.

 src/plugins/tracker/Makefile.am                    |    1 +
 .../tracker/rygel-tracker-metadata-values.vala     |  103 ++++++++++++++++++++
 .../tracker/rygel-tracker-root-container.vala      |    8 ++
 3 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/tracker/Makefile.am b/src/plugins/tracker/Makefile.am
index 4e89b13..da83cb3 100644
--- a/src/plugins/tracker/Makefile.am
+++ b/src/plugins/tracker/Makefile.am
@@ -12,6 +12,7 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
 librygel_media_tracker_la_SOURCES = \
 				    rygel-media-tracker.vala \
 				    rygel-tracker-root-container.vala \
+				    rygel-tracker-metadata-values.vala \
 				    rygel-tracker-category.vala \
 				    rygel-tracker-video-category.vala \
 				    rygel-tracker-music-category.vala \
diff --git a/src/plugins/tracker/rygel-tracker-metadata-values.vala b/src/plugins/tracker/rygel-tracker-metadata-values.vala
new file mode 100644
index 0000000..353d730
--- /dev/null
+++ b/src/plugins/tracker/rygel-tracker-metadata-values.vala
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
+ * Copyright (C) 2008 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali <zeenix gmail com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+using DBus;
+using Gee;
+
+/**
+ * Container listing possible values of a particuler Tracker metadata key.
+ */
+public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
+    /* class-wide constants */
+    private const string TRACKER_SERVICE = "org.freedesktop.Tracker";
+    private const string METADATA_PATH = "/org/freedesktop/Tracker/Metadata";
+    private const string METADATA_IFACE = "org.freedesktop.Tracker.Metadata";
+
+    private const string CATEGORY = "Files";
+
+    public dynamic DBus.Object metadata;
+
+    public string key;
+
+    public TrackerMetadataValues (string         key,
+                                  string         id,
+                                  MediaContainer parent,
+                                  string         title) {
+        base (id, parent, title);
+
+        this.key = key;
+
+        try {
+            this.create_proxies ();
+
+            var keys = new string[] { this.key };
+
+            /* FIXME: We need to hook to some tracker signals to keep
+             *        this field up2date at all times
+             */
+            this.metadata.GetUniqueValues (CATEGORY,
+                                           keys,
+                                           "",
+                                           true,
+                                           0,
+                                           -1,
+                                           on_get_unique_values_cb);
+        } catch (GLib.Error error) {
+            critical ("Failed to create to Session bus: %s\n",
+                      error.message);
+        }
+    }
+
+    private void on_get_unique_values_cb (string[][] search_result,
+                                          GLib.Error error) {
+        if (error != null) {
+            critical ("error getting all values for '%s': %s",
+                      this.key,
+                      error.message);
+
+            return;
+        }
+
+        /* Iterate through all the values */
+        for (uint i = 0; i < search_result.length; i++) {
+            string value = search_result[i][0];
+
+            var container = new SimpleContainer (value, this, value);
+
+            this.children.add (container);
+        }
+
+        this.child_count = this.children.size;
+        this.updated ();
+    }
+
+    private void create_proxies () throws GLib.Error {
+        DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
+
+        this.metadata = connection.get_object (TRACKER_SERVICE,
+                                               METADATA_PATH,
+                                               METADATA_IFACE);
+    }
+}
+
diff --git a/src/plugins/tracker/rygel-tracker-root-container.vala b/src/plugins/tracker/rygel-tracker-root-container.vala
index 4162ad0..8f1e2ba 100644
--- a/src/plugins/tracker/rygel-tracker-root-container.vala
+++ b/src/plugins/tracker/rygel-tracker-root-container.vala
@@ -42,6 +42,14 @@ public class Rygel.TrackerRootContainer : Rygel.SimpleContainer {
         this.children.add (new TrackerVideoCategory ("15",
                                                      this,
                                                      "Videos"));
+        this.children.add (new TrackerMetadataValues ("Audio:Artist",
+                                                      "17",
+                                                      this,
+                                                      "Artists"));
+        this.children.add (new TrackerMetadataValues ("Audio:Album",
+                                                      "18",
+                                                      this,
+                                                      "Albums"));
 
         // Now we know how many top-level containers we have
         this.child_count = this.children.size;



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