[rygel/wip/gobject: 14/19] server: Media items and containers to GObject-style.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/gobject: 14/19] server: Media items and containers to GObject-style.
- Date: Tue, 22 Jan 2013 13:03:50 +0000 (UTC)
commit 39214e36fff596e0d3de101b52d908caf657d836
Author: Krzesimir Nowak <krnowak openismus com>
Date: Tue Jan 15 15:14:58 2013 +0100
server: Media items and containers to GObject-style.
src/librygel-server/rygel-audio-item.vala | 5 ++-
src/librygel-server/rygel-image-item.vala | 9 +++++-
src/librygel-server/rygel-media-container.vala | 34 ++++++++++++-------
src/librygel-server/rygel-media-item.vala | 21 +++++++-----
src/librygel-server/rygel-media-object.vala | 23 ++++++++++---
src/librygel-server/rygel-music-item.vala | 7 +++-
src/librygel-server/rygel-photo-item.vala | 5 ++-
src/librygel-server/rygel-playlist-item.vala | 5 ++-
src/librygel-server/rygel-video-item.vala | 9 +++++-
src/plugins/external/rygel-external-container.vala | 4 +-
10 files changed, 87 insertions(+), 35 deletions(-)
---
diff --git a/src/librygel-server/rygel-audio-item.vala b/src/librygel-server/rygel-audio-item.vala
index 24b34a1..5882ea5 100644
--- a/src/librygel-server/rygel-audio-item.vala
+++ b/src/librygel-server/rygel-audio-item.vala
@@ -41,7 +41,10 @@ public class Rygel.AudioItem : MediaItem {
MediaContainer parent,
string title,
string upnp_class = AudioItem.UPNP_CLASS) {
- base (id, parent, title, upnp_class);
+ Object (id : id,
+ parent : parent,
+ title : title,
+ upnp_class : upnp_class);
}
public override bool streamable () {
diff --git a/src/librygel-server/rygel-image-item.vala b/src/librygel-server/rygel-image-item.vala
index 07b12be..55503c6 100644
--- a/src/librygel-server/rygel-image-item.vala
+++ b/src/librygel-server/rygel-image-item.vala
@@ -62,7 +62,14 @@ public class Rygel.ImageItem : MediaItem, VisualItem {
MediaContainer parent,
string title,
string upnp_class = ImageItem.UPNP_CLASS) {
- base (id, parent, title, upnp_class);
+ Object (id : id,
+ parent : parent,
+ title : title,
+ upnp_class : upnp_class);
+ }
+
+ public override void constructed () {
+ base.constructed ();
this.thumbnails = new ArrayList<Thumbnail> ();
}
diff --git a/src/librygel-server/rygel-media-container.vala b/src/librygel-server/rygel-media-container.vala
index f05c40e..711f759 100644
--- a/src/librygel-server/rygel-media-container.vala
+++ b/src/librygel-server/rygel-media-container.vala
@@ -89,7 +89,7 @@ public abstract class Rygel.MediaContainer : MediaObject {
*/
public signal void sub_tree_updates_finished (MediaObject sub_tree_root);
- public int child_count;
+ public int child_count { get; set construct; }
public uint32 update_id;
public int64 storage_used;
@@ -146,17 +146,10 @@ public abstract class Rygel.MediaContainer : MediaObject {
MediaContainer? parent,
string title,
int child_count) {
- this.id = id;
- this.parent = parent;
- this.title = title;
- this.child_count = child_count;
- this.update_id = 0;
- this.storage_used = -1;
- this.total_deleted_child_count = 0;
- this.upnp_class = STORAGE_FOLDER;
-
- this.container_updated.connect (on_container_updated);
- this.sub_tree_updates_finished.connect (on_sub_tree_updates_finished);
+ Object (id : id,
+ parent : parent,
+ title : title,
+ child_count : child_count);
}
/**
@@ -168,7 +161,22 @@ public abstract class Rygel.MediaContainer : MediaObject {
*/
public MediaContainer.root (string title,
int child_count) {
- this ("0", null, title, child_count);
+ Object (id : "0",
+ parent : null,
+ title : title,
+ child_count : child_count);
+ }
+
+ public override void constructed () {
+ base.constructed ();
+
+ this.update_id = 0;
+ this.storage_used = -1;
+ this.total_deleted_child_count = 0;
+ this.upnp_class = STORAGE_FOLDER;
+
+ this.container_updated.connect (on_container_updated);
+ this.sub_tree_updates_finished.connect (on_sub_tree_updates_finished);
}
/**
diff --git a/src/librygel-server/rygel-media-item.vala b/src/librygel-server/rygel-media-item.vala
index 9677258..e42c291 100644
--- a/src/librygel-server/rygel-media-item.vala
+++ b/src/librygel-server/rygel-media-item.vala
@@ -89,19 +89,21 @@ public abstract class Rygel.MediaItem : MediaObject {
}
}
- protected Regex address_regex;
+ protected static Regex address_regex;
public MediaItem (string id,
MediaContainer parent,
string title,
string upnp_class) {
- this.id = id;
- this.parent = parent;
- this.title = title;
- this.upnp_class = upnp_class;
+ Object (id : id,
+ parent : parent,
+ title : title,
+ upnp_class : upnp_class);
+ }
+ static construct {
try {
- this.address_regex = new Regex (Regex.escape_string ("@ADDRESS@"));
+ address_regex = new Regex (Regex.escape_string ("@ADDRESS@"));
} catch (GLib.RegexError err) {
assert_not_reached ();
}
@@ -117,7 +119,7 @@ public abstract class Rygel.MediaItem : MediaObject {
string translated_uri = this.uris.get (0);
if (host_ip != null) {
try {
- translated_uri = this.address_regex.replace_literal
+ translated_uri = MediaItem.address_regex.replace_literal
(this.uris.get (0), -1, 0, host_ip);
} catch (Error error) {
assert_not_reached ();
@@ -260,7 +262,10 @@ public abstract class Rygel.MediaItem : MediaObject {
this.add_resources (didl_item, internal_allowed);
foreach (var res in didl_item.get_resources ()) {
- res.uri = this.address_regex.replace_literal (res.uri, -1, 0, host_ip);
+ res.uri = MediaItem.address_regex.replace_literal (res.uri,
+ -1,
+ 0,
+ host_ip);
}
}
diff --git a/src/librygel-server/rygel-media-object.vala b/src/librygel-server/rygel-media-object.vala
index 09bbcdb..6b3953a 100644
--- a/src/librygel-server/rygel-media-object.vala
+++ b/src/librygel-server/rygel-media-object.vala
@@ -38,9 +38,9 @@ public abstract class Rygel.MediaObject : GLib.Object {
private static Regex user_name_regex;
private static Regex host_name_regex;
- public string id { get; set; }
+ public string id { get; set construct; }
public string ref_id { get; set; }
- public string upnp_class { get; set; }
+ public string upnp_class { get; construct set; }
public uint64 modified { get; set; }
public uint object_update_id { get; set; }
@@ -57,7 +57,18 @@ public abstract class Rygel.MediaObject : GLib.Object {
//
// You must set 'parent' if you set 'parent_ref' but the opposite is not
// mandatory.
- public unowned MediaContainer parent; // TODO: Turn this into a property?
+ public unowned MediaContainer parent {
+ get {
+ return this.parent_ptr;
+ }
+
+ set construct {
+ this.parent_ptr = value;
+ }
+ }
+ // This one is needed only because external plugin needs to access
+ // the address of the parent to add weak pointer.
+ public unowned MediaContainer parent_ptr;
private MediaContainer _parent_ref;
public MediaContainer parent_ref {
get {
@@ -91,7 +102,7 @@ public abstract class Rygel.MediaObject : GLib.Object {
return _title;
}
- set {
+ set construct {
try {
this._title = real_name_regex.replace_literal
(value,
@@ -132,7 +143,9 @@ public abstract class Rygel.MediaObject : GLib.Object {
}
}
- construct {
+ public override void constructed () {
+ base.constructed ();
+
uris = new ArrayList<string> ();
}
diff --git a/src/librygel-server/rygel-music-item.vala b/src/librygel-server/rygel-music-item.vala
index f51883c..288c229 100644
--- a/src/librygel-server/rygel-music-item.vala
+++ b/src/librygel-server/rygel-music-item.vala
@@ -43,7 +43,10 @@ public class Rygel.MusicItem : AudioItem {
MediaContainer parent,
string title,
string upnp_class = MusicItem.UPNP_CLASS) {
- base (id, parent, title, upnp_class);
+ Object (id : id,
+ parent : parent,
+ title : title,
+ upnp_class : upnp_class);
}
public void lookup_album_art () {
@@ -136,7 +139,7 @@ public class Rygel.MusicItem : AudioItem {
}
if (didl_item.album_art != null) {
- didl_item.album_art = this.address_regex.replace_literal
+ didl_item.album_art = MediaItem.address_regex.replace_literal
(didl_item.album_art,
-1,
0,
diff --git a/src/librygel-server/rygel-photo-item.vala b/src/librygel-server/rygel-photo-item.vala
index b344e08..a83102e 100644
--- a/src/librygel-server/rygel-photo-item.vala
+++ b/src/librygel-server/rygel-photo-item.vala
@@ -39,7 +39,10 @@ public class Rygel.PhotoItem : ImageItem {
MediaContainer parent,
string title,
string upnp_class = PhotoItem.UPNP_CLASS) {
- base (id, parent, title, upnp_class);
+ Object (id : id,
+ parent : parent,
+ title : title,
+ upnp_class : upnp_class);
}
internal override int compare_by_property (MediaObject media_object,
diff --git a/src/librygel-server/rygel-playlist-item.vala b/src/librygel-server/rygel-playlist-item.vala
index 0a416bf..60175fd 100644
--- a/src/librygel-server/rygel-playlist-item.vala
+++ b/src/librygel-server/rygel-playlist-item.vala
@@ -36,7 +36,10 @@ public class Rygel.PlaylistItem : MediaItem {
MediaContainer parent,
string title,
string upnp_class = PlaylistItem.UPNP_CLASS) {
- base (id, parent, title, upnp_class);
+ Object (id : id,
+ parent : parent,
+ title : title,
+ upnp_class : upnp_class);
}
public override bool streamable () {
diff --git a/src/librygel-server/rygel-video-item.vala b/src/librygel-server/rygel-video-item.vala
index 93f61a1..38082c0 100644
--- a/src/librygel-server/rygel-video-item.vala
+++ b/src/librygel-server/rygel-video-item.vala
@@ -67,7 +67,14 @@ public class Rygel.VideoItem : AudioItem, VisualItem {
MediaContainer parent,
string title,
string upnp_class = VideoItem.UPNP_CLASS) {
- base (id, parent, title, upnp_class);
+ Object (id : id,
+ parent : parent,
+ title : title,
+ upnp_class : upnp_class);
+ }
+
+ public override void constructed () {
+ base.constructed ();
this.thumbnails = new ArrayList<Thumbnail> ();
this.subtitles = new ArrayList<Subtitle> ();
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index 128068f..fca762c 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -64,13 +64,13 @@ public class Rygel.External.Container : Rygel.MediaContainer,
this.update_container.begin (true);
if (parent != null) {
- parent.add_weak_pointer (&this.parent);
+ parent.add_weak_pointer (&this.parent_ptr);
}
}
~Container() {
if (this.parent != null) {
- this.parent.remove_weak_pointer (&this.parent);
+ this.parent.remove_weak_pointer (&this.parent_ptr);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]