--- plugins/artdisplay/artdisplay/__init__.py	2007/01/18 18:32:08	1.4
+++ plugins/artdisplay/artdisplay/__init__.py	2007/01/19 00:55:03
@@ -234,12 +234,19 @@ gobject.type_register (FadingImage)
 
 
 class ArtDisplayWidget (FadingImage):
+	__gsignals__ = {
+			'drop-pixbuf' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (rhythmdb.RhythmDB, rhythmdb.Entry, gtk.gdk.Pixbuf)),
+			'drop-uri' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (rhythmdb.RhythmDB, rhythmdb.Entry, gobject.TYPE_STRING))
+			}
+
 	def __init__ (self, shell, missing_image):
 		self.shell = shell
 		super (ArtDisplayWidget, self).__init__ (missing_image)
 		self.set_padding (0, 5)
 		db = shell.get_property ("db")
 		self.eemn_art_id = db.connect_after ('entry-extra-metadata-notify::rb:coverArt', self.cover_art_notify)
+		self.ddg_id = self.connect ('drag-data-get', self.drag_data_get)
+		self.ddr_id = self.connect ('drag-data-received', self.drag_data_received)
 		self.current_entry, self.working = None, False
 		self.current_pixbuf, self.current_uri = None, None
 	
@@ -247,12 +254,36 @@ class ArtDisplayWidget (FadingImage):
 		super (ArtDisplayWidget, self).disconnect_handlers ()
 		db = shell.get_property ("db")
 		db.disconnect (self.eemn_art_id)
+		self.disconnect (self.ddg_id)
+		self.disconnect (self.ddr_id)
+	
+	def update_dnd_targets (self):
+		targets = None
+		if self.current_entry:
+			targets = gtk.target_list_add_image_targets (targets)
+			targets = gtk.target_list_add_uri_targets (targets)
+			targets = gtk.target_list_add_text_targets (targets)
+		if targets:
+			self.drag_dest_set (gtk.DEST_DEFAULT_ALL, targets, gtk.gdk.ACTION_COPY)
+		else:
+			self.drag_dest_unset ()
+
+		targets = None
+		if self.current_pixbuf:
+			targets = gtk.target_list_add_image_targets (targets, writable=True)
+		if self.current_uri:
+			targets = gtk.target_list_add_uri_targets (targets)
+		if targets:
+			self.drag_source_set (gtk.gdk.BUTTON1_MASK, targets, gtk.gdk.ACTION_COPY)
+		else:
+			self.drag_source_unset ()
 	
 	def set (self, entry, pixbuf, uri, working):
 		self.current_entry = entry
 		self.current_pixbuf = pixbuf
 		self.current_uri = uri
 		self.set_current_art (pixbuf, working)
+		self.update_dnd_targets ()
 
 	def cover_art_notify (self, db, entry, field, metadata):
 		if entry != self.current_entry:
@@ -263,6 +294,26 @@ class ArtDisplayWidget (FadingImage):
 			return
 		self.set (entry, metadata, None, False)
 
+	def drag_data_get (self, widget, drag_context, selection_data, info, timestamp):
+		if self.current_pixbuf:
+			selection_data.set_pixbuf (self.current_pixbuf)
+		if self.current_uri:
+			selection_data.set_uris ([self.current_uri])
+
+	def drag_data_received (self, widget, drag_context, x, y, selection_data, info, timestamp):
+		db = self.shell.get_property ("db")
+		entry = self.current_entry
+		pixbuf = selection_data.get_pixbuf ()
+		uris = selection_data.get_uris ()
+		text = selection_data.get_text ()
+		if pixbuf:
+			self.emit ('pixbuf-dropped', db, entry, pixbuf)
+		elif uris:
+			self.emit ('uri-dropped', db, entry, uris[0])
+		elif text:
+			self.emit ('uri-dropped', db, entry, text)
+gobject.type_register (ArtDisplayWidget)
+
 
 class ArtDisplayPlugin (rb.Plugin):
 	def __init__ (self):
@@ -277,6 +328,8 @@ class ArtDisplayPlugin (rb.Plugin):
 		self.eemr_art_id = db.connect_after ('entry-extra-metadata-request::rb:coverArt', self.cover_art_request)
 		self.eemn_art_id = db.connect_after ('entry-extra-metadata-notify::rb:coverArt', self.cover_art_notify)
 		self.art_widget = ArtDisplayWidget (shell, self.find_file (ART_MISSING_ICON + ".svg"))
+		self.art_widget.connect ('pixbuf-dropped', self.on_set_pixbuf)
+		self.art_widget.connect ('uri-dropped', self.on_set_uri)
 		shell.add_widget (self.art_widget, rb.SHELL_UI_LOCATION_SIDEBAR)
 		self.art_db = CoverArtDatabase ()
 		self.current_entry, self.current_pixbuf = None, None
@@ -334,3 +387,8 @@ class ArtDisplayPlugin (rb.Plugin):
 	def cover_art_notify (self, db, entry, field, metadata):
 		self.art_db.cancel_get_pixbuf (entry)
 
+	def on_set_pixbuf (self, widget, db, entry, pixbuf):
+		self.art_db.set_pixbuf (db, entry, pixbuf, self.on_get_pixbuf_completed)
+
+	def on_set_uri (self, widget, db, entry, uri):
+		self.art_db.set_pixbuf_from_uri (db, entry, uri, self.on_get_pixbuf_completed)
