From a1ab184e9a588854cdcab4de4b1c125dacf29417 Mon Sep 17 00:00:00 2001 From: Et0h Date: Sat, 2 Jul 2016 17:33:46 +0100 Subject: [PATCH] Add 'Set Trusted Domain' feature to main GUI and highlight untrusted domains in playlist --- syncplay/__init__.py | 2 +- syncplay/client.py | 6 ++++++ syncplay/constants.py | 1 + syncplay/messages_de.py | 4 +++- syncplay/messages_en.py | 4 +++- syncplay/messages_ru.py | 4 +++- syncplay/ui/gui.py | 38 +++++++++++++++++++++++++++++++++++++- 7 files changed, 54 insertions(+), 5 deletions(-) diff --git a/syncplay/__init__.py b/syncplay/__init__.py index fef95bb..4696516 100644 --- a/syncplay/__init__.py +++ b/syncplay/__init__.py @@ -1,4 +1,4 @@ version = '1.4.0' milestone = 'Yoitsu' -release_number = '25' +release_number = '26' projectURL = 'http://syncplay.pl/' diff --git a/syncplay/client.py b/syncplay/client.py index d0b4261..0443712 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -455,6 +455,12 @@ class SyncplayClient(object): self.sendFile() self.playlist.changeToPlaylistIndexFromFilename(filename) + def setTrustedDomains(self, newTrustedDomains): + from syncplay.ui.ConfigurationGetter import ConfigurationGetter + ConfigurationGetter().setConfigOption("trustedDomains", newTrustedDomains) + self._config['trustedDomains'] = newTrustedDomains + self.fileSwitchFoundFiles() + def isURITrusted(self, URIToTest): for trustedProtocol in constants.TRUSTABLE_WEB_PROTOCOLS: if URIToTest.startswith(trustedProtocol): diff --git a/syncplay/constants.py b/syncplay/constants.py index d15ad5d..b92b56b 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -144,6 +144,7 @@ STYLE_ERRORNOTIFICATION = "color: red;" STYLE_DIFFERENTITEM_COLOR = 'red' STYLE_NOFILEITEM_COLOR = 'blue' STYLE_NOTCONTROLLER_COLOR = 'grey' +STYLE_UNTRUSTEDITEM_COLOR = 'purple' USERLIST_GUI_USERNAME_OFFSET = 21 # Pixels USERLIST_GUI_USERNAME_COLUMN = 0 diff --git a/syncplay/messages_de.py b/syncplay/messages_de.py index 7e8844a..38bf60f 100644 --- a/syncplay/messages_de.py +++ b/syncplay/messages_de.py @@ -267,6 +267,7 @@ de = { "setoffset-menu-label" : u"&Offset einstellen", "createcontrolledroom-menu-label" : u"&Zentral gesteuerten Raum erstellen", "identifyascontroller-menu-label" : u"Als Raumleiter &identifizieren", + "settrusteddomains-menu-label" : u"Set &trusted domains", # TODO: Translate "playback-menu-label" : u"&Wiedergabe", @@ -283,6 +284,7 @@ de = { "addfolder-label" : u"Add folder", # TODO: Translate "adduris-msgbox-label" : u"Add URLs to playlist (one per line)", # TODO: Translate + "trusteddomains-msgbox-label" : u"Domains it is okay to automatically switch to (one per line)", # TODO: Translate "createcontrolledroom-msgbox-label" : u"Zentral gesteuerten Raum erstellen", "controlledroominfo-msgbox-label" : u"Namen des zentral gesteuerten Raums eingeben\r\n(siehe http://syncplay.pl/guide/ für eine Anleitung [Englisch]):", @@ -388,7 +390,7 @@ de = { "playlist-contents-changed-notification" : u"{} updated the playlist", # Username "cannot-find-file-for-playlist-switch-error" : u"Could not find file {} in media directories for playlist switch!", # Filename "cannot-add-duplicate-error" : u"Could not add second entry for '{}' to the playlist as no duplicates are allowed.", #Filename - "cannot-add-unsafe-path-error" : u"Could not load {} because it is not known as a trusted path.", # Filename + "cannot-add-unsafe-path-error" : u"Could not automatically load {} because it is not on a trusted domain. You can switch to the URL manually by double clicking it in the playlist, and add trusted domains via File->Advanced->Set Trusted Domains.", # Filename "sharedplaylistenabled-label" : u"Enable shared playlists", "removefromplaylist-menu-label" : u"Remove from playlist", "shuffleplaylist-menuu-label" : u"Shuffle playlist", diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index e695292..ccf49ce 100644 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -269,6 +269,7 @@ en = { "setoffset-menu-label" : "Set &offset", "createcontrolledroom-menu-label" : "&Create managed room", "identifyascontroller-menu-label" : "&Identify as room operator", + "settrusteddomains-menu-label" : u"Set &trusted domains", "playback-menu-label" : u"&Playback", @@ -285,6 +286,7 @@ en = { "addfolder-label" : u"Add folder", "adduris-msgbox-label" : u"Add URLs to playlist (one per line)", + "trusteddomains-msgbox-label" : u"Domains it is okay to automatically switch to (one per line)", "createcontrolledroom-msgbox-label" : "Create managed room", "controlledroominfo-msgbox-label" : "Enter name of managed room\r\n(see http://syncplay.pl/guide/ for usage instructions):", @@ -389,7 +391,7 @@ en = { "playlist-contents-changed-notification" : u"{} updated the playlist", # Username "cannot-find-file-for-playlist-switch-error" : u"Could not find file {} in media directories for playlist switch!", # Filename "cannot-add-duplicate-error" : u"Could not add second entry for '{}' to the playlist as no duplicates are allowed.", #Filename - "cannot-add-unsafe-path-error" : u"Could not load {} because it is not known as a trusted path.", # Filename + "cannot-add-unsafe-path-error" : u"Could not automatically load {} because it is not on a trusted domain. You can switch to the URL manually by double clicking it in the playlist, and add trusted domains via File->Advanced->Set Trusted Domains.", # Filename "sharedplaylistenabled-label" : u"Enable shared playlists", "removefromplaylist-menu-label" : u"Remove from playlist", "shuffleplaylist-menuu-label" : u"Shuffle playlist", diff --git a/syncplay/messages_ru.py b/syncplay/messages_ru.py index 1b98007..30e2a66 100644 --- a/syncplay/messages_ru.py +++ b/syncplay/messages_ru.py @@ -269,6 +269,7 @@ ru = { "setoffset-menu-label" : u"Установить &смещение", "createcontrolledroom-menu-label" : u"&Создать управляемую комнату", "identifyascontroller-menu-label" : u"&Войти как оператор комнаты", + "settrusteddomains-menu-label" : u"Set &trusted domains", # TODO: Translate "playback-menu-label" : u"&Воспроизведение", @@ -285,6 +286,7 @@ ru = { "addfolder-label" : u"Add folder", # TODO: Translate "adduris-msgbox-label" : u"Add URLs to playlist (one per line)", # TODO: Translate + "trusteddomains-msgbox-label" : u"Domains it is okay to automatically switch to (one per line)", # TODO: Translate "createcontrolledroom-msgbox-label" : u"Создать управляемую комнату", "controlledroominfo-msgbox-label" : u"Введите имя управляемой комнаты\r\n(см. инструкцию на странице http://syncplay.pl/guide/):", @@ -388,7 +390,7 @@ ru = { "playlist-contents-changed-notification" : u"{} updated the playlist", # Username "cannot-find-file-for-playlist-switch-error" : u"Could not find file {} in media directories for playlist switch!", # Filename "cannot-add-duplicate-error" : u"Could not add second entry for '{}' to the playlist as no duplicates are allowed.", #Filename - "cannot-add-unsafe-path-error" : u"Could not load {} because it is not known as a trusted path.", # Filename + "cannot-add-unsafe-path-error" : u"Could not automatically load {} because it is not on a trusted domain. You can switch to the URL manually by double clicking it in the playlist, and add trusted domains via File->Advanced->Set Trusted Domains.", # Filename # TODO: Translate "sharedplaylistenabled-label" : u"Enable shared playlists", "removefromplaylist-menu-label" : u"Remove from playlist", "shuffleplaylist-menuu-label" : u"Shuffle playlist", diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 537c3b7..8349f35 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -182,7 +182,10 @@ class MainWindow(QtGui.QMainWindow): isPlayingFilename = itemFilename == self.playlistIndexFilename self.item(item).setData(Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE, isPlayingFilename) fileIsAvailable = self.selfWindow.isFileAvailable(itemFilename) - if fileIsAvailable: + fileIsUntrusted = self.selfWindow.isItemUntrusted(itemFilename) + if fileIsUntrusted: + self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_UNTRUSTEDITEM_COLOR))) + elif fileIsAvailable: self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(QtGui.QPalette.ColorRole(QtGui.QPalette.Text)))) else: self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR))) @@ -349,6 +352,10 @@ class MainWindow(QtGui.QMainWindow): self.newWatchlist.extend([filename]) return constants.FILEITEM_SWITCH_NO_SWITCH + @needsClient + def isItemUntrusted(self, filename): + return isURL(filename) and not self._syncplayClient.isURITrusted(filename) + @needsClient def isFileAvailable(self, filename): if filename: @@ -834,6 +841,32 @@ class MainWindow(QtGui.QMainWindow): newMediaDirectories = utils.convertMultilineStringToList(MediaDirectoriesTextbox.toPlainText()) self._syncplayClient.fileSwitch.changeMediaDirectories(newMediaDirectories) + @needsClient + def openSetTrustedDomainsDialog(self): + TrustedDomainsDialog = QtGui.QDialog() + TrustedDomainsDialog.setWindowTitle(getMessage("settrusteddomains-menu-label")) + TrustedDomainsLayout = QtGui.QGridLayout() + TrustedDomainsLabel = QtGui.QLabel(getMessage("trusteddomains-msgbox-label")) + TrustedDomainsLayout.addWidget(TrustedDomainsLabel, 0, 0, 1, 1) + TrustedDomainsTextbox = QtGui.QPlainTextEdit() + TrustedDomainsTextbox.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) + TrustedDomainsTextbox.setPlainText(utils.getListAsMultilineString(self.config["trustedDomains"])) + TrustedDomainsLayout.addWidget(TrustedDomainsTextbox, 1, 0, 1, 1) + TrustedDomainsButtonBox = QtGui.QDialogButtonBox() + TrustedDomainsButtonBox.setOrientation(Qt.Horizontal) + TrustedDomainsButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel) + TrustedDomainsButtonBox.accepted.connect(TrustedDomainsDialog.accept) + TrustedDomainsButtonBox.rejected.connect(TrustedDomainsDialog.reject) + TrustedDomainsLayout.addWidget(TrustedDomainsButtonBox, 2, 0, 1, 1) + TrustedDomainsDialog.setLayout(TrustedDomainsLayout) + TrustedDomainsDialog.setModal(True) + TrustedDomainsDialog.show() + result = TrustedDomainsDialog.exec_() + if result == QtGui.QDialog.Accepted: + newTrustedDomains = utils.convertMultilineStringToList(TrustedDomainsTextbox.toPlainText()) + self._syncplayClient.setTrustedDomains(newTrustedDomains) + + @needsClient def openAddMediaDirectoryDialog(self, MediaDirectoriesTextbox, MediaDirectoriesDialog): folderName = unicode(QtGui.QFileDialog.getExistingDirectory(self,None,self.getInitialMediaDirectory(includeUserSpecifiedDirectories=False),QtGui.QFileDialog.ShowDirsOnly)) @@ -1179,6 +1212,9 @@ class MainWindow(QtGui.QMainWindow): window.identifyascontroller = window.advancedMenu.addAction(QtGui.QIcon(self.resourcespath + 'key_go.png'), getMessage("identifyascontroller-menu-label")) window.identifyascontroller.triggered.connect(self.identifyAsController) + window.setTrustedDomainsAction = window.advancedMenu.addAction(QtGui.QIcon(self.resourcespath + 'film_folder_edit.png'), + getMessage("settrusteddomains-menu-label")) + window.setTrustedDomainsAction.triggered.connect(self.openSetTrustedDomainsDialog) window.menuBar.addMenu(window.advancedMenu)