add webbouqueteditor (dmm plugin contest winner plugin)
[enigma2-plugins.git] / webbouqueteditor / src / WebComponents / Sources / SatellitesList.py
1 from Components.Sources.Source import Source
2 from Screens.ChannelSelection import service_types_tv, service_types_radio, FLAG_SERVICE_NEW_FOUND,MODE_TV, MODE_RADIO
3 from enigma import eServiceReference, eServiceCenter
4 from Tools.HardwareInfo import HardwareInfo
5 service_types_tv_hd = '1:7:1:0:0:0:0:0:0:0:(type == 17) || (type == 25) || (type == 134) || (type == 195)'
6
7
8 class SatellitesList(Source):
9         FETCH = 0
10
11         def __init__(self, func=FETCH):
12                 Source.__init__(self)
13                 self.func = func
14                 self.xml = ""
15                 self.mode = MODE_TV
16
17         def handleCommand(self, param):
18                 self.mode = int(param)
19
20         def do_func(self):
21                 if self.func == self.FETCH:
22                         func = self.buildList
23                 else:
24                         func = self.buildList
25                 return func(self.mode)
26
27         def buildList(self, mode):
28                 print "[WebComponents.SatellitesList] buildList with param = %d" % mode
29                 if mode == MODE_TV:
30                         s_type = service_types_tv
31                 else:
32                         s_type = service_types_radio
33                 refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(s_type)
34                 ref = eServiceReference(refstr)
35                 serviceHandler = eServiceCenter.getInstance()
36                 counter = i = 0
37                 if HardwareInfo().get_device_name() != "dm7025" and mode == MODE_TV:
38                         counter = 1
39                 while i <= counter:
40                         if i:
41                                 refstr ='%s FROM SATELLITES ORDER BY satellitePosition'%(service_types_tv_hd)
42                                 ref = eServiceReference(refstr)
43                         servicelist = serviceHandler.list(ref)
44                         if not servicelist is None:
45                                 while True:
46                                         service = servicelist.getNext()
47                                         if not service.valid(): #check if end of list
48                                                 break
49                                         unsigned_orbpos = service.getUnsignedData(4) >> 16
50                                         orbpos = service.getData(4) >> 16
51                                         if orbpos < 0:
52                                                 orbpos += 3600
53                                         if service.getPath().find("FROM PROVIDER") != -1:
54                                                 continue
55                                         elif service.getPath().find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
56                                                 service_type = _("New")
57                                         else:
58                                                 service_type = _("Services")
59                                         try:
60                                                 # why we need this cast?
61                                                 service_name = str(nimmanager.getSatDescription(orbpos))
62                                         except:
63                                                 if unsigned_orbpos == 0xFFFF: #Cable
64                                                         service_name = _("Cable")
65                                                 elif unsigned_orbpos == 0xEEEE: #Terrestrial
66                                                         service_name = _("Terrestrial")
67                                                 else:
68                                                         if orbpos > 1800: # west
69                                                                 orbpos = 3600 - orbpos
70                                                                 h = _("W")
71                                                         else:
72                                                                 h = _("E")
73                                                         service_name = ("%d.%d %s") % (orbpos / 10, orbpos % 10, h)
74                                         if i:
75                                                 service_type = "HD %s" % service_type
76                                         service.setName("%s - %s" % (service_name, service_type))
77                                         self.xml += "\t\t<e2service>\n"
78                                         self.xml += "\t\t<e2servicereference>%s</e2servicereference>\n\t\t<e2servicename>%s</e2servicename>\n" % (self.filterXML(service.toString()), self.filterXML(service.getName()))
79                                         self.xml += "\t\t</e2service>\n"
80                         i += 1
81                 return self.xml
82
83         def filterXML(self, item):
84                 item = item.replace("&", "&amp;").replace("<", "&lt;").replace('"', '&quot;').replace(">", "&gt;").replace('\xc2\x86', '').replace('\xc2\x87', '')
85                 return item
86
87         text = property(do_func)
88