Index: plugins/ipod/rb-ipod-source.c
===================================================================
--- plugins/ipod/rb-ipod-source.c	(revision 4842)
+++ plugins/ipod/rb-ipod-source.c	(working copy)
@@ -87,6 +87,7 @@ static gchar* ipod_path_from_unix_path (
 					const gchar *unix_path);
 #endif
 static void itdb_schedule_save (Itdb_iTunesDB *db);
+static RhythmDB *get_db_for_source (RBiPodSource *source);
 
 typedef struct
 {
@@ -97,6 +98,9 @@ typedef struct
 	GList *playlists;
 
 	guint load_idle_id;
+
+	GHashTable *artwork_request_map;
+	guint artwork_notify_id;
 } RBiPodSourcePrivate;
 
 RB_PLUGIN_DEFINE_TYPE(RBiPodSource,
@@ -222,6 +226,18 @@ rb_ipod_source_dispose (GObject *object)
 		priv->load_idle_id = 0;
 	}
 
+	if (priv->artwork_request_map) {
+		g_hash_table_destroy (priv->artwork_request_map);
+		priv->artwork_request_map = NULL;
+ 	}
+
+	if (priv->artwork_notify_id) {
+		RhythmDB *db = get_db_for_source (RB_IPOD_SOURCE (object));
+		g_signal_handler_disconnect (db, priv->artwork_notify_id);
+		priv->artwork_notify_id = 0;
+		g_object_unref (db);
+	}
+
 	G_OBJECT_CLASS (rb_ipod_source_parent_class)->dispose (object);
 }
 
@@ -947,6 +963,51 @@ impl_build_dest_uri (RBRemovableMediaSou
 	return NULL;
 }
 
+static void
+artwork_notify_cb (RhythmDB *db,
+		   RhythmDBEntry *entry,
+		   const gchar *property_name,
+		   const GValue *metadata,
+		   RBiPodSource *isource)
+{
+	RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (isource);
+	Itdb_Track *song;
+	GdkPixbuf *pixbuf;
+	gchar *image_data;
+	gsize image_data_len;
+	
+	if (!(song = g_hash_table_lookup (priv->artwork_request_map, entry)))
+		return;
+	g_return_if_fail (G_VALUE_HOLDS (metadata, GDK_TYPE_PIXBUF));
+	g_return_if_fail ((pixbuf = GDK_PIXBUF (g_value_get_object (metadata))));
+	g_return_if_fail (gdk_pixbuf_save_to_buffer (pixbuf, &image_data, &image_data_len, "jpeg", NULL, "quality", "100", NULL));
+	g_hash_table_remove (priv->artwork_request_map, entry);
+	itdb_track_set_thumbnails_from_data (song, (guchar *) image_data, image_data_len);
+	g_free (image_data);
+	itdb_schedule_save (priv->ipod_db);
+}
+
+static void
+request_artwork (RBiPodSource *isource,
+		 RhythmDBEntry *entry,
+		 RhythmDB *db,
+		 Itdb_Track *song)
+{
+	RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (isource);
+	GValue *metadata;
+
+	if (priv->artwork_request_map == NULL)
+		priv->artwork_request_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+	g_hash_table_insert (priv->artwork_request_map, entry, song);
+
+	if (priv->artwork_notify_id == 0)
+		priv->artwork_notify_id = g_signal_connect (db, "entry-extra-metadata-notify::rb:coverArt", (GCallback) artwork_notify_cb, isource);
+
+	metadata = rhythmdb_entry_request_extra_metadata (db, entry, "rb:coverArt");
+	if (metadata)
+		artwork_notify_cb (db, entry, "rb:coverArt", metadata, isource);
+}
+
 static gboolean
 impl_track_added (RBRemovableMediaSource *source,
 		  RhythmDBEntry *entry,
@@ -970,6 +1031,7 @@ impl_track_added (RBRemovableMediaSource
 		itdb_track_add (priv->ipod_db, song, -1);
 		itdb_playlist_add_track (itdb_playlist_mpl (priv->ipod_db),
 					 song, -1);
+		request_artwork (isource, entry, db, song);
 
 		add_ipod_song_to_db (isource, db, song);
 		itdb_schedule_save (priv->ipod_db);
