diff options
author | Iago Toral Quiroga <itoral@igalia.com> | 2010-03-10 08:19:40 +0100 |
---|---|---|
committer | Iago Toral Quiroga <itoral@igalia.com> | 2010-03-10 08:19:40 +0100 |
commit | 486bae040a57249773bed3fdee293d5e22babae7 (patch) | |
tree | e1057844a311648395630936533862790e4993a1 | |
parent | a4b22a81bda45f52f280078772252acc824b7dea (diff) |
[core] Added APIs to modify metadata
-rw-r--r-- | src/grl-metadata-source.c | 76 | ||||
-rw-r--r-- | src/grl-metadata-source.h | 50 |
2 files changed, 126 insertions, 0 deletions
diff --git a/src/grl-metadata-source.c b/src/grl-metadata-source.c index 94bd04c..f0ffc65 100644 --- a/src/grl-metadata-source.c +++ b/src/grl-metadata-source.c @@ -283,6 +283,16 @@ resolve_idle (gpointer user_data) return FALSE; } +static gboolean +set_metadata_idle (gpointer user_data) +{ + g_debug ("set_metadata_idle"); + GrlMetadataSourceSetMetadataSpec *sms = + (GrlMetadataSourceSetMetadataSpec *) user_data; + GRL_METADATA_SOURCE_GET_CLASS (sms->source)->set_metadata (sms->source, sms); + return FALSE; +} + /* ================ API ================ */ /** @@ -340,6 +350,27 @@ grl_metadata_source_key_depends (GrlMetadataSource *source, GrlKeyID key_id) } /** + * grl_metadata_source_writable_keys: + * @source: a metadata source + * + * Similar to grl_metadata_source_supported_keys(), but these keys + * are marked as writable, meaning the source allows the client + * to provide new values for these keys that will be stored permanently. + * + * Returns: (transfer none) (allow-none): a #GList with the keys + */ +const GList * +grl_metadata_source_writable_keys (GrlMetadataSource *source) +{ + g_return_val_if_fail (GRL_IS_METADATA_SOURCE (source), NULL); + if (GRL_METADATA_SOURCE_GET_CLASS (source)->writable_keys) { + return GRL_METADATA_SOURCE_GET_CLASS (source)->writable_keys (source); + } else { + return NULL; + } +} + +/** * grl_metadata_source_resolve: * @source: a metadata source * @keys: the #GList of #GrlKeyID to retrieve @@ -716,6 +747,48 @@ grl_metadata_source_get_description (GrlMetadataSource *source) } /** + * grl_metadata_source_set_metadata: + * @source: a metadata source + * @media: the #GrlMedia object that we want to operate on. + * @key: a #GrlKeyID which value we want to change. + * @callback: the callback to execute when the operation is finished. + * @user_data: user data set for the @callback + * + * This is the main method of the #GrlMetadataSource class. It will + * get the value for @key from @media and store it permanently. After + * calling this method, future queries that return this media object + * shall return this new value for the selected key. + * + * This function is asynchronic and uses the Glib's main loop. + */ +void +grl_metadata_source_set_metadata (GrlMetadataSource *source, + GrlMedia *media, + GrlKeyID key_id, + GrlMetadataSourceSetMetadataCb callback, + gpointer user_data) +{ + GrlMetadataSourceSetMetadataSpec *sms; + + g_debug ("grl_metadata_source_set_metadata"); + + g_return_if_fail (GRL_IS_METADATA_SOURCE (source)); + g_return_if_fail (callback != NULL); + g_return_if_fail (media != NULL); + g_return_if_fail (grl_metadata_source_supported_operations (source) & + GRL_OP_SET_METADATA); + + sms = g_new0 (GrlMetadataSourceSetMetadataSpec, 1); + sms->source = g_object_ref (source); + sms->media = g_object_ref (media); + sms->key_id = key_id; + sms->callback = callback; + sms->user_data = user_data; + + g_idle_add (set_metadata_idle, sms); +} + +/** * grl_metadata_source_supported_operations: * @source: a metadata source * @@ -738,5 +811,8 @@ grl_metadata_source_supported_operations_impl (GrlMetadataSource *source) metadata_source_class = GRL_METADATA_SOURCE_GET_CLASS (source); if (metadata_source_class->resolve) caps |= GRL_OP_RESOLVE; + if (metadata_source_class->set_metadata) + caps |= GRL_OP_SET_METADATA; return caps; } + diff --git a/src/grl-metadata-source.h b/src/grl-metadata-source.h index e95ab27..e5033da 100644 --- a/src/grl-metadata-source.h +++ b/src/grl-metadata-source.h @@ -103,6 +103,21 @@ typedef void (*GrlMetadataSourceResolveCb) (GrlMetadataSource *source, GrlMedia *media, gpointer user_data, const GError *error); + +/** + * GrlMetadataSourceSetMetadataCb: + * @source: a metadata source + * @media: a #GrlMedia transfer object + * @user_data: user data passed to grl_metadata_source_set_metadata() + * @error: (not-error): possible #GError generated when updating the metadata + * + * Prototype for the callback passed to grl_metadata_source_set_metadata() + */ +typedef void (*GrlMetadataSourceSetMetadataCb) (GrlMetadataSource *source, + GrlMedia *media, + gpointer user_data, + const GError *error); + /* Types for GrlMetadataSource */ /** @@ -128,6 +143,24 @@ typedef struct { } GrlMetadataSourceResolveSpec; /** + * GrlMetadataSourceSetMetadataSpec: + * @source: a metadata source + * @media: a #GrlMedia transfer object + * @key_id: Key which value is to be stored + * @callback: the callback passed to grl_metadata_source_set_metadata() + * @user_data: user data passed to grl_metadata_source_set_metadata() + * + * Represents the closure used by the derived objects to operate. + */ +typedef struct { + GrlMetadataSource *source; + GrlMedia *media; + GrlKeyID key_id; + GrlMetadataSourceSetMetadataCb callback; + gpointer user_data; +} GrlMetadataSourceSetMetadataSpec; + +/** * GrlSupportedOps: * @GRL_OP_NONE: no one operation is supported * @GRL_OP_METADATA: TBD @@ -152,6 +185,7 @@ typedef enum { GRL_OP_STORE = 1 << 5, GRL_OP_STORE_PARENT = 1 << 6, GRL_OP_REMOVE = 1 << 7, + GRL_OP_SET_METADATA = 1 << 8, } GrlSupportedOps; /* GrlMetadataSource class */ @@ -165,7 +199,10 @@ typedef struct _GrlMetadataSourceClass GrlMetadataSourceClass; * @supported_keys: the list of keys that can be handled * @slow_keys: the list of slow keys that can be fetched * @key_depends: the list of keys which @key_id depends on + * @writable_keys: the list of keys which value can be written * @resolve: resolve the metadata of a given transfer object + * @set_metadata: update metadata values for a given object in a + * permanent fashion * * Grilo MetadataSource class. Override the vmethods to implement the * element functionality. @@ -182,8 +219,13 @@ struct _GrlMetadataSourceClass { const GList * (*key_depends) (GrlMetadataSource *source, GrlKeyID key_id); + const GList * (*writable_keys) (GrlMetadataSource *source); + void (*resolve) (GrlMetadataSource *source, GrlMetadataSourceResolveSpec *rs); + + void (*set_metadata) (GrlMetadataSource *source, + GrlMetadataSourceSetMetadataSpec *sms); }; G_BEGIN_DECLS @@ -207,6 +249,8 @@ GList *grl_metadata_source_filter_slow (GrlMetadataSource *source, const GList *grl_metadata_source_key_depends (GrlMetadataSource *source, GrlKeyID key_id); +const GList *grl_metadata_source_writable_keys (GrlMetadataSource *source); + void grl_metadata_source_resolve (GrlMetadataSource *source, const GList *keys, GrlMedia *media, @@ -214,6 +258,12 @@ void grl_metadata_source_resolve (GrlMetadataSource *source, GrlMetadataSourceResolveCb callback, gpointer user_data); +void grl_metadata_source_set_metadata (GrlMetadataSource *source, + GrlMedia *media, + GrlKeyID key_id, + GrlMetadataSourceSetMetadataCb callback, + gpointer user_data); + const gchar *grl_metadata_source_get_id (GrlMetadataSource *source); const gchar *grl_metadata_source_get_name (GrlMetadataSource *source); |