[gnome-music] view: track now-playing indicator by track URI



commit a6ff4d6f114a7dd0af2c78dad056bba1ab2d6688
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Sun Mar 1 15:46:38 2015 +0100

    view: track now-playing indicator by track URI
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705852

 gnomemusic/player.py  |   13 ++++++++++++-
 gnomemusic/view.py    |   12 ++++++++----
 gnomemusic/widgets.py |    4 ++--
 3 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index cf59d8f..86fce47 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -94,6 +94,7 @@ class Player(GObject.GObject):
         self.playlistId = None
         self.playlistField = None
         self.currentTrack = None
+        self.currentTrackUri = None
         self._lastState = Gst.State.PAUSED
         self.cache = AlbumArtCache.get_default()
         self._noArtworkIcon = self.cache.get_default_icon(ART_SIZE, ART_SIZE)
@@ -244,6 +245,8 @@ class Player(GObject.GObject):
                 currentTrack = self.playlist.get_path(self.playlist.get_iter_first())
                 if currentTrack:
                     self.currentTrack = Gtk.TreeRowReference.new(self.playlist, currentTrack)
+                    self.currentTrackUri = self.playlist.get_value(
+                        self.playlist.get_iter(currentTrack.get_path()), 5).get_url()
                 else:
                     self.currentTrack = None
                 self.load(self.get_current_media())
@@ -258,6 +261,8 @@ class Player(GObject.GObject):
     @log
     def _on_glib_idle(self):
         self.currentTrack = self.nextTrack
+        self.currentTrackUri = self.playlist.get_value(
+            self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
         self.play()
 
     @log
@@ -566,8 +571,9 @@ class Player(GObject.GObject):
 
         self.stop()
         self.currentTrack = self.nextTrack
-
         if self.currentTrack:
+            self.currentTrackUri = self.playlist.get_value(
+                self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
             self.play()
 
     @log
@@ -588,6 +594,8 @@ class Player(GObject.GObject):
 
         self.currentTrack = self._get_previous_track()
         if self.currentTrack:
+            self.currentTrackUri = self.playlist.get_value(
+                self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
             self.play()
 
     @log
@@ -612,6 +620,9 @@ class Player(GObject.GObject):
         self.playlistType = type
         self.playlistId = id
         self.currentTrack = Gtk.TreeRowReference.new(model, model.get_path(iter))
+        if self.currentTrack:
+            self.currentTrackUri = self.playlist.get_value(
+                self.playlist.get_iter(self.currentTrack.get_path()), 5).get_url()
         self.playlistField = field
         self.discovery_status_field = discovery_status_field
 
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 4787720..cdb3475 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -417,6 +417,8 @@ class Songs(ViewContainer):
         self.view.get_generic_view().scroll_to_path(path)
         if self.model.get_value(currentIter, 8) != self.errorIconName:
             self.iter_to_clean = currentIter.copy()
+
+        self.view.queue_draw()
         return False
 
     def _add_item(self, source, param, item, remaining=0, data=None):
@@ -512,14 +514,14 @@ class Songs(ViewContainer):
             cell.set_property('text', item.get_string(Grl.METADATA_KEY_ALBUM) or _("Unknown Album"))
 
     def _on_list_widget_icon_render(self, col, cell, model, _iter, data):
-        if model != self.player.playlist:
+        if not self.player.currentTrackUri:
             cell.set_visible(False)
             return
 
         if model.get_value(_iter, 11) == DiscoveryStatus.FAILED:
             cell.set_property('icon-name', self.errorIconName)
             cell.set_visible(True)
-        elif model.get_path(_iter) == self.player.currentTrack.get_path():
+        elif model.get_value(_iter, 5).get_url() == self.player.currentTrackUri:
             cell.set_property('icon-name', self.nowPlayingIconName)
             cell.set_visible(True)
         else:
@@ -940,14 +942,14 @@ class Playlist(ViewContainer):
             cell.set_property('text', item.get_string(Grl.METADATA_KEY_ALBUM) or _("Unknown Album"))
 
     def _on_list_widget_icon_render(self, col, cell, model, _iter, data):
-        if model != self.player.playlist:
+        if not self.player.currentTrackUri:
             cell.set_visible(False)
             return
 
         if model.get_value(_iter, 11) == DiscoveryStatus.FAILED:
             cell.set_property('icon-name', self.errorIconName)
             cell.set_visible(True)
-        elif model.get_path(_iter) == self.player.currentTrack.get_path():
+        elif model.get_value(_iter, 5).get_url() == self.player.currentTrackUri:
             cell.set_property('icon-name', self.nowPlayingIconName)
             cell.set_visible(True)
         else:
@@ -970,6 +972,8 @@ class Playlist(ViewContainer):
         if self.model.get_value(currentIter, 8) != self.errorIconName:
             self.iter_to_clean = currentIter.copy()
             self.iter_to_clean_model = self.model
+
+        self.view.queue_draw()
         return False
 
     @log
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index ea65abf..3608145 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -195,14 +195,14 @@ class AlbumWidget(Gtk.EventBox):
         self.star_handler._add_star_renderers(list_widget, cols)
 
     def _on_list_widget_icon_render(self, col, cell, model, _iter, data):
-        if model != self.player.playlist:
+        if not self.player.currentTrackUri:
             cell.set_visible(False)
             return
 
         if model.get_value(_iter, 10) == DiscoveryStatus.FAILED:
             cell.set_property('icon-name', ERROR_ICON_NAME)
             cell.set_visible(True)
-        elif model.get_path(_iter) == self.player.currentTrack.get_path():
+        elif model.get_value(_iter, 5).get_url() == self.player.currentTrackUri:
             cell.set_property('icon-name', NOW_PLAYING_ICON_NAME)
             cell.set_visible(True)
         else:


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