Added TransponderInfo parameter for Servicename in skin. It can be limite for using...
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / ServiceName.py
1 # -*- coding: utf-8 -*-
2 from Components.Converter.Converter import Converter
3 from enigma import iServiceInformation, iPlayableService, iPlayableServicePtr, eServiceCenter
4 from Components.Element import cached
5 from ServiceReference import resolveAlternate,  ServiceReference
6 from Tools.Transponder import ConvertToHumanReadable
7 from Components.NimManager import nimmanager
8 from Components.Converter.ChannelNumbers import channelnumbers
9 import Screens.InfoBar
10
11 class ServiceName(Converter, object):
12         NAME = 0
13         PROVIDER = 1
14         REFERENCE = 2
15         EDITREFERENCE = 3
16         TRANSPONDER = 4
17
18         def __init__(self, type):
19                 Converter.__init__(self, type)
20
21                 self.mode = ""
22                 if ';' in type:
23                         type, self.mode = type.split(';')
24
25                 if type == "Provider":
26                         self.type = self.PROVIDER
27                 elif type == "Reference":
28                         self.type = self.REFERENCE
29                 elif type == "EditReference":
30                         self.type = self.EDITREFERENCE
31                 elif type == "TransponderInfo":
32                         self.type = self.TRANSPONDER
33                 else:
34                         self.type = self.NAME
35
36         @cached
37         def getText(self):
38                 service = self.source.service
39                 if isinstance(service, iPlayableServicePtr):
40                         info = service and service.info()
41                         ref = None
42                 else: # reference
43                         info = service and self.source.info
44                         ref = service
45                 if not info:
46                         return ""
47                 if self.type == self.NAME:
48                         name = ref and info.getName(ref)
49                         if name is None:
50                                 name = info.getName()
51                         return name.replace('\xc2\x86', '').replace('\xc2\x87', '')
52                 elif self.type == self.PROVIDER:
53                         return info.getInfoString(iServiceInformation.sProvider)
54                 elif self.type == self.REFERENCE or self.type == self.EDITREFERENCE and hasattr(self.source, "editmode") and self.source.editmode:
55                         if not ref:
56                                 return info.getInfoString(iServiceInformation.sServiceref)
57                         nref = resolveAlternate(ref)
58                         if nref:
59                                 ref = nref
60                         return ref.toString()
61                 elif self.type == self.TRANSPONDER:
62                         if ref:
63                                 nref = resolveAlternate(ref)
64                                 if nref:
65                                         ref = nref
66                                         info = eServiceCenter.getInstance().info(ref)
67                                 transponder_info = info.getInfoObject(ref, iServiceInformation.sTransponderData)
68                         else:
69                                 transponder_info = info.getInfoObject(iServiceInformation.sTransponderData)
70                         if "InRootOnly" in self.mode and not self.rootBouquet():
71                                 return ""
72                         if transponder_info:
73                                 self.t_info = ConvertToHumanReadable(transponder_info)
74                                 if "DVB-T" in self.system():
75                                         return  self.dvb_t()
76                                 elif "DVB-C" in self.system():
77                                         return self.dvb_c()
78                                 return  self.dvb_s()
79                         return ""
80
81         text = property(getText)
82
83         def changed(self, what):
84                 if what[0] != self.CHANGED_SPECIFIC or what[1] in (iPlayableService.evStart,):
85                         Converter.changed(self, what)
86
87         def dvb_s(self):
88                 return "%s %d %s %d %s %s" % (self.system(), self.freq()/1000, self.polar(), self.s_rate()/1000, self.fec(), self.orb_pos())
89         def dvb_t(self):
90                 return "%s %s %d/%s" % (self.system(), self.ch_number(), self.freq()/1000000 + 0.5 , self.bandwidth())
91         def dvb_c(self):
92                 return "%s %d %s %s" % (self.system(), self.freq()/1000, _("kHz"), self.bandwidth())
93         def system(self):
94                 return self.t_info["system"]
95         def freq(self):
96                 return self.t_info["frequency"]
97         def bandwidth(self):
98                 return self.t_info["bandwidth"]
99         def s_rate(self):
100                 return self.t_info["symbol_rate"]
101         def polar(self):
102                 return self.t_info["polarization"][0]
103         def orb_pos(self):
104                 op = self.t_info["orbital_position"].split(' ')[0]
105                 return "%s°%s" % (op[:-1],op[-1:])
106         def fec(self):
107                 return self.t_info["fec_inner"]
108         def ch_number(self):
109                 for n in nimmanager.nim_slots:
110                         if n.isCompatible("DVB-T"):
111                                 channel = channelnumbers.getChannelNumber(self.freq(), n.slot)
112                                 if channel:
113                                         return _("CH") + "%s" % channel
114                 return ""
115
116         def rootBouquet(self):
117                 servicelist = Screens.InfoBar.InfoBar.instance.servicelist
118                 epg_bouquet = servicelist and servicelist.getRoot()
119                 if ServiceReference(epg_bouquet).getServiceName():
120                         return False
121                 return True