public signal void sub_tree_updates_finished (MediaObject sub_tree_root);
public int child_count { get; set construct; }
+ protected int empty_child_count;
+ public int all_child_count {
+ get {
+ return this.child_count + this.empty_child_count;
+ }
+ }
public uint32 update_id;
public int64 storage_used;
+ public bool create_mode_enabled;
// This is an uint32 in UPnP. SystemUpdateID should reach uint32.MAX way
// before this variable and cause a SystemResetProcedure.
public override void constructed () {
base.constructed ();
+ this.empty_child_count = 0;
this.update_id = 0;
this.storage_used = -1;
this.total_deleted_child_count = 0;
this.upnp_class = STORAGE_FOLDER;
+ this.create_mode_enabled = false;
this.container_updated.connect (on_container_updated);
this.sub_tree_updates_finished.connect (on_sub_tree_updates_finished);
this.parent.sub_tree_updates_finished (sub_tree_root);
}
}
+
+ internal void check_search_expression (SearchExpression? expression) {
+ this.create_mode_enabled = false;
+ if (expression != null && expression is RelationalExpression) {
+ var relational_exp = expression as RelationalExpression;
+ if (relational_exp.op == SearchCriteriaOp.DERIVED_FROM &&
+ relational_exp.operand1 == "upnp:createClass") {
+ this.create_mode_enabled = true;
+ }
+ }
+ }
}
throws Error {
var result = new MediaObjects ();
+ int count = this.child_count;
+ this.check_search_expression (expression);
+
+ if (this.create_mode_enabled) {
+ count = this.all_child_count;
+ }
+
var children = yield this.get_children (0,
- this.child_count,
+ count,
sort_criteria,
cancellable);
"until it has any children to offer.",
child.id);
this.empty_children.add (child);
+ this.empty_child_count++;
child.container_updated.connect (this.on_container_updated);
}
}
Cancellable? cancellable)
throws Error {
uint stop = offset + max_count;
- stop = stop.clamp (0, this.child_count);
+ MediaObjects unsorted_children;
- var sorted_children = this.children.slice (0, this.child_count)
+ if (this.create_mode_enabled) {
+ stop = stop.clamp (0, this.all_child_count);
+ unsorted_children = this.get_all_children ();
+ } else {
+ stop = stop.clamp (0, this.child_count);
+
+ unsorted_children = this.children.slice (0, this.child_count)
as MediaObjects;
- sorted_children.sort_by_criteria (sort_criteria);
+ }
+
+ unsorted_children.sort_by_criteria (sort_criteria);
- return sorted_children.slice ((int) offset, (int) stop)
+ return unsorted_children.slice ((int) offset, (int) stop)
as MediaObjects;
}
Cancellable? cancellable)
throws Error {
MediaObject media_object = null;
+ var max_count = 0;
var restart_count = 0;
var restart = false;
+ if (this.create_mode_enabled) {
+ max_count = this.all_child_count;
+ } else {
+ max_count = this.child_count;
+ }
+ var children_to_search = yield this.get_children (0, max_count, "", cancellable);
+
do {
restart = false;
ulong updated_id = 0;
- foreach (var child in this.children) {
+ foreach (var child in children_to_search) {
if (child.id == id) {
media_object = child;
}
this.empty_children.remove (updated);
+ this.empty_child_count--;
this.add_child (updated);
this.remove_child (updated);
this.empty_children.add (updated);
+ this.empty_child_count++;
this.updated ();
public class MediaContainer : MediaObject {
public string sort_criteria = "+dc:title";
- public uint child_count = 10;
+ public int child_count = 10;
+ public bool create_mode_enabled = false;
+ public int all_child_count {
+ get { return this.child_count; }
+ }
public async MediaObjects? get_children (
uint offset,
uint max_count,
return result;
}
+
+ internal void check_search_expression (SearchExpression? expression) {}
}
public class TestContainer : MediaContainer, Rygel.SearchableContainer {