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