Commit 1b8ff842 authored by Jonathan Matthew's avatar Jonathan Matthew 🕳

podcast: don't set status on current download when cancelling

This can race with the download task, so we should wait until the
task callback instead.
parent 2fd31b69
......@@ -166,7 +166,7 @@ static void download_task (GTask *task,
gpointer task_data,
GCancellable *cancel);
static void download_info_free (RBPodcastDownload *data);
static void cancel_download (RBPodcastDownload *pd);
static gboolean cancel_download (RBPodcastDownload *pd);
static void rb_podcast_manager_start_update_timer (RBPodcastManager *pd);
G_DEFINE_TYPE (RBPodcastManager, rb_podcast_manager, G_TYPE_OBJECT)
......@@ -1239,7 +1239,7 @@ rb_podcast_manager_delete_download (RBPodcastManager *pd, RhythmDBEntry *entry)
g_object_unref (file);
}
void
gboolean
rb_podcast_manager_cancel_download (RBPodcastManager *pd, RhythmDBEntry *entry)
{
GList *lst;
......@@ -1248,10 +1248,11 @@ rb_podcast_manager_cancel_download (RBPodcastManager *pd, RhythmDBEntry *entry)
for (lst = pd->priv->download_list; lst != NULL; lst = lst->next) {
RBPodcastDownload *data = (RBPodcastDownload *) lst->data;
if (data->entry == entry) {
cancel_download (data);
return;
return cancel_download (data);
}
}
return FALSE;
}
static void
......@@ -2260,7 +2261,7 @@ download_task (GTask *task, gpointer source_object, gpointer task_data, GCancell
}
static void
static gboolean
cancel_download (RBPodcastDownload *data)
{
g_assert (rb_is_main_thread ());
......@@ -2271,9 +2272,11 @@ cancel_download (RBPodcastDownload *data)
g_cancellable_cancel (data->cancel);
/* download data will be cleaned up after the task returns */
return TRUE;
} else {
/* destroy download data */
data->pd->priv->download_list = g_list_remove (data->pd->priv->download_list, data);
download_info_free (data);
return FALSE;
}
}
......@@ -67,7 +67,7 @@ typedef struct
GType rb_podcast_manager_get_type (void);
RBPodcastManager* rb_podcast_manager_new (RhythmDB *db);
void rb_podcast_manager_download_entry (RBPodcastManager *pd, RhythmDBEntry *entry);
void rb_podcast_manager_cancel_download (RBPodcastManager *pd, RhythmDBEntry *entry);
gboolean rb_podcast_manager_cancel_download (RBPodcastManager *pd, RhythmDBEntry *entry);
void rb_podcast_manager_update_feeds (RBPodcastManager *pd);
void rb_podcast_manager_start_sync (RBPodcastManager *pd);
void rb_podcast_manager_delete_download (RBPodcastManager *pd, RhythmDBEntry *entry);
......
......@@ -453,6 +453,7 @@ podcast_download_cancel_action_cb (GSimpleAction *action, GVariant *parameter, g
lst = rb_entry_view_get_selected_entries (posts);
g_value_init (&val, G_TYPE_ULONG);
g_value_set_ulong (&val, RHYTHMDB_PODCAST_STATUS_PAUSED);
while (lst != NULL) {
RhythmDBEntry *entry = (RhythmDBEntry *) lst->data;
......@@ -460,9 +461,9 @@ podcast_download_cancel_action_cb (GSimpleAction *action, GVariant *parameter, g
if ((status > 0 && status < RHYTHMDB_PODCAST_STATUS_COMPLETE) ||
status == RHYTHMDB_PODCAST_STATUS_WAITING) {
g_value_set_ulong (&val, RHYTHMDB_PODCAST_STATUS_PAUSED);
rhythmdb_entry_set (source->priv->db, entry, RHYTHMDB_PROP_STATUS, &val);
rb_podcast_manager_cancel_download (source->priv->podcast_mgr, entry);
if (rb_podcast_manager_cancel_download (source->priv->podcast_mgr, entry) == FALSE) {
rhythmdb_entry_set (source->priv->db, entry, RHYTHMDB_PROP_STATUS, &val);
}
}
lst = lst->next;
......
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