Merge branch 'bug_274_disable_fast_winding_for_non_ts'
[enigma2.git] / lib / python / Plugins / SystemPlugins / CommonInterfaceAssignment / plugin.py
1 from Screens.Screen import Screen
2 from Screens.ChannelSelection import *
3 from Components.ActionMap import HelpableActionMap, ActionMap, NumberActionMap
4 from Components.Sources.List import List
5 from Components.Sources.StaticText import StaticText
6 from Components.config import ConfigNothing
7 from Components.ConfigList import ConfigList
8 from Components.Label import Label
9 from Components.SelectionList import SelectionList
10 from Components.MenuList import MenuList
11 from ServiceReference import ServiceReference
12 from Plugins.Plugin import PluginDescriptor
13 from xml.etree.cElementTree import parse as ci_parse
14 from Tools.XMLTools import elementsWithTag, mergeText, stringToXML
15 from enigma import eDVBCI_UI, eDVBCIInterfaces
16
17 from os import system, path as os_path
18
19 class CIselectMainMenu(Screen):
20         skin = """
21                 <screen name="CIselectMainMenu" position="center,center" size="500,250" title="CI assignment" >
22                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
23                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
24                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
25                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
26                         <widget name="CiList" position="5,50" size="490,200" scrollbarMode="showOnDemand" />
27                 </screen>"""
28
29         def __init__(self, session, args = 0):
30
31                 Screen.__init__(self, session)
32
33                 self["key_red"] = StaticText(_("Close"))
34                 self["key_green"] = StaticText(_("Edit"))
35
36                 self["actions"] = ActionMap(["ColorActions","SetupActions"],
37                         {
38                                 "green": self.greenPressed,
39                                 "red": self.close,
40                                 "ok": self.greenPressed,
41                                 "cancel": self.close
42                         }, -1)
43
44                 NUM_CI=eDVBCIInterfaces.getInstance().getNumOfSlots()
45
46                 print "[CI_Wizzard] FOUND %d CI Slots " % NUM_CI
47
48                 self.dlg = None
49                 self.state = { }
50                 self.list = [ ]
51                 if NUM_CI > 0:
52                         for slot in range(NUM_CI):
53                                 state = eDVBCI_UI.getInstance().getState(slot)
54                                 if state == 0:
55                                         appname = _("Slot %d") %(slot+1) + " - " + _("no module found")
56                                 elif state == 1:        
57                                         appname = _("Slot %d") %(slot+1) + " - " + _("init modules")
58                                 elif state == 2:
59                                         appname = _("Slot %d") %(slot+1) + " - " + eDVBCI_UI.getInstance().getAppName(slot)
60                                 self.list.append( (appname, ConfigNothing(), 0, slot) )
61                 else:
62                         self.list.append( (_("no CI slots found") , ConfigNothing(), 1, -1) )
63
64                 menuList = ConfigList(self.list)
65                 menuList.list = self.list
66                 menuList.l.setList(self.list)
67                 self["CiList"] = menuList
68                 self.onShown.append(self.setWindowTitle)
69
70         def setWindowTitle(self):
71                 self.setTitle(_("CI assignment"))
72
73         def greenPressed(self):
74                 cur = self["CiList"].getCurrent()
75                 if cur and len(cur) > 2:
76                         action = cur[2]
77                         slot = cur[3]
78                         if action == 1:
79                                 print "[CI_Wizzard] there is no CI Slot in your receiver"
80                         else:
81                                 print "[CI_Wizzard] selected CI Slot : %d" % slot
82                                 if config.usage.setup_level.index > 1: # advanced
83                                         self.session.open(CIconfigMenu, slot)
84                                 else:
85                                         self.session.open(easyCIconfigMenu, slot)
86
87         """def yellowPressed(self): # unused
88                 NUM_CI=eDVBCIInterfaces.getInstance().getNumOfSlots()
89                 print "[CI_Check] FOUND %d CI Slots " % NUM_CI
90                 if NUM_CI > 0:
91                         for ci in range(NUM_CI):
92                                 print eDVBCIInterfaces.getInstance().getDescrambleRules(ci)"""
93
94
95 class CIconfigMenu(Screen):
96         skin = """
97                 <screen name="CIconfigMenu" position="center,center" size="560,440" title="CI assignment" >
98                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
99                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
100                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
101                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
102                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
103                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
104                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
105                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
106                         <widget source="CAidList_desc" render="Label" position="5,50" size="550,22" font="Regular;20"  backgroundColor="#25062748" transparent="1" />
107                         <widget source="CAidList" render="Label" position="5,80" size="550,45" font="Regular;20"  backgroundColor="#25062748" transparent="1" />
108                         <ePixmap pixmap="skin_default/div-h.png" position="0,125" zPosition="1" size="560,2" />
109                         <widget source="ServiceList_desc" render="Label" position="5,130" size="550,22" font="Regular;20" backgroundColor="#25062748" transparent="1"  />
110                         <widget name="ServiceList" position="5,160" size="550,250" zPosition="1" scrollbarMode="showOnDemand" />
111                         <widget source="ServiceList_info" render="Label" position="5,160" size="550,250" zPosition="2" font="Regular;20" backgroundColor="#25062748" transparent="1"  />
112                 </screen>"""
113
114         def __init__(self, session, ci_slot="9"):
115
116                 Screen.__init__(self, session)
117                 self.ci_slot=ci_slot
118                 self.filename="/etc/enigma2/ci"+str(self.ci_slot)+".xml"
119
120                 self["key_red"] = StaticText(_("Delete"))
121                 self["key_green"] = StaticText(_("add Service"))
122                 self["key_yellow"] = StaticText(_("add Provider"))
123                 self["key_blue"] = StaticText(_("select CAId"))
124                 self["CAidList_desc"] = StaticText(_("assigned CAIds:"))
125                 self["CAidList"] = StaticText()
126                 self["ServiceList_desc"] = StaticText(_("assigned Services/Provider:"))
127                 self["ServiceList_info"] = StaticText()
128
129                 self["actions"] = ActionMap(["ColorActions","SetupActions"],
130                         {
131                                 "green": self.greenPressed,
132                                 "red": self.redPressed,
133                                 "yellow": self.yellowPressed,
134                                 "blue": self.bluePressed,
135                                 "cancel": self.cancel
136                         }, -1)
137
138                 print "[CI_Wizzard_Config] Configuring CI Slots : %d  " % self.ci_slot
139
140                 i=0
141                 self.caidlist=[]
142                 print eDVBCIInterfaces.getInstance().readCICaIds(self.ci_slot)
143                 for caid in eDVBCIInterfaces.getInstance().readCICaIds(self.ci_slot):
144                         i+=1
145                         self.caidlist.append((str(hex(int(caid))),str(caid),i))
146
147                 print "[CI_Wizzard_Config_CI%d] read following CAIds from CI: %s" %(self.ci_slot, self.caidlist)
148
149                 self.selectedcaid = []
150                 self.servicelist = []
151                 self.caids = ""
152
153                 serviceList = ConfigList(self.servicelist)
154                 serviceList.list = self.servicelist
155                 serviceList.l.setList(self.servicelist)
156                 self["ServiceList"] = serviceList
157
158                 self.loadXML()
159                 # if config mode !=advanced autoselect any caid
160                 if config.usage.setup_level.index <= 1: # advanced
161                         self.selectedcaid=self.caidlist
162                         self.finishedCAidSelection(self.selectedcaid)
163                 self.onShown.append(self.setWindowTitle)
164
165         def setWindowTitle(self):
166                 self.setTitle(_("CI assignment"))
167
168         def redPressed(self):
169                 self.delete()
170
171         def greenPressed(self):
172                 self.session.openWithCallback( self.finishedChannelSelection, myChannelSelection, None)
173
174         def yellowPressed(self):
175                 self.session.openWithCallback( self.finishedProviderSelection, myProviderSelection, None)
176
177         def bluePressed(self):
178                 self.session.openWithCallback(self.finishedCAidSelection, CAidSelect, self.caidlist, self.selectedcaid)
179
180         def cancel(self):
181                 self.saveXML()
182                 activate_all(self)
183                 self.close()
184
185         def setServiceListInfo(self):
186                 if len(self.servicelist):
187                         self["ServiceList_info"].setText("")
188                 else:
189                         self["ServiceList_info"].setText(_("no Services/Providers selected"))
190
191         def delete(self):
192                 cur = self["ServiceList"].getCurrent()
193                 if cur and len(cur) > 2:
194                         self.servicelist.remove(cur)
195                 self["ServiceList"].l.setList(self.servicelist)
196                 self.setServiceListInfo()
197
198         def finishedChannelSelection(self, *args):
199                 if len(args):
200                         ref=args[0]
201                         service_ref = ServiceReference(ref)
202                         service_name = service_ref.getServiceName()
203                         if find_in_list(self.servicelist, service_name, 0)==False:
204                                 split_ref=service_ref.ref.toString().split(":")
205                                 if split_ref[0] == "1":#== dvb service und nicht muell von None
206                                         self.servicelist.append( (service_name , ConfigNothing(), 0, service_ref.ref.toString()) )
207                                         self["ServiceList"].l.setList(self.servicelist)
208                                         self.setServiceListInfo()
209
210         def finishedProviderSelection(self, *args):
211                 if len(args)>1: # bei nix selected kommt nur 1 arg zurueck (==None)
212                         name=args[0]
213                         dvbnamespace=args[1]
214                         if find_in_list(self.servicelist, name, 0)==False:
215                                 self.servicelist.append( (name , ConfigNothing(), 1, dvbnamespace) )
216                                 self["ServiceList"].l.setList(self.servicelist)
217                                 self.setServiceListInfo()
218
219         def finishedCAidSelection(self, *args):
220                 if len(args):
221                         self.selectedcaid=args[0]
222                         self.caids=""
223                         if len(self.selectedcaid):
224                                 for item in self.selectedcaid:
225                                         if len(self.caids):
226                                                 self.caids+= ", " + item[0]
227                                         else:
228                                                 self.caids=item[0]
229                         else:
230                                 self.selectedcaid=[]
231                                 self.caids=_("no CAId selected")
232                 else:
233                         self.selectedcaid=[]
234                         self.caids=_("no CAId selected")
235                 self["CAidList"].setText(self.caids)
236
237         def saveXML(self):
238                 try:
239                         fp = file(self.filename, 'w')
240                         fp.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n")
241                         fp.write("<ci>\n")
242                         fp.write("\t<slot>\n")
243                         fp.write("\t\t<id>%s</id>\n" % self.ci_slot)
244                         for item in self.selectedcaid:
245                                 if len(self.selectedcaid):
246                                         fp.write("\t\t<caid id=\"%s\" />\n" % item[0])
247                         for item in self.servicelist:
248                                 if len(self.servicelist):
249                                         if item[2]==1:
250                                                 fp.write("\t\t<provider name=\"%s\" dvbnamespace=\"%s\" />\n" % (item[0], item[3]))
251                                         else:
252                                                 fp.write("\t\t<service name=\"%s\" ref=\"%s\" />\n"  % (item[0], item[3]))
253                         fp.write("\t</slot>\n")
254                         fp.write("</ci>\n")
255                         fp.close()
256                 except:
257                         print "[CI_Config_CI%d] xml not written" %self.ci_slot
258                         os.unlink(self.filename)
259
260         def loadXML(self):
261                 if not os_path.exists(self.filename):
262                         return
263
264                 def getValue(definitions, default):
265                         ret = ""
266                         Len = len(definitions)
267                         return Len > 0 and definitions[Len-1].text or default
268
269                 try:
270                         tree = ci_parse(self.filename).getroot()
271                         self.read_services=[]
272                         self.read_providers=[]
273                         self.usingcaid=[]
274                         self.ci_config=[]
275                         for slot in tree.findall("slot"):
276                                 read_slot = getValue(slot.findall("id"), False).encode("UTF-8")
277                                 print "ci " + read_slot
278
279                                 i=0
280                                 for caid in slot.findall("caid"):
281                                         read_caid = caid.get("id").encode("UTF-8")
282                                         self.selectedcaid.append((str(read_caid),str(read_caid),i))
283                                         self.usingcaid.append(long(read_caid,16))
284                                         i+=1
285
286                                 for service in  slot.findall("service"):
287                                         read_service_name = service.get("name").encode("UTF-8")
288                                         read_service_ref = service.get("ref").encode("UTF-8")
289                                         self.read_services.append (read_service_ref)
290
291                                 for provider in  slot.findall("provider"):
292                                         read_provider_name = provider.get("name").encode("UTF-8")
293                                         read_provider_dvbname = provider.get("dvbnamespace").encode("UTF-8")
294                                         self.read_providers.append((read_provider_name,read_provider_dvbname))
295
296                                 self.ci_config.append((int(read_slot), (self.read_services, self.read_providers, self.usingcaid)))
297                 except:
298                         print "[CI_Config_CI%d] error parsing xml..." %self.ci_slot
299
300                 for item in self.read_services:
301                         if len(item):
302                                 self.finishedChannelSelection(item)
303
304                 for item in self.read_providers:
305                         if len(item):
306                                 self.finishedProviderSelection(item[0],item[1])
307
308                 print self.ci_config
309                 self.finishedCAidSelection(self.selectedcaid)
310                 self["ServiceList"].l.setList(self.servicelist)
311                 self.setServiceListInfo()
312
313
314 class easyCIconfigMenu(CIconfigMenu):
315         skin = """
316                 <screen name="easyCIconfigMenu" position="center,center" size="560,440" title="CI assignment" >
317                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
318                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
319                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
320                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
321                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
322                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
323                         <widget source="ServiceList_desc" render="Label" position="5,50" size="550,22" font="Regular;20" backgroundColor="#25062748" transparent="1"  />
324                         <widget name="ServiceList" position="5,80" size="550,300" zPosition="1" scrollbarMode="showOnDemand" />
325                         <widget source="ServiceList_info" render="Label" position="5,80" size="550,300" zPosition="2" font="Regular;20" backgroundColor="#25062748" transparent="1"  />
326                 </screen>"""
327
328         def __init__(self, session, ci_slot="9"):
329
330                 ci=ci_slot
331                 CIconfigMenu.__init__(self, session, ci_slot)
332
333                 self["actions"] = ActionMap(["ColorActions","SetupActions"],
334                 {
335                         "green": self.greenPressed,
336                         "red": self.redPressed,
337                         "yellow": self.yellowPressed,
338                         "cancel": self.cancel
339                 })
340
341
342 class CAidSelect(Screen):
343         skin = """
344                 <screen name="CAidSelect" position="center,center" size="450,440" title="select CAId's" >
345                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
346                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
347                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
348                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
349                         <widget name="list" position="5,50" size="440,330" scrollbarMode="showOnDemand" />
350                         <ePixmap pixmap="skin_default/div-h.png" position="0,390" zPosition="1" size="450,2" />
351                         <widget source="introduction" render="Label" position="0,400" size="450,40" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
352                 </screen>"""
353
354         def __init__(self, session, list, selected_caids):
355
356                 Screen.__init__(self, session)
357
358                 self.list = SelectionList()
359                 self["list"] = self.list
360
361                 for listindex in range(len(list)):
362                         if find_in_list(selected_caids,list[listindex][0],0):
363                                 self.list.addSelection(list[listindex][0], list[listindex][1], listindex, True)
364                         else:
365                                 self.list.addSelection(list[listindex][0], list[listindex][1], listindex, False)
366
367                 self["key_red"] = StaticText(_("Cancel"))
368                 self["key_green"] = StaticText(_("Save"))
369                 self["introduction"] = StaticText(_("Press OK to select/deselect a CAId."))
370
371                 self["actions"] = ActionMap(["ColorActions","SetupActions"],
372                 {
373                         "ok": self.list.toggleSelection, 
374                         "cancel": self.cancel, 
375                         "green": self.greenPressed,
376                         "red": self.cancel
377                 }, -1)
378                 self.onShown.append(self.setWindowTitle)
379
380         def setWindowTitle(self):
381                 self.setTitle(_("select CAId's"))
382
383         def greenPressed(self):
384                 list = self.list.getSelectionsList()
385                 print list
386                 self.close(list)
387
388         def cancel(self):
389                 self.close()
390
391 class myProviderSelection(ChannelSelectionBase):
392         skin = """
393                 <screen name="myProviderSelection" position="center,center" size="560,440" title="Select provider to add...">
394                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
395                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
396                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
397                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
398                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
399                         <widget name="list" position="5,50" size="550,330" scrollbarMode="showOnDemand" />
400                         <ePixmap pixmap="skin_default/div-h.png" position="0,390" zPosition="1" size="560,2" />
401                         <widget source="introduction" render="Label" position="0,400" size="560,40" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
402                 </screen>"""
403
404         def __init__(self, session, title):
405                 ChannelSelectionBase.__init__(self, session)
406                 self.onShown.append(self.__onExecCallback)
407
408                 self["actions"] = ActionMap(["OkCancelActions", "ChannelSelectBaseActions"],
409                         {
410                                 "showFavourites": self.doNothing,
411                                 "showAllServices": self.cancel,
412                                 "showProviders": self.doNothing,
413                                 "showSatellites": self.doNothing,
414                                 "cancel": self.cancel,
415                                 "ok": self.channelSelected
416                         })
417                 self["key_red"] = StaticText(_("Close"))
418                 self["key_green"] = StaticText()
419                 self["key_yellow"] = StaticText()
420                 self["key_blue"] = StaticText()
421                 self["introduction"] = StaticText(_("Press OK to select a Provider."))
422
423         def doNothing(self):
424                 pass
425
426         def __onExecCallback(self):
427                 self.showSatellites()
428                 self.setTitle(_("Select provider to add..."))
429
430         def channelSelected(self): # just return selected service
431                 ref = self.getCurrentSelection()
432                 splited_ref=ref.toString().split(":")
433                 if ref.flags == 7 and splited_ref[6] != "0":
434                         self.dvbnamespace=splited_ref[6]
435                         self.enterPath(ref)
436                 else:
437                         self.close(ref.getName(), self.dvbnamespace)
438
439         def showSatellites(self):
440                 if not self.pathChangeDisabled:
441                         refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
442                         if not self.preEnterPath(refstr):
443                                 ref = eServiceReference(refstr)
444                                 justSet=False
445                                 prev = None
446
447                                 if self.isBasePathEqual(ref):
448                                         if self.isPrevPathEqual(ref):
449                                                 justSet=True
450                                         prev = self.pathUp(justSet)
451                                 else:
452                                         currentRoot = self.getRoot()
453                                         if currentRoot is None or currentRoot != ref:
454                                                 justSet=True
455                                                 self.clearPath()
456                                                 self.enterPath(ref, True)
457                                 if justSet:
458                                         serviceHandler = eServiceCenter.getInstance()
459                                         servicelist = serviceHandler.list(ref)
460                                         if not servicelist is None:
461                                                 while True:
462                                                         service = servicelist.getNext()
463                                                         if not service.valid(): #check if end of list
464                                                                 break
465                                                         unsigned_orbpos = service.getUnsignedData(4) >> 16
466                                                         orbpos = service.getData(4) >> 16
467                                                         if orbpos < 0:
468                                                                 orbpos += 3600
469                                                         if service.getPath().find("FROM PROVIDER") != -1:
470                                                                 service_type = _("Providers")
471                                                                 try:
472                                                                         # why we need this cast?
473                                                                         service_name = str(nimmanager.getSatDescription(orbpos))
474                                                                 except:
475                                                                         if unsigned_orbpos == 0xFFFF: #Cable
476                                                                                 service_name = _("Cable")
477                                                                         elif unsigned_orbpos == 0xEEEE: #Terrestrial
478                                                                                 service_name = _("Terrestrial")
479                                                                         else:
480                                                                                 if orbpos > 1800: # west
481                                                                                         orbpos = 3600 - orbpos
482                                                                                         h = _("W")
483                                                                                 else:
484                                                                                         h = _("E")
485                                                                                 service_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
486                                                                 service.setName("%s - %s" % (service_name, service_type))
487                                                                 self.servicelist.addService(service)
488                                                 self.servicelist.finishFill()
489                                                 if prev is not None:
490                                                         self.setCurrentSelection(prev)
491
492         def cancel(self):
493                 self.close(None)
494
495 class myChannelSelection(ChannelSelectionBase):
496         skin = """
497                 <screen name="myChannelSelection" position="center,center" size="560,440" title="Select service to add...">
498                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
499                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
500                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
501                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
502                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
503                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
504                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
505                         <widget name="list" position="5,50" size="550,330" scrollbarMode="showOnDemand" />
506                         <ePixmap pixmap="skin_default/div-h.png" position="0,390" zPosition="1" size="560,2" />
507                         <widget source="introduction" render="Label" position="0,400" size="560,40" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
508                 </screen>"""
509
510         def __init__(self, session, title):
511                 ChannelSelectionBase.__init__(self, session)
512                 self.onShown.append(self.__onExecCallback)
513
514                 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions", "ChannelSelectBaseActions"],
515                         {
516                                 "showProviders": self.doNothing,
517                                 "showSatellites": self.showAllServices,
518                                 "showAllServices": self.cancel,
519                                 "cancel": self.cancel,
520                                 "ok": self.channelSelected,
521                                 "keyRadio": self.setModeRadio,
522                                 "keyTV": self.setModeTv
523                         })
524
525                 self["key_red"] = StaticText(_("Close"))
526                 self["key_green"] = StaticText(_("All"))
527                 self["key_yellow"] = StaticText()
528                 self["key_blue"] = StaticText(_("Favourites"))
529                 self["introduction"] = StaticText(_("Press OK to select a Provider."))
530
531         def __onExecCallback(self):
532                 self.setModeTv()
533                 self.setTitle(_("Select service to add..."))
534
535         def doNothing(self):
536                 pass
537
538         def channelSelected(self): # just return selected service
539                 ref = self.getCurrentSelection()
540                 if (ref.flags & 7) == 7:
541                         self.enterPath(ref)
542                 elif not (ref.flags & eServiceReference.isMarker):
543                         ref = self.getCurrentSelection()
544                         self.close(ref)
545
546         def setModeTv(self):
547                 self.setTvMode()
548                 self.showFavourites()
549
550         def setModeRadio(self):
551                 self.setRadioMode()
552                 self.showFavourites()
553
554         def cancel(self):
555                 self.close(None)
556
557 def activate_all(session):
558         NUM_CI=eDVBCIInterfaces.getInstance().getNumOfSlots()
559         print "[CI_Activate] FOUND %d CI Slots " % NUM_CI
560         if NUM_CI > 0:
561                 ci_config=[]
562                 def getValue(definitions, default):
563                         # Initialize Output
564                         ret = ""
565                         # How many definitions are present
566                         Len = len(definitions)
567                         return Len > 0 and definitions[Len-1].text or default   
568
569                 for ci in range(NUM_CI):
570                         filename="/etc/enigma2/ci"+str(ci)+".xml"
571
572                         if not os_path.exists(filename):
573                                 print "[CI_Activate_Config_CI%d] no config file found" %ci
574
575                         try:
576                                 tree = ci_parse(filename).getroot()
577                                 read_services=[]
578                                 read_providers=[]
579                                 usingcaid=[]
580                                 for slot in tree.findall("slot"):
581                                         read_slot = getValue(slot.findall("id"), False).encode("UTF-8")
582
583                                         for caid in slot.findall("caid"):
584                                                 read_caid = caid.get("id").encode("UTF-8")
585                                                 usingcaid.append(long(read_caid,16))
586
587                                         for service in slot.findall("service"):
588                                                 read_service_ref = service.get("ref").encode("UTF-8")
589                                                 read_services.append (read_service_ref)
590
591                                         for provider in slot.findall("provider"):
592                                                 read_provider_name = provider.get("name").encode("UTF-8")
593                                                 read_provider_dvbname = provider.get("dvbnamespace").encode("UTF-8")
594                                                 read_providers.append((read_provider_name,long(read_provider_dvbname,16)))
595
596                                         ci_config.append((int(read_slot), (read_services, read_providers, usingcaid)))
597                         except:
598                                 print "[CI_Activate_Config_CI%d] error parsing xml..." %ci
599
600                 for item in ci_config:
601                         print "[CI_Activate] activate CI%d with following settings:" %item[0]
602                         print item[0]
603                         print item[1]
604                         try:
605                                 eDVBCIInterfaces.getInstance().setDescrambleRules(item[0],item[1])
606                         except:
607                                 print "[CI_Activate_Config_CI%d] error setting DescrambleRules..." %item[0]
608
609 def find_in_list(list, search, listpos=0):
610         for item in list:
611                 if item[listpos]==search:
612                         return True
613         return False
614
615 global_session = None
616
617 def sessionstart(reason, session):
618         global global_session
619         global_session = session
620
621 def autostart(reason, **kwargs):
622         global global_session
623         if reason == 0:
624                 print "[CI_Assignment] activating ci configs:"
625                 activate_all(global_session)
626         elif reason == 1:
627                 global_session = None
628
629 def main(session, **kwargs):
630         session.open(CIselectMainMenu)
631
632 def menu(menuid, **kwargs):
633         if menuid == "setup" and eDVBCIInterfaces.getInstance().getNumOfSlots():
634                 return [(_("Common Interface Assignment"), main, "ci_assign", 11)]
635         return [ ]
636
637 def Plugins(**kwargs):
638         if config.usage.setup_level.index > 1:
639                 return [PluginDescriptor( where = PluginDescriptor.WHERE_SESSIONSTART, fnc = sessionstart ),
640                                 PluginDescriptor( where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart ),
641                                 PluginDescriptor( name = "CommonInterfaceAssignment", description = _("a gui to assign services/providers/caids to common interface modules"), where = PluginDescriptor.WHERE_MENU, fnc = menu )]
642         else:
643                 return [PluginDescriptor( where = PluginDescriptor.WHERE_SESSIONSTART, fnc = sessionstart ),
644                                 PluginDescriptor( where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart ),
645                                 PluginDescriptor( name = "CommonInterfaceAssignment", description = _("a gui to assign services/providers to common interface modules"), where = PluginDescriptor.WHERE_MENU, fnc = menu )]