core: Add hacks for Panasonic TV
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Sun, 16 Oct 2011 22:47:03 +0000 (01:47 +0300)
committerJens Georg <mail@jensge.org>
Wed, 19 Oct 2011 06:55:17 +0000 (08:55 +0200)
Currently its just about lieing to the device that png's thumbnails are
jpegs.

https://bugzilla.gnome.org/show_bug.cgi?id=661336

src/rygel/Makefile.am
src/rygel/rygel-client-hacks.vala
src/rygel/rygel-panasonic-hacks.vala [new file with mode: 0644]

index 2ae265e..0308b71 100644 (file)
@@ -85,6 +85,7 @@ VAPI_SOURCE_FILES = \
        rygel-search.vala \
        rygel-client-hacks.vala \
        rygel-xbox-hacks.vala \
+       rygel-panasonic-hacks.vala \
        rygel-import-resource.vala \
        rygel-item-creator.vala \
        rygel-item-destroyer.vala \
index ae7c725..baf7380 100644 (file)
@@ -37,12 +37,20 @@ internal abstract class Rygel.ClientHacks : GLib.Object {
 
     public static ClientHacks create_for_action (ServiceAction action)
                                                  throws ClientHacksError {
-        return new XBoxHacks.for_action (action);
+        try {
+            return new XBoxHacks.for_action (action);
+        } catch {}
+
+        return new PanasonicHacks.for_action (action);
     }
 
     public static ClientHacks create_for_headers (MessageHeaders headers)
                                                   throws ClientHacksError {
-        return new XBoxHacks.for_headers (headers);
+        try {
+            return new XBoxHacks.for_headers (headers);
+        } catch {}
+
+        return new PanasonicHacks.for_headers (headers);
     }
 
     protected ClientHacks (string agent_pattern, MessageHeaders? headers = null)
diff --git a/src/rygel/rygel-panasonic-hacks.vala b/src/rygel/rygel-panasonic-hacks.vala
new file mode 100644 (file)
index 0000000..5a3a56f
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
+ *
+ * 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 Soup;
+using GUPnP;
+
+internal class Rygel.PanasonicHacks : ClientHacks {
+    private static string AGENT = ".*Panasonic MIL DLNA CP.*";
+
+    private static Regex mime_regex;
+    private static Regex dlna_regex;
+
+    static construct {
+        try {
+            mime_regex = new Regex ("png");
+            dlna_regex = new Regex ("PNG");
+        } catch (RegexError error) {
+            assert_not_reached ();
+        }
+    }
+
+    public PanasonicHacks () throws ClientHacksError, RegexError {
+        base (AGENT);
+    }
+
+    public PanasonicHacks.for_action (ServiceAction action)
+                                      throws ClientHacksError {
+        unowned MessageHeaders headers = action.get_message ().request_headers;
+        this.for_headers (headers);
+    }
+
+    public PanasonicHacks.for_headers (MessageHeaders headers)
+                                       throws ClientHacksError {
+        base (AGENT, headers);
+    }
+
+    public override void apply (MediaItem item) {
+        if (!(item is VisualItem)) {
+            return;
+        }
+
+        foreach (var thumbnail in (item as VisualItem).thumbnails) {
+            try {
+                thumbnail.mime_type = mime_regex.replace_literal
+                                        (thumbnail.mime_type, -1, 0, "jpeg");
+                thumbnail.dlna_profile = dlna_regex.replace_literal
+                                        (thumbnail.dlna_profile, -1, 0, "JPEG");
+            } catch (RegexError error) {
+                assert_not_reached ();
+            }
+        }
+    }
+}