Commit ae8e0dde authored by Jonathan Matthew's avatar Jonathan Matthew 🕳

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.
parent 614353cd
Pipeline #221792 passed with stage
in 16 minutes and 5 seconds
......@@ -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);
}
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment