Fix double playlist change notification bug

This commit is contained in:
Et0h 2016-01-30 13:07:31 +00:00
parent 3b6f8fd414
commit 9d4732ad40
3 changed files with 23 additions and 14 deletions

View File

@ -1329,6 +1329,7 @@ class SyncplayPlaylist():
self._previousPlaylistRoom = None self._previousPlaylistRoom = None
self._playlist = [] self._playlist = []
self._playlistIndex = None self._playlistIndex = None
self.addedChangeListCallback = False
def needsSharedPlaylistsEnabled(f): # @NoSelf def needsSharedPlaylistsEnabled(f): # @NoSelf
@wraps(f) @wraps(f)
@ -1342,18 +1343,23 @@ class SyncplayPlaylist():
def changeToPlaylistIndexFromFilename(self, filename): def changeToPlaylistIndexFromFilename(self, filename):
try: try:
index = self._playlist.index(filename) index = self._playlist.index(filename)
self.changeToPlaylistIndex(index) if index <> self._playlistIndex:
self.changeToPlaylistIndex(index)
except ValueError: except ValueError:
pass pass
def changeToPlaylistIndex(self, index, username = None): 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 return
if index is None: if index is None:
return return
if username is None and not self._client.sharedPlaylistIsEnabled(): if username is None and not self._client.sharedPlaylistIsEnabled():
return 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: try:
filename = self._playlist[index] filename = self._playlist[index]
self._ui.setPlaylistIndexFilename(filename) self._ui.setPlaylistIndexFilename(filename)
@ -1364,13 +1370,10 @@ class SyncplayPlaylist():
except IndexError: except IndexError:
pass pass
if self._client.playerIsNotReady():
self._client.addPlayerReadyCallback(lambda x: self.changeToPlaylistIndex(index, username))
return
self._playlistIndex = index self._playlistIndex = index
if username is None and self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled(): if username is None:
self._client.setPlaylistIndex(index) if self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled():
self._client.setPlaylistIndex(index)
else: else:
self._ui.showMessage(getMessage("playlist-selection-changed-notification").format(username)) self._ui.showMessage(getMessage("playlist-selection-changed-notification").format(username))
self.switchToNewPlaylistIndex(index) self.switchToNewPlaylistIndex(index)
@ -1431,6 +1434,11 @@ class SyncplayPlaylist():
return filename return filename
def changePlaylist(self, files, username = None, resetIndex=False): def changePlaylist(self, files, username = None, resetIndex=False):
if self._playlist == files:
if self._playlistIndex <> 0 and resetIndex:
self.changeToPlaylistIndex(0)
return
if resetIndex: if resetIndex:
newIndex = 0 newIndex = 0
filename = files[0] if files and len(files) > 0 else None filename = files[0] if files and len(files) > 0 else None
@ -1442,13 +1450,13 @@ class SyncplayPlaylist():
self._playlist = files self._playlist = files
if username is None: 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._client._protocol.setPlaylist(files)
self.changeToPlaylistIndex(newIndex) self.changeToPlaylistIndex(newIndex)
self._ui.setPlaylist(self._playlist, filename) self._ui.setPlaylist(self._playlist, filename)
self._ui.showMessage(getMessage("playlist-contents-changed-notification").format(self._client.getUsername()))
else: else:
self._ui.setPlaylist(self._playlist, filename) self._ui.setPlaylist(self._playlist)
self.changeToPlaylistIndex(newIndex, username)
self._ui.showMessage(getMessage("playlist-contents-changed-notification").format(username)) self._ui.showMessage(getMessage("playlist-contents-changed-notification").format(username))
@needsSharedPlaylistsEnabled @needsSharedPlaylistsEnabled
@ -1525,4 +1533,4 @@ class SyncplayPlaylist():
self._previousPlaylistRoom = currentRoom self._previousPlaylistRoom = currentRoom
def _playlistBufferNeedsUpdating(self, newPlaylist): def _playlistBufferNeedsUpdating(self, newPlaylist):
return self._previousPlaylist <> self._playlist and self._playlist <> newPlaylist return self._previousPlaylist <> self._playlist and self._playlist <> newPlaylist

View File

@ -91,7 +91,7 @@ class OldMpvPlayer(MpvPlayer):
self.reactor.callFromThread(self._client.ui.showErrorMessage, getMessage("mpv-version-error"), True) self.reactor.callFromThread(self._client.ui.showErrorMessage, getMessage("mpv-version-error"), True)
self.drop() 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) self._client.ui.showErrorMessage(line)
def _handleUnknownLine(self, line): def _handleUnknownLine(self, line):

View File

@ -1418,6 +1418,7 @@ class MainWindow(QtGui.QMainWindow):
self.ui.showDebugMessage("Trying to set playlist while it is already being updated") self.ui.showDebugMessage("Trying to set playlist while it is already being updated")
if newPlaylist == self.playlistState: if newPlaylist == self.playlistState:
self.playlist.setPlaylistIndexFilename(newIndexFilename) self.playlist.setPlaylistIndexFilename(newIndexFilename)
self.updatingPlaylist = False
return return
self.updatingPlaylist = True self.updatingPlaylist = True
if newPlaylist and len(newPlaylist) > 0: if newPlaylist and len(newPlaylist) > 0: