bug #238
[enigma2.git] / lib / python / Components / ParentalControl.py
old mode 100644 (file)
new mode 100755 (executable)
index bcd788d..d68e01f
@@ -1,6 +1,5 @@
 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigYesNo, ConfigSubList, ConfigInteger
-from Components.Input import Input
-from Screens.InputBox import InputBox, PinInput
+from Screens.InputBox import PinInput
 from Screens.MessageBox import MessageBox
 from Tools.BoundFunction import boundFunction
 from ServiceReference import ServiceReference
@@ -34,7 +33,7 @@ def InitParentalControl():
 
        config.ParentalControl.servicepin = ConfigSubList()
 
-       for i in range(3):
+       for i in (0, 1, 2):
                config.ParentalControl.servicepin.append(ConfigPIN(default = -1))
                #config.ParentalControl.servicepin.append(configElement("config.ParentalControl.servicepin.level" + str(i), configSequence, "0000", configSequenceArg().get("PINCODE", (4, ""))))
 
@@ -61,51 +60,52 @@ class ParentalControl:
                self.blacklist.remove(service)
                if self.serviceLevel.has_key(service):
                        self.serviceLevel.remove(service)
-                               
-       def isServicePlayable(self, service, callback):
-               if not config.ParentalControl.configured.value:
+
+       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:", service
+               #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()
+               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):
                        self.callback = callback
-                       print "service:", ServiceReference(service).getServiceName()
+                       #print "service:", ServiceReference(service).getServiceName()
                        levelNeeded = 0
                        if self.serviceLevel.has_key(service):
                                levelNeeded = self.serviceLevel[service]
                        pinList = self.getPinList()[:levelNeeded + 1]
-                       Notifications.AddNotificationWithCallback(boundFunction(self.servicePinEntered, service), PinInput, triesEntry = config.ParentalControl.retries.servicepin, pinList = pinList, service = ServiceReference(service).getServiceName(), title = _("this service is protected by a parental control pin"), windowTitle = _("Parental control"))
+                       Notifications.AddNotificationWithCallback(boundFunction(self.servicePinEntered, ref), PinInput, triesEntry = config.ParentalControl.retries.servicepin, pinList = pinList, service = ServiceReference(ref).getServiceName(), title = _("this service is protected by a parental control pin"), windowTitle = _("Parental control"))
                        return False
                else:
                        return True
                
        def protectService(self, service):
-               print "protect"
-               print "config.ParentalControl.type.value:", config.ParentalControl.type.value
+               #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)
                else: # blacklist
                        if service not in self.blacklist:
                                self.addBlacklistService(service)
-               print "whitelist:", self.whitelist
-               print "blacklist:", self.blacklist
+               #print "whitelist:", self.whitelist
+               #print "blacklist:", self.blacklist
 
                                
        def unProtectService(self, service):
-               print "unprotect"
-               print "config.ParentalControl.type.value:", config.ParentalControl.type.value
+               #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)
                else: # blacklist
                        if service in self.blacklist:
                                self.deleteBlacklistService(service)
-               print "whitelist:", self.whitelist
-               print "blacklist:", self.blacklist
+               #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):
@@ -117,10 +117,7 @@ class ParentalControl:
                        return -1
        
        def getPinList(self):
-               pinList = []
-               for x in config.ParentalControl.servicepin:
-                       pinList.append(x.value)
-               return pinList
+               return [ x.value for x in config.ParentalControl.servicepin ]
        
        def servicePinEntered(self, service, result):
 #              levelNeeded = 0
@@ -134,12 +131,12 @@ class ParentalControl:
 #              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"
-                       self.callback(ref = ServiceReference(service).ref)
+                       #print "pin ok, playing service"
+                       self.callback(ref = service)
                else:
                        if result is not None:
                                Notifications.AddNotification(MessageBox,  _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
-                       print "wrong pin entered"
+                       #print "wrong pin entered"
                        
        def saveWhitelist(self):
                file = open(resolveFilename(SCOPE_CONFIG, "whitelist"), 'w')
@@ -153,7 +150,8 @@ class ParentalControl:
                        file = open(resolveFilename(SCOPE_CONFIG, "whitelist"), 'r')
                        lines = file.readlines()
                        for x in lines:
-                               self.whitelist.append(x.strip())
+                               ref = ServiceReference(x.strip())
+                               self.whitelist.append(str(ref))
                        file.close
                except:
                        pass
@@ -170,7 +168,8 @@ class ParentalControl:
                        file = open(resolveFilename(SCOPE_CONFIG, "blacklist"), 'r')
                        lines = file.readlines()
                        for x in lines:
-                               self.blacklist.append(x.strip())
+                               ref = ServiceReference(x.strip())
+                               self.blacklist.append(str(ref))
                        file.close
                except:
                        pass
@@ -183,4 +182,4 @@ class ParentalControl:
                self.openBlacklist()
                self.openWhitelist()
 
-parentalControl = ParentalControl()
\ No newline at end of file
+parentalControl = ParentalControl()