From: Christian Weiske Date: Mon, 2 Sep 2013 18:20:38 +0000 (+0200) Subject: Add option to disable settings button, load option from XML page feed file X-Git-Url: https://git.cweiske.de/enigma2-curlytx.git/commitdiff_plain/5a3881a8fa5611a7defe420be7d36611a35b999d Add option to disable settings button, load option from XML page feed file --- diff --git a/README.rst b/README.rst index 0726c32..1af6c2d 100644 --- a/README.rst +++ b/README.rst @@ -103,6 +103,43 @@ If this file exists, it gets loaded unconditionally and overwrites the current page configuration. +Disable settings +================ +The page feed file may contain a tag that disables the settings button. +By using it, you can prevent people from modifying the CurlyTx settings. + +First, register the namespace:: + + + +Then, add the setting after the author or self link:: + + 0 + +Here is the example feed with disabled settings:: + + + + URL list for CurlyTx + + Christian Weiske + cweiske@cweiske.de + + + 0 + + ip + My IP + + + + temp + House temperatures + + + + + ================= Modifying CurlyTx ================= diff --git a/src/AtomFeed.py b/src/AtomFeed.py index 51da7f8..eff3eaa 100644 --- a/src/AtomFeed.py +++ b/src/AtomFeed.py @@ -11,6 +11,7 @@ import os class AtomFeed: """ Simple XML parser that extracts pages from a atom feed """ ns = "{http://www.w3.org/2005/Atom}" + nsc = "{http://ns.cweiske.de/curlytx}" errorCallback = None def __init__(self, url, callback, errorCallback): @@ -44,7 +45,12 @@ class AtomFeed: if titleE != None and titleE.text != "" and url != None: pages.append({"title": titleE.text, "url": url}) - callback(pages) + settings = dict() + for entry in list(xml): + if (entry.tag.startswith(self.nsc)): + settings[entry.tag[len(self.nsc):]] = entry.text + + callback(pages, settings) def bestLink(self, list): """ Fetch the best matching link from an atom feed entry """ diff --git a/src/CurlyTx.py b/src/CurlyTx.py index 3572601..3e74c5e 100644 --- a/src/CurlyTx.py +++ b/src/CurlyTx.py @@ -17,7 +17,7 @@ from twisted.web.client import _makeGetterFactory, HTTPClientFactory from enigma import gFont from . import config -from config import createPage, loadDefaultPageOptions, feedPagesToConfig, savePageConfig +from config import createPage, loadDefaultPageOptions, feedPagesToConfig, feedSettingsToConfig, savePageConfig from Components.config import config import os @@ -125,6 +125,11 @@ class CurlyTx(Screen, HelpableScreen): self["key_yellow"].setText(_("Prev")) self["key_blue"].setText(_("Next")) + if config.plugins.CurlyTx.enableSettings.getValue(): + self["key_red"].setText(_("Settings")) + else: + self["key_red"].setText("") + def pageUp(self): self["text"].pageUp() @@ -235,6 +240,9 @@ class CurlyTx(Screen, HelpableScreen): self.showingHeaders = True def showSettings(self): + if not config.plugins.CurlyTx.enableSettings.getValue(): + return + from CurlyTxSettings import CurlyTxSettings self.session.openWithCallback(self.onSettingsChanged, CurlyTxSettings) @@ -290,6 +298,8 @@ class CurlyTx(Screen, HelpableScreen): type = MessageBox.TYPE_ERROR ) - def saveStaticConfig(self, pages): + def saveStaticConfig(self, pages, settings): feedPagesToConfig(pages) + feedSettingsToConfig(settings) savePageConfig() + self.loadButtons() diff --git a/src/CurlyTxSettings.py b/src/CurlyTxSettings.py index ba2281c..5d39725 100644 --- a/src/CurlyTxSettings.py +++ b/src/CurlyTxSettings.py @@ -12,7 +12,7 @@ from Components.Sources.StaticText import StaticText from Screens.MessageBox import MessageBox from . import config -from config import createPage, loadDefaultPageOptions, feedPagesToConfig, savePageConfig +from config import createPage, loadDefaultPageOptions, feedPagesToConfig, feedSettingsToConfig, savePageConfig from Components.config import config, getConfigListEntry, ConfigSelection from Components.ConfigList import ConfigList, ConfigListScreen @@ -152,8 +152,9 @@ class CurlyTxSettings(ConfigListScreen, HelpableScreen, Screen): self["config"].setList(self.getConfigList()) - def feedPagesReceived(self, pages): + def feedPagesReceived(self, pages, settings): feedPagesToConfig(pages) + feedSettingsToConfig(settings) self["config"].setList(self.getConfigList()) def feedPagesFail(self, errorMessage): diff --git a/src/config.py b/src/config.py index 7b11142..5482fc4 100644 --- a/src/config.py +++ b/src/config.py @@ -3,7 +3,7 @@ # Copyright (C) 2011 Christian Weiske # License: GPLv3 or later -from Components.config import config, ConfigYesNo, ConfigSelection, ConfigNumber, ConfigText, ConfigSubsection, ConfigSubList, ConfigInteger +from Components.config import config, ConfigEnableDisable, ConfigYesNo, ConfigSelection, ConfigNumber, ConfigText, ConfigSubsection, ConfigSubList, ConfigInteger def createPage(): """ Create and return a configuration page object """ @@ -38,6 +38,15 @@ def feedPagesToConfig(pages): page.title.setValue(pageData["title"]) page.uri.setValue(pageData["url"]) +def feedSettingsToConfig(settings): + changed = False + if 'enableSettings' in settings and config.plugins.CurlyTx.enableSettings.getValue() != settings['enableSettings']: + config.plugins.CurlyTx.enableSettings.setValue(int(settings['enableSettings'])) + changed = True + + if changed: + config.plugins.CurlyTx.save() + def savePageConfig(): for i in range(0, len(config.plugins.CurlyTx.pages)): config.plugins.CurlyTx.pages[i].save() @@ -49,6 +58,7 @@ def savePageConfig(): config.plugins.CurlyTx = ConfigSubsection() config.plugins.CurlyTx.menuMain = ConfigYesNo(default = True) config.plugins.CurlyTx.menuExtensions = ConfigYesNo(default = False) +config.plugins.CurlyTx.enableSettings = ConfigEnableDisable(default = True) config.plugins.CurlyTx.menuTitle = ConfigText(default = "CurlyTx", fixed_size = False) config.plugins.CurlyTx.feedUrl = ConfigText(default = "", fixed_size = False) config.plugins.CurlyTx.pages = ConfigSubList()