From 7465c85d8e97a1f1d39ae3868a197460c636da7a Mon Sep 17 00:00:00 2001 From: Et0h Date: Mon, 17 Oct 2016 23:50:45 +0100 Subject: [PATCH] Add "add X as trusted domain" playlist menu option --- buildPy2exe.py | 1 + resources/shield_add.png | Bin 0 -> 758 bytes syncplay/client.py | 16 ++++++++++++++-- syncplay/messages_de.py | 1 + syncplay/messages_en.py | 1 + syncplay/messages_ru.py | 1 + syncplay/ui/gui.py | 10 +++++++++- syncplay/utils.py | 6 ++++++ 8 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 resources/shield_add.png diff --git a/buildPy2exe.py b/buildPy2exe.py index abe0db1..8c40178 100644 --- a/buildPy2exe.py +++ b/buildPy2exe.py @@ -658,6 +658,7 @@ guiIcons = ['resources/accept.png', 'resources/arrow_undo.png', 'resources/clock 'resources/film_folder_edit.png', 'resources/film_edit.png', 'resources/shield_edit.png', + 'resources/shield_add.png', 'resources/world_add.png', 'resources/film_add.png', 'resources/delete.png', 'resources/spinner.mng' ] resources = ["resources/icon.ico", "resources/syncplay.png"] diff --git a/resources/shield_add.png b/resources/shield_add.png new file mode 100644 index 0000000000000000000000000000000000000000..e20a1b4ab6f6d664d4d4b7175569ff0de32be247 GIT binary patch literal 758 zcmV?Fzp3k#2;Op=9! zVS%RGgcvtB?=hrnT(^1LdEEQ||L^Y{iyPBKvvKOIPJPa&)A<@z<$uZ3-6v zc~$Gk^h9y;%5Y0+$*))mIb#7qgC5d9!ldIb@VnnpFu9T5$YrK&jTjd|MT^t1mgM-l zi=cwqeuBO>+~TDe5+v>*=`WxH zDB^YD#jY{*;V7u!b$6g5&jH-u$57F%uJu6zFoLAQn4AE$>1<~_P>T~PCNq?*1bT)6 zRzMZRM{R&{ERX^dVAKOmgLqjZYY{8*w}EC2R0Gf)APsmZ9%=*BdZ-GBL9K*F0<0k7 z;S|ik4n)A@g5!gewRjZEqxJiE`ktM{PYJ1^!X4M4$r(0~Gs!nsaL3hQLK85q!MFj& z^?C5w(w-@!VR-|4w(O;LaWzcjP~E<&Q-1(e8=fB+?7UC%eKWb`8*vK8;N%7vcaYn! zlPsKDi*+oum8-EPpl(4uz}^wBtX9efI_@#hai37>HjFzH;|vn-OAs<+SwC+-00&oH zV8)~xfcz1FsheLVGO1*BZ?u`-$W^RA1x2fB&I!kl=p3xE?XyZ9830Hn>o()jVx z+;X+D-*LwrDVp8Lxw|)dqa{Tp^)<_wRk4Towq)Bpeg literal 0 HcmV?d00001 diff --git a/syncplay/client.py b/syncplay/client.py index 3c788eb..a9fce18 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -462,10 +462,22 @@ class SyncplayClient(object): def setTrustedDomains(self, newTrustedDomains): from syncplay.ui.ConfigurationGetter import ConfigurationGetter ConfigurationGetter().setConfigOption("trustedDomains", newTrustedDomains) - self._config['trustedDomains'] = newTrustedDomains - self.fileSwitchFoundFiles() + oldTrustedDomains = self._config['trustedDomains'] + if oldTrustedDomains <> newTrustedDomains: + self._config['trustedDomains'] = newTrustedDomains + self.fileSwitchFoundFiles() + self.ui.showMessage("Trusted domains updated") + # TODO: Properly add message for setting trusted domains! + + def isUntrustedTrustableURI(self, URIToTest): + if utils.isURL(URIToTest): + for trustedProtocol in constants.TRUSTABLE_WEB_PROTOCOLS: + if URIToTest.startswith(trustedProtocol) and not self.isURITrusted(URIToTest): + return True + return False def isURITrusted(self, URIToTest): + URIToTest = URIToTest+u"/" for trustedProtocol in constants.TRUSTABLE_WEB_PROTOCOLS: if URIToTest.startswith(trustedProtocol): if self._config['onlySwitchToTrustedDomains']: diff --git a/syncplay/messages_de.py b/syncplay/messages_de.py index 69beb1f..2af0e9f 100644 --- a/syncplay/messages_de.py +++ b/syncplay/messages_de.py @@ -269,6 +269,7 @@ de = { "createcontrolledroom-menu-label" : u"&Zentral gesteuerten Raum erstellen", "identifyascontroller-menu-label" : u"Als Raumleiter &identifizieren", "settrusteddomains-menu-label" : u"Set &trusted domains", # TODO: Translate + "addtrusteddomain-menu-label" : u"Add {} as trusted domain", # Domain # TODO: Translate "playback-menu-label" : u"&Wiedergabe", diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index d2b933b..16be0b7 100644 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -271,6 +271,7 @@ en = { "createcontrolledroom-menu-label" : "&Create managed room", "identifyascontroller-menu-label" : "&Identify as room operator", "settrusteddomains-menu-label" : u"Set &trusted domains", + "addtrusteddomain-menu-label" : u"Add {} as trusted domain", # Domain "playback-menu-label" : u"&Playback", diff --git a/syncplay/messages_ru.py b/syncplay/messages_ru.py index 8778678..a06ac92 100644 --- a/syncplay/messages_ru.py +++ b/syncplay/messages_ru.py @@ -230,6 +230,7 @@ ru = { "unpause-ifminusersready-option" : u"Unpause if already ready or if all others ready and min users ready", # TODO: Translate into Russian "unpause-always" : u"Always unpause", # TODO: Translate into Russian "syncplay-trusteddomains-title": u"Trusted domains (for streaming services and hosted content)", # TODO: Translate into Russian +"addtrusteddomain-menu-label" : u"Add {} as trusted domain", # Domain # TODO: Translate "help-label" : u"Помощь", "reset-label" : u"Сброс настроек", diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 7fec6a5..02a082b 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -498,6 +498,9 @@ class MainWindow(QtGui.QMainWindow): pathFound = self._syncplayClient.fileSwitch.findFilepath(firstFile) if pathFound: menu.addAction(QtGui.QPixmap(resourcespath + u"film_go.png"), getMessage("openmedia-menu-label"), lambda: self.openFile(pathFound)) + if self._syncplayClient.isUntrustedTrustableURI(firstFile): + domain = utils.getDomainFromURL(firstFile) + menu.addAction(QtGui.QPixmap(resourcespath + u"shield_add.png"),getMessage("addtrusteddomain-menu-label").format(domain), lambda: self.addTrustedDomain(domain)) menu.addAction(QtGui.QPixmap(resourcespath + u"delete.png"), getMessage("removefromplaylist-menu-label"), lambda: self.deleteSelectedPlaylistItems()) menu.addSeparator() menu.addAction(QtGui.QPixmap(resourcespath + u"arrow_switch.png"), getMessage("shuffleplaylist-menuu-label"), lambda: self.shufflePlaylist()) @@ -897,7 +900,12 @@ class MainWindow(QtGui.QMainWindow): if result == QtGui.QDialog.Accepted: newTrustedDomains = utils.convertMultilineStringToList(TrustedDomainsTextbox.toPlainText()) self._syncplayClient.setTrustedDomains(newTrustedDomains) - + @needsClient + def addTrustedDomain(self, newDomain): + trustedDomains = self.config["trustedDomains"][:] + if newDomain: + trustedDomains.append(newDomain) + self._syncplayClient.setTrustedDomains(trustedDomains) @needsClient def openAddMediaDirectoryDialog(self, MediaDirectoriesTextbox, MediaDirectoriesDialog): diff --git a/syncplay/utils.py b/syncplay/utils.py index fb629df..dca6449 100644 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -250,6 +250,12 @@ def getListAsMultilineString(pathArray): def convertMultilineStringToList(multilineString): return unicode.split(multilineString,u"\n") if multilineString else "" +def getDomainFromURL(URL): + try: + return URL.split("//")[-1].split("/")[0] + except: + return None + def getListOfPublicServers(): try: import urllib, syncplay, sys, messages, json