add possibility to use ValueRange as ValueEqual Converter
[enigma2.git] / lib / python / Components / Converter / ServiceInfo.py
1 from Components.Converter.Converter import Converter
2 from enigma import iServiceInformation, iPlayableService
3 from Components.Element import cached
4
5 class ServiceInfo(Converter, object):
6         HAS_TELETEXT = 0
7         IS_MULTICHANNEL = 1
8         IS_CRYPTED = 2
9         IS_WIDESCREEN = 3
10         SUBSERVICES_AVAILABLE = 4
11         XRES = 5
12         YRES = 6
13
14         def __init__(self, type):
15                 Converter.__init__(self, type)
16                 self.type = {
17                                 "HasTelext": self.HAS_TELETEXT,
18                                 "IsMultichannel": self.IS_MULTICHANNEL,
19                                 "IsCrypted": self.IS_CRYPTED,
20                                 "IsWidescreen": self.IS_WIDESCREEN,
21                                 "SubservicesAvailable": self.SUBSERVICES_AVAILABLE,
22                                 "VideoWidth": self.XRES,
23                                 "VideoHeight": self.YRES,
24                         }[type]
25
26                 self.interesting_events = {
27                                 self.HAS_TELETEXT: [iPlayableService.evUpdatedInfo],
28                                 self.IS_MULTICHANNEL: [iPlayableService.evUpdatedInfo],
29                                 self.IS_CRYPTED: [iPlayableService.evUpdatedInfo],
30                                 self.IS_WIDESCREEN: [iPlayableService.evVideoSizeChanged],
31                                 self.SUBSERVICES_AVAILABLE: [iPlayableService.evUpdatedEventInfo],
32                                 self.XRES: [iPlayableService.evVideoSizeChanged],
33                                 self.YRES: [iPlayableService.evVideoSizeChanged],
34                         }[self.type]
35
36         def getServiceInfoString(self, info, what):
37                 v = info.getInfo(what)
38                 if v == -1:
39                         return "N/A"
40                 if v == -2:
41                         return info.getInfoString(what)
42                 return "%d" % v
43
44         @cached
45         def getBoolean(self):
46                 service = self.source.service
47                 info = service and service.info()
48                 if not info:
49                         return False
50                 
51                 if self.type == self.HAS_TELETEXT:
52                         tpid = info.getInfo(iServiceInformation.sTXTPID)
53                         return tpid != -1
54                 elif self.type == self.IS_MULTICHANNEL:
55                         # FIXME. but currently iAudioTrackInfo doesn't provide more information.
56                         audio = service.audioTracks()
57                         if audio:
58                                 n = audio.getNumberOfTracks()
59                                 for x in range(n):
60                                         i = audio.getTrackInfo(x)
61                                         description = i.getDescription();
62                                         if description.find("AC3") != -1 or description.find("DTS") != -1:
63                                                 return True
64                         return False
65                 elif self.type == self.IS_CRYPTED:
66                         return info.getInfo(iServiceInformation.sIsCrypted) == 1
67                 elif self.type == self.IS_WIDESCREEN:
68                         return info.getInfo(iServiceInformation.sAspect) in [3, 4, 7, 8, 0xB, 0xC, 0xF, 0x10]
69                 elif self.type == self.SUBSERVICES_AVAILABLE:
70                         subservices = service.subServices()
71                         return subservices and subservices.getNumberOfSubservices() > 0
72
73         boolean = property(getBoolean)
74         
75         @cached
76         def getText(self):
77                 service = self.source.service
78                 info = service and service.info()
79                 if not info:
80                         return ""
81
82                 if self.type == self.XRES:
83                         return self.getServiceInfoString(info, iServiceInformation.sVideoWidth)
84                 if self.type == self.YRES:
85                         return self.getServiceInfoString(info, iServiceInformation.sVideoHeight)
86                 return ""
87
88         text = property(getText)
89
90         @cached
91         def getValue(self):
92                 service = self.source.service
93                 info = service and service.info()
94                 if not info:
95                         return -1
96
97                 if self.type == self.XRES:
98                         return info.getInfo(iServiceInformation.sVideoWidth)
99                 if self.type == self.YRES:
100                         return info.getInfo(iServiceInformation.sVideoHeight)
101
102                 return -1
103
104         value = property(getValue)
105
106         def changed(self, what):
107                 if what[0] != self.CHANGED_SPECIFIC or what[1] in self.interesting_events:
108                         Converter.changed(self, what)