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.Directories import resolveFilename, SCOPE_CONFIG
13 from Tools.BoundFunction import boundFunction
14 from ServiceReference import ServiceReference
15 from enigma import eServiceCenter, eServiceReference, eTimer
19 class ProtectedScreen:
21 if self.isProtected():
22 self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.protectedWithPin()], triesEntry = self.getTriesEntry(), title = self.getPinText(), windowTitle = _("Change pin code")))
24 def getTriesEntry(self):
25 return config.ParentalControl.retries.setuppin
28 return _("Please enter the correct pin code")
30 def isProtected(self):
33 def protectedWithPin(self):
34 return config.ParentalControl.setuppin.value
36 def pinEntered(self, result):
40 self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
42 class ParentalControlSetup(Screen, ConfigListScreen, ProtectedScreen):
43 def __init__(self, session):
44 Screen.__init__(self, session)
45 ProtectedScreen.__init__(self)
47 ConfigListScreen.__init__(self, self.list)
50 self["actions"] = NumberActionMap(["SetupActions"],
52 "cancel": self.keyCancel
55 def isProtected(self):
56 return config.ParentalControl.setuppinactive.value
58 def createSetup(self):
59 self.editListEntry = None
61 self.changeSetupPin = None
64 self.list.append(getConfigListEntry(_("Enable parental control"), config.ParentalControl.configured))
65 print "config.ParentalControl.configured.value", config.ParentalControl.configured.value
66 if config.ParentalControl.configured.value:
67 #self.list.append(getConfigListEntry(_("Configuration mode"), config.ParentalControl.mode))
68 self.list.append(getConfigListEntry(_("Protect setup"), config.ParentalControl.setuppinactive))
69 if config.ParentalControl.setuppinactive.value:
70 self.changeSetupPin = getConfigListEntry(_("Change setup pin"), NoSave(ConfigNothing()))
71 self.list.append(self.changeSetupPin)
72 self.list.append(getConfigListEntry(_("Protect services"), config.ParentalControl.servicepinactive))
73 if config.ParentalControl.servicepinactive.value:
74 self.list.append(getConfigListEntry(_("Parental control type"), config.ParentalControl.type))
75 if config.ParentalControl.mode.value == "complex":
76 self.changePin = getConfigListEntry(_("Change service pins"), NoSave(ConfigNothing()))
77 self.list.append(self.changePin)
78 elif config.ParentalControl.mode.value == "simple":
79 self.changePin = getConfigListEntry(_("Change service pin"), NoSave(ConfigNothing()))
80 self.list.append(self.changePin)
81 #self.list.append(getConfigListEntry(_("Remember service pin"), config.ParentalControl.storeservicepin))
82 self.editListEntry = getConfigListEntry(_("Edit services list"), NoSave(ConfigNothing()))
83 self.list.append(self.editListEntry)
85 self["config"].list = self.list
86 self["config"].setList(self.list)
89 print "self[\"config\"].l.getCurrentSelection()", self["config"].l.getCurrentSelection()
90 if self["config"].l.getCurrentSelection() == self.editListEntry:
91 self.session.open(ParentalControlEditor)
92 elif self["config"].l.getCurrentSelection() == self.changePin:
93 if config.ParentalControl.mode.value == "complex":
96 self.session.open(ParentalControlChangePin, config.ParentalControl.servicepin[0], _("service pin"))
97 elif self["config"].l.getCurrentSelection() == self.changeSetupPin:
98 self.session.open(ParentalControlChangePin, config.ParentalControl.setuppin, _("setup pin"))
100 ConfigListScreen.keyRight(self)
101 print "current selection:", self["config"].l.getCurrentSelection()
105 ConfigListScreen.keyLeft(self)
106 print "current selection:", self["config"].l.getCurrentSelection()
110 ConfigListScreen.keyRight(self)
111 print "current selection:", self["config"].l.getCurrentSelection()
115 for x in self["config"].list:
119 def keyNumberGlobal(self, number):
123 class ParentalControlEditor(Screen):
124 def __init__(self, session):
125 Screen.__init__(self, session)
127 self.servicelist = ParentalControlList(self.list)
128 self["servicelist"] = self.servicelist;
129 #self.onShown.append(self.chooseLetter)
130 self.currentLetter = chr(SPECIAL_CHAR)
131 self.readServiceList()
132 self.chooseLetterTimer = eTimer()
133 self.chooseLetterTimer.timeout.get().append(self.chooseLetter)
134 self.onLayoutFinish.append(self.LayoutFinished)
136 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
139 "cancel": self.cancel,
140 #"left": self.keyLeft,
141 #"right": self.keyRight,
142 "1": self.keyNumberGlobal,
143 "2": self.keyNumberGlobal,
144 "3": self.keyNumberGlobal,
145 "4": self.keyNumberGlobal,
146 "5": self.keyNumberGlobal,
147 "6": self.keyNumberGlobal,
148 "7": self.keyNumberGlobal,
149 "8": self.keyNumberGlobal,
150 "9": self.keyNumberGlobal,
151 "0": self.keyNumberGlobal
154 def LayoutFinished(self):
155 self.chooseLetterTimer.start(0, True)
161 self.servicelist.toggleSelectedLock()
163 def keyNumberGlobal(self, number):
166 def readServiceList(self):
167 serviceHandler = eServiceCenter.getInstance()
168 refstr = '%s ORDER BY name' % (service_types_tv)
169 self.root = eServiceReference(refstr)
170 self.servicesList = {}
171 list = serviceHandler.list(self.root)
173 services = list.getContent("CN", True) #(servicecomparestring, name)
175 if ord(s[1][0])==0xc2 and ord(s[1][1])==0x86: # ignore shortname brackets
176 key = s[1].lower()[2]
178 key = s[1].lower()[0]
179 if key < 'a' or key > 'z':
180 key = chr(SPECIAL_CHAR)
182 if not self.servicesList.has_key(key):
183 self.servicesList[key] = []
184 self.servicesList[key].append(s)
186 def chooseLetter(self):
187 print "choose letter"
189 for x in self.servicesList.keys():
190 if x == chr(SPECIAL_CHAR):
191 x = ("special characters", x)
195 mylist.sort(key=operator.itemgetter(1))
196 sel = ord(self.currentLetter) - SPECIAL_CHAR
197 self.session.openWithCallback(self.letterChosen, ChoiceBox, title=_("Show services beginning with"), list=mylist, keys = [], selection = sel)
199 def letterChosen(self, result):
200 if result is not None:
201 print "result:", result
202 self.currentLetter = result[1]
204 for x in self.servicesList[result[1]]:
205 self.list.append(ParentalControlEntryComponent(x[0], x[1], parentalControl.getProtectionLevel(x[0]) != -1))
206 self.servicelist.setList(self.list)
208 parentalControl.save()
211 class ParentalControlChangePin(Screen, ConfigListScreen, ProtectedScreen):
212 def __init__(self, session, pin, pinname):
213 Screen.__init__(self, session)
216 self.pin1 = ConfigPIN(default = 1111, censor = "*")
217 self.pin2 = ConfigPIN(default = 1112, censor = "*")
218 self.list.append(getConfigListEntry(_("New pin"), NoSave(self.pin1)))
219 self.list.append(getConfigListEntry(_("Reenter new pin"), NoSave(self.pin2)))
220 ConfigListScreen.__init__(self, self.list)
221 # print "old pin:", pin
222 #if pin.value != "aaaa":
223 #self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.pinEntered, PinInput, pinList = [self.pin.value], title = _("please enter the old pin"), windowTitle = _("Change pin code")))
224 ProtectedScreen.__init__(self)
226 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions"],
228 "cancel": self.cancel,
231 def getPinText(self):
232 return _("Please enter the old pin code")
234 def isProtected(self):
235 return (self.pin.value != "aaaa")
237 def protectedWithPin(self):
238 return self.pin.value
240 # def pinEntered(self, result):
241 #if result[0] is None:
244 #print result, "-", self.pin.value
245 #self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
248 if self.pin1.value == self.pin2.value:
249 self.pin.value = self.pin1.value
251 self.session.openWithCallback(self.close, MessageBox, _("The pin code has been changed successfully."), MessageBox.TYPE_INFO)
253 self.session.open(MessageBox, _("The pin codes you entered are different."), MessageBox.TYPE_ERROR)
258 def keyNumberGlobal(self, number):
259 ConfigListScreen.keyNumberGlobal(self, number)