Fixes inconsistencies in returned results.
https://bugzilla.gnome.org/show_bug.cgi?id=661482
this.requested_count,
this.object_id,
this.index);
+
var children = yield container.get_children (this.index,
this.requested_count,
+ this.sort_criteria,
this.cancellable);
+
debug ("Fetched %u children of container '%s' from index %u.",
this.requested_count,
this.object_id,
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws Error {
return yield container.search (expression,
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
}
0,
1,
out total_matches,
+ "",
this.cancellable);
if (result.size > 0) {
this.didl_item.upnp_class = upnp_class;
*
* @param offset zero-based index of the first item to return
* @param max_count maximum number of objects to return
+ * @param sort_criteria sorting order of objects to return
* @param cancellable optional cancellable for this operation
*
* @return A list of media objects.
*/
public async abstract MediaObjects? get_children (uint offset,
uint max_count,
+ string sort_criteria,
Cancellable? cancellable)
throws Error;
this.index,
this.requested_count,
out this.total_matches,
+ this.sort_criteria,
this.cancellable);
} else {
return yield container.search (parser.expression,
this.index,
this.requested_count,
out this.total_matches,
+ this.sort_criteria,
this.cancellable);
}
}
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws Error;
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws Error {
var result = new MediaObjects ();
var children = yield this.get_children (0,
this.child_count,
+ sort_criteria,
cancellable);
// The maximum number of results we need to be able to slice-out
if (limit == 0 || result.size < limit) {
// Then search in the children
var child_limit = (limit == 0)? 0: limit - result.size;
-
var child_results = yield this.search_in_children (expression,
children,
child_limit,
0,
1,
out total_matches,
+ "",
cancellable);
if (results.size > 0) {
return results[0];
0,
limit,
out tmp,
+ "",
cancellable);
result.add_all (child_result);
return unique;
}
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws Error {
+ public override async MediaObjects? get_children (
+ uint offset,
+ uint max_count,
+ string sort_criteria,
+ Cancellable? cancellable)
+ throws Error {
uint stop = offset + max_count;
stop = stop.clamp (0, this.child_count);
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws Error {
return yield this.simple_search (expression,
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
}
uint offset,
uint requested,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws Error {
// Drop the limit. WMP has a problem if we don't know the number of
offset,
0,
out total_matches,
+ sort_criteria,
cancellable);
}
}
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws Error {
var set_total_matches = false;
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
if (total_matches == 0 && set_total_matches) {
total_matches = results.size;
}
}
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? get_children (
+ uint offset,
+ uint max_count,
+ string sort_criteria,
+ Cancellable? cancellable)
+ throws GLib.Error {
string[] filter = {};
foreach (var object_prop in MediaObjectProxy.PROPERTIES) {
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws GLib.Error {
if (expression == null || !this.searchable) {
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
}
base (id, parent, title, (int) child_count);
}
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws Error {
+ public override async MediaObjects? get_children (
+ uint offset,
+ uint max_count,
+ string sort_criteria,
+ Cancellable? cancellable)
+ throws Error {
return new MediaObjects ();
}
- public override async MediaObject? find_object (string id,
+ public override async MediaObject? find_object (string id,
Cancellable? cancellable)
throws Error {
return null;
}
}
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? get_children (
+ uint offset,
+ uint max_count,
+ string sort_criteria,
+ Cancellable? cancellable)
+ throws GLib.Error {
return this.media_db.get_children (this, offset, max_count);
}
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws GLib.Error {
MediaObjects children = null;
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
} else {
throw error;
base (cache, expression, id, name);
}
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? get_children
+ (uint offset,
+ uint max_count,
+ string sort_criteria,
+ Cancellable? cancellable)
+ throws GLib.Error {
uint total_matches;
var children = yield this.search (null,
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
foreach (var child in children) {
child.parent = this;
// MediaContainer overrides
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? get_children
+ (uint offset,
+ uint max_count,
+ string sort_criteria,
+ Cancellable? cancellable)
+ throws GLib.Error {
var children = new MediaObjects ();
var data = this.media_db.get_object_attribute_by_search_expression
(this.attribute,
this.expression,
+ // sort criteria
offset,
max_count);
base.root ("MediaExport", 0);
}
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws Error {
+ public override async MediaObjects? get_children (
+ uint offset,
+ uint max_count,
+ string sort_criteria,
+ Cancellable? cancellable)
+ throws Error {
return new MediaObjects ();
}
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws GLib.Error {
MediaObjects children = null;
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws GLib.Error {
if (expression == null) {
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
}
if (query_container != null) {
list = yield query_container.get_children (offset,
max_count,
+ sort_criteria,
cancellable);
total_matches = query_container.child_count;
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
}
}
uint offset,
uint max_count,
out uint total_matches,
+ string sort_criteria,
Cancellable? cancellable)
throws Error {
return yield this.simple_search (expression,
offset,
max_count,
out total_matches,
+ sort_criteria,
cancellable);
}
/* class-wide constants */
private const string MODIFIED_PROPERTY = "nfo:fileLastModified";
+ private string sort_criteria = "";
+
public SelectionQuery query;
public ItemFactory item_factory;
}
}
- public override async MediaObjects? get_children (uint offset,
- uint max_count,
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ string sort_criteria,
Cancellable? cancellable)
throws GLib.Error {
var expression = new RelationalExpression ();
uint total_matches;
+ this.sort_criteria = sort_criteria;
+
return yield this.execute_query (expression,
offset,
max_count,
var query = this.create_query (expression as RelationalExpression,
(int) offset,
- (int) max_count);
+ (int) max_count,
+ this.sort_criteria);
if (query != null) {
yield query.execute (this.resources);
}
private SelectionQuery? create_query (RelationalExpression? expression,
- int offset,
- int max_count) {
+ int offset,
+ int max_count,
+ string sort_criteria = "") {
if (expression.operand1 == "upnp:class" &&
!this.item_factory.upnp_class.has_prefix (expression.operand2)) {
return null;
}
- var query = new SelectionQuery.clone (this.query);
+ SelectionQuery query;
+ if (sort_criteria == null || sort_criteria == "") {
+ query = new SelectionQuery.clone (this.query);
+ } else {
+ query = create_sorted_query ();
+ }
if (expression.operand1 == "@parentID") {
if (!expression.compare_string (this.id)) {
query.offset = offset;
query.max_count = max_count;
+ this.sort_criteria = "";
return query;
}
+ private SelectionQuery? create_sorted_query () {
+ var key_chain_map = UPnPPropertyMap.get_property_map ();
+ var sort_props = sort_criteria.split (",");
+ string order = "";
+ ArrayList<string> variables = new ArrayList<string> ();
+ ArrayList<string> filters = new ArrayList<string> ();
+
+ variables.add_all (this.query.variables);
+ filters.add_all (this.query.filters);
+
+ foreach (string s in sort_props) {
+ var key = key_chain_map[s.substring(1)];
+ if (key.index_of (SelectionQuery.ITEM_VARIABLE) == 0) {
+ continue;
+ }
+
+ if (s.has_prefix("-")) {
+ order += "DESC (" +
+ key + ") ";
+ } else {
+ order += key + " ";
+ }
+ }
+
+ if (order == "") {
+ order = this.query.order_by;
+ }
+
+ return new SelectionQuery (
+ variables,
+ new QueryTriplets.clone(this.query.triplets),
+ filters,
+ order);
+ }
+
private string? urn_to_utf8 (string urn) {
var urn_builder = new StringBuilder ();
unowned string s = urn;