parental locking fixes
[vuplus_dvbapp] / lib / python / Screens / ParentalControlSetup.py
index 780114b..c0561b5 100644 (file)
@@ -9,17 +9,18 @@ from Screens.ChoiceBox import ChoiceBox
 from Screens.MessageBox import MessageBox
 from Screens.InputBox import InputBox, Input, PinInput
 from Screens.ChannelSelection import service_types_tv
-from Tools.Directories import resolveFilename, SCOPE_CONFIG
 from Tools.BoundFunction import boundFunction
 from ServiceReference import ServiceReference
 from enigma import eServiceCenter, eServiceReference, eTimer
-import os
-import operator
+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()], 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 = _("Change pin code")))
+
+       def getTriesEntry(self):
+               return config.ParentalControl.retries.setuppin
 
        def getPinText(self):
                return _("Please enter the correct pin code")
@@ -31,10 +32,9 @@ class ProtectedScreen:
                return config.ParentalControl.setuppin.value
 
        def pinEntered(self, result):
-               if result[0] is None:
+               if result is None:
                        self.close()
-               if not result[0]:
-                       print result, "-", self.protectedWithPin()
+               elif not result:
                        self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
 
 class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
@@ -51,7 +51,7 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
                }, -2)
 
        def isProtected(self):
-               return config.ParentalControl.setuppinactive.value
+               return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value
        
        def createSetup(self):
                self.editListEntry = None
@@ -76,7 +76,7 @@ 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)) 
+                               #self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin))        
                                self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
                                self.list.append(self.editListEntry)
                                
@@ -109,16 +109,38 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
                print "current selection:", self["config"].l.getCurrentSelection()
                self.createSetup()
 
+       def SetupPinMessageCallback(self, value):
+               if value:
+                       self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
+               else:
+                       config.ParentalControl.setuppinactive.value = False
+                       self.keyCancel()
+
+       def ServicePinMessageCallback(self, value):
+               if value:
+                       self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
+               else:
+                       config.ParentalControl.servicepinactive.value = False
+                       self.keyCancel()
+
+       def cancelCB(self,value):
+               self.keyCancel()
+
        def keyCancel(self):
-               for x in self["config"].list:
-                       x[1].save()
-               self.close()
+               if config.ParentalControl.setuppinactive.value and config.ParentalControl.setuppin.value == 'aaaa':
+                       self.session.openWithCallback(self.SetupPinMessageCallback, MessageBox, _("No valid setup PIN found!\nDo you like to change the setup PIN now?\nWhen you say 'No' here the setup protection stay disabled!"), MessageBox.TYPE_YESNO)
+               elif config.ParentalControl.servicepinactive.value and config.ParentalControl.servicepin[0].value == 'aaaa':
+                       self.session.openWithCallback(self.ServicePinMessageCallback, MessageBox, _("No valid service PIN found!\nDo you like to change the service PIN now?\nWhen you say 'No' here the service protection stay disabled!"), MessageBox.TYPE_YESNO)
+               else:
+                       for x in self["config"].list:
+                               x[1].save()
+                       self.close()
 
        def keyNumberGlobal(self, number):
                pass
 
+SPECIAL_CHAR = 96
 class ParentalControlEditor(Screen):
-       SPECIAL_CHAR = 96
        def __init__(self, session):
                Screen.__init__(self, session)
                self.list = []
@@ -170,10 +192,7 @@ class ParentalControlEditor(Screen):
                if list is not None:
                        services = list.getContent("CN", True) #(servicecomparestring, name)
                        for s in services:
-                               if s[1][0]=='\xc2' and s[1][1]=='\x86': # ignore shortname brackets
-                                       key = s[1].lower()[2]
-                               else:
-                                       key = s[1].lower()[0]
+                               key = s[1].lower()[0]
                                if key < 'a' or key > 'z':
                                        key = chr(SPECIAL_CHAR)
                                #key = str(key)
@@ -190,7 +209,7 @@ class ParentalControlEditor(Screen):
                        else:
                                x = (x, x)
                        mylist.append(x)
-               mylist.sort(key=operator.itemgetter(1))
+               mylist.sort(key=itemgetter(1))
                sel = ord(self.currentLetter) - SPECIAL_CHAR
                self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=mylist, keys = [], selection = sel)