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