do not delete timer.. (sefault in some situations)
[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 class CiConfigList(HTMLComponent, GUIComponent):
16         def __init__(self, list):
17                 GUIComponent.__init__(self)
18                 self.l = eListboxPythonConfigContent()
19                 self.l.setList(list)
20                 self.l.setSeperation(100)
21                 self.list = list
22
23         def toggle(self):
24                 pass
25
26         def handleKey(self, key):
27                 selection = self.getCurrent()
28                 selection[1].handleKey(key)
29                 self.invalidateCurrent()
30
31         def getCurrent(self):
32                 return self.l.getCurrentSelection()
33
34         def invalidateCurrent(self):
35                 self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
36
37         def invalidate(self, entry):
38                 i = 0
39                 for x in self.list:
40                         if (entry.getConfigPath() == x[1].parent.getConfigPath()):
41                                 self.l.invalidateEntry(i)
42                         i += 1
43                 pass
44
45         def GUIcreate(self, parent):
46                 self.instance = eListbox(parent)
47                 self.instance.setContent(self.l)
48
49         def GUIdelete(self):
50                 self.instance.setContent(None)
51                 self.instance = None
52
53 class CiMmi(Screen):
54         def addEntry(self, list, entry):
55                 if entry[0] == "TEXT":          #handle every item (text / pin only?)
56                         #list.append( (entry[1], entry[2]) )
57                         list.append( (entry[1], entry[2]) )
58                 if entry[0] == "PIN":
59                         if entry[3] == 1:
60                                 # masked pins:
61                                 x = configElement_nonSave("", configSequence, [1234], configsequencearg.get("PINCODE", (entry[1], "-")))
62                         else:                           
63                                 # unmasked pins:
64                                 x = configElement_nonSave("", configSequence, [1234], configsequencearg.get("PINCODE", (entry[1], "")))                 
65                         
66                         list.append( (entry[2], 0) )    
67                         self.pin = getConfigListEntry("",x)
68                         list.append( self.pin )
69
70         def okbuttonClick(self):
71                 print "ok"
72                 if self.tag == "WAIT":
73                         print "do nothing - wait"
74                 elif self.tag == "MENU":
75                         print "answer MENU"
76                         eDVBCI_UI.getInstance().answerMenu(self.slotid, self["entries"].getCurrent()[1])
77                         self.showWait() 
78                 elif self.tag == "LIST":
79                         print "answer LIST"
80                         eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
81                         self.showWait() 
82                 elif self.tag == "ENQ":
83                         print "answer ENQ"
84                         eDVBCI_UI.getInstance().answerEnq(self.slotid, str(self.pin[1].parent.value))
85                         self.showWait() 
86
87         def closeMmi(self):
88                 self.Timer.stop()
89                 self.close()
90
91         def keyCancel(self):
92                 print "keyCancel"
93                 if self.tag == "WAIT":
94                         self.closeMmi()
95                 elif self.tag == "MENU":
96                         eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
97                         self.showWait() 
98                 elif self.tag == "LIST":
99                         eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
100                         self.showWait() 
101                 elif self.tag == "ENQ":
102                         eDVBCI_UI.getInstance().cancelEnq(self.slotid)
103                         self.showWait() 
104                 else:
105                         print "give cancel action to ci"        
106
107         def keyNumberGlobal(self, number):
108                 self["entries"].handleKey(config.key[str(number)])
109
110         def keyLeft(self):
111                 self["entries"].handleKey(config.key["prevElement"])
112
113         def keyRight(self):
114                 self["entries"].handleKey(config.key["nextElement"])
115
116         def updateList(self, list):
117                 self["entries"].list = list
118                 self["entries"].l.setList(list)
119
120         def showWait(self):
121                 self.tag = "WAIT"
122                 self["title"].setText("")
123                 self["subtitle"].setText("")
124                 self["bottom"].setText("")
125                 list = [ ]
126                 list.append( ("wait for ci...", 0) )
127                 self.updateList(list)
128                 
129         def showScreen(self):
130                 screen = eDVBCI_UI.getInstance().getMMIScreen(self.slotid)
131         
132                 list = [ ]
133
134                 self.tag = screen[0][0]
135                 
136                 for entry in screen:
137                         if entry[0] == "TITLE":
138                                 self["title"].setText(entry[1])
139                         elif entry[0] == "SUBTITLE":
140                                 self["subtitle"].setText(entry[1])
141                         elif entry[0] == "BOTTOM":
142                                 self["bottom"].setText(entry[1])
143                         elif entry[0] == "TEXT":
144                                 self.addEntry(list, entry)
145                         elif entry[0] == "PIN":
146                                 self.addEntry(list, entry)
147
148                 self.updateList(list)
149
150         def TimerCheck(self):
151
152                 if self.action == 0:                    #reset
153                         self.closeMmi()
154                 if self.action == 1:                    #init
155                         self.closeMmi()
156
157                 #module still there ?                   
158                 if eDVBCI_UI.getInstance().getState(self.slotid) != 2:
159                         self.closeMmi()
160
161                 #mmi session still active ?                     
162                 if eDVBCI_UI.getInstance().getMMIState(self.slotid) != 1:
163                         self.closeMmi()
164                         
165                 #new screen available?  
166                 if eDVBCI_UI.getInstance().availableMMI(self.slotid) == 1:
167                         self.showScreen()
168                         
169                 #FIXME: check for mmi-session closed    
170                         
171         def __init__(self, session, slotid, action):
172                 Screen.__init__(self, session)
173                 
174                 print "ciMMI with action" + str(action)
175
176                 self.slotid = slotid
177
178                 self.Timer = eTimer()
179                 self.Timer.timeout.get().append(self.TimerCheck)
180                 self.Timer.start(1000)
181
182                 #else the skins fails
183                 self["title"] = Label("")
184                 self["subtitle"] = Label("")
185                 self["bottom"] = Label("")
186                 self["entries"] = MenuList([ ])
187                 #self["entries"] = CiConfigList([ ])
188
189                 self["actions"] = NumberActionMap(["SetupActions"],
190                         {
191                                 "ok": self.okbuttonClick,
192                                 "cancel": self.keyCancel,
193                                 #for PIN
194                                 "left": self.keyLeft,
195                                 "right": self.keyRight,
196                                 "1": self.keyNumberGlobal,
197                                 "2": self.keyNumberGlobal,
198                                 "3": self.keyNumberGlobal,
199                                 "4": self.keyNumberGlobal,
200                                 "5": self.keyNumberGlobal,
201                                 "6": self.keyNumberGlobal,
202                                 "7": self.keyNumberGlobal,
203                                 "8": self.keyNumberGlobal,
204                                 "9": self.keyNumberGlobal,
205                                 "0": self.keyNumberGlobal
206                         }, -1)
207                 
208                 self.action = action
209
210                 if action == 0:                 #reset
211                         eDVBCI_UI.getInstance().setReset(self.slotid)
212                         self.showWait() 
213                 elif action == 1:               #init
214                         pass
215                         self.showWait() 
216                 elif action == 2:               #start MMI
217                         eDVBCI_UI.getInstance().startMMI(self.slotid)
218                         self.showWait() 
219                 elif action == 3:               #mmi already there (called from infobar)
220                         self.showScreen()       
221                         
222 class CiSelection(Screen):
223         def createMenu(self):
224                 self.list = [ ]
225                 self.list.append( ("Reset", 0) )
226                 self.list.append( ("Init", 1) )
227                 
228                 self.state = eDVBCI_UI.getInstance().getState(0)
229                 if self.state == 0:                     #no module
230                         self.list.append( ("no module found", 2) )
231                 elif self.state == 1:           #module in init
232                         self.list.append( ("init module", 2) )
233                 elif self.state == 2:           #module ready
234                         #get appname            
235                         appname = eDVBCI_UI.getInstance().getAppName(0)
236                         self.list.append( (appname, 2) )
237
238                 self["entries"] .list = self.list
239                 self["entries"] .l.setList(self.list)
240
241         def TimerCheck(self):
242                 state = eDVBCI_UI.getInstance().getState(0)
243                 if self.state != state:
244                         #print "something happens"
245                         self.state = state
246                         self.createMenu()
247         
248         def okbuttonClick(self):
249                 self.slot = 0
250         
251                 if self.state == 2:
252                         self.session.open(CiMmi, 0, self["entries"].getCurrent()[1])
253
254                 #generate menu / list
255                 #list = [ ]
256                 #list.append( ("TEXT", "CA-Info") )
257                 #list.append( ("TEXT", "Card Status") )
258                 #list.append( ("PIN", 6, "Card Pin", 1) )
259                 #self.session.open(CiMmi, 0, 0, "Wichtiges CI", "Mainmenu", "Footer", list)
260
261         def cancel(self):
262                 self.Timer.stop()
263                 self.close()
264                 
265         def __init__(self, session):
266                 #FIXME support for one ci only
267                 Screen.__init__(self, session)
268                 
269                 self["actions"] = ActionMap(["OkCancelActions"], 
270                         {
271                                 "ok": self.okbuttonClick,
272                                 "cancel": self.cancel
273                         })
274
275                 self.list = [ ]
276                 self["entries"] = MenuList(list)
277                 self.createMenu()
278
279                 self.Timer = eTimer()
280                 self.Timer.timeout.get().append(self.TimerCheck)
281                 self.Timer.start(1000)