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