From 31bf9e34c6d78422a628bd996fde1a5b490bfafe Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Mon, 26 Jul 2010 21:49:11 +0300 Subject: [PATCH] core: Support sorting by essential item properties --- src/rygel/rygel-media-item.vala | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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; + } + } } -- 2.7.4