[rygel] tracker: Add TrackerKeywords



commit 89dfd2ae624c3f195942a2fdee8fe9064cf2884f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Sep 21 00:39:48 2009 +0300

    tracker: Add TrackerKeywords
    
    A new container that lists all the available tags in the Tracker DB. For
    each tag, it creates a container that lists all items with that tag.

 src/plugins/tracker/Makefile.am                    |    1 +
 src/plugins/tracker/rygel-tracker-keywords.vala    |   95 ++++++++++++++++++++
 .../tracker/rygel-tracker-root-container.vala      |    1 +
 3 files changed, 97 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/tracker/Makefile.am b/src/plugins/tracker/Makefile.am
index 85ffbc7..7cee5c0 100644
--- a/src/plugins/tracker/Makefile.am
+++ b/src/plugins/tracker/Makefile.am
@@ -13,6 +13,7 @@ librygel_media_tracker_la_SOURCES = \
 				    rygel-media-tracker.vala \
 				    rygel-tracker-root-container.vala \
 				    rygel-tracker-metadata-values.vala \
+				    rygel-tracker-keywords.vala \
 				    rygel-tracker-search-container.vala \
 				    rygel-tracker-search-result.vala \
 				    rygel-tracker-get-metadata-result.vala \
diff --git a/src/plugins/tracker/rygel-tracker-keywords.vala b/src/plugins/tracker/rygel-tracker-keywords.vala
new file mode 100644
index 0000000..208cbd8
--- /dev/null
+++ b/src/plugins/tracker/rygel-tracker-keywords.vala
@@ -0,0 +1,95 @@
+/*
+ * 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 all available keywords (tags) in Tracker DB.
+ */
+public class Rygel.TrackerKeywords : Rygel.SimpleContainer {
+    /* class-wide constants */
+    private const string TRACKER_SERVICE = "org.freedesktop.Tracker";
+    private const string KEYWORDS_PATH = "/org/freedesktop/Tracker/Keywords";
+    private const string KEYWORDS_IFACE = "org.freedesktop.Tracker.Keywords";
+
+    private const string SERVICE = "Files";
+    private const string TITLE = "Tags";
+
+    public dynamic DBus.Object keywords;
+
+    public TrackerKeywords (string         id,
+                            MediaContainer parent) {
+        base (id, parent, TITLE);
+
+        try {
+            this.create_proxies ();
+
+            /* FIXME: We need to hook to some tracker signals to keep
+             *        this field up2date at all times
+             */
+            this.keywords.GetList (SERVICE, on_get_keywords_cb);
+        } catch (GLib.Error error) {
+            critical ("Failed to create to Session bus: %s\n",
+                      error.message);
+        }
+    }
+
+    private void on_get_keywords_cb (string[][] keywords_list,
+                                     GLib.Error error) {
+        if (error != null) {
+            critical ("error getting all keywords: %s", error.message);
+
+            return;
+        }
+
+        /* Iterate through all the values */
+        for (uint i = 0; i < keywords_list.length; i++) {
+            string keyword = keywords_list[i][0];
+
+            var keywords = new string[] { keyword };
+
+            var container = new TrackerSearchContainer (keyword,
+                                                        this,
+                                                        keyword,
+                                                        SERVICE,
+                                                        "",
+                                                        keywords);
+
+            this.children.add (container);
+        }
+
+        this.child_count = this.children.size;
+        this.updated ();
+    }
+
+    private void create_proxies () throws DBus.Error {
+        DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
+
+        this.keywords = connection.get_object (TRACKER_SERVICE,
+                                               KEYWORDS_PATH,
+                                               KEYWORDS_IFACE);
+    }
+}
+
diff --git a/src/plugins/tracker/rygel-tracker-root-container.vala b/src/plugins/tracker/rygel-tracker-root-container.vala
index cc308c0..612364b 100644
--- a/src/plugins/tracker/rygel-tracker-root-container.vala
+++ b/src/plugins/tracker/rygel-tracker-root-container.vala
@@ -59,6 +59,7 @@ public class Rygel.TrackerRootContainer : Rygel.SimpleContainer {
                                                       "18",
                                                       this,
                                                       "Albums"));
+        this.children.add (new TrackerKeywords ("19", this));
 
         // 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]