Added "trying" to download dialog
authorIvan Frade <ivan.frade@gmail.com>
Wed, 26 Aug 2009 08:46:01 +0000 (11:46 +0300)
committerIvan Frade <ivan.frade@gmail.com>
Wed, 26 Aug 2009 08:46:01 +0000 (11:46 +0300)
The big name shows the last downloaded album art
The small letters explain what are we trying to download now.
It should help in some "stall" cases.

src/download_dialog.py

index eb03119..c71fa08 100644 (file)
@@ -5,13 +5,17 @@ from utils import escape_html
 
 class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
 
-    def __init__ (self, parent):
+    def __init__ (self, parent, downloader=None):
         gtk.Dialog.__init__ (self,
                              "Downloading album art", parent,
                              gtk.DIALOG_DESTROY_WITH_PARENT,
                              (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
                         )
-        self.downloader = MussorgskyAlbumArt ()
+        if (downloader):
+            self.downloader = downloader
+        else:
+            self.downloader = MussorgskyAlbumArt ()
+            
         self.set_title ("Downloading album art")
         self.connect ("response", self.handle_response)
         self.__create_view ()
@@ -27,8 +31,8 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
         hbox.pack_start (self.album_art, expand=False, fill=True)
 
         labels = gtk.VBox ()
-        self.status_label = gtk.Label ("")
-        labels.pack_start (self.status_label)
+        self.previous_label = gtk.Label ("")
+        labels.pack_start (self.previous_label)
         self.current_label = gtk.Label ("")
         labels.pack_start (self.current_label)
 
@@ -46,7 +50,6 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
 
         it = artist_albums_model.get_iter_first ()
         while (it):
-
             while (gtk.events_pending()):
                 gtk.main_iteration()
 
@@ -56,22 +59,27 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
             artist = artist_albums_model.get_value (it, 2)
             album = artist_albums_model.get_value (it, 3)
             
+            self.current_label.set_markup ("<small>Trying: %s - %s</small>" % (escape_html(artist),
+                                                                                   escape_html(album)))
+            
             try:
+                while (gtk.events_pending()):
+                    gtk.main_iteration()
+
+                if (self.cancel):
+                    break
+                
                 (image, thumb) = self.downloader.get_album_art (artist, album)
                 if thumb:
-                        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 124, 124)
+                        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
                         artist_albums_model.set_value (it, 1, pixbuf)
             except Exception, e:
                 print "Error processing %s - %s" % (artist, album)
                 print str(e)
-                self.album_art.set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
-                current += 1
-                it = artist_albums_model.iter_next (it)
-                continue
-
-            #self.status_label.set_text ("Retrieved (%d/%d)" % (current, TOTAL))
+                thumb = None
+            
             self.set_title ("Downloading album art (%d/%d)" % (current, TOTAL))
-            self.current_label.set_markup ("<b>%s - %s</b>" % (escape_html(artist), escape_html(album)))
+            self.previous_label.set_markup ("<b>%s - %s</b>" % (escape_html(artist), escape_html(album)))
               
             if (thumb):
                 self.album_art.set_from_file (thumb)
@@ -90,12 +98,25 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
 
 if __name__ == "__main__":
 
+    import time
+    import random
+    class MockDownloader:
+        def __init__ (self):
+            self.alt = [("../hendrix.jpeg", "../hendrix-thumb.jpeg"),
+                        ("../hoover.jpeg", "../hoover-thumb.jpeg"),
+                        ("../backbeat.jpeg", "../backbeat-thumb.jpeg"),
+                        ("../dylan.jpeg", "../dylan-thumb.jpeg")]
+            self.counter = 0
+        def get_album_art (self, artist, album, force=False):
+            time.sleep (3)
+            return  self.alt [random.randint (0, len (self.alt)-1)]
+
     PAIRS_store = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str)
     for i in range (0, 100):
         PAIRS_store.append (("blablabal", None, "Artist %d" % i, "Album %d" %i))
 
     def clicked_button (self):
-        aadd = MussorgskyAlbumArtDownloadDialog (w)
+        aadd = MussorgskyAlbumArtDownloadDialog (w, MockDownloader ())
         aadd.show_all ()
         aadd.do_the_job (PAIRS_store)