1 from Screen import Screen
2 from Components.ConfigList import ConfigList, ConfigListScreen
3 from Components.ActionMap import NumberActionMap
4 from Components.config import config, getConfigListEntry, ConfigNothing, NoSave, ConfigPIN
5 from Components.ServiceList import ServiceList
6 from Components.ParentalControlList import ParentalControlEntryComponent, ParentalControlList
7 from Components.ParentalControl import parentalControl
8 from Screens.ChoiceBox import ChoiceBox
9 from Screens.MessageBox import MessageBox
10 from Screens.InputBox import InputBox, Input, PinInput
11 from Screens.ChannelSelection import service_types_tv
12 from Tools.BoundFunction import boundFunction
13 from ServiceReference import ServiceReference
14 from enigma import eServiceCenter, eServiceReference, eTimer
15 from operator import itemgetter
17 class ProtectedScreen:
19 if self.isProtected():
20 self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.protectedWithPin()], triesEntry = self.getTriesEntry(), title = self.getPinText(), windowTitle = _("Change pin code")))
22 def getTriesEntry(self):
23 return config.ParentalControl.retries.setuppin
26 return _("Please enter the correct pin code")
28 def isProtected(self):
31 def protectedWithPin(self):
32 return config.ParentalControl.setuppin.value
34 def pinEntered(self, result):
38 self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
40 class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
41 def __init__(self, session):
42 Screen.__init__(self, session)
43 ProtectedScreen.__init__(self)
45 ConfigListScreen.__init__(self, self.list)
48 self["actions"] = NumberActionMap(["SetupActions"],
50 "cancel": self.keyCancel
53 def isProtected(self):
54 return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value
56 def createSetup(self):
57 self.editListEntry = None
59 self.changeSetupPin = None
62 self.list.append(getConfigListEntry(_("Enable parental control"), config.ParentalControl.configured))
63 print "config.ParentalControl.configured.value", config.ParentalControl.configured.value
64 if config.ParentalControl.configured.value:
65 #self.list.append(getConfigListEntry(_("Configuration mode"), config.ParentalControl.mode))
66 self.list.append(getConfigListEntry(_("Protect setup"), config.ParentalControl.setuppinactive))
67 if config.ParentalControl.setuppinactive.value:
68 self.changeSetupPin = getConfigListEntry(_("Change setup pin"), NoSave(ConfigNothing()))
69 self.list.append(self.changeSetupPin)
70 self.list.append(getConfigListEntry(_("Protect services"), config.ParentalControl.servicepinactive))
71 if config.ParentalControl.servicepinactive.value:
72 self.list.append(getConfigListEntry(_("Parental control type"), config.ParentalControl.type))
73 if config.ParentalControl.mode.value == "complex":
74 self.changePin = getConfigListEntry(_("Change service pins"), NoSave(ConfigNothing()))
75 self.list.append(self.changePin)
76 elif config.ParentalControl.mode.value == "simple":
77 self.changePin = getConfigListEntry(_("Change service pin"), NoSave(ConfigNothing()))
78 self.list.append(self.changePin)
79 #self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin))
80 self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
81 self.list.append(self.editListEntry)
83 self["config"].list = self.list
84 self["config"].setList(self.list)
87 print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
88 if self["config"].l.getCurrentSelection() == self.editListEntry:
89 self.session.open(ParentalControlEditor)
90 elif self["config"].l.getCurrentSelection() == self.changePin:
91 if config.ParentalControl.mode.value == "complex":
94 self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
95 elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
96 self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
98 ConfigListScreen.keyRight(self)
99 print "current selection:", self["config"].l.getCurrentSelection()
103 ConfigListScreen.keyLeft(self)
104 print "current selection:", self["config"].l.getCurrentSelection()
108 ConfigListScreen.keyRight(self)
109 print "current selection:", self["config"].l.getCurrentSelection()
112 def SetupPinMessageCallback(self, value):
114 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
116 config.ParentalControl.setuppinactive.value = False
119 def ServicePinMessageCallback(self, value):
121 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
123 config.ParentalControl.servicepinactive.value = False
126 def cancelCB(self,value):
130 if config.ParentalControl.setuppinactive.value and config.ParentalControl.setuppin.value == 'aaaa':
131 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)
132 elif config.ParentalControl.servicepinactive.value and config.ParentalControl.servicepin[0].value == 'aaaa':
133 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)
135 for x in self["config"].list:
139 def keyNumberGlobal(self, number):
143 class ParentalControlEditor(Screen):
144 def __init__(self, session):
145 Screen.__init__(self, session)
147 self.servicelist = ParentalControlList(self.list)
148 self["servicelist"] = self.servicelist;
149 #self.onShown.append(self.chooseLetter)
150 self.currentLetter = chr(SPECIAL_CHAR)
151 self.readServiceList()
152 self.chooseLetterTimer = eTimer()
153 self.chooseLetterTimer.timeout.get().append(self.chooseLetter)
154 self.onLayoutFinish.append(self.LayoutFinished)
156 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
159 "cancel": self.cancel,
160 #"left": self.keyLeft,
161 #"right": self.keyRight,
162 "1": self.keyNumberGlobal,
163 "2": self.keyNumberGlobal,
164 "3": self.keyNumberGlobal,
165 "4": self.keyNumberGlobal,
166 "5": self.keyNumberGlobal,
167 "6": self.keyNumberGlobal,
168 "7": self.keyNumberGlobal,
169 "8": self.keyNumberGlobal,
170 "9": self.keyNumberGlobal,
171 "0": self.keyNumberGlobal
174 def LayoutFinished(self):
175 self.chooseLetterTimer.start(0, True)
181 self.servicelist.toggleSelectedLock()
183 def keyNumberGlobal(self, number):
186 def readServiceList(self):
187 serviceHandler = eServiceCenter.getInstance()
188 refstr = '%s ORDER BY name' % (service_types_tv)
189 self.root = eServiceReference(refstr)
190 self.servicesList = {}
191 list = serviceHandler.list(self.root)
193 services = list.getContent("CN", True) #(servicecomparestring, name)
195 if ord(s[1][0])==0xc2 and ord(s[1][1])==0x86: # ignore shortname brackets
196 key = s[1].lower()[2]
198 key = s[1].lower()[0]
199 if key < 'a' or key > 'z':
200 key = chr(SPECIAL_CHAR)
202 if not self.servicesList.has_key(key):
203 self.servicesList[key] = []
204 self.servicesList[key].append(s)
206 def chooseLetter(self):
207 print "choose letter"
209 for x in self.servicesList.keys():
210 if x == chr(SPECIAL_CHAR):
211 x = ("special characters", x)
215 mylist.sort(key=itemgetter(1))
216 sel = ord(self.currentLetter) - SPECIAL_CHAR
217 self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=mylist, keys = [], selection = sel)
219 def letterChosen(self, result):
220 if result is not None:
221 print "result:", result
222 self.currentLetter = result[1]
224 for x in self.servicesList[result[1]]:
225 self.list.append(ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1))
226 self.servicelist.setList(self.list)
228 parentalControl.save()
231 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
232 def __init__(self, session, pin, pinname):
233 Screen.__init__(self, session)
236 self.pin1 = ConfigPIN(default = 1111, censor = "*")
237 self.pin2 = ConfigPIN(default = 1112, censor = "*")
238 self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1)))
239 self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2)))
240 ConfigListScreen.__init__(self, self.list)
241 # print "old pin:", pin
242 #if pin.value != "aaaa":
243 #self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.pin.value], title = _("please enter the old pin"), windowTitle = _("Change pin code")))
244 ProtectedScreen.__init__(self)
246 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
248 "cancel": self.cancel,
251 def getPinText(self):
252 return _("Please enter the old pin code")
254 def isProtected(self):
255 return (self.pin.value != "aaaa")
257 def protectedWithPin(self):
258 return self.pin.value
260 # def pinEntered(self, result):
261 #if result[0] is None:
264 #print result, "-", self.pin.value
265 #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
268 if self.pin1.value == self.pin2.value:
269 self.pin.value = self.pin1.value
271 self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
273 self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
278 def keyNumberGlobal(self, number):
279 ConfigListScreen.keyNumberGlobal(self, number)