--- plugins/artdisplay/artdisplay/__init__.py	2007/02/20 18:51:09	1.3
+++ plugins/artdisplay/artdisplay/__init__.py	2007/02/20 18:56:01
@@ -19,6 +19,7 @@
 import rhythmdb, rb
 import gtk, gobject
 import pango
+import os, gnomevfs, tempfile
 from warnings import warn
 
 from CoverArtDatabase import CoverArtDatabase
@@ -32,6 +33,8 @@ ui_str = """
 		<separator/>
 		<menuitem name="SetCover" action="SetCover"/>
 		<menuitem name="SearchCover" action="SearchCover"/>
+		<separator/>
+		<menuitem name="ViewCover" action="ViewCover"/>
 	</popup>
 </ui>
 """
@@ -737,11 +740,15 @@ class ArtDisplayPlugin (rb.Plugin):
 		self.paste_cover_action = gtk.Action ('PasteCover', _('Paste'), _('Paste cover art from clipboard'), gtk.STOCK_PASTE)
 		self.paste_cover_action.connect ('activate', self.paste_cover)
 		self.paste_cover_action.set_sensitive (False)
+		self.view_cover_action = gtk.Action ('ViewCover', _('_View cover'), _('Open cover art in the image viewer'), None)
+		self.view_cover_action.connect ('activate', self.view_cover)
+		self.view_cover_action.set_sensitive (False)
 		self.action_group = gtk.ActionGroup ('ArtDisplayPluginActions')
 		self.action_group.add_action (self.set_cover_action)
 		self.action_group.add_action (self.search_cover_action)
 		self.action_group.add_action (self.copy_cover_action)
 		self.action_group.add_action (self.paste_cover_action)
+		self.action_group.add_action (self.view_cover_action)
 		uim = shell.get_ui_manager ()
 		uim.insert_action_group (self.action_group, 0)
 		self.ui_id = uim.add_ui_from_string (ui_str);
@@ -775,6 +782,7 @@ class ArtDisplayPlugin (rb.Plugin):
 		self.search_cover_action.set_sensitive (bool (self.current_entry))
 		self.copy_cover_action.set_sensitive (bool (self.current_entry) and bool (self.current_pixbuf))
 		self.paste_cover_action.set_sensitive (bool (self.current_entry))
+		self.view_cover_action.set_sensitive (bool (self.current_uri) or bool (self.current_pixbuf))
 
 	def set_entry (self, entry):
 		if entry == self.current_entry:
@@ -835,6 +843,7 @@ class ArtDisplayPlugin (rb.Plugin):
 				self.art_db.cancel_get_pixbuf (entry)
 				self.on_get_pixbuf_completed (entry, pixbuf, uri)
 		load_pixbuf_from_uri (self.current_uri, pixbuf_cb, self.current_uri)
+		self.set_actions_sensitive ()
 
 	def set_cover (self, action):
 		entry = self.current_entry
@@ -870,6 +879,30 @@ class ArtDisplayPlugin (rb.Plugin):
 		if text:
 			self.art_db.set_pixbuf_from_uri (db, entry, text, self.on_get_pixbuf_completed)
 
+	def view_cover (self, action):
+		if self.current_uri:
+			uri = str (gnomevfs.URI (self.current_uri))
+			mime = gnomevfs.get_mime_type (uri)
+			scheme = gnomevfs.get_uri_scheme (uri)
+			# http://bugzilla.gnome.org/show_bug.cgi?id=411560
+			id, name, command, multi, paths_for_local, schemes, term = gnomevfs.mime_get_default_application (mime)
+			if scheme == 'file' and paths_for_local:
+				return os.spawnlp (os.P_WAIT, command, command, gnomevfs.get_local_path_from_uri (uri))
+			elif scheme == 'file' or scheme in schemes:
+				return os.spawnlp (os.P_WAIT, command, command, uri)
+			else:
+				for id, name, command, multi, paths_for_local, schemes, term in gnomevfs.mime_get_short_list_applications (mime) + gnomevfs.mime_get_all_applications (mime):
+					if scheme in schemes:
+						return os.spawnlp (os.P_WAIT, command, command, uri)
+		if self.current_pixbuf:
+			id, name, command, multi, paths_for_local, schemes, term = gnomevfs.mime_get_default_application (mime)
+			temp_loc = tempfile.mkstemp ('jpg', 'rb-artwork')
+			self.current_pixbuf.save (temp_loc, 'jpeg', {"quality": "100"})
+			if paths_for_local:
+				return os.spawnlp (os.P_WAIT, command, command, temp_loc)
+			else:
+				return os.spawnlp (os.P_WAIT, command, command, gnomevfs.get_uri_from_local_path(temp_loc))
+
 	def create_song_info (self, shell, song_info, is_multiple):
 		x = ArtPane (shell.get_property ("db"), song_info, self.art_db)
 
