[rygel/wip/gobject: 18/19] media-export: Most of container to GObject-style construction.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/gobject: 18/19] media-export: Most of container to GObject-style construction.
- Date: Tue, 22 Jan 2013 13:04:11 +0000 (UTC)
commit 784497b193acfcc87ad07d0ad8eee24a05df8b9c
Author: Krzesimir Nowak <krnowak openismus com>
Date: Tue Jan 22 12:04:19 2013 +0100
media-export: Most of container to GObject-style construction.
Also moved children counting in DBContainer to constructed call and
made it a virtual function. That way, when constructing
NodeQueryContainer the children counting will happen once instead of
three times as it used to be.
.../rygel-media-export-db-container.vala | 21 +++++++---
.../rygel-media-export-leaf-query-container.vala | 14 +++++-
.../rygel-media-export-node-query-container.vala | 45 +++++++++-----------
.../rygel-media-export-null-container.vala | 10 ++++-
.../rygel-media-export-query-container.vala | 20 +++------
.../rygel-media-export-root-container.vala | 7 ++-
.../rygel-media-export-trackable-db-container.vala | 9 +++-
.../rygel-media-export-writable-db-container.vala | 9 ++++-
8 files changed, 80 insertions(+), 55 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-db-container.vala b/src/plugins/media-export/rygel-media-export-db-container.vala
index 79415d2..28aec72 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -28,24 +28,33 @@ public class Rygel.MediaExport.DBContainer : MediaContainer,
public ArrayList<string> search_classes { get; set; }
public DBContainer (string id, string title) {
- base (id, null, title, 0);
+ Object (id : id,
+ parent : null,
+ title : title,
+ child_count : 0);
+ }
+
+ public override void constructed () {
+ base.constructed ();
try {
this.media_db = MediaCache.get_default ();
} catch (Error error) { }
this.search_classes = new ArrayList<string> ();
- this.container_updated.connect ( () => { this.count_children (); });
- this.count_children ();
+ this.container_updated.connect ( () => {
+ this.child_count = this.count_children ();
+ });
+ this.child_count = this.count_children ();
}
- private void count_children () {
+ public virtual int count_children () {
try {
- this.child_count = this.media_db.get_child_count (this.id);
+ return this.media_db.get_child_count (this.id);
} catch (DatabaseError error) {
debug ("Could not get child count from database: %s",
error.message);
- this.child_count = 0;
+ return 0;
}
}
diff --git a/src/plugins/media-export/rygel-media-export-leaf-query-container.vala b/src/plugins/media-export/rygel-media-export-leaf-query-container.vala
index c42ed0b..7edee98 100644
--- a/src/plugins/media-export/rygel-media-export-leaf-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-leaf-query-container.vala
@@ -22,7 +22,11 @@ internal class Rygel.MediaExport.LeafQueryContainer : QueryContainer {
public LeafQueryContainer (SearchExpression expression,
string id,
string name) {
- base (expression, id, name);
+ Object (id : id,
+ title : name,
+ parent : null,
+ child_count : 0,
+ expression : expression);
}
public override async MediaObjects? get_children
@@ -49,8 +53,12 @@ internal class Rygel.MediaExport.LeafQueryContainer : QueryContainer {
return children;
}
- protected override int count_children () throws Error {
- return (int) this.media_db.get_object_count_by_search_expression
+ public override int count_children () {
+ try {
+ return (int) this.media_db.get_object_count_by_search_expression
(this.expression, null);
+ } catch (Error error) {
+ return 0;
+ }
}
}
diff --git a/src/plugins/media-export/rygel-media-export-node-query-container.vala b/src/plugins/media-export/rygel-media-export-node-query-container.vala
index c0b14bc..c1a7dc5 100644
--- a/src/plugins/media-export/rygel-media-export-node-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-node-query-container.vala
@@ -19,25 +19,21 @@
*/
internal class Rygel.MediaExport.NodeQueryContainer : QueryContainer {
- private string template;
- private string attribute;
+ public string template { private get; construct; }
+ public string attribute { private get; construct; }
public NodeQueryContainer (SearchExpression expression,
string id,
string name,
string template,
string attribute) {
- base (expression, id, name);
-
- this.template = template;
- this.attribute = attribute;
-
- // base constructor does count_children but it depends on template and
- // attribute; so we have to call it again here after those two have
- // been set.
- try {
- this.child_count = this.count_children ();
- } catch (Error error) {};
+ Object (id : id,
+ title : name,
+ parent : null,
+ child_count : 0,
+ expression : expression,
+ template : template,
+ attribute : attribute);
}
// MediaContainer overrides
@@ -80,24 +76,23 @@ internal class Rygel.MediaExport.NodeQueryContainer : QueryContainer {
return children;
}
- // QueryContainer overrides
-
- protected override int count_children () throws Error {
- // Happens during construction
- if (this.attribute == null || this.expression == null) {
- return 0;
- }
+ // DBContainer overrides
- var data = this.media_db.get_object_attribute_by_search_expression
+ public override int count_children () {
+ try {
+ var data = this.media_db.get_object_attribute_by_search_expression
(this.attribute,
this.expression,
0,
-1);
- if (this.add_all_container ()) {
- return data.size + 1;
- }
+ if (this.add_all_container ()) {
+ return data.size + 1;
+ }
- return data.size;
+ return data.size;
+ } catch (Error error) {
+ return 0;
+ }
}
private bool add_all_container () {
diff --git a/src/plugins/media-export/rygel-media-export-null-container.vala b/src/plugins/media-export/rygel-media-export-null-container.vala
index 73d2fed..cb42fa9 100644
--- a/src/plugins/media-export/rygel-media-export-null-container.vala
+++ b/src/plugins/media-export/rygel-media-export-null-container.vala
@@ -30,11 +30,17 @@ internal class Rygel.NullContainer : MediaContainer {
public NullContainer (string id,
MediaContainer? parent,
string title) {
- base(id, parent, title, 0);
+ Object (id : id,
+ title : title,
+ parent : parent,
+ child_count : 0);
}
public NullContainer.root () {
- base.root("MediaExport", 0);
+ Object (id : "0",
+ parent : null,
+ title : "MediaExport",
+ child_count : 0);
}
public override async MediaObjects? get_children (
diff --git a/src/plugins/media-export/rygel-media-export-query-container.vala b/src/plugins/media-export/rygel-media-export-query-container.vala
index 97999d1..38d49ea 100644
--- a/src/plugins/media-export/rygel-media-export-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-query-container.vala
@@ -26,22 +26,18 @@ internal abstract class Rygel.MediaExport.QueryContainer : DBContainer {
public static const string PREFIX = "virtual-container:";
public static const string ITEM_PREFIX = "virtual-id:";
- // protected members
- protected SearchExpression expression;
+ // public members
+ public SearchExpression expression { get; construct set; }
// constructors
public QueryContainer (SearchExpression expression,
string id,
string name) {
- base (id, name);
-
- this.expression = expression;
-
- try {
- this.child_count = this.count_children ();
- } catch (Error error) {
- this.child_count = 0;
- }
+ Object (id : id,
+ parent : null,
+ title : name,
+ child_count : 0,
+ expression : expression);
}
// public methods
@@ -85,6 +81,4 @@ internal abstract class Rygel.MediaExport.QueryContainer : DBContainer {
return children;
}
-
- protected abstract int count_children () throws Error;
}
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index 870f6ba..d981fe4 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -346,8 +346,11 @@ public class Rygel.MediaExport.RootContainer : TrackableDbContainer {
/**
* Create a new root container.
*/
- private RootContainer () throws Error {
- base ("0", _("@REALNAME@'s media"));
+ private RootContainer () {
+ Object (id : "id",
+ title : _("@REALNAME@'s media"),
+ parent : null,
+ child_count : 0);
}
private bool initialized = false;
diff --git a/src/plugins/media-export/rygel-media-export-trackable-db-container.vala b/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
index af41c00..aac9a35 100644
--- a/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
@@ -24,10 +24,13 @@ using Gee;
/**
* A DB container that is trackable.
*/
-public class Rygel.MediaExport.TrackableDbContainer : TrackableContainer,
- DBContainer {
+public class Rygel.MediaExport.TrackableDbContainer : DBContainer,
+ TrackableContainer {
public TrackableDbContainer (string id, string title) {
- base (id, title);
+ Object (id : id,
+ title : title,
+ parent : null,
+ child_count : 0);
}
// TrackableContainer virtual function implementations:
diff --git a/src/plugins/media-export/rygel-media-export-writable-db-container.vala b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
index 789d65d..d8940b9 100644
--- a/src/plugins/media-export/rygel-media-export-writable-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
@@ -33,7 +33,14 @@ internal class Rygel.MediaExport.WritableDbContainer : TrackableDbContainer,
public ArrayList<string> create_classes { get; set; }
public WritableDbContainer (string id, string title) {
- base (id, title);
+ Object (id : id,
+ title : title,
+ parent : null,
+ child_count : 0);
+ }
+
+ public override void constructed () {
+ base.constructed ();
this.create_classes = new ArrayList<string> ();
this.create_classes.add (Rygel.ImageItem.UPNP_CLASS);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]