From: Stefan Pluecken Date: Tue, 10 Oct 2006 03:00:49 +0000 (+0000) Subject: add parental control (still somehow buggy and some minor features missing... don... X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=commitdiff_plain;h=01abec53c6856c24666967ee51d25d09fc6b8863 add parental control (still somehow buggy and some minor features missing... don't trust it yet to protect your children) --- diff --git a/Navigation.py b/Navigation.py index 7b615bb..9ba0afc 100644 --- a/Navigation.py +++ b/Navigation.py @@ -1,4 +1,6 @@ from enigma import * +from Components.ParentalControl import parentalControl +from Tools.BoundFunction import boundFunction import RecordTimer import NavigationInstance @@ -14,7 +16,7 @@ class Navigation: NavigationInstance.instance = self self.ServiceHandler = eServiceCenter.getInstance() - + import Navigation as Nav Nav.navcore = self @@ -25,13 +27,13 @@ class Navigation: self.currentlyPlayingService = None self.state = 0 self.RecordTimer = RecordTimer.RecordTimer() - + def callEvent(self, i): self.state = i != 1 for x in self.event: x(i) - def playService(self, ref): + def playService(self, ref, checkParentalControl = True): print "playing", ref and ref.toString() self.currentlyPlayingServiceReference = None self.currentlyPlayingService = None @@ -39,9 +41,12 @@ class Navigation: self.stopService() return 0 - if self.pnav and not self.pnav.playService(ref): - self.currentlyPlayingServiceReference = ref - return 0 + if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl = False)): + if self.pnav and not self.pnav.playService(ref): + self.currentlyPlayingServiceReference = ref + return 0 + else: + self.stopService() return 1 def getCurrentlyPlayingServiceReference(self): diff --git a/data/menu.xml b/data/menu.xml index ba1dbc5..40916f9 100644 --- a/data/menu.xml +++ b/data/menu.xml @@ -58,8 +58,10 @@ + + diff --git a/data/skin_default.xml b/data/skin_default.xml index 1733608..9b1e0b0 100644 --- a/data/skin_default.xml +++ b/data/skin_default.xml @@ -122,6 +122,12 @@ + + + + + + @@ -318,6 +324,16 @@ + + + + + + + + + + diff --git a/lib/python/Components/Input.py b/lib/python/Components/Input.py index 710ad0b..b30a74e 100644 --- a/lib/python/Components/Input.py +++ b/lib/python/Components/Input.py @@ -20,6 +20,9 @@ class Input(VariableText, HTMLComponent, GUIComponent, NumericalTextInput): self.currPos = 0 self.overwrite = 0 self.setText(text) + + def __len__(self): + return len(self.text) def update(self): self.setMarkedPos(self.currPos) diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am index 4aa6a29..05e15ad 100644 --- a/lib/python/Components/Makefile.am +++ b/lib/python/Components/Makefile.am @@ -16,4 +16,4 @@ install_PYTHON = \ PluginList.py PluginComponent.py RecordingConfig.py About.py UsageConfig.py \ FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py \ MultiContent.py MediaPlayer.py TunerInfo.py VideoWindow.py ChoiceList.py \ - Element.py Playlist.py + Element.py Playlist.py ParentalControl.py ParentalControlList.py diff --git a/lib/python/Components/ParentalControl.py b/lib/python/Components/ParentalControl.py new file mode 100644 index 0000000..86f188a --- /dev/null +++ b/lib/python/Components/ParentalControl.py @@ -0,0 +1,185 @@ +from Components.config import config, ConfigSubsection, ConfigSelection, ConfigPIN, ConfigYesNo, ConfigSubList +from Components.Input import Input +from Screens.InputBox import InputBox, PinInput +from Screens.MessageBox import MessageBox +from Tools.BoundFunction import boundFunction +from ServiceReference import ServiceReference +from Tools import Notifications +from Tools.Directories import resolveFilename, SCOPE_CONFIG + +def InitParentalControl(): + config.ParentalControl = ConfigSubsection() + config.ParentalControl.configured = ConfigYesNo(default = False) + config.ParentalControl.mode = ConfigSelection(default = "simple", choices = [("simple", _("simple")), ("complex", _("complex"))]) + config.ParentalControl.storeservicepin = ConfigSelection(default = "never", choices = [("never", _("never")), ("5_minutes", _("5 minutes")), ("30_minutes", _("30 minutes")), ("60_minutes", _("60 minutes")), ("restart", _("until restart"))]) + config.ParentalControl.servicepinactive = ConfigYesNo(default = False) + 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.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.servicepinactive = configElement("config.ParentalControl.servicepinactive", configSelection, 1, (("yes", _("yes")), ("no", _("no")))) + #config.ParentalControl.setuppinactive = configElement("config.ParentalControl.setuppinactive", configSelection, 1, (("yes", _("yes")), ("no", _("no")))) + #config.ParentalControl.type = configElement("config.ParentalControl.type", configSelection, 0, (("whitelist", _("whitelist")), ("blacklist", _("blacklist")))) + #config.ParentalControl.setuppin = configElement("config.ParentalControl.setuppin", configSequence, "0000", configSequenceArg().get("PINCODE", (4, ""))) + + config.ParentalControl.servicepin = ConfigSubList() + + for i in range(3): + config.ParentalControl.servicepin.append(ConfigPIN(default = -1)) + #config.ParentalControl.servicepin.append(configElement("config.ParentalControl.servicepin.level" + str(i), configSequence, "0000", configSequenceArg().get("PINCODE", (4, "")))) + +class ParentalControl: + def __init__(self): + self.open() + self.serviceLevel = {} + self.tries = 3 + + def addWhitelistService(self, service): + self.whitelist.append(service.toString()) + + def addBlacklistService(self, service): + self.blacklist.append(service.toString()) + + def setServiceLevel(self, service, level): + self.serviceLevel[service.toString()] = level + + def deleteWhitelistService(self, service): + self.whitelist.remove(service.toString()) + if self.serviceLevel.has_key(service.toString()): + self.serviceLevel.remove(service.toString()) + + def deleteBlacklistService(self, service): + self.blacklist.remove(service.toString()) + if self.serviceLevel.has_key(service.toString()): + self.serviceLevel.remove(service.toString()) + + def isServicePlayable(self, serviceref, callback): + service = serviceref.toString() + if not config.ParentalControl.configured.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 + 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() + 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")) + return False + else: + return True + + def protectService(self, service): + print "protect" + print "config.ParentalControl.type.value:", config.ParentalControl.type.value + if config.ParentalControl.type.value == "whitelist": + if service.toString() in self.whitelist: + self.deleteWhitelistService(service) + else: # blacklist + if service.toString() not in self.blacklist: + self.addBlacklistService(service) + print "whitelist:", self.whitelist + print "blacklist:", self.blacklist + + + def unProtectService(self, service): + print "unprotect" + print "config.ParentalControl.type.value:", config.ParentalControl.type.value + if config.ParentalControl.type.value == "whitelist": + if service.toString() not in self.whitelist: + self.addWhitelistService(service) + else: # blacklist + if service.toString() in self.blacklist: + self.deleteBlacklistService(service) + print "whitelist:", self.whitelist + print "blacklist:", self.blacklist + + + + def getProtectionLevel(self, serviceref): + service = serviceref.toString() + 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] + else: + return 0 + else: + return -1 + + def getPinList(self): + pinList = [] + for x in config.ParentalControl.servicepin: + pinList.append(x.value) + return pinList + + def servicePinEntered(self, service, result): +# levelNeeded = 0 + #if self.serviceLevel.has_key(service): + #levelNeeded = self.serviceLevel[service] +# + #print "getPinList():", self.getPinList() + #pinList = self.getPinList()[:levelNeeded + 1] + #print "pinList:", 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]: + print "pin ok, playing service" + self.tries = 3 + self.callback(ref = ServiceReference(service).ref) + else: + self.tries = result[1] + if result[0] is not None: + Notifications.AddNotification(MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR) + print "wrong pin entered" + + def saveWhitelist(self): + file = open(resolveFilename(SCOPE_CONFIG, "whitelist"), 'w') + for x in self.whitelist: + file.write(x + "\n") + file.close + + def openWhitelist(self): + self.whitelist = [] + try: + file = open(resolveFilename(SCOPE_CONFIG, "whitelist"), 'r') + lines = file.readlines() + for x in lines: + self.whitelist.append(x.strip()) + file.close + except: + pass + + def saveBlacklist(self): + file = open(resolveFilename(SCOPE_CONFIG, "blacklist"), 'w') + for x in self.blacklist: + file.write(x + "\n") + file.close + + def openBlacklist(self): + self.blacklist = [] + try: + file = open(resolveFilename(SCOPE_CONFIG, "blacklist"), 'r') + lines = file.readlines() + for x in lines: + self.blacklist.append(x.strip()) + file.close + except: + pass + + def save(self): + self.saveBlacklist() + self.saveWhitelist() + + def open(self): + self.openBlacklist() + self.openWhitelist() + +parentalControl = ParentalControl() \ No newline at end of file diff --git a/lib/python/Components/ParentalControlList.py b/lib/python/Components/ParentalControlList.py new file mode 100644 index 0000000..6315963 --- /dev/null +++ b/lib/python/Components/ParentalControlList.py @@ -0,0 +1,55 @@ +from HTMLComponent import * +from GUIComponent import * + +from MenuList import MenuList +from Components.ParentalControl import parentalControl +from Tools.Directories import * + +from enigma import * + +RT_HALIGN_LEFT = 0 +RT_HALIGN_RIGHT = 1 +RT_HALIGN_CENTER = 2 +RT_HALIGN_BLOCK = 4 + +RT_VALIGN_TOP = 0 +RT_VALIGN_CENTER = 8 +RT_VALIGN_BOTTOM = 16 + +lockPicture = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "lock-fs8.png")) + +def ParentalControlEntryComponent(service, name, locked = True): + res = [ (service, name, locked) ] + res.append((eListboxPythonMultiContent.TYPE_TEXT, 80, 5, 200, 50, 0, RT_HALIGN_LEFT, name)) + if locked: + res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 0, 0, 32, 32, lockPicture)) + + return res + +class ParentalControlList(MenuList, HTMLComponent, GUIComponent): + def __init__(self, list): + GUIComponent.__init__(self) + self.l = eListboxPythonMultiContent() + self.list = list + self.l.setList(list) + self.l.setFont(0, gFont("Regular", 20)) + + GUI_WIDGET = eListbox + + def setList(self, list): + self.list = list + self.l.setList(list) + + def postWidgetCreate(self, instance): + instance.setContent(self.l) + instance.setItemHeight(32) + + def toggleSelectedLock(self): + print "self.l.getCurrentSelection():", self.l.getCurrentSelection() + print "self.l.getCurrentSelectionIndex():", self.l.getCurrentSelectionIndex() + self.list[self.l.getCurrentSelectionIndex()] = ParentalControlEntryComponent(self.l.getCurrentSelection()[0][0], self.l.getCurrentSelection()[0][1], not self.l.getCurrentSelection()[0][2]); + if self.l.getCurrentSelection()[0][2]: + parentalControl.protectService(self.l.getCurrentSelection()[0][0]) + else: + parentalControl.unProtectService(self.l.getCurrentSelection()[0][0]) + self.l.setList(self.list) diff --git a/lib/python/Components/__init__.py b/lib/python/Components/__init__.py index c303c5a..f37827d 100644 --- a/lib/python/Components/__init__.py +++ b/lib/python/Components/__init__.py @@ -7,4 +7,5 @@ __all__ = ["ActionMap", "Button", "Clock", "ConfigList", "EventInfo", "InputDevice", "ServicePosition", "IPAddress", "VariableIP", "IPGateway", "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry", "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList", "TimerSanityCheck", - "FileList", "MultiContent", "TunerInfo", "ChoiceList", "Playlist" ] + "FileList", "MultiContent", "TunerInfo", "ChoiceList", "Playlist", + "ParentalControl" ] diff --git a/lib/python/Screens/ChannelSelection.py b/lib/python/Screens/ChannelSelection.py index 6c3abb5..58c57f4 100644 --- a/lib/python/Screens/ChannelSelection.py +++ b/lib/python/Screens/ChannelSelection.py @@ -11,8 +11,11 @@ from Tools.NumericalTextInput import NumericalTextInput from Components.NimManager import nimmanager from Components.Sources.Clock import Clock from Components.Input import Input -from Screens.InputBox import InputBox +from Components.ParentalControl import parentalControl +from Screens.InputBox import InputBox, PinInput +from Screens.MessageBox import MessageBox from ServiceReference import ServiceReference +from Tools.BoundFunction import boundFunction from re import * from os import remove @@ -75,6 +78,11 @@ class ChannelContextMenu(Screen): if not csel.bouquet_mark_edit and not csel.movemode: if not inBouquetRootList: if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory: + if config.ParentalControl.configured.value: + if parentalControl.getProtectionLevel(csel.getCurrentSelection()) == -1: + menu.append((_("add to parental protection"), boundFunction(self.addParentalProtection, csel.getCurrentSelection()))) + else: + menu.append((_("remove from parental protection"), boundFunction(self.removeParentalProtection, csel.getCurrentSelection()))) if haveBouquets: menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected)) else: @@ -130,6 +138,21 @@ class ChannelContextMenu(Screen): self.csel.addBouquet(bouquet, None) self.close() + def addParentalProtection(self, service): + parentalControl.protectService(service) + self.close() + + def removeParentalProtection(self, service): + self.session.openWithCallback(boundFunction(self.pinEntered, service), PinInput, pinList = [config.ParentalControl.servicepin[0].value], title = _("Enter the service pin"), windowTitle = _("Change pin code")) + + def pinEntered(self, service, result): + if result[0]: + parentalControl.unProtectService(service) + self.close() + else: + self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR) + + def addServiceToBouquetSelected(self): bouquets = self.csel.getBouquetList() if bouquets is None: diff --git a/lib/python/Screens/InputBox.py b/lib/python/Screens/InputBox.py index 558cbc0..e73215c 100644 --- a/lib/python/Screens/InputBox.py +++ b/lib/python/Screens/InputBox.py @@ -5,15 +5,17 @@ from Components.ActionMap import NumberActionMap from Components.Label import Label from Components.Input import Input from Components.GUIComponent import * +from Tools.BoundFunction import boundFunction import os class InputBox(Screen): - def __init__(self, session, title = "", **kwargs): + def __init__(self, session, title = "", windowTitle = _("Input"), **kwargs): Screen.__init__(self, session) self["text"] = Label(title) self["input"] = Input(**kwargs) + self.onShown.append(boundFunction(self.setTitle, windowTitle)) self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"], { @@ -85,3 +87,50 @@ class InputBox(Screen): def keyInsert(self): self["input"].toggleOverwrite() + +class PinInput(InputBox): + def __init__(self, session, service = "", tries = 1, pinList = [], *args, **kwargs): + InputBox.__init__(self, session = session, text="9876", maxSize=True, type=Input.PIN, *args, **kwargs) + + self.showTries = True + if tries == 1: + self.showTries = False + + self.pinList = pinList + self["service"] = Label(service) + + self["tries"] = Label("") + self.onShown.append(boundFunction(self.setTries, tries)) + + def keyNumberGlobal(self, number): + if self["input"].currPos == len(self["input"]) - 1: + InputBox.keyNumberGlobal(self, number) + self.go() + else: + InputBox.keyNumberGlobal(self, number) + + def checkPin(self, pin): + if pin is not None and int(pin) in self.pinList: + return True + return False + + def go(self): + if self.checkPin(self["input"].getText()): + self.close((True, self.tries)) + else: + self.keyHome() + self.setTries(self.tries - 1) + if self.tries == 0: + self.close((False, self.tries)) + else: + pass + + def cancel(self): + rcinput = eRCInput.getInstance() + rcinput.setKeyboardMode(rcinput.kmNone) + self.close((None, self.tries)) + + def setTries(self, tries): + self.tries = tries + if self.showTries: + self["tries"].setText(_("Tries left:") + " " + str(tries)) \ No newline at end of file diff --git a/lib/python/Screens/Makefile.am b/lib/python/Screens/Makefile.am index 0d253d5..4abfcd1 100644 --- a/lib/python/Screens/Makefile.am +++ b/lib/python/Screens/Makefile.am @@ -11,4 +11,4 @@ install_PYTHON = \ TutorialWizard.py PluginBrowser.py MinuteInput.py Scart.py PVRState.py \ Console.py InputBox.py ChoiceBox.py SimpleSummary.py ImageWizard.py \ MediaPlayer.py TimerSelection.py PictureInPicture.py TimeDateInput.py \ - SubtitleDisplay.py SubservicesQuickzap.py NumericalTextInputHelpDialog.py + SubtitleDisplay.py SubservicesQuickzap.py ParentalControlSetup.py NumericalTextInputHelpDialog.py diff --git a/lib/python/Screens/ParentalControlSetup.py b/lib/python/Screens/ParentalControlSetup.py new file mode 100644 index 0000000..2a90746 --- /dev/null +++ b/lib/python/Screens/ParentalControlSetup.py @@ -0,0 +1,264 @@ +from Screen import Screen +from Components.ConfigList import ConfigList, ConfigListScreen +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 Screens.InputBox import InputBox, Input, PinInput +from Tools.Directories import resolveFilename, SCOPE_CONFIG +from Tools.BoundFunction import boundFunction +from ServiceReference import ServiceReference +from enigma import eServiceCenter, eServiceReference +import os +import operator + +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"))) + + def getPinText(self): + return _("Please enter the correct pin code") + + def isProtected(self): + return True + + def protectedWithPin(self): + return config.ParentalControl.setuppin.value + + def pinEntered(self, result): + if result[0] is None: + self.close() + if not result[0]: + print result, "-", self.protectedWithPin() + 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) + + self["actions"] = NumberActionMap(["SetupActions"], + { + "cancel": self.keyCancel + }, -2) + + self.list = [] + ConfigListScreen.__init__(self, self.list) + self.createSetup() + + def isProtected(self): + return config.ParentalControl.setuppinactive.value + + def createSetup(self): + self.editListEntry = None + self.changePin = None + self.changeSetupPin = None + + self.list = [] + self.list.append(getConfigListEntry(_("Enable parental control"), config.ParentalControl.configured)) + print "config.ParentalControl.configured.value", config.ParentalControl.configured.value + if config.ParentalControl.configured.value: + #self.list.append(getConfigListEntry(_("Configuration mode"), config.ParentalControl.mode)) + self.list.append(getConfigListEntry(_("Protect setup"), config.ParentalControl.setuppinactive)) + if config.ParentalControl.setuppinactive.value: + self.changeSetupPin = getConfigListEntry(_("Change setup pin"), NoSave(ConfigNothing())) + self.list.append(self.changeSetupPin) + self.list.append(getConfigListEntry(_("Protect services"), config.ParentalControl.servicepinactive)) + if config.ParentalControl.servicepinactive.value: + self.list.append(getConfigListEntry(_("Parental control type"), config.ParentalControl.type)) + if config.ParentalControl.mode.value == "complex": + self.changePin = getConfigListEntry(_("Change service pins"), 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.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: + self.session.open(ParentalControlEditor) + elif self["config"].l.getCurrentSelection() == self.changePin: + if config.ParentalControl.mode.value == "complex": + pass + else: + 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")) + else: + 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() + self.createSetup() + + def keyRight(self): + ConfigListScreen.keyRight(self) + print "current selection:", self["config"].l.getCurrentSelection() + self.createSetup() + + def keyCancel(self): + for x in self["config"].list: + x[1].save() + self.close() + + def keyNumberGlobal(self, number): + pass + +class ParentalControlEditor(Screen): + def __init__(self, session): + Screen.__init__(self, session) + + self.list = [] + self.servicelist = ParentalControlList(self.list) + self["servicelist"] = self.servicelist; + + #self.onShown.append(self.chooseLetter) + self.currentLetter = '' + + self.readServiceList() + + 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, + "2": self.keyNumberGlobal, + "3": self.keyNumberGlobal, + "4": self.keyNumberGlobal, + "5": self.keyNumberGlobal, + "6": self.keyNumberGlobal, + "7": self.keyNumberGlobal, + "8": self.keyNumberGlobal, + "9": self.keyNumberGlobal, + "0": self.keyNumberGlobal + }, -1) + + def cancel(self): + parentalControl.save() + self.close() + + def select(self): + self.servicelist.toggleSelectedLock() + + def keyNumberGlobal(self, number): + pass + + 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) + self.root = eServiceReference(refstr) + + self.servicesList = {} + + list = serviceHandler.list(self.root) + if list is not None: + while 1: + s = list.getNext() + if s.valid(): + service = s.toString() + name = ServiceReference(service).getServiceName() + key = name.lower()[0] + if key < 'a' or key > 'z': + key = '&' + #key = str(key) + if not self.servicesList.has_key(key): + self.servicesList[key] = [] + # (servicestring, eServiceRef, name) + self.servicesList[key].append((service, s, name)) + else: + break + print self.servicesList + + def chooseLetter(self): + print "choose letter" + list = [] + for x in self.servicesList.keys(): + if 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) + + def letterChosen(self, result): + 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[1], x[2], parentalControl.getProtectionLevel(x[1]) != -1)) + self.servicelist.setList(self.list) + +class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen): + def __init__(self, session, pin, pinname): + Screen.__init__(self, session) + + self.pin = pin + + self.list = [] + self.pin1 = ConfigPIN(default = 1111, censor = "*") + self.pin2 = ConfigPIN(default = 1112, censor = "*") + 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"))) + ProtectedScreen.__init__(self) + + self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"], + { + "cancel": self.cancel, + }, -1) + + def getPinText(self): + return _("Please enter the old pin code") + + def isProtected(self): + return (self.pin.value != "aaaa") + + 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 keyOK(self): + if self.pin1.value == self.pin2.value: + self.pin.value = self.pin1.value + self.pin.save() + 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 keyNumberGlobal(self, number): + ConfigListScreen.keyNumberGlobal(self, number) + diff --git a/lib/python/Screens/SubservicesQuickzap.py b/lib/python/Screens/SubservicesQuickzap.py index 07e35e3..09f2e72 100644 --- a/lib/python/Screens/SubservicesQuickzap.py +++ b/lib/python/Screens/SubservicesQuickzap.py @@ -4,14 +4,14 @@ from Components.Label import Label from Screens.ChoiceBox import ChoiceBox from Screens.MessageBox import MessageBox -from InfoBarGenerics import InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarTimeshift, InfoBarSeek, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport +from InfoBarGenerics import InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarTimeshift, InfoBarSeek, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, InfoBarAudioSelection from enigma import eTimer -class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, Screen): +class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, InfoBarAudioSelection, Screen): def __init__(self, session, subservices): Screen.__init__(self, session) - for x in [InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarSubtitleSupport, InfoBarExtensions]: + for x in [InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarSubtitleSupport, InfoBarExtensions, InfoBarAudioSelection]: x.__init__(self) self.restoreService = self.session.nav.getCurrentlyPlayingServiceReference() @@ -118,6 +118,7 @@ class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, Info del self.subservices del self.service self.lastservice = self.currentlyPlayingSubservice + self.session.nav.stopService() self.session.nav.playService(newservice) self.currentlyPlayingSubservice = number self.currentSubserviceNumberLabel.setText(str(number)) diff --git a/lib/python/Screens/__init__.py b/lib/python/Screens/__init__.py index 3cb1222..5eac3b1 100644 --- a/lib/python/Screens/__init__.py +++ b/lib/python/Screens/__init__.py @@ -6,4 +6,4 @@ __all__ = ["ChannelSelection", "ClockDisplay", "ConfigMenu", "EpgSelection", "EventView", "Standby", "ServiceInfo", "InfoBarGenerics", "HelpMenu", "Wizard", "PiPSetup", "PVRState", "Console", "InputBox", "ChoiceBox", "SimpleSummary", - "TimerSelection", "SubservicesQuickzap" ] + "TimerSelection", "SubservicesQuickzap", "ParentalControlSetup" ] diff --git a/mytest.py b/mytest.py index 26edd6b..86549f7 100644 --- a/mytest.py +++ b/mytest.py @@ -19,6 +19,9 @@ import time import ServiceReference +from Components.ParentalControl import InitParentalControl +InitParentalControl() + from Navigation import Navigation from skin import readSkin, applyAllAttributes @@ -499,6 +502,9 @@ try: runScreenTest() plugins.shutdown() + + from Components.ParentalControl import parentalControl + parentalControl.save() except: print 'EXCEPTION IN PYTHON STARTUP CODE:' print '-'*60