[rygel/wip/track-changes: 13/18] wip: Add automatic change tracking
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/track-changes: 13/18] wip: Add automatic change tracking
- Date: Mon, 22 Oct 2012 08:47:45 +0000 (UTC)
commit 99177eabfc1bc63f15aa4a4814fe57fe88524ce8
Author: Jens Georg <jensg openismus com>
Date: Sat Oct 20 21:54:05 2012 +0200
wip: Add automatic change tracking
src/librygel-server/rygel-trackable-container.vala | 55 ++++++++++++++++++++
src/plugins/mediathek/rygel-mediathek-plugin.vala | 5 ++-
.../mediathek/rygel-mediathek-root-container.vala | 10 +++-
.../mediathek/rygel-mediathek-rss-container.vala | 12 +++--
4 files changed, 74 insertions(+), 8 deletions(-)
---
diff --git a/src/librygel-server/rygel-trackable-container.vala b/src/librygel-server/rygel-trackable-container.vala
new file mode 100644
index 0000000..e98fb42
--- /dev/null
+++ b/src/librygel-server/rygel-trackable-container.vala
@@ -0,0 +1,55 @@
+public interface Rygel.TrackableContainer : Rygel.MediaContainer {
+ public async void clear () {
+ try {
+ var children = yield this.get_children (0, 0, "", null);
+ if (children == null) {
+ return;
+ }
+
+ foreach (var child in children) {
+ yield this.remove_child_tracked (child);
+ }
+ } catch (Error error) {
+ }
+ }
+
+ public abstract async void add_child (MediaObject object);
+
+ public async void add_child_tracked (MediaObject object) {
+ yield this.add_child (object);
+
+ this.updated (object, ObjectEventType.ADDED);
+ this.updated ();
+ if (object is TrackableContainer) {
+ var trackable = object as TrackableContainer;
+
+ // Release the events that might have accumulated
+ trackable.thaw_events ();
+ }
+ }
+
+ public abstract async void remove_child (MediaObject object);
+
+ public async void remove_child_tracked (MediaObject object) {
+ // We need to descend into this to get the proper events
+ if (object is TrackableContainer) {
+ var trackable = object as TrackableContainer;
+ yield trackable.clear ();
+ }
+
+ yield this.remove_child (object);
+
+ this.updated (object, ObjectEventType.DELETED);
+ this.updated ();
+ }
+
+ private void thaw_events () {
+ // Forward events.
+ }
+
+ private void on_parent_changed () {
+ if (this.parent != null) {
+ this.thaw_events ();
+ }
+ }
+}
diff --git a/src/plugins/mediathek/rygel-mediathek-plugin.vala b/src/plugins/mediathek/rygel-mediathek-plugin.vala
index 1a37335..e9d4313 100644
--- a/src/plugins/mediathek/rygel-mediathek-plugin.vala
+++ b/src/plugins/mediathek/rygel-mediathek-plugin.vala
@@ -45,6 +45,9 @@ public class Rygel.Mediathek.Plugin : Rygel.MediaServerPlugin {
public const string NAME = "ZDFMediathek";
public Plugin () {
- base (RootContainer.get_instance (), Plugin.NAME);
+ base (RootContainer.get_instance (),
+ Plugin.NAME,
+ null,
+ PluginCapabilities.TRACK_CHANGES);
}
}
diff --git a/src/plugins/mediathek/rygel-mediathek-root-container.vala b/src/plugins/mediathek/rygel-mediathek-root-container.vala
index e324895..1534565 100644
--- a/src/plugins/mediathek/rygel-mediathek-root-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-root-container.vala
@@ -32,7 +32,7 @@ public class Rygel.Mediathek.RootContainer : Rygel.TrackableContainer,
public static RootContainer get_instance () {
if (RootContainer.instance == null) {
RootContainer.instance = new RootContainer ();
- RootContainer.instance.init ();
+ RootContainer.instance.init.begin ();
}
return instance;
@@ -47,7 +47,7 @@ public class Rygel.Mediathek.RootContainer : Rygel.TrackableContainer,
this.session = new Soup.SessionAsync ();
}
- private void init () {
+ private async void init () {
Gee.ArrayList<int> feeds = null;
int update_interval = DEFAULT_UPDATE_INTERVAL;
@@ -73,7 +73,7 @@ public class Rygel.Mediathek.RootContainer : Rygel.TrackableContainer,
}
foreach (int id in feeds) {
- this.add_child_container (new RssContainer (this, id));
+ yield this.add_child_tracked (new RssContainer (this, id));
}
Timeout.add_seconds (update_interval, () => {
@@ -86,4 +86,8 @@ public class Rygel.Mediathek.RootContainer : Rygel.TrackableContainer,
return true;
});
}
+
+ public async void add_child (MediaObject object) {
+ this.add_child_container (object as MediaContainer);
+ }
}
diff --git a/src/plugins/mediathek/rygel-mediathek-rss-container.vala b/src/plugins/mediathek/rygel-mediathek-rss-container.vala
index ff9905a..b0b744a 100644
--- a/src/plugins/mediathek/rygel-mediathek-rss-container.vala
+++ b/src/plugins/mediathek/rygel-mediathek-rss-container.vala
@@ -24,7 +24,8 @@ using Gee;
using Soup;
using Xml;
-public class Rygel.Mediathek.RssContainer : Rygel.SimpleContainer {
+public class Rygel.Mediathek.RssContainer : Rygel.TrackableContainer,
+ Rygel.SimpleContainer {
private const string uri_template = "http://www.zdf.de/ZDFmediathek/" +
"content/%u?view=rss";
private uint content_id;
@@ -103,14 +104,14 @@ public class Rygel.Mediathek.RssContainer : Rygel.SimpleContainer {
return false;
}
- this.children.clear ();
+ yield this.clear ();
this.child_count = 0;
for (int i = 0; i < xpath_object->nodesetval->length (); i++) {
var node = xpath_object->nodesetval->item (i);
try {
var item = yield factory.create (this, node);
if (item != null) {
- this.add_child_item (item);
+ yield this.add_child_tracked (item);
}
} catch (VideoItemError error) {
debug ("Could not create video item: %s, skipping",
@@ -119,7 +120,6 @@ public class Rygel.Mediathek.RssContainer : Rygel.SimpleContainer {
}
xpath_free_object (xpath_object);
- this.updated ();
return this.child_count > 0;
}
@@ -135,4 +135,8 @@ public class Rygel.Mediathek.RssContainer : Rygel.SimpleContainer {
return message;
}
+
+ public async void add_child (MediaObject object) {
+ this.add_child_item (object as MediaItem);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]