diff --git a/resources/film_go.png b/resources/film_go.png new file mode 100644 index 0000000..dd0168e Binary files /dev/null and b/resources/film_go.png differ diff --git a/resources/world_go.png b/resources/world_go.png new file mode 100644 index 0000000..aee9c97 Binary files /dev/null and b/resources/world_go.png differ diff --git a/syncplay/constants.py b/syncplay/constants.py index 9ab1ada..dc7dcfd 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -131,6 +131,8 @@ STYLE_NOFILEITEM_COLOR = 'blue' STYLE_NOTCONTROLLER_COLOR = 'grey' USERLIST_GUI_USERNAME_OFFSET = 21 # Pixels +USERLIST_GUI_USERNAME_COLUMN = 0 +USERLIST_GUI_FILENAME_COLUMN = 3 MPLAYER_SLAVE_ARGS = ['-slave', '--hr-seek=always', '-nomsgcolor', '-msglevel', 'all=1:global=4:cplayer=4', '-af', 'scaletempo'] # --quiet works with both mpv 0.2 and 0.3 @@ -163,6 +165,10 @@ CONFIG_NAME_MARKER = ":" CONFIG_VALUE_MARKER = "=" USERITEM_CONTROLLER_ROLE = 0 USERITEM_READY_ROLE = 1 +FILEITEM_SWITCH_ROLE = 1 +FILEITEM_SWITCH_NO_SWITCH = 0 +FILEITEM_SWITCH_FILE_SWITCH = 1 +FILEITEM_SWITCH_STREAM_SWITCH = 2 SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/" \ No newline at end of file diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 57f6e5d..e608499 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -17,15 +17,15 @@ class UserlistItemDelegate(QtGui.QStyledItemDelegate): def sizeHint(self, option, index): size = QtGui.QStyledItemDelegate.sizeHint(self, option, index) - if (index.column() == 0): + if (index.column() == constants.USERLIST_GUI_USERNAME_COLUMN): size.setWidth(size.width() + constants.USERLIST_GUI_USERNAME_OFFSET) return size def paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex): column = indexQModelIndex.column() - if column == 0: + if column == constants.USERLIST_GUI_USERNAME_COLUMN: currentQAbstractItemModel = indexQModelIndex.model() - itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), 0, indexQModelIndex.parent()) + itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_USERNAME_COLUMN, indexQModelIndex.parent()) if sys.platform.startswith('win'): resourcespath = utils.findWorkingDir() + "\\resources\\" else: @@ -56,6 +56,29 @@ class UserlistItemDelegate(QtGui.QStyledItemDelegate): isUserRow = indexQModelIndex.parent() != indexQModelIndex.parent().parent() if isUserRow: optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+constants.USERLIST_GUI_USERNAME_OFFSET) + if column == constants.USERLIST_GUI_FILENAME_COLUMN: + if sys.platform.startswith('win'): + resourcespath = utils.findWorkingDir() + "\\resources\\" + else: + resourcespath = utils.findWorkingDir() + "/resources/" + currentQAbstractItemModel = indexQModelIndex.model() + itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_FILENAME_COLUMN, indexQModelIndex.parent()) + fileSwitchRole = currentQAbstractItemModel.data(itemQModelIndex, Qt.UserRole + constants.FILEITEM_SWITCH_ROLE) + if fileSwitchRole == constants.FILEITEM_SWITCH_FILE_SWITCH: + fileSwitchIconQPixmap = QtGui.QPixmap(resourcespath + "film_go.png") + itemQPainter.drawPixmap ( + (optionQStyleOptionViewItem.rect.x()), + optionQStyleOptionViewItem.rect.y(), + fileSwitchIconQPixmap.scaled(16, 16, Qt.KeepAspectRatio)) + optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+16) + + elif fileSwitchRole == constants.FILEITEM_SWITCH_STREAM_SWITCH: + streamSwitchIconQPixmap = QtGui.QPixmap(resourcespath + "world_go.png") + itemQPainter.drawPixmap ( + (optionQStyleOptionViewItem.rect.x()), + optionQStyleOptionViewItem.rect.y(), + streamSwitchIconQPixmap.scaled(16, 16, Qt.KeepAspectRatio)) + optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+16) QtGui.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex) class MainWindow(QtGui.QMainWindow): @@ -86,7 +109,7 @@ class MainWindow(QtGui.QMainWindow): self.roomInput.setText(self._syncplayClient.getRoom()) self.config = self._syncplayClient.getConfig() try: - self.updateReadyState(self.config['readyAtStart']) + self.updateReadyState(self.config['readyAtStart']) autoplayInitialState = self.config['autoplayInitialState'] if autoplayInitialState is not None: self.autoplayPushButton.blockSignals(True) @@ -118,6 +141,25 @@ class MainWindow(QtGui.QMainWindow): else: self.newMessage(time.strftime(constants.UI_TIME_FORMAT, time.localtime()) + message + "
") + def getFileSwitchState(self, filename): + if filename: + if self._syncplayClient.userlist.currentUser.file and filename == self._syncplayClient.userlist.currentUser.file['name']: + return constants.FILEITEM_SWITCH_NO_SWITCH + if isURL(filename): + return constants.FILEITEM_SWITCH_FILE_SWITCH + else: + currentPath = self._syncplayClient.userlist.currentUser.file["path"] if self._syncplayClient.userlist.currentUser.file else None + if currentPath: + currentDirectory = os.path.dirname(currentPath) + newPath = os.path.join(currentDirectory, filename) + if os.path.isfile(newPath): + return constants.FILEITEM_SWITCH_FILE_SWITCH + else: + return constants.FILEITEM_SWITCH_NO_SWITCH + else: + return constants.FILEITEM_SWITCH_NO_SWITCH + return constants.FILEITEM_SWITCH_NO_SWITCH + def showUserList(self, currentUser, rooms): self._usertreebuffer = QtGui.QStandardItemModel() self._usertreebuffer.setHorizontalHeaderLabels( @@ -157,6 +199,8 @@ class MainWindow(QtGui.QMainWindow): filesizeitem = QtGui.QStandardItem(formatSize(user.file['size'])) filedurationitem = QtGui.QStandardItem("({})".format(formatTime(user.file['duration']))) filenameitem = QtGui.QStandardItem((user.file['name'])) + fileSwitchState = self.getFileSwitchState(user.file['name']) if room == currentUser.room else None + filenameitem.setData(fileSwitchState, Qt.UserRole + constants.FILEITEM_SWITCH_ROLE) if currentUser.file: sameName = sameFilename(user.file['name'], currentUser.file['name']) sameSize = sameFilesize(user.file['size'], currentUser.file['size'])