From 9d4732ad4090ed9838db3931a6e837377fcb38d6 Mon Sep 17 00:00:00 2001 From: Et0h Date: Sat, 30 Jan 2016 13:07:31 +0000 Subject: [PATCH] Fix double playlist change notification bug --- syncplay/client.py | 34 +++++++++++++++++++++------------- syncplay/players/mpv.py | 2 +- syncplay/ui/gui.py | 1 + 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index ae8e5e2..48f2824 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -1329,6 +1329,7 @@ class SyncplayPlaylist(): self._previousPlaylistRoom = None self._playlist = [] self._playlistIndex = None + self.addedChangeListCallback = False def needsSharedPlaylistsEnabled(f): # @NoSelf @wraps(f) @@ -1342,18 +1343,23 @@ class SyncplayPlaylist(): def changeToPlaylistIndexFromFilename(self, filename): try: index = self._playlist.index(filename) - self.changeToPlaylistIndex(index) + if index <> self._playlistIndex: + self.changeToPlaylistIndex(index) except ValueError: pass def changeToPlaylistIndex(self, index, username = None): - if not self._playlist or len(self._playlist) == 0: + if self._playlist is None or len(self._playlist) == 0: return if index is None: return if username is None and not self._client.sharedPlaylistIsEnabled(): return - self._playlistIndex = index + if self._client.playerIsNotReady(): + if not self.addedChangeListCallback: + self.addedChangeListCallback = True + self._client.addPlayerReadyCallback(lambda x: self.changeToPlaylistIndex(index, username)) + return try: filename = self._playlist[index] self._ui.setPlaylistIndexFilename(filename) @@ -1364,13 +1370,10 @@ class SyncplayPlaylist(): except IndexError: pass - if self._client.playerIsNotReady(): - self._client.addPlayerReadyCallback(lambda x: self.changeToPlaylistIndex(index, username)) - return - self._playlistIndex = index - if username is None and self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled(): - self._client.setPlaylistIndex(index) + if username is None: + if self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled(): + self._client.setPlaylistIndex(index) else: self._ui.showMessage(getMessage("playlist-selection-changed-notification").format(username)) self.switchToNewPlaylistIndex(index) @@ -1431,6 +1434,11 @@ class SyncplayPlaylist(): return filename def changePlaylist(self, files, username = None, resetIndex=False): + if self._playlist == files: + if self._playlistIndex <> 0 and resetIndex: + self.changeToPlaylistIndex(0) + return + if resetIndex: newIndex = 0 filename = files[0] if files and len(files) > 0 else None @@ -1442,13 +1450,13 @@ class SyncplayPlaylist(): self._playlist = files if username is None: - if self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled(): + if self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled(): self._client._protocol.setPlaylist(files) self.changeToPlaylistIndex(newIndex) self._ui.setPlaylist(self._playlist, filename) + self._ui.showMessage(getMessage("playlist-contents-changed-notification").format(self._client.getUsername())) else: - self._ui.setPlaylist(self._playlist, filename) - self.changeToPlaylistIndex(newIndex, username) + self._ui.setPlaylist(self._playlist) self._ui.showMessage(getMessage("playlist-contents-changed-notification").format(username)) @needsSharedPlaylistsEnabled @@ -1525,4 +1533,4 @@ class SyncplayPlaylist(): self._previousPlaylistRoom = currentRoom def _playlistBufferNeedsUpdating(self, newPlaylist): - return self._previousPlaylist <> self._playlist and self._playlist <> newPlaylist + return self._previousPlaylist <> self._playlist and self._playlist <> newPlaylist \ No newline at end of file diff --git a/syncplay/players/mpv.py b/syncplay/players/mpv.py index 3167f8b..667946b 100644 --- a/syncplay/players/mpv.py +++ b/syncplay/players/mpv.py @@ -91,7 +91,7 @@ class OldMpvPlayer(MpvPlayer): self.reactor.callFromThread(self._client.ui.showErrorMessage, getMessage("mpv-version-error"), True) self.drop() - if any(errormsg in line for errormsg in constants.MPV_ERROR_MESSAGES_TO_REPEAT): + if constants and any(errormsg in line for errormsg in constants.MPV_ERROR_MESSAGES_TO_REPEAT): self._client.ui.showErrorMessage(line) def _handleUnknownLine(self, line): diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index c95f94a..c6d66be 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -1418,6 +1418,7 @@ class MainWindow(QtGui.QMainWindow): self.ui.showDebugMessage("Trying to set playlist while it is already being updated") if newPlaylist == self.playlistState: self.playlist.setPlaylistIndexFilename(newIndexFilename) + self.updatingPlaylist = False return self.updatingPlaylist = True if newPlaylist and len(newPlaylist) > 0: