Commits

Vladimir Kolev committed 4ba6a27

A try to fix the problems with the special characters in labels

Comments (0)

Files changed (2)

 except locale.Error:
     locale.setlocale(locale.LC_ALL, 'en_US.utf8')
 locale.bindtextdomain(APP, DIR)
+locale.bind_textdomain_codeset(APP, 'UTF-8')
 gettext.bindtextdomain(APP, DIR)
 gettext.textdomain(APP)
 gettext.install(APP, localedir = DIR, unicode = True)
             dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                       0, gtk.BUTTONS_OK,)
             dialog.set_title(_("Song Information - {songid}").format(songid = song['SongID']))
-            _filename = _("<b>Filename:</b> {artist} - {title}.mp3\n").format(artist = song['ArtistName'],
+            _filename = _("<b>Filename:</b> {artist} - {title}.mp3\n").format(artist = glib.markup_escape_text(song['ArtistName']),
                                                        title = glib.markup_escape_text(song['SongName']))
-            _artist = _("<b>Artist:</b> {artist}\n").format(artist = song['ArtistName'])
+            _artist = _("<b>Artist:</b> {artist}\n").format(artist = glib.markup_escape_text(song['ArtistName']))
             _title = _("<b>Title:</b> {title}\n").format(title = glib.markup_escape_text(song['SongName']))
             _duration = "%.2f" % (float(song['EstimateDuration']) / 60)
             _duration = _("<b>Duration:</b> {mins}:{secs} min\n").format(mins = _duration.split(".")[0],
                                                       secs = _duration.split(".")[1])
-            _album = _("<b>Album:</b> {album}\n").format(album = song['AlbumName'])
+            _album = _("<b>Album:</b> {album}\n").format(album = glib.markup_escape_text(song['AlbumName']))
             _year = _("<b>Year:</b> {year}\n").format(year = song['Year'])
             info = _filename + _artist + _title + _duration + _album + _year
             image = gtk.Image()
         """
         if self.current_song != None:
             t = LyricsThread(self, '%s/data/lyrics_dialog.ui' % BASEPATH,
-                        self.current_song['ArtistName'], self.current_song['SongName'])
+                            self.current_song['ArtistName'],
+                            self.current_song['SongName'])
             t.start()
             #lyric = lib.lyrdblib.search(song['ArtistName'],
             #                             song['SongName'])
+        else:
+            info = lib.guihelpers.InfoDialog(self.window,
+                _("There should be a playing song to view\nthe lyrics for it"))
+            info.show_all()
 
     def show_about(self, widget, data = None):
         """
             play.composite(image1, 0, 0, image1.props.width, image1.props.height,
                               0, 0, 1.0, 1.0, gtk.gdk.INTERP_HYPER, 255)
             self.playlist.set(playing, 1, image1)
-
             self.songinfo.set_markup(
                 _("<b>Playing:</b> {artist} - {title}").format(artist = glib.markup_escape_text(self.current_song['ArtistName']),
                                          title = glib.markup_escape_text(self.current_song['SongName']))
             )
             if int(CONFIG['show_notification']) == 1:
                 n = pynotify.Notification(_("Now playing"),
-                    "%s - %s" % (song['ArtistName'], song['SongName']),
+                    "%s - %s" % (glib.markup_escape_text(song['ArtistName']),
+                                 glib.markup_escape_text(song['SongName'])),
                     "audio-x-generic")
                 n.set_timeout(50)
                 n.show()
             #filename = "%s - %s.mp3" % (song["ArtistName"].strip("<>:\"/\|?*"),
             #                        song["SongName"].strip("<>:\"/\|?*"))
             pattern = CONFIG['file_pattern'] + ".mp3"
-            filename = pattern.format(artist = song['ArtistName'].strip("<>:\"/\|?*"),
-                                      song = song["SongName"].strip("<>:\"/\|?*"),
-                                      album = song["AlbumName"].strip("<>:\"/\|?*"))
+            filename = pattern.format(artist = song['ArtistName'].strip("<>:\"/\|?&*"),
+                                      song = song["SongName"].strip("<>:\"/\|?&*"),
+                                      album = song["AlbumName"].strip("<>:\"/\|?&*"))
             filename = filename.replace('/', '-')
             filename = os.path.join(CONFIG['down_path'], filename)
             filename = self.get_overwritten_filename(filename)
             else:
                 self.downmenu.popup(None, None, None, event.button, event.time)
 
-    def cancel_download(self, path):
+    def cancel_download(self, path, option = None):
         """
         Cancel a download by a list path
         """
         thread = self.downloads[path[0]][4]
-        thread.stop()
+        thread.stop(option)
         # TODO: Should improve the busy waiting
         while(thread.is_alive()):
             pass
         """
         select = self.downloads_view.get_selection().get_selected_rows()
         for path in select[1]:
-            self.cancel_download(path)
+            self.cancel_download(path, 'cancel')
 
     def on_stop_download(self, button, data = None):
         """
+        TODO: Not yet implemented, have to see how the download
+        list will be saved.
         Stop download, in order to be resumed later
         """
-        pass
+        select = self.downloads_view.get_selection().get_selected_rows()
+        for path in select[1]:
+            self.cancel_download(path, 'stop')
 
     def on_resume_download(self, button, data = None):
         """
+        TODO: Not yet implemnted, after stopping download we have to
+        load the download list in order to resume.
         Resume stopped download
         """
+        pass
 
     def get_stream_url(self):
         """
                     _("There is no song to be loved.\n A song should be playing"))
             info.show_all()
         else:
-            track = self.lastfm.get_track(self.current_song['ArtistName'],
+            try:
+                track = self.lastfm.get_track(self.current_song['ArtistName'],
                                           self.current_song['SongName'])
-            track.love()
+                track.love()
+            except pylast.MalformedResponseError, e:
+                pass
 
     def get_sliced_string(self, str, max):
         sliced = str[0:max - 3]
             return ""
         else:
             song = self.app.current_song
-            info = "Artist: " + song['ArtistName'] + "\n"
-            info += "Song:" + song['SongName'] + "\n"
-            info += "Album:" + song['AlbumName'] + "\n"
+            info = "Artist: " + glib.markup_escape_text(song['ArtistName']) + "\n"
+            info += "Song:" + glib.markup_escpate_text(song['SongName']) + "\n"
+            info += "Album:" + glib.markup_escpate_text(song['AlbumName']) + "\n"
             info += "Year:" + song['Year'] + "\n"
             return info
 

lib/guihelpers.py

 import sys
 import locale
 import gettext
+import glib
 try:
     import appindicator
     HAVE_INDICATOR = True
         self.lyrics.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK)
         self.lyrics.set_default_response(gtk.RESPONSE_OK)
         self.lyrics.connect('response', self.handle_clicked)
+        song_title = glib.markup_escape_text(_artist) + " - "
+        song_title += glib.markup_escape_text(_song)
 
-        self.songlabel.set_text(_artist + " - " + _song)
-        self.lyrics_buffer.set_text(_lyrics)
+        self.songlabel.set_text(song_title)
+        self.lyrics_buffer.set_text(glib.markup_escape_text(_lyrics))
 
     def show_all(self):
         """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.