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")
20 def __init__(self, session, slotid, action):
21 Screen.__init__(self, session)
23 print "ciMMI 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 if action == 2: #start MMI
59 eDVBCI_UI.getInstance().startMMI(self.slotid)
61 elif action == 3: #mmi already there (called from infobar)
64 def addEntry(self, list, entry):
65 if entry[0] == "TEXT": #handle every item (text / pin only?)
66 list.append( (entry[1], ConfigNothing(), entry[2]) )
71 x = ConfigPIN(0, len = pinlength, censor = "*")
74 x = ConfigPIN(0, len = pinlength)
75 self["subtitle"].setText(entry[2])
76 list.append( getConfigListEntry("", x) )
77 self["bottom"].setText(_("please press OK when ready"))
79 def okbuttonClick(self):
83 if self.tag == "WAIT":
84 print "do nothing - wait"
85 elif self.tag == "MENU":
87 cur = self["entries"].getCurrent()
89 eDVBCI_UI.getInstance().answerMenu(self.slotid, cur[2])
91 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
93 elif self.tag == "LIST":
95 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
97 elif self.tag == "ENQ":
98 cur = self["entries"].getCurrent()
99 answer = str(cur[1].value)
101 while length < cur[1].getLength():
104 eDVBCI_UI.getInstance().answerEnq(self.slotid, answer)
109 self.close(self.slotid)
115 if self.tag == "WAIT":
116 eDVBCI_UI.getInstance().stopMMI(self.slotid)
118 elif self.tag in [ "MENU", "LIST" ]:
120 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
122 elif self.tag == "ENQ":
124 eDVBCI_UI.getInstance().cancelEnq(self.slotid)
127 print "give cancel action to ci"
129 def keyConfigEntry(self, key):
132 self["entries"].handleKey(key)
136 def keyNumberGlobal(self, number):
138 self.keyConfigEntry(KEY_0 + number)
142 self.keyConfigEntry(KEY_LEFT)
146 self.keyConfigEntry(KEY_RIGHT)
148 def updateList(self, list):
149 List = self["entries"]
151 List.instance.moveSelectionTo(0)
158 self["title"].setText("")
159 self["subtitle"].setText("")
160 self["bottom"].setText("")
162 list.append( (_("wait for ci..."), ConfigNothing()) )
163 self.updateList(list)
165 def showScreen(self):
166 screen = eDVBCI_UI.getInstance().getMMIScreen(self.slotid)
171 if len(screen) > 0 and screen[0][0] == "CLOSE":
172 timeout = screen[0][1]
174 self.timer.start(timeout*1000, True)
178 self.tag = screen[0][0]
180 if entry[0] == "PIN":
181 self.addEntry(list, entry)
183 if entry[0] == "TITLE":
184 self["title"].setText(entry[1])
185 elif entry[0] == "SUBTITLE":
186 self["subtitle"].setText(entry[1])
187 elif entry[0] == "BOTTOM":
188 self["bottom"].setText(entry[1])
189 elif entry[0] == "TEXT":
190 self.addEntry(list, entry)
191 self.updateList(list)
193 def ciStateChanged(self):
194 if self.action == 0: #reset
196 if self.action == 1: #init
199 #module still there ?
200 if eDVBCI_UI.getInstance().getState(self.slotid) != 2:
203 #mmi session still active ?
204 if eDVBCI_UI.getInstance().getMMIState(self.slotid) != 1:
207 if self.action > 1 and eDVBCI_UI.getInstance().availableMMI(self.slotid) == 1:
210 #FIXME: check for mmi-session closed
212 class CiMessageHandler:
217 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
219 def setSession(self, session):
220 self.session = session
222 def ciStateChanged(self, slot):
226 if slot in self.dlgs:
227 self.dlgs[slot].ciStateChanged()
228 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
230 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, 3)
232 def dlgClosed(self, slot):
233 if slot in self.dlgs:
236 def registerCIMessageHandler(self, slot, func):
237 self.unregisterCIMessageHandler(slot)
240 def unregisterCIMessageHandler(self, slot):
244 CiHandler = CiMessageHandler()
246 class CiSelection(Screen):
247 def __init__(self, session):
248 Screen.__init__(self, session)
249 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
251 "left": self.keyLeft,
252 "right": self.keyLeft,
253 "ok": self.okbuttonClick,
254 "cancel": self.cancel
261 for slot in range(MAX_NUM_CI):
262 state = eDVBCI_UI.getInstance().getState(slot)
264 self.appendEntries(slot, state)
265 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
267 menuList = ConfigList(self.list)
268 menuList.list = self.list
269 menuList.l.setList(self.list)
270 self["entries"] = menuList
271 self["entries"].onSelectionChanged.append(self.selectionChanged)
272 self["text"] = Label(_("Slot %d")%(1))
274 def selectionChanged(self):
275 cur_idx = self["entries"].getCurrentIndex()
276 self["text"].setText(_("Slot %d")%((cur_idx / 4)+1))
278 def keyConfigEntry(self, key):
280 self["entries"].handleKey(key)
281 self["entries"].getCurrent()[1].save()
286 self.keyConfigEntry(KEY_LEFT)
289 self.keyConfigEntry(KEY_RIGHT)
291 def appendEntries(self, slot, state):
292 self.state[slot] = state
293 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
294 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
296 if self.state[slot] == 0: #no module
297 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
298 elif self.state[slot] == 1: #module in init
299 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
300 elif self.state[slot] == 2: #module ready
302 appname = eDVBCI_UI.getInstance().getAppName(slot)
303 self.list.append( (appname, ConfigNothing(), 2, slot) )
305 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
307 def updateState(self, slot):
308 state = eDVBCI_UI.getInstance().getState(slot)
309 self.state[slot] = state
312 while len(self.list[slotidx]) < 3 or self.list[slotidx][3] != slot:
315 slotidx += 1 # do not change Reset
316 slotidx += 1 # do not change Init
318 if state == 0: #no module
319 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
320 elif state == 1: #module in init
321 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
322 elif state == 2: #module ready
324 appname = eDVBCI_UI.getInstance().getAppName(slot)
325 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
327 lst = self["entries"]
329 lst.l.setList(self.list)
331 def ciStateChanged(self, slot):
333 self.dlg.ciStateChanged()
335 state = eDVBCI_UI.getInstance().getState(slot)
336 if self.state[slot] != state:
337 #print "something happens"
338 self.state[slot] = state
339 self.updateState(slot)
341 def dlgClosed(self, slot):
344 def okbuttonClick(self):
345 cur = self["entries"].getCurrent()
346 if cur and len(cur) > 2:
349 if action == 0: #reset
350 eDVBCI_UI.getInstance().setReset(slot)
351 elif action == 1: #init
352 eDVBCI_UI.getInstance().setInit(slot)
353 elif self.state[slot] == 2:
354 self.dlg = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, action)
357 for slot in range(MAX_NUM_CI):
358 state = eDVBCI_UI.getInstance().getState(slot)
360 CiHandler.unregisterCIMessageHandler(slot)