From eca33f89346b4ad0e7bbaef7438e8a87daa963a9 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 11 Jan 2010 19:18:34 +0100 Subject: [PATCH] Add some parental control improvements (made by Tode) --- data/skin_default/Makefile.am | 4 + data/skin_default/lock.png | Bin 0 -> 1053 bytes data/skin_default/lockBouquet.png | Bin 0 -> 1176 bytes data/skin_default/unlock.png | Bin 0 -> 965 bytes data/skin_default/unlockBouquet.png | Bin 0 -> 1141 bytes lib/python/Components/ParentalControl.py | 316 ++++++++++++++----- lib/python/Components/ParentalControlList.py | 29 +- lib/python/Screens/ParentalControlSetup.py | 79 ++++- 8 files changed, 320 insertions(+), 108 deletions(-) create mode 100644 data/skin_default/lock.png create mode 100644 data/skin_default/lockBouquet.png create mode 100644 data/skin_default/unlock.png create mode 100644 data/skin_default/unlockBouquet.png mode change 100755 => 100644 lib/python/Components/ParentalControl.py mode change 100755 => 100644 lib/python/Screens/ParentalControlSetup.py diff --git a/data/skin_default/Makefile.am b/data/skin_default/Makefile.am index 9e9b7cd4..85bb800d 100755 --- a/data/skin_default/Makefile.am +++ b/data/skin_default/Makefile.am @@ -32,6 +32,8 @@ dist_install_DATA = \ expanded-plugins.png \ info-bg_mp.png \ info-bg.png \ + lock.png \ + lockBouquet.png \ mediaplayer_bg.png \ mute.png \ nim_active.png \ @@ -52,6 +54,8 @@ dist_install_DATA = \ timeline-now.png \ timeline.png \ unhandled-key.png \ + unlock.png \ + unlockBouquet.png \ verticalline-plugins.png \ vkey_backspace.png \ vkey_bg.png \ diff --git a/data/skin_default/lock.png b/data/skin_default/lock.png new file mode 100644 index 0000000000000000000000000000000000000000..d0ae7f64f5de4e0d52dffd860e49049d801286b8 GIT binary patch literal 1053 zcmXw1eJqr59DkHvh?e-H!c=Qx&6btWi?$0BLx!=GQqF8r(b{^K=Q&pt5>{*5gO72x1RG1lJ+2_PeHIU3UwqNqm;5TZ#6K@7vv%z4j{KoW}@hB{)j2{?`6lQN?oLqiPn zAjB2(p@X8LKp}~RBy_0?l3+$m$BQa`g%;R=0wEd) z6eV>tPB0ebGVwqNp?PFRBw`7Kj`c>z7?C zJ#{*Zlj{Djf=h#T;?s5-A@NJ`xJq??39~8kgfS&;SZOys*c!b-tmZhs&nH8g#*cEd zn{RaX=N;Z=Do)@$`x3u<$wOnrrnZq>Rm3{8BCBFcgKu2z$oe@)QKILkCP!K5luLL@ z(wzIN3yO9Zdz+TkM7&+RqLkOzW*F1bkF1>>`x&+SR-u)}HN(a$=aO@zvB^%Hjq4%V zO>0%`jkfR44um|=SGA?wt#OeRFCXe3@9r4V>fQ|g{`uN4H7C6KXnL$OzR%pVQd3qa zwY)6yVaq&!IK<^8SdvjUaib(Pp~YuGuTOA#!jXeHGcMYyI%l(0k<>lgDQjo2h0^|; z+r14rfqZcMj)8o&uPf{95t?i35ty4)@0V+zn&0QWZ=h)_-$MEtuI~Cn>zX b&&nqp_h8W}=1GMBk^WsxC_yKBeR zsD;R!sJK~iXaM;=!BIhanDSSlXn{kAtNaGR!Cc00hp>lT;@9u`z2Eyj@AE$Id#8(4 z$X#95xex^58vU*;4yQLBA7=;r>+|N94#zafEW= z20bmFZr~YcBYVkMFtkfILJYgwg)?Q{SId#oB3V6R&fuCdO%9^=sG!adLhpVgon+PH zx7B^xxS?BLLLq3;3o2sBkSdG|9@~Z3}@$OaAP=r4DK{3^T=DwpzK; zDJx&ir}ecqaC{B>xOL*U1%{csU}h%U$9iV2T<@Q3?&AlUZc~5NEYtDBQ1^{dyNzME zD|}TW-&j3&+UP!U*oPpNI0(N!JkevO;GO&7~ZBx$2VxIu_pf?vN_M zbGp+~G;IkYf3I>oQW#Y6$5W>RmhE4xO1GtlFt)#6joOuSN|N7J?O)+{(y~!1j`p8Y z@t)5l9}kZQD#H@TOqSa^$1dNuRbF+$X#w?i-EnHqNA-sj@B+F(O*UQnpF zkK|Zjta!dMky!LkGHePQ_LrNqGB0IrNx4JVf_%$cFJ6ndw2w_aS95OG%{x1#K6jO$ z7j+`P`^=4SuX?;O!&po|ux6|i$tTEJRG9^~|_AY)>VA!3y{ill`R-`^G-MYTz&Oc|3+_qhx zIdbCtq3-WR7~0~lx&FFf3yUni`9}FKdJkRyt>#(rkFS^esn(>7gt%|6TC1HadNV3w z^M>mlC8l7-iItzG7ilFON6&0sVa^)7|8SGXy1$&9p53+Tm)yH@GgMn@aU*Nh){jcXy#BIFLkO8RZ2izA zOGc&X`n^|YNm(emh2%_Oeu}PBk8{3#=l#C#InVpN&--^$Emk zgJ-qL0>tzT-TYz@>E-XmFqIkRx-dhA(W?#EAM6X9T8OHM+KB3i%7|)+Du~93R7BH6 z?L_^;W`w9yI2H=zA);&|fPFMSz%Ldyz`Ke537P=z3m_8Hg=kP&Bv2m&^+4OvX3a0CJzG#En`+5~?{ zXaq&U!CO%oDX0Z|$$~g^fP;^SE5Z<&s19Rd?})e%3}oS!L;}b)LKU$=kRgIv=mmVF zqY4bb5-tH%kO*(MI*7mzOu_(U(d;bQu3hv2AMa{Zpgf4-X1K{2-3-U^JSPmS*zw#L z$JMvba06rS+0NFyk1Vg_%gd*`=H^POC-_%9`;MLZ@oQMq#YVCN6TG%OaU?dKAD!i^ z$8wQA@#jm0uC2ShP00>7P7XfOq)z>gOXK_4XFof7`EGS_MSM*!{v=nKk5_PX&xue< zycsjPQF50F3NeZ*THElJebcH|9s1P%P@7;M!3LEzRp_78R6Z>jG(BQJ@F%IE$;|Sz zgKUra5~~zRaDIxO@wqI^+s%$G^`7yI9~5rMOLCH{iSyOD0whv17ya@uZ|QTF#sf6_RMz4j;zGO_zOxC<9j91P0Mm_WY#GX97^?aCjAx}9CMJl$E|m@>d)O6 z7SOV(RFjz&(h+ahvZ1)kRa22FYBjdkrRVbWsWlOrO6Tv)4x^VBH}k0qd_qR% LEBATq9h&eTRIUiX literal 0 HcmV?d00001 diff --git a/data/skin_default/unlockBouquet.png b/data/skin_default/unlockBouquet.png new file mode 100644 index 0000000000000000000000000000000000000000..c5d146d757ac8d29f0cbbc65e526ae28ec99b37c GIT binary patch literal 1141 zcmXw14NOy46u#AprWJ%}GP0tMB@UOU5eYcTG!$#41F=K4CC-`Q21szGbBr+(+*RxZ zAqBFz!G;2&WGR$7L0<-)rZ|d*|JI?svZPopWD_ zDrHBY=tU7BBv6?sPsKM3@5&_$;kD%~{}E=%cFG9(v0TiiFCt_?uqruiyVvW*5xqe< zj-zdq_EBn}w1ZM3r8-LIDD9>mkB6EmwNu_dq;#0lC%)}H%G*~y59jq|HB$OF1(nvMH~il7`7-145+{iK$TCM z=6O0WNQB|k^}H!C;6V!=)NZ%)YxE0`c7TCMf5cCP_OV4d9AN=@&<2B4bd3kvfb=r} zfI_r_caT2iG|6%VP4Z>j4(iieV7qng(MC72I} zY^@1*DE9nRElFXHsK*(`TM z1tEgtO1Ug8|8C)6#ybhJ;D9l~3PFgVOMId0e~XI@SzhER-7t14TD^7jlQS2iE@YH`A^tD{Nlrp54~0=&UwSz zD~r9A6!GQFo$(PC?}^yMt9Gm%|6VFC8?rKy)|mauW1XMX4K8ITHn%=*GTOwyj86BB zTY`eP=}G6*{M>ulg13dPoPC;vB=zvw=+k0t!JabV>T|l`?r2S9Qui{OIO3%jvYGhw zbIRJ@M)RV}!P2djEe)ML>VRn+VUyl< zqQ9xEDQi`IMwu)$u0L4%R@6`B<_!v|V*E^|D!I*b^g%^)<8|lx`&FVzd3!FKER2yo z_%P9yn0#Q@UgiEzB|%3HST?`BzJ1H(-u16~7V2up^S9MjHsjwQ%IzugmW20@{RiGB Ba2Nmp literal 0 HcmV?d00001 diff --git a/lib/python/Components/ParentalControl.py b/lib/python/Components/ParentalControl.py old mode 100755 new mode 100644 index d68e01ff..4830d20a --- a/lib/python/Components/ParentalControl.py +++ b/lib/python/Components/ParentalControl.py @@ -1,19 +1,34 @@ -from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigYesNo, ConfigSubList, ConfigInteger +from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigText, ConfigYesNo, ConfigSubList, ConfigInteger +#from Screens.ChannelSelection import service_types_tv from Screens.InputBox import PinInput from Screens.MessageBox import MessageBox from Tools.BoundFunction import boundFunction from ServiceReference import ServiceReference from Tools import Notifications from Tools.Directories import resolveFilename, SCOPE_CONFIG +from enigma import eTimer +import time + +TYPE_SERVICE = "SERVICE" +TYPE_BOUQUETSERVICE = "BOUQUETSERVICE" +TYPE_BOUQUET = "BOUQUET" +LIST_BLACKLIST = "blacklist" +LIST_WHITELIST = "whitelist" + +IMG_WHITESERVICE = LIST_WHITELIST + "-" + TYPE_SERVICE +IMG_WHITEBOUQUET = LIST_WHITELIST + "-" + TYPE_BOUQUET +IMG_BLACKSERVICE = LIST_BLACKLIST + "-" + TYPE_SERVICE +IMG_BLACKBOUQUET = LIST_BLACKLIST + "-" + TYPE_BOUQUET def InitParentalControl(): config.ParentalControl = ConfigSubsection() config.ParentalControl.configured = ConfigYesNo(default = False) config.ParentalControl.mode = ConfigSelection(default = "simple", choices = [("simple", _("simple")), ("complex", _("complex"))]) - config.ParentalControl.storeservicepin = ConfigSelection(default = "never", choices = [("never", _("never")), ("5_minutes", _("5 minutes")), ("30_minutes", _("30 minutes")), ("60_minutes", _("60 minutes")), ("restart", _("until restart"))]) + config.ParentalControl.storeservicepin = ConfigSelection(default = "never", choices = [("never", _("never")), ("5", _("5 minutes")), ("30", _("30 minutes")), ("60", _("60 minutes")), ("standby", _("until standby/restart"))]) + config.ParentalControl.storeservicepincancel = ConfigSelection(default = "never", choices = [("never", _("never")), ("5", _("5 minutes")), ("30", _("30 minutes")), ("60", _("60 minutes")), ("standby", _("until standby/restart"))]) config.ParentalControl.servicepinactive = ConfigYesNo(default = False) config.ParentalControl.setuppinactive = ConfigYesNo(default = False) - config.ParentalControl.type = ConfigSelection(default = "blacklist", choices = [("whitelist", _("whitelist")), ("blacklist", _("blacklist"))]) + config.ParentalControl.type = ConfigSelection(default = "blacklist", choices = [(LIST_WHITELIST, _("whitelist")), (LIST_BLACKLIST, _("blacklist"))]) config.ParentalControl.setuppin = ConfigPIN(default = -1) config.ParentalControl.retries = ConfigSubsection() @@ -39,40 +54,58 @@ def InitParentalControl(): class ParentalControl: def __init__(self): - self.open() + #Do not call open on init, because bouquets are not ready at that moment +# self.open() self.serviceLevel = {} - - def addWhitelistService(self, service): - self.whitelist.append(service) + #Instead: Use Flags to see, if we already initialized config and called open + self.configInitialized = False + self.filesOpened = False + #This is the timer that is used to see, if the time for caching the pin is over + #Of course we could also work without a timer and compare the times every + #time we call isServicePlayable. But this might probably slow down zapping, + #That's why I decided to use a timer + self.sessionPinTimer = eTimer() + self.sessionPinTimer.callback.append(self.resetSessionPin) - def addBlacklistService(self, service): - self.blacklist.append(service) - - def setServiceLevel(self, service, level): - self.serviceLevel[service] = level - - def deleteWhitelistService(self, service): - self.whitelist.remove(service) - if self.serviceLevel.has_key(service): - self.serviceLevel.remove(service) + def serviceMethodWrapper(self, service, method, *args): + #This method is used to call all functions that need a service as Parameter: + #It takes either a Service- Reference or a Bouquet- Reference and passes + #Either the service or all services contained in the bouquet to the method given + #That way all other functions do not need to distinguish between service and bouquet. + if "FROM BOUQUET" in service: + method( service , TYPE_BOUQUET , *args ) + servicelist = self.readServicesFromBouquet(service,"C") + for ref in servicelist: + sRef = str(ref[0]) + method( sRef , TYPE_BOUQUETSERVICE , *args ) + else: + ref = ServiceReference(service) + sRef = str(ref) + method( sRef , TYPE_SERVICE , *args ) - def deleteBlacklistService(self, service): - self.blacklist.remove(service) - if self.serviceLevel.has_key(service): - self.serviceLevel.remove(service) + def setServiceLevel(self, service, type, level): + self.serviceLevel[service] = level def isServicePlayable(self, ref, callback): if not config.ParentalControl.configured.value or not config.ParentalControl.servicepinactive.value: return True - #print "whitelist:", self.whitelist - #print "blacklist:", self.blacklist - #print "config.ParentalControl.type.value:", config.ParentalControl.type.value - #print "not in whitelist:", (service not in self.whitelist) - #print "checking parental control for service:", ref.toString() + #Check if we already read the whitelists and blacklists. If not: call open + if self.filesOpened == False: + self.open() + #Check if configuration has already been read or if the significant values have changed. + #If true: read the configuration + if self.configInitialized == False or self.storeServicePin != config.ParentalControl.storeservicepin.value or self.storeServicePinCancel != config.ParentalControl.storeservicepincancel.value: + self.getConfigValues() service = ref.toCompareString() - if (config.ParentalControl.type.value == "whitelist" and service not in self.whitelist) or (config.ParentalControl.type.value == "blacklist" and service in self.blacklist): + if (config.ParentalControl.type.value == LIST_WHITELIST and not self.whitelist.has_key(service)) or (config.ParentalControl.type.value == LIST_BLACKLIST and self.blacklist.has_key(service)): + #Check if the session pin is cached and return the cached value, if it is. + if self.sessionPinCached == True: + #As we can cache successful pin- entries as well as canceled pin- entries, + #We give back the last action + return self.sessionPinCachedValue self.callback = callback - #print "service:", ServiceReference(service).getServiceName() + #Someone started to implement different levels of protection. Seems they were never completed + #I did not throw out this code, although it is of no use at the moment levelNeeded = 0 if self.serviceLevel.has_key(service): levelNeeded = self.serviceLevel[service] @@ -83,103 +116,214 @@ class ParentalControl: return True def protectService(self, service): - #print "protect" - #print "config.ParentalControl.type.value:", config.ParentalControl.type.value - if config.ParentalControl.type.value == "whitelist": - if service in self.whitelist: - self.deleteWhitelistService(service) + if config.ParentalControl.type.value == LIST_WHITELIST: + if self.whitelist.has_key(service): + self.serviceMethodWrapper(service, self.removeServiceFromList, self.whitelist) + #self.deleteWhitelistService(service) else: # blacklist - if service not in self.blacklist: - self.addBlacklistService(service) + if not self.blacklist.has_key(service): + self.serviceMethodWrapper(service, self.addServiceToList, self.blacklist) + #self.addBlacklistService(service) #print "whitelist:", self.whitelist #print "blacklist:", self.blacklist - def unProtectService(self, service): #print "unprotect" #print "config.ParentalControl.type.value:", config.ParentalControl.type.value - if config.ParentalControl.type.value == "whitelist": - if service not in self.whitelist: - self.addWhitelistService(service) + if config.ParentalControl.type.value == LIST_WHITELIST: + if not self.whitelist.has_key(service): + self.serviceMethodWrapper(service, self.addServiceToList, self.whitelist) + #self.addWhitelistService(service) else: # blacklist - if service in self.blacklist: - self.deleteBlacklistService(service) + if self.blacklist.has_key(service): + self.serviceMethodWrapper(service, self.removeServiceFromList, self.blacklist) + #self.deleteBlacklistService(service) #print "whitelist:", self.whitelist #print "blacklist:", self.blacklist def getProtectionLevel(self, service): - if (config.ParentalControl.type.value == "whitelist" and service not in self.whitelist) or (config.ParentalControl.type.value == "blacklist" and service in self.blacklist): + if (config.ParentalControl.type.value == LIST_WHITELIST and not self.whitelist.has_key(service)) or (config.ParentalControl.type.value == LIST_BLACKLIST and self.blacklist.has_key(service)): if self.serviceLevel.has_key(service): return self.serviceLevel[service] else: return 0 else: return -1 + + def getProtectionType(self, service): + #New method used in ParentalControlList: This method does not only return + #if a service is protected or not, it also returns, why (whitelist or blacklist, service or bouquet) + if self.filesOpened == False: + self.open() + sImage = "" + if (config.ParentalControl.type.value == LIST_WHITELIST): + if self.whitelist.has_key(service): + if TYPE_SERVICE in self.whitelist[service]: + sImage = IMG_WHITESERVICE + else: + sImage = IMG_WHITEBOUQUET + elif (config.ParentalControl.type.value == LIST_BLACKLIST): + if self.blacklist.has_key(service): + if TYPE_SERVICE in self.blacklist[service]: + sImage = IMG_BLACKSERVICE + else: + sImage = IMG_BLACKBOUQUET + bLocked = self.getProtectionLevel(service) != -1 + return (bLocked,sImage) + + def getConfigValues(self): + #Read all values from configuration + self.checkPinInterval = False + self.checkPinIntervalCancel = False + self.checkSessionPin = False + self.checkSessionPinCancel = False + + self.sessionPinCached = False + self.pinIntervalSeconds = 0 + self.pinIntervalSecondsCancel = 0 + + self.storeServicePin = config.ParentalControl.storeservicepin.value + self.storeServicePinCancel = config.ParentalControl.storeservicepincancel.value + + if self.storeServicePin == "never": + pass + elif self.storeServicePin == "standby": + self.checkSessionPin = True + else: + self.checkPinInterval = True + iMinutes = float(self.storeServicePin) + iSeconds = iMinutes*60 + self.pinIntervalSeconds = iSeconds + + if self.storeServicePinCancel == "never": + pass + elif self.storeServicePinCancel == "standby": + self.checkSessionPinCancel = True + else: + self.checkPinIntervalCancel = True + iMinutes = float(self.storeServicePinCancel) + iSeconds = iMinutes*60 + self.pinIntervalSecondsCancel = iSeconds + self.configInitialized = True + # Reset PIN cache on standby: Use StandbyCounter- Config- Callback + config.misc.standbyCounter.addNotifier(self.standbyCounterCallback, initial_call = False) + + def standbyCounterCallback(self, configElement): + self.resetSessionPin() + + def resetSessionPin(self): + #Reset the session pin, stop the timer + self.sessionPinCached = False + self.sessionPinTimer.stop() + + def getCurrentTimeStamp(self): + return time.time() + def getPinList(self): return [ x.value for x in config.ParentalControl.servicepin ] - + def servicePinEntered(self, service, result): -# levelNeeded = 0 - #if self.serviceLevel.has_key(service): - #levelNeeded = self.serviceLevel[service] -# - #print "getPinList():", self.getPinList() - #pinList = self.getPinList()[:levelNeeded + 1] - #print "pinList:", pinList -# -# print "pin entered for service", service, "and pin was", pin - #if pin is not None and int(pin) in pinList: + if result is not None and result: - #print "pin ok, playing service" + #This is the new function of caching the service pin + #save last session and time of last entered pin... + if self.checkSessionPin == True: + self.sessionPinCached = True + self.sessionPinCachedValue = True + if self.checkPinInterval == True: + self.sessionPinCached = True + self.sessionPinCachedValue = True + self.sessionPinTimer.start(self.pinIntervalSeconds*1000,1) self.callback(ref = service) else: + #This is the new function of caching cancelling of service pin if result is not None: Notifications.AddNotification(MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR) - #print "wrong pin entered" + else: + if self.checkSessionPinCancel == True: + self.sessionPinCached = True + self.sessionPinCachedValue = False + if self.checkPinIntervalCancel == True: + self.sessionPinCached = True + self.sessionPinCachedValue = False + self.sessionPinTimer.start(self.pinIntervalSecondsCancel*1000,1) - def saveWhitelist(self): - file = open(resolveFilename(SCOPE_CONFIG, "whitelist"), 'w') - for x in self.whitelist: - file.write(x + "\n") - file.close - - def openWhitelist(self): - self.whitelist = [] - try: - file = open(resolveFilename(SCOPE_CONFIG, "whitelist"), 'r') - lines = file.readlines() - for x in lines: - ref = ServiceReference(x.strip()) - self.whitelist.append(str(ref)) - file.close - except: - pass - - def saveBlacklist(self): - file = open(resolveFilename(SCOPE_CONFIG, "blacklist"), 'w') - for x in self.blacklist: - file.write(x + "\n") + def saveListToFile(self,sWhichList): + #Replaces saveWhiteList and saveBlackList: + #I don't like to have two functions with identical code... + if sWhichList == LIST_BLACKLIST: + vList = self.blacklist + else: + vList = self.whitelist + file = open(resolveFilename(SCOPE_CONFIG, sWhichList), 'w') + for sService,sType in vList.iteritems(): + #Only Services that are selected directly and Bouqets are saved. + #Services that are added by a bouquet are not saved. + #This is the reason for the change in self.whitelist and self.blacklist + if TYPE_SERVICE in sType or TYPE_BOUQUET in sType: + file.write(str(sService) + "\n") file.close - def openBlacklist(self): - self.blacklist = [] + def openListFromFile(self,sWhichList): + #Replaces openWhiteList and openBlackList: + #I don't like to have two functions with identical code... + if sWhichList == LIST_BLACKLIST: + self.blacklist = {} + vList = self.blacklist + else: + self.whitelist = {} + vList = self.whitelist try: - file = open(resolveFilename(SCOPE_CONFIG, "blacklist"), 'r') + file = open(resolveFilename(SCOPE_CONFIG, sWhichList ), 'r') lines = file.readlines() for x in lines: - ref = ServiceReference(x.strip()) - self.blacklist.append(str(ref)) + sPlain = x.strip() + self.serviceMethodWrapper(sPlain, self.addServiceToList, vList) file.close except: pass + + def addServiceToList(self, service, type, vList): + #Replaces addWhitelistService and addBlacklistService + #The lists are not only lists of service references any more. + #They are named lists with the service as key and an array of types as value: + + if vList.has_key(service): + if not type in vList[service]: + vList[service].append(type) + else: + vList[service] = [type] + + def removeServiceFromList(self, service, type, vList): + #Replaces deleteWhitelistService and deleteBlacklistService + if vList.has_key(service): + if type in vList[service]: + vList[service].remove(type) + if not vList[service]: + del vList[service] + if self.serviceLevel.has_key(service): + self.serviceLevel.remove(service) + + def readServicesFromBouquet(self,sBouquetSelection,formatstring): + #This method gives back a list of services for a given bouquet + from enigma import eServiceCenter, eServiceReference + from Screens.ChannelSelection import service_types_tv + serviceHandler = eServiceCenter.getInstance() + refstr = sBouquetSelection + root = eServiceReference(refstr) + list = serviceHandler.list(root) + if list is not None: + services = list.getContent("CN", True) #(servicecomparestring, name) + return services def save(self): - self.saveBlacklist() - self.saveWhitelist() + self.saveListToFile(LIST_BLACKLIST) + self.saveListToFile(LIST_WHITELIST) def open(self): - self.openBlacklist() - self.openWhitelist() + self.openListFromFile(LIST_BLACKLIST) + self.openListFromFile(LIST_WHITELIST) + self.filesOpened = True parentalControl = ParentalControl() diff --git a/lib/python/Components/ParentalControlList.py b/lib/python/Components/ParentalControlList.py index 128e6d3e..797ea391 100644 --- a/lib/python/Components/ParentalControlList.py +++ b/lib/python/Components/ParentalControlList.py @@ -1,19 +1,28 @@ from MenuList import MenuList -from Components.ParentalControl import parentalControl +from Components.ParentalControl import parentalControl, IMG_WHITESERVICE, IMG_WHITEBOUQUET, IMG_BLACKSERVICE, IMG_BLACKBOUQUET from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT from Tools.LoadPixmap import LoadPixmap -lockPicture = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock.png")) +#Now there is a list of pictures instead of one... +entryPicture = {} -def ParentalControlEntryComponent(service, name, locked = True): +entryPicture[IMG_BLACKSERVICE] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock.png")) +entryPicture[IMG_BLACKBOUQUET] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lockBouquet.png")) +entryPicture[IMG_WHITESERVICE] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/unlock.png")) +entryPicture[IMG_WHITEBOUQUET] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/unlockBouquet.png")) + +def ParentalControlEntryComponent(service, name, protectionType): + locked = protectionType[0] + sImage = protectionType[1] res = [ (service, name, locked), (eListboxPythonMultiContent.TYPE_TEXT, 80, 5, 300, 50, 0, RT_HALIGN_LEFT, name) ] - if locked: - res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 0, 0, 32, 32, lockPicture)) + #Changed logic: The image is defined by sImage, not by locked anymore + if sImage != "": + res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 0, 0, 32, 32, entryPicture[sImage])) return res class ParentalControlList(MenuList): @@ -25,9 +34,11 @@ class ParentalControlList(MenuList): def toggleSelectedLock(self): print "self.l.getCurrentSelection():", self.l.getCurrentSelection() print "self.l.getCurrentSelectionIndex():", self.l.getCurrentSelectionIndex() - self.list[self.l.getCurrentSelectionIndex()] = ParentalControlEntryComponent(self.l.getCurrentSelection()[0][0], self.l.getCurrentSelection()[0][1], not self.l.getCurrentSelection()[0][2]); - if self.l.getCurrentSelection()[0][2]: - parentalControl.protectService(self.l.getCurrentSelection()[0][0]) + curSel = self.l.getCurrentSelection() + if curSel[0][2]: + parentalControl.unProtectService(self.l.getCurrentSelection()[0][0]) else: - parentalControl.unProtectService(self.l.getCurrentSelection()[0][0]) + parentalControl.protectService(self.l.getCurrentSelection()[0][0]) + #Instead of just negating the locked- flag, now I call the getProtectionType every time... + self.list[self.l.getCurrentSelectionIndex()] = ParentalControlEntryComponent(curSel[0][0], curSel[0][1], parentalControl.getProtectionType(curSel[0][0])) self.l.setList(self.list) diff --git a/lib/python/Screens/ParentalControlSetup.py b/lib/python/Screens/ParentalControlSetup.py old mode 100755 new mode 100644 index a123d2d3..2bf4841e --- a/lib/python/Screens/ParentalControlSetup.py +++ b/lib/python/Screens/ParentalControlSetup.py @@ -16,7 +16,7 @@ from operator import itemgetter class ProtectedScreen: def __init__(self): if self.isProtected(): - self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.protectedWithPin()], triesEntry = self.getTriesEntry(), title = self.getPinText(), windowTitle = _("Change pin code"))) + self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.protectedWithPin()], triesEntry = self.getTriesEntry(), title = self.getPinText(), windowTitle = _("Enter pin code"))) def getTriesEntry(self): return config.ParentalControl.retries.setuppin @@ -48,11 +48,11 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen): self.list = [] ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry) self.createSetup() - + self["actions"] = NumberActionMap(["SetupActions"], { - "cancel": self.keyCancel, - "save": self.keyCancel + "cancel": self.keyCancel, + "save": self.keyCancel }, -2) self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("OK")) @@ -63,12 +63,12 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen): def isProtected(self): return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value - + def createSetup(self): self.editListEntry = None self.changePin = None self.changeSetupPin = None - + self.list = [] self.list.append(getConfigListEntry(_("Enable parental control"), config.ParentalControl.configured)) print "config.ParentalControl.configured.value", config.ParentalControl.configured.value @@ -87,10 +87,19 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen): elif config.ParentalControl.mode.value == "simple": self.changePin = getConfigListEntry(_("Change service pin"), NoSave(ConfigNothing())) self.list.append(self.changePin) - #self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin)) + #Added Option to remember the service pin + self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin)) + #Added Option to remember the cancellation of service pin entry + self.list.append(getConfigListEntry(_("Remember service pin cancel"), config.ParentalControl.storeservicepincancel)) self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing())) self.list.append(self.editListEntry) - + #New funtion: Possibility to add Bouquets to whitelist / blacklist + self.editBouquetListEntry = getConfigListEntry(_("Edit bouquets list"), NoSave(ConfigNothing())) + self.list.append(self.editBouquetListEntry) + #New option to reload service lists (for example if bouquets have changed) + self.reloadLists = getConfigListEntry(_("Reload Black-/Whitelists"), NoSave(ConfigNothing())) + self.list.append(self.reloadLists) + self["config"].list = self.list self["config"].setList(self.list) @@ -98,6 +107,8 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen): print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection() if self["config"].l.getCurrentSelection() == self.editListEntry: self.session.open(ParentalControlEditor) + elif self["config"].l.getCurrentSelection() == self.editBouquetListEntry: + self.session.open(ParentalControlBouquetEditor) elif self["config"].l.getCurrentSelection() == self.changePin: if config.ParentalControl.mode.value == "complex": pass @@ -105,6 +116,8 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen): self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin")) elif self["config"].l.getCurrentSelection() == self.changeSetupPin: self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin")) + elif self["config"].l.getCurrentSelection() == self.reloadLists: + parentalControl.open() else: ConfigListScreen.keyRight(self) print "current selection:", self["config"].l.getCurrentSelection() @@ -149,6 +162,7 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen): def keyNumberGlobal(self, number): pass + # for summary: def changedEntry(self): for x in self.onChangedEntry: @@ -224,13 +238,13 @@ class ParentalControlEditor(Screen): if not self.servicesList.has_key(key): self.servicesList[key] = [] self.servicesList[key].append(s) - + def chooseLetter(self): print "choose letter" mylist = [] for x in self.servicesList.keys(): if x == chr(SPECIAL_CHAR): - x = ("special characters", x) + x = (_("special characters"), x) else: x = (x, x) mylist.append(x) @@ -242,12 +256,51 @@ class ParentalControlEditor(Screen): if result is not None: print "result:", result self.currentLetter = result[1] - self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1) for x in self.servicesList[result[1]]] + #Replace getProtectionLevel by new getProtectionType + self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.servicesList[result[1]]] self.servicelist.setList(self.list) else: parentalControl.save() self.close() +class ParentalControlBouquetEditor(Screen): + #This new class allows adding complete bouquets to black- and whitelists + #The servicereference that is stored for bouquets is their refstr as listed in bouquets.tv + def __init__(self, session): + Screen.__init__(self, session) + self.skinName = "ParentalControlEditor" + self.list = [] + self.bouquetslist = ParentalControlList(self.list) + self["servicelist"] = self.bouquetslist; + self.readBouquetList() + self.onLayoutFinish.append(self.selectBouquet) + + self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"], + { + "ok": self.select, + "cancel": self.cancel + }, -1) + + def cancel(self): + parentalControl.save() + self.close() + + def select(self): + self.bouquetslist.toggleSelectedLock() + + def readBouquetList(self): + serviceHandler = eServiceCenter.getInstance() + refstr = '1:134:1:0:0:0:0:0:0:0:FROM BOUQUET \"bouquets.tv\" ORDER BY bouquet' + bouquetroot = eServiceReference(refstr) + self.bouquetlist = {} + list = serviceHandler.list(bouquetroot) + if list is not None: + self.bouquetlist = list.getContent("CN", True) + + def selectBouquet(self): + self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.bouquetlist] + self.bouquetslist.setList(self.list) + class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen): def __init__(self, session, pin, pinname): Screen.__init__(self, session) @@ -264,12 +317,12 @@ class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen): self.pin2.addEndNotifier(boundFunction(self.valueChanged, 2)) self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1))) self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2))) - ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry) + ConfigListScreen.__init__(self, self.list) # print "old pin:", pin #if pin.value != "aaaa": #self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.pin.value], title = _("please enter the old pin"), windowTitle = _("Change pin code"))) ProtectedScreen.__init__(self) - + self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"], { "cancel": self.cancel, -- 2.30.2