Remove references to the old album_art file
[mussorgsky] / src / edit_panel.py
index a997e1e..3de1d5b 100755 (executable)
@@ -4,7 +4,6 @@ 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!
@@ -18,21 +17,25 @@ 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.song_counter = 0
         self.album_callback_id = -1
         self.album_change_handler = -1
+        self.artist_change_handler = -1
         self.writer = MutagenBackend ()
         self.player = MediaPlayer ()
-        self.album_art_retriever = MussorgskyAlbumArt ()
         self.albums_list = [a [0] for a in albums_list]
         self.artists_list = [a [0] for a in artists_list]
-        self.add (self.__create_view ())
+        self.__create_view ()
         if (songs_list):
             self.set_songs_list (songs_list)
+        self.update_title ()
         self.banner = None
 
+
+    def update_title (self):
+        self.set_title ("Edit (%d/%d)" % (self.song_counter+1, len (self.songs_list)))
+
         
     def set_songs_list (self, songs_list):
         if (songs_list and len (songs_list) > 0):
@@ -58,6 +61,9 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         if (self.song_counter > 0):
             self.song_counter -= 1
             self.set_data_in_view (self.songs_list [self.song_counter])
+            self.update_title ()
+        else:
+            self.destroy ()
 
     def press_next_cb (self, widget):
         if (self.player.is_playing ()):
@@ -77,6 +83,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         if (self.song_counter < len (self.songs_list) -1):
             self.song_counter += 1
             self.set_data_in_view (self.songs_list [self.song_counter])
+            self.update_title ()
         else:
             self.destroy ()
 
@@ -153,7 +160,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         table.attach (self.title_entry, 1, 2, 0, 1)
 
         # Artist row
-        artist_selector = hildon.hildon_touch_selector_entry_new_text ()
+        artist_selector = hildon.TouchSelectorEntry (text=True)
         for a in self.artists_list:
             artist_selector.append_text (a)
         self.artist_button = hildon.PickerButton (hildon.BUTTON_STYLE_NORMAL,
@@ -164,7 +171,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
 
 
         # Album row
-        album_selector = hildon.hildon_touch_selector_entry_new_text ()
+        album_selector = hildon.TouchSelectorEntry (text=True)
         for a in self.albums_list:
             album_selector.append_text (a)
         self.album_button = hildon.PickerButton (hildon.BUTTON_STYLE_NORMAL,
@@ -200,8 +207,20 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         
         view_vbox.pack_start (button_box, expand=False, fill=True, padding=6)
         
-        return view_vbox
+        self.add (view_vbox)
+
+        #menu = hildon.AppMenu ()
+        #go_to = hildon.Button (hildon.BUTTON_STYLE_NORMAL,
+        #                       hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
+        #go_to.set_title ("Go to")
+        #go_to.connect ("clicked", self.go_to_cb)
+        #menu.append (go_to)
+        #menu.show_all ()
+        #self.set_app_menu (menu)
+        
 
+    def go_to_cb (self, widget):
+        pass
 
     def set_data_in_view (self, song):
         """
@@ -213,25 +232,34 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         self.filename_data.set_text (song[FILE_URI])
         self.title_entry.set_text (song[TITLE_KEY])
         
+
+        # Disconnect the value-change signal to avoid extra album art retrievals
+        if (self.album_button.handler_is_connected (self.album_change_handler)):
+            self.album_button.disconnect (self.album_change_handler)
+            
+        if (self.artist_button.handler_is_connected (self.artist_change_handler)):
+            self.artist_button.disconnect (self.artist_change_handler)
+
+        # Set values in the picker buttons
         try:
             self.artist_button.set_active (self.artists_list.index(song[ARTIST_KEY]))
         except ValueError:
             print "'%s' not in artist list!?" % (song[ARTIST_KEY])
-
-        # Disconnect the value-change signal to avoid extra album art retrievals
-        if (self.album_change_handler != -1):
-            self.album_button.disconnect (self.album_change_handler)
-            self.album_change_handle = -1
+            self.artist_button.set_value ("")
             
         try:
             self.album_button.set_active (self.albums_list.index (song[ALBUM_KEY]))
         except ValueError:
             print "'%s' is not in the album list!?" % (song[ALBUM_KEY])
+            self.album_button.set_value ("")
 
-        # Reconnect the signal!
+        # Reconnect the signals!
         self.album_change_handler = self.album_button.connect ("value-changed",
                                                                self.album_selection_cb)
 
+        self.artist_change_handler = self.artist_button.connect ("value-changed",
+                                                                 self.artist_selection_cb)
+
         # Set the album art given the current data
         has_album = False
         if (song[ALBUM_KEY]):
@@ -274,19 +302,38 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         print "implement me, please"
 
     def album_selection_cb (self, widget):
+        """
+        On album change, add the album the local list of albums and the selector
+        if it doesn't exist already. So we show the new entry in the selector next time.
+        """
         song = self.songs_list [self.song_counter]
+        if (not widget.get_value () in self.albums_list):
+            print "Inserting ", widget.get_value ()
+            widget.get_selector ().prepend_text (widget.get_value ())
+            self.albums_list.insert (0, widget.get_value ())
         self.retrieve_album_art (song[ARTIST_KEY], widget.get_value ())
+
+    def artist_selection_cb (self, widget):
+        """
+        On artist change, add the artist the local list of artists and the selector
+        if it doesn't exist already. So we show the new entry in the selector next time
+        """
+        song = self.songs_list [self.song_counter]
+        if (not widget.get_value () in self.artists_list):
+            print "Inserting artist", widget.get_value ()
+            widget.get_selector ().prepend_text (widget.get_value ())
+            self.artists_list.insert (0, widget.get_value ())
     
 # Testing porpuses
 if __name__ == "__main__":
 
-    TEST_DATA = [("/a/b/c/d.mp3", "Music", "", "title", "Album 9", "audio/mpeg"),
+    TEST_DATA = [("/home/user/Music/dylan.mp3", "Music", "Bob Dylan", "Subterranean homesick blues", "Bring it all back home", "audio/mpeg"),
                  ("/home/user/mufix/a.mp3", "Music", "", "title", "Album 2", "a/b"),
                 ("/media/mmc1/Attachments/b.m4a", "Music", "", "b", "Album 9", "audio/mpeg"),
                  ("/home/user/mufix/3.mp2", "Music", "", "titlex", "Album 3", "audio/mpeg")]
     #TEST_DATA = []
-    ALBUMS = [["Album %d" % i] for i in range (0, 10)]
-    ARTISTS = [["Artist %d" % i] for i in range (0, 10)]
+    ALBUMS = [["Album %d" % i] for i in range (0, 10)] + [["Bring it all back home"]]
+    ARTISTS = [["Artist %d" % i] for i in range (0, 10)] + [["Bob Dylan"]]
     window = MussorgskyEditPanel (TEST_DATA, ALBUMS, ARTISTS)
     window.connect ("destroy", gtk.main_quit)
     window.show_all ()