fix linked tuners option in tuner config,
[enigma2.git] / lib / python / Components / ParentalControl.py
index 86f188a4ab51017e80a0f44b70cb72df9ced5686..bcd788d7b36eb614c6d75c74dc7d4222de0620c8 100644 (file)
@@ -1,4 +1,4 @@
-from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigYesNo, ConfigSubList
+from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigYesNo, ConfigSubList, ConfigInteger
 from Components.Input import Input
 from Screens.InputBox import InputBox, PinInput
 from Screens.MessageBox import MessageBox
 from Components.Input import Input
 from Screens.InputBox import InputBox, PinInput
 from Screens.MessageBox import MessageBox
@@ -16,6 +16,14 @@ def InitParentalControl():
        config.ParentalControl.setuppinactive = ConfigYesNo(default = False)
        config.ParentalControl.type = ConfigSelection(default = "blacklist", choices = [("whitelist", _("whitelist")), ("blacklist", _("blacklist"))])
        config.ParentalControl.setuppin = ConfigPIN(default = -1)
        config.ParentalControl.setuppinactive = ConfigYesNo(default = False)
        config.ParentalControl.type = ConfigSelection(default = "blacklist", choices = [("whitelist", _("whitelist")), ("blacklist", _("blacklist"))])
        config.ParentalControl.setuppin = ConfigPIN(default = -1)
+       
+       config.ParentalControl.retries = ConfigSubsection()
+       config.ParentalControl.retries.setuppin = ConfigSubsection()
+       config.ParentalControl.retries.setuppin.tries = ConfigInteger(default = 3)
+       config.ParentalControl.retries.setuppin.time = ConfigInteger(default = 3)       
+       config.ParentalControl.retries.servicepin = ConfigSubsection()
+       config.ParentalControl.retries.servicepin.tries = ConfigInteger(default = 3)
+       config.ParentalControl.retries.servicepin.time = ConfigInteger(default = 3)
 #      config.ParentalControl.configured = configElement("config.ParentalControl.configured", configSelection, 1, (("yes", _("yes")), ("no", _("no"))))
        #config.ParentalControl.mode = configElement("config.ParentalControl.mode", configSelection, 0, (("simple", _("simple")), ("complex", _("complex"))))
        #config.ParentalControl.storeservicepin = configElement("config.ParentalControl.storeservicepin", configSelection, 0, (("never", _("never")), ("5_minutes", _("5 minutes")), ("30_minutes", _("30 minutes")), ("60_minutes", _("60 minutes")), ("restart", _("until restart"))))
 #      config.ParentalControl.configured = configElement("config.ParentalControl.configured", configSelection, 1, (("yes", _("yes")), ("no", _("no"))))
        #config.ParentalControl.mode = configElement("config.ParentalControl.mode", configSelection, 0, (("simple", _("simple")), ("complex", _("complex"))))
        #config.ParentalControl.storeservicepin = configElement("config.ParentalControl.storeservicepin", configSelection, 0, (("never", _("never")), ("5_minutes", _("5 minutes")), ("30_minutes", _("30 minutes")), ("60_minutes", _("60 minutes")), ("restart", _("until restart"))))
@@ -34,29 +42,27 @@ class ParentalControl:
        def __init__(self):
                self.open()
                self.serviceLevel = {}
        def __init__(self):
                self.open()
                self.serviceLevel = {}
-               self.tries = 3
                
        def addWhitelistService(self, service):
                
        def addWhitelistService(self, service):
-               self.whitelist.append(service.toString())
+               self.whitelist.append(service)
        
        def addBlacklistService(self, service):
        
        def addBlacklistService(self, service):
-               self.blacklist.append(service.toString())
+               self.blacklist.append(service)
 
        def setServiceLevel(self, service, level):
 
        def setServiceLevel(self, service, level):
-               self.serviceLevel[service.toString()] = level
+               self.serviceLevel[service] = level
 
        def deleteWhitelistService(self, service):
 
        def deleteWhitelistService(self, service):
-               self.whitelist.remove(service.toString())
-               if self.serviceLevel.has_key(service.toString()):
-                       self.serviceLevel.remove(service.toString())
+               self.whitelist.remove(service)
+               if self.serviceLevel.has_key(service):
+                       self.serviceLevel.remove(service)
        
        def deleteBlacklistService(self, service):
        
        def deleteBlacklistService(self, service):
-               self.blacklist.remove(service.toString())
-               if self.serviceLevel.has_key(service.toString()):
-                       self.serviceLevel.remove(service.toString())
+               self.blacklist.remove(service)
+               if self.serviceLevel.has_key(service):
+                       self.serviceLevel.remove(service)
                                
                                
-       def isServicePlayable(self, serviceref, callback):
-               service = serviceref.toString()
+       def isServicePlayable(self, service, callback):
                if not config.ParentalControl.configured.value:
                        return True
                print "whitelist:", self.whitelist
                if not config.ParentalControl.configured.value:
                        return True
                print "whitelist:", self.whitelist
@@ -71,7 +77,7 @@ class ParentalControl:
                        if self.serviceLevel.has_key(service):
                                levelNeeded = self.serviceLevel[service]
                        pinList = self.getPinList()[:levelNeeded + 1]
                        if self.serviceLevel.has_key(service):
                                levelNeeded = self.serviceLevel[service]
                        pinList = self.getPinList()[:levelNeeded + 1]
-                       Notifications.AddNotificationWithCallback(boundFunction(self.servicePinEntered, service), PinInput, tries = self.tries, pinList = pinList, service = ServiceReference(service).getServiceName(), title = _("this service is protected by a parental control pin"), windowTitle = _("Parental control"))
+                       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"))
                        return False
                else:
                        return True
                        return False
                else:
                        return True
@@ -80,10 +86,10 @@ class ParentalControl:
                print "protect"
                print "config.ParentalControl.type.value:", config.ParentalControl.type.value
                if config.ParentalControl.type.value == "whitelist":
                print "protect"
                print "config.ParentalControl.type.value:", config.ParentalControl.type.value
                if config.ParentalControl.type.value == "whitelist":
-                       if service.toString() in self.whitelist:
+                       if service in self.whitelist:
                                self.deleteWhitelistService(service)
                else: # blacklist
                                self.deleteWhitelistService(service)
                else: # blacklist
-                       if service.toString() not in self.blacklist:
+                       if service not in self.blacklist:
                                self.addBlacklistService(service)
                print "whitelist:", self.whitelist
                print "blacklist:", self.blacklist
                                self.addBlacklistService(service)
                print "whitelist:", self.whitelist
                print "blacklist:", self.blacklist
@@ -93,18 +99,15 @@ class ParentalControl:
                print "unprotect"
                print "config.ParentalControl.type.value:", config.ParentalControl.type.value
                if config.ParentalControl.type.value == "whitelist":
                print "unprotect"
                print "config.ParentalControl.type.value:", config.ParentalControl.type.value
                if config.ParentalControl.type.value == "whitelist":
-                       if service.toString() not in self.whitelist:
+                       if service not in self.whitelist:
                                self.addWhitelistService(service)
                else: # blacklist
                                self.addWhitelistService(service)
                else: # blacklist
-                       if service.toString() in self.blacklist:
+                       if service in self.blacklist:
                                self.deleteBlacklistService(service)
                print "whitelist:", self.whitelist
                print "blacklist:", self.blacklist
 
                                self.deleteBlacklistService(service)
                print "whitelist:", self.whitelist
                print "blacklist:", self.blacklist
 
-
-               
-       def getProtectionLevel(self, serviceref):
-               service = serviceref.toString()
+       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 self.serviceLevel.has_key(service):
                                return self.serviceLevel[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 self.serviceLevel.has_key(service):
                                return self.serviceLevel[service]
@@ -130,13 +133,11 @@ class ParentalControl:
 #              
 #              print "pin entered for service", service, "and pin was", pin
                #if pin is not None and int(pin) in pinList:
 #              
 #              print "pin entered for service", service, "and pin was", pin
                #if pin is not None and int(pin) in pinList:
-               if result[0] is not None and result[0]:
+               if result is not None and result:
                        print "pin ok, playing service"
                        print "pin ok, playing service"
-                       self.tries = 3
                        self.callback(ref = ServiceReference(service).ref)
                else:
                        self.callback(ref = ServiceReference(service).ref)
                else:
-                       self.tries = result[1]
-                       if result[0] is not None:
+                       if result is not None:
                                Notifications.AddNotification(MessageBox,  _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
                        print "wrong pin entered"
                        
                                Notifications.AddNotification(MessageBox,  _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
                        print "wrong pin entered"