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 self.editBouquetListEntry = -1
77 if config.ParentalControl.configured.value:
78 #self.list.append(getConfigListEntry(_("Configuration mode"), config.ParentalControl.mode))
79 self.list.append(getConfigListEntry(_("Protect setup"), config.ParentalControl.setuppinactive))
80 if config.ParentalControl.setuppinactive.value:
81 self.changeSetupPin = getConfigListEntry(_("Change setup pin"), NoSave(ConfigNothing()))
82 self.list.append(self.changeSetupPin)
83 self.list.append(getConfigListEntry(_("Protect services"), config.ParentalControl.servicepinactive))
84 if config.ParentalControl.servicepinactive.value:
85 self.list.append(getConfigListEntry(_("Parental control type"), config.ParentalControl.type))
86 if config.ParentalControl.mode.value == "complex":
87 self.changePin = getConfigListEntry(_("Change service pins"), NoSave(ConfigNothing()))
88 self.list.append(self.changePin)
89 elif config.ParentalControl.mode.value == "simple":
90 self.changePin = getConfigListEntry(_("Change service pin"), NoSave(ConfigNothing()))
91 self.list.append(self.changePin)
92 #Added Option to remember the service pin
93 self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin))
94 #Added Option to remember the cancellation of service pin entry
95 self.list.append(getConfigListEntry(_("Remember service pin cancel"), config.ParentalControl.storeservicepincancel))
96 self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
97 self.list.append(self.editListEntry)
98 #New funtion: Possibility to add Bouquets to whitelist / blacklist
99 self.editBouquetListEntry = getConfigListEntry(_("Edit bouquets list"), NoSave(ConfigNothing()))
100 self.list.append(self.editBouquetListEntry)
101 #New option to reload service lists (for example if bouquets have changed)
102 self.reloadLists = getConfigListEntry(_("Reload Black-/Whitelists"), NoSave(ConfigNothing()))
103 self.list.append(self.reloadLists)
105 self["config"].list = self.list
106 self["config"].setList(self.list)
109 print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
110 if self["config"].l.getCurrentSelection() == self.editListEntry:
111 self.session.open(ParentalControlEditor)
112 elif self["config"].l.getCurrentSelection() == self.editBouquetListEntry:
113 self.session.open(ParentalControlBouquetEditor)
114 elif self["config"].l.getCurrentSelection() == self.changePin:
115 if config.ParentalControl.mode.value == "complex":
118 self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
119 elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
120 self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
121 elif self["config"].l.getCurrentSelection() == self.reloadLists:
122 parentalControl.open()
124 ConfigListScreen.keyRight(self)
125 print "current selection:", self["config"].l.getCurrentSelection()
129 ConfigListScreen.keyLeft(self)
130 print "current selection:", self["config"].l.getCurrentSelection()
134 ConfigListScreen.keyRight(self)
135 print "current selection:", self["config"].l.getCurrentSelection()
138 def SetupPinMessageCallback(self, value):
140 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
142 config.ParentalControl.setuppinactive.value = False
145 def ServicePinMessageCallback(self, value):
147 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
149 config.ParentalControl.servicepinactive.value = False
152 def cancelCB(self,value):
156 if config.ParentalControl.setuppinactive.value and config.ParentalControl.setuppin.value == 'aaaa':
157 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)
158 elif config.ParentalControl.servicepinactive.value and config.ParentalControl.servicepin[0].value == 'aaaa':
159 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)
161 for x in self["config"].list:
165 def keyNumberGlobal(self, number):
169 def changedEntry(self):
170 for x in self.onChangedEntry:
173 def getCurrentEntry(self):
174 return self["config"].getCurrent()[0]
176 def getCurrentValue(self):
177 return str(self["config"].getCurrent()[1].getText())
179 def createSummary(self):
180 from Screens.Setup import SetupSummary
184 class ParentalControlEditor(Screen):
185 def __init__(self, session):
186 Screen.__init__(self, session)
188 self.servicelist = ParentalControlList(self.list)
189 self["servicelist"] = self.servicelist;
190 #self.onShown.append(self.chooseLetter)
191 self.currentLetter = chr(SPECIAL_CHAR)
192 self.readServiceList()
193 self.chooseLetterTimer = eTimer()
194 self.chooseLetterTimer.callback.append(self.chooseLetter)
195 self.onLayoutFinish.append(self.LayoutFinished)
197 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
200 "cancel": self.cancel,
201 #"left": self.keyLeft,
202 #"right": self.keyRight,
203 "1": self.keyNumberGlobal,
204 "2": self.keyNumberGlobal,
205 "3": self.keyNumberGlobal,
206 "4": self.keyNumberGlobal,
207 "5": self.keyNumberGlobal,
208 "6": self.keyNumberGlobal,
209 "7": self.keyNumberGlobal,
210 "8": self.keyNumberGlobal,
211 "9": self.keyNumberGlobal,
212 "0": self.keyNumberGlobal
215 def LayoutFinished(self):
216 self.chooseLetterTimer.start(0, True)
222 self.servicelist.toggleSelectedLock()
224 def keyNumberGlobal(self, number):
227 def readServiceList(self):
228 serviceHandler = eServiceCenter.getInstance()
229 refstr = '%s ORDER BY name' % (service_types_tv)
230 self.root = eServiceReference(refstr)
231 self.servicesList = {}
232 list = serviceHandler.list(self.root)
234 services = list.getContent("CN", True) #(servicecomparestring, name)
236 key = s[1].lower()[0]
237 if key < 'a' or key > 'z':
238 key = chr(SPECIAL_CHAR)
240 if not self.servicesList.has_key(key):
241 self.servicesList[key] = []
242 self.servicesList[key].append(s)
244 def chooseLetter(self):
245 print "choose letter"
247 for x in self.servicesList.keys():
248 if x == chr(SPECIAL_CHAR):
249 x = (_("special characters"), x)
253 mylist.sort(key=itemgetter(1))
254 sel = ord(self.currentLetter) - SPECIAL_CHAR
255 self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=mylist, keys = [], selection = sel)
257 def letterChosen(self, result):
258 if result is not None:
259 print "result:", result
260 self.currentLetter = result[1]
261 #Replace getProtectionLevel by new getProtectionType
262 self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.servicesList[result[1]]]
263 self.servicelist.setList(self.list)
265 parentalControl.save()
268 class ParentalControlBouquetEditor(Screen):
269 #This new class allows adding complete bouquets to black- and whitelists
270 #The servicereference that is stored for bouquets is their refstr as listed in bouquets.tv
271 def __init__(self, session):
272 Screen.__init__(self, session)
273 self.skinName = "ParentalControlEditor"
275 self.bouquetslist = ParentalControlList(self.list)
276 self["servicelist"] = self.bouquetslist;
277 self.readBouquetList()
278 self.onLayoutFinish.append(self.selectBouquet)
280 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
283 "cancel": self.cancel
287 parentalControl.save()
291 self.bouquetslist.toggleSelectedLock()
293 def readBouquetList(self):
294 serviceHandler = eServiceCenter.getInstance()
295 refstr = '1:134:1:0:0:0:0:0:0:0:FROM BOUQUET \"bouquets.tv\" ORDER BY bouquet'
296 bouquetroot = eServiceReference(refstr)
297 self.bouquetlist = {}
298 list = serviceHandler.list(bouquetroot)
300 self.bouquetlist = list.getContent("CN", True)
302 def selectBouquet(self):
303 self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionType(x[0])) for x in self.bouquetlist]
304 self.bouquetslist.setList(self.list)
306 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
307 def __init__(self, session, pin, pinname):
308 Screen.__init__(self, session)
309 # for the skin: first try ParentalControlChangePin, then Setup, this allows individual skinning
310 self.skinName = ["ParentalControlChangePin", "Setup" ]
311 self.setup_title = _("Change pin code")
312 self.onChangedEntry = [ ]
316 self.pin1 = ConfigPIN(default = 1111, censor = "*")
317 self.pin2 = ConfigPIN(default = 1112, censor = "*")
318 self.pin1.addEndNotifier(boundFunction(self.valueChanged, 1))
319 self.pin2.addEndNotifier(boundFunction(self.valueChanged, 2))
320 self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1)))
321 self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2)))
322 ConfigListScreen.__init__(self, self.list)
323 # print "old pin:", pin
324 #if pin.value != "aaaa":
325 #self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.pin.value], title = _("please enter the old pin"), windowTitle = _("Change pin code")))
326 ProtectedScreen.__init__(self)
328 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
330 "cancel": self.cancel,
334 self["key_red"] = StaticText(_("Cancel"))
335 self["key_green"] = StaticText(_("OK"))
336 self.onLayoutFinish.append(self.layoutFinished)
338 def layoutFinished(self):
339 self.setTitle(self.setup_title)
341 def valueChanged(self, pin, value):
343 self["config"].setCurrentIndex(1)
347 def getPinText(self):
348 return _("Please enter the old pin code")
350 def isProtected(self):
351 return (self.pin.value != "aaaa")
353 def protectedWithPin(self):
354 return self.pin.value
356 # def pinEntered(self, result):
357 #if result[0] is None:
360 #print result, "-", self.pin.value
361 #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
364 if self.pin1.value == self.pin2.value:
365 self.pin.value = self.pin1.value
367 self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
369 self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
374 def keyNumberGlobal(self, number):
375 ConfigListScreen.keyNumberGlobal(self, number)
378 def changedEntry(self):
379 for x in self.onChangedEntry:
382 def getCurrentEntry(self):
383 return self["config"].getCurrent()[0]
385 def getCurrentValue(self):
386 return str(self["config"].getCurrent()[1].getText())
388 def createSummary(self):
389 from Screens.Setup import SetupSummary