[rygel] core: Support sorting by essential item properties



commit 31bf9e34c6d78422a628bd996fde1a5b490bfafe
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Jul 26 21:49:11 2010 +0300

    core: Support sorting by essential item properties

 src/rygel/rygel-media-item.vala |   49 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/rygel-media-item.vala b/src/rygel/rygel-media-item.vala
index 439b875..b1b10ef 100644
--- a/src/rygel/rygel-media-item.vala
+++ b/src/rygel/rygel-media-item.vala
@@ -237,6 +237,24 @@ public class Rygel.MediaItem : MediaObject {
         return res;
     }
 
+    internal override int compare_by_property (MediaObject media_object,
+                                               string      property) {
+        var item = media_object as MediaItem;
+
+        switch (property) {
+        case "dc:creator":
+        case "dc:artist":
+        case "dc:author":
+            return this.compare_string_props (this.author, item.author);
+        case "upnp:album":
+            return this.compare_string_props (this.album, item.album);
+        case "dc:date":
+            return this.compare_by_date (item);
+        default:
+            return base.compare_by_property (item, property);
+        }
+    }
+
     private ProtocolInfo get_protocol_info (string? uri,
                                             string  protocol) {
         var protocol_info = new ProtocolInfo ();
@@ -285,4 +303,35 @@ public class Rygel.MediaItem : MediaObject {
             return scheme;
         }
     }
+
+    private int compare_by_date (MediaItem item) {
+        if (this.date == null) {
+            return -1;
+        } else if (item.date == null) {
+            return 1;
+        } else {
+            var tv1 = TimeVal ();
+            assert (tv1.from_iso8601 (this.date));
+
+            var tv2 = TimeVal ();
+            assert (tv2.from_iso8601 (item.date));
+
+            var ret = this.compare_long (tv1.tv_sec, tv2.tv_sec);
+            if (ret == 0) {
+                ret = this.compare_long (tv1.tv_usec, tv2.tv_usec);
+            }
+
+            return ret;
+        }
+    }
+
+    private int compare_long (long a, long b) {
+        if (a < b) {
+            return -1;
+        } else if (a > b) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
 }



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