hide default page config option when no page defined
[enigma2-curlytx.git] / src / CurlyTxSettings.py
index 3a58ecb..154bf37 100644 (file)
@@ -1,12 +1,16 @@
+from . import _
+
 from Screens.Screen import Screen
+from Screens.HelpMenu import HelpableScreen
 from Components.ActionMap import ActionMap, NumberActionMap
 from Components.Sources.StaticText import StaticText
 
 from . import config
-from Components.config import config, getConfigListEntry
+from config import createPage, loadDefaultPageOptions
+from Components.config import config, getConfigListEntry, ConfigSelection
 from Components.ConfigList import ConfigList, ConfigListScreen
 
-class CurlyTxSettings(ConfigListScreen, Screen):
+class CurlyTxSettings(ConfigListScreen, HelpableScreen, Screen):
     skin = """
        <screen name="Setup" position="center,center" size="560,430" title="Setup">
          <ePixmap pixmap="skin_default/buttons/red.png"    position="0,0"   size="140,40" transparent="1" alphatest="on" />
@@ -23,6 +27,7 @@ class CurlyTxSettings(ConfigListScreen, Screen):
     def __init__(self, session):
         self.skin = CurlyTxSettings.skin
         Screen.__init__(self, session)
+        HelpableScreen.__init__(self)
         #self.skinName = [ "CurlyTxSettings", "Setup" ]
         self.setup_title = _("Settings")
 
@@ -30,9 +35,9 @@ class CurlyTxSettings(ConfigListScreen, Screen):
             {
                 "cancel": self.keyCancel,
                 "save": self.keySave,
-                #"ok": self.ok,
-                "blue": self.deletePage,
-                "yellow": self.newPage
+                "ok": self.editPage,
+                "yellow": self.newPage,
+                "blue": self.deletePage
             }, -2)
 
         self["key_red"]    = StaticText(_("Cancel"))
@@ -42,15 +47,41 @@ class CurlyTxSettings(ConfigListScreen, Screen):
 
         ConfigListScreen.__init__(self, self.getConfigList(), session = self.session)
 
+        self.loadHelp()
+        self.onClose.append(self.abort)
+
     def getConfigList(self):
+        #reload titles
+        loadDefaultPageOptions()
+
         list = [
-            getConfigListEntry(_("Page"), x.uri)
+            getConfigListEntry(_("Page:") + " " + x.title.value, x.uri)
                 for x in config.plugins.CurlyTx.pages
             ]
+        if len(config.plugins.CurlyTx.pages):
+            list.append(getConfigListEntry(_("Default page"), config.plugins.CurlyTx.defaultPage))
         list.append(getConfigListEntry(_("Show in main menu"), config.plugins.CurlyTx.menuMain))
+        list.append(getConfigListEntry(_("Show in extensions menu"), config.plugins.CurlyTx.menuExtensions))
         list.append(getConfigListEntry(_("Menu title"), config.plugins.CurlyTx.menuTitle))
         return list
 
+    def loadHelp(self):
+        self.helpList.append((
+                self["actions"], "SetupActions",
+                [("cancel", _("Dismiss all setting changes"))]))
+        self.helpList.append((
+                self["actions"], "SetupActions",
+                [("save", _("Save settings and close screen"))]))
+        self.helpList.append((
+                self["actions"], "SetupActions",
+                [("ok", _("Edit selected page"))]))
+        self.helpList.append((
+                self["actions"], "ColorActions",
+                [("yellow", _("Add new page"))]))
+        self.helpList.append((
+                self["actions"], "ColorActions",
+                [("blue", _("Delete selected page"))]))
+
     def keyLeft(self):
         ConfigListScreen.keyLeft(self)
 
@@ -58,12 +89,15 @@ class CurlyTxSettings(ConfigListScreen, Screen):
         ConfigListScreen.keyRight(self)
 
     def deletePage(self):
+        if len(config.plugins.CurlyTx.pages) == 0:
+            return
+
         from Screens.MessageBox import MessageBox
         self.session.openWithCallback(
             self.deletePageConfirm,
             MessageBox,
             _("Really delete this page?\nIt cannot be recovered!")
-        )
+            )
 
     def deletePageConfirm(self, result):
         if not result:
@@ -71,19 +105,69 @@ class CurlyTxSettings(ConfigListScreen, Screen):
 
         id = self["config"].getCurrentIndex()
         del config.plugins.CurlyTx.pages[id]
-        config.plugins.CurlyTx.pageCount.value -= 1
+
+        config.plugins.CurlyTx.pages.save()
 
         self["config"].setList(self.getConfigList())
 
     def newPage(self):
-        # FIXME
+        from CurlyTxSettings import CurlyTxSettings
+        self.session.openWithCallback(self.pageEdited, CurlyTxPageEdit, createPage(), True)
+
+    def editPage(self):
+        id = self["config"].getCurrentIndex()
+        if id < len(config.plugins.CurlyTx.pages):
+            self.session.openWithCallback(
+                self.pageEdited, CurlyTxPageEdit,
+                config.plugins.CurlyTx.pages[id], False
+                )
+
+    def pageEdited(self, page, new):
+        if not page:
+            return
+
+        if new:
+            config.plugins.CurlyTx.pages.append(page)
+
+        self["config"].setList(self.getConfigList())
+
+
+    def keySave(self):
+        for i in range(0, len(config.plugins.CurlyTx.pages)):
+            config.plugins.CurlyTx.pages[i].save()
+
+        config.plugins.CurlyTx.pages.save()
+        ConfigListScreen.keySave(self)
+
+    def abort(self):
         pass
 
 
 
 class CurlyTxPageEdit(Screen, ConfigListScreen):
-    def __init__(self, session):
+    def __init__(self, session, page, new = False):
         Screen.__init__(self, session)
+        self.skinName = [ "CurlyTxPageEdit", "Setup" ]
 
         self["key_red"]   = StaticText(_("Cancel"))
         self["key_green"] = StaticText(_("OK"))
+
+        self["setupActions"] = ActionMap(["SetupActions"],
+            {
+                "save": self.save,
+                "cancel": self.keyCancel
+           }, -1)
+
+        self.page = page
+        self.new = new
+        list = [
+            getConfigListEntry(_("Page URL"), page.uri),
+            getConfigListEntry(_("Title"), page.title),
+            ]
+        ConfigListScreen.__init__(self, list, session = self.session)
+
+    def save(self):
+        self.close(self.page, self.new)
+
+    def keyCancel(self):
+        self.close(None, self.new)