[rygel] server: Move properties up the hierarchy



commit f08c044e6d2e472e877f337b1404fa3621d2cec6
Author: Jens Georg <jensg openismus com>
Date:   Fri Oct 11 12:53:46 2013 +0200

    server: Move properties up the hierarchy
    
    Move artist, genre and album to MediaObject/AudioItem to make them available in
    containers and videos as well
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709723

 src/librygel-server/rygel-audio-item.vala   |   33 +++++++++++++++++++++++++++
 src/librygel-server/rygel-media-item.vala   |    9 +++++++
 src/librygel-server/rygel-media-object.vala |   17 ++++++++++++++
 src/librygel-server/rygel-music-item.vala   |   32 --------------------------
 4 files changed, 59 insertions(+), 32 deletions(-)
---
diff --git a/src/librygel-server/rygel-audio-item.vala b/src/librygel-server/rygel-audio-item.vala
index eff94a3..3854335 100644
--- a/src/librygel-server/rygel-audio-item.vala
+++ b/src/librygel-server/rygel-audio-item.vala
@@ -63,6 +63,8 @@ public class Rygel.AudioItem : MediaItem {
      */
     public int channels { get; set; default = -1; }
 
+    public string album { get; set; }
+
     public AudioItem (string         id,
                       MediaContainer parent,
                       string         title,
@@ -77,6 +79,37 @@ public class Rygel.AudioItem : MediaItem {
         return true;
     }
 
+    internal override void apply_didl_lite (DIDLLiteObject didl_object) {
+        this.album = didl_object.album;
+    }
+
+    internal override int compare_by_property (MediaObject media_object,
+                                               string      property) {
+        if (!(media_object is AudioItem)) {
+            return 1;
+        }
+
+        var item = media_object as AudioItem;
+        switch (property) {
+        case "upnp:album":
+            return this.compare_string_props (this.album, item.album);
+        default:
+            return base.compare_by_property (item, property);
+        }
+    }
+
+    internal override DIDLLiteObject? serialize (Serializer serializer,
+                                                 HTTPServer http_server)
+                                                 throws Error {
+        var didl_item = base.serialize (serializer, http_server);
+
+        if (this.album != null && this.album != "") {
+            didl_item.album = this.album;
+        }
+
+        return didl_item;
+    }
+
     internal override DIDLLiteResource add_resource
                                         (DIDLLiteObject didl_object,
                                          string?        uri,
diff --git a/src/librygel-server/rygel-media-item.vala b/src/librygel-server/rygel-media-item.vala
index 54cf6eb..8ce7bf9 100644
--- a/src/librygel-server/rygel-media-item.vala
+++ b/src/librygel-server/rygel-media-item.vala
@@ -234,6 +234,15 @@ public abstract class Rygel.MediaItem : MediaObject {
             didl_item.update_id = this.object_update_id;
         }
 
+        if (this.artist != null && this.artist != "") {
+            var contributor = didl_item.add_artist ();
+            contributor.name = this.artist;
+        }
+
+        if (this.genre != null && this.genre != "") {
+            didl_item.genre = this.genre;
+        }
+
         /* We list proxy/transcoding resources first instead of original URIs
          * because some crappy MediaRenderer/ControlPoint implemenation out
          * there just choose the first one in the list instead of the one they
diff --git a/src/librygel-server/rygel-media-object.vala b/src/librygel-server/rygel-media-object.vala
index 43df421..29659e1 100644
--- a/src/librygel-server/rygel-media-object.vala
+++ b/src/librygel-server/rygel-media-object.vala
@@ -47,6 +47,9 @@ public abstract class Rygel.MediaObject : GLib.Object {
     public uint64 modified { get; set; }
     public uint object_update_id { get; set; }
 
+    public string artist { get; set; }
+    public string genre { get; set; }
+
     //TODO: { get; private set; } or, even better,
     // add virtual set_uri in Object and make add_uri() in Item into set_uri()
     // and make the uri property single-value.
@@ -203,6 +206,8 @@ public abstract class Rygel.MediaObject : GLib.Object {
 
     internal virtual void apply_didl_lite (DIDLLiteObject didl_object) {
         this.title = didl_object.title;
+        this.artist = this.get_first (didl_object.get_artists ());
+        this.genre = didl_object.genre;
     }
 
     // Recursively drop attributes of a certain namespace from a node.
@@ -272,6 +277,10 @@ public abstract class Rygel.MediaObject : GLib.Object {
         case "upnp:class":
             return this.compare_string_props (this.upnp_class,
                                               media_object.upnp_class);
+        case "dc:artist":
+            return this.compare_string_props (this.artist, media_object.artist);
+        case "upnp:genre":
+            return this.compare_string_props (this.genre, media_object.genre);
         case "dc:creator":
             return this.compare_string_props (this.creator,
                                               media_object.creator);
@@ -374,4 +383,12 @@ public abstract class Rygel.MediaObject : GLib.Object {
             return 0;
         }
     }
+
+    private string get_first (GLib.List<DIDLLiteContributor>? contributors) {
+        if (contributors != null) {
+            return contributors.data.name;
+        }
+
+        return "";
+    }
 }
diff --git a/src/librygel-server/rygel-music-item.vala b/src/librygel-server/rygel-music-item.vala
index 73b5a5b..a26d018 100644
--- a/src/librygel-server/rygel-music-item.vala
+++ b/src/librygel-server/rygel-music-item.vala
@@ -32,9 +32,6 @@ using GUPnP;
 public class Rygel.MusicItem : AudioItem {
     public new const string UPNP_CLASS = "object.item.audioItem.musicTrack";
 
-    public string artist { get; set; }
-    public string album { get; set; }
-    public string genre { get; set; }
     public int track_number { get; set; default = -1; }
 
     public Thumbnail album_art { get; set; }
@@ -85,10 +82,6 @@ public class Rygel.MusicItem : AudioItem {
         var item = media_object as MusicItem;
 
         switch (property) {
-        case "dc:artist":
-            return this.compare_string_props (this.artist, item.artist);
-        case "upnp:album":
-            return this.compare_string_props (this.album, item.album);
         case "upnp:originalTrackNumber":
              return this.compare_int_props (this.track_number,
                                             item.track_number);
@@ -100,10 +93,7 @@ public class Rygel.MusicItem : AudioItem {
     internal override void apply_didl_lite (DIDLLiteObject didl_object) {
         base.apply_didl_lite (didl_object);
 
-        this.artist = this.get_first (didl_object.get_artists ());
         this.track_number = didl_object.track_number;
-        this.album = didl_object.album;
-        this.genre = didl_object.genre;
         // TODO: Not sure about it.
         //this.album_art.uri = didl_object.album_art
     }
@@ -113,23 +103,10 @@ public class Rygel.MusicItem : AudioItem {
                                                  throws Error {
         var didl_item = base.serialize (serializer, http_server);
 
-        if (this.artist != null && this.artist != "") {
-            var contributor = didl_item.add_artist ();
-            contributor.name = this.artist;
-        }
-
         if (this.track_number >= 0) {
             didl_item.track_number = this.track_number;
         }
 
-        if (this.album != null && this.album != "") {
-            didl_item.album = this.album;
-        }
-
-        if (this.genre != null && this.genre != "") {
-            didl_item.genre = this.genre;
-        }
-
         if (didl_item.album_art != null) {
             didl_item.album_art = MediaItem.address_regex.replace_literal
                                         (didl_item.album_art,
@@ -157,13 +134,4 @@ public class Rygel.MusicItem : AudioItem {
                                                               null);
         }
     }
-
-    private string get_first (GLib.List<DIDLLiteContributor>? contributors) {
-        if (contributors != null) {
-            return contributors.data.name;
-        }
-
-        return "";
-    }
-
 }


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