[gnome-music/cherry-pick-0d474cb4] player: Synchronize Player and PlayerPlaylist repeat_mode



commit dd71504436986a048d4f211451b1c8519471369a
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Sep 19 12:24:52 2018 +0000

    player: Synchronize Player and PlayerPlaylist repeat_mode
    
    Repeat mode is saved in a setting. PlayerToolbar repeat_mode property
    is initialized from this setting and listens to its changes.
    
    There are two ways to change the repeat mode.
    First, from the PlayerToolbar. It updates an action associated with
    the setting. This change triggers the 'changed::repeat' signal of the
    setting which updates PlayerPlaylist repeat_mode property. It also
    updates Player repeat_mode property because of a binding. However,
    this binding is unidirectional.
    It is also possible to change the repeat mode by using shortcuts (for
    example Ctrl + r). This updates Player repeat_mode property but not
    the PlayerPlaylist one as the binding is unidirectional. Therefore,
    the player toolbar icon is not updated and the setting is unchanged.
    
    Make the binding bidirectional to fix this issue. Create the binding
    at instantion time because it does not need to be updated when a
    playlist changes.
    Update The repeat setting in PlayerPlaylist repeat_mode setter.
    
    
    (cherry picked from commit 0d474cb4361f898e2425df40a77d72151ec95803)

 gnomemusic/player.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 773816df..ae9aae32 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -445,6 +445,9 @@ class PlayerPlaylist(GObject.GObject):
 
         :param RepeatMode mode: new repeat_mode
         """
+        if mode == self._repeat:
+            return
+
         if (mode == RepeatMode.SHUFFLE
                 and self._songs):
             self._shuffle_indexes = list(range(len(self._songs)))
@@ -453,6 +456,7 @@ class PlayerPlaylist(GObject.GObject):
             self._shuffle_indexes.insert(0, self._current_index)
 
         self._repeat = mode
+        self._settings.set_enum('repeat', mode)
 
     @GObject.Property(type=int, flags=GObject.ParamFlags.READABLE)
     def playlist_id(self):
@@ -514,6 +518,10 @@ class Player(GObject.GObject):
 
         self._playlist = PlayerPlaylist()
         self._playlist.connect('song-validated', self._on_song_validated)
+        self._playlist.bind_property(
+            'repeat-mode', self, 'repeat-mode',
+            GObject.BindingFlags.SYNC_CREATE |
+            GObject.BindingFlags.BIDIRECTIONAL)
 
         self._new_clock = True
 
@@ -657,10 +665,6 @@ class Player(GObject.GObject):
         if self._player.state == Playback.PLAYING:
             self.emit('prev-next-invalidated')
 
-        self._playlist.bind_property(
-            'repeat_mode', self, 'repeat_mode',
-            GObject.BindingFlags.SYNC_CREATE)
-
         if playlist_changed:
             self.emit('playlist-changed')
 
@@ -761,10 +765,11 @@ class Player(GObject.GObject):
 
     @GObject.Property(type=int)
     def repeat_mode(self):
-        return self._playlist.props.repeat_mode
+        return self._repeat
 
     @repeat_mode.setter
     def repeat_mode(self, mode):
+        self._repeat = mode
         self.emit('repeat-mode-changed')
         self.emit('prev-next-invalidated')
 


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