[grilo] core: Add support for two new operations in GrlMediaSource - test_media_from_site - get_
- From: Iago Toral Quiroga <itoral src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo] core: Add support for two new operations in GrlMediaSource - test_media_from_site - get_
- Date: Mon, 13 Dec 2010 11:47:08 +0000 (UTC)
commit 93d48590067290d4792f2285e0647df20debb247
Author: Iago Toral Quiroga <itoral igalia com>
Date: Wed Dec 1 18:24:05 2010 +0100
core: Add support for two new operations in GrlMediaSource
- test_media_from_site
- get_media_from_site
https://bugzilla.gnome.org/show_bug.cgi?id=635394
src/grl-media-source.c | 97 +++++++++++++++++++++++++++++++++++++++++++++
src/grl-media-source.h | 36 +++++++++++++++++
src/grl-metadata-source.h | 22 ++++++-----
3 files changed, 145 insertions(+), 10 deletions(-)
---
diff --git a/src/grl-media-source.c b/src/grl-media-source.c
index 9aa3873..4c43bbb 100644
--- a/src/grl-media-source.c
+++ b/src/grl-media-source.c
@@ -541,6 +541,27 @@ remove_idle (gpointer user_data)
return FALSE;
}
+static void
+media_from_site_idle_destroy (gpointer user_data)
+{
+ GrlMediaSourceMediaFromSiteSpec *mfss =
+ (GrlMediaSourceMediaFromSiteSpec *) user_data;
+ g_object_unref (mfss->source);
+ g_free (mfss->site_uri);
+ g_free (mfss);
+}
+
+static gboolean
+media_from_site_idle (gpointer user_data)
+{
+ GRL_DEBUG ("media_from_site_idle");
+ GrlMediaSourceMediaFromSiteSpec *mfss =
+ (GrlMediaSourceMediaFromSiteSpec *) user_data;
+ GRL_MEDIA_SOURCE_GET_CLASS (mfss->source)->media_from_site (mfss->source,
+ mfss);
+ return FALSE;
+}
+
static gboolean
browse_result_relay_idle (gpointer user_data)
{
@@ -1942,6 +1963,9 @@ grl_media_source_supported_operations (GrlMetadataSource *metadata_source)
caps |= GRL_OP_STORE;
if (media_source_class->remove)
caps |= GRL_OP_REMOVE;
+ if (media_source_class->test_media_from_site &&
+ media_source_class->media_from_site)
+ caps |= GRL_OP_MEDIA_FROM_SITE;
return caps;
}
@@ -2253,3 +2277,76 @@ grl_media_source_remove_sync (GrlMediaSource *source,
g_slice_free (GrlDataSync, ds);
}
+
+/**
+ * grl_media_source_test_media_from_site:
+ * @source: a media source
+ * @site_uri: The media site URI
+ *
+ * Tests whether @source can instantiate a #GrlMedia object representing
+ * the media resource exposed at @site_uri.
+ *
+ * Returns: %TRUE if it can, %FALSE otherwise.
+ *
+ * This method is synchronous.
+ */
+gboolean
+grl_media_source_test_media_from_site (GrlMediaSource *source,
+ const gchar *site_uri)
+{
+ GRL_DEBUG ("grl_media_source_test_media_from_site");
+
+ g_return_val_if_fail (GRL_IS_MEDIA_SOURCE (source), FALSE);
+ g_return_val_if_fail (site_uri != NULL, FALSE);
+
+ if (GRL_MEDIA_SOURCE_GET_CLASS (source)->test_media_from_site) {
+ return GRL_MEDIA_SOURCE_GET_CLASS (source)->test_media_from_site (source,
+ site_uri);
+ } else {
+ return FALSE;
+ }
+}
+
+/**
+ * grl_media_source_get_media_from_site:
+ * @source: a media source
+ * @site_uri: The media site URI
+ * @callback: (scope notified): the user defined callback
+ * @user_data: the user data to pass in the callback
+ *
+ * Creates an instance of #GrlMedia representing the media resource
+ * exposed at @site_uri.
+ *
+ * It is recommended to call grl_media_source_test_media_from_site() before
+ * invoking this to check whether the target source can theoretically do the
+ * resolution.
+ *
+ * This method is asynchronous.
+ */
+void
+grl_media_source_get_media_from_site (GrlMediaSource *source,
+ const gchar *site_uri,
+ GrlMediaSourceMetadataCb callback,
+ gpointer user_data)
+{
+ GRL_DEBUG ("grl_media_source_get_media_from_site");
+
+ GrlMediaSourceMediaFromSiteSpec *mfss;
+
+ g_return_if_fail (GRL_IS_MEDIA_SOURCE (source));
+ g_return_if_fail (site_uri != NULL);
+ g_return_if_fail (callback != NULL);
+ g_return_if_fail (grl_metadata_source_supported_operations (GRL_METADATA_SOURCE (source)) &
+ GRL_OP_MEDIA_FROM_SITE);
+
+ mfss = g_new0 (GrlMediaSourceMediaFromSiteSpec, 1);
+ mfss->source = g_object_ref (source);
+ mfss->site_uri = g_strdup (site_uri);
+ mfss->callback = callback;
+ mfss->user_data = user_data;
+
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ media_from_site_idle,
+ mfss,
+ media_from_site_idle_destroy);
+}
diff --git a/src/grl-media-source.h b/src/grl-media-source.h
index 837d675..df91974 100644
--- a/src/grl-media-source.h
+++ b/src/grl-media-source.h
@@ -284,6 +284,24 @@ typedef struct {
gpointer user_data;
} GrlMediaSourceRemoveSpec;
+/**
+ * GrlMediaSourceMediaFromSiteSpec:
+ * @source: a media source
+ * @site_uri: The site media URI
+ * @callback: the user defined callback
+ * @user_data: the user data to pass in the callback
+ *
+ * Data transport structure used internally by the plugins which support
+ * media_from_site vmethod.
+ */
+typedef struct {
+ GrlMediaSource *source;
+ gchar *site_uri;
+ GrlMediaSourceMetadataCb callback;
+ gpointer user_data;
+} GrlMediaSourceMediaFromSiteSpec;
+
+
/* GrlMediaSource class */
typedef struct _GrlMediaSourceClass GrlMediaSourceClass;
@@ -299,6 +317,10 @@ typedef struct _GrlMediaSourceClass GrlMediaSourceClass;
* @metadata: request for specific metadata
* @store: store a media in a container
* @remove: remove a media from a container
+ * @test_media_from_site: tests if this source can create #GrlMedia
+ * instances from a given site URI.
+ * @media_from_site: Creates a #GrlMedia instance representing the media
+ * exposed by a certain site URI.
*
* Grilo MediaSource class. Override the vmethods to implement the
* source functionality.
@@ -322,6 +344,12 @@ struct _GrlMediaSourceClass {
void (*store) (GrlMediaSource *source, GrlMediaSourceStoreSpec *ss);
void (*remove) (GrlMediaSource *source, GrlMediaSourceRemoveSpec *ss);
+
+ gboolean (*test_media_from_site) (GrlMediaSource *source,
+ const gchar *site_uri);
+
+ void (*media_from_site) (GrlMediaSource *source,
+ GrlMediaSourceMediaFromSiteSpec *mfss);
};
G_BEGIN_DECLS
@@ -427,6 +455,14 @@ void grl_media_source_set_auto_split_threshold (GrlMediaSource *source,
guint grl_media_source_get_auto_split_threshold (GrlMediaSource *source);
+gboolean grl_media_source_test_media_from_site (GrlMediaSource *source,
+ const gchar *site_uri);
+
+void grl_media_source_get_media_from_site (GrlMediaSource *source,
+ const gchar *site_uri,
+ GrlMediaSourceMetadataCb callback,
+ gpointer user_data);
+
G_END_DECLS
#endif /* _GRL_MEDIA_SOURCE_H_ */
diff --git a/src/grl-metadata-source.h b/src/grl-metadata-source.h
index e225e28..6f9faf2 100644
--- a/src/grl-metadata-source.h
+++ b/src/grl-metadata-source.h
@@ -194,21 +194,23 @@ typedef struct {
* @GRL_OP_STORE_PARENT: Store content as child of a certian parent category.
* @GRL_OP_REMOVE: Remove content from a service.
* @GRL_OP_SET_METADATA: Update metadata of a #GrlMedia in a service.
+ * @GRL_OP_MEDIA_FROM_SITE: Create a #GrlMedia instance from a site URL.
*
* Bitwise flags which reflect the kind of operations that a
* #GrlMediaPlugin supports.
*/
typedef enum {
- GRL_OP_NONE = 0,
- GRL_OP_METADATA = 1,
- GRL_OP_RESOLVE = 1 << 1,
- GRL_OP_BROWSE = 1 << 2,
- GRL_OP_SEARCH = 1 << 3,
- GRL_OP_QUERY = 1 << 4,
- GRL_OP_STORE = 1 << 5,
- GRL_OP_STORE_PARENT = 1 << 6,
- GRL_OP_REMOVE = 1 << 7,
- GRL_OP_SET_METADATA = 1 << 8,
+ GRL_OP_NONE = 0,
+ GRL_OP_METADATA = 1,
+ GRL_OP_RESOLVE = 1 << 1,
+ GRL_OP_BROWSE = 1 << 2,
+ GRL_OP_SEARCH = 1 << 3,
+ GRL_OP_QUERY = 1 << 4,
+ GRL_OP_STORE = 1 << 5,
+ GRL_OP_STORE_PARENT = 1 << 6,
+ GRL_OP_REMOVE = 1 << 7,
+ GRL_OP_SET_METADATA = 1 << 8,
+ GRL_OP_MEDIA_FROM_SITE = 1 << 9,
} GrlSupportedOps;
/* GrlMetadataSource class */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]