Support older dreamboxes (e.g. 7025+) that don't have a recent elementtree library.
[enigma2-curlytx.git] / src / config.py
index e32e27b5cae17c14e2347eb4bfe02057d7152493..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 """
@@ -25,10 +25,40 @@ def loadDefaultPageOptions():
     else:
         config.plugins.CurlyTx.defaultPage = ConfigSelection(defaults, "0")
 
+def feedPagesToConfig(pages):
+    """ save pages from atom feed into config. """
+    if len(pages) == 0:
+        return
+
+    del config.plugins.CurlyTx.pages[:]
+
+    for pageData in pages:
+        page = createPage()
+        config.plugins.CurlyTx.pages.append(page)
+        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()
+
+    config.plugins.CurlyTx.pages.save()
+
+
 #configuration setup
 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()