Allow shared playlists to be disabled from main UI, and make this persistent
This commit is contained in:
parent
cfe123a361
commit
d87511f60e
@ -130,6 +130,15 @@ class SyncplayClient(object):
|
|||||||
if missingStrings is not None and missingStrings is not "":
|
if missingStrings is not None and missingStrings is not "":
|
||||||
self.ui.showDebugMessage("MISSING/UNUSED STRINGS DETECTED:\n{}".format(missingStrings))
|
self.ui.showDebugMessage("MISSING/UNUSED STRINGS DETECTED:\n{}".format(missingStrings))
|
||||||
|
|
||||||
|
def needsSharedPlaylistsEnabled(f): # @NoSelf
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(self, *args, **kwds):
|
||||||
|
if not self._config['sharedPlaylistEnabled']:
|
||||||
|
self.ui.showDebugMessage("Tried to use shared playlists when it was disabled!")
|
||||||
|
return
|
||||||
|
return f(self, *args, **kwds)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
def initProtocol(self, protocol):
|
def initProtocol(self, protocol):
|
||||||
self._protocol = protocol
|
self._protocol = protocol
|
||||||
|
|
||||||
@ -171,6 +180,7 @@ class SyncplayClient(object):
|
|||||||
seeked = _playerDiff > constants.SEEK_THRESHOLD and _globalDiff > constants.SEEK_THRESHOLD
|
seeked = _playerDiff > constants.SEEK_THRESHOLD and _globalDiff > constants.SEEK_THRESHOLD
|
||||||
return pauseChange, seeked
|
return pauseChange, seeked
|
||||||
|
|
||||||
|
@needsSharedPlaylistsEnabled
|
||||||
def loadNextFileInPlaylist(self):
|
def loadNextFileInPlaylist(self):
|
||||||
# TODO: Fix for GUIDs & add path checks (and make more of code re-use?)
|
# TODO: Fix for GUIDs & add path checks (and make more of code re-use?)
|
||||||
if self._playlistIndex is None or len(self._playlist) <= self._playlistIndex+1:
|
if self._playlistIndex is None or len(self._playlist) <= self._playlistIndex+1:
|
||||||
@ -467,9 +477,12 @@ class SyncplayClient(object):
|
|||||||
path = None
|
path = None
|
||||||
if index is None:
|
if index is None:
|
||||||
return
|
return
|
||||||
|
if username is None and not self._config['sharedPlaylistEnabled']:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
filename = self._playlist[index]
|
filename = self._playlist[index]
|
||||||
self.ui.setPlaylistIndexFilename(filename)
|
self.ui.setPlaylistIndexFilename(filename)
|
||||||
|
self._playlistIndex = index
|
||||||
if username is not None and self.userlist.currentUser.file and filename == self.userlist.currentUser.file['name']:
|
if username is not None and self.userlist.currentUser.file and filename == self.userlist.currentUser.file['name']:
|
||||||
return
|
return
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -478,31 +491,37 @@ class SyncplayClient(object):
|
|||||||
if self._player is None:
|
if self._player is None:
|
||||||
self.__playerReady.addCallback(lambda x: self.changeToPlaylistIndex(index, username))
|
self.__playerReady.addCallback(lambda x: self.changeToPlaylistIndex(index, username))
|
||||||
return
|
return
|
||||||
self._playlistIndex = index
|
|
||||||
if username is None and self._protocol and self._protocol.logged:
|
if username is None and self._protocol and self._protocol.logged and self._config["sharedPlaylistEnabled"]:
|
||||||
|
self._playlistIndex = index
|
||||||
self._protocol.setPlaylistIndex(index)
|
self._protocol.setPlaylistIndex(index)
|
||||||
else:
|
else:
|
||||||
self.ui.showMessage(u"{} changed the playlist selection".format(username))
|
self.ui.showMessage(u"{} changed the playlist selection".format(username))
|
||||||
# TODO: Display info about playlist file change
|
self._playlistIndex = index
|
||||||
try:
|
self.switchToNewPlaylistIndex(index)
|
||||||
filename = self._playlist[index]
|
|
||||||
if utils.isURL(filename):
|
|
||||||
for URI in constants.SAFE_URIS:
|
@needsSharedPlaylistsEnabled
|
||||||
if filename.startswith(URI):
|
def switchToNewPlaylistIndex(self, index):
|
||||||
self._player.openFile(filename)
|
try:
|
||||||
return
|
filename = self._playlist[index]
|
||||||
self.ui.showErrorMessage(u"Could not load {} because it is not known as a safe path.".format(filename))
|
if utils.isURL(filename):
|
||||||
return
|
for URI in constants.SAFE_URIS:
|
||||||
else:
|
if filename.startswith(URI):
|
||||||
path = self.findFilenameInDirectories(filename)
|
self._player.openFile(filename)
|
||||||
# TODO: Find Path properly
|
return
|
||||||
if path:
|
self.ui.showErrorMessage(u"Could not load {} because it is not known as a safe path.".format(filename))
|
||||||
self._player.openFile(path)
|
return
|
||||||
else:
|
else:
|
||||||
self.ui.showErrorMessage(u"Could not find file {} for playlist switch!".format(filename))
|
path = self.findFilenameInDirectories(filename)
|
||||||
return
|
# TODO: Find Path properly
|
||||||
except IndexError:
|
if path:
|
||||||
pass
|
self._player.openFile(path)
|
||||||
|
else:
|
||||||
|
self.ui.showErrorMessage(u"Could not find file {} for playlist switch!".format(filename))
|
||||||
|
return
|
||||||
|
except IndexError:
|
||||||
|
self.ui.showDebugMessage("Could not change playlist index due to IndexError")
|
||||||
|
|
||||||
def changePlaylist(self, files, username = None):
|
def changePlaylist(self, files, username = None):
|
||||||
try:
|
try:
|
||||||
@ -519,13 +538,15 @@ class SyncplayClient(object):
|
|||||||
self._playlist = files
|
self._playlist = files
|
||||||
|
|
||||||
if username is None and self._protocol and self._protocol.logged:
|
if username is None and self._protocol and self._protocol.logged:
|
||||||
self._protocol.setPlaylist(files)
|
if self._config['sharedPlaylistEnabled']:
|
||||||
self.changeToPlaylistIndex(newIndex)
|
self._protocol.setPlaylist(files)
|
||||||
|
self.changeToPlaylistIndex(newIndex)
|
||||||
else:
|
else:
|
||||||
self.ui.setPlaylist(self._playlist)
|
self.ui.setPlaylist(self._playlist)
|
||||||
self.changeToPlaylistIndex(newIndex, username)
|
self.changeToPlaylistIndex(newIndex, username)
|
||||||
self.ui.showMessage(u"{} updated the playlist".format(username))
|
self.ui.showMessage(u"{} updated the playlist".format(username))
|
||||||
|
|
||||||
|
@needsSharedPlaylistsEnabled
|
||||||
def undoPlaylistChange(self):
|
def undoPlaylistChange(self):
|
||||||
if self._previousPlaylist is not None and self._playlist <> self._previousPlaylist:
|
if self._previousPlaylist is not None and self._playlist <> self._previousPlaylist:
|
||||||
undidPlaylist = self._playlist
|
undidPlaylist = self._playlist
|
||||||
@ -533,6 +554,7 @@ class SyncplayClient(object):
|
|||||||
self.changePlaylist(self._previousPlaylist)
|
self.changePlaylist(self._previousPlaylist)
|
||||||
self._previousPlaylist = undidPlaylist
|
self._previousPlaylist = undidPlaylist
|
||||||
|
|
||||||
|
@needsSharedPlaylistsEnabled
|
||||||
def shufflePlaylist(self):
|
def shufflePlaylist(self):
|
||||||
if self._playlist and len(self._playlist) > 0:
|
if self._playlist and len(self._playlist) > 0:
|
||||||
oldPlaylist = self._playlist
|
oldPlaylist = self._playlist
|
||||||
@ -685,6 +707,14 @@ class SyncplayClient(object):
|
|||||||
return wrapper
|
return wrapper
|
||||||
return requireMinVersionDecorator
|
return requireMinVersionDecorator
|
||||||
|
|
||||||
|
def changePlaylistEnabledState(self, newState):
|
||||||
|
oldState = self._config["sharedPlaylistEnabled"]
|
||||||
|
from syncplay.ui.ConfigurationGetter import ConfigurationGetter
|
||||||
|
ConfigurationGetter().setConfigOption("sharedPlaylistEnabled", newState)
|
||||||
|
self._config["sharedPlaylistEnabled"] = newState
|
||||||
|
if oldState == False and newState == True:
|
||||||
|
self.changeToPlaylistIndex(self._playlistIndex)
|
||||||
|
|
||||||
def changeAutoplayState(self, newState):
|
def changeAutoplayState(self, newState):
|
||||||
self.autoPlay = newState
|
self.autoPlay = newState
|
||||||
self.autoplayCheck()
|
self.autoplayCheck()
|
||||||
|
|||||||
@ -34,6 +34,7 @@ class ConfigurationGetter(object):
|
|||||||
"playerPath": None,
|
"playerPath": None,
|
||||||
"perPlayerArguments": None,
|
"perPlayerArguments": None,
|
||||||
"mediaSearchDirectories": None,
|
"mediaSearchDirectories": None,
|
||||||
|
"sharedPlaylistEnabled": False,
|
||||||
"file": None,
|
"file": None,
|
||||||
"playerArgs": [],
|
"playerArgs": [],
|
||||||
"playerClass": None,
|
"playerClass": None,
|
||||||
@ -102,7 +103,8 @@ class ConfigurationGetter(object):
|
|||||||
"showDifferentRoomOSD",
|
"showDifferentRoomOSD",
|
||||||
"showSameRoomOSD",
|
"showSameRoomOSD",
|
||||||
"showNonControllerOSD",
|
"showNonControllerOSD",
|
||||||
"showDurationNotification"
|
"showDurationNotification",
|
||||||
|
"sharedPlaylistEnabled"
|
||||||
]
|
]
|
||||||
self._tristate = [
|
self._tristate = [
|
||||||
"checkForUpdatesAutomatically",
|
"checkForUpdatesAutomatically",
|
||||||
@ -123,7 +125,7 @@ class ConfigurationGetter(object):
|
|||||||
|
|
||||||
self._iniStructure = {
|
self._iniStructure = {
|
||||||
"server_data": ["host", "port", "password"],
|
"server_data": ["host", "port", "password"],
|
||||||
"client_settings": ["name", "room", "playerPath", "perPlayerArguments", "slowdownThreshold", "rewindThreshold", "fastforwardThreshold", "slowOnDesync", "rewindOnDesync", "fastforwardOnDesync", "dontSlowDownWithMe", "forceGuiPrompt", "filenamePrivacyMode", "filesizePrivacyMode", "unpauseAction", "pauseOnLeave", "readyAtStart", "autoplayMinUsers", "autoplayInitialState", "autoplayRequireSameFilenames", "mediaSearchDirectories"],
|
"client_settings": ["name", "room", "playerPath", "perPlayerArguments", "slowdownThreshold", "rewindThreshold", "fastforwardThreshold", "slowOnDesync", "rewindOnDesync", "fastforwardOnDesync", "dontSlowDownWithMe", "forceGuiPrompt", "filenamePrivacyMode", "filesizePrivacyMode", "unpauseAction", "pauseOnLeave", "readyAtStart", "autoplayMinUsers", "autoplayInitialState", "autoplayRequireSameFilenames", "mediaSearchDirectories", "sharedPlaylistEnabled"],
|
||||||
"gui": ["showOSD", "showOSDWarnings", "showSlowdownOSD", "showDifferentRoomOSD", "showSameRoomOSD", "showNonControllerOSD", "showDurationNotification"],
|
"gui": ["showOSD", "showOSDWarnings", "showSlowdownOSD", "showDifferentRoomOSD", "showSameRoomOSD", "showNonControllerOSD", "showDurationNotification"],
|
||||||
"general": ["language", "checkForUpdatesAutomatically", "lastCheckedForUpdates"]
|
"general": ["language", "checkForUpdatesAutomatically", "lastCheckedForUpdates"]
|
||||||
}
|
}
|
||||||
@ -411,6 +413,15 @@ class ConfigurationGetter(object):
|
|||||||
qt4reactor.install()
|
qt4reactor.install()
|
||||||
return self._config
|
return self._config
|
||||||
|
|
||||||
|
def setConfigOption(self, option, value):
|
||||||
|
path = self._getConfigurationFilePath()
|
||||||
|
backup = self._config.copy()
|
||||||
|
self._parseConfigFile(path)
|
||||||
|
self._config[option] = value
|
||||||
|
backup[option] = value
|
||||||
|
self._saveConfig(path)
|
||||||
|
self._config = backup
|
||||||
|
|
||||||
class SafeConfigParserUnicode(SafeConfigParser):
|
class SafeConfigParserUnicode(SafeConfigParser):
|
||||||
def write(self, fp):
|
def write(self, fp):
|
||||||
"""Write an .ini-format representation of the configuration state."""
|
"""Write an .ini-format representation of the configuration state."""
|
||||||
|
|||||||
@ -91,6 +91,8 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
playlistIndex = None
|
playlistIndex = None
|
||||||
|
|
||||||
def setPlaylistInsertPosition(self, newPosition):
|
def setPlaylistInsertPosition(self, newPosition):
|
||||||
|
if not self.playlist.isEnabled():
|
||||||
|
return
|
||||||
if MainWindow.insertPosition <> newPosition:
|
if MainWindow.insertPosition <> newPosition:
|
||||||
MainWindow.insertPosition = newPosition
|
MainWindow.insertPosition = newPosition
|
||||||
self.playlist.forceUpdate()
|
self.playlist.forceUpdate()
|
||||||
@ -146,6 +148,8 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def dropEvent(self, event):
|
def dropEvent(self, event):
|
||||||
window = self.parent().parent().parent().parent().parent()
|
window = self.parent().parent().parent().parent().parent()
|
||||||
|
if not window.playlist.isEnabled():
|
||||||
|
return
|
||||||
window.setPlaylistInsertPosition(None)
|
window.setPlaylistInsertPosition(None)
|
||||||
if QtGui.QDropEvent.proposedAction(event) == Qt.MoveAction:
|
if QtGui.QDropEvent.proposedAction(event) == Qt.MoveAction:
|
||||||
QtGui.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted
|
QtGui.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted
|
||||||
@ -233,6 +237,8 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def dropEvent(self, event):
|
def dropEvent(self, event):
|
||||||
window = self.parent().parent().parent().parent().parent().parent()
|
window = self.parent().parent().parent().parent().parent().parent()
|
||||||
|
if not window.playlist.isEnabled():
|
||||||
|
return
|
||||||
window.setPlaylistInsertPosition(None)
|
window.setPlaylistInsertPosition(None)
|
||||||
if QtGui.QDropEvent.proposedAction(event) == Qt.MoveAction:
|
if QtGui.QDropEvent.proposedAction(event) == Qt.MoveAction:
|
||||||
QtGui.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted
|
QtGui.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted
|
||||||
@ -425,6 +431,9 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.roomInput.setText(self._syncplayClient.getRoom())
|
self.roomInput.setText(self._syncplayClient.getRoom())
|
||||||
self.config = self._syncplayClient.getConfig()
|
self.config = self._syncplayClient.getConfig()
|
||||||
try:
|
try:
|
||||||
|
self.playlistGroup.blockSignals(True)
|
||||||
|
self.playlistGroup.setChecked(self.config['sharedPlaylistEnabled'])
|
||||||
|
self.playlistGroup.blockSignals(False)
|
||||||
self.FileSwitchManager.setMediaDirectories(self.config["mediaSearchDirectories"])
|
self.FileSwitchManager.setMediaDirectories(self.config["mediaSearchDirectories"])
|
||||||
self.updateReadyState(self.config['readyAtStart'])
|
self.updateReadyState(self.config['readyAtStart'])
|
||||||
autoplayInitialState = self.config['autoplayInitialState']
|
autoplayInitialState = self.config['autoplayInitialState']
|
||||||
@ -637,10 +646,11 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
if roomToJoin <> self._syncplayClient.getRoom():
|
if roomToJoin <> self._syncplayClient.getRoom():
|
||||||
menu.addAction("Join room {}".format(roomToJoin), lambda: self.joinRoom(roomToJoin))
|
menu.addAction("Join room {}".format(roomToJoin), lambda: self.joinRoom(roomToJoin))
|
||||||
elif username and filename and filename <> getMessage("nofile-note"):
|
elif username and filename and filename <> getMessage("nofile-note"):
|
||||||
if isURL(filename):
|
if self.config['sharedPlaylistEnabled']:
|
||||||
menu.addAction(QtGui.QPixmap(resourcespath + "world_add.png"), "Add {} stream to playlist".format(shortUsername), lambda: self.addStreamToPlaylist(filename))
|
if isURL(filename):
|
||||||
else:
|
menu.addAction(QtGui.QPixmap(resourcespath + "world_add.png"), "Add {} stream to playlist".format(shortUsername), lambda: self.addStreamToPlaylist(filename))
|
||||||
menu.addAction(QtGui.QPixmap(resourcespath + "film_add.png"), "Add {} file to playlist".format(shortUsername), lambda: self.addStreamToPlaylist(filename))
|
else:
|
||||||
|
menu.addAction(QtGui.QPixmap(resourcespath + "film_add.png"), "Add {} file to playlist".format(shortUsername), lambda: self.addStreamToPlaylist(filename))
|
||||||
|
|
||||||
if self._syncplayClient.userlist.currentUser.file is None or filename <> self._syncplayClient.userlist.currentUser.file["name"]:
|
if self._syncplayClient.userlist.currentUser.file is None or filename <> self._syncplayClient.userlist.currentUser.file["name"]:
|
||||||
if isURL(filename):
|
if isURL(filename):
|
||||||
@ -1077,6 +1087,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
|
|
||||||
window.playlistGroup = self.PlaylistGroupBox(u"Enable shared playlists")
|
window.playlistGroup = self.PlaylistGroupBox(u"Enable shared playlists")
|
||||||
window.playlistGroup.setCheckable(True)
|
window.playlistGroup.setCheckable(True)
|
||||||
|
window.playlistGroup.toggled.connect(self.changePlaylistEnabledState)
|
||||||
window.playlistLayout = QtGui.QHBoxLayout()
|
window.playlistLayout = QtGui.QHBoxLayout()
|
||||||
window.playlistGroup.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
|
window.playlistGroup.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
|
||||||
window.playlistGroup.setAcceptDrops(True)
|
window.playlistGroup.setAcceptDrops(True)
|
||||||
@ -1300,6 +1311,9 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
else:
|
else:
|
||||||
self.showDebugMessage("Tried to change ready state too soon.")
|
self.showDebugMessage("Tried to change ready state too soon.")
|
||||||
|
|
||||||
|
def changePlaylistEnabledState(self):
|
||||||
|
self._syncplayClient.changePlaylistEnabledState(self.playlistGroup.isChecked())
|
||||||
|
|
||||||
@needsClient
|
@needsClient
|
||||||
def changeAutoplayThreshold(self, source=None):
|
def changeAutoplayThreshold(self, source=None):
|
||||||
self._syncplayClient.changeAutoPlayThrehsold(self.autoplayThresholdSpinbox.value())
|
self._syncplayClient.changeAutoPlayThrehsold(self.autoplayThresholdSpinbox.value())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user