[gnome-music/wip/merge: 243/343] Correctly unescape empty titles



commit 5c122b154a2b2c659edef80511d05091f6c89986
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Thu Jul 18 11:05:37 2013 +0200

    Correctly unescape empty titles
    
    Fixes #47

 gnomemusic/albumArtCache.py |   18 ++++++++++++++++++
 gnomemusic/widgets.py       |   12 ++++++------
 2 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index 489c9e6..ee89fe8 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -19,6 +19,24 @@ class AlbumArtCache:
             self.instance = AlbumArtCache()
         return self.instance
 
+    @classmethod
+    def getMediaTitle(self, media, escaped=False):
+        title = media.get_title()
+        if title is not None:
+            return title
+        uri = media.get_url()
+        if uri is None:
+            return "Untitled"
+
+        uri_file = Gio.File.new_for_path(uri)
+        basename = uri_file.get_basename()
+        
+        title = GLib.uri_unescape_string(basename, None)
+        if escaped:
+            return GLib.markup_escape_text(title)
+
+        return title
+
     def __init__(self):
         self.logLookupErrors = False
         self.requested_uris = {}
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index eeccfb1..7cbc64b 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -206,8 +206,8 @@ class AlbumWidget(Gtk.EventBox):
         self.view.connect('view-selection-changed',
                           self._on_view_selection_changed)
         self.view.set_model(self.model)
-        escapedArtist = GLib.markup_escape_text(artist, -1)
-        escapedAlbum = GLib.markup_escape_text(album, -1)
+        escapedArtist = GLib.markup_escape_text(artist)
+        escapedAlbum = GLib.markup_escape_text(album)
         self.ui.get_object("artist_label").set_markup(escapedArtist)
         self.ui.get_object("title_label").set_markup(escapedAlbum)
         if (item.get_creation_date()):
@@ -248,7 +248,7 @@ class AlbumWidget(Gtk.EventBox):
             self.tracks.append(track)
             self.duration = self.duration + track.get_duration()
             iter = self.model.append()
-            escapedTitle = GLib.markup_escape_text(track.get_title(), -1)
+            escapedTitle = AlbumArtCache.getMediaTitle(track, True)
             try:
                 self.player.discoverer.discover_uri(track.get_url())
                 self.model.set(iter,
@@ -281,7 +281,7 @@ class AlbumWidget(Gtk.EventBox):
         while iter:
             song = playlist.get_value(iter, 5)
 
-            escapedTitle = GLib.markup_escape_text(song.get_title(), -1)
+            escapedTitle = AlbumArtCache.getMediaTitle(song, True)
             if (song == currentSong):
                 title = "<b>%s</b>" % escapedTitle
                 iconVisible = True
@@ -362,7 +362,7 @@ class ArtistAlbums(Gtk.VBox):
             if not song_widget.can_be_played:
                 continue
 
-            escapedTitle = GLib.markup_escape_text(song.get_title(), -1)
+            escapedTitle = AlbumArtCache.getMediaTitle(song, True)
             if (song == currentSong):
                 song_widget.now_playing_sign.show()
                 song_widget.title.set_markup("<b>%s</b>" % escapedTitle)
@@ -382,7 +382,7 @@ class ArtistAlbums(Gtk.VBox):
         while itr:
             song = self.model.get_value(itr, 5)
             song_widget = song.song_widget
-            escapedTitle = GLib.markup_escape_text(song.get_title(), -1)
+            escapedTitle = AlbumArtCache.getMediaTitle(song, True)
             if song_widget.can_be_played:
                 song_widget.now_playing_sign.hide()
             song_widget.title.set_markup("<span>%s</span>" % escapedTitle)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]