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 Components.SystemInfo import SystemInfo
11 from enigma import eTimer, eDVBCI_UI, eDVBCIInterfaces
15 def setCIBitrate(configElement):
16 if configElement.value == "no":
17 eDVBCI_UI.getInstance().setClockRate(configElement.slotid, eDVBCI_UI.rateNormal)
19 eDVBCI_UI.getInstance().setClockRate(configElement.slotid, eDVBCI_UI.rateHigh)
22 config.ci = ConfigSubList()
23 for slot in range(MAX_NUM_CI):
24 config.ci.append(ConfigSubsection())
25 config.ci[slot].canDescrambleMultipleServices = ConfigSelection(choices = [("auto", _("Auto")), ("no", _("No")), ("yes", _("Yes"))], default = "auto")
26 if SystemInfo["CommonInterfaceSupportsHighBitrates"]:
27 config.ci[slot].canHandleHighBitrates = ConfigSelection(choices = [("no", _("No")), ("yes", _("Yes"))], default = "no")
28 config.ci[slot].canHandleHighBitrates.slotid = slot
29 config.ci[slot].canHandleHighBitrates.addNotifier(setCIBitrate)
31 class MMIDialog(Screen):
32 def __init__(self, session, slotid, action, handler = eDVBCI_UI.getInstance(), wait_text = _("wait for ci...") ):
33 Screen.__init__(self, session)
35 print "MMIDialog with action" + str(action)
37 self.mmiclosed = False
42 self.timer.callback.append(self.keyCancel)
45 self["title"] = Label("")
46 self["subtitle"] = Label("")
47 self["bottom"] = Label("")
48 self["entries"] = ConfigList([ ])
50 self["actions"] = NumberActionMap(["SetupActions"],
52 "ok": self.okbuttonClick,
53 "cancel": self.keyCancel,
56 "right": self.keyRight,
57 "1": self.keyNumberGlobal,
58 "2": self.keyNumberGlobal,
59 "3": self.keyNumberGlobal,
60 "4": self.keyNumberGlobal,
61 "5": self.keyNumberGlobal,
62 "6": self.keyNumberGlobal,
63 "7": self.keyNumberGlobal,
64 "8": self.keyNumberGlobal,
65 "9": self.keyNumberGlobal,
66 "0": self.keyNumberGlobal
71 self.handler = handler
72 self.wait_text = wait_text
74 if action == 2: #start MMI
75 handler.startMMI(self.slotid)
77 elif action == 3: #mmi already there (called from infobar)
80 def addEntry(self, list, entry):
81 if entry[0] == "TEXT": #handle every item (text / pin only?)
82 list.append( (entry[1], ConfigNothing(), entry[2]) )
87 x = ConfigPIN(0, len = pinlength, censor = "*")
90 x = ConfigPIN(0, len = pinlength)
91 self["subtitle"].setText(entry[2])
92 list.append( getConfigListEntry("", x) )
93 self["bottom"].setText(_("please press OK when ready"))
95 def okbuttonClick(self):
99 if self.tag == "WAIT":
100 print "do nothing - wait"
101 elif self.tag == "MENU":
103 cur = self["entries"].getCurrent()
105 self.handler.answerMenu(self.slotid, cur[2])
107 self.handler.answerMenu(self.slotid, 0)
109 elif self.tag == "LIST":
111 self.handler.answerMenu(self.slotid, 0)
113 elif self.tag == "ENQ":
114 cur = self["entries"].getCurrent()
115 answer = str(cur[1].value)
117 while length < cur[1].getLength():
120 self.handler.answerEnq(self.slotid, answer)
125 self.close(self.slotid)
129 if not self.tag or self.mmiclosed:
131 elif self.tag == "WAIT":
132 self.handler.stopMMI(self.slotid)
134 elif self.tag in ( "MENU", "LIST" ):
136 self.handler.answerMenu(self.slotid, 0)
138 elif self.tag == "ENQ":
140 self.handler.cancelEnq(self.slotid)
143 print "give cancel action to ci"
145 def keyConfigEntry(self, key):
148 self["entries"].handleKey(key)
152 def keyNumberGlobal(self, number):
154 self.keyConfigEntry(KEY_0 + number)
158 self.keyConfigEntry(KEY_LEFT)
162 self.keyConfigEntry(KEY_RIGHT)
164 def updateList(self, list):
165 List = self["entries"]
167 List.instance.moveSelectionTo(0)
174 self["title"].setText("")
175 self["subtitle"].setText("")
176 self["bottom"].setText("")
178 list.append( (self.wait_text, ConfigNothing()) )
179 self.updateList(list)
181 def showScreen(self):
182 screen = self.handler.getMMIScreen(self.slotid)
187 if len(screen) > 0 and screen[0][0] == "CLOSE":
188 timeout = screen[0][1]
189 self.mmiclosed = True
191 self.timer.start(timeout*1000, True)
195 self.mmiclosed = False
196 self.tag = screen[0][0]
198 if entry[0] == "PIN":
199 self.addEntry(list, entry)
201 if entry[0] == "TITLE":
202 self["title"].setText(entry[1])
203 elif entry[0] == "SUBTITLE":
204 self["subtitle"].setText(entry[1])
205 elif entry[0] == "BOTTOM":
206 self["bottom"].setText(entry[1])
207 elif entry[0] == "TEXT":
208 self.addEntry(list, entry)
209 self.updateList(list)
211 def ciStateChanged(self):
213 if self.action == 0: #reset
215 if self.action == 1: #init
218 #module still there ?
219 if self.handler.getState(self.slotid) != 2:
222 #mmi session still active ?
223 if self.handler.getMMIState(self.slotid) != 1:
228 elif self.action > 1 and self.handler.availableMMI(self.slotid) == 1:
231 #FIXME: check for mmi-session closed
233 class CiMessageHandler:
238 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
239 SystemInfo["CommonInterface"] = eDVBCIInterfaces.getInstance().getNumOfSlots() > 0
241 file = open("/proc/stb/tsmux/ci0_tsclk", "r")
243 SystemInfo["CommonInterfaceSupportsHighBitrates"] = True
245 SystemInfo["CommonInterfaceSupportsHighBitrates"] = False
247 def setSession(self, session):
248 self.session = session
250 def ciStateChanged(self, slot):
254 if slot in self.dlgs:
255 self.dlgs[slot].ciStateChanged()
256 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
258 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, 3)
260 def dlgClosed(self, slot):
261 if slot in self.dlgs:
264 def registerCIMessageHandler(self, slot, func):
265 self.unregisterCIMessageHandler(slot)
268 def unregisterCIMessageHandler(self, slot):
272 CiHandler = CiMessageHandler()
274 class CiSelection(Screen):
275 def __init__(self, session):
276 Screen.__init__(self, session)
277 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
279 "left": self.keyLeft,
280 "right": self.keyLeft,
281 "ok": self.okbuttonClick,
282 "cancel": self.cancel
289 for slot in range(MAX_NUM_CI):
290 state = eDVBCI_UI.getInstance().getState(slot)
292 self.appendEntries(slot, state)
293 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
295 menuList = ConfigList(self.list)
296 menuList.list = self.list
297 menuList.l.setList(self.list)
298 self["entries"] = menuList
299 self["entries"].onSelectionChanged.append(self.selectionChanged)
300 self["text"] = Label(_("Slot %d")%(1))
302 def selectionChanged(self):
303 cur_idx = self["entries"].getCurrentIndex()
304 self["text"].setText(_("Slot %d")%((cur_idx / 5)+1))
306 def keyConfigEntry(self, key):
308 self["entries"].handleKey(key)
309 self["entries"].getCurrent()[1].save()
314 self.keyConfigEntry(KEY_LEFT)
317 self.keyConfigEntry(KEY_RIGHT)
319 def appendEntries(self, slot, state):
320 self.state[slot] = state
321 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
322 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
324 if self.state[slot] == 0: #no module
325 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
326 elif self.state[slot] == 1: #module in init
327 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
328 elif self.state[slot] == 2: #module ready
330 appname = eDVBCI_UI.getInstance().getAppName(slot)
331 self.list.append( (appname, ConfigNothing(), 2, slot) )
333 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
334 if SystemInfo["CommonInterfaceSupportsHighBitrates"]:
335 self.list.append(getConfigListEntry(_("High bitrate support"), config.ci[slot].canHandleHighBitrates))
337 def updateState(self, slot):
338 state = eDVBCI_UI.getInstance().getState(slot)
339 self.state[slot] = state
342 while len(self.list[slotidx]) < 3 or self.list[slotidx][3] != slot:
345 slotidx += 1 # do not change Reset
346 slotidx += 1 # do not change Init
348 if state == 0: #no module
349 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
350 elif state == 1: #module in init
351 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
352 elif state == 2: #module ready
354 appname = eDVBCI_UI.getInstance().getAppName(slot)
355 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
357 lst = self["entries"]
359 lst.l.setList(self.list)
361 def ciStateChanged(self, slot):
363 self.dlg.ciStateChanged()
365 state = eDVBCI_UI.getInstance().getState(slot)
366 if self.state[slot] != state:
367 #print "something happens"
368 self.state[slot] = state
369 self.updateState(slot)
371 def dlgClosed(self, slot):
374 def okbuttonClick(self):
375 cur = self["entries"].getCurrent()
376 if cur and len(cur) > 2:
379 if action == 0: #reset
380 eDVBCI_UI.getInstance().setReset(slot)
381 elif action == 1: #init
382 eDVBCI_UI.getInstance().setInit(slot)
383 elif self.state[slot] == 2:
384 self.dlg = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, action)
387 for slot in range(MAX_NUM_CI):
388 state = eDVBCI_UI.getInstance().getState(slot)
390 CiHandler.unregisterCIMessageHandler(slot)