[rhythmbox] podcast: fix podcast status on download completion (bug #633469)



commit 10d4b587b1f2f9b27fec7efd3464eddbd4ed1fdb
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Jan 2 14:07:53 2011 +1000

    podcast: fix podcast status on download completion (bug #633469)
    
    Only set the status to 'downloaded' if we've downloaded the whole file.
    
    If a selected entry is in the download queue, enable the 'cancel download'
    action.  If a selected entry is not in the download queue and has a status
    other than 'downloaded', enable the 'download episode' action.
    
    This should make it possible to complete downloads that fail due to
    connection errors and the like.

 podcast/rb-podcast-manager.c |   26 ++++++++++++++++++++++----
 podcast/rb-podcast-manager.h |    1 +
 podcast/rb-podcast-source.c  |    9 ++++-----
 3 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/podcast/rb-podcast-manager.c b/podcast/rb-podcast-manager.c
index c83f90a..5d2d736 100644
--- a/podcast/rb-podcast-manager.c
+++ b/podcast/rb-podcast-manager.c
@@ -506,6 +506,22 @@ rb_podcast_manager_entry_downloaded (RhythmDBEntry *entry)
 	return (status != RHYTHMDB_PODCAST_STATUS_ERROR && file_name != NULL);
 }
 
+gboolean
+rb_podcast_manager_entry_in_download_queue (RBPodcastManager *pd, RhythmDBEntry *entry)
+{
+	RBPodcastManagerInfo *info;
+	GList *l;
+
+	for (l = pd->priv->download_list; l != NULL; l = l->next) {
+		info = l->data;
+		if (info->entry == entry) {
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
 void
 rb_podcast_manager_start_sync (RBPodcastManager *pd)
 {
@@ -1437,10 +1453,12 @@ download_progress (RBPodcastManagerInfo *data, guint64 downloaded, guint64 total
 			rhythmdb_entry_set (data->pd->priv->db, data->entry, RHYTHMDB_PROP_FILE_SIZE, &val);
 			g_value_unset (&val);
 
-			g_value_init (&val, G_TYPE_ULONG);
-			g_value_set_ulong (&val, RHYTHMDB_PODCAST_STATUS_COMPLETE);
-			rhythmdb_entry_set (data->pd->priv->db, data->entry, RHYTHMDB_PROP_STATUS, &val);
-			g_value_unset (&val);
+			if (total == 0 || downloaded >= total) {
+				g_value_init (&val, G_TYPE_ULONG);
+				g_value_set_ulong (&val, RHYTHMDB_PODCAST_STATUS_COMPLETE);
+				rhythmdb_entry_set (data->pd->priv->db, data->entry, RHYTHMDB_PROP_STATUS, &val);
+				g_value_unset (&val);
+			}
 
 			rb_podcast_manager_save_metadata (data->pd,
 							  data->entry);
diff --git a/podcast/rb-podcast-manager.h b/podcast/rb-podcast-manager.h
index deaa18b..b00dd2f 100644
--- a/podcast/rb-podcast-manager.h
+++ b/podcast/rb-podcast-manager.h
@@ -90,6 +90,7 @@ RhythmDBEntry *         rb_podcast_manager_add_post  	  	(RhythmDB *db,
 								 guint64 filesize);
 
 gboolean		rb_podcast_manager_entry_downloaded	(RhythmDBEntry *entry);
+gboolean		rb_podcast_manager_entry_in_download_queue (RBPodcastManager *pd, RhythmDBEntry *entry);
 
 
 G_END_DECLS
diff --git a/podcast/rb-podcast-source.c b/podcast/rb-podcast-source.c
index 94c14ad..2e1933d 100644
--- a/podcast/rb-podcast-source.c
+++ b/podcast/rb-podcast-source.c
@@ -217,12 +217,11 @@ podcast_posts_show_popup_cb (RBEntryView *view,
 			RhythmDBEntry *entry = (RhythmDBEntry*) lst->data;
 			gulong status = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_STATUS);
 
-			if ((status > 0 && status < RHYTHMDB_PODCAST_STATUS_COMPLETE) ||
-			    status == RHYTHMDB_PODCAST_STATUS_WAITING)
+			if (rb_podcast_manager_entry_in_download_queue (source->priv->podcast_mgr, entry)) {
 				cancellable = TRUE;
-			else if (status == RHYTHMDB_PODCAST_STATUS_PAUSED ||
-				 status == RHYTHMDB_PODCAST_STATUS_ERROR)
-				 downloadable = TRUE;
+			} else if (status != RHYTHMDB_PODCAST_STATUS_COMPLETE) {
+				downloadable = TRUE;
+			}
 
 			lst = lst->next;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]