Add some parental control improvements (made by Tode)
[enigma2.git] / lib / python / Screens / ParentalControlSetup.py
index 6ae12cae88bce4a7c9206f49ac5d611d8c7aec7d..2bf4841e25efde3bdb2f229c5cc1635cb536d78e 100644 (file)
@@ -4,6 +4,7 @@ from Components.ActionMap import NumberActionMap
 from Components.config import config, getConfigListEntry, ConfigNothing, NoSave, ConfigPIN
 from Components.ParentalControlList import ParentalControlEntryComponent, ParentalControlList 
 from Components.ParentalControl import parentalControl
 from Components.config import config, getConfigListEntry, ConfigNothing, NoSave, ConfigPIN
 from Components.ParentalControlList import ParentalControlEntryComponent, ParentalControlList 
 from Components.ParentalControl import parentalControl
+from Components.Sources.StaticText import StaticText
 from Screens.ChoiceBox import ChoiceBox
 from Screens.MessageBox import MessageBox
 from Screens.InputBox import PinInput
 from Screens.ChoiceBox import ChoiceBox
 from Screens.MessageBox import MessageBox
 from Screens.InputBox import PinInput
@@ -15,7 +16,7 @@ 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()], triesEntry = self.getTriesEntry(), 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 = _("Enter pin code")))
 
        def getTriesEntry(self):
                return config.ParentalControl.retries.setuppin
 
        def getTriesEntry(self):
                return config.ParentalControl.retries.setuppin
@@ -39,14 +40,26 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
        def __init__(self, session):
                Screen.__init__(self, session)
                ProtectedScreen.__init__(self)
        def __init__(self, session):
                Screen.__init__(self, session)
                ProtectedScreen.__init__(self)
+               # for the skin: first try ParentalControlSetup, then Setup, this allows individual skinning
+               self.skinName = ["ParentalControlSetup", "Setup" ]
+               self.setup_title = _("Parental control setup")
+               self.onChangedEntry = [ ]
+
                self.list = []
                self.list = []
-               ConfigListScreen.__init__(self, self.list)
+               ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
                self.createSetup()
                
                self["actions"] = NumberActionMap(["SetupActions"],
                {
                self.createSetup()
                
                self["actions"] = NumberActionMap(["SetupActions"],
                {
-                       "cancel": self.keyCancel
+                 "cancel": self.keyCancel,
+                 "save": self.keyCancel
                }, -2)
                }, -2)
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("OK"))
+               self.onLayoutFinish.append(self.layoutFinished)
+
+       def layoutFinished(self):
+               self.setTitle(self.setup_title)
 
        def isProtected(self):
                return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value
 
        def isProtected(self):
                return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value
@@ -74,9 +87,18 @@ 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))        
+                               #Added Option to remember the service pin
+                               self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin)) 
+                               #Added Option to remember the cancellation of service pin entry
+                               self.list.append(getConfigListEntry(_("Remember service pin cancel"), config.ParentalControl.storeservicepincancel))    
                                self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
                                self.list.append(self.editListEntry)
                                self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
                                self.list.append(self.editListEntry)
+                               #New funtion: Possibility to add Bouquets to whitelist / blacklist
+                               self.editBouquetListEntry = getConfigListEntry(_("Edit bouquets list"), NoSave(ConfigNothing()))
+                               self.list.append(self.editBouquetListEntry)
+                               #New option to reload service lists (for example if bouquets have changed)
+                               self.reloadLists = getConfigListEntry(_("Reload Black-/Whitelists"), NoSave(ConfigNothing()))
+                               self.list.append(self.reloadLists)
                                
                self["config"].list = self.list
                self["config"].setList(self.list)
                                
                self["config"].list = self.list
                self["config"].setList(self.list)
@@ -85,6 +107,8 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
                print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
                if self["config"].l.getCurrentSelection() == self.editListEntry:
                        self.session.open(ParentalControlEditor)
                print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
                if self["config"].l.getCurrentSelection() == self.editListEntry:
                        self.session.open(ParentalControlEditor)
+               elif self["config"].l.getCurrentSelection() == self.editBouquetListEntry:
+                       self.session.open(ParentalControlBouquetEditor)
                elif self["config"].l.getCurrentSelection() == self.changePin:
                        if config.ParentalControl.mode.value == "complex":
                                pass
                elif self["config"].l.getCurrentSelection() == self.changePin:
                        if config.ParentalControl.mode.value == "complex":
                                pass
@@ -92,6 +116,8 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
                                self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
                elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
                        self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
                                self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
                elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
                        self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
+               elif self["config"].l.getCurrentSelection() == self.reloadLists:
+                       parentalControl.open()
                else:
                        ConfigListScreen.keyRight(self)
                        print "current selection:", self["config"].l.getCurrentSelection()
                else:
                        ConfigListScreen.keyRight(self)
                        print "current selection:", self["config"].l.getCurrentSelection()
@@ -137,6 +163,21 @@ class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
        def keyNumberGlobal(self, number):
                pass
 
        def keyNumberGlobal(self, number):
                pass
 
+       # for summary:
+       def changedEntry(self):
+               for x in self.onChangedEntry:
+                       x()
+
+       def getCurrentEntry(self):
+               return self["config"].getCurrent()[0]
+
+       def getCurrentValue(self):
+               return str(self["config"].getCurrent()[1].getText())
+
+       def createSummary(self):
+               from Screens.Setup import SetupSummary
+               return SetupSummary
+
 SPECIAL_CHAR = 96
 class ParentalControlEditor(Screen):
        def __init__(self, session):
 SPECIAL_CHAR = 96
 class ParentalControlEditor(Screen):
        def __init__(self, session):
@@ -197,13 +238,13 @@ class ParentalControlEditor(Screen):
                                if not self.servicesList.has_key(key):
                                        self.servicesList[key] = []
                                self.servicesList[key].append(s)
                                if not self.servicesList.has_key(key):
                                        self.servicesList[key] = []
                                self.servicesList[key].append(s)
-
+                       
        def chooseLetter(self):
                print "choose letter"
                mylist = []
                for x in self.servicesList.keys():
                        if x == chr(SPECIAL_CHAR):
        def chooseLetter(self):
                print "choose letter"
                mylist = []
                for x in self.servicesList.keys():
                        if x == chr(SPECIAL_CHAR):
-                               x = ("special characters", x)
+                               x = (_("special characters"), x)
                        else:
                                x = (x, x)
                        mylist.append(x)
                        else:
                                x = (x, x)
                        mylist.append(x)
@@ -215,17 +256,59 @@ class ParentalControlEditor(Screen):
                if result is not None:
                        print "result:", result
                        self.currentLetter = result[1]
                if result is not None:
                        print "result:", result
                        self.currentLetter = result[1]
-                       self.list = []
-                       for x in self.servicesList[result[1]]:
-                               self.list.append(ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1))
+                       #Replace getProtectionLevel by new getProtectionType
+                       self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.servicesList[result[1]]]
                        self.servicelist.setList(self.list)
                else:
                        parentalControl.save()
                        self.close()
 
                        self.servicelist.setList(self.list)
                else:
                        parentalControl.save()
                        self.close()
 
+class ParentalControlBouquetEditor(Screen):
+       #This new class allows adding complete bouquets to black- and whitelists
+       #The servicereference that is stored for bouquets is their refstr as listed in bouquets.tv
+       def __init__(self, session):
+               Screen.__init__(self, session)
+               self.skinName = "ParentalControlEditor"
+               self.list = []
+               self.bouquetslist = ParentalControlList(self.list)
+               self["servicelist"] = self.bouquetslist;
+               self.readBouquetList()
+               self.onLayoutFinish.append(self.selectBouquet)
+
+               self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
+               {
+                       "ok": self.select,
+                       "cancel": self.cancel
+               }, -1)
+
+       def cancel(self):
+               parentalControl.save()
+               self.close()
+
+       def select(self):
+               self.bouquetslist.toggleSelectedLock()
+
+       def readBouquetList(self):
+               serviceHandler = eServiceCenter.getInstance()
+               refstr = '1:134:1:0:0:0:0:0:0:0:FROM BOUQUET \"bouquets.tv\" ORDER BY bouquet'
+               bouquetroot = eServiceReference(refstr)
+               self.bouquetlist = {}
+               list = serviceHandler.list(bouquetroot)
+               if list is not None:
+                       self.bouquetlist = list.getContent("CN", True)
+       
+       def selectBouquet(self):
+               self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.bouquetlist]
+               self.bouquetslist.setList(self.list)
+
 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)
+               # for the skin: first try ParentalControlChangePin, then Setup, this allows individual skinning
+               self.skinName = ["ParentalControlChangePin", "Setup" ]
+               self.setup_title = _("Change pin code")
+               self.onChangedEntry = [ ]
+
                self.pin = pin
                self.list = []
                self.pin1 = ConfigPIN(default = 1111, censor = "*")
                self.pin = pin
                self.list = []
                self.pin1 = ConfigPIN(default = 1111, censor = "*")
@@ -243,7 +326,15 @@ class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
                self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
                {
                        "cancel": self.cancel,
                self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
                {
                        "cancel": self.cancel,
+                       "red": self.cancel,
+                       "save": self.keyOK,
                }, -1)
                }, -1)
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("OK"))
+               self.onLayoutFinish.append(self.layoutFinished)
+
+       def layoutFinished(self):
+               self.setTitle(self.setup_title)
 
        def valueChanged(self, pin, value):
                if pin == 1:
 
        def valueChanged(self, pin, value):
                if pin == 1:
@@ -281,3 +372,17 @@ class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
        def keyNumberGlobal(self, number):
                ConfigListScreen.keyNumberGlobal(self, number)
 
        def keyNumberGlobal(self, number):
                ConfigListScreen.keyNumberGlobal(self, number)
 
+       # for summary:
+       def changedEntry(self):
+               for x in self.onChangedEntry:
+                       x()
+
+       def getCurrentEntry(self):
+               return self["config"].getCurrent()[0]
+
+       def getCurrentValue(self):
+               return str(self["config"].getCurrent()[1].getText())
+
+       def createSummary(self):
+               from Screens.Setup import SetupSummary
+               return SetupSummary