Index: podcast/rb-podcast-manager.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/podcast/rb-podcast-manager.c,v
retrieving revision 1.6
diff -u -3 -p -r1.6 rb-podcast-manager.c
--- podcast/rb-podcast-manager.c	27 Oct 2005 13:02:00 -0000	1.6
+++ podcast/rb-podcast-manager.c	27 Oct 2005 18:46:49 -0000
@@ -442,7 +442,7 @@ rb_podcast_manager_download_entry (RBPod
         	g_static_mutex_lock (&entry_add_mutex);
 		pd->priv->download_list =  g_list_append (pd->priv->download_list, data);
 		g_static_mutex_unlock (&entry_add_mutex);
-		rb_podcast_manager_next_file (pd);
+		gtk_idle_add ((GtkFunction) rb_podcast_manager_next_file_idle , pd);
 	}
 }
 
@@ -600,10 +600,12 @@ rb_podcast_manager_copy_post (RBPodcastM
 	
 	remote_uri = gnome_vfs_uri_new (location);
 	if (!remote_uri) {
+		rb_debug ("Error downloading podcast: could not create remote uri");
 		goto next_step;
 	}
 		
 	if (gnome_vfs_uri_is_local (remote_uri)) {	
+		rb_debug ("Error downloading podcast: uri is local");
 		goto next_step;
 	}
 
@@ -620,7 +622,7 @@ rb_podcast_manager_copy_post (RBPodcastM
 
 	 if (!g_file_test (dir_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
 		if (rb_podcast_manager_mkdir_with_parents (dir_name, 0750) != 0) {
-			rb_debug ("Error on create local dirs.");
+			rb_debug ("Error downloading podcast: could not create local dirs");
 			goto next_step;
 		}
 	 }
@@ -633,13 +635,56 @@ rb_podcast_manager_copy_post (RBPodcastM
 
 	local_uri = gnome_vfs_uri_new (local_file_name);
 	if (!local_uri) {
+		rb_debug ("Error downloading podcast: could not create local uri");
 		goto next_step;
 	}
 
-	//TODO: suport resume file
 	if (g_file_test (local_file_name, G_FILE_TEST_EXISTS)) {
-		rb_debug ("Removing existent file.");
-		g_remove (local_file_name);
+		guint64 remote_size = rhythmdb_entry_get_uint64 (entry, RHYTHMDB_PROP_FILE_SIZE);
+		GnomeVFSFileInfo *info = gnome_vfs_file_info_new ();
+		GnomeVFSResult result;
+
+		if (remote_size == 0) {
+			result = gnome_vfs_get_file_info_uri (remote_uri, info, GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
+			if (result != GNOME_VFS_OK) {
+				rb_debug ("unable to retrieve info on remote of podcast");
+			} else { 
+				remote_size = info->size;
+				gnome_vfs_file_info_unref (info);
+			}
+		}
+
+		result = gnome_vfs_get_file_info (local_file_name, info, GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
+		if (result != GNOME_VFS_OK) {
+			rb_debug ("unable to retrieve info on local copy of podcast");
+			goto next_step;
+		} else if (remote_size == info->size) {
+			GValue val = {0,};
+			char *uri = gnome_vfs_uri_to_string (local_uri, GNOME_VFS_URI_HIDE_NONE);
+		
+			rb_debug ("podcast %s already downloaded", location);
+
+			g_value_init (&val, G_TYPE_ULONG);
+			g_value_set_ulong (&val, 100);
+			rhythmdb_entry_set (pd->priv->db, data->entry, RHYTHMDB_PROP_STATUS, &val);
+			g_value_unset (&val);
+
+			g_value_init (&val, G_TYPE_STRING);
+			g_value_set_string (&val, uri);
+			rhythmdb_entry_set (pd->priv->db, data->entry, RHYTHMDB_PROP_MOUNTPOINT, &val);
+			g_value_unset (&val);
+
+			rb_podcast_manager_save_metadata (pd->priv->db, data->entry, uri);
+			rhythmdb_commit (pd->priv->db);
+				
+			goto next_step;
+		} else if (remote_size > info->size) {
+			/* TODO: suport resume file */
+		} else {
+			/* the local file is larger. replace it */
+		}
+		
+		gnome_vfs_file_info_unref (info);
 	}
 
 	
@@ -658,7 +703,6 @@ next_step:
 	if (local_uri)
 		gnome_vfs_uri_unref (local_uri);
 
-	rb_debug ("Erro starting job");
 	g_static_mutex_lock (&entry_add_mutex);
 	pd->priv->download_list = g_list_remove (pd->priv->download_list, (gconstpointer ) data);
 	g_static_mutex_unlock (&entry_add_mutex);
@@ -667,7 +711,7 @@ next_step:
 	data = NULL;
 
 	g_mutex_unlock (pd->priv->mutex_job);
-	rb_podcast_manager_next_file (pd);
+	gtk_idle_add ((GtkFunction) rb_podcast_manager_next_file_idle , pd);	
 }
 
 
@@ -787,7 +831,8 @@ rb_podcast_manager_add_post (RhythmDB *d
 			      const char *uri,
 			      const char *description,
 			      gulong status,
-			      gulong date)
+			      gulong date,
+			      guint64 filesize)
 {
 	//GThread* copy_thread = NULL;
 	GValue title_val = { 0, };
@@ -800,6 +845,7 @@ rb_podcast_manager_add_post (RhythmDB *d
 	GValue subtitle_val = { 0, };
 	GValue description_val = { 0, };
 	GValue value =  { 0, };
+	GValue size_val = {0,};
 	GTimeVal time;
 	
 	RhythmDBEntry *entry;
@@ -848,6 +894,9 @@ rb_podcast_manager_add_post (RhythmDB *d
 		else
 			g_value_set_string (&artist_val, "");
 
+		g_value_init (&size_val, G_TYPE_UINT64);
+		g_value_set_uint64 (&size_val, filesize);
+
 
 		
 		entry = rhythmdb_entry_new (db,
@@ -884,6 +933,7 @@ rb_podcast_manager_add_post (RhythmDB *d
 		rhythmdb_entry_set_uninserted (db, entry, RHYTHMDB_PROP_MOUNTPOINT, &mountpoit_val);
 		rhythmdb_entry_set_uninserted (db, entry, RHYTHMDB_PROP_STATUS, &status_val);
 		rhythmdb_entry_set_uninserted (db, entry, RHYTHMDB_PROP_DESCRIPTION, &description_val);
+		rhythmdb_entry_set_uninserted (db, entry, RHYTHMDB_PROP_FILE_SIZE, &size_val);
 			
 		g_value_unset (&time_val);
 		g_value_unset (&title_val);
@@ -893,6 +943,7 @@ rb_podcast_manager_add_post (RhythmDB *d
 		g_value_unset (&status_val);
 		g_value_unset (&artist_val);
 		g_value_unset (&description_val);
+		g_value_unset (&size_val);
 
 	}
 	return TRUE;
@@ -1193,10 +1244,7 @@ download_progress_update_cb (GnomeVFSAsy
 	
 	if ((info->phase == GNOME_VFS_XFER_PHASE_COPYING) &&
 	    (data->entry != NULL)) {
-		guint local_progress = 0;
-	       
-		if (info->file_size > 0)
-			local_progress = (gint) 100 * info->total_bytes_copied / info->file_size;
+		guint local_progress = (gint) 100 * info->total_bytes_copied / info->file_size;
 
 		if (local_progress != data->progress) {
 			data->entry->podcast->status = local_progress;
@@ -1529,7 +1577,9 @@ load_posts:
 							       (gchar* ) item->url,
 							       (gchar* ) item->description,
 							       status,
-							       (gulong ) (item->pub_date > 0 ? item->pub_date : data->pub_date));
+							       (gulong ) (item->pub_date > 0 ? item->pub_date : data->pub_date),
+							       item->filesize);
+			
 			status = 103;
 		} else {
 			if (!g_strcasecmp(last_post, (gchar* )item->url)) {
Index: podcast/rb-podcast-manager.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/podcast/rb-podcast-manager.h,v
retrieving revision 1.1
diff -u -3 -p -r1.1 rb-podcast-manager.h
--- podcast/rb-podcast-manager.h	20 Oct 2005 16:42:16 -0000	1.1
+++ podcast/rb-podcast-manager.h	27 Oct 2005 18:46:49 -0000
@@ -81,7 +81,8 @@ gboolean                rb_podcast_manag
 	                                                 	 const char *uri,
 		        	                               	 const char *description,
 								 gulong status,
-	        	                                       	 gulong date);
+	        	                                       	 gulong date,
+								 guint64 filesize);
 
 G_END_DECLS
 
Index: podcast/rb-podcast-parse.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/podcast/rb-podcast-parse.c,v
retrieving revision 1.4
diff -u -3 -p -r1.4 rb-podcast-parse.c
--- podcast/rb-podcast-parse.c	26 Oct 2005 09:17:50 -0000	1.4
+++ podcast/rb-podcast-parse.c	27 Oct 2005 18:46:49 -0000
@@ -129,6 +129,8 @@ rb_set_item_value (struct RBPoadcastLoad
        ctx->item_data->description = dvalue;
    } else if (!strcmp (name, "author")) {
        ctx->item_data->author = dvalue;
+   } else if (!strcmp (name, "length")) {
+       ctx->item_data->filesize = g_ascii_strtoull ((char*)dvalue, NULL, 10);
    } else {
        g_free (dvalue);
    }
@@ -230,6 +232,9 @@ rb_podcast_parser_start_element (struct 
                     if (!strcmp (*attrs, "url")) {
                         const char *url_value = *(attrs+1);
                         rb_set_item_value(ctx, "url", url_value);
+                    } else if (!strcmp (*attrs, "length")) {
+                        const char *length_value = *(attrs+1);
+                        rb_set_item_value(ctx, "length", length_value);
                     }
                 }
             } else  if (!rb_validate_item_propert (name)) {
Index: podcast/rb-podcast-parse.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/podcast/rb-podcast-parse.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 rb-podcast-parse.h
--- podcast/rb-podcast-parse.h	22 Oct 2005 02:13:04 -0000	1.2
+++ podcast/rb-podcast-parse.h	27 Oct 2005 18:46:50 -0000
@@ -31,6 +31,7 @@ typedef struct
 	xmlChar* description;
 	xmlChar* author;
 	uintmax_t pub_date;
+	guint64 filesize;
 }RBPodcastItem;
 
 typedef struct 
