Add i18n to mussorgsky
[mussorgsky] / src / edit_panel_tm.py
index 7cd280f..751c534 100644 (file)
@@ -17,6 +17,11 @@ MIME_COLUMN = 5
 UI_COLUMN = 6
 SEARCH_COLUMN = 7
 
+THEME_PATH = "/usr/share/themes/default"
+
+import i18n
+_ = i18n.language.gettext
+
 class MussorgskyEditPanel (hildon.StackableWindow):
 
     def __init__ (self):
@@ -30,6 +35,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         self.data_loaded = False
         self.artist_list = None
         self.albums_list = None
+        self.current = None
         self.connect ("delete-event", self.close_function)
 
     def close_function (self, widget, event):
@@ -41,8 +47,8 @@ class MussorgskyEditPanel (hildon.StackableWindow):
 
         
     def update_title (self):
-        self.set_title ("Edit (%d/%d)" % (self.model.get_path (self.current)[0] + 1,
-                                          len (self.model)))
+        self.set_title (_("Edit song") + " (%d/%d)" % (self.model.get_path (self.current)[0] + 1,
+                                                       len (self.model)))
 
     def get_current_row (self):
         if (not self.current):
@@ -50,6 +56,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         return self.model.get (self.current, 0, 1, 2, 3, 4, 5)
 
     def set_model (self, model, current=None):
+        assert type(model) == gtk.TreeModelFilter
         try:
             if self.artists_list or self.albums_list:
                 pass
@@ -130,13 +137,8 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         # 0 - filename -> doesn't change
         # 1 - "Music"  -> doesn't change
         # 5 - mimetype -> doesn't change
-        if (type (self.model) == gtk.TreeModelFilter):
-            m = self.model.get_model ()
-            c = self.model.convert_iter_to_child_iter (self.current)
-        else:
-            # Very unlikely
-            m = self.model
-            c = self.current
+        m = self.model.get_model ()
+        c = self.model.convert_iter_to_child_iter (self.current)
 
         artist = self.artist_button.get_value ()
         title = self.title_entry.get_text ()
@@ -145,16 +147,16 @@ class MussorgskyEditPanel (hildon.StackableWindow):
                                                  escape_html (artist) + " / " + escape_html (album))
         search_str = artist.lower () + " " + title.lower () + " " + album.lower ()
 
+        uri, mime = m.get (c, URI_COLUMN, MIME_COLUMN)
         m.set (c,
                ARTIST_COLUMN, artist,
                TITLE_COLUMN, title,
                ALBUM_COLUMN, album,
                UI_COLUMN, text,
                SEARCH_COLUMN, search_str)
-        new_song = self.get_current_row ()
         try:
-            self.writer.save_metadata_on_file (new_song[URI_COLUMN],
-                                               new_song[MIME_COLUMN],
+            self.writer.save_metadata_on_file (uri,
+                                               mime, 
                                                self.artist_button.get_value (),
                                                self.title_entry.get_text (),
                                                self.album_button.get_value ())
@@ -162,12 +164,6 @@ class MussorgskyEditPanel (hildon.StackableWindow):
             # This error in case of tracker returning unexistent files.
             # Uhm.... for instance after removing a memory card we are editing!
             pass
-            #dialog = gtk.MessageDialog (self,
-            #                            gtk.DIALOG_DESTROY_WITH_PARENT,
-            #                            gtk.MESSAGE_ERROR,
-            #                            gtk.BUTTONS_CLOSE,
-            #                            "%s" % str(e));
-            #dialog.run ()
         
 
     def __is_view_dirty (self):
@@ -202,7 +198,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         view_vbox.pack_start (central_panel, expand=True, fill=True)
 
         # Title row
-        label_title = gtk.Label ("Title:")
+        label_title = gtk.Label (_("Title:"))
         table.attach (label_title, 0, 1, 0, 1, 0)
         self.title_entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
         table.attach (self.title_entry, 1, 2, 0, 1)
@@ -210,7 +206,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         # Artist row
         self.artist_button = hildon.PickerButton (gtk.HILDON_SIZE_THUMB_HEIGHT,
                                                   hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
-        self.artist_button.set_title ("Artist: ")
+        self.artist_button.set_title (_("Artist:"))
         # Set data will set the selector
         table.attach (self.artist_button, 0, 2, 1, 2)
 
@@ -218,7 +214,7 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         # Album row
         self.album_button = hildon.PickerButton (gtk.HILDON_SIZE_THUMB_HEIGHT,
                                                  hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
-        self.album_button.set_title ("Album: ")
+        self.album_button.set_title (_("Album:"))
         # set_data will set the selector
         table.attach (self.album_button, 0, 2, 2, 3)
         
@@ -230,8 +226,8 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         
         # Buttons row
         button_box = gtk.Toolbar ()
-
-        play_button = gtk.ToolButton (gtk.image_new_from_stock (gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON))
+        play_image = os.path.join (THEME_PATH, "mediaplayer", "Play.png")
+        play_button = gtk.ToolButton (gtk.image_new_from_file (play_image))
         play_button.connect ("clicked", self.clicked_play)                   
         play_button.set_expand (True)
         button_box.insert (play_button, -1)
@@ -240,16 +236,14 @@ class MussorgskyEditPanel (hildon.StackableWindow):
         separator.set_expand (True)
         button_box.insert  (separator, -1)
 
-        back_img = gtk.Image ()
-        back_img.set_from_icon_name ("general_back", gtk.ICON_SIZE_BUTTON)
-        back_button = gtk.ToolButton (back_img)
+        back_image = os.path.join (THEME_PATH, "mediaplayer", "Back.png")
+        back_button = gtk.ToolButton (gtk.image_new_from_file (back_image))
         back_button.connect ("clicked", self.press_back_cb)
         back_button.set_expand (True)
         button_box.insert (back_button, -1)
 
-        next_img = gtk.Image ()
-        next_img.set_from_icon_name ("general_forward", gtk.ICON_SIZE_BUTTON)
-        next_button = gtk.ToolButton (next_img)
+        next_image = os.path.join (THEME_PATH, "mediaplayer", "Forward.png")
+        next_button = gtk.ToolButton (gtk.image_new_from_file (next_image))
         next_button.connect ("clicked", self.press_next_cb)
         next_button.set_expand (True)
         button_box.insert (next_button, -1)
@@ -359,19 +353,21 @@ class MussorgskyEditPanel (hildon.StackableWindow):
 # Testing porpuses
 if __name__ == "__main__":
 
-    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 = [("/a/b/c/%d.mp3" %i, "Music",
+                  "Artist %d" % i, "Title %d" % i, "Album %d" % (i*100),
+                  "audio/mpeg",
+                  "artist %d album %d" % (i, i*100),
+                  "text to be searched artist %d album %d" % (i, i*100)) for i in range (0, 4)]
 
-    model = gtk.ListStore (str, str, str, str, str, str)
+    model = gtk.ListStore (str, str, str, str, str, str, str, str)
     for t in TEST_DATA:
+        print t
         model.append (t)
 
     window = MussorgskyEditPanel ()
-    window.set_artist_alternatives (["", "Bob Dylan"])
-    window.set_album_alternatives (["", "Bring it all back home", "Album 2", "Album 9", "Album 3"])
-    window.set_model (model)
+    window.set_artist_alternatives (["Artist %d" % i for i in range (0, 4)])
+    window.set_album_alternatives (["Album %d" % (i*100) for i in range (0, 4)])
+    window.set_model (model.filter_new ())
     window.connect ("destroy", gtk.main_quit)
     window.show_all ()
     gtk.main ()