[PATCH 1/1] Add 'sort' parameter to browse(), search() and query() functions
- From: "Juan A. Suarez Romero" <jasuarez igalia com>
- To: grilo-list gnome org
- Subject: [PATCH 1/1] Add 'sort' parameter to browse(), search() and query() functions
- Date: Thu, 8 Jul 2010 18:15:29 +0200
'sort' is a list of metadata keys.
Sources will try to sort the results following the list of keys. If some of the
keys are not supported or can be used to sort the results, then they will be
skipped. As case extreme, if source does not support sorting, it will ignore
this parameter.
---
bindings/vala/grilo-0.1.vapi | 6 +++---
bindings/vala/grilo-0.1/grilo-0.1.gi | 3 +++
src/grl-media-source.c | 18 ++++++++++++++++++
src/grl-media-source.h | 9 +++++++++
src/grl-multiple.c | 1 +
tools/grilo-test-ui/main.c | 32 ++++++++++++++++++++++++++++----
tools/vala/grilo-test.vala | 2 +-
7 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/bindings/vala/grilo-0.1.vapi b/bindings/vala/grilo-0.1.vapi
index 567d56a..1979c51 100644
--- a/bindings/vala/grilo-0.1.vapi
+++ b/bindings/vala/grilo-0.1.vapi
@@ -92,14 +92,14 @@ namespace Grl {
}
[CCode (cheader_filename = "grilo.h")]
public class MediaSource : Grl.MetadataSource {
- public virtual void browse (Grl.Media container, GLib.List keys, uint skip, uint count, Grl.MetadataResolutionFlags flags, Grl.MediaSourceResultCb callback);
+ public virtual void browse (Grl.Media container, GLib.List keys, GLib.List sort, uint skip, uint count, Grl.MetadataResolutionFlags flags, Grl.MediaSourceResultCb callback);
public virtual void cancel (uint operation_id);
public uint get_auto_split_threshold ();
public void* get_operation_data (uint operation_id);
public virtual void metadata (Grl.Media media, GLib.List keys, Grl.MetadataResolutionFlags flags, Grl.MediaSourceMetadataCb callback);
- public virtual void query (string query, GLib.List keys, uint skip, uint count, Grl.MetadataResolutionFlags flags, Grl.MediaSourceResultCb callback);
+ public virtual void query (string query, GLib.List keys, GLib.List sort, uint skip, uint count, Grl.MetadataResolutionFlags flags, Grl.MediaSourceResultCb callback);
public virtual void remove (Grl.Media media, Grl.MediaSourceRemoveCb callback);
- public virtual void search (string text, GLib.List keys, uint skip, uint count, Grl.MetadataResolutionFlags flags, Grl.MediaSourceResultCb callback);
+ public virtual void search (string text, GLib.List keys, GLib.List sort, uint skip, uint count, Grl.MetadataResolutionFlags flags, Grl.MediaSourceResultCb callback);
public void set_auto_split_threshold (uint threshold);
public void set_operation_data (uint operation_id, void* data);
public virtual void store (Grl.MediaBox parent, Grl.Media media, Grl.MediaSourceStoreCb callback);
diff --git a/bindings/vala/grilo-0.1/grilo-0.1.gi b/bindings/vala/grilo-0.1/grilo-0.1.gi
index 08f1ead..9224761 100644
--- a/bindings/vala/grilo-0.1/grilo-0.1.gi
+++ b/bindings/vala/grilo-0.1/grilo-0.1.gi
@@ -433,6 +433,7 @@
<parameter name="source" type="GrlMediaSource*"/>
<parameter name="container" type="GrlMedia*"/>
<parameter name="keys" type="GList*"/>
+ <parameter name="sort" type="GList*"/>
<parameter name="skip" type="guint"/>
<parameter name="count" type="guint"/>
<parameter name="flags" type="GrlMetadataResolutionFlags"/>
@@ -477,6 +478,7 @@
<parameter name="source" type="GrlMediaSource*"/>
<parameter name="query" type="gchar*"/>
<parameter name="keys" type="GList*"/>
+ <parameter name="sort" type="GList*"/>
<parameter name="skip" type="guint"/>
<parameter name="count" type="guint"/>
<parameter name="flags" type="GrlMetadataResolutionFlags"/>
@@ -499,6 +501,7 @@
<parameter name="source" type="GrlMediaSource*"/>
<parameter name="text" type="gchar*"/>
<parameter name="keys" type="GList*"/>
+ <parameter name="sort" type="GList*"/>
<parameter name="skip" type="guint"/>
<parameter name="count" type="guint"/>
<parameter name="flags" type="GrlMetadataResolutionFlags"/>
diff --git a/src/grl-media-source.c b/src/grl-media-source.c
index 122b689..bc26aee 100644
--- a/src/grl-media-source.c
+++ b/src/grl-media-source.c
@@ -406,6 +406,7 @@ free_browse_operation_spec (GrlMediaSourceBrowseSpec *spec)
g_object_unref (spec->source);
g_object_unref (spec->container);
g_list_free (spec->keys);
+ g_list_free (spec->sort);
g_free (spec);
}
@@ -416,6 +417,7 @@ free_search_operation_spec (GrlMediaSourceSearchSpec *spec)
g_object_unref (spec->source);
g_free (spec->text);
g_list_free (spec->keys);
+ g_list_free (spec->sort);
g_free (spec);
}
@@ -426,6 +428,7 @@ free_query_operation_spec (GrlMediaSourceQuerySpec *spec)
g_object_unref (spec->source);
g_free (spec->query);
g_list_free (spec->keys);
+ g_list_free (spec->sort);
g_free (spec);
}
@@ -1093,6 +1096,7 @@ metadata_full_resolution_ctl_cb (GrlMediaSource *source,
* @source: a media source
* @container: a container of data transfer objects
* @keys: the list of #GrlKeyID to request
+ * @sort: the list of #GrlKeyID used to sort results
* @skip: the number if elements to skip in the browse operation
* @count: the number of elements to retrieve in the browse operation
* @flags: the resolution mode
@@ -1109,6 +1113,7 @@ guint
grl_media_source_browse (GrlMediaSource *source,
GrlMedia *container,
const GList *keys,
+ const GList *sort,
guint skip,
guint count,
GrlMetadataResolutionFlags flags,
@@ -1118,6 +1123,7 @@ grl_media_source_browse (GrlMediaSource *source,
GrlMediaSourceResultCb _callback;
gpointer _user_data ;
GList *_keys;
+ GList *_sort;
struct SourceKeyMapList key_mapping;
GrlMediaSourceBrowseSpec *bs;
guint browse_id;
@@ -1133,6 +1139,7 @@ grl_media_source_browse (GrlMediaSource *source,
/* By default assume we will use the parameters specified by the user */
_keys = g_list_copy ((GList *) keys);
+ _sort = g_list_copy ((GList *) sort);
_callback = callback;
_user_data = user_data;
@@ -1185,6 +1192,7 @@ grl_media_source_browse (GrlMediaSource *source,
bs->source = g_object_ref (source);
bs->browse_id = browse_id;
bs->keys = _keys;
+ bs->sort = _sort;
bs->skip = skip;
bs->count = count;
bs->flags = flags;
@@ -1231,6 +1239,7 @@ grl_media_source_browse (GrlMediaSource *source,
* @keys: the list of #GrlKeyID to request
* @skip: the number if elements to skip in the search operation
* @count: the number of elements to retrieve in the search operation
+ * @sort: the list of #GrlKeyID used to sort results
* @flags: the resolution mode
* @callback: the user defined callback
* @user_data: the user data to pass in the callback
@@ -1246,6 +1255,7 @@ guint
grl_media_source_search (GrlMediaSource *source,
const gchar *text,
const GList *keys,
+ const GList *sort,
guint skip,
guint count,
GrlMetadataResolutionFlags flags,
@@ -1255,6 +1265,7 @@ grl_media_source_search (GrlMediaSource *source,
GrlMediaSourceResultCb _callback;
gpointer _user_data ;
GList *_keys;
+ GList *_sort;
struct SourceKeyMapList key_mapping;
GrlMediaSourceSearchSpec *ss;
guint search_id;
@@ -1273,6 +1284,7 @@ grl_media_source_search (GrlMediaSource *source,
_callback = callback;
_user_data = user_data;
_keys = g_list_copy ((GList *) keys);
+ _sort = g_list_copy ((GList *) sort);
if (flags & GRL_RESOLVE_FAST_ONLY) {
g_debug ("requested fast keys only");
@@ -1318,6 +1330,7 @@ grl_media_source_search (GrlMediaSource *source,
ss->search_id = search_id;
ss->text = g_strdup (text);
ss->keys = _keys;
+ ss->sort = _sort;
ss->skip = skip;
ss->count = count;
ss->flags = flags;
@@ -1357,6 +1370,7 @@ grl_media_source_search (GrlMediaSource *source,
* @keys: the list of #GrlKeyID to request
* @skip: the number if elements to skip in the query operation
* @count: the number of elements to retrieve in the query operation
+ * @sort: the list of #GrlKeyID used to sort results
* @flags: the resolution mode
* @callback: the user defined callback
* @user_data: the user data to pass in the callback
@@ -1376,6 +1390,7 @@ guint
grl_media_source_query (GrlMediaSource *source,
const gchar *query,
const GList *keys,
+ const GList *sort,
guint skip,
guint count,
GrlMetadataResolutionFlags flags,
@@ -1385,6 +1400,7 @@ grl_media_source_query (GrlMediaSource *source,
GrlMediaSourceResultCb _callback;
gpointer _user_data ;
GList *_keys;
+ GList *_sort;
struct SourceKeyMapList key_mapping;
GrlMediaSourceQuerySpec *qs;
guint query_id;
@@ -1403,6 +1419,7 @@ grl_media_source_query (GrlMediaSource *source,
_callback = callback;
_user_data = user_data;
_keys = g_list_copy ((GList *) keys);
+ _sort = g_list_copy ((GList *) sort);
if (flags & GRL_RESOLVE_FAST_ONLY) {
g_debug ("requested fast keys only");
@@ -1450,6 +1467,7 @@ grl_media_source_query (GrlMediaSource *source,
qs->query_id = query_id;
qs->query = g_strdup (query);
qs->keys = _keys;
+ qs->sort = _sort;
qs->skip = skip;
qs->count = count;
qs->flags = flags;
diff --git a/src/grl-media-source.h b/src/grl-media-source.h
index bc167c0..affa65a 100644
--- a/src/grl-media-source.h
+++ b/src/grl-media-source.h
@@ -148,6 +148,7 @@ typedef void (*GrlMediaSourceRemoveCb) (GrlMediaSource *source,
* @browse_id: operation identifier
* @container: a container of data transfer objects
* @keys: the list of #GrlKeyID to request
+ * @sort: the list of #GrlKeyID used to sort results
* @skip: the number if elements to skip in the browse operation
* @count: the number of elements to retrieve in the browse operation
* @flags: the resolution mode
@@ -162,6 +163,7 @@ typedef struct {
guint browse_id;
GrlMedia *container;
GList *keys;
+ GList *sort;
guint skip;
guint count;
GrlMetadataResolutionFlags flags;
@@ -175,6 +177,7 @@ typedef struct {
* @search_id: operation identifier
* @text: the text to search
* @keys: the list of #GrlKeyID to request
+ * @sort: the list of #GrlKeyID used to sort results
* @skip: the number if elements to skip in the browse operation
* @count: the number of elements to retrieve in the browse operation
* @flags: the resolution mode
@@ -189,6 +192,7 @@ typedef struct {
guint search_id;
gchar *text;
GList *keys;
+ GList *sort;
guint skip;
guint count;
GrlMetadataResolutionFlags flags;
@@ -202,6 +206,7 @@ typedef struct {
* @query_id: operation identifier
* @query: the query to process
* @keys: the list of #GrlKeyID to request
+ * @sort: the list of #GrlKeyID used to sort results
* @skip: the number if elements to skip in the browse operation
* @count: the number of elements to retrieve in the browse operation
* @flags: the resolution mode
@@ -216,6 +221,7 @@ typedef struct {
guint query_id;
gchar *query;
GList *keys;
+ GList *sort;
guint skip;
guint count;
GrlMetadataResolutionFlags flags;
@@ -329,6 +335,7 @@ GType grl_media_source_get_type (void);
guint grl_media_source_browse (GrlMediaSource *source,
GrlMedia *container,
const GList *keys,
+ const GList *sort,
guint skip,
guint count,
GrlMetadataResolutionFlags flags,
@@ -338,6 +345,7 @@ guint grl_media_source_browse (GrlMediaSource *source,
guint grl_media_source_search (GrlMediaSource *source,
const gchar *text,
const GList *keys,
+ const GList *sort,
guint skip,
guint count,
GrlMetadataResolutionFlags flags,
@@ -347,6 +355,7 @@ guint grl_media_source_search (GrlMediaSource *source,
guint grl_media_source_query (GrlMediaSource *source,
const gchar *query,
const GList *keys,
+ const GList *sort,
guint skip,
guint count,
GrlMetadataResolutionFlags flags,
diff --git a/src/grl-multiple.c b/src/grl-multiple.c
index 7bacfbf..c379990 100644
--- a/src/grl-multiple.c
+++ b/src/grl-multiple.c
@@ -198,6 +198,7 @@ start_multiple_search_operation (guint search_id,
id = grl_media_source_search (source,
msd->text,
msd->keys,
+ NULL,
skip, rc->count,
flags,
multiple_search_cb,
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index ab75550..1d3396b 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -243,10 +243,29 @@ get_icon_for_media (GrlMedia *media)
static GList *
browse_keys (void)
{
- return grl_metadata_key_list_new (GRL_METADATA_KEY_ID,
- GRL_METADATA_KEY_TITLE,
- GRL_METADATA_KEY_CHILDCOUNT,
- NULL);
+ GList *list = NULL;
+
+ if (!list) {
+ list = grl_metadata_key_list_new (GRL_METADATA_KEY_ID,
+ GRL_METADATA_KEY_TITLE,
+ GRL_METADATA_KEY_CHILDCOUNT,
+ NULL);
+ }
+
+ return list;
+}
+
+static GList *
+sort_keys (void)
+{
+ GList *list = NULL;
+
+ if (!list) {
+ list = grl_metadata_key_list_new (GRL_METADATA_KEY_TITLE,
+ NULL);
+ }
+
+ return list;
}
static GList *
@@ -511,6 +530,7 @@ browse_cb (GrlMediaSource *source,
grl_media_source_browse (source,
ui_state->cur_container,
browse_keys (),
+ sort_keys (),
state->offset, BROWSE_CHUNK_SIZE,
BROWSE_FLAGS,
browse_cb,
@@ -547,6 +567,7 @@ browse (GrlMediaSource *source, GrlMedia *container)
browse_id = grl_media_source_browse (source,
container,
browse_keys (),
+ sort_keys (),
0, BROWSE_CHUNK_SIZE,
BROWSE_FLAGS,
browse_cb,
@@ -960,6 +981,7 @@ search_cb (GrlMediaSource *source,
grl_media_source_search (source,
state->text,
browse_keys (),
+ sort_keys (),
state->offset, BROWSE_CHUNK_SIZE,
BROWSE_FLAGS,
search_cb,
@@ -995,6 +1017,7 @@ search (GrlMediaSource *source, const gchar *text)
search_id = grl_media_source_search (source,
text,
browse_keys (),
+ sort_keys (),
0, BROWSE_CHUNK_SIZE,
BROWSE_FLAGS,
search_cb,
@@ -1049,6 +1072,7 @@ query (GrlMediaSource *source, const gchar *text)
query_id = grl_media_source_query (source,
text,
browse_keys (),
+ sort_keys (),
0, BROWSE_CHUNK_SIZE,
BROWSE_FLAGS,
search_cb,
diff --git a/tools/vala/grilo-test.vala b/tools/vala/grilo-test.vala
index 59eb585..224acbe 100644
--- a/tools/vala/grilo-test.vala
+++ b/tools/vala/grilo-test.vala
@@ -68,7 +68,7 @@ public class SimplePlaylist : Object {
foreach (MediaSource source in source_list) {
debug ("%s - %s", source.get_name (), q);
- source.search (q, keys, 0, 100, Grl.MetadataResolutionFlags.FULL | Grl.MetadataResolutionFlags.IDLE_RELAY, search_cb);
+ source.search (q, keys, null, 0, 100, Grl.MetadataResolutionFlags.FULL | Grl.MetadataResolutionFlags.IDLE_RELAY, search_cb);
}
}
--
1.7.0.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]