Add option to disable settings button, load option from XML page feed file
authorChristian Weiske <cweiske@cweiske.de>
Mon, 2 Sep 2013 18:20:38 +0000 (20:20 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 2 Sep 2013 18:20:38 +0000 (20:20 +0200)
README.rst
src/AtomFeed.py
src/CurlyTx.py
src/CurlyTxSettings.py
src/config.py

index 0726c32ff2196172dcfee29e605cb7a23c5c01a9..1af6c2d12d7245b4f2fdde3a52748d024a332877 100644 (file)
@@ -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::
+
+    <feed xmlns="http://www.w3.org/2005/Atom" xmlns:c="http://ns.cweiske.de/curlytx">
+
+Then, add the setting after the author or self link::
+
+    <c:enableSettings>0</c:enableSettings>
+
+Here is the example feed with disabled settings::
+
+  <?xml version="1.0" encoding="utf-8"?>
+  <feed xmlns="http://www.w3.org/2005/Atom" xmlns:c="http://ns.cweiske.de/curlytx">
+   <title>URL list for CurlyTx</title>
+   <author>
+    <name>Christian Weiske</name>
+    <email>cweiske@cweiske.de</email>
+   </author>
+   <link rel="self" href="http://home.cweiske.de/pagefeed.atom"/>
+   <c:enableSettings>0</c:enableSettings>
+   <entry>
+    <id>ip</id>
+    <title>My IP</title>
+    <link rel="alternate" type="text/html" href="http://ip.cweiske.de/" />
+   </entry>
+   <entry>
+    <id>temp</id>
+    <title>House temperatures</title>
+    <link rel="alternate" type="text/html" href="http://home/temperatures.txt" />
+   </entry>
+  </feed>
+
+
 =================
 Modifying CurlyTx
 =================
index 51da7f8249cd352fec76aba95b91b69e620c7758..eff3eaad74f0ea48357abef5716531433271b828 100644 (file)
@@ -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 """
index 3572601ffdf9e546021224852f1ca8beee7a9c4d..3e74c5e54e9fbfdcb1cd3d97e4803b1e36f7a482 100644 (file)
@@ -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()
index ba2281c4280b5e46ba8681782b002298e71443e6..5d39725b9b40f3234daf05abc565ba7588f87437 100644 (file)
@@ -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):
index 7b1114271eacf3e6f7bac05aaa5f991b019ccc0f..5482fc469c7934da191a227713686640b44b6093 100644 (file)
@@ -3,7 +3,7 @@
 # Copyright (C) 2011 Christian Weiske <cweiske@cweiske.de>
 # 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()