tracker: Add title-based hierarchies
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 8 Dec 2010 16:23:44 +0000 (18:23 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 8 Dec 2010 16:36:22 +0000 (18:36 +0200)
Under each category container, add a container providing a title-based
hierarchy: One container for each unique starting character of all the titles
available for the contegory in question. Something like this:

Music
  |
  |----> Genre
          |..
  ^
  |----> Titles
          |
          |---> A
                |
                |--> Alpha
                |--> alright
          ^
          |---> B
                |
                |--> Bravo
                |--> brave
                |..
          ^
  ^       |..
  |..

src/plugins/tracker/Makefile.am
src/plugins/tracker/rygel-tracker-music.vala
src/plugins/tracker/rygel-tracker-pictures.vala
src/plugins/tracker/rygel-tracker-titles.vala [new file with mode: 0644]
src/plugins/tracker/rygel-tracker-videos.vala

index f93b5af..2c78a5c 100644 (file)
@@ -19,6 +19,7 @@ librygel_media_tracker_la_SOURCES = rygel-tracker-root-container.vala \
                                    rygel-tracker-metadata-values.vala \
                                    rygel-tracker-tags.vala \
                                    rygel-tracker-years.vala \
+                                   rygel-tracker-titles.vala \
                                    rygel-tracker-albums.vala \
                                    rygel-tracker-artists.vala \
                                    rygel-tracker-genre.vala \
index 2a82201..751b2a0 100644 (file)
@@ -34,6 +34,7 @@ public class Rygel.Tracker.Music : CategoryContainer {
         this.add_child (new Albums (this));
         this.add_child (new Genre (this));
         this.add_child (new Tags (this, item_factory));
+        this.add_child (new Titles (this, this.item_factory));
     }
 }
 
index 42e761b..09776e6 100644 (file)
@@ -34,6 +34,7 @@ public class Rygel.Tracker.Pictures : CategoryContainer {
 
         this.add_child (new Tags (this, this.item_factory));
         this.add_child (new Years (this, this.item_factory));
+        this.add_child (new Titles (this, this.item_factory));
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-titles.vala b/src/plugins/tracker/rygel-tracker-titles.vala
new file mode 100644 (file)
index 0000000..684d9e3
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
+ *                               <zeeshan.ali@nokia.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.
+ */
+
+/**
+ * Container providing a title-based hierarchy.
+ *
+ * Under each category container, add a container providing a title-based
+ * hierarchy: One container for each unique starting character of all the titles
+ * available for the contegory in question. Something like this:
+ *
+ * Music
+ *   |
+ *   |----> Genre
+ *           |..
+ *   ^
+ *   |----> Titles
+ *           |
+ *           |---> A
+ *                 |
+ *                 |--> Alpha
+ *                 |--> alright
+ *           ^
+ *           |---> B
+ *                 |
+ *                 |--> Bravo
+ *                 |--> brave
+ *                 |..
+ *           ^
+ *   ^       |..
+ *   |..
+ */
+public class Rygel.Tracker.Titles : MetadataValues {
+    private const string[] KEY_CHAIN = { "nie:title", null };
+
+    public Titles (MediaContainer parent, ItemFactory item_factory) {
+        base (parent.id + "Titles",
+              parent,
+              _("Titles"),
+              item_factory,
+              KEY_CHAIN);
+    }
+
+    // The parent class will only create a child container for each unique
+    // title this method returns so we don't need to worry about multiple
+    // containers being created for each letter.
+    protected override string? create_title_for_value (string value) {
+        var c = value.get_char_validated ();
+
+        if (unlikely (c < 0)) {
+            return null;
+        }
+
+        return c.to_string ().up ();
+    }
+
+    protected override string create_filter (string variable, string value) {
+        var title = this.create_title_for_value (value);
+
+        return "regex(" + variable + ", \"^" + title + "\", \"i\")";
+    }
+}
index 9ae8fec..c0be593 100644 (file)
@@ -32,6 +32,7 @@ public class Rygel.Tracker.Videos : CategoryContainer {
 
         this.add_child (new Tags (this, this.item_factory));
         this.add_child (new Years (this, this.item_factory));
+        this.add_child (new Titles (this, this.item_factory));
     }
 }