Commits

Damián Nohales committed 03841e4

Asynchronous cover download for in the playlist, tooltip slightly modified.

Oh... we need to change the "Loading" image. I create a dummy image to make it work for now.
I suggest... errr... a sand clock. I tried to set a PixbufAnimation to the item, but is not supported by Gtk+.

Comments (0)

Files changed (4)

data/loading.png

Added
New image

data/play.png

Old
Old image
New
New image
 from lib.tfuncs import KeyListenerThread
 from lib.tfuncs import LyricsThread
 from lib.tfuncs import UpdateThread
+from lib.tfuncs import SongCoverThread
 import lib.guihelpers
 import locale
 import gettext
         song_string = "<span>%s</span>\n<span fgcolor='#777777'>%s</span>" % (self.get_sliced_string(song['SongName'], 25), self.get_sliced_string(song['ArtistName'],20))
         #if len(song_string) > 14:
         #    song_string = song_string[:13] + "..."
-        tooltip = _("<b>Song:</b> {artist} - {title}\n").format(artist=song['ArtistName'], 
-                                                                title=song['SongName'])
+        tooltip = _("<b>Title:</b> {title}\n").format(title=song['SongName'])
+        tooltip += _("<b>Artist:</b> {artist}\n").format(artist=song['ArtistName'])
         tooltip += _("<b>Album:</b> {album}\n").format(album=song['AlbumName'])
-        tooltip += _("<b>Year:</b> {year}").format(year=song['Year'])  
-        self.playlist.append([
+        tooltip += _("<b>Year:</b> {year}").format(year=song['Year'])
+        
+        appended_iter = self.playlist.append([
             song_string,
-            self.create_track_icon(song['CoverArtFilename']),
-            tooltip ,
+            self.create_loading_track_icon(),
+            tooltip,
             song['SongID'],
             song,
             400
         ])
         
-    def create_track_icon(self, cover_url):
-        try:
-            url = "http://beta.grooveshark.com/static/amazonart/s%s"
-            response = urllib2.urlopen(url % cover_url)
-            loader = gtk.gdk.PixbufLoader()
-            loader.write(response.read())
-            loader.close()
-            corners = gtk.gdk.pixbuf_new_from_file("%s/data/corners.png" % BASEPATH)
-            image = loader.get_pixbuf()
-            corners.composite(image, 0, 0, image.props.width, image.props.height,
-                              0, 0, 1.0, 1.0, gtk.gdk.INTERP_HYPER, 255)
-            return image
-        except:
-            corners = gtk.gdk.pixbuf_new_from_file("%s/data/corners.png" % BASEPATH)
-            default = gtk.gdk.pixbuf_new_from_file("%s/data/sdefault.png" % BASEPATH)
-            corners.composite(default, 0, 0, default.props.width, default.props.height,
-                              0, 0, 1.0, 1.0, gtk.gdk.INTERP_HYPER, 255)
-            return default
-        
+        thread = SongCoverThread(self, appended_iter)
+        thread.start()
+    
+    def create_default_track_icon(self):
+        default = gtk.gdk.pixbuf_new_from_file("%s/data/sdefault.png" % BASEPATH)
+        return self.create_cornered_image(default)
+    
+    def create_loading_track_icon(self):
+        default = gtk.gdk.pixbuf_new_from_file("%s/data/loading.png" % BASEPATH)
+        return self.create_cornered_image(default)
+    
+    def create_cornered_image(self, pixbuf):
+        corners = gtk.gdk.pixbuf_new_from_file("%s/data/corners.png" % BASEPATH)
+        corners.composite(pixbuf, 0, 0, pixbuf.props.width, pixbuf.props.height,
+                          0, 0, 1.0, 1.0, gtk.gdk.INTERP_HYPER, 255)
+        return pixbuf
+    
     def get_current_cover_url(self, iter):
         song = self.playlist.get_value(self.last_iter, 4)
         try: 
         """
         Removes all items from the playlist
         """
+        self.stop_play()
         self.playlist.clear()
-        self.stop_play()
 
     def toggle_repeat(self, widget, data=None):
         """
                                               self.song,
                                               lyrics)
             lyrdiag.show_all()
+
+class SongCoverThread(threading.Thread):
+    def __init__(self, _parent, _iter):
+        threading.Thread.__init__(self)
+        self.parent = _parent
+        self.iter = _iter
+    
+    def run(self):
+        cover_url = self.parent.playlist_song(self.iter)['CoverArtFilename']
+        pixbuf = None
+        
+        try:
+            url = "http://beta.grooveshark.com/static/amazonart/s%s"
+            response = urllib2.urlopen(url % cover_url)
+            loader = gtk.gdk.PixbufLoader()
+            loader.write(response.read())
+            loader.close()
+            image = loader.get_pixbuf()
+            pixbuf = self.parent.create_cornered_image(image)
+        except:
+            pixbuf = self.parent.create_default_track_icon()
+            
+        self.parent.playlist[self.iter][1] = pixbuf
+