tracker: Provide 'Years' hierarchy
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Fri, 4 Dec 2009 18:05:22 +0000 (20:05 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Fri, 4 Dec 2009 18:05:22 +0000 (20:05 +0200)
Enable user to browse pictures and videos by year of creation.

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

index ac36bcd..076cbf4 100644 (file)
@@ -17,6 +17,7 @@ librygel_media_tracker_la_SOURCES = \
                                    rygel-tracker-pictures.vala \
                                    rygel-tracker-metadata-values.vala \
                                    rygel-tracker-tags.vala \
+                                   rygel-tracker-years.vala \
                                    rygel-tracker-search-container.vala \
                                    rygel-tracker-query.vala \
                                    rygel-tracker-query-triplet.vala \
index 86222a0..dcba0ae 100644 (file)
@@ -27,6 +27,8 @@ using Gee;
  * Container listing Pictures content hierarchy.
  */
 public class Rygel.TrackerPictures : Rygel.SimpleContainer {
+    private const string[] KEY_CHAIN = { "nie:contentCreated", null };
+
     public TrackerPictures (string         id,
                             MediaContainer parent,
                             string         title) {
@@ -35,6 +37,7 @@ public class Rygel.TrackerPictures : Rygel.SimpleContainer {
         var item_factory = new TrackerPictureItemFactory ();
 
         this.add_child (new TrackerTags ("19", this, item_factory));
+        this.add_child (new TrackerYears ("22", this, item_factory));
     }
 }
 
index bc798de..0834aac 100644 (file)
@@ -35,6 +35,7 @@ public class Rygel.TrackerVideos : Rygel.SimpleContainer {
         var item_factory = new TrackerVideoItemFactory ();
 
         this.add_child (new TrackerTags ("20", this, item_factory));
+        this.add_child (new TrackerYears ("23", this, item_factory));
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-years.vala b/src/plugins/tracker/rygel-tracker-years.vala
new file mode 100644 (file)
index 0000000..975fdd7
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+using Gee;
+
+/**
+ * Container listing content hierarchy by year of creation.
+ */
+public class Rygel.TrackerYears : Rygel.TrackerMetadataValues {
+    private const string[] KEY_CHAIN = { "nie:contentCreated", null };
+
+    public TrackerYears (string             id,
+                         MediaContainer     parent,
+                         TrackerItemFactory item_factory) {
+        base (id,
+              parent,
+              "Year",
+              item_factory,
+              KEY_CHAIN,
+              year_id_func,
+              year_id_func,
+              year_filter_func);
+    }
+
+    private static string year_id_func (string value) {
+        return value.ndup (4);
+    }
+
+    private static string year_filter_func (string variable, string value) {
+        var year = year_id_func (value);
+        var next_year = (year.to_int () + 1).to_string ();
+
+        year += "-01-01T00:00:00Z";
+        next_year += "-01-01T00:00:00Z";
+
+        return variable + " > \"" + year + "\" && " +
+               variable + " < \"" + next_year + "\"";
+    }
+}
+