From d89be097be4a9ac52166c5f47cc189c5522d3441 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Fri, 1 Feb 2008 23:15:24 +0000 Subject: [PATCH] add possibilty to hide menu entries when needed hardware is not available --- data/menu.xml | 8 ++--- data/setup.xml | 6 ++-- lib/driver/avswitch.cpp | 14 ++++++++ lib/driver/avswitch.h | 1 + lib/driver/misc_options.cpp | 12 +++++++ lib/driver/misc_options.h | 1 + lib/driver/rfmod.h | 2 +- lib/python/Components/AVSwitch.py | 3 ++ lib/python/Components/Harddisk.py | 4 +++ lib/python/Components/Makefile.am | 2 +- lib/python/Components/RFmod.py | 65 +++++++++++++++++++----------------- lib/python/Components/UsageConfig.py | 3 ++ lib/python/Screens/Ci.py | 5 ++- lib/python/Screens/Menu.py | 8 +++++ lib/python/Screens/Setup.py | 5 +++ 15 files changed, 98 insertions(+), 41 deletions(-) diff --git a/data/menu.xml b/data/menu.xml index d49a570..32ef741 100644 --- a/data/menu.xml +++ b/data/menu.xml @@ -19,7 +19,7 @@ - self.session.scart.VCRSbChanged(3) + self.session.scart.VCRSbChanged(3) @@ -52,8 +52,8 @@ - - + + @@ -68,7 +68,7 @@ - + diff --git a/data/setup.xml b/data/setup.xml index 738e882..8f6399a 100644 --- a/data/setup.xml +++ b/data/setup.xml @@ -13,7 +13,7 @@ config.av.tvsystem config.av.wss config.av.defaultac3 - config.av.vcrswitch + config.av.vcrswitch config.usage.setup_level @@ -27,7 +27,7 @@ config.usage.e1like_radio_mode config.usage.on_long_powerpress config.usage.infobar_timeout - config.usage.output_12V + config.usage.output_12V config.usage.show_infobar_on_zap config.usage.show_infobar_on_skip config.usage.show_infobar_on_event_change @@ -35,7 +35,7 @@ config.usage.pip_zero_button config.usage.alternatives_priority - + config.usage.hdd_standby diff --git a/lib/driver/avswitch.cpp b/lib/driver/avswitch.cpp index d582db8..a936aa5 100644 --- a/lib/driver/avswitch.cpp +++ b/lib/driver/avswitch.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,19 @@ eAVSwitch *eAVSwitch::getInstance() return instance; } +bool eAVSwitch::haveScartSwitch() +{ + char tmp[255]; + int fd = open("/proc/stb/avs/0/input_choices", O_RDONLY); + if(fd < 0) { + eDebug("cannot open /proc/stb/avs/0/input_choices"); + return false; + } + read(fd, tmp, 255); + close(fd); + return !!strstr(tmp, "scart"); +} + void eAVSwitch::setInput(int val) { /* diff --git a/lib/driver/avswitch.h b/lib/driver/avswitch.h index 2b3b40f..cc92e20 100644 --- a/lib/driver/avswitch.h +++ b/lib/driver/avswitch.h @@ -24,6 +24,7 @@ public: ~eAVSwitch(); #endif static eAVSwitch *getInstance(); + bool haveScartSwitch(); int getVCRSlowBlanking(); void setFastBlank(int val); void setColorFormat(int format); diff --git a/lib/driver/misc_options.cpp b/lib/driver/misc_options.cpp index ecb7bdb..c567878 100644 --- a/lib/driver/misc_options.cpp +++ b/lib/driver/misc_options.cpp @@ -39,6 +39,18 @@ int Misc_Options::set_12V_output(int state) return 0; } +bool Misc_Options::detected_12V_output() +{ + int fd = open("/proc/stb/misc/12V_output", O_WRONLY); + if (fd < 0) + { + eDebug("couldn't open /proc/stb/misc/12V_output"); + return false; + } + close(fd); + return true; +} + Misc_Options *Misc_Options::getInstance() { return instance; diff --git a/lib/driver/misc_options.h b/lib/driver/misc_options.h index 6baf2cf..8192494 100644 --- a/lib/driver/misc_options.h +++ b/lib/driver/misc_options.h @@ -15,6 +15,7 @@ public: static Misc_Options *getInstance(); int set_12V_output(int val); int get_12V_output() { return m_12V_output_state; } + bool detected_12V_output(); }; #endif // __misc_options_h diff --git a/lib/driver/rfmod.h b/lib/driver/rfmod.h index 909a08d..56f9ef5 100644 --- a/lib/driver/rfmod.h +++ b/lib/driver/rfmod.h @@ -16,7 +16,7 @@ public: ~eRFmod(); #endif static eRFmod *getInstance(); - + bool detected() { return fd >= 0; } void setFunction(int val); //0=Enable 1=Disable void setTestmode(int val); //0=Enable 1=Disable void setSoundFunction(int val); //0=Enable 1=Disable diff --git a/lib/python/Components/AVSwitch.py b/lib/python/Components/AVSwitch.py index d3224fd..ab17fd8 100644 --- a/lib/python/Components/AVSwitch.py +++ b/lib/python/Components/AVSwitch.py @@ -1,5 +1,6 @@ from config import config, ConfigSelection, ConfigYesNo, ConfigEnableDisable, ConfigSubsection, ConfigBoolean from enigma import eAVSwitch +from SystemInfo import SystemInfo class AVSwitch: INPUT = { "ENCODER": (0, 4), "SCART": (1, 3), "AUX": (2, 4) } @@ -120,3 +121,5 @@ def InitAVSwitch(): config.av.wss.addNotifier(setWSS) iAVSwitch.setInput("ENCODER") # init on startup + SystemInfo["ScartSwitch"] = eAVSwitch.getInstance().haveScartSwitch() + diff --git a/lib/python/Components/Harddisk.py b/lib/python/Components/Harddisk.py index 16736b2..8253544 100644 --- a/lib/python/Components/Harddisk.py +++ b/lib/python/Components/Harddisk.py @@ -3,6 +3,8 @@ from os import system, listdir, statvfs, popen, makedirs from Tools.Directories import SCOPE_HDD, resolveFilename from Tools.CList import CList +from SystemInfo import SystemInfo + def tryOpen(filename): try: procFile = open(filename) @@ -215,6 +217,8 @@ class HarddiskManager: hdd = Harddisk(hddNum) self.hdd.append(hdd) + SystemInfo["Harddisc"] = len(self.hdd) > 0 + # currently, this is just an enumeration of what's possible, # this probably has to be changed to support automount stuff. # still, if stuff is mounted into the correct mountpoints by diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am index 03c5d1c..7a17eb7 100644 --- a/lib/python/Components/Makefile.am +++ b/lib/python/Components/Makefile.am @@ -17,4 +17,4 @@ install_PYTHON = \ FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py \ MultiContent.py MediaPlayer.py TunerInfo.py VideoWindow.py ChoiceList.py \ Element.py Playlist.py ParentalControl.py ParentalControlList.py \ - Ipkg.py SelectionList.py Scanner.py + Ipkg.py SelectionList.py Scanner.py SystemInfo.py diff --git a/lib/python/Components/RFmod.py b/lib/python/Components/RFmod.py index be088a5..a8f7c9f 100644 --- a/lib/python/Components/RFmod.py +++ b/lib/python/Components/RFmod.py @@ -1,5 +1,6 @@ from config import config, ConfigSelection, ConfigSubsection, ConfigOnOff, ConfigSlider from enigma import eRFmod +from Components.SystemInfo import SystemInfo # CHECK ME. RFMOD_CHANNEL_MIN = 21 @@ -23,34 +24,36 @@ class RFmod: eRFmod.getInstance().setFinetune(value) def InitRFmod(): - - config.rfmod = ConfigSubsection() - config.rfmod.enable = ConfigOnOff(default=False) - config.rfmod.test = ConfigOnOff(default=False) - config.rfmod.sound = ConfigOnOff(default=True) - config.rfmod.soundcarrier = ConfigSelection(choices=[("4500","4.5 MHz"), ("5500", "5.5 MHz"), ("6000", "6.0 MHz"), ("6500", "6.5 MHz")], default="5500") - config.rfmod.channel = ConfigSelection(default = "36", choices = ["%d" % x for x in range(RFMOD_CHANNEL_MIN, RFMOD_CHANNEL_MAX)]) - config.rfmod.finetune = ConfigSlider(default=5, limits=(1, 10)) - - iRFmod = RFmod() - - def setFunction(configElement): - iRFmod.setFunction(configElement.value); - def setTestmode(configElement): - iRFmod.setTestmode(configElement.value); - def setSoundFunction(configElement): - iRFmod.setSoundFunction(configElement.value); - def setSoundCarrier(configElement): - iRFmod.setSoundCarrier(configElement.index); - def setChannel(configElement): - iRFmod.setChannel(int(configElement.value)); - def setFinetune(configElement): - iRFmod.setFinetune(configElement.value - 5); - - # this will call the "setup-val" initial - config.rfmod.enable.addNotifier(setFunction); - config.rfmod.test.addNotifier(setTestmode); - config.rfmod.sound.addNotifier(setSoundFunction); - config.rfmod.soundcarrier.addNotifier(setSoundCarrier); - config.rfmod.channel.addNotifier(setChannel); - config.rfmod.finetune.addNotifier(setFinetune); + detected = eRFmod.getInstance().detected() + SystemInfo["RfModulator"] = detected + if detected: + config.rfmod = ConfigSubsection() + config.rfmod.enable = ConfigOnOff(default=False) + config.rfmod.test = ConfigOnOff(default=False) + config.rfmod.sound = ConfigOnOff(default=True) + config.rfmod.soundcarrier = ConfigSelection(choices=[("4500","4.5 MHz"), ("5500", "5.5 MHz"), ("6000", "6.0 MHz"), ("6500", "6.5 MHz")], default="5500") + config.rfmod.channel = ConfigSelection(default = "36", choices = ["%d" % x for x in range(RFMOD_CHANNEL_MIN, RFMOD_CHANNEL_MAX)]) + config.rfmod.finetune = ConfigSlider(default=5, limits=(1, 10)) + + iRFmod = RFmod() + + def setFunction(configElement): + iRFmod.setFunction(configElement.value); + def setTestmode(configElement): + iRFmod.setTestmode(configElement.value); + def setSoundFunction(configElement): + iRFmod.setSoundFunction(configElement.value); + def setSoundCarrier(configElement): + iRFmod.setSoundCarrier(configElement.index); + def setChannel(configElement): + iRFmod.setChannel(int(configElement.value)); + def setFinetune(configElement): + iRFmod.setFinetune(configElement.value - 5); + + # this will call the "setup-val" initial + config.rfmod.enable.addNotifier(setFunction); + config.rfmod.test.addNotifier(setTestmode); + config.rfmod.sound.addNotifier(setSoundFunction); + config.rfmod.soundcarrier.addNotifier(setSoundCarrier); + config.rfmod.channel.addNotifier(setChannel); + config.rfmod.finetune.addNotifier(setFinetune); diff --git a/lib/python/Components/UsageConfig.py b/lib/python/Components/UsageConfig.py index 73538ea..36d149c 100644 --- a/lib/python/Components/UsageConfig.py +++ b/lib/python/Components/UsageConfig.py @@ -1,5 +1,6 @@ from config import ConfigSubsection, ConfigYesNo, config, ConfigSelection, ConfigText, ConfigInteger from enigma import Misc_Options, setTunerTypePriorityOrder; +from SystemInfo import SystemInfo import os def InitUsageConfig(): @@ -63,4 +64,6 @@ def InitUsageConfig(): Misc_Options.getInstance().set_12V_output(0) config.usage.output_12V.addNotifier(set12VOutput) + SystemInfo["12V_Output"] = Misc_Options.getInstance().detected_12V_output() + config.usage.keymap = ConfigText(default = "/usr/share/enigma2/keymap.xml") diff --git a/lib/python/Screens/Ci.py b/lib/python/Screens/Ci.py index d19386b..10423ad 100644 --- a/lib/python/Screens/Ci.py +++ b/lib/python/Screens/Ci.py @@ -6,7 +6,9 @@ from Components.Label import Label from Components.config import config, ConfigSubsection, ConfigSelection, ConfigSubList, getConfigListEntry, KEY_LEFT, KEY_RIGHT, KEY_0, ConfigNothing, ConfigPIN from Components.ConfigList import ConfigList -from enigma import eTimer, eDVBCI_UI +from Components.SystemInfo import SystemInfo + +from enigma import eTimer, eDVBCI_UI, eDVBCIInterfaces MAX_NUM_CI = 4 @@ -224,6 +226,7 @@ class CiMessageHandler: self.ci = { } self.dlgs = { } eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged) + SystemInfo["CommonInterface"]= eDVBCIInterfaces.getInstance().getNumOfSlots() > 0 def setSession(self, session): self.session = session diff --git a/lib/python/Screens/Menu.py b/lib/python/Screens/Menu.py index 7c084d4..ce7f2ea 100644 --- a/lib/python/Screens/Menu.py +++ b/lib/python/Screens/Menu.py @@ -5,6 +5,7 @@ from Components.Sources.StaticText import StaticText from Components.config import configfile from Components.PluginComponent import plugins from Components.config import config +from Components.SystemInfo import SystemInfo from Tools.Directories import resolveFilename, SCOPE_SKIN @@ -102,6 +103,9 @@ class Menu(Screen): self.session.openWithCallback(self.menuClosed, Setup, dialog) def addMenu(self, destList, node): + requires = node.getAttribute("requires") + if requires and not SystemInfo.get(requires, False): + return MenuTitle = _(node.getAttribute("text").encode("UTF-8") or "??") entryID = node.getAttribute("entryID") or "undefined" weight = node.getAttribute("weight") or 50 @@ -122,6 +126,9 @@ class Menu(Screen): self.close(True) def addItem(self, destList, node): + requires = node.getAttribute("requires") + if requires and not SystemInfo.get(requires, False): + return item_text = node.getAttribute("text").encode("UTF-8") entryID = node.getAttribute("entryID") or "undefined" weight = node.getAttribute("weight") or 50 @@ -173,6 +180,7 @@ class Menu(Screen): continue elif x.tagName == 'item': item_level = int(x.getAttribute("level") or "0") + if item_level <= config.usage.setup_level.index: self.addItem(list, x) count += 1 diff --git a/lib/python/Screens/Setup.py b/lib/python/Screens/Setup.py index f7b4fa5..f352e8c 100644 --- a/lib/python/Screens/Setup.py +++ b/lib/python/Screens/Setup.py @@ -1,6 +1,7 @@ from Screen import Screen from Components.ActionMap import NumberActionMap from Components.config import config, ConfigNothing +from Components.SystemInfo import SystemInfo from Components.ConfigList import ConfigListScreen from Components.Label import Label from Components.Pixmap import Pixmap @@ -133,6 +134,10 @@ class Setup(ConfigListScreen, Screen): if item_level > config.usage.setup_level.index: continue + requires = x.getAttribute("requires") + if requires and not SystemInfo.get(requires, False): + continue; + item_text = _(x.getAttribute("text").encode("UTF-8") or "??") b = eval(XMLTools.mergeText(x.childNodes)); if b == "": -- 2.7.4