add possibility to select between different list styles via context menu
[enigma2.git] / lib / python / Components / Converter / ServiceInfo.py
index 413aa19..7118025 100644 (file)
@@ -1,5 +1,6 @@
 from Components.Converter.Converter import Converter
 from enigma import iServiceInformation, iPlayableService
+from Components.Element import cached
 
 class ServiceInfo(Converter, object):
        HAS_TELETEXT = 0
@@ -7,31 +8,40 @@ class ServiceInfo(Converter, object):
        IS_CRYPTED = 2
        IS_WIDESCREEN = 3
        SUBSERVICES_AVAILABLE = 4
+       XRES = 5
+       YRES = 6
 
-       def __init__(self, type, *args, **kwargs):
-               Converter.__init__(self)
+       def __init__(self, type):
+               Converter.__init__(self, type)
                self.type = {
                                "HasTelext": self.HAS_TELETEXT,
                                "IsMultichannel": self.IS_MULTICHANNEL,
                                "IsCrypted": self.IS_CRYPTED,
                                "IsWidescreen": self.IS_WIDESCREEN,
                                "SubservicesAvailable": self.SUBSERVICES_AVAILABLE,
+                               "VideoWidth": self.XRES,
+                               "VideoHeight": self.YRES,
                        }[type]
 
                self.interesting_events = {
-                               self.HAS_TELETEXT: [iPlayableService.evEnd, iPlayableService.evUpdatedInfo],
-                               self.IS_MULTICHANNEL: [iPlayableService.evUpdatedInfo, iPlayableService.evEnd],
-                               self.IS_CRYPTED: [iPlayableService.evUpdatedInfo, iPlayableService.evEnd],
-                               self.IS_WIDESCREEN: [iPlayableService.evUpdatedEventInfo, iPlayableService.evEnd],
-                               self.SUBSERVICES_AVAILABLE: [iPlayableService.evUpdatedEventInfo, iPlayableService.evEnd]
+                               self.HAS_TELETEXT: [iPlayableService.evUpdatedInfo],
+                               self.IS_MULTICHANNEL: [iPlayableService.evUpdatedInfo],
+                               self.IS_CRYPTED: [iPlayableService.evUpdatedInfo],
+                               self.IS_WIDESCREEN: [iPlayableService.evVideoSizeChanged],
+                               self.SUBSERVICES_AVAILABLE: [iPlayableService.evUpdatedEventInfo],
+                               self.XRES: [iPlayableService.evVideoSizeChanged],
+                               self.YRES: [iPlayableService.evVideoSizeChanged],
                        }[self.type]
 
-       def getServiceInfoValue(self, info, what):
+       def getServiceInfoString(self, info, what):
                v = info.getInfo(what)
-               if v != -2:
+               if v == -1:
                        return "N/A"
-               return info.getInfoString(what)
+               if v == -2:
+                       return info.getInfoString(what)
+               return "%d" % v
 
+       @cached
        def getBoolean(self):
                service = self.source.service
                info = service and service.info()
@@ -61,3 +71,38 @@ class ServiceInfo(Converter, object):
                        return subservices and subservices.getNumberOfSubservices() > 0
 
        boolean = property(getBoolean)
+       
+       @cached
+       def getText(self):
+               service = self.source.service
+               info = service and service.info()
+               if not info:
+                       return ""
+
+               if self.type == self.XRES:
+                       return self.getServiceInfoString(info, iServiceInformation.sVideoWidth)
+               if self.type == self.YRES:
+                       return self.getServiceInfoString(info, iServiceInformation.sVideoHeight)
+               return ""
+
+       text = property(getText)
+
+       @cached
+       def getValue(self):
+               service = self.source.service
+               info = service and service.info()
+               if not info:
+                       return -1
+
+               if self.type == self.XRES:
+                       return info.getInfo(iServiceInformation.sVideoWidth)
+               if self.type == self.YRES:
+                       return info.getInfo(iServiceInformation.sVideoHeight)
+
+               return -1
+
+       value = property(getValue)
+
+       def changed(self, what):
+               if what[0] != self.CHANGED_SPECIFIC or what[1] in self.interesting_events:
+                       Converter.changed(self, what)