From c5753773411866cd8ab1313d69c4049c88e45c58 Mon Sep 17 00:00:00 2001 From: Et0h Date: Fri, 2 Oct 2015 18:34:12 +0100 Subject: [PATCH] Add context menu to list of who is playing what --- buildPy2exe.py | 3 +- syncplay/client.py | 4 +-- syncplay/ui/gui.py | 69 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/buildPy2exe.py b/buildPy2exe.py index a4e7da3..6cbc095 100644 --- a/buildPy2exe.py +++ b/buildPy2exe.py @@ -654,7 +654,8 @@ guiIcons = ['resources/accept.png', 'resources/arrow_undo.png', 'resources/clock 'resources/user_key.png', 'resources/lock.png', 'resources/key_go.png', 'resources/page_white_key.png', 'resources/tick.png', 'resources/lock_open.png', 'resources/empty_checkbox.png', 'resources/tick_checkbox.png', 'resources/world_explore.png', 'resources/application_get.png', 'resources/cog.png', - 'resources/film_go.png', 'resources/world_go.png', 'resources/arrow_refresh.png' + 'resources/film_go.png', 'resources/world_go.png', 'resources/arrow_refresh.png', + 'resources/world_add.png', 'resources/film_add.png' ] resources = ["resources/icon.ico", "resources/syncplay.png"] resources.extend(guiIcons) diff --git a/syncplay/client.py b/syncplay/client.py index 56e40af..c6c31cc 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -176,8 +176,8 @@ class SyncplayClient(object): if filename.startswith(URI): self._player.openFile(filename, resetPosition=True) return - self.ui.showErrorMessage(u"Could not load {} because it is not known as a safe path.".format(filename)) - return + self.ui.showErrorMessage(u"Could not load {} because it is not known as a safe path.".format(filename)) + return else: path = self.findFilenameInDirectories(filename) if path: diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 50af7cf..0e8ed2b 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -532,10 +532,10 @@ class MainWindow(QtGui.QMainWindow): if isControlledRoom and not isController: useritem.setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_NOTCONTROLLER_COLOR))) useritem.setFont(font) - useritem.setFlags(useritem.flags() & ~Qt.ItemIsEditable & ~Qt.ItemIsSelectable) - filenameitem.setFlags(filenameitem.flags() & ~Qt.ItemIsEditable & ~Qt.ItemIsSelectable) - filesizeitem.setFlags(filesizeitem.flags() & ~Qt.ItemIsEditable & ~Qt.ItemIsSelectable) - filedurationitem.setFlags(filedurationitem.flags() & ~Qt.ItemIsEditable & ~Qt.ItemIsSelectable) + useritem.setFlags(useritem.flags() & ~Qt.ItemIsEditable) + filenameitem.setFlags(filenameitem.flags() & ~Qt.ItemIsEditable) + filesizeitem.setFlags(filesizeitem.flags() & ~Qt.ItemIsEditable) + filedurationitem.setFlags(filedurationitem.flags() & ~Qt.ItemIsEditable) roomitem.appendRow((useritem, filesizeitem, filedurationitem, filenameitem)) self.listTreeModel = self._usertreebuffer self.listTreeView.setModel(self.listTreeModel) @@ -547,6 +547,51 @@ class MainWindow(QtGui.QMainWindow): MainWindow.FileSwitchManager.setFilenameWatchlist(self.newWatchlist) self.checkForDisabledDir() + def openRoomMenu(self, position): + # TODO: Deselect items after right click + indexes = self.listTreeView.selectedIndexes() + if sys.platform.startswith('win'): + resourcespath = utils.findWorkingDir() + "\\resources\\" + else: + resourcespath = utils.findWorkingDir() + "/resources/" + if len(indexes) > 0: + item = self.listTreeView.selectedIndexes()[0] + else: + return + + menu = QtGui.QMenu() + username = item.sibling(item.row(), 0).data() + if username == self._syncplayClient.userlist.currentUser.username: + shortUsername = "your" # TODO: Use messages.py + elif len(username) < 15: + shortUsername = u"{}'s".format(username) + else: + shortUsername = "{}'s...".format(username[0:12]) + + filename = item.sibling(item.row(), 3).data() + while item.parent().row() != -1: + item = item.parent() + roomToJoin = item.sibling(item.row(), 0).data() + if roomToJoin <> self._syncplayClient.getRoom(): + menu.addAction("Join room {}".format(roomToJoin), lambda: self.joinRoom(roomToJoin)) + elif username and filename and filename <> getMessage("nofile-note"): + if isURL(filename): + menu.addAction(QtGui.QPixmap(resourcespath + "world_add.png"), "Add {} stream 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 isURL(filename): + menu.addAction(QtGui.QPixmap(resourcespath + "world_go.png"), "Open stream {} stream".format(shortUsername), lambda: self.openFile(filename)) + else: + pathFound = MainWindow.FileSwitchManager.findFilepath(filename) + if pathFound: + menu.addAction(QtGui.QPixmap(resourcespath + "film_go.png"), "Open {} file".format(shortUsername), lambda: self.openFile(pathFound)) + else: + return + menu.exec_(self.listTreeView.viewport().mapToGlobal(position)) + + def checkForDisabledDir(self): if MainWindow.FileSwitchManager.disabledDir is not None and MainWindow.FileSwitchManager.currentWindow is not None: self.showErrorMessage(getMessage("folder-search-timeout-error").format(MainWindow.FileSwitchManager.disabledDir)) @@ -590,7 +635,7 @@ class MainWindow(QtGui.QMainWindow): if pathFound: self._syncplayClient._player.openFile(pathFound) else: - self.ui.showErrorMessage(u"Could not find file {} for playlist switch!".format(filename)) + self._syncplayClient.ui.showErrorMessage(u"Could not find file {} for playlist switch!".format(filename)) def roomClicked(self, item): username = item.sibling(item.row(), 0).data() @@ -848,6 +893,9 @@ class MainWindow(QtGui.QMainWindow): window.listTreeView.setModel(window.listTreeModel) window.listTreeView.setIndentation(21) window.listTreeView.doubleClicked.connect(self.roomClicked) + self.listTreeView.setContextMenuPolicy(Qt.CustomContextMenu) + self.listTreeView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) + self.listTreeView.customContextMenuRequested.connect(self.openRoomMenu) window.listlabel = QtGui.QLabel(getMessage("userlist-heading-label")) window.listFrame = QtGui.QFrame() window.listFrame.setLineWidth(0) @@ -1236,10 +1284,15 @@ class MainWindow(QtGui.QMainWindow): self.playlist.addItem(os.path.basename(filePath)) else: self.playlist.insertItem(index, os.path.basename(filePath)) + self.playlistUpdated() - def addStreamToPlaylist(self, filePath): - self.removePlayListNote() - self.playlist.addItem(os.path.basename(filePath)) + def openFile(self, filePath, resetPosition=False): + self._syncplayClient._player.openFile(filePath, resetPosition) + + def addStreamToPlaylist(self, streamURI): + self.removePlaylistNote() + self.playlist.addItem(streamURI) + self.playlistUpdated() def removePlaylistNote(self): if not self.clearedPlaylistNote: