[rygel] Fix more stlye issues



commit 26ea10a7221f1580739c52a8dbcc9265cf522326
Author: Jens Georg <mail jensge org>
Date:   Sun May 3 20:39:55 2009 +0200

    Fix more stlye issues
---
 .../mediathek/rygel-mediathek-asx-playlist.vala    |   45 +++++----
 src/plugins/mediathek/rygel-mediathek-plugin.vala  |    4 +-
 .../mediathek/rygel-mediathek-root-container.vala  |   62 ++++++------
 .../mediathek/rygel-mediathek-rss-container.vala   |  106 +++++++++++--------
 .../mediathek/rygel-mediathek-video-item.vala      |   77 +++++++++------
 5 files changed, 171 insertions(+), 123 deletions(-)

diff --git a/src/plugins/mediathek/rygel-mediathek-asx-playlist.vala b/src/plugins/mediathek/rygel-mediathek-asx-playlist.vala
index 08c7510..d6dfdc8 100644
--- a/src/plugins/mediathek/rygel-mediathek-asx-playlist.vala
+++ b/src/plugins/mediathek/rygel-mediathek-asx-playlist.vala
@@ -41,8 +41,8 @@ public class Rygel.MediathekAsxPlaylist : Object {
     public ArrayList<string> uris;
     private string uri;
 
-    public MediathekAsxPlaylist(string uri) {
-        this.uris = new ArrayList<string>();
+    public MediathekAsxPlaylist (string uri) {
+        this.uris = new ArrayList<string> ();
         this.uri = uri;
     }
 
@@ -58,38 +58,47 @@ public class Rygel.MediathekAsxPlaylist : Object {
      */
     public void parse() throws MediathekAsxPlaylistError {
         // FIXME make async using global soup session
-        var session = new Soup.SessionSync();
-        var message = new Soup.Message("GET",
-            this.uri);
+        var session = new Soup.SessionSync ();
+        var message = new Soup.Message ("GET",
+                                        this.uri);
 
-        session.send_message(message);
+        session.send_message (message);
         if (message.status_code == 200) {
             try {
                 // lowercase all tags using regex and \L\E syntax
-                var normalizer = new Regex("(<[/]?)([a-zA-Z:]+)");
-                string normalized_content = normalizer.replace(message.response_body.data,
-                        (long)message.response_body.length, 0, "\\1\\L\\2\\E");
-                var doc = Parser.parse_memory(normalized_content, (int)normalized_content.length);
+                var normalizer = new Regex ("(<[/]?)([a-zA-Z:]+)");
+                string normalized_content = 
+                        normalizer.replace (message.response_body.data,
+                                            (long)message.response_body.length,
+                                            0, 
+                                            "\\1\\L\\2\\E");
+
+                var doc = Parser.parse_memory (normalized_content, 
+                                               (int)normalized_content.length);
 
                 if (doc != null) {
-                    var ctx = new XPathContext(doc);
-                    var xpo = ctx.eval("/asx/entry/ref/@href");
+                    var ctx = new XPathContext (doc);
+                    var xpo = ctx.eval ("/asx/entry/ref/@href");
                     if (xpo->type == XPathObjectType.NODESET) {
-                        for (int i = 0; i < xpo->nodesetval->length(); i++) {
-                            var item = xpo->nodesetval->item(i);
-                            uris.add(item->children->content);
+                        for (int i = 0; i < xpo->nodesetval->length (); i++) {
+                            var item = xpo->nodesetval->item (i);
+                            uris.add (item->children->content);
                         }
                     }
                 }
                 else {
-                    throw new MediathekAsxPlaylistError.XML_ERROR("Could not received XML");
+                    throw new 
+                        MediathekAsxPlaylistError.XML_ERROR (
+                                                  "Could not received XML");
                 }
             }
             catch (RegexError error) { }
         }
         else {
-            throw new MediathekAsxPlaylistError.NETWORK_ERROR("Could not download playlist, error code was %u (%s)".printf(message.status_code, 
-                Soup.status_get_phrase(message.status_code)));
+            throw new MediathekAsxPlaylistError.NETWORK_ERROR (
+                 "Could not download playlist, error code was %u (%s)".printf (
+                 message.status_code, 
+                 Soup.status_get_phrase (message.status_code)));
         }
     }
 }
diff --git a/src/plugins/mediathek/rygel-mediathek-plugin.vala b/src/plugins/mediathek/rygel-mediathek-plugin.vala
index af2d167..c744b32 100644
--- a/src/plugins/mediathek/rygel-mediathek-plugin.vala
+++ b/src/plugins/mediathek/rygel-mediathek-plugin.vala
@@ -22,8 +22,8 @@ using Rygel;
 using GUPnP;
 
 [ModuleInit]
-public Plugin load_plugin() {
-    Plugin plugin = new Plugin("ZDFMediathek");
+public Plugin load_plugin () {
+    Plugin plugin = new Plugin ("ZDFMediathek");
 
     var resource_info = new ResourceInfo (ContentDirectory.UPNP_ID,
                                           ContentDirectory.UPNP_TYPE,
diff --git a/src/plugins/mediathek/rygel-mediathek-root-container.vala b/src/plugins/mediathek/rygel-mediathek-root-container.vala
index 43e580d..b455478 100644
--- a/src/plugins/mediathek/rygel-mediathek-root-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-root-container.vala
@@ -28,39 +28,43 @@ public class Rygel.MediathekRootContainer : MediaContainer {
     internal SessionAsync session;
     private GConf.Client gconf;
 
-    public override void get_children(uint offset, uint max_count, 
-        Cancellable? cancellable, AsyncReadyCallback callback)
+    public override void get_children (uint offset, 
+                                       uint max_count, 
+                                       Cancellable? cancellable, 
+                                       AsyncReadyCallback callback)
     {
         uint stop = offset + max_count;
-        stop = stop.clamp(0, this.child_count);
-        var children = this.items.slice ((int)offset, (int)stop);
+        stop = stop.clamp (0, this.child_count);
+        var children = this.items.slice ((int) offset, (int) stop);
 
         var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (this,
-        callback);
+                                                                    callback);
         res.data = children;
-        res.complete_in_idle();
+        res.complete_in_idle ();
     }
 
-    public override Gee.List<MediaObject>? get_children_finish (AsyncResult
-    res)
-                                                         throws GLib.Error {
+    public override Gee.List<MediaObject>? get_children_finish (
+                                                        AsyncResult res)
+                                                        throws GLib.Error {
         var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
 
         return simple_res.data;
     }
-    public override void find_object (string id, Cancellable? cancellable,
-    AsyncReadyCallback callback) {
+
+    public override void find_object (string id, 
+                                      Cancellable? cancellable,
+                                      AsyncReadyCallback callback) {
         var res = new Rygel.SimpleAsyncResult<string> (this,
-            callback);
+                                                       callback);
 
         res.data = id;
-        res.complete_in_idle();
+        res.complete_in_idle ();
     }
 
-    public override MediaObject? find_object_finish (AsyncResult res) throws
-    GLib.Error {
+    public override MediaObject? find_object_finish (AsyncResult res) 
+                                                     throws GLib.Error {
         MediaObject item = null;
-        var id = ((Rygel.SimpleAsyncResult<string>)res).data;
+        var id = ((Rygel.SimpleAsyncResult<string>) res).data;
 
         foreach (MediathekRssContainer tmp in this.items) {
             if (id == tmp.id) {
@@ -71,7 +75,7 @@ public class Rygel.MediathekRootContainer : MediaContainer {
 
         if (item == null) {
             foreach (MediathekRssContainer container in this.items) {
-                item = container.find_object_sync(id);
+                item = container.find_object_sync (id);
                 if (item != null) {
                     break;
                 }
@@ -81,43 +85,43 @@ public class Rygel.MediathekRootContainer : MediaContainer {
         return item;
     }
 
-    private bool on_schedule_update() {
+    private bool on_schedule_update () {
         message("Scheduling update for all feeds....");
         foreach (MediathekRssContainer container in this.items) {
-            container.update();
+            container.update ();
         }
 
         return true;
     }
 
-    public MediathekRootContainer() {
-        base.root("ZDF Mediathek", 0);
+    public MediathekRootContainer () {
+        base.root ("ZDF Mediathek", 0);
         this.session = new Soup.SessionAsync ();
-        this.items = new ArrayList<MediathekRssContainer>();
+        this.items = new ArrayList<MediathekRssContainer> ();
 
-        this.gconf = GConf.Client.get_default();
+        this.gconf = GConf.Client.get_default ();
         unowned SList<int> feeds = null;
 
         // get subscribed feeds
         try {
             // TODO get gconf prefix from Rygel
             feeds = gconf.get_list("/apps/rygel/ZDFMediathek/rss",
-                                GConf.ValueType.INT);
+                                   GConf.ValueType.INT);
 
         } catch (GLib.Error error) {
-            message("Error on getting configuration: %s", error.message);
+            message ("Error on getting configuration: %s", error.message);
         }
 
         if (feeds == null) {
-            message("Could not get RSS items from GConf, using defaults");
-            feeds.append(508);
+            message ("Could not get RSS items from GConf, using defaults");
+            feeds.append (508);
         }
 
         foreach (int id in feeds) {
-            this.items.add(new MediathekRssContainer(this, id));
+            this.items.add (new MediathekRssContainer (this, id));
         }
 
         this.child_count = this.items.size;
-        GLib.Timeout.add_seconds(1800, on_schedule_update);
+        GLib.Timeout.add_seconds (1800, on_schedule_update);
     }
 }
diff --git a/src/plugins/mediathek/rygel-mediathek-rss-container.vala b/src/plugins/mediathek/rygel-mediathek-rss-container.vala
index 17d0b35..45a5114 100644
--- a/src/plugins/mediathek/rygel-mediathek-rss-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-rss-container.vala
@@ -34,97 +34,105 @@ public class Rygel.MediathekRssContainer : MediaContainer {
                 message("Feed has not changed, nothing to do");
                 break;
             case 200:
-                if (parse_response(
-                        msg.response_body.data, 
-                        (size_t)msg.response_body.length)) {
-                    last_modified = new Soup.Date.from_string(msg.response_headers.get("Date"));
+                if (parse_response (msg.response_body.data, 
+                                    (size_t) msg.response_body.length)) {
+                    last_modified = new Soup.Date.from_string(
+                                            msg.response_headers.get ("Date"));
                 }
                 break;
             default:
                 // TODO Need to handle redirects....
                 warning("Got unexpected response %u (%s)",
-                    msg.status_code,
-                    Soup.status_get_phrase (msg.status_code));
+                        msg.status_code,
+                        Soup.status_get_phrase (msg.status_code));
                 break;
         }
     }
 
-    private bool parse_response(string data, size_t length) {
+    private bool parse_response (string data, size_t length) {
         bool ret = false;
-        Xml.Doc* doc = Xml.Parser.parse_memory(data, (int)length);
+        Xml.Doc* doc = Xml.Parser.parse_memory (data, (int) length);
         if (doc != null) {
-            items.clear();
-            var ctx = new XPathContext(doc);
-            var xpo = ctx.eval("/rss/channel/title");
+            items.clear ();
+            var ctx = new XPathContext (doc);
+            var xpo = ctx.eval ("/rss/channel/title");
             if (xpo->type == Xml.XPathObjectType.NODESET &&
-                xpo->nodesetval->length() > 0) {
+                xpo->nodesetval->length () > 0) {
                 // just use first title (there should be only one)
-                this.title = xpo->nodesetval->item(0)->get_content();
+                this.title = xpo->nodesetval->item (0)->get_content ();
             }
 
-            xpo = ctx.eval("/rss/channel/item");
+            xpo = ctx.eval ("/rss/channel/item");
             if (xpo->type == Xml.XPathObjectType.NODESET) {
-                for (int i = 0; i < xpo->nodesetval->length(); i++) {
-                    Xml.Node* node = xpo->nodesetval->item(i);
+                for (int i = 0; i < xpo->nodesetval->length (); i++) {
+                    Xml.Node* node = xpo->nodesetval->item (i);
                     try {
-                        var item = MediathekVideoItem.create_from_xml(this, node);
-                        this.items.add(item);
+                        var item = 
+                                MediathekVideoItem.create_from_xml (this, 
+                                                                    node);
+                        this.items.add (item);
                         ret = true;
                     }
                     catch (MediathekVideoItemError error) {
-                        GLib.message("Error creating video item: %s", 
-                            error.message); 
+                        GLib.message ("Error creating video item: %s", 
+                                      error.message); 
                     }
                 }
             }
             else {
-                warning("XPath query failed");
+                warning ("XPath query failed");
             }
 
             delete doc;
             this.child_count = items.size;
-            this.updated();
+            this.updated ();
         }
         else {
-            warning("Failed to parse doc");
+            warning ("Failed to parse doc");
         }
 
         return ret;
     }
 
-    public override void get_children(uint offset, uint max_count, 
-        Cancellable? cancellable, AsyncReadyCallback callback) {
-        debug("get_children called");
+    public override void get_children (uint offset, 
+                                       uint max_count, 
+                                       Cancellable? cancellable, 
+                                       AsyncReadyCallback callback) {
         uint stop = offset + max_count;
-        stop = stop.clamp(0, this.child_count);
-        var children = this.items.slice ((int)offset, (int)stop);
+        stop = stop.clamp (0, this.child_count);
+        var children = this.items.slice ((int) offset, (int) stop);
 
         var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (this,
-        callback);
+                                                                    callback);
         res.data = children;
-        res.complete_in_idle();
+        res.complete_in_idle ();
     }
 
-    public override Gee.List<MediaObject>? get_children_finish (AsyncResult res) throws GLib.Error {
+    public override Gee.List<MediaObject>? get_children_finish (
+                                                            AsyncResult res)
+                                                            throws GLib.Error {
         var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
 
         return simple_res.data;
     }
 
-    public override void find_object (string id, Cancellable? cancellable, AsyncReadyCallback callback) {
+    public override void find_object (string id, 
+                                      Cancellable? cancellable, 
+                                      AsyncReadyCallback callback) {
         var res = new Rygel.SimpleAsyncResult<string> (this,
-            callback);
+                                                       callback);
 
         res.data = id;
-        res.complete_in_idle();
+        res.complete_in_idle ();
     }
 
-    public override MediaObject? find_object_finish (AsyncResult res) throws GLib.Error {
-        var id = ((Rygel.SimpleAsyncResult<string>)res).data;
-        return find_object_sync(id);
+    public override MediaObject? find_object_finish (AsyncResult res) 
+                                                     throws GLib.Error {
+        var id = ((Rygel.SimpleAsyncResult<string>) res).data;
+        return find_object_sync (id);
     }
 
-    public MediaObject? find_object_sync(string id) {
+    public MediaObject? find_object_sync (string id) {
         MediaItem item = null;
         foreach (MediaItem tmp in this.items) {
             if (id == tmp.id) {
@@ -136,22 +144,30 @@ public class Rygel.MediathekRssContainer : MediaContainer {
         return item;
     }
 
-    public void update() {
+    public void update () {
         var message = new Soup.Message ("GET",
-            "http://www.zdf.de/ZDFmediathek/content/%u?view=rss".printf(zdf_content_id)); 
+            "http://www.zdf.de/ZDFmediathek/content/%u?view=rss".printf(
+                                                            zdf_content_id)); 
         if (last_modified != null) {
-            debug("Requesting change since %s", last_modified.to_string(DateFormat.HTTP));
-            message.request_headers.append("If-Modified-Since", last_modified.to_string(DateFormat.HTTP));
+            debug ("Requesting change since %s", 
+                   last_modified.to_string(DateFormat.HTTP));
+            message.request_headers.append("If-Modified-Since", 
+                   last_modified.to_string(DateFormat.HTTP));
         }
 
-        ((MediathekRootContainer)this.parent).session.queue_message (message, on_feed_got);
+        ((MediathekRootContainer) this.parent).session.queue_message (
+                                                                  message, 
+                                                                  on_feed_got);
     }
 
     public MediathekRssContainer (MediaContainer parent, uint id) {
-        base("GroupId:%u".printf(id), parent, "ZDF Mediathek RSS feed %u".printf(id), 0);
+        base ("GroupId:%u".printf(id), 
+             parent, 
+             "ZDF Mediathek RSS feed %u".printf(id), 
+             0);
         this.items = new ArrayList<MediaItem> ();
         this.child_count = 0;
         this.zdf_content_id = id;
-        update();
+        update ();
     }
 }
diff --git a/src/plugins/mediathek/rygel-mediathek-video-item.vala b/src/plugins/mediathek/rygel-mediathek-video-item.vala
index 2a07398..c3136e3 100644
--- a/src/plugins/mediathek/rygel-mediathek-video-item.vala
+++ b/src/plugins/mediathek/rygel-mediathek-video-item.vala
@@ -27,8 +27,12 @@ public errordomain Rygel.MediathekVideoItemError {
 }
 
 public class Rygel.MediathekVideoItem : Rygel.MediaItem {
-    private MediathekVideoItem(MediaContainer parent, string title) {
-        base(Checksum.compute_for_string(ChecksumType.MD5, title), parent, title, MediaItem.VIDEO_CLASS);
+    private MediathekVideoItem (MediaContainer parent, string title) {
+        base(Checksum.compute_for_string (ChecksumType.MD5, title), 
+             parent, 
+             title, 
+             MediaItem.VIDEO_CLASS);
+
         this.mime_type = "video/x-ms-asf";
         this.author = "ZDF - Zweites Deutsches Fernsehen";
     }
@@ -37,65 +41,80 @@ public class Rygel.MediathekVideoItem : Rygel.MediaItem {
         return node->ns != null && node->ns->prefix == "media";
     }
 
-    public static MediathekVideoItem create_from_xml(MediaContainer parent, Xml.Node *item) throws MediathekVideoItemError {
+    public static MediathekAsxPlaylist? handle_content(Xml.Node *group) {
+        MediathekAsxPlaylist asx = null;
+        if (namespace_ok (group)) {
+            Xml.Attr* attr = group->has_prop ("url");
+            if (attr != null) {
+                var url = attr->children->content;
+                if (url.has_suffix (".asx")) {
+                    asx = new MediathekAsxPlaylist (url);
+                    asx.parse ();
+                }
+            }
+            else {
+                throw new MediathekVideoItemError.XML_PARSE_ERROR (
+                                                "group node has url property");
+            }
+        }
+        else {
+            throw new MediathekVideoItemError.XML_PARSE_ERROR (
+                                                "invalid or no namespace");
+        }
+
+        return asx;
+    }
+
+    public static MediathekVideoItem create_from_xml(
+                                               MediaContainer parent, 
+                                               Xml.Node *item) 
+                                               throws MediathekVideoItemError {
         string title = null;
         MediathekVideoItem video_item = null;
         MediathekAsxPlaylist asx = null;
 
-        for (Xml.Node* item_child = item->children; item_child != null; item_child = item_child->next)
+        for (Xml.Node* item_child = item->children; 
+             item_child != null; 
+             item_child = item_child->next)
         {
             switch (item_child->name) {
                 case "title":
-                    title = item_child->get_content();
+                    title = item_child->get_content ();
                     break;
                 case "group":
-                    if (namespace_ok(item_child)) {
+                    if (namespace_ok (item_child)) {
                         for (Xml.Node* group = item_child->children; 
                              group != null;
                              group = group->next) {
                             if (group->name == "content") {
-                                if (namespace_ok(group)) {
-                                    Xml.Attr* attr = group->has_prop("url");
-                                    if (attr != null) {
-                                        var url = attr->children->content;
-                                        if (url.has_suffix(".asx")) {
-                                            debug("Found Url %s", url);
-                                            asx = new MediathekAsxPlaylist(url);
-                                            asx.parse();
-                                        }
-                                    }
-                                    else {
-                                        throw new MediathekVideoItemError.XML_PARSE_ERROR("group node has url property");
-                                    }
-                                }
-                                else {
-                                    throw new MediathekVideoItemError.XML_PARSE_ERROR("invalid or no namespace");
-                                }
+                                handle_content (group);
                             }
                         }
                     }
                     else {
-                        throw new MediathekVideoItemError.XML_PARSE_ERROR("invalid or no namespace on group node");
+                        throw new MediathekVideoItemError.XML_PARSE_ERROR (
+                                      "invalid or no namespace on group node");
                     }
                     break;
                 default:
-                    //debug("Got node->name %s", node->name);
                     break;
              }
 
         }
         if (title == null) {
-            throw new MediathekVideoItemError.XML_PARSE_ERROR("Could not find title");
+            throw new MediathekVideoItemError.XML_PARSE_ERROR (
+                                                       "Could not find title");
         }
 
 
         if (asx == null) {
-            throw new MediathekVideoItemError.XML_PARSE_ERROR("Could not find uris");
+            throw new MediathekVideoItemError.XML_PARSE_ERROR (
+                                                       "Could not find uris");
         }
 
-        video_item = new MediathekVideoItem(parent, title);
+        video_item = new MediathekVideoItem (parent, title);
         foreach (string uri in asx.uris) {
-            video_item.uris.add(uri);
+            video_item.uris.add (uri);
         }
 
         return video_item;



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