when in expert mode, add 'restart from begin' as choice on leave movie player dialog
[enigma2.git] / lib / python / Screens / ParentalControlSetup.py
index a8fdcc5fb5f67282d6fdc9d2db7af2c51fa6bd1f..f5f48e250f66d9e510de4dc205306396d111f88d 100644 (file)
@@ -1,58 +1,55 @@
 from Screen import Screen
 from Screen import Screen
-from Components.ConfigList import ConfigList, ConfigListScreen
+from Components.ConfigList import ConfigListScreen
 from Components.ActionMap import NumberActionMap
 from Components.config import config, getConfigListEntry, ConfigNothing, NoSave, ConfigPIN
 from Components.ActionMap import NumberActionMap
 from Components.config import config, getConfigListEntry, ConfigNothing, NoSave, ConfigPIN
-from Components.ServiceList import ServiceList
 from Components.ParentalControlList import ParentalControlEntryComponent, ParentalControlList 
 from Components.ParentalControl import parentalControl
 from Screens.ChoiceBox import ChoiceBox
 from Screens.MessageBox import MessageBox
 from Components.ParentalControlList import ParentalControlEntryComponent, ParentalControlList 
 from Components.ParentalControl import parentalControl
 from Screens.ChoiceBox import ChoiceBox
 from Screens.MessageBox import MessageBox
-from Screens.InputBox import InputBox, Input, PinInput
-from Tools.Directories import resolveFilename, SCOPE_CONFIG
+from Screens.InputBox import PinInput
+from Screens.ChannelSelection import service_types_tv
 from Tools.BoundFunction import boundFunction
 from Tools.BoundFunction import boundFunction
-from ServiceReference import ServiceReference
-from enigma import eServiceCenter, eServiceReference
-import os
-import operator
+from enigma import eServiceCenter, eTimer, eServiceReference
+from operator import itemgetter
 
 class ProtectedScreen:
        def __init__(self):
                if self.isProtected():
 
 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")
 
        def getPinText(self):
                return _("Please enter the correct pin code")
-       
+
        def isProtected(self):
                return True
        def isProtected(self):
                return True
-       
+
        def protectedWithPin(self):
                return config.ParentalControl.setuppin.value
        def protectedWithPin(self):
                return config.ParentalControl.setuppin.value
-       
+
        def pinEntered(self, result):
        def pinEntered(self, result):
-               if result[0] is None:
+               if result is None:
                        self.close()
                        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):
        def __init__(self, session):
                Screen.__init__(self, session)
                        self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
 
 class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
        def __init__(self, session):
                Screen.__init__(self, session)
-               
                ProtectedScreen.__init__(self)
                ProtectedScreen.__init__(self)
+               self.list = []
+               ConfigListScreen.__init__(self, self.list)
+               self.createSetup()
                
                self["actions"] = NumberActionMap(["SetupActions"],
                {
                        "cancel": self.keyCancel
                }, -2)
                
                self["actions"] = NumberActionMap(["SetupActions"],
                {
                        "cancel": self.keyCancel
                }, -2)
-               
-               self.list = []
-               ConfigListScreen.__init__(self, self.list)
-               self.createSetup()
-       
+
        def isProtected(self):
        def isProtected(self):
-               return config.ParentalControl.setuppinactive.value
+               return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value
        
        def createSetup(self):
                self.editListEntry = None
        
        def createSetup(self):
                self.editListEntry = None
@@ -77,13 +74,13 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
                                elif config.ParentalControl.mode.value == "simple":     
                                        self.changePin = getConfigListEntry(_("Change service pin"), NoSave(ConfigNothing()))
                                        self.list.append(self.changePin)
                                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)
                                
                self["config"].list = self.list
                self["config"].setList(self.list)
                                self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
                                self.list.append(self.editListEntry)
                                
                self["config"].list = self.list
                self["config"].setList(self.list)
-               
+
        def keyOK(self):
                print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
                if self["config"].l.getCurrentSelection() == self.editListEntry:
        def keyOK(self):
                print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
                if self["config"].l.getCurrentSelection() == self.editListEntry:
@@ -99,43 +96,65 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
                        ConfigListScreen.keyRight(self)
                        print "current selection:", self["config"].l.getCurrentSelection()
                        self.createSetup()
                        ConfigListScreen.keyRight(self)
                        print "current selection:", self["config"].l.getCurrentSelection()
                        self.createSetup()
-                       
+
        def keyLeft(self):
                ConfigListScreen.keyLeft(self)
                print "current selection:", self["config"].l.getCurrentSelection()
        def keyLeft(self):
                ConfigListScreen.keyLeft(self)
                print "current selection:", self["config"].l.getCurrentSelection()
-               self.createSetup()              
-                       
+               self.createSetup()
+
        def keyRight(self):
                ConfigListScreen.keyRight(self)
                print "current selection:", self["config"].l.getCurrentSelection()
                self.createSetup()
        def keyRight(self):
                ConfigListScreen.keyRight(self)
                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):
        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
 
        def keyNumberGlobal(self, number):
                pass
 
+SPECIAL_CHAR = 96
 class ParentalControlEditor(Screen):
        def __init__(self, session):
                Screen.__init__(self, session)
 class ParentalControlEditor(Screen):
        def __init__(self, session):
                Screen.__init__(self, session)
-
                self.list = []
                self.servicelist = ParentalControlList(self.list)
                self["servicelist"] = self.servicelist;
                self.list = []
                self.servicelist = ParentalControlList(self.list)
                self["servicelist"] = self.servicelist;
-               
                #self.onShown.append(self.chooseLetter)
                #self.onShown.append(self.chooseLetter)
-               self.currentLetter = ''
-               
+               self.currentLetter = chr(SPECIAL_CHAR)
                self.readServiceList()
                self.readServiceList()
-               
+               self.chooseLetterTimer = eTimer()
+               self.chooseLetterTimer.timeout.get().append(self.chooseLetter)
+               self.onLayoutFinish.append(self.LayoutFinished)
+
                self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
                {
                        "ok": self.select,
                        "cancel": self.cancel,
                self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
                {
                        "ok": self.select,
                        "cancel": self.cancel,
-                       "red": self.chooseLetter,
                        #"left": self.keyLeft,
                        #"right": self.keyRight,
                        "1": self.keyNumberGlobal,
                        #"left": self.keyLeft,
                        #"right": self.keyRight,
                        "1": self.keyNumberGlobal,
@@ -149,52 +168,49 @@ class ParentalControlEditor(Screen):
                        "9": self.keyNumberGlobal,
                        "0": self.keyNumberGlobal
                }, -1)
                        "9": self.keyNumberGlobal,
                        "0": self.keyNumberGlobal
                }, -1)
-               
+
+       def LayoutFinished(self):
+               self.chooseLetterTimer.start(0, True)
+
        def cancel(self):
        def cancel(self):
-               parentalControl.save()
-               self.close()
-               
+               self.chooseLetter()
+
        def select(self):
                self.servicelist.toggleSelectedLock()
        def select(self):
                self.servicelist.toggleSelectedLock()
-       
+
        def keyNumberGlobal(self, number):
                pass
        def keyNumberGlobal(self, number):
                pass
-       
+
        def readServiceList(self):
                serviceHandler = eServiceCenter.getInstance()
        def readServiceList(self):
                serviceHandler = eServiceCenter.getInstance()
-               self.service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25)'
-               refstr = '%s ORDER BY name' % (self.service_types_tv)
+               refstr = '%s ORDER BY name' % (service_types_tv)
                self.root = eServiceReference(refstr)
                self.root = eServiceReference(refstr)
-               
                self.servicesList = {}
                self.servicesList = {}
-               
                list = serviceHandler.list(self.root)
                if list is not None:
                        services = list.getContent("CN", True) #(servicecomparestring, name)
                        for s in services:
                                key = s[1].lower()[0]
                                if key < 'a' or key > 'z':
                list = serviceHandler.list(self.root)
                if list is not None:
                        services = list.getContent("CN", True) #(servicecomparestring, name)
                        for s in services:
                                key = s[1].lower()[0]
                                if key < 'a' or key > 'z':
-                                       key = '&'
+                                       key = chr(SPECIAL_CHAR)
                                #key = str(key)
                                if not self.servicesList.has_key(key):
                                        self.servicesList[key] = []
                                self.servicesList[key].append(s)
 
                                #key = str(key)
                                if not self.servicesList.has_key(key):
                                        self.servicesList[key] = []
                                self.servicesList[key].append(s)
 
-               print self.servicesList
-
        def chooseLetter(self):
                print "choose letter"
        def chooseLetter(self):
                print "choose letter"
-               list = []
+               mylist = []
                for x in self.servicesList.keys():
                for x in self.servicesList.keys():
-                       if x == '&':
+                       if x == chr(SPECIAL_CHAR):
                                x = ("special characters", x)
                        else:
                                x = (x, x)
                                x = ("special characters", x)
                        else:
                                x = (x, x)
-                       list.append(x)
-               print "sorted list:", sorted(list, key=operator.itemgetter(1))
-               print self.servicesList.keys()
-               self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=list)
-               
+                       mylist.append(x)
+               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)
+
        def letterChosen(self, result):
                if result is not None:
                        print "result:", result
        def letterChosen(self, result):
                if result is not None:
                        print "result:", result
@@ -202,21 +218,23 @@ class ParentalControlEditor(Screen):
                        self.list = []
                        for x in self.servicesList[result[1]]:
                                self.list.append(ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1))
                        self.list = []
                        for x in self.servicesList[result[1]]:
                                self.list.append(ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1))
-                       self.servicelist.setList(self.list)                     
+                       self.servicelist.setList(self.list)
+               else:
+                       parentalControl.save()
+                       self.close()
 
 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
        def __init__(self, session, pin, pinname):
                Screen.__init__(self, session)
 
 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
        def __init__(self, session, pin, pinname):
                Screen.__init__(self, session)
-
                self.pin = pin
                self.pin = pin
-
                self.list = []
                self.pin1 = ConfigPIN(default = 1111, censor = "*")
                self.pin2 = ConfigPIN(default = 1112, censor = "*")
                self.list = []
                self.pin1 = ConfigPIN(default = 1111, censor = "*")
                self.pin2 = ConfigPIN(default = 1112, censor = "*")
+               self.pin1.addEndNotifier(boundFunction(self.valueChanged, 1))
+               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)
                self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1)))
                self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2)))
                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")))
 #              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")))
@@ -226,7 +244,13 @@ class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
                {
                        "cancel": self.cancel,
                }, -1)
                {
                        "cancel": self.cancel,
                }, -1)
-               
+
+       def valueChanged(self, pin, value):
+               if pin == 1:
+                       self["config"].setCurrentIndex(1)
+               elif pin == 2:
+                       self.keyOK()
+
        def getPinText(self):
                return _("Please enter the old pin code")
 
        def getPinText(self):
                return _("Please enter the old pin code")
 
@@ -235,14 +259,14 @@ class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
 
        def protectedWithPin(self):
                return self.pin.value
 
        def protectedWithPin(self):
                return self.pin.value
-               
+
 #      def pinEntered(self, result):
                #if result[0] is None:
                        #self.close()
                #if not result[0]:
                        #print result, "-", self.pin.value
                        #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
 #      def pinEntered(self, result):
                #if result[0] is None:
                        #self.close()
                #if not result[0]:
                        #print result, "-", self.pin.value
                        #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
-       
+
        def keyOK(self):
                if self.pin1.value == self.pin2.value:
                        self.pin.value = self.pin1.value
        def keyOK(self):
                if self.pin1.value == self.pin2.value:
                        self.pin.value = self.pin1.value
@@ -250,10 +274,10 @@ class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
                        self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
                else:
                        self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
                        self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
                else:
                        self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
-       
+
        def cancel(self):
                self.close(None)
        def cancel(self):
                self.close(None)
-       
+
        def keyNumberGlobal(self, number):
                ConfigListScreen.keyNumberGlobal(self, number)
        def keyNumberGlobal(self, number):
                ConfigListScreen.keyNumberGlobal(self, number)
-               
+