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 = _("Change 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 #self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin))
91 self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
92 self.list.append(self.editListEntry)
94 self["config"].list = self.list
95 self["config"].setList(self.list)
98 print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
99 if self["config"].l.getCurrentSelection() == self.editListEntry:
100 self.session.open(ParentalControlEditor)
101 elif self["config"].l.getCurrentSelection() == self.changePin:
102 if config.ParentalControl.mode.value == "complex":
105 self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
106 elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
107 self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
109 ConfigListScreen.keyRight(self)
110 print "current selection:", self["config"].l.getCurrentSelection()
114 ConfigListScreen.keyLeft(self)
115 print "current selection:", self["config"].l.getCurrentSelection()
119 ConfigListScreen.keyRight(self)
120 print "current selection:", self["config"].l.getCurrentSelection()
123 def SetupPinMessageCallback(self, value):
125 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
127 config.ParentalControl.setuppinactive.value = False
130 def ServicePinMessageCallback(self, value):
132 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
134 config.ParentalControl.servicepinactive.value = False
137 def cancelCB(self,value):
141 if config.ParentalControl.setuppinactive.value and config.ParentalControl.setuppin.value == 'aaaa':
142 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)
143 elif config.ParentalControl.servicepinactive.value and config.ParentalControl.servicepin[0].value == 'aaaa':
144 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)
146 for x in self["config"].list:
150 def keyNumberGlobal(self, number):
153 def changedEntry(self):
154 for x in self.onChangedEntry:
157 def getCurrentEntry(self):
158 return self["config"].getCurrent()[0]
160 def getCurrentValue(self):
161 return str(self["config"].getCurrent()[1].getText())
163 def createSummary(self):
164 from Screens.Setup import SetupSummary
168 class ParentalControlEditor(Screen):
169 def __init__(self, session):
170 Screen.__init__(self, session)
172 self.servicelist = ParentalControlList(self.list)
173 self["servicelist"] = self.servicelist;
174 #self.onShown.append(self.chooseLetter)
175 self.currentLetter = chr(SPECIAL_CHAR)
176 self.readServiceList()
177 self.chooseLetterTimer = eTimer()
178 self.chooseLetterTimer.callback.append(self.chooseLetter)
179 self.onLayoutFinish.append(self.LayoutFinished)
181 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
184 "cancel": self.cancel,
185 #"left": self.keyLeft,
186 #"right": self.keyRight,
187 "1": self.keyNumberGlobal,
188 "2": self.keyNumberGlobal,
189 "3": self.keyNumberGlobal,
190 "4": self.keyNumberGlobal,
191 "5": self.keyNumberGlobal,
192 "6": self.keyNumberGlobal,
193 "7": self.keyNumberGlobal,
194 "8": self.keyNumberGlobal,
195 "9": self.keyNumberGlobal,
196 "0": self.keyNumberGlobal
199 def LayoutFinished(self):
200 self.chooseLetterTimer.start(0, True)
206 self.servicelist.toggleSelectedLock()
208 def keyNumberGlobal(self, number):
211 def readServiceList(self):
212 serviceHandler = eServiceCenter.getInstance()
213 refstr = '%s ORDER BY name' % (service_types_tv)
214 self.root = eServiceReference(refstr)
215 self.servicesList = {}
216 list = serviceHandler.list(self.root)
218 services = list.getContent("CN", True) #(servicecomparestring, name)
220 key = s[1].lower()[0]
221 if key < 'a' or key > 'z':
222 key = chr(SPECIAL_CHAR)
224 if not self.servicesList.has_key(key):
225 self.servicesList[key] = []
226 self.servicesList[key].append(s)
228 def chooseLetter(self):
229 print "choose letter"
231 for x in self.servicesList.keys():
232 if x == chr(SPECIAL_CHAR):
233 x = ("special characters", x)
237 mylist.sort(key=itemgetter(1))
238 sel = ord(self.currentLetter) - SPECIAL_CHAR
239 self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=mylist, keys = [], selection = sel)
241 def letterChosen(self, result):
242 if result is not None:
243 print "result:", result
244 self.currentLetter = result[1]
245 self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1) for x in self.servicesList[result[1]]]
246 self.servicelist.setList(self.list)
248 parentalControl.save()
251 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
252 def __init__(self, session, pin, pinname):
253 Screen.__init__(self, session)
254 # for the skin: first try ParentalControlChangePin, then Setup, this allows individual skinning
255 self.skinName = ["ParentalControlChangePin", "Setup" ]
256 self.setup_title = _("Change pin code")
257 self.onChangedEntry = [ ]
261 self.pin1 = ConfigPIN(default = 1111, censor = "*")
262 self.pin2 = ConfigPIN(default = 1112, censor = "*")
263 self.pin1.addEndNotifier(boundFunction(self.valueChanged, 1))
264 self.pin2.addEndNotifier(boundFunction(self.valueChanged, 2))
265 self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1)))
266 self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2)))
267 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
268 # print "old pin:", pin
269 #if pin.value != "aaaa":
270 #self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.pin.value], title = _("please enter the old pin"), windowTitle = _("Change pin code")))
271 ProtectedScreen.__init__(self)
273 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
275 "cancel": self.cancel,
279 self["key_red"] = StaticText(_("Cancel"))
280 self["key_green"] = StaticText(_("OK"))
281 self.onLayoutFinish.append(self.layoutFinished)
283 def layoutFinished(self):
284 self.setTitle(self.setup_title)
286 def valueChanged(self, pin, value):
288 self["config"].setCurrentIndex(1)
292 def getPinText(self):
293 return _("Please enter the old pin code")
295 def isProtected(self):
296 return (self.pin.value != "aaaa")
298 def protectedWithPin(self):
299 return self.pin.value
301 # def pinEntered(self, result):
302 #if result[0] is None:
305 #print result, "-", self.pin.value
306 #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
309 if self.pin1.value == self.pin2.value:
310 self.pin.value = self.pin1.value
312 self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
314 self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
319 def keyNumberGlobal(self, number):
320 ConfigListScreen.keyNumberGlobal(self, number)
323 def changedEntry(self):
324 for x in self.onChangedEntry:
327 def getCurrentEntry(self):
328 return self["config"].getCurrent()[0]
330 def getCurrentValue(self):
331 return str(self["config"].getCurrent()[1].getText())
333 def createSummary(self):
334 from Screens.Setup import SetupSummary