add automatic downloading of latest image and possibility of backing up configuration...
[enigma2.git] / lib / python / Screens / ServiceInfo.py
index 7738e325754ae1b5f0d2de84c779c5dedc92c721..4606f883f4950175133a4eaa2340775f5ab7d47e 100644 (file)
@@ -1,11 +1,10 @@
-from Components.HTMLComponent import *
-from Components.GUIComponent import *
+from Components.HTMLComponent import HTMLComponent
+from Components.GUIComponent import GUIComponent
 from Screen import Screen
 from Components.ActionMap import ActionMap
 from Components.Label import Label
 from Screen import Screen
 from Components.ActionMap import ActionMap
 from Components.Label import Label
-from Components.MenuList import MenuList
 from ServiceReference import ServiceReference
 from ServiceReference import ServiceReference
-from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation
+from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation, eServiceCenter
 
 RT_HALIGN_LEFT = 0
 
 
 RT_HALIGN_LEFT = 0
 
@@ -15,6 +14,9 @@ TYPE_VALUE_DEC = 2
 TYPE_VALUE_HEX_DEC = 3
 TYPE_SLIDER = 4
 
 TYPE_VALUE_HEX_DEC = 3
 TYPE_SLIDER = 4
 
+def to_unsigned(x):
+       return x & 0xFFFFFFFF
+
 def ServiceInfoListEntry(a, b, valueType=TYPE_TEXT, param=4):
        res = [ ]
 
 def ServiceInfoListEntry(a, b, valueType=TYPE_TEXT, param=4):
        res = [ ]
 
@@ -24,14 +26,13 @@ def ServiceInfoListEntry(a, b, valueType=TYPE_TEXT, param=4):
        print "b:", b
        if type(b) is not str:
                if valueType == TYPE_VALUE_HEX:
        print "b:", b
        if type(b) is not str:
                if valueType == TYPE_VALUE_HEX:
-                       b = ("0x%0" + str(param) + "x") % b
+                       b = ("0x%0" + str(param) + "x") % to_unsigned(b)
                elif valueType == TYPE_VALUE_DEC:
                        b = str(b)
                elif valueType == TYPE_VALUE_HEX_DEC:
                elif valueType == TYPE_VALUE_DEC:
                        b = str(b)
                elif valueType == TYPE_VALUE_HEX_DEC:
-                       b = ("0x%0" + str(param) + "x (%dd)") % (b, b)
+                       b = ("0x%0" + str(param) + "x (%dd)") % (to_unsigned(b), b)
                else:
                else:
-                       b = str(b)              
-       
+                       b = str(b)
        
        res.append((eListboxPythonMultiContent.TYPE_TEXT, 220, 0, 350, 25, 0, RT_HALIGN_LEFT, b))
 
        
        res.append((eListboxPythonMultiContent.TYPE_TEXT, 220, 0, 350, 25, 0, RT_HALIGN_LEFT, b))
 
@@ -44,18 +45,18 @@ class ServiceInfoList(HTMLComponent, GUIComponent):
                self.list = source
                self.l.setList(self.list)
                self.l.setFont(0, gFont("Regular", 23))
                self.list = source
                self.l.setList(self.list)
                self.l.setFont(0, gFont("Regular", 23))
+               self.l.setItemHeight(25)
 
 
-       def GUIcreate(self, parent):
-               self.instance = eListbox(parent)
+       GUI_WIDGET = eListbox
+
+       def postWidgetCreate(self, instance):
                self.instance.setContent(self.l)
                self.instance.setContent(self.l)
-               self.instance.setItemHeight(25)
 
 
-       def GUIdelete(self):
-               self.instance.setContent(None)
-               self.instance = None
+TYPE_SERVICE_INFO = 1
+TYPE_TRANSPONDER_INFO = 2
 
 class ServiceInfo(Screen):
 
 class ServiceInfo(Screen):
-       def __init__(self, session):
+       def __init__(self, session, serviceref=None):
                Screen.__init__(self, session)
                
                self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
                Screen.__init__(self, session)
                
                self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
@@ -67,99 +68,160 @@ class ServiceInfo(Screen):
                        "yellow": self.transponder,
                        "blue": self.tuner
                }, -1)
                        "yellow": self.transponder,
                        "blue": self.tuner
                }, -1)
-               
-               service = session.nav.getCurrentService()
-               if service is not None:
-                       self.info = service.info()
-                       self.feinfo = service.frontendStatusInfo()
-                       print self.info.getInfoObject(iServiceInformation.sVideoPID);
-               else:
-                       self.info = None
 
 
+               if serviceref:
+                       self.type = TYPE_TRANSPONDER_INFO
+                       self["red"] = Label()
+                       self["green"] = Label()
+                       self["yellow"] = Label()
+                       self["blue"] = Label()
+                       info = eServiceCenter.getInstance().info(serviceref)
+                       self.transponder_info = info.getInfoObject(serviceref, iServiceInformation.sTransponderData)
+                       # info is a iStaticServiceInformation, not a iServiceInformation
+                       self.info = None
+                       self.feinfo = None
+               else:
+                       self.type = TYPE_SERVICE_INFO
+                       self["red"] = Label(_("Serviceinfo"))
+                       self["green"] = Label(_("PIDs"))
+                       self["yellow"] = Label(_("Transponder"))
+                       self["blue"] = Label(_("Tuner status"))
+                       service = session.nav.getCurrentService()
+                       if service is not None:
+                               self.info = service.info()
+                               self.feinfo = service.frontendInfo()
+                               print self.info.getInfoObject(iServiceInformation.sCAIDs);
+                       else:
+                               self.info = None
+                               self.feinfo = None
 
 
-               self["red"] = Label("Serviceinfo")
-               self["green"] = Label("PIDs")
-               self["yellow"] = Label("Transponder")
-               self["blue"] = Label("Tuner status")
-       
                tlist = [ ]
 
                self["infolist"] = ServiceInfoList(tlist)
                self.onShown.append(self.information)
 
        def information(self):
                tlist = [ ]
 
                self["infolist"] = ServiceInfoList(tlist)
                self.onShown.append(self.information)
 
        def information(self):
-               if self.session.nav.getCurrentlyPlayingServiceReference() is not None:
-                       name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
+               if self.type == TYPE_SERVICE_INFO:
+                       if self.session.nav.getCurrentlyPlayingServiceReference():
+                               name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
+                               refstr = self.session.nav.getCurrentlyPlayingServiceReference().toString()
+                       else:
+                               name = "N/A"
+                               refstr = "N/A"
+                       aspect = self.getServiceInfoValue(iServiceInformation.sAspect)
+                       if aspect in ( 1, 2, 5, 6, 9, 0xA, 0xD, 0xE ):
+                               aspect = "4:3"
+                       else:
+                               aspect = "16:9"
+                       width = self.info and self.info.getInfo(iServiceInformation.sVideoWidth) or -1
+                       height = self.info and self.info.getInfo(iServiceInformation.sVideoHeight) or -1
+                       if width != -1 and height != -1:
+                               Labels = ( ("Name", name, TYPE_TEXT),
+                                                  ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
+                                                  ("Videoformat", aspect, TYPE_TEXT),
+                                                  ("Videosize", "%dx%d" %(width, height), TYPE_TEXT),
+                                                  ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8),
+                                                  ("Service Reference", refstr, TYPE_TEXT))
+                       else:
+                               Labels = ( ("Name", name, TYPE_TEXT),
+                                                  ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
+                                                  ("Videoformat", aspect, TYPE_TEXT),
+                                                  ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8),
+                                                  ("Service Reference", refstr, TYPE_TEXT))
+                       self.fillList(Labels)
                else:
                else:
-                       name = "N/A"
-               Labels = ( ("Name",  name, TYPE_TEXT),
-                                  ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
-                                  ("Videoformat", self.getServiceInfoValue(iServiceInformation.sAspect), TYPE_TEXT),
-                                  ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8))
-               self.fillList(Labels)
-       
+                       if self.transponder_info:
+                               conv = { "type"                         : _("Transponder Type"),
+                                                "system"                       : _("System"),
+                                                "modulation"           : _("Modulation"),
+                                                "orbital position" : _("Orbital Position"),
+                                                "frequency"            : _("Frequency"),
+                                                "symbolrate"           : _("Symbolrate"),
+                                                "bandwidth"            : _("Bandwidth"),
+                                                "polarization"         : _("Polarization"),
+                                                "inversion"            : _("Inversion"),
+                                                "pilot"                        : _("Pilot"),
+                                                "roll off"                     : _("Rolloff"),
+                                                "fec inner"            : _("FEC"),
+                                                "code rate lp"         : _("Coderate LP"),
+                                                "code rate hp"         : _("Coderate HP"),
+                                                "constellation"        : _("Constellation"),
+                                                "transmission mode": _("Transmission Mode"),
+                                                "guard interval"       : _("Guard Interval"),
+                                                "hierarchy"            : _("Hierarchy Information") }
+                               Labels = [ ]
+                               for i in self.transponder_info.keys():
+                                       Labels.append( (conv[i], self.transponder_info[i], TYPE_TEXT) )
+                               self.fillList(Labels)
+
        def pids(self):
        def pids(self):
-               Labels = ( ("VideoPID", self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
-                                  ("AudioPID", self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
-                                  ("PCRPID", self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
-                                  ("PMTPID", self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
-                                  ("TXTPID", self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
-                                  ("TSID", self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
-                                  ("ONID", self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
-                                  ("SID", self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
-               self.fillList(Labels)
+               if self.type == TYPE_SERVICE_INFO:
+                       Labels = ( ("VideoPID", self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
+                                          ("AudioPID", self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
+                                          ("PCRPID", self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
+                                          ("PMTPID", self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
+                                          ("TXTPID", self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
+                                          ("TSID", self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
+                                          ("ONID", self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
+                                          ("SID", self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
+                       self.fillList(Labels)
+       
+       def showFrontendData(self, real):
+               if self.type == TYPE_SERVICE_INFO:
+                       frontendData = self.feinfo and self.feinfo.getAll(real)
+                       Labels = self.getFEData(frontendData)
+                       self.fillList(Labels)
        
        def transponder(self):
        
        def transponder(self):
-               frontendData = self.feinfo.getFrontendData(True)
-               Labels = self.getFEData(frontendData)
-               self.fillList(Labels)
+               if self.type == TYPE_SERVICE_INFO:
+                       self.showFrontendData(True)
                
        def tuner(self):
                
        def tuner(self):
-               frontendData = self.feinfo.getFrontendData(False)
-               Labels = self.getFEData(frontendData)
-               self.fillList(Labels)
-               
+               if self.type == TYPE_SERVICE_INFO:
+                       self.showFrontendData(False)
+
        def getFEData(self, frontendData):
        def getFEData(self, frontendData):
-               if frontendData is None:
-                       return []
-               if frontendData["tuner_type"] == "DVB-S":
-                       return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
-                                          ("Type", frontendData["tuner_type"], TYPE_TEXT),
-                                          ("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
-                                          ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
-                                          ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
-                                          ("Polarization", frontendData["polarization"], TYPE_TEXT),
-                                          ("Inversion", frontendData["inversion"], TYPE_TEXT),
-                                          ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
-                                               )
-               elif frontendData["tuner_type"] == "DVB-C":
-                       return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
-                                          ("Type", frontendData["tuner_type"], TYPE_TEXT),
-                                          ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
-                                          ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
-                                          ("Modulation", frontendData["modulation"], TYPE_TEXT),
-                                          ("Inversion", frontendData["inversion"], TYPE_TEXT),
-                                          ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
-                                               )
-               elif frontendData["tuner_type"] == "DVB-T":
-                       return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
-                                          ("Type", frontendData["tuner_type"], TYPE_TEXT),
-                                          ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
-                                          ("Inversion", frontendData["inversion"], TYPE_TEXT),
-                                          ("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
-                                          ("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
-                                          ("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
-                                          ("Constellation", frontendData["constellation"], TYPE_TEXT),
-                                          ("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
-                                          ("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
-                                          ("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
-                                               )
-               
+               if frontendData and len(frontendData):
+                       if frontendData["tuner_type"] == "DVB-S":
+                               return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
+                                                       ("Type", frontendData["system"], TYPE_TEXT),
+                                                       ("Modulation", frontendData["modulation"], TYPE_TEXT),
+                                                       ("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
+                                                       ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
+                                                       ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
+                                                       ("Polarization", frontendData["polarization"], TYPE_TEXT),
+                                                       ("Inversion", frontendData["inversion"], TYPE_TEXT),
+                                                       ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
+                                                       ("Pilot", frontendData.get("pilot", None), TYPE_TEXT),
+                                                       ("Rolloff", frontendData.get("rolloff", None), TYPE_TEXT))
+                       elif frontendData["tuner_type"] == "DVB-C":
+                               return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
+                                               ("Type", frontendData["tuner_type"], TYPE_TEXT),
+                                               ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
+                                               ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
+                                               ("Modulation", frontendData["modulation"], TYPE_TEXT),
+                                               ("Inversion", frontendData["inversion"], TYPE_TEXT),
+                                               ("FEC inner", frontendData["fec_inner"], TYPE_TEXT))
+                       elif frontendData["tuner_type"] == "DVB-T":
+                               return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
+                                               ("Type", frontendData["tuner_type"], TYPE_TEXT),
+                                               ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
+                                               ("Inversion", frontendData["inversion"], TYPE_TEXT),
+                                               ("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
+                                               ("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
+                                               ("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
+                                               ("Constellation", frontendData["constellation"], TYPE_TEXT),
+                                               ("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
+                                               ("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
+                                               ("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT))
+               return [ ]
+
        def fillList(self, Labels):
                tlist = [ ]
 
                for item in Labels:
        def fillList(self, Labels):
                tlist = [ ]
 
                for item in Labels:
-                       print item
+                       if item[1] is None:
+                               continue;
                        value = item[1]
                        if len(item) < 4:
                                tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))
                        value = item[1]
                        if len(item) < 4:
                                tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))