[rhythmbox] podcast: rework parsing a bit more
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] podcast: rework parsing a bit more
- Date: Fri, 16 Oct 2020 07:18:33 +0000 (UTC)
commit ae8e0dde2723c78a1a4d9e5a9eb0c6ab8b3ae097
Author: Jonathan Matthew <jonathan d14n org>
Date: Tue Oct 6 22:07:27 2020 +1000
podcast: rework parsing a bit more
Now the parser updates an existing RBPodcastChannel rather than filling out
a new one, which simplifies things a little bit for the podcast add dialog.
podcast/rb-podcast-add-dialog.c | 58 +++++++++++++++++++++++++----------------
podcast/rb-podcast-manager.c | 8 +++---
podcast/rb-podcast-parse.c | 10 ++++---
podcast/rb-podcast-parse.h | 1 -
podcast/test-podcast-parse.c | 3 ++-
5 files changed, 47 insertions(+), 33 deletions(-)
---
diff --git a/podcast/rb-podcast-add-dialog.c b/podcast/rb-podcast-add-dialog.c
index 794a2744f..0180b00b9 100644
--- a/podcast/rb-podcast-add-dialog.c
+++ b/podcast/rb-podcast-add-dialog.c
@@ -280,7 +280,6 @@ update_feed_status (RBPodcastAddDialog *dialog)
typedef struct {
RBPodcastAddDialog *dialog;
- char *url;
RBPodcastChannel *channel;
gboolean existing;
gboolean single;
@@ -293,12 +292,13 @@ parse_cb (RBPodcastChannel *channel, GError *error, gpointer user_data)
{
ParseData *data = user_data;
+ g_assert (channel == data->channel);
+
if (error != NULL) {
/* fake up a channel with just the url as the title, allowing the user
* to subscribe to the podcast anyway.
*/
- data->channel->url = g_strdup (data->url);
- data->channel->title = g_strdup (data->url);
+ channel->title = g_strdup (channel->url);
g_error_free (error);
}
@@ -307,8 +307,8 @@ parse_cb (RBPodcastChannel *channel, GError *error, gpointer user_data)
rb_podcast_parse_channel_free (data->channel);
g_object_unref (data->dialog);
g_clear_error (&data->error);
- g_free (data->url);
g_free (data);
+ return;
}
if (data->error != NULL) {
@@ -336,23 +336,18 @@ parse_cb (RBPodcastChannel *channel, GError *error, gpointer user_data)
update_feed_status (data->dialog);
rb_podcast_parse_channel_free (data->channel);
} else if (data->existing) {
- /* find the row for the feed, replace the channel */
GtkTreeIter iter;
gboolean found = FALSE;
+ /* find the row for the feed */
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (data->dialog->priv->feed_model), &iter)) {
do {
- RBPodcastChannel *channel;
+ RBPodcastChannel *rchannel;
gtk_tree_model_get (GTK_TREE_MODEL (data->dialog->priv->feed_model), &iter,
- FEED_COLUMN_PARSED_FEED, &channel,
+ FEED_COLUMN_PARSED_FEED, &rchannel,
-1);
- if (g_strcmp0 (channel->url, data->url) == 0) {
- gtk_list_store_set (data->dialog->priv->feed_model,
- &iter,
- FEED_COLUMN_PARSED_FEED, data->channel,
- -1);
+ if (g_strcmp0 (rchannel->url, channel->url) == 0) {
found = TRUE;
- rb_podcast_parse_channel_free (channel);
break;
}
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (data->dialog->priv->feed_model),
&iter));
@@ -382,24 +377,41 @@ parse_cb (RBPodcastChannel *channel, GError *error, gpointer user_data)
g_object_unref (data->dialog);
g_clear_error (&data->error);
- g_free (data->url);
g_free (data);
}
static void
-parse_in_thread (RBPodcastAddDialog *dialog, const char *text, gboolean existing, gboolean single)
+parse_search_text (RBPodcastAddDialog *dialog, const char *text)
+{
+ ParseData *data;
+ RBPodcastChannel *channel;
+
+ channel = g_new0 (RBPodcastChannel, 1);
+ channel->url = g_strdup (text);
+
+ data = g_new0 (ParseData, 1);
+ data->dialog = g_object_ref (dialog);
+ data->channel = channel;
+ data->existing = FALSE;
+ data->single = TRUE;
+ data->reset_count = dialog->priv->reset_count;
+
+ rb_podcast_parse_load_feed (data->channel, NULL, parse_cb, data);
+}
+
+static void
+parse_search_result (RBPodcastAddDialog *dialog, RBPodcastChannel *channel)
{
ParseData *data;
data = g_new0 (ParseData, 1);
data->dialog = g_object_ref (dialog);
- data->url = g_strdup (text);
- data->channel = g_new0 (RBPodcastChannel, 1);
- data->existing = existing;
- data->single = single;
+ data->channel = channel;
+ data->existing = TRUE;
+ data->single = FALSE;
data->reset_count = dialog->priv->reset_count;
- rb_podcast_parse_load_feed (data->channel, data->url, NULL, parse_cb, data);
+ rb_podcast_parse_load_feed (channel, NULL, parse_cb, data);
}
static void
@@ -450,14 +462,14 @@ search_cb (RBSearchEntry *entry, const char *text, RBPodcastAddDialog *dialog)
/* if the entered text looks like a feed URL, parse it directly */
for (i = 0; i < G_N_ELEMENTS (podcast_uri_prefixes); i++) {
if (g_str_has_prefix (text, podcast_uri_prefixes[i])) {
- parse_in_thread (dialog, text, FALSE, TRUE);
+ parse_search_text (dialog, text);
return;
}
}
/* not really sure about this one */
if (g_path_is_absolute (text)) {
- parse_in_thread (dialog, text, FALSE, TRUE);
+ parse_search_text (dialog, text);
return;
}
@@ -558,7 +570,7 @@ feed_selection_changed_cb (GtkTreeSelection *selection, RBPodcastAddDialog *dial
if (channel->posts == NULL) {
rb_debug ("parsing feed %s to get posts", channel->url);
- parse_in_thread (dialog, channel->url, TRUE, FALSE);
+ parse_search_result (dialog, channel);
} else {
add_posts_for_feed (dialog, channel);
}
diff --git a/podcast/rb-podcast-manager.c b/podcast/rb-podcast-manager.c
index a0768923e..73708fa77 100644
--- a/podcast/rb-podcast-manager.c
+++ b/podcast/rb-podcast-manager.c
@@ -95,7 +95,6 @@ typedef struct
typedef struct
{
RBPodcastManager *pd;
- char *url;
gboolean automatic;
RBPodcastChannel *channel;
GError *error;
@@ -672,7 +671,6 @@ podcast_update_free (RBPodcastUpdate *update)
g_clear_error (&update->error);
rb_podcast_parse_channel_free (update->channel);
- g_free (update->url);
g_free (update);
}
@@ -744,7 +742,7 @@ start_feed_parse (RBPodcastManager *pd, RBPodcastUpdate *update)
g_object_notify (G_OBJECT (pd), "updating");
}
- rb_podcast_parse_load_feed (update->channel, update->url, pd->priv->update_cancel, feed_parse_cb,
update);
+ rb_podcast_parse_load_feed (update->channel, pd->priv->update_cancel, feed_parse_cb, update);
}
static void
@@ -787,7 +785,7 @@ mime_type_check_cb (GObject *source_object, GAsyncResult *res, gpointer user_dat
_("The URL '%s' does not appear to be a podcast feed. "
"It may be the wrong URL, or the feed may be broken. "
"Would you like Rhythmbox to attempt to use it anyway?"),
- update->url);
+ update->channel->url);
gtk_widget_show_all (dialog);
g_signal_connect (dialog, "response", G_CALLBACK (confirm_bad_mime_type_response_cb), update);
g_clear_error (&error);
@@ -825,9 +823,9 @@ rb_podcast_manager_subscribe_feed (RBPodcastManager *pd, const char *url, gboole
update = g_new0 (RBPodcastUpdate, 1);
update->pd = g_object_ref (pd);
- update->url = feed_url;
update->automatic = automatic;
update->channel = g_new0 (RBPodcastChannel, 1);
+ update->channel->url = g_strdup (feed_url);
entry = rhythmdb_entry_lookup_by_location (pd->priv->db, feed_url);
if (entry) {
diff --git a/podcast/rb-podcast-parse.c b/podcast/rb-podcast-parse.c
index 937f6f732..25307d5bf 100644
--- a/podcast/rb-podcast-parse.c
+++ b/podcast/rb-podcast-parse.c
@@ -64,20 +64,27 @@ playlist_metadata_foreach (const char *key,
RBPodcastChannel *channel = (RBPodcastChannel *) data;
if (strcmp (key, TOTEM_PL_PARSER_FIELD_TITLE) == 0) {
+ g_free (channel->title);
channel->title = g_strdup (value);
} else if (strcmp (key, TOTEM_PL_PARSER_FIELD_LANGUAGE) == 0) {
+ g_free (channel->lang);
channel->lang = g_strdup (value);
} else if (strcmp (key, TOTEM_PL_PARSER_FIELD_DESCRIPTION) == 0) {
+ g_free (channel->description);
channel->description = g_strdup (value);
} else if (strcmp (key, TOTEM_PL_PARSER_FIELD_AUTHOR) == 0) {
+ g_free (channel->author);
channel->author = g_strdup (value);
} else if (strcmp (key, TOTEM_PL_PARSER_FIELD_CONTACT) == 0) {
+ g_free (channel->contact);
channel->contact = g_strdup (value);
} else if (strcmp (key, TOTEM_PL_PARSER_FIELD_IMAGE_URI) == 0) {
+ g_free (channel->img);
channel->img = g_strdup (value);
} else if (strcmp (key, TOTEM_PL_PARSER_FIELD_PUB_DATE) == 0) {
channel->pub_date = totem_pl_parser_parse_date (value, FALSE);
} else if (strcmp (key, TOTEM_PL_PARSER_FIELD_COPYRIGHT) == 0) {
+ g_free (channel->copyright);
channel->copyright = g_strdup (value);
}
}
@@ -191,7 +198,6 @@ parse_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
void
rb_podcast_parse_load_feed (RBPodcastChannel *channel,
- const char *feed_url,
GCancellable *cancellable,
RBPodcastParseCallback callback,
gpointer user_data)
@@ -199,8 +205,6 @@ rb_podcast_parse_load_feed (RBPodcastChannel *channel,
TotemPlParser *plparser;
RBPodcastParseData *data;
- channel->url = g_strdup (feed_url);
-
data = g_new0 (RBPodcastParseData, 1);
data->channel = channel;
data->callback = callback;
diff --git a/podcast/rb-podcast-parse.h b/podcast/rb-podcast-parse.h
index 7b6d8b3f1..c2acc9613 100644
--- a/podcast/rb-podcast-parse.h
+++ b/podcast/rb-podcast-parse.h
@@ -79,7 +79,6 @@ GType rb_podcast_item_get_type (void);
typedef void (*RBPodcastParseCallback) (RBPodcastChannel *data, GError *error, gpointer user_data);
void rb_podcast_parse_load_feed (RBPodcastChannel *data,
- const char *url,
GCancellable *cancellable,
RBPodcastParseCallback callback,
gpointer user_data);
diff --git a/podcast/test-podcast-parse.c b/podcast/test-podcast-parse.c
index 07458c03d..b87b81a93 100644
--- a/podcast/test-podcast-parse.c
+++ b/podcast/test-podcast-parse.c
@@ -122,7 +122,8 @@ main (int argc, char **argv)
ml = g_main_loop_new (NULL, FALSE);
data = g_new0 (RBPodcastChannel, 1);
- rb_podcast_parse_load_feed (data, argv[1], NULL, parse_cb, ml);
+ data->url = g_strdup (argv[1]);
+ rb_podcast_parse_load_feed (data, NULL, parse_cb, ml);
g_main_loop_run (ml);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]