needed update for avahi stuff
[enigma2.git] / lib / python / Components / ParentalControl.py
index f8a6dff25250626ed0071980fb683f7eaa9634c3..8c8a3305cc64c18217b12a8b7ac10ea6990cf5ce 100644 (file)
@@ -1,6 +1,5 @@
-from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigYesNo, ConfigSubList
-from Components.Input import Input
-from Screens.InputBox import InputBox, PinInput
+from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigYesNo, ConfigSubList, ConfigInteger
+from Screens.InputBox import PinInput
 from Screens.MessageBox import MessageBox
 from Tools.BoundFunction import boundFunction
 from ServiceReference import ServiceReference
@@ -16,6 +15,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.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"))))
@@ -34,75 +41,73 @@ class ParentalControl:
        def __init__(self):
                self.open()
                self.serviceLevel = {}
-               self.tries = 3
                
        def addWhitelistService(self, service):
-               self.whitelist.append(service.toCompareString())
+               self.whitelist.append(service)
        
        def addBlacklistService(self, service):
-               self.blacklist.append(service.toCompareString())
+               self.blacklist.append(service)
 
        def setServiceLevel(self, service, level):
-               self.serviceLevel[service.toCompareString()] = level
+               self.serviceLevel[service] = level
 
        def deleteWhitelistService(self, service):
-               self.whitelist.remove(service.toCompareString())
-               if self.serviceLevel.has_key(service.toCompareString()):
-                       self.serviceLevel.remove(service.toCompareString())
+               self.whitelist.remove(service)
+               if self.serviceLevel.has_key(service):
+                       self.serviceLevel.remove(service)
        
        def deleteBlacklistService(self, service):
-               self.blacklist.remove(service.toCompareString())
-               if self.serviceLevel.has_key(service.toCompareString()):
-                       self.serviceLevel.remove(service.toCompareString())
-                               
-       def isServicePlayable(self, serviceref, callback):
-               service = serviceref.toCompareString()
-               if not config.ParentalControl.configured.value:
+               self.blacklist.remove(service)
+               if self.serviceLevel.has_key(service):
+                       self.serviceLevel.remove(service)
+
+       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, 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, 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.toCompareString() in self.whitelist:
+                       if service in self.whitelist:
                                self.deleteWhitelistService(service)
                else: # blacklist
-                       if service.toCompareString() not in self.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.toCompareString() not in self.whitelist:
+                       if service not in self.whitelist:
                                self.addWhitelistService(service)
                else: # blacklist
-                       if service.toCompareString() in self.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, serviceref):
-               service = serviceref.toCompareString()
+       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]
@@ -128,15 +133,13 @@ class ParentalControl:
 #              
 #              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]:
-                       print "pin ok, playing service"
-                       self.tries = 3
-                       self.callback(ref = ServiceReference(service).ref)
+               if result is not None and result:
+                       #print "pin ok, playing service"
+                       self.callback(ref = service)
                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"
+                       #print "wrong pin entered"
                        
        def saveWhitelist(self):
                file = open(resolveFilename(SCOPE_CONFIG, "whitelist"), 'w')
@@ -150,7 +153,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
@@ -167,7 +171,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
@@ -180,4 +185,4 @@ class ParentalControl:
                self.openBlacklist()
                self.openWhitelist()
 
-parentalControl = ParentalControl()
\ No newline at end of file
+parentalControl = ParentalControl()