[gnome-music/wip/jfelder/coremodel-reset-item-changed-signal] coremodel: Correctly disconnect items-changed for player model



commit e0b7d98e6b96cc9ff3edf59ac6894230f07b5c1f
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Sep 9 21:23:35 2019 +0200

    coremodel: Correctly disconnect items-changed for player model
    
    When a new player playlist is set, an existing "items-changed" signal
    is disconnected if the new playlist type matches the current playlist
    type. This is wrong because the new model will replace the existing
    one whatever its type is.
    
    Fix the issue by disconnecting an "items-changed" signal as soon as
    the playlist changes.

 gnomemusic/coremodel.py | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 0df16163..f54a478d 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -246,6 +246,20 @@ class CoreModel(GObject.GObject):
                         | GObject.BindingFlags.SYNC_CREATE)
 
         with model.freeze_notify():
+            if self._playlist_signal_id:
+                self._previous_playlist_model.disconnect(
+                    self._playlist_signal_id)
+                self._playlist_signal_id = None
+
+            elif self._song_signal_id:
+                self._songliststore.props.model.disconnect(
+                    self._song_signal_id)
+                self._song_signal_id = None
+
+            elif self._search_signal_id:
+                self._song_search_flatten.disconnect(self._search_signal_id)
+                self._search_signal_id = None
+
             self._playlist_model.remove_all()
 
             if playlist_type == PlayerPlaylist.Type.ALBUM:
@@ -300,10 +314,6 @@ class CoreModel(GObject.GObject):
 
                 self.emit("playlist-loaded")
             elif playlist_type == PlayerPlaylist.Type.SONGS:
-                if self._song_signal_id:
-                    self._songliststore.props.model.disconnect(
-                        self._song_signal_id)
-
                 for song in self._songliststore.props.model:
                     self._playlist_model.append(song)
 
@@ -315,10 +325,6 @@ class CoreModel(GObject.GObject):
 
                 self.emit("playlist-loaded")
             elif playlist_type == PlayerPlaylist.Type.SEARCH_RESULT:
-                if self._search_signal_id:
-                    self._song_search_flatten.disconnect(
-                        self._search_signal_id)
-
                 for song in self._song_search_flatten:
                     self._playlist_model.append(song)
 
@@ -327,10 +333,6 @@ class CoreModel(GObject.GObject):
 
                 self.emit("playlist-loaded")
             elif playlist_type == PlayerPlaylist.Type.PLAYLIST:
-                if self._playlist_signal_id:
-                    self._previous_playlist_model.disconnect(
-                        self._playlist_signal_id)
-
                 for model_song in model:
                     song = CoreSong(
                         model_song.props.media, self._coreselection,


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