1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ActionMap import NumberActionMap
4 from Components.Label import Label
6 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigSubList, getConfigListEntry, KEY_LEFT, KEY_RIGHT, KEY_0, ConfigNothing, ConfigPIN
7 from Components.ConfigList import ConfigList
9 from enigma import eTimer, eDVBCI_UI
14 config.ci = ConfigSubList()
15 for slot in range(MAX_NUM_CI):
16 config.ci.append(ConfigSubsection())
17 config.ci[slot].canDescrambleMultipleServices = ConfigSelection(choices = [("auto", _("Auto")), ("no", _("No")), ("yes", _("Yes"))], default = "auto")
19 class MMIDialog(Screen):
20 def __init__(self, session, slotid, action, handler = eDVBCI_UI.getInstance(), wait_text = _("wait for ci...") ):
21 Screen.__init__(self, session)
23 print "MMIDialog with action" + str(action)
29 self.timer.timeout.get().append(self.keyCancel)
32 self["title"] = Label("")
33 self["subtitle"] = Label("")
34 self["bottom"] = Label("")
35 self["entries"] = ConfigList([ ])
37 self["actions"] = NumberActionMap(["SetupActions"],
39 "ok": self.okbuttonClick,
40 "cancel": self.keyCancel,
43 "right": self.keyRight,
44 "1": self.keyNumberGlobal,
45 "2": self.keyNumberGlobal,
46 "3": self.keyNumberGlobal,
47 "4": self.keyNumberGlobal,
48 "5": self.keyNumberGlobal,
49 "6": self.keyNumberGlobal,
50 "7": self.keyNumberGlobal,
51 "8": self.keyNumberGlobal,
52 "9": self.keyNumberGlobal,
53 "0": self.keyNumberGlobal
58 self.handler = handler
59 self.wait_text = wait_text
61 if action == 2: #start MMI
62 handler.startMMI(self.slotid)
64 elif action == 3: #mmi already there (called from infobar)
67 def addEntry(self, list, entry):
68 if entry[0] == "TEXT": #handle every item (text / pin only?)
69 list.append( (entry[1], ConfigNothing(), entry[2]) )
74 x = ConfigPIN(0, len = pinlength, censor = "*")
77 x = ConfigPIN(0, len = pinlength)
78 self["subtitle"].setText(entry[2])
79 list.append( getConfigListEntry("", x) )
80 self["bottom"].setText(_("please press OK when ready"))
82 def okbuttonClick(self):
86 if self.tag == "WAIT":
87 print "do nothing - wait"
88 elif self.tag == "MENU":
90 cur = self["entries"].getCurrent()
92 self.handler.answerMenu(self.slotid, cur[2])
94 self.handler.answerMenu(self.slotid, 0)
96 elif self.tag == "LIST":
98 self.handler.answerMenu(self.slotid, 0)
100 elif self.tag == "ENQ":
101 cur = self["entries"].getCurrent()
102 answer = str(cur[1].value)
104 while length < cur[1].getLength():
107 self.handler.answerEnq(self.slotid, answer)
112 self.close(self.slotid)
119 if self.tag == "WAIT":
120 self.handler.stopMMI(self.slotid)
122 elif self.tag in [ "MENU", "LIST" ]:
124 self.handler.answerMenu(self.slotid, 0)
126 elif self.tag == "ENQ":
128 self.handler.cancelEnq(self.slotid)
131 print "give cancel action to ci"
133 def keyConfigEntry(self, key):
136 self["entries"].handleKey(key)
140 def keyNumberGlobal(self, number):
142 self.keyConfigEntry(KEY_0 + number)
146 self.keyConfigEntry(KEY_LEFT)
150 self.keyConfigEntry(KEY_RIGHT)
152 def updateList(self, list):
153 List = self["entries"]
155 List.instance.moveSelectionTo(0)
162 self["title"].setText("")
163 self["subtitle"].setText("")
164 self["bottom"].setText("")
166 list.append( (self.wait_text, ConfigNothing()) )
167 self.updateList(list)
169 def showScreen(self):
170 screen = self.handler.getMMIScreen(self.slotid)
175 if len(screen) > 0 and screen[0][0] == "CLOSE":
176 timeout = screen[0][1]
178 self.timer.start(timeout*1000, True)
182 self.tag = screen[0][0]
184 if entry[0] == "PIN":
185 self.addEntry(list, entry)
187 if entry[0] == "TITLE":
188 self["title"].setText(entry[1])
189 elif entry[0] == "SUBTITLE":
190 self["subtitle"].setText(entry[1])
191 elif entry[0] == "BOTTOM":
192 self["bottom"].setText(entry[1])
193 elif entry[0] == "TEXT":
194 self.addEntry(list, entry)
195 self.updateList(list)
197 def ciStateChanged(self):
199 if self.action == 0: #reset
201 if self.action == 1: #init
204 #module still there ?
205 if self.handler.getState(self.slotid) != 2:
208 #mmi session still active ?
209 if self.handler.getMMIState(self.slotid) != 1:
214 elif self.action > 1 and self.handler.availableMMI(self.slotid) == 1:
217 #FIXME: check for mmi-session closed
219 class CiMessageHandler:
224 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
226 def setSession(self, session):
227 self.session = session
229 def ciStateChanged(self, slot):
233 if slot in self.dlgs:
234 self.dlgs[slot].ciStateChanged()
235 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
237 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, 3)
239 def dlgClosed(self, slot):
240 if slot in self.dlgs:
243 def registerCIMessageHandler(self, slot, func):
244 self.unregisterCIMessageHandler(slot)
247 def unregisterCIMessageHandler(self, slot):
251 CiHandler = CiMessageHandler()
253 class CiSelection(Screen):
254 def __init__(self, session):
255 Screen.__init__(self, session)
256 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
258 "left": self.keyLeft,
259 "right": self.keyLeft,
260 "ok": self.okbuttonClick,
261 "cancel": self.cancel
268 for slot in range(MAX_NUM_CI):
269 state = eDVBCI_UI.getInstance().getState(slot)
271 self.appendEntries(slot, state)
272 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
274 menuList = ConfigList(self.list)
275 menuList.list = self.list
276 menuList.l.setList(self.list)
277 self["entries"] = menuList
278 self["entries"].onSelectionChanged.append(self.selectionChanged)
279 self["text"] = Label(_("Slot %d")%(1))
281 def selectionChanged(self):
282 cur_idx = self["entries"].getCurrentIndex()
283 self["text"].setText(_("Slot %d")%((cur_idx / 4)+1))
285 def keyConfigEntry(self, key):
287 self["entries"].handleKey(key)
288 self["entries"].getCurrent()[1].save()
293 self.keyConfigEntry(KEY_LEFT)
296 self.keyConfigEntry(KEY_RIGHT)
298 def appendEntries(self, slot, state):
299 self.state[slot] = state
300 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
301 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
303 if self.state[slot] == 0: #no module
304 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
305 elif self.state[slot] == 1: #module in init
306 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
307 elif self.state[slot] == 2: #module ready
309 appname = eDVBCI_UI.getInstance().getAppName(slot)
310 self.list.append( (appname, ConfigNothing(), 2, slot) )
312 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
314 def updateState(self, slot):
315 state = eDVBCI_UI.getInstance().getState(slot)
316 self.state[slot] = state
319 while len(self.list[slotidx]) < 3 or self.list[slotidx][3] != slot:
322 slotidx += 1 # do not change Reset
323 slotidx += 1 # do not change Init
325 if state == 0: #no module
326 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
327 elif state == 1: #module in init
328 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
329 elif state == 2: #module ready
331 appname = eDVBCI_UI.getInstance().getAppName(slot)
332 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
334 lst = self["entries"]
336 lst.l.setList(self.list)
338 def ciStateChanged(self, slot):
340 self.dlg.ciStateChanged()
342 state = eDVBCI_UI.getInstance().getState(slot)
343 if self.state[slot] != state:
344 #print "something happens"
345 self.state[slot] = state
346 self.updateState(slot)
348 def dlgClosed(self, slot):
351 def okbuttonClick(self):
352 cur = self["entries"].getCurrent()
353 if cur and len(cur) > 2:
356 if action == 0: #reset
357 eDVBCI_UI.getInstance().setReset(slot)
358 elif action == 1: #init
359 eDVBCI_UI.getInstance().setInit(slot)
360 elif self.state[slot] == 2:
361 self.dlg = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, action)
364 for slot in range(MAX_NUM_CI):
365 state = eDVBCI_UI.getInstance().getState(slot)
367 CiHandler.unregisterCIMessageHandler(slot)