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 Screens.ChoiceBox import ChoiceBox
8 from Screens.MessageBox import MessageBox
9 from Screens.InputBox import PinInput
10 from Screens.ChannelSelection import service_types_tv
11 from Tools.BoundFunction import boundFunction
12 from enigma import eServiceCenter, eTimer, eServiceReference
13 from operator import itemgetter
15 class ProtectedScreen:
17 if self.isProtected():
18 self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.protectedWithPin()], triesEntry = self.getTriesEntry(), title = self.getPinText(), windowTitle = _("Change pin code")))
20 def getTriesEntry(self):
21 return config.ParentalControl.retries.setuppin
24 return _("Please enter the correct pin code")
26 def isProtected(self):
29 def protectedWithPin(self):
30 return config.ParentalControl.setuppin.value
32 def pinEntered(self, result):
36 self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
38 class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
39 def __init__(self, session):
40 Screen.__init__(self, session)
41 ProtectedScreen.__init__(self)
43 ConfigListScreen.__init__(self, self.list)
46 self["actions"] = NumberActionMap(["SetupActions"],
48 "cancel": self.keyCancel
51 def isProtected(self):
52 return config.ParentalControl.setuppinactive.value and config.ParentalControl.configured.value
54 def createSetup(self):
55 self.editListEntry = None
57 self.changeSetupPin = None
60 self.list.append(getConfigListEntry(_("Enable parental control"), config.ParentalControl.configured))
61 print "config.ParentalControl.configured.value", config.ParentalControl.configured.value
62 if config.ParentalControl.configured.value:
63 #self.list.append(getConfigListEntry(_("Configuration mode"), config.ParentalControl.mode))
64 self.list.append(getConfigListEntry(_("Protect setup"), config.ParentalControl.setuppinactive))
65 if config.ParentalControl.setuppinactive.value:
66 self.changeSetupPin = getConfigListEntry(_("Change setup pin"), NoSave(ConfigNothing()))
67 self.list.append(self.changeSetupPin)
68 self.list.append(getConfigListEntry(_("Protect services"), config.ParentalControl.servicepinactive))
69 if config.ParentalControl.servicepinactive.value:
70 self.list.append(getConfigListEntry(_("Parental control type"), config.ParentalControl.type))
71 if config.ParentalControl.mode.value == "complex":
72 self.changePin = getConfigListEntry(_("Change service pins"), NoSave(ConfigNothing()))
73 self.list.append(self.changePin)
74 elif config.ParentalControl.mode.value == "simple":
75 self.changePin = getConfigListEntry(_("Change service pin"), NoSave(ConfigNothing()))
76 self.list.append(self.changePin)
77 #self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin))
78 self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
79 self.list.append(self.editListEntry)
81 self["config"].list = self.list
82 self["config"].setList(self.list)
85 print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
86 if self["config"].l.getCurrentSelection() == self.editListEntry:
87 self.session.open(ParentalControlEditor)
88 elif self["config"].l.getCurrentSelection() == self.changePin:
89 if config.ParentalControl.mode.value == "complex":
92 self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
93 elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
94 self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
96 ConfigListScreen.keyRight(self)
97 print "current selection:", self["config"].l.getCurrentSelection()
101 ConfigListScreen.keyLeft(self)
102 print "current selection:", self["config"].l.getCurrentSelection()
106 ConfigListScreen.keyRight(self)
107 print "current selection:", self["config"].l.getCurrentSelection()
110 def SetupPinMessageCallback(self, value):
112 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
114 config.ParentalControl.setuppinactive.value = False
117 def ServicePinMessageCallback(self, value):
119 self.session.openWithCallback(self.cancelCB, ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
121 config.ParentalControl.servicepinactive.value = False
124 def cancelCB(self,value):
128 if config.ParentalControl.setuppinactive.value and config.ParentalControl.setuppin.value == 'aaaa':
129 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)
130 elif config.ParentalControl.servicepinactive.value and config.ParentalControl.servicepin[0].value == 'aaaa':
131 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)
133 for x in self["config"].list:
137 def keyNumberGlobal(self, number):
141 class ParentalControlEditor(Screen):
142 def __init__(self, session):
143 Screen.__init__(self, session)
145 self.servicelist = ParentalControlList(self.list)
146 self["servicelist"] = self.servicelist;
147 #self.onShown.append(self.chooseLetter)
148 self.currentLetter = chr(SPECIAL_CHAR)
149 self.readServiceList()
150 self.chooseLetterTimer = eTimer()
151 self.chooseLetterTimer.callback.append(self.chooseLetter)
152 self.onLayoutFinish.append(self.LayoutFinished)
154 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
157 "cancel": self.cancel,
158 #"left": self.keyLeft,
159 #"right": self.keyRight,
160 "1": self.keyNumberGlobal,
161 "2": self.keyNumberGlobal,
162 "3": self.keyNumberGlobal,
163 "4": self.keyNumberGlobal,
164 "5": self.keyNumberGlobal,
165 "6": self.keyNumberGlobal,
166 "7": self.keyNumberGlobal,
167 "8": self.keyNumberGlobal,
168 "9": self.keyNumberGlobal,
169 "0": self.keyNumberGlobal
172 def LayoutFinished(self):
173 self.chooseLetterTimer.start(0, True)
179 self.servicelist.toggleSelectedLock()
181 def keyNumberGlobal(self, number):
184 def readServiceList(self):
185 serviceHandler = eServiceCenter.getInstance()
186 refstr = '%s ORDER BY name' % (service_types_tv)
187 self.root = eServiceReference(refstr)
188 self.servicesList = {}
189 list = serviceHandler.list(self.root)
191 services = list.getContent("CN", True) #(servicecomparestring, name)
193 key = s[1].lower()[0]
194 if key < 'a' or key > 'z':
195 key = chr(SPECIAL_CHAR)
197 if not self.servicesList.has_key(key):
198 self.servicesList[key] = []
199 self.servicesList[key].append(s)
201 def chooseLetter(self):
202 print "choose letter"
204 for x in self.servicesList.keys():
205 if x == chr(SPECIAL_CHAR):
206 x = ("special characters", x)
210 mylist.sort(key=itemgetter(1))
211 sel = ord(self.currentLetter) - SPECIAL_CHAR
212 self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=mylist, keys = [], selection = sel)
214 def letterChosen(self, result):
215 if result is not None:
216 print "result:", result
217 self.currentLetter = result[1]
218 self.list = [ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1) for x in self.servicesList[result[1]]]
219 self.servicelist.setList(self.list)
221 parentalControl.save()
224 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
225 def __init__(self, session, pin, pinname):
226 Screen.__init__(self, session)
229 self.pin1 = ConfigPIN(default = 1111, censor = "*")
230 self.pin2 = ConfigPIN(default = 1112, censor = "*")
231 self.pin1.addEndNotifier(boundFunction(self.valueChanged, 1))
232 self.pin2.addEndNotifier(boundFunction(self.valueChanged, 2))
233 self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1)))
234 self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2)))
235 ConfigListScreen.__init__(self, self.list)
236 # print "old pin:", pin
237 #if pin.value != "aaaa":
238 #self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.pin.value], title = _("please enter the old pin"), windowTitle = _("Change pin code")))
239 ProtectedScreen.__init__(self)
241 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
243 "cancel": self.cancel,
246 def valueChanged(self, pin, value):
248 self["config"].setCurrentIndex(1)
252 def getPinText(self):
253 return _("Please enter the old pin code")
255 def isProtected(self):
256 return (self.pin.value != "aaaa")
258 def protectedWithPin(self):
259 return self.pin.value
261 # def pinEntered(self, result):
262 #if result[0] is None:
265 #print result, "-", self.pin.value
266 #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
269 if self.pin1.value == self.pin2.value:
270 self.pin.value = self.pin1.value
272 self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
274 self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
279 def keyNumberGlobal(self, number):
280 ConfigListScreen.keyNumberGlobal(self, number)