Add .gitignore file to the repository
[mussorgsky] / src / edit_panel.py
index 6117bc3..d665180 100755 (executable)
@@ -1,8 +1,11 @@
 #!/usr/bin/env python2.5
 import hildon
-import gtk
+import gtk, gobject
 from mutagen_backend import MutagenBackend
 from player_backend import MediaPlayer
+import album_art_spec
+from album_art import MussorgskyAlbumArt
+import os
 
 # Fields in the tuple!
 FILE_URI = 0
@@ -16,8 +19,10 @@ class MussorgskyEditPanel (hildon.StackableWindow):
     def __init__ (self, songs_list=None, albums_list=None, artists_list=None):
         hildon.StackableWindow.__init__ (self)
         self.set_title ("Edit")
+        self.set_border_width (12)
         self.writer = MutagenBackend ()
         self.player = MediaPlayer ()
+        self.album_art_retriever = MussorgskyAlbumArt ()
         self.albums_list = albums_list
         self.artists_list = artists_list
         self.add (self.__create_view ())
@@ -30,8 +35,11 @@ class MussorgskyEditPanel (hildon.StackableWindow):
 
         self.albums_selector = None
         self.albums_dialog = None
+        self.album_callback_id = -1
+
         
     def set_songs_list (self, songs_list):
+        if (songs_list and len (songs_list) > 0):
             self.songs_list = songs_list
             self.set_data_in_view (songs_list [0])
             self.song_counter = 0
@@ -43,6 +51,10 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         if (self.banner and self.banner.get_property("visible")):
             self.banner.destroy ()
 
+        if (self.album_callback_id != -1):
+            gobject.source_remove (self.album_callback_id)
+            self.album_callback_id = -1
+
         if self.__is_view_dirty ():
             print "Modified data. Save!"
             self.save_metadata ()
@@ -58,6 +70,10 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         if (self.banner and self.banner.get_property("visible")):
             self.banner.destroy ()
 
+        if (self.album_callback_id != -1):
+            gobject.source_remove (self.album_callback_id)
+            self.album_callback_id = -1
+
         if self.__is_view_dirty ():
             print "Modified data. Save!"
             self.save_metadata ()
@@ -110,7 +126,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         
 
     def __create_view (self):
-        view_vbox = gtk.VBox (homogeneous=False, spacing = 24)
+        view_vbox = gtk.VBox (homogeneous=False, spacing = 12)
 
         filename_row = gtk.HBox ()
         filename_label = gtk.Label ("Filename:")
@@ -118,18 +134,21 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         self.filename_data = gtk.Label ("")
         filename_row.pack_start (self.filename_data, expand=True)
 
-        play_button = gtk.Button (stock=gtk.STOCK_MEDIA_PLAY)
+        #play_button = gtk.Button (stock=gtk.STOCK_MEDIA_PLAY)
+        play_button = hildon.Button (hildon.BUTTON_STYLE_NORMAL, hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
+        img = gtk.image_new_from_stock (gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON)
+        play_button.set_image (img)
         play_button.connect ("clicked", self.clicked_play)
-        filename_row.pack_start (play_button, expand=False, fill=False, padding=12)
-        view_vbox.pack_start (filename_row, expand=True);
+        filename_row.pack_start (play_button, expand=False, fill=False)
+        view_vbox.pack_start (filename_row, expand=False);
 
-        central_panel = gtk.HBox ()
+        central_panel = gtk.HBox (spacing=12)
 
         table = gtk.Table (3, 2, False)
         table.set_col_spacings (12)
         table.set_row_spacings (12)
 
-        central_panel.pack_start (table)
+        central_panel.pack_start (table, fill=True)
         view_vbox.pack_start (central_panel, expand=True, fill=True)
 
         # Artist row
@@ -162,21 +181,25 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         self.album_art.set_size_request (124, 124)
         album_button.add (self.album_art)
         album_button.connect ("clicked", self.clicked_album_art)
-        central_panel.pack_start (album_button, expand=False, fill=False, padding=24)
+        central_panel.pack_start (album_button, expand=False, fill=False)
         
         # Buttons row
         button_box = gtk.HButtonBox ()
         button_box.set_layout (gtk.BUTTONBOX_END)
 
-        back_button = gtk.Button (stock=gtk.STOCK_GO_BACK)
+        back_button = hildon.Button (hildon.BUTTON_STYLE_NORMAL, hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
+        img = gtk.image_new_from_stock (gtk.STOCK_GO_BACK, gtk.ICON_SIZE_BUTTON)
+        back_button.set_image (img)
         back_button.connect ("clicked", self.press_back_cb)
         button_box.pack_start (back_button, expand=True, fill=True, padding=6)
         
-        next_button = gtk.Button (stock=gtk.STOCK_GO_FORWARD)
+        next_button = hildon.Button (hildon.BUTTON_STYLE_NORMAL, hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
+        img = gtk.image_new_from_stock (gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON)
+        next_button.set_image (img)
         next_button.connect ("clicked", self.press_next_cb)
         button_box.pack_start (next_button, expand=True, fill=True, padding=6)
         
-        view_vbox.pack_start (button_box, expand=False, fill=True, padding=12)
+        view_vbox.pack_start (button_box, expand=False, fill=True, padding=6)
         
         return view_vbox
 
@@ -192,7 +215,18 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         self.title_entry.set_text (song[TITLE_KEY])
         self.album_entry.set_text (song[ALBUM_KEY])
 
-        self.album_art.set_from_file ("/home/ivan/cover-sample.jpeg")
+        has_album = False
+        if (song[ALBUM_KEY]):
+            thumb = album_art_spec.getCoverArtThumbFileName (song[ALBUM_KEY])
+           print "%s -> %s" % (song[ALBUM_KEY], thumb)
+            if (os.path.exists (thumb)):
+                self.album_art.set_from_file (thumb)
+                has_album = True
+            else:
+                self.album_callback_id = gobject.idle_add (self.retrieve_album_art, song[ARTIST_KEY], song[ALBUM_KEY])
+                
+        if (not has_album):
+            self.album_art.set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
 
         if (not song[MIME_KEY] in self.writer.get_supported_mimes ()):
             print "show notification"
@@ -200,6 +234,16 @@ class MussorgskyEditPanel (hildon.StackableWindow):
             self.banner.set_text ("Unsupported format (%s)" % song[MIME_KEY])
             self.banner.show_all ()
 
+    def retrieve_album_art (self, artist, album):
+        print "trying to get the album art"
+        (img, thumb) = self.album_art_retriever.get_album_art (artist, album)
+        if (thumb):
+            self.album_art.set_from_file (thumb)
+        else:
+            print "Unable to retrieve album art"
+
+        return False
+        
     def clicked_play (self, widget):
         if (self.player.is_playing ()):
             self.player.stop ()
@@ -250,6 +294,7 @@ if __name__ == "__main__":
 
     TEST_DATA = [("/a/b/c/d.mp3", "Music", "", "title", "album", "audio/mpeg"),
                  ("/home/user/mufix/dejame.mp3", "Music", "", "title", "album 2", "a/b"),
+                ("/media/mmc1/Attachments/1-14 Una Rosa Es Una Rosa.m4a", "Music", "", "Una rosa es una rosa", "Ana, Jose, Nacho", "audio/mpeg"),
                  ("/home/user/mufix/3.mp2", "Music", "", "titlex", "album 3", "audio/mpeg")]
     ALBUMS = [["Album %d" % i] for i in range (0, 10)]
     ARTISTS = [["Artist %d" % i] for i in range (0, 10)]