help: improve key description, a bit.
[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
21                 if self.lastQuery == 2:
22                         eDVBCI_UI.getInstance().stopMMI(self.slot)
23
24                 self.close()
25
26         def TimerCheck(self):
27                 #special cases to prevent to fast resets/inits
28                 if self.lastQuery == 0:
29                         self.cancel()
30                 elif self.lastQuery == 1:
31                         self.cancel()
32                 else:
33                         if eDVBCI_UI.getInstance().getState(self.slot) != 2:    #module removed
34                                 self.cancel()
35
36         def __init__(self, session, slot, query):
37                 Screen.__init__(self, session)
38
39                 self["message"] = Label(_("waiting for CI..."))
40
41                 self["actions"] = ActionMap(["OkCancelActions"], 
42                         {
43                                 "cancel": self.cancel
44                         })
45                         
46                 self.lastQuery = query
47                 self.slot = slot
48
49                 self.Timer = eTimer()
50                 self.Timer.timeout.get().append(self.TimerCheck)
51                 self.Timer.start(1000)                                  #check and block 1 second
52
53                 if query == 0:                                                                  #reset
54                         print "reset"
55                         eDVBCI_UI.getInstance().setReset(slot)
56                 if query == 1:                                                                  #init
57                         print "init"
58                         eDVBCI_UI.getInstance().initialize(slot)
59                 if query == 2:                                                                  #mmi-open
60                         print "mmi open"
61                         eDVBCI_UI.getInstance().startMMI(slot)
62                 if query == 3:                                                                  #mmi-answer
63                         print "mmi answer"
64                         eDVBCI_UI.getInstance().answerMMI(slot, 0, 0)
65                         
66
67 class CiEntryList(HTMLComponent, GUIComponent):
68         def __init__(self, list):
69                 GUIComponent.__init__(self)
70                 self.l = eListboxPythonConfigContent()
71                 self.l.setList(list)
72                 self.l.setSeperation(100)
73                 self.list = list
74
75         def toggle(self):
76                 selection = self.getCurrent()
77                 selection[1].toggle()
78                 self.invalidateCurrent()
79
80         def handleKey(self, key):
81                 #not every element got an .handleKey
82                 try:
83                         selection = self.getCurrent()
84                         selection[1].handleKey(key)
85                         self.invalidateCurrent()
86                 except: 
87                         pass    
88
89         def getCurrent(self):
90                 return self.l.getCurrentSelection()
91
92         def getCurrentIndex(self):
93                 return self.l.getCurrentSelectionIndex()
94
95         def invalidateCurrent(self):
96                 self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
97
98         def GUIcreate(self, parent):
99                 self.instance = eListbox(parent)
100                 self.instance.setContent(self.l)
101
102         def GUIdelete(self):
103                 self.instance.setContent(None)
104                 self.instance = None
105
106 class CiMmi(Screen):
107         def addEntry(self, list, entry, index):
108                 if entry[0] == "TEXT":          #handle every item (text / pin only?)
109                         list.append( (entry[1], index) )
110                 if entry[0] == "PIN":
111                         if entry[3] == 1:
112                                 # masked pins:
113                                 x = configElement_nonSave("", configSequence, [1234], configsequencearg.get("PINCODE", (entry[1], "-")))
114                         else:                           
115                                 # unmasked pins:
116                                 x = configElement_nonSave("", configSequence, [1234], configsequencearg.get("PINCODE", (entry[1], "")))                 
117                                 
118                         self.pin = getConfigListEntry(entry[2],x)
119                         list.append( self.pin )
120
121         def okbuttonClick(self):
122                 if self.tag == 0:       #ENQ
123                         print "enq- answer pin:" +  str(self.pin[1].parent.value[0])
124                         #ci[self.slotid]->getInstance().mmiEnqAnswer(self.pin[1].parent.value[0])
125                 elif self.tag == 1:     #Menu
126                         print "answer - actual:" + str(self["entries"].getCurrentIndex())
127                         #ci[self.slotid]->getInstance().mmiAnswer(self["entries"].getCurrentIndex())
128                 elif self.tag == 2:     #List
129                         print "answer on List - send 0"
130                         #ci[self.slotid]->getInstance().mmiAnswer(0)
131                 self.close()
132
133         def keyNumberGlobal(self, number):
134                 self["entries"].handleKey(config.key[str(number)])
135
136         def keyLeft(self):
137                 self["entries"].handleKey(config.key["prevElement"])
138
139         def keyRight(self):
140                 self["entries"].handleKey(config.key["nextElement"])
141
142         def keyCancel(self):
143                 print "keyCancel"
144                 self.close()
145                 
146                 #tag is 0=ENQ 1=Menu 2=List
147         def __init__(self, session, slotid, tag, title, subtitle, bottom, entries):
148                 Screen.__init__(self, session)
149
150                 self.slotid = slotid
151                 self.tag = tag
152                 self["title"] = Label(title)
153                 self["subtitle"] = Label(subtitle)
154                 self["bottom"] = Label(bottom)
155                                 
156                 list = [ ]
157                 cnt = 0
158                 for entry in entries:
159                         self.addEntry(list, entry, cnt)
160                         cnt = cnt + 1
161                 self["entries"] = CiEntryList(list)
162
163                 self["actions"] = NumberActionMap(["SetupActions"],
164                         {
165                                 "ok": self.okbuttonClick,
166                                 "cancel": self.keyCancel,
167                                 #for PIN
168                                 "left": self.keyLeft,
169                                 "right": self.keyRight,
170                                 "1": self.keyNumberGlobal,
171                                 "2": self.keyNumberGlobal,
172                                 "3": self.keyNumberGlobal,
173                                 "4": self.keyNumberGlobal,
174                                 "5": self.keyNumberGlobal,
175                                 "6": self.keyNumberGlobal,
176                                 "7": self.keyNumberGlobal,
177                                 "8": self.keyNumberGlobal,
178                                 "9": self.keyNumberGlobal,
179                                 "0": self.keyNumberGlobal
180                         }, -1)
181
182
183 class CiSelection(Screen):
184         def createMenu(self):
185                 self.list = [ ]
186                 self.list.append( ("Reset", 0) )
187                 self.list.append( ("Init", 1) )
188                 
189                 self.state = eDVBCI_UI.getInstance().getState(0)
190                 if self.state == 0:                     #no module
191                         self.list.append( ("no module found", 2) )
192                 elif self.state == 1:           #module in init
193                         self.list.append( ("init module", 2) )
194                 elif self.state == 2:           #module ready
195                         #get appname            
196                         appname = eDVBCI_UI.getInstance().getAppName(0)
197                         self.list.append( (appname, 2) )
198
199                 self["entries"] .list = self.list
200                 self["entries"] .l.setList(self.list)
201
202         def TimerCheck(self):
203                 state = eDVBCI_UI.getInstance().getState(0)
204                 if self.state != state:
205                         print "something happens"
206                         self.state = state
207                         self.createMenu()
208         
209         def okbuttonClick(self):
210                 if self.state == 2:
211                         #FIXME: find out the correct slot
212                         self.session.open(CiWait, 0, self["entries"].getCurrent()[1])
213
214                 #generate menu / list
215                 #list = [ ]
216                 #list.append( ("TEXT", "CA-Info") )
217                 #list.append( ("TEXT", "Card Status") )
218                 #list.append( ("PIN", 6, "Card Pin", 1) )
219                 #self.session.open(CiMmi, 0, 0, "Wichtiges CI", "Mainmenu", "Footer", list)
220
221         def cancel(self):
222                 self.Timer.stop()
223                 self.close()
224                 
225         def __init__(self, session):
226                 #FIXME support for one ci only
227                 Screen.__init__(self, session)
228                 
229                 self["actions"] = ActionMap(["OkCancelActions"], 
230                         {
231                                 "ok": self.okbuttonClick,
232                                 "cancel": self.cancel
233                         })
234
235                 self.list = [ ]
236                 self["entries"] = CiEntryList(list)
237                 self.createMenu()
238
239                 self.Timer = eTimer()
240                 self.Timer.timeout.get().append(self.TimerCheck)
241                 self.Timer.start(1000)