Use __ to prefix internal methods
[mussorgsky] / src / download_dialog.py
index 2a61af9..eb03119 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python2.5
 import gtk, gobject
 from album_art import MussorgskyAlbumArt
+from utils import escape_html
 
 class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
 
@@ -13,10 +14,10 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
         self.downloader = MussorgskyAlbumArt ()
         self.set_title ("Downloading album art")
         self.connect ("response", self.handle_response)
-        self.create_view ()
+        self.__create_view ()
         self.cancel = False
 
-    def create_view (self):
+    def __create_view (self):
 
         hbox = gtk.HBox (homogeneous=False)
 
@@ -36,27 +37,41 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
         self.vbox.add (hbox)
 
 
-    def do_the_job (self, artist_albums):
-        TOTAL = len (artist_albums)
+    def do_the_job (self, artist_albums_model):
+        """
+        each row: ("Visible text", pixbuf, Artist, Album)
+        """
+        TOTAL = len (artist_albums_model)
         current = 1
-        
-        for (artist, album) in artist_albums:
+
+        it = artist_albums_model.get_iter_first ()
+        while (it):
+
             while (gtk.events_pending()):
                 gtk.main_iteration()
 
             if (self.cancel):
                 break
+
+            artist = artist_albums_model.get_value (it, 2)
+            album = artist_albums_model.get_value (it, 3)
             
             try:
                 (image, thumb) = self.downloader.get_album_art (artist, album)
-            except LookupError, e:
+                if thumb:
+                        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 124, 124)
+                        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))
-            self.current_label.set_markup ("<b>%s - %s</b>" % (artist, album))
+            #self.status_label.set_text ("Retrieved (%d/%d)" % (current, TOTAL))
+            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)))
               
             if (thumb):
                 self.album_art.set_from_file (thumb)
@@ -64,6 +79,7 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
                 self.album_art.set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
 
             current += 1
+            it = artist_albums_model.iter_next (it)
 
         
     def handle_response (self, widget, response_id):
@@ -74,18 +90,14 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
 
 if __name__ == "__main__":
 
-    PAIRS_NO = [("Led Zeppelin", "Led Zeppelin IV"),
-             ("Pink Floyd", "The Wall"),
-             ("Deep purple", "Made in Japan"),
-             ("", "Freakin' out"),
-             ("Dinah Washington", "")]
-
-    PAIRS = [ ("Artist %d" % i, "Album %d" %i) for i in range (0, 100)]
+    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.show_all ()
-        aadd.do_the_job (PAIRS)
+        aadd.do_the_job (PAIRS_store)
         
     w = gtk.Window ()
     box = gtk.VBox ()