1 from Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.ActionMap import NumberActionMap
4 from Components.config import config, getConfigListEntry, ConfigNothing, NoSave, ConfigPIN
5 from Components.ParentalControlList import ParentalControlEntryComponent, ParentalControlList
6 from Components.ParentalControl import parentalControl
7 from Components.Sources.StaticText import StaticText
8 from Screens.ChoiceBox import ChoiceBox
9 from Screens.MessageBox import MessageBox
10 from Screens.InputBox import PinInput
11 from Screens.ChannelSelection import service_types_tv
12 from Tools.BoundFunction import boundFunction
13 from enigma import eServiceCenter, eTimer, eServiceReference
14 from operator import itemgetter
16 class ProtectedScreen:
18 if self.isProtected():
19 self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.protectedWithPin()], triesEntry = self.getTriesEntry(), title = self.getPinText(), windowTitle = _("Enter pin code")))
21 def getTriesEntry(self):
22 return config.ParentalControl.retries.setuppin
25 return _("Please enter the correct pin code")
27 def isProtected(self):
30 def protectedWithPin(self):
31 return config.ParentalControl.setuppin.value
33 def pinEntered(self, result):
37 self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
39 class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
40 def __init__(self, session):
41 Screen.__init__(self, session)
42 ProtectedScreen.__init__(self)
43 # for the skin: first try ParentalControlSetup, then Setup, this allows individual skinning
44 self.skinName = ["ParentalControlSetup", "Setup" ]
45 self.setup_title = _("Parental control setup")
46 self.onChangedEntry = [ ]
49 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
52 self["actions"] = NumberActionMap(["SetupActions"],
54 "cancel": self.keyCancel,
55 "save": self.keyCancel
57 self["key_red"] = StaticText(_("Cancel"))
58 self["key_green"] = StaticText(_("OK"))
59 self.onLayoutFinish.append(self.layoutFinished)
61 def layoutFinished(self):
62 self.setTitle(self.setup_title)
64 def isProtected(self):
65 return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value
67 def createSetup(self):
68 self.editListEntry = None
70 self.changeSetupPin = None
73 self.list.append(getConfigListEntry(_("Enable parental control"), config.ParentalControl.configured))
74 print "config.ParentalControl.configured.value", config.ParentalControl.configured.value
75 if config.ParentalControl.configured.value:
76 #self.list.append(getConfigListEntry(_("Configuration mode"), config.ParentalControl.mode))
77 self.list.append(getConfigListEntry(_("Protect setup"), config.ParentalControl.setuppinactive))
78 if config.ParentalControl.setuppinactive.value:
79 self.changeSetupPin = getConfigListEntry(_("Change setup pin"), NoSave(ConfigNothing()))
80 self.list.append(self.changeSetupPin)
81 self.list.append(getConfigListEntry(_("Protect services"), config.ParentalControl.servicepinactive))
82 if config.ParentalControl.servicepinactive.value:
83 self.list.append(getConfigListEntry(_("Parental control type"), config.ParentalControl.type))
84 if config.ParentalControl.mode.value == "complex":
85 self.changePin = getConfigListEntry(_("Change service pins"), NoSave(ConfigNothing()))
86 self.list.append(self.changePin)
87 elif config.ParentalControl.mode.value == "simple":
88 self.changePin = getConfigListEntry(_("Change service pin"), NoSave(ConfigNothing()))
89 self.list.append(self.changePin)
90 #Added Option to remember the service pin
91 self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin))
92 #Added Option to remember the cancellation of service pin entry
93 self.list.append(getConfigListEntry(_("Remember service pin cancel"), config.ParentalControl.storeservicepincancel))
94 self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
95 self.list.append(self.editListEntry)
96 #New funtion: Possibility to add Bouquets to whitelist / blacklist
97 self.editBouquetListEntry = getConfigListEntry(_("Edit bouquets list"), NoSave(ConfigNothing()))
98 self.list.append(self.editBouquetListEntry)
99 #New option to reload service lists (for example if bouquets have changed)
100 self.reloadLists = getConfigListEntry(_("Reload Black-/Whitelists"), NoSave(ConfigNothing()))
101 self.list.append(self.reloadLists)
103 self["config"].list = self.list
104 self["config"].setList(self.list)
107 print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
108 if self["config"].l.getCurrentSelection() == self.editListEntry:
109 self.session.open(ParentalControlEditor)
110 elif self["config"].l.getCurrentSelection() == self.editBouquetListEntry:
111 self.session.open(ParentalControlBouquetEditor)
112 elif self["config"].l.getCurrentSelection() == self.changePin:
113 if config.ParentalControl.mode.value == "complex":
116 self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
117 elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
118 self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
119 elif self["config"].l.getCurrentSelection() == self.reloadLists:
120 parentalControl.open()
122 ConfigListScreen.keyRight(self)
123 print "current selection:", self["config"].l.getCurrentSelection()
127 ConfigListScreen.keyLeft(self)
128 print "current selection:", self["config"].l.getCurrentSelection()
132 ConfigListScreen.keyRight(self)
133 print "current selection:", self["config"].l.getCurrentSelection()
136 def SetupPinMessageCallback(self, value):
138 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
140 config.ParentalControl.setuppinactive.value = False
143 def ServicePinMessageCallback(self, value):
145 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
147 config.ParentalControl.servicepinactive.value = False
150 def cancelCB(self,value):
154 if config.ParentalControl.setuppinactive.value and config.ParentalControl.setuppin.value == 'aaaa':
155 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)
156 elif config.ParentalControl.servicepinactive.value and config.ParentalControl.servicepin[0].value == 'aaaa':
157 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)
159 for x in self["config"].list:
163 def keyNumberGlobal(self, number):
167 def changedEntry(self):
168 for x in self.onChangedEntry:
171 def getCurrentEntry(self):
172 return self["config"].getCurrent()[0]
174 def getCurrentValue(self):
175 return str(self["config"].getCurrent()[1].getText())
177 def createSummary(self):
178 from Screens.Setup import SetupSummary
182 class ParentalControlEditor(Screen):
183 def __init__(self, session):
184 Screen.__init__(self, session)
186 self.servicelist = ParentalControlList(self.list)
187 self["servicelist"] = self.servicelist;
188 #self.onShown.append(self.chooseLetter)
189 self.currentLetter = chr(SPECIAL_CHAR)
190 self.readServiceList()
191 self.chooseLetterTimer = eTimer()
192 self.chooseLetterTimer.callback.append(self.chooseLetter)
193 self.onLayoutFinish.append(self.LayoutFinished)
195 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
198 "cancel": self.cancel,
199 #"left": self.keyLeft,
200 #"right": self.keyRight,
201 "1": self.keyNumberGlobal,
202 "2": self.keyNumberGlobal,
203 "3": self.keyNumberGlobal,
204 "4": self.keyNumberGlobal,
205 "5": self.keyNumberGlobal,
206 "6": self.keyNumberGlobal,
207 "7": self.keyNumberGlobal,
208 "8": self.keyNumberGlobal,
209 "9": self.keyNumberGlobal,
210 "0": self.keyNumberGlobal
213 def LayoutFinished(self):
214 self.chooseLetterTimer.start(0, True)
220 self.servicelist.toggleSelectedLock()
222 def keyNumberGlobal(self, number):
225 def readServiceList(self):
226 serviceHandler = eServiceCenter.getInstance()
227 refstr = '%s ORDER BY name' % (service_types_tv)
228 self.root = eServiceReference(refstr)
229 self.servicesList = {}
230 list = serviceHandler.list(self.root)
232 services = list.getContent("CN", True) #(servicecomparestring, name)
234 key = s[1].lower()[0]
235 if key < 'a' or key > 'z':
236 key = chr(SPECIAL_CHAR)
238 if not self.servicesList.has_key(key):
239 self.servicesList[key] = []
240 self.servicesList[key].append(s)
242 def chooseLetter(self):
243 print "choose letter"
245 for x in self.servicesList.keys():
246 if x == chr(SPECIAL_CHAR):
247 x = (_("special characters"), x)
251 mylist.sort(key=itemgetter(1))
252 sel = ord(self.currentLetter) - SPECIAL_CHAR
253 self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=mylist, keys = [], selection = sel)
255 def letterChosen(self, result):
256 if result is not None:
257 print "result:", result
258 self.currentLetter = result[1]
259 #Replace getProtectionLevel by new getProtectionType
260 self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.servicesList[result[1]]]
261 self.servicelist.setList(self.list)
263 parentalControl.save()
266 class ParentalControlBouquetEditor(Screen):
267 #This new class allows adding complete bouquets to black- and whitelists
268 #The servicereference that is stored for bouquets is their refstr as listed in bouquets.tv
269 def __init__(self, session):
270 Screen.__init__(self, session)
271 self.skinName = "ParentalControlEditor"
273 self.bouquetslist = ParentalControlList(self.list)
274 self["servicelist"] = self.bouquetslist;
275 self.readBouquetList()
276 self.onLayoutFinish.append(self.selectBouquet)
278 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
281 "cancel": self.cancel
285 parentalControl.save()
289 self.bouquetslist.toggleSelectedLock()
291 def readBouquetList(self):
292 serviceHandler = eServiceCenter.getInstance()
293 refstr = '1:134:1:0:0:0:0:0:0:0:FROM BOUQUET \"bouquets.tv\" ORDER BY bouquet'
294 bouquetroot = eServiceReference(refstr)
295 self.bouquetlist = {}
296 list = serviceHandler.list(bouquetroot)
298 self.bouquetlist = list.getContent("CN", True)
300 def selectBouquet(self):
301 self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.bouquetlist]
302 self.bouquetslist.setList(self.list)
304 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
305 def __init__(self, session, pin, pinname):
306 Screen.__init__(self, session)
307 # for the skin: first try ParentalControlChangePin, then Setup, this allows individual skinning
308 self.skinName = ["ParentalControlChangePin", "Setup" ]
309 self.setup_title = _("Change pin code")
310 self.onChangedEntry = [ ]
314 self.pin1 = ConfigPIN(default = 1111, censor = "*")
315 self.pin2 = ConfigPIN(default = 1112, censor = "*")
316 self.pin1.addEndNotifier(boundFunction(self.valueChanged, 1))
317 self.pin2.addEndNotifier(boundFunction(self.valueChanged, 2))
318 self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1)))
319 self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2)))
320 ConfigListScreen.__init__(self, self.list)
321 # print "old pin:", pin
322 #if pin.value != "aaaa":
323 #self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.pin.value], title = _("please enter the old pin"), windowTitle = _("Change pin code")))
324 ProtectedScreen.__init__(self)
326 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
328 "cancel": self.cancel,
332 self["key_red"] = StaticText(_("Cancel"))
333 self["key_green"] = StaticText(_("OK"))
334 self.onLayoutFinish.append(self.layoutFinished)
336 def layoutFinished(self):
337 self.setTitle(self.setup_title)
339 def valueChanged(self, pin, value):
341 self["config"].setCurrentIndex(1)
345 def getPinText(self):
346 return _("Please enter the old pin code")
348 def isProtected(self):
349 return (self.pin.value != "aaaa")
351 def protectedWithPin(self):
352 return self.pin.value
354 # def pinEntered(self, result):
355 #if result[0] is None:
358 #print result, "-", self.pin.value
359 #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
362 if self.pin1.value == self.pin2.value:
363 self.pin.value = self.pin1.value
365 self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
367 self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
372 def keyNumberGlobal(self, number):
373 ConfigListScreen.keyNumberGlobal(self, number)
376 def changedEntry(self):
377 for x in self.onChangedEntry:
380 def getCurrentEntry(self):
381 return self["config"].getCurrent()[0]
383 def getCurrentValue(self):
384 return str(self["config"].getCurrent()[1].getText())
386 def createSummary(self):
387 from Screens.Setup import SetupSummary