[rygel] plugins: Make use of SimpleContainer



commit ffd1825fba8715f9bc9c644eb52df47d4a5ca1e3
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Sep 21 15:40:30 2009 +0300

    plugins: Make use of SimpleContainer
    
    Derive as many containers from SimpleContainer as possible.

 .../gstlaunch/rygel-gstlaunch-root-container.vala  |   59 +---------------
 .../mediathek/rygel-mediathek-root-container.vala  |   71 ++------------------
 .../mediathek/rygel-mediathek-rss-container.vala   |   65 ++----------------
 src/plugins/test/rygel-test-root-container.vala    |   72 +++-----------------
 4 files changed, 26 insertions(+), 241 deletions(-)
---
diff --git a/src/plugins/gstlaunch/rygel-gstlaunch-root-container.vala b/src/plugins/gstlaunch/rygel-gstlaunch-root-container.vala
index da0299e..355d331 100644
--- a/src/plugins/gstlaunch/rygel-gstlaunch-root-container.vala
+++ b/src/plugins/gstlaunch/rygel-gstlaunch-root-container.vala
@@ -29,17 +29,14 @@ using CStuff;
 /**
  * Represents the root container for GstLaunch content hierarchy.
  */
-public class Rygel.GstLaunchRootContainer : MediaContainer {
+public class Rygel.GstLaunchRootContainer : SimpleContainer {
     const string CONFIG_GROUP = "GstLaunch";
     const string ITEM_NAMES = "launch_items";
 
-    ArrayList<MediaItem> items;
     MetaConfig config;
 
     public GstLaunchRootContainer (string title) {
-        base.root (title, 0);
-
-        this.items = new ArrayList<MediaItem> ();
+        base.root (title);
 
         try {
           config = MetaConfig.get_default ();
@@ -50,7 +47,7 @@ public class Rygel.GstLaunchRootContainer : MediaContainer {
           debug ("GstLaunch init failed: %s", err.message);
         }
 
-        this.child_count = this.items.size;
+        this.child_count = this.children.size;
     }
 
     void add_launch_item (string name) {
@@ -58,58 +55,10 @@ public class Rygel.GstLaunchRootContainer : MediaContainer {
         string title = config.get_string (CONFIG_GROUP, "%s_title".printf (name));
         string mime_type = config.get_string (CONFIG_GROUP, "%s_mime".printf (name));
         string launch_line = config.get_string (CONFIG_GROUP, "%s_launch".printf (name));
-        this.items.add (new GstLaunchItem (name, this, title, mime_type, launch_line));
+        this.children.add (new GstLaunchItem (name, this, title, mime_type, launch_line));
       } catch (GLib.Error err) {
         debug ("GstLaunch failed item '%s': %s", name, err.message);
       }
     }
-
-    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);
-
-        var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>>
-                                            (this,
-                                             callback);
-        res.data = children;
-        res.complete_in_idle ();
-    }
-
-    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) {
-        var res = new Rygel.SimpleAsyncResult<string> (this, callback);
-
-        res.data = id;
-        res.complete_in_idle ();
-    }
-
-    public override MediaObject? find_object_finish (AsyncResult res)
-                                                     throws Error {
-        MediaItem item = null;
-        var id = ((Rygel.SimpleAsyncResult<string>) res).data;
-
-        foreach (MediaItem tmp in this.items) {
-            if (id == tmp.id) {
-                item = tmp;
-
-                break;
-            }
-        }
-
-        return item;
-    }
 }
 
diff --git a/src/plugins/mediathek/rygel-mediathek-root-container.vala b/src/plugins/mediathek/rygel-mediathek-root-container.vala
index b8b4af1..7936aef 100644
--- a/src/plugins/mediathek/rygel-mediathek-root-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-root-container.vala
@@ -23,72 +23,14 @@
 using Gee;
 using Soup;
 
-public class Rygel.MediathekRootContainer : Rygel.MediaContainer {
-    private ArrayList<MediathekRssContainer> items;
+public class Rygel.MediathekRootContainer : Rygel.SimpleContainer {
     internal SessionAsync session;
     private static MediathekRootContainer instance;
 
-    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);
-
-        var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (this,
-                                                                    callback);
-        res.data = children;
-        res.complete_in_idle ();
-    }
-
-    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) {
-        var res = new Rygel.SimpleAsyncResult<string> (this,
-                                                       callback);
-
-        res.data = id;
-        res.complete_in_idle ();
-    }
-
-    public override MediaObject? find_object_finish (AsyncResult res)
-                                                     throws GLib.Error {
-        MediaObject item = null;
-        var id = ((Rygel.SimpleAsyncResult<string>) res).data;
-
-        foreach (MediathekRssContainer tmp in this.items) {
-            if (id == tmp.id) {
-                item = tmp;
-                break;
-            }
-        }
-
-        if (item == null) {
-            foreach (MediathekRssContainer container in this.items) {
-                item = container.find_object_sync (id);
-                if (item != null) {
-                    break;
-                }
-            }
-        }
-
-        return item;
-    }
-
     private bool on_schedule_update () {
         message("Scheduling update for all feeds....");
-        foreach (MediathekRssContainer container in this.items) {
-            container.update ();
+        foreach (var container in this.children) {
+            ((MediathekRssContainer) container).update ();
         }
 
         return true;
@@ -103,9 +45,8 @@ public class Rygel.MediathekRootContainer : Rygel.MediaContainer {
     }
 
     private MediathekRootContainer () {
-        base.root ("ZDF Mediathek", 0);
+        base.root ("ZDF Mediathek");
         this.session = new Soup.SessionAsync ();
-        this.items = new ArrayList<MediathekRssContainer> ();
         Gee.ArrayList<int> feeds = null;
 
         var config = Rygel.MetaConfig.get_default ();
@@ -121,10 +62,10 @@ public class Rygel.MediathekRootContainer : Rygel.MediaContainer {
         }
 
         foreach (int id in feeds) {
-            this.items.add (new MediathekRssContainer (this, id));
+            this.children.add (new MediathekRssContainer (this, id));
         }
 
-        this.child_count = this.items.size;
+        this.child_count = this.children.size;
         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 ffd179b..5e05183 100644
--- a/src/plugins/mediathek/rygel-mediathek-rss-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-rss-container.vala
@@ -24,8 +24,7 @@ using Gee;
 using Soup;
 using Xml;
 
-public class Rygel.MediathekRssContainer : Rygel.MediaContainer {
-    private ArrayList<MediaItem> items;
+public class Rygel.MediathekRssContainer : Rygel.SimpleContainer {
     private uint zdf_content_id;
     private Soup.Date last_modified = null;
 
@@ -54,7 +53,7 @@ public class Rygel.MediathekRssContainer : Rygel.MediaContainer {
         bool ret = false;
         Xml.Doc* doc = Xml.Parser.parse_memory (data, (int) length);
         if (doc != null) {
-            items.clear ();
+            this.children.clear ();
             var ctx = new XPathContext (doc);
             var xpo = ctx.eval ("/rss/channel/title");
             if (xpo->type == Xml.XPathObjectType.NODESET &&
@@ -71,7 +70,7 @@ public class Rygel.MediathekRssContainer : Rygel.MediaContainer {
                         var item = 
                                 MediathekVideoItem.create_from_xml (this, 
                                                                     node);
-                        this.items.add (item);
+                        this.children.add (item);
                         ret = true;
                     }
                     catch (MediathekVideoItemError error) {
@@ -85,7 +84,7 @@ public class Rygel.MediathekRssContainer : Rygel.MediaContainer {
             }
 
             delete doc;
-            this.child_count = items.size;
+            this.child_count = children.size;
             this.updated ();
         }
         else {
@@ -95,56 +94,6 @@ public class Rygel.MediathekRssContainer : Rygel.MediaContainer {
         return ret;
     }
 
-    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);
-
-        var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (this,
-                                                                    callback);
-        res.data = children;
-        res.complete_in_idle ();
-    }
-
-    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) {
-        var res = new Rygel.SimpleAsyncResult<string> (this,
-                                                       callback);
-
-        res.data = id;
-        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 MediaObject? find_object_sync (string id) {
-        MediaItem item = null;
-        foreach (MediaItem tmp in this.items) {
-            if (id == tmp.id) {
-                item = tmp;
-                break;
-            }
-        }
-
-        return item;
-    }
-
     public void update () {
         var message = new Soup.Message ("GET",
             "http://www.zdf.de/ZDFmediathek/content/%u?view=rss".printf(
@@ -164,10 +113,8 @@ public class Rygel.MediathekRssContainer : Rygel.MediaContainer {
     public MediathekRssContainer (MediaContainer parent, uint id) {
         base ("GroupId:%u".printf(id), 
              parent, 
-             "ZDF Mediathek RSS feed %u".printf(id), 
-             0);
-        this.items = new ArrayList<MediaItem> ();
-        this.child_count = 0;
+             "ZDF Mediathek RSS feed %u".printf(id));
+
         this.zdf_content_id = id;
         update ();
     }
diff --git a/src/plugins/test/rygel-test-root-container.vala b/src/plugins/test/rygel-test-root-container.vala
index c019ac5..f126684 100644
--- a/src/plugins/test/rygel-test-root-container.vala
+++ b/src/plugins/test/rygel-test-root-container.vala
@@ -29,71 +29,19 @@ using Gst;
 /**
  * Represents the root container for Test media content hierarchy.
  */
-public class Rygel.TestRootContainer : Rygel.MediaContainer {
-    private ArrayList<MediaItem> items;
-
+public class Rygel.TestRootContainer : Rygel.SimpleContainer {
     public TestRootContainer (string title) {
-        base.root (title, 0);
-
-        this.items = new ArrayList<MediaItem> ();
-        this.items.add (new TestAudioItem ("sinewave",
-                                           this,
-                                           "Sine Wave"));
-        this.items.add (new TestVideoItem ("smtpe",
-                                           this,
-                                           "SMTPE"));
-
-        // Now we know how many top-level items we have
-        this.child_count = this.items.size;
-    }
-
-    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);
-
-        var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>>
-                                            (this,
-                                             callback);
-        res.data = children;
-        res.complete_in_idle ();
-    }
+        base.root (title);
 
-    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) {
-        var res = new Rygel.SimpleAsyncResult<string> (this, callback);
-
-        res.data = id;
-        res.complete_in_idle ();
-    }
+        this.children.add (new TestAudioItem ("sinewave",
+                                              this,
+                                              "Sine Wave"));
+        this.children.add (new TestVideoItem ("smtpe",
+                                              this,
+                                              "SMTPE"));
 
-    public override MediaObject? find_object_finish (AsyncResult res)
-                                                     throws Error {
-        MediaItem item = null;
-        var id = ((Rygel.SimpleAsyncResult<string>) res).data;
-
-        foreach (MediaItem tmp in this.items) {
-            if (id == tmp.id) {
-                item = tmp;
-
-                break;
-            }
-        }
-
-        return item;
+        // Now we know how many top-level children we have
+        this.child_count = this.children.size;
     }
-
 }
 



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