close screen when session is closed
[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                 #mmi session still active ?                     
115                 if eDVBCI_UI.getInstance().getMMIState(self.slotid) != 1:
116                         self.closeMmi()
117                         
118                 #new screen available?  
119                 if eDVBCI_UI.getInstance().availableMMI(self.slotid) == 1:
120                         self.showScreen()
121                         
122                 #FIXME: check for mmi-session closed    
123                         
124         def __init__(self, session, slotid, action):
125                 Screen.__init__(self, session)
126                 
127                 print "ciMMI with action" + str(action)
128
129                 self.slotid = slotid
130
131                 self.Timer = eTimer()
132                 self.Timer.timeout.get().append(self.TimerCheck)
133                 self.Timer.start(1000)
134
135                 #else the skins fails
136                 self["title"] = Label("")
137                 self["subtitle"] = Label("")
138                 self["bottom"] = Label("")
139                 self["entries"] = MenuList([ ])
140
141                 self["actions"] = NumberActionMap(["SetupActions"],
142                         {
143                                 "ok": self.okbuttonClick,
144                                 "cancel": self.keyCancel,
145                                 #for PIN
146                                 "left": self.keyLeft,
147                                 "right": self.keyRight,
148                                 "1": self.keyNumberGlobal,
149                                 "2": self.keyNumberGlobal,
150                                 "3": self.keyNumberGlobal,
151                                 "4": self.keyNumberGlobal,
152                                 "5": self.keyNumberGlobal,
153                                 "6": self.keyNumberGlobal,
154                                 "7": self.keyNumberGlobal,
155                                 "8": self.keyNumberGlobal,
156                                 "9": self.keyNumberGlobal,
157                                 "0": self.keyNumberGlobal
158                         }, -1)
159                 
160                 self.action = action
161
162                 if action == 0:                 #reset
163                         eDVBCI_UI.getInstance().setReset(self.slotid)
164                         self.showWait() 
165                 elif action == 1:               #init
166                         pass
167                         self.showWait() 
168                 elif action == 2:               #start MMI
169                         eDVBCI_UI.getInstance().startMMI(self.slotid)
170                         self.showWait() 
171                 elif action == 3:               #mmi already there (called from infobar)
172                         self.showScreen()       
173                         
174 class CiSelection(Screen):
175         def createMenu(self):
176                 self.list = [ ]
177                 self.list.append( ("Reset", 0) )
178                 self.list.append( ("Init", 1) )
179                 
180                 self.state = eDVBCI_UI.getInstance().getState(0)
181                 if self.state == 0:                     #no module
182                         self.list.append( ("no module found", 2) )
183                 elif self.state == 1:           #module in init
184                         self.list.append( ("init module", 2) )
185                 elif self.state == 2:           #module ready
186                         #get appname            
187                         appname = eDVBCI_UI.getInstance().getAppName(0)
188                         self.list.append( (appname, 2) )
189
190                 self["entries"] .list = self.list
191                 self["entries"] .l.setList(self.list)
192
193         def TimerCheck(self):
194                 state = eDVBCI_UI.getInstance().getState(0)
195                 if self.state != state:
196                         #print "something happens"
197                         self.state = state
198                         self.createMenu()
199         
200         def okbuttonClick(self):
201                 self.slot = 0
202         
203                 if self.state == 2:
204                         self.session.open(CiMmi, 0, self["entries"].getCurrent()[1])
205
206                 #generate menu / list
207                 #list = [ ]
208                 #list.append( ("TEXT", "CA-Info") )
209                 #list.append( ("TEXT", "Card Status") )
210                 #list.append( ("PIN", 6, "Card Pin", 1) )
211                 #self.session.open(CiMmi, 0, 0, "Wichtiges CI", "Mainmenu", "Footer", list)
212
213         def cancel(self):
214                 self.Timer.stop()
215                 self.close()
216                 
217         def __init__(self, session):
218                 #FIXME support for one ci only
219                 Screen.__init__(self, session)
220                 
221                 self["actions"] = ActionMap(["OkCancelActions"], 
222                         {
223                                 "ok": self.okbuttonClick,
224                                 "cancel": self.cancel
225                         })
226
227                 self.list = [ ]
228                 self["entries"] = MenuList(list)
229                 self.createMenu()
230
231                 self.Timer = eTimer()
232                 self.Timer.timeout.get().append(self.TimerCheck)
233                 self.Timer.start(1000)