19ee474b1fb1f5695f1954939f8abb417e830bd7
[enigma2.git] / lib / python / Screens / Ci.py
1 from Screen import *
2 from Components.MenuList import MenuList
3 from Components.ActionMap import ActionMap
4 from Components.ActionMap import NumberActionMap
5 from Components.Header import Header
6 from Components.Button import Button
7 from Components.Label import Label
8
9 from Components.HTMLComponent import *
10 from Components.GUIComponent import *
11 from Components.config import *
12
13 from enigma import *
14
15 #use this class to synchronize all ci to/from user communications
16 class CiWait(Screen):
17         def cancel(self):
18                 #stop pending requests
19                 self.Timer.stop()
20                 self.close()
21
22         def Keycancel(self):
23                 if self.lastQuery >= 2:
24                         eDVBCI_UI.getInstance().stopMMI(self.slot)
25                 self.parent.mmistate = 0
26                 self.cancel()
27
28         def TimerCheck(self):
29                 #special cases to prevent to fast resets/inits
30                 if self.lastQuery == 0:                 #reset requested
31                         self.Keycancel()
32                 elif self.lastQuery == 1:               #init requested
33                         self.Keycancel()
34                 elif self.lastQuery == 4:               #close requested
35                         self.Keycancel()
36                 else:
37                         if eDVBCI_UI.getInstance().getState(self.slot) != 2:    #module removed
38                                 self.Keycancel()
39                         else:   
40                                 if eDVBCI_UI.getInstance().availableMMI(self.slot) == 1:        #data?
41                                         self.parent.mmistate = 2        #request screen
42                                         self.cancel()
43
44         def __init__(self, session, parent, slot, query):
45                 Screen.__init__(self, session)
46
47                 self["message"] = Label(_("waiting for CI..."))
48
49                 self["actions"] = ActionMap(["OkCancelActions"], 
50                         {
51                                 "cancel": self.Keycancel
52                         })
53                 
54                 self.parent = parent    
55                 self.lastQuery = query
56                 self.slot = slot
57
58                 self.Timer = eTimer()
59                 self.Timer.timeout.get().append(self.TimerCheck)
60                 self.Timer.start(1000)                                  #check and block 1 second
61
62                 if query == 0:                                                                  #reset
63                         #print "reset"
64                         eDVBCI_UI.getInstance().setReset(slot)
65                 if query == 1:                                                                  #init
66                         #print "init"
67                         eDVBCI_UI.getInstance().initialize(slot)
68                 if query == 2:                                                                  #mmi-open
69                         #print "mmi open"
70                         eDVBCI_UI.getInstance().startMMI(slot)
71                 if query == 3:                                                                  #mmi-answer
72                         #print "mmi answer"
73                         if self.parent.answertype == 0: #ENQ
74                                 eDVBCI_UI.getInstance().answerEnq(slot, self.parent.answertype, self.parent.answer)
75                         elif self.parent.answertype == 1: #ENQ cancel
76                                 eDVBCI_UI.getInstance().answerEnq(slot, self.parent.answertype, "")
77                         elif self.parent.answertype == 2: #Menu
78                                 eDVBCI_UI.getInstance().answerMenu(slot, self.parent.answer)
79                         elif self.parent.answertype == 3: #List
80                                 eDVBCI_UI.getInstance().answerMenu(slot, self.parent.answer)
81                 if query == 4:                                                                  #mmi-close
82                         #print "mmi close"
83                         pass
84                         
85
86 class CiEntryList(HTMLComponent, GUIComponent):
87         def __init__(self, list):
88                 GUIComponent.__init__(self)
89                 self.l = eListboxPythonConfigContent()
90                 self.l.setList(list)
91                 self.l.setSeperation(100)
92                 self.list = list
93
94         def toggle(self):
95                 selection = self.getCurrent()
96                 selection[1].toggle()
97                 self.invalidateCurrent()
98
99         def handleKey(self, key):
100                 #not every element got an .handleKey
101                 try:
102                         selection = self.getCurrent()
103                         selection[1].handleKey(key)
104                         self.invalidateCurrent()
105                 except: 
106                         pass    
107
108         def getCurrent(self):
109                 return self.l.getCurrentSelection()
110
111         def getCurrentIndex(self):
112                 return self.l.getCurrentSelectionIndex()
113
114         def invalidateCurrent(self):
115                 self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
116
117         def GUIcreate(self, parent):
118                 self.instance = eListbox(parent)
119                 self.instance.setContent(self.l)
120
121         def GUIdelete(self):
122                 self.instance.setContent(None)
123                 self.instance = None
124
125 class CiMmi(Screen):
126         def addEntry(self, list, entry):
127                 if entry[0] == "TEXT":          #handle every item (text / pin only?)
128                         list.append( (entry[1], entry[2]) )
129                 if entry[0] == "PIN":
130                         if entry[3] == 1:
131                                 # masked pins:
132                                 x = configElement_nonSave("", configSequence, [1234], configsequencearg.get("PINCODE", (entry[1], "-")))
133                         else:                           
134                                 # unmasked pins:
135                                 x = configElement_nonSave("", configSequence, [1234], configsequencearg.get("PINCODE", (entry[1], "")))                 
136                                 
137                         self.pin = getConfigListEntry(entry[2],x)
138                         list.append( self.pin )
139
140         def closeMMI(self, cancel):
141                 if self.tag == "ENQ":
142                         #print "enq- answer pin:" +  str(self.pin[1].parent.value[0])
143                         if cancel == 0:
144                                 self.parent.answertype = 0
145                                 self.parent.answer = str(self.pin[1].parent.value[0])
146                         else:   
147                                 self.parent.answertype = 1
148                                 self.parent.answer = 0
149                 elif self.tag == "MENU":
150                         #print "answer - actual:" + str(self["entries"].getCurrent()[1])
151                         self.parent.answertype = 2
152                         if cancel == 0:
153                                 self.parent.answer = self["entries"].getCurrent()[1]
154                         else:   
155                                 self.parent.answer = 0
156                 elif self.tag == "LIST":
157                         #print "answer on List"
158                         self.parent.answertype = 3
159                         if cancel == 0:
160                                 self.parent.answer = self["entries"].getCurrent()[1]
161                         else:   
162                                 self.parent.answer = 0
163
164                 self.parent.mmistate = 4        #request wait
165                 self.close()
166
167         def okbuttonClick(self):
168                 self.closeMMI(0)
169
170         def keyCancel(self):
171                 print "keyCancel"
172                 self.closeMMI(1)
173
174         def keyNumberGlobal(self, number):
175                 self["entries"].handleKey(config.key[str(number)])
176
177         def keyLeft(self):
178                 self["entries"].handleKey(config.key["prevElement"])
179
180         def keyRight(self):
181                 self["entries"].handleKey(config.key["nextElement"])
182
183         def __init__(self, session, parent, slotid, appname, entries):
184                 Screen.__init__(self, session)
185
186                 self.parent = parent
187                 self.slotid = slotid
188                 self.tag = entries[0][0]
189                 
190                 #else the skins fails
191                 self["title"] = Label("")
192                 self["subtitle"] = Label("")
193                 self["bottom"] = Label("")
194
195                 list = [ ]
196                 
197                 for entry in entries:
198                         if entry[0] == "TITLE":
199                                 self["title"] = Label(entry[1])
200                         elif entry[0] == "SUBTITLE":
201                                 self["subtitle"] = Label(entry[1])
202                         elif entry[0] == "BOTTOM":
203                                 self["bottom"] = Label(entry[1])                                
204                         elif entry[0] == "TEXT":
205                                 self.addEntry(list, entry)
206                         elif entry[0] == "PIN":
207                                 self.addEntry(list, entry)
208
209                 self["entries"] = CiEntryList(list)
210
211                 self["actions"] = NumberActionMap(["SetupActions"],
212                         {
213                                 "ok": self.okbuttonClick,
214                                 "cancel": self.keyCancel,
215                                 #for PIN
216                                 "left": self.keyLeft,
217                                 "right": self.keyRight,
218                                 "1": self.keyNumberGlobal,
219                                 "2": self.keyNumberGlobal,
220                                 "3": self.keyNumberGlobal,
221                                 "4": self.keyNumberGlobal,
222                                 "5": self.keyNumberGlobal,
223                                 "6": self.keyNumberGlobal,
224                                 "7": self.keyNumberGlobal,
225                                 "8": self.keyNumberGlobal,
226                                 "9": self.keyNumberGlobal,
227                                 "0": self.keyNumberGlobal
228                         }, -1)
229
230
231 class CiSelection(Screen):
232         def createMenu(self):
233                 self.list = [ ]
234                 self.list.append( ("Reset", 0) )
235                 self.list.append( ("Init", 1) )
236                 
237                 self.state = eDVBCI_UI.getInstance().getState(0)
238                 if self.state == 0:                     #no module
239                         self.list.append( ("no module found", 2) )
240                 elif self.state == 1:           #module in init
241                         self.list.append( ("init module", 2) )
242                 elif self.state == 2:           #module ready
243                         #get appname            
244                         appname = eDVBCI_UI.getInstance().getAppName(0)
245                         self.list.append( (appname, 2) )
246
247                 self["entries"] .list = self.list
248                 self["entries"] .l.setList(self.list)
249
250         def TimerCheck(self):
251                 state = eDVBCI_UI.getInstance().getState(0)
252                 if self.state != state:
253                         #print "something happens"
254                         self.state = state
255                         self.createMenu()
256         
257         def ciWaitAnswer(self):
258                 #FIXME: handling for correct slot
259                 #print "ciWaitAnswer with self.mmistate = " + str(self.mmistate)
260
261                 if self.mmistate == 0:          
262                         #print "do nothing"
263                         pass
264                 elif self.mmistate == 1:                        #wait requested
265                         #print "wait requested"
266                         self.session.openWithCallback(self.ciWaitAnswer, CiWait, self, 0, self["entries"].getCurrent()[1])
267                 elif self.mmistate == 2:                        #open screen requested
268                         #print "open screen requested"
269                         self.answertype = -1
270                         self.answer = ""
271                         appname = eDVBCI_UI.getInstance().getAppName(0)
272                         list = eDVBCI_UI.getInstance().getMMIScreen(self.slot)
273                         self.session.openWithCallback(self.ciWaitAnswer, CiMmi, self, self.slot, appname, list)
274                 elif self.mmistate == 3:                        #close mmi requested
275                         #print "close mmi requested"
276                         self.session.openWithCallback(self.ciWaitAnswer, CiWait, self, 0, 4)
277                 elif self.mmistate == 4:                        #mmi answer requested
278                         #print "mmi answer requested"
279                         self.session.openWithCallback(self.ciWaitAnswer, CiWait, self, 0, 3)
280                 
281         def okbuttonClick(self):
282                 self.slot = 0
283         
284                 if self.state == 2:
285                         self.mmistate = 1
286                         self.ciWaitAnswer()
287
288                 #generate menu / list
289                 #list = [ ]
290                 #list.append( ("TEXT", "CA-Info") )
291                 #list.append( ("TEXT", "Card Status") )
292                 #list.append( ("PIN", 6, "Card Pin", 1) )
293                 #self.session.open(CiMmi, 0, 0, "Wichtiges CI", "Mainmenu", "Footer", list)
294
295         def cancel(self):
296                 self.Timer.stop()
297                 self.close()
298                 
299         def __init__(self, session):
300                 #FIXME support for one ci only
301                 Screen.__init__(self, session)
302                 
303                 self["actions"] = ActionMap(["OkCancelActions"], 
304                         {
305                                 "ok": self.okbuttonClick,
306                                 "cancel": self.cancel
307                         })
308
309                 self.list = [ ]
310                 self["entries"] = CiEntryList(list)
311                 self.createMenu()
312
313                 self.Timer = eTimer()
314                 self.Timer.timeout.get().append(self.TimerCheck)
315                 self.Timer.start(1000)