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
16 config.ci = ConfigSubList()
17 for slot in range(MAX_NUM_CI):
18 config.ci.append(ConfigSubsection())
19 config.ci[slot].canDescrambleMultipleServices = ConfigSelection(choices = [("auto", _("Auto")), ("no", _("No")), ("yes", _("Yes"))], default = "auto")
21 class MMIDialog(Screen):
22 def __init__(self, session, slotid, action, handler = eDVBCI_UI.getInstance(), wait_text = _("wait for ci...") ):
23 Screen.__init__(self, session)
25 print "MMIDialog with action" + str(action)
27 self.mmiclosed = False
32 self.timer.callback.append(self.keyCancel)
35 self["title"] = Label("")
36 self["subtitle"] = Label("")
37 self["bottom"] = Label("")
38 self["entries"] = ConfigList([ ])
40 self["actions"] = NumberActionMap(["SetupActions"],
42 "ok": self.okbuttonClick,
43 "cancel": self.keyCancel,
46 "right": self.keyRight,
47 "1": self.keyNumberGlobal,
48 "2": self.keyNumberGlobal,
49 "3": self.keyNumberGlobal,
50 "4": self.keyNumberGlobal,
51 "5": self.keyNumberGlobal,
52 "6": self.keyNumberGlobal,
53 "7": self.keyNumberGlobal,
54 "8": self.keyNumberGlobal,
55 "9": self.keyNumberGlobal,
56 "0": self.keyNumberGlobal
61 self.handler = handler
62 self.wait_text = wait_text
64 if action == 2: #start MMI
65 handler.startMMI(self.slotid)
67 elif action == 3: #mmi already there (called from infobar)
70 def addEntry(self, list, entry):
71 if entry[0] == "TEXT": #handle every item (text / pin only?)
72 list.append( (entry[1], ConfigNothing(), entry[2]) )
77 x = ConfigPIN(0, len = pinlength, censor = "*")
80 x = ConfigPIN(0, len = pinlength)
81 self["subtitle"].setText(entry[2])
82 list.append( getConfigListEntry("", x) )
83 self["bottom"].setText(_("please press OK when ready"))
85 def okbuttonClick(self):
89 if self.tag == "WAIT":
90 print "do nothing - wait"
91 elif self.tag == "MENU":
93 cur = self["entries"].getCurrent()
95 self.handler.answerMenu(self.slotid, cur[2])
97 self.handler.answerMenu(self.slotid, 0)
99 elif self.tag == "LIST":
101 self.handler.answerMenu(self.slotid, 0)
103 elif self.tag == "ENQ":
104 cur = self["entries"].getCurrent()
105 answer = str(cur[1].value)
107 while length < cur[1].getLength():
110 self.handler.answerEnq(self.slotid, answer)
115 self.close(self.slotid)
119 if not self.tag or self.mmiclosed:
121 elif self.tag == "WAIT":
122 self.handler.stopMMI(self.slotid)
124 elif self.tag in [ "MENU", "LIST" ]:
126 self.handler.answerMenu(self.slotid, 0)
128 elif self.tag == "ENQ":
130 self.handler.cancelEnq(self.slotid)
133 print "give cancel action to ci"
135 def keyConfigEntry(self, key):
138 self["entries"].handleKey(key)
142 def keyNumberGlobal(self, number):
144 self.keyConfigEntry(KEY_0 + number)
148 self.keyConfigEntry(KEY_LEFT)
152 self.keyConfigEntry(KEY_RIGHT)
154 def updateList(self, list):
155 List = self["entries"]
157 List.instance.moveSelectionTo(0)
164 self["title"].setText("")
165 self["subtitle"].setText("")
166 self["bottom"].setText("")
168 list.append( (self.wait_text, ConfigNothing()) )
169 self.updateList(list)
171 def showScreen(self):
172 screen = self.handler.getMMIScreen(self.slotid)
177 if len(screen) > 0 and screen[0][0] == "CLOSE":
178 timeout = screen[0][1]
179 self.mmiclosed = True
181 self.timer.start(timeout*1000, True)
185 self.mmiclosed = False
186 self.tag = screen[0][0]
188 if entry[0] == "PIN":
189 self.addEntry(list, entry)
191 if entry[0] == "TITLE":
192 self["title"].setText(entry[1])
193 elif entry[0] == "SUBTITLE":
194 self["subtitle"].setText(entry[1])
195 elif entry[0] == "BOTTOM":
196 self["bottom"].setText(entry[1])
197 elif entry[0] == "TEXT":
198 self.addEntry(list, entry)
199 self.updateList(list)
201 def ciStateChanged(self):
203 if self.action == 0: #reset
205 if self.action == 1: #init
208 #module still there ?
209 if self.handler.getState(self.slotid) != 2:
212 #mmi session still active ?
213 if self.handler.getMMIState(self.slotid) != 1:
218 elif self.action > 1 and self.handler.availableMMI(self.slotid) == 1:
221 #FIXME: check for mmi-session closed
223 class CiMessageHandler:
228 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
229 SystemInfo["CommonInterface"]= eDVBCIInterfaces.getInstance().getNumOfSlots() > 0
231 def setSession(self, session):
232 self.session = session
234 def ciStateChanged(self, slot):
238 if slot in self.dlgs:
239 self.dlgs[slot].ciStateChanged()
240 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
242 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, 3)
244 def dlgClosed(self, slot):
245 if slot in self.dlgs:
248 def registerCIMessageHandler(self, slot, func):
249 self.unregisterCIMessageHandler(slot)
252 def unregisterCIMessageHandler(self, slot):
256 CiHandler = CiMessageHandler()
258 class CiSelection(Screen):
259 def __init__(self, session):
260 Screen.__init__(self, session)
261 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
263 "left": self.keyLeft,
264 "right": self.keyLeft,
265 "ok": self.okbuttonClick,
266 "cancel": self.cancel
273 for slot in range(MAX_NUM_CI):
274 state = eDVBCI_UI.getInstance().getState(slot)
276 self.appendEntries(slot, state)
277 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
279 menuList = ConfigList(self.list)
280 menuList.list = self.list
281 menuList.l.setList(self.list)
282 self["entries"] = menuList
283 self["entries"].onSelectionChanged.append(self.selectionChanged)
284 self["text"] = Label(_("Slot %d")%(1))
286 def selectionChanged(self):
287 cur_idx = self["entries"].getCurrentIndex()
288 self["text"].setText(_("Slot %d")%((cur_idx / 4)+1))
290 def keyConfigEntry(self, key):
292 self["entries"].handleKey(key)
293 self["entries"].getCurrent()[1].save()
298 self.keyConfigEntry(KEY_LEFT)
301 self.keyConfigEntry(KEY_RIGHT)
303 def appendEntries(self, slot, state):
304 self.state[slot] = state
305 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
306 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
308 if self.state[slot] == 0: #no module
309 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
310 elif self.state[slot] == 1: #module in init
311 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
312 elif self.state[slot] == 2: #module ready
314 appname = eDVBCI_UI.getInstance().getAppName(slot)
315 self.list.append( (appname, ConfigNothing(), 2, slot) )
317 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
319 def updateState(self, slot):
320 state = eDVBCI_UI.getInstance().getState(slot)
321 self.state[slot] = state
324 while len(self.list[slotidx]) < 3 or self.list[slotidx][3] != slot:
327 slotidx += 1 # do not change Reset
328 slotidx += 1 # do not change Init
330 if state == 0: #no module
331 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
332 elif state == 1: #module in init
333 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
334 elif state == 2: #module ready
336 appname = eDVBCI_UI.getInstance().getAppName(slot)
337 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
339 lst = self["entries"]
341 lst.l.setList(self.list)
343 def ciStateChanged(self, slot):
345 self.dlg.ciStateChanged()
347 state = eDVBCI_UI.getInstance().getState(slot)
348 if self.state[slot] != state:
349 #print "something happens"
350 self.state[slot] = state
351 self.updateState(slot)
353 def dlgClosed(self, slot):
356 def okbuttonClick(self):
357 cur = self["entries"].getCurrent()
358 if cur and len(cur) > 2:
361 if action == 0: #reset
362 eDVBCI_UI.getInstance().setReset(slot)
363 elif action == 1: #init
364 eDVBCI_UI.getInstance().setInit(slot)
365 elif self.state[slot] == 2:
366 self.dlg = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, action)
369 for slot in range(MAX_NUM_CI):
370 state = eDVBCI_UI.getInstance().getState(slot)
372 CiHandler.unregisterCIMessageHandler(slot)