From 383d0b65c2c83d29de5466e48e9cbc6c9f0bffe5 Mon Sep 17 00:00:00 2001 From: Et0h Date: Sat, 6 Dec 2014 16:40:10 +0000 Subject: [PATCH] Initial readiness GUI code + none state (back compat_ + 1.3.1 ver-up/ver-check --- syncplay/__init__.py | 4 ++-- syncplay/client.py | 43 +++++++++++++++++++++++++++++++------------ syncplay/constants.py | 1 + syncplay/protocols.py | 2 +- syncplay/server.py | 2 +- syncplay/ui/gui.py | 20 +++++++++++++++++++- 6 files changed, 55 insertions(+), 17 deletions(-) diff --git a/syncplay/__init__.py b/syncplay/__init__.py index a1fa3eb..ff59e5a 100644 --- a/syncplay/__init__.py +++ b/syncplay/__init__.py @@ -1,3 +1,3 @@ -version = '1.3.0' -milestone = 'Akki' +version = '1.3.1' +milestone = 'Chami' projectURL = 'http://syncplay.pl/' diff --git a/syncplay/client.py b/syncplay/client.py index 23e9ac7..855b73f 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -402,6 +402,10 @@ class SyncplayClient(object): self.identifyAsController(storedRoomPassword) def connected(self): + if self.userlist.currentUser.isReady() is not None: + self._protocol.setReady(self.userlist.currentUser.isReady()) + else: + self._protocol.setReady(False) self.reIdentifyAsController() def getRoom(self): @@ -459,17 +463,6 @@ class SyncplayClient(object): if promptForAction: self.ui.promptFor(getMessage("enter-to-exit-prompt")) - def toggleReady(self): - self._protocol.setReady(not self.userlist.currentUser.isReady()) - - def setReady(self, username, isReady): - self.userlist.setReady(username, isReady) - if isReady: - message = "<{}> I'm ready".format(username) - else: - message = "<{}> I'm not ready".format(username) - self.ui.showMessage(message) - def requireMinServerVersion(minVersion): def requireMinVersionDecorator(f): @wraps(f) @@ -481,6 +474,23 @@ class SyncplayClient(object): return wrapper return requireMinVersionDecorator + @requireMinServerVersion(constants.USER_READY_MIN_VERSION) + def toggleReady(self): + self._protocol.setReady(not self.userlist.currentUser.isReady()) + + def setReady(self, username, isReady): + oldReadyState = self.userlist.isReady(username) + if oldReadyState is None: + oldReadyState = False + self.userlist.setReady(username, isReady) + self.ui.userListChange() + if oldReadyState != isReady: + if isReady: + message = "<{}> I'm ready".format(username) + else: + message = "<{}> I'm not ready".format(username) + self.ui.showMessage(message) + @requireMinServerVersion(constants.CONTROLLED_ROOMS_MIN_VERSION) def createControlledRoom(self, roomName): controlPassword = utils.RandomStringGenerator.generate_room_password() @@ -577,7 +587,7 @@ class SyncplayClient(object): class SyncplayUser(object): def __init__(self, username=None, room=None, file_=None): - self.ready = False + self.ready = None self.username = username self.room = room self.file = file_ @@ -765,6 +775,15 @@ class SyncplayUserlist(object): return True return False + def isReady(self, username): + if self.currentUser.username == username: + return self.currentUser.isReady() + + for user in self._users.itervalues(): + if user.username == username: + return user.isReady() + return False + def setReady(self, username, isReady): if self.currentUser.username == username: self.currentUser.setReady(isReady) diff --git a/syncplay/constants.py b/syncplay/constants.py index 6e85c61..19d9dfe 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -63,6 +63,7 @@ MPC_MIN_VER = "1.6.4" VLC_MIN_VERSION = "2.0.0" VLC_INTERFACE_MIN_VERSION = "0.2.1" CONTROLLED_ROOMS_MIN_VERSION = "1.3.0" +USER_READY_MIN_VERSION = "1.3.1" MPC_PATHS = [ r"c:\program files (x86)\mpc-hc\mpc-hc.exe", r"c:\program files\mpc-hc\mpc-hc.exe", diff --git a/syncplay/protocols.py b/syncplay/protocols.py index f262623..cd1ead6 100644 --- a/syncplay/protocols.py +++ b/syncplay/protocols.py @@ -161,7 +161,7 @@ class SyncClientProtocol(JSONCommandProtocol): userName = user[0] file_ = user[1]['file'] if user[1]['file'] <> {} else None isController = user[1]['controller'] if 'controller' in user[1] else False - isReady = user[1]['isReady'] if 'isReady' in user[1] else False + isReady = user[1]['isReady'] if 'isReady' in user[1] else None self._client.userlist.addUser(userName, roomName, file_, noMessage=True, isController=isController, isReady=isReady) self._client.userlist.showUserList() diff --git a/syncplay/server.py b/syncplay/server.py index b743ea9..6e61ef9 100644 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -302,7 +302,7 @@ class ControlledRoom(Room): class Watcher(object): def __init__(self, server, connector, name): - self._ready = False + self._ready = None self._server = server self._connector = connector self._name = name diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 5b02d8b..dd51ecd 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -125,7 +125,13 @@ class MainWindow(QtGui.QMainWindow): for user in rooms[room]: useritem = QtGui.QStandardItem(user.username) isController = user.isController() + sameRoom = room == currentUser.room + if sameRoom: + isReady = user.isReady() + else: + isReady = None useritem.setData(isController, Qt.UserRole + constants.USERITEM_CONTROLLER_ROLE) + useritem.setData(isReady, Qt.UserRole + constants.USERITEM_READY_ROLE) if user.file: filesizeitem = QtGui.QStandardItem(formatSize(user.file['size'])) filedurationitem = QtGui.QStandardItem("({})".format(formatTime(user.file['duration']))) @@ -134,7 +140,6 @@ class MainWindow(QtGui.QMainWindow): sameName = sameFilename(user.file['name'], currentUser.file['name']) sameSize = sameFilesize(user.file['size'], currentUser.file['size']) sameDuration = sameFileduration(user.file['duration'], currentUser.file['duration']) - sameRoom = room == currentUser.room underlinefont = QtGui.QFont() underlinefont.setUnderline(True) if sameRoom: @@ -446,6 +451,15 @@ class MainWindow(QtGui.QMainWindow): window.listLayout.setContentsMargins(0, 0, 0, 0) window.listLayout.addWidget(window.listlabel) window.listLayout.addWidget(window.listTreeView) + + window.readyCheckbox = QtGui.QCheckBox() + readyFont = QtGui.QFont() + readyFont.setWeight(QtGui.QFont.Bold) + window.readyCheckbox.setText("I'm ready to watch!") + window.readyCheckbox.setFont(readyFont) + window.readyCheckbox.toggled.connect(self.changeReadyState) + window.listLayout.addWidget(window.readyCheckbox, Qt.AlignRight) + window.contactLabel = QtGui.QLabel() window.contactLabel.setWordWrap(True) window.contactLabel.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Sunken) @@ -606,6 +620,10 @@ class MainWindow(QtGui.QMainWindow): self.listbox.insertHtml(item) self.listbox.moveCursor(QtGui.QTextCursor.End) + def changeReadyState(self): + if self.readyCheckbox.isChecked() != self._syncplayClient.userlist.currentUser.isReady(): + self._syncplayClient.toggleReady() + def dragEnterEvent(self, event): data = event.mimeData() urls = data.urls()