diff -u -u -r1.5 artdisplay.py
--- plugins/artdisplay/artdisplay.py	6 May 2006 07:28:58 -0000	1.5
+++ plugins/artdisplay/artdisplay.py	6 May 2006 12:34:33 -0000
@@ -43,59 +43,49 @@
     def __init__(self):
 	    	self.chunk = 4096
 
-    def read_cb(self, handle, buffer, exc_type, bytes_requested):
-			if exc_type:
-				if issubclass(exc_type, gnomevfs.EOFError):
-					gobject.idle_add(self.callback, self.data)
-					handle.close(lambda *args: None)
-				else:
-					gobject.idle_add(self.callback, None)
-					handle.close(lambda *args: None)
-				return
+    def read_cb(self, handle, buffer, exc_type, bytes_requested, (data, callback, args)):
+		if exc_type:
+			if issubclass(exc_type, gnomevfs.EOFError):
+				gobject.idle_add(callback, data, *args)
+				handle.close(lambda *args: None)
+			else:
+				gobject.idle_add(callback, None, *args)
+				handle.close(lambda *args: None)
+			return
 			
-			self.data += buffer
-			handle.read(self.chunk, self.read_cb)
+		data += buffer
+		handle.read(self.chunk, self.read_cb, (data, callback, args))
     
-    def open_cb(self, handle, exc_type):
-			if exc_type:
-				gobject.idle_add(self.callback, None)
-				return
-	    
-			handle.read(self.chunk, self.read_cb)
+    def open_cb(self, handle, exc_type, (data, callback, args)):
+		if exc_type:
+			gobject.idle_add(callback, None, *args)
+			return
+
+		handle.read(self.chunk, self.read_cb, (data, callback, args))
     
-    def get_url(self, url, callback):
-			self.callback = callback
-			self.url = url
-			self.data = ""
-			gnomevfs.async.open(url, self.open_cb)
+    def get_url(self, url, callback, *args):
+		gnomevfs.async.open(url, self.open_cb, data=("", callback, args))
 
 class URLLibSrc(object):
-    def get_url(self, url, callback):
+    def get_url(self, url, callback, *args):
 			try:
 				sock = urllib.urlopen(url)
 				data = sock.read()
 				sock.close()
-				callback(data)
+				callback(data, *args)
 			except:
-				callback(None)
+				callback(None, *args)
 				raise
 
 class CoverArtDatabase (object):
 	def __init__(self):
-		self.set_search_engine(self.get_default_search_engine())
-		if use_gnomevfs:
-			self.image_loader = GnomeVFSAsyncSrc()
-		else:
-			self.image_loader = URLLibSrc()
-
-	def get_default_search_engine (self):
 		if use_gnomevfs:
-			return AmazonCoverArtSearch (GnomeVFSAsyncSrc())
+			self.loader = GnomeVFSAsyncSrc()
 		else:
-			return AmazonCoverArtSearch (URLLibSrc())
+			self.loader = URLLibSrc()
 
-	def set_search_engine (self, search_engine):
-		self.search_engine = search_engine
+	def create_search (self):
+		return AmazonCoverArtSearch (self.loader)
 
 	def build_art_cache_filename (self, album, artist, extension):
 		art_folder = os.path.expanduser (ART_FOLDER)
@@ -107,9 +97,9 @@
 		# FIXME: the following block of code is messy and needs to be redone ASAP
 		return art_folder + '/%s - %s.%s' % (artist.replace ('/', '-'), album.replace ('/', '-'), extension)	
 
-	def get_pixbuf (self, db, entry, on_get_pixbuf_completed):
+	def get_pixbuf (self, db, entry, callback):
 		if entry is None:
-			on_get_pixbuf_completed (db, entry, None)
+			callback (entry, None)
 			return
             
 		st_artist = db.entry_get (entry, rhythmdb.PROP_ARTIST)
@@ -123,7 +113,7 @@
 
 		# If unknown artist and album there is no point continuing
 		if st_album == "Unknown" and st_artist == "Unknown":
-			on_get_pixbuf_completed (db, entry, None)
+			callback (entry, None)
 			return
 
 		# replace quote characters
@@ -137,52 +127,50 @@
 		# Check local cache
 		if os.path.exists (art_location):
 			pixbuf = gtk.gdk.pixbuf_new_from_file (art_location)	
-			on_get_pixbuf_completed (db, entry, pixbuf)
+			callback (entry, pixbuf)
 		# Check for unsuccessful previous image download to prevent overhead search
 		elif os.path.exists (blist_location):
-			on_get_pixbuf_completed (db, entry, None)
+			callback (entry, None)
 		else:
 			# Otherwise spawn (online) search-engine search
-			if entry != self.search_engine.entry:
-				self.on_get_pixbuf_completed = on_get_pixbuf_completed
-				self.search_engine.search (db, entry, self.on_search_engine_results)
+			se = self.create_search ()
+			se.search (db, entry, self.on_search_engine_results, callback)
 
-	def on_search_engine_results (self, db, entry, results):
+	def on_search_engine_results (self, search_engine, entry, results, callback):
 		if results is None:
-			self.on_get_pixbuf_completed (db, entry, None)
+			callback (entry, None)
 			return
 
 		# Get best match from results
-		self.best_match = self.search_engine.get_best_match (results)
+		best_match = search_engine.get_best_match (results)
 
 		# Attempt to download image for best match
-		pic_url = str(self.best_match.ImageUrlLarge)
-		self.image_version = "large";
-		self.image_loader.get_url (pic_url, self.on_image_data_received)
+		pic_url = str(best_match.ImageUrlLarge)
+		self.loader.get_url (pic_url, self.on_image_data_received, search_engine, "large", callback, best_match)
 
-	def on_image_data_received	 (self, image_data):
+	def on_image_data_received (self, image_data, search_engine, image_version, callback, best_match):
 		if image_data is None:
-			self.search_engine.search_next()
+			search_engine.search_next()
 			return
 
 		if len(image_data) < 1000:
-			if self.image_version == "large":
+			if image_version == "large":
 				# Fallback and try to load medium one
-				self.image_version = "medium"
-				pic_url = str(self.best_match.ImageUrlMedium)
-				self.image_loader.get_url (pic_url, self.on_image_data_received)
+				best_match = search_engine.get_best_match (best_match)
+				pic_url = str(best_match.ImageUrlMedium)
+				self.loader.get_url (pic_url, self.on_image_data_received, search_engine, "medium", callback)
 				return
-			blist_location = self.build_art_cache_filename(self.search_engine.st_album, self.search_engine.st_artist, "rb-blist")
+			blist_location = self.build_art_cache_filename(search_engine.st_album, search_engine.st_artist, "rb-blist")
 			f = file (blist_location, 'w')
 			f.close ()
-			self.search_engine.search_next()
+			search_engine.search_next()
 		else:
-			art_location = self.build_art_cache_filename(self.search_engine.st_album, self.search_engine.st_artist, "jpg")
+			art_location = self.build_art_cache_filename(search_engine.st_album, search_engine.st_artist, "jpg")
 			f = file (art_location, 'wb')
 			f.write (image_data)
 			f.close ()
 			pixbuf = gtk.gdk.pixbuf_new_from_file (art_location)
-			self.on_get_pixbuf_completed (self.search_engine.db, self.search_engine.entry, pixbuf)
+			callback (search_engine.entry, pixbuf)
 
 class Bag: pass
 
@@ -211,12 +199,13 @@
 		lc_name = self._supportedLocales[lc_id][0]
 		return ((lc_host, lc_name))
 
-	def search (self, db, entry, on_search_completed_callback):
+	def search (self, db, entry, on_search_completed_callback, *args):
 		self.searching = True
 		self.cancel = False
 		self.db = db
 		self.entry = entry
 		self.on_search_completed_callback = on_search_completed_callback
+		self.args = args
 		self.keywords = []
 
 		st_artist = db.entry_get (entry, rhythmdb.PROP_ARTIST)
@@ -345,7 +334,7 @@
 		self.on_search_completed (results)
 
 	def on_search_completed (self, result):
-		self.on_search_completed_callback (self.db, self.entry, result)
+		self.on_search_completed_callback (self, self.entry, result, *self.args)
 		self.searching = False
 
 	# TODO: Better overall matching algo - "==" is inaccurate on minor differences
@@ -440,7 +429,7 @@
 			self.current_entry = entry
 			self.art_db.get_pixbuf(db, entry, self.on_get_pixbuf_completed)
 
-	def on_get_pixbuf_completed(self, db, entry, pixbuf):
+	def on_get_pixbuf_completed(self, entry, pixbuf):
 		# Set the pixbuf for the entry returned from the art db
 		self.set_current_art (pixbuf)
 
