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)
25 self.mmiclosed = False
30 self.timer.timeout.get().append(self.keyCancel)
33 self["title"] = Label("")
34 self["subtitle"] = Label("")
35 self["bottom"] = Label("")
36 self["entries"] = ConfigList([ ])
38 self["actions"] = NumberActionMap(["SetupActions"],
40 "ok": self.okbuttonClick,
41 "cancel": self.keyCancel,
44 "right": self.keyRight,
45 "1": self.keyNumberGlobal,
46 "2": self.keyNumberGlobal,
47 "3": self.keyNumberGlobal,
48 "4": self.keyNumberGlobal,
49 "5": self.keyNumberGlobal,
50 "6": self.keyNumberGlobal,
51 "7": self.keyNumberGlobal,
52 "8": self.keyNumberGlobal,
53 "9": self.keyNumberGlobal,
54 "0": self.keyNumberGlobal
59 self.handler = handler
60 self.wait_text = wait_text
62 if action == 2: #start MMI
63 handler.startMMI(self.slotid)
65 elif action == 3: #mmi already there (called from infobar)
68 def addEntry(self, list, entry):
69 if entry[0] == "TEXT": #handle every item (text / pin only?)
70 list.append( (entry[1], ConfigNothing(), entry[2]) )
75 x = ConfigPIN(0, len = pinlength, censor = "*")
78 x = ConfigPIN(0, len = pinlength)
79 self["subtitle"].setText(entry[2])
80 list.append( getConfigListEntry("", x) )
81 self["bottom"].setText(_("please press OK when ready"))
83 def okbuttonClick(self):
87 if self.tag == "WAIT":
88 print "do nothing - wait"
89 elif self.tag == "MENU":
91 cur = self["entries"].getCurrent()
93 self.handler.answerMenu(self.slotid, cur[2])
95 self.handler.answerMenu(self.slotid, 0)
97 elif self.tag == "LIST":
99 self.handler.answerMenu(self.slotid, 0)
101 elif self.tag == "ENQ":
102 cur = self["entries"].getCurrent()
103 answer = str(cur[1].value)
105 while length < cur[1].getLength():
108 self.handler.answerEnq(self.slotid, answer)
113 self.close(self.slotid)
117 if not self.tag or self.mmiclosed:
119 elif 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]
177 self.mmiclosed = True
179 self.timer.start(timeout*1000, True)
183 self.mmiclosed = False
184 self.tag = screen[0][0]
186 if entry[0] == "PIN":
187 self.addEntry(list, entry)
189 if entry[0] == "TITLE":
190 self["title"].setText(entry[1])
191 elif entry[0] == "SUBTITLE":
192 self["subtitle"].setText(entry[1])
193 elif entry[0] == "BOTTOM":
194 self["bottom"].setText(entry[1])
195 elif entry[0] == "TEXT":
196 self.addEntry(list, entry)
197 self.updateList(list)
199 def ciStateChanged(self):
201 if self.action == 0: #reset
203 if self.action == 1: #init
206 #module still there ?
207 if self.handler.getState(self.slotid) != 2:
210 #mmi session still active ?
211 if self.handler.getMMIState(self.slotid) != 1:
216 elif self.action > 1 and self.handler.availableMMI(self.slotid) == 1:
219 #FIXME: check for mmi-session closed
221 class CiMessageHandler:
226 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
228 def setSession(self, session):
229 self.session = session
231 def ciStateChanged(self, slot):
235 if slot in self.dlgs:
236 self.dlgs[slot].ciStateChanged()
237 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
239 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, 3)
241 def dlgClosed(self, slot):
242 if slot in self.dlgs:
245 def registerCIMessageHandler(self, slot, func):
246 self.unregisterCIMessageHandler(slot)
249 def unregisterCIMessageHandler(self, slot):
253 CiHandler = CiMessageHandler()
255 class CiSelection(Screen):
256 def __init__(self, session):
257 Screen.__init__(self, session)
258 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
260 "left": self.keyLeft,
261 "right": self.keyLeft,
262 "ok": self.okbuttonClick,
263 "cancel": self.cancel
270 for slot in range(MAX_NUM_CI):
271 state = eDVBCI_UI.getInstance().getState(slot)
273 self.appendEntries(slot, state)
274 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
276 menuList = ConfigList(self.list)
277 menuList.list = self.list
278 menuList.l.setList(self.list)
279 self["entries"] = menuList
280 self["entries"].onSelectionChanged.append(self.selectionChanged)
281 self["text"] = Label(_("Slot %d")%(1))
283 def selectionChanged(self):
284 cur_idx = self["entries"].getCurrentIndex()
285 self["text"].setText(_("Slot %d")%((cur_idx / 4)+1))
287 def keyConfigEntry(self, key):
289 self["entries"].handleKey(key)
290 self["entries"].getCurrent()[1].save()
295 self.keyConfigEntry(KEY_LEFT)
298 self.keyConfigEntry(KEY_RIGHT)
300 def appendEntries(self, slot, state):
301 self.state[slot] = state
302 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
303 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
305 if self.state[slot] == 0: #no module
306 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
307 elif self.state[slot] == 1: #module in init
308 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
309 elif self.state[slot] == 2: #module ready
311 appname = eDVBCI_UI.getInstance().getAppName(slot)
312 self.list.append( (appname, ConfigNothing(), 2, slot) )
314 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
316 def updateState(self, slot):
317 state = eDVBCI_UI.getInstance().getState(slot)
318 self.state[slot] = state
321 while len(self.list[slotidx]) < 3 or self.list[slotidx][3] != slot:
324 slotidx += 1 # do not change Reset
325 slotidx += 1 # do not change Init
327 if state == 0: #no module
328 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
329 elif state == 1: #module in init
330 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
331 elif state == 2: #module ready
333 appname = eDVBCI_UI.getInstance().getAppName(slot)
334 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
336 lst = self["entries"]
338 lst.l.setList(self.list)
340 def ciStateChanged(self, slot):
342 self.dlg.ciStateChanged()
344 state = eDVBCI_UI.getInstance().getState(slot)
345 if self.state[slot] != state:
346 #print "something happens"
347 self.state[slot] = state
348 self.updateState(slot)
350 def dlgClosed(self, slot):
353 def okbuttonClick(self):
354 cur = self["entries"].getCurrent()
355 if cur and len(cur) > 2:
358 if action == 0: #reset
359 eDVBCI_UI.getInstance().setReset(slot)
360 elif action == 1: #init
361 eDVBCI_UI.getInstance().setInit(slot)
362 elif self.state[slot] == 2:
363 self.dlg = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, action)
366 for slot in range(MAX_NUM_CI):
367 state = eDVBCI_UI.getInstance().getState(slot)
369 CiHandler.unregisterCIMessageHandler(slot)