diff options
author | Juan A. Suarez Romero <jasuarez@igalia.com> | 2010-02-19 16:40:17 +0100 |
---|---|---|
committer | Juan A. Suarez Romero <jasuarez@igalia.com> | 2010-02-19 16:40:17 +0100 |
commit | 0be5c9d96ef7e36337da2ea0a4153ac861a9793e (patch) | |
tree | 40473b7874909b78ca9f7006800789730a44e018 | |
parent | 4585c5a0f60edf6e27d8ed66698cdd0dfbf918f5 (diff) | |
download | grilo-plugins-0be5c9d96ef7e36337da2ea0a4153ac861a9793e.tar.gz |
[shoutcast] Implement cancel operation
-rw-r--r-- | src/shoutcast/grl-shoutcast.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/shoutcast/grl-shoutcast.c b/src/shoutcast/grl-shoutcast.c index 6b7d5e8..86d0870 100644 --- a/src/shoutcast/grl-shoutcast.c +++ b/src/shoutcast/grl-shoutcast.c @@ -68,6 +68,7 @@ typedef struct { xmlDocPtr xml_doc; gchar *genre; gint to_send; + gboolean cancelled; } OperationData; static GrlShoutcastSource *grl_shoutcast_source_new (void); @@ -81,6 +82,8 @@ static const GList *grl_shoutcast_source_supported_keys (GrlMetadataSource *sour static void grl_shoutcast_source_browse (GrlMediaSource *source, GrlMediaSourceBrowseSpec *bs); +static void grl_shoutcast_source_cancel (GrlMediaSource *source, + guint operation_id); /* =================== SHOUTcast Plugin =============== */ @@ -126,6 +129,7 @@ grl_shoutcast_source_class_init (GrlShoutcastSourceClass * klass) GrlMediaSourceClass *source_class = GRL_MEDIA_SOURCE_CLASS (klass); GrlMetadataSourceClass *metadata_class = GRL_METADATA_SOURCE_CLASS (klass); source_class->browse = grl_shoutcast_source_browse; + source_class->cancel = grl_shoutcast_source_cancel; metadata_class->supported_keys = grl_shoutcast_source_supported_keys; } @@ -222,17 +226,19 @@ build_media_from_station (OperationData *op_data) static gboolean send_media (OperationData *op_data, GrlContentMedia *media) { - op_data->bs->callback (op_data->bs->source, - op_data->bs->browse_id, - media, - --op_data->to_send, - op_data->bs->user_data, - NULL); + if (!op_data->cancelled) { + op_data->bs->callback (op_data->bs->source, + op_data->bs->browse_id, + media, + --op_data->to_send, + op_data->bs->user_data, + NULL); - op_data->xml_entries = op_data->xml_entries->next; - skip_garbage_nodes (&op_data->xml_entries); + op_data->xml_entries = op_data->xml_entries->next; + skip_garbage_nodes (&op_data->xml_entries); + } - if (op_data->to_send == 0) { + if (op_data->to_send == 0 || op_data->cancelled) { xmlFreeDoc (op_data->xml_doc); g_free (op_data); return FALSE; @@ -261,6 +267,11 @@ xml_parse_result (const gchar *str, OperationData *op_data) GError *error = NULL; xmlNodePtr node; + if (op_data->cancelled) { + g_free (op_data); + return; + } + op_data->xml_doc = xmlRecoverDoc ((xmlChar *) str); if (!op_data->xml_doc) { error = g_error_new (GRL_ERROR, @@ -426,7 +437,23 @@ grl_shoutcast_source_browse (GrlMediaSource *source, data->genre = g_strdup (container_id); } + grl_media_source_set_operation_data (source, bs->browse_id, data); + read_url_async (url, data); g_free (url); } + +static void +grl_shoutcast_source_cancel (GrlMediaSource *source, guint operation_id) +{ + OperationData *op_data; + + g_debug ("grl_shoutcast_source_cancel"); + + op_data = (OperationData *) grl_media_source_get_operation_data (source, operation_id); + + if (op_data) { + op_data->cancelled = TRUE; + } +} |