[gnome-music/wip/jfelder/player-remove-prev-next-invalidated: 2/7] playertoolbar: Use repeat-mode changes to update prev/next buttons



commit 74876e0bcfbfaa121f9214dd50eaf3c124637505
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Apr 24 00:12:43 2019 +0200

    playertoolbar: Use repeat-mode changes to update prev/next buttons
    
    With the previous repeat logic changes in player.py (repeat-mode
    property is now set in Player and propagated to PlayerPlaylist), the
    has_next and has_previous methods of PlayerPlaylist can sometimes be
    called before the repeat-mode property has been propagated. Indeed,
    the prev-next-invalidated signal (which results in has_previous and
    has_next calls) is emitted inside the repeat-mode setter of the
    Player.
    This can result in the previous and next buttons being improperly
    updated on repeat-mode changes.
    
    In fact, there are only two cases when the previous and next button
    need to be updated:
    * the current song changes (already covered)
    * the repeat mode changes (not covered)
    
    Thus, this issue is fixed by updating the previous and next button on
    repeat-mode changes and removing the "prev-next-invalidated"
    connection.

 gnomemusic/widgets/playertoolbar.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 7c0b69ca..12ca9263 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -82,8 +82,8 @@ class PlayerToolbar(Gtk.ActionBar):
 
         self._player.connect('clock-tick', self._on_clock_tick)
         self._player.connect('song-changed', self._update_view)
-        self._player.connect('prev-next-invalidated', self._sync_prev_next)
-        self._player.connect('notify::repeat-mode', self._sync_repeat_image)
+        self._player.connect(
+            'notify::repeat-mode', self._on_repeat_mode_changed)
         self._player.connect('notify::state', self._sync_playing)
 
     @Gtk.Template.Callback()
@@ -112,7 +112,12 @@ class PlayerToolbar(Gtk.ActionBar):
         self._player.next()
 
     @log
-    def _sync_repeat_image(self, player=None, param=None):
+    def _on_repeat_mode_changed(self, klass, param):
+        self._sync_repeat_image()
+        self._sync_prev_next()
+
+    @log
+    def _sync_repeat_image(self):
         icon = None
         repeat_mode = self._player.props.repeat_mode
         if repeat_mode == RepeatMode.NONE:
@@ -144,7 +149,7 @@ class PlayerToolbar(Gtk.ActionBar):
         self._play_button.set_tooltip_text(tooltip)
 
     @log
-    def _sync_prev_next(self, player=None):
+    def _sync_prev_next(self):
         self._next_button.props.sensitive = self._player.props.has_next
         self._prev_button.props.sensitive = self._player.props.has_previous
 


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