some more ugly hacks for renamed services (so much hasssle for something that useless...)
[vuplus_dvbapp-plugin] / autotimer / src / AutoTimerEditor.py
index 8fce85f..27294cc 100644 (file)
@@ -15,7 +15,7 @@ from Screens.Setup import SetupSummary
 
 # GUI (Components)
 from Components.ActionMap import ActionMap
-from Components.Button import Button
+from Components.Sources.StaticText import StaticText
 
 # Configuration
 from Components.config import getConfigListEntry, ConfigEnableDisable, \
@@ -58,7 +58,7 @@ class ExtendedConfigText(ConfigText):
 
                # Workaround some characters currently not "typeable" using NumericalTextInput
                mapping = self.mapping
-               if len(mapping):
+               if mapping:
                        if "&" not in mapping[0]:
                                mapping[0] += "&"
                        if ";" not in mapping[0]:
@@ -142,10 +142,10 @@ class AutoTimerEditorBase:
                        timer.getIncludedDescription(),
                        timer.getIncludedDays()
                )
-               if len(excludes[0]) or len(excludes[1]) \
-                               or len(excludes[2]) or len(excludes[3]) \
-                               or len(includes[0]) or len(includes[1]) \
-                               or len(includes[2]) or len(includes[3]):
+               if excludes[0] or excludes[1] \
+                               or excludes[2] or excludes[3] \
+                               or includes[0] or includes[1] \
+                               or includes[2] or includes[3]:
                        self.filterSet = True
                else:
                        self.filterSet = False
@@ -155,7 +155,7 @@ class AutoTimerEditorBase:
                # See if services are restricted
                self.services = timer.services
                self.bouquets = timer.bouquets
-               if len(self.services) or len(self.bouquets):
+               if self.services or self.bouquets:
                        self.serviceRestriction = True
                else:
                        self.serviceRestriction = False
@@ -180,6 +180,9 @@ class AutoTimerEditorBase:
                self.searchType = NoSave(ConfigSelection(choices = [("partial", _("partial match")), ("exact", _("exact match"))], default = timer.searchType))
                self.searchCase = NoSave(ConfigSelection(choices = [("sensitive", _("case-sensitive search")), ("insensitive", _("case-insensitive search"))], default = timer.searchCase))
 
+               # Alternatives override
+               self.overrideAlternatives = NoSave(ConfigYesNo(default = timer.overrideAlternatives))
+
                # Justplay
                self.justplay = NoSave(ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[int(timer.justplay)]))
 
@@ -314,9 +317,9 @@ class AutoTimerEditorBase:
 
        def pathSelected(self, res):
                if res is not None:
-                       if res not in self.destination.choices:
-                               self.destination.choices.append(res)
-                               self.destination.description[res] = res
+                       # I'm pretty sure this will always fail
+                       if config.movielist.videodirs.value != self.destination.choices:
+                                       self.destination.setChoices(config.movielist.videodirs.value, default = res)
                        self.destination.value = res
 
        def chooseDestination(self):
@@ -347,16 +350,16 @@ class AutoTimerEditorBase:
 class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
        """Edit AutoTimer"""
 
-       skin = """<screen name="AutoTimerEdit" title="Edit AutoTimer" position="75,155" size="565,280">
+       skin = """<screen name="AutoTimerEditor" title="Edit AutoTimer" position="center,center" size="565,280">
                <widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
-               <ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
-               <ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
-               <ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
-               <ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
-               <widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <ePixmap position="0,235" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+               <ePixmap position="140,235" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+               <ePixmap position="280,235" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+               <ePixmap position="420,235" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+               <widget source="key_red" render="Label" position="0,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_green" render="Label" position="140,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_yellow" render="Label" position="280,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_blue" render="Label" position="420,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
        </screen>"""
 
        def __init__(self, session, timer, editingDefaults = False):
@@ -382,10 +385,10 @@ class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
                ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
 
                # Initialize Buttons
-               self["key_red"] = Button(_("Cancel"))
-               self["key_green"] = Button(_("OK"))
-               self["key_yellow"] = Button()
-               self["key_blue"] = Button()
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("OK"))
+               self["key_yellow"] = StaticText()
+               self["key_blue"] = StaticText()
 
                # Set Button texts
                self.renameServiceButton()
@@ -426,7 +429,7 @@ class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
                for x in self.onChangedEntry:
                        try:
                                x()
-                       except:
+                       except Exception:
                                pass
 
        def getCurrentEntry(self):
@@ -453,6 +456,7 @@ class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
                        getConfigListEntry(_("Search Type"), self.searchType),
                        getConfigListEntry(_("Search strictness"), self.searchCase),
                        getConfigListEntry(_("Timer Type"), self.justplay),
+                       getConfigListEntry(_("Override found with alternative Service"), self.overrideAlternatives),
                        getConfigListEntry(_("Only match during Timespan"), self.timespan)
                ))
 
@@ -546,6 +550,22 @@ class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
                        self.bouquets = ret[1][1]
                        self.renameServiceButton()
 
+       def keyLeft(self):
+               cur = self["config"].getCurrent()
+               cur = cur and cur[1]
+               if cur == self.tags:
+                       self.chooseTags()
+               else:
+                       ConfigListScreen.keyLeft(self)
+
+       def keyRight(self):
+               cur = self["config"].getCurrent()
+               cur = cur and cur[1]
+               if cur == self.tags:
+                       self.chooseTags()
+               else:
+                       ConfigListScreen.keyRight(self)
+
        def ok(self):
                cur = self["config"].getCurrent()
                cur = cur and cur[1]
@@ -614,6 +634,9 @@ class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
                self.timer.searchType = self.searchType.value
                self.timer.searchCase = self.searchCase.value
 
+               # Alternatives
+               self.timer.overrideAlternatives = self.overrideAlternatives.value
+
                # Enabled
                self.timer.enabled = self.enabled.value
 
@@ -705,16 +728,16 @@ class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
 class AutoTimerFilterEditor(Screen, ConfigListScreen):
        """Edit AutoTimer Filter"""
 
-       skin = """<screen name="AutoFilterEditor" title="Edit AutoTimer Filters" position="75,150" size="565,245">
-               <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
-               <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
-               <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
-               <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
-               <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
-               <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+       skin = """<screen name="AutoTimerFilterEditor" title="Edit AutoTimer Filters" position="center,center" size="565,280">
+               <widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
+               <ePixmap position="0,235" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+               <ePixmap position="140,235" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+               <ePixmap position="280,235" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+               <ePixmap position="420,235" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+               <widget source="key_red" render="Label" position="0,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_green" render="Label" position="140,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_yellow" render="Label" position="280,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_blue" render="Label" position="420,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
        </screen>"""
 
        def __init__(self, session, filterset, excludes, includes):
@@ -742,10 +765,10 @@ class AutoTimerFilterEditor(Screen, ConfigListScreen):
                ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
 
                # Initialize Buttons
-               self["key_red"] = Button(_("Cancel"))
-               self["key_green"] = Button(_("Save"))
-               self["key_yellow"] = Button(_("delete"))
-               self["key_blue"] = Button(_("New"))
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("Save"))
+               self["key_yellow"] = StaticText(_("delete"))
+               self["key_blue"] = StaticText(_("New"))
 
                # Define Actions
                self["actions"] = ActionMap(["SetupActions", "ColorActions"],
@@ -770,7 +793,7 @@ class AutoTimerFilterEditor(Screen, ConfigListScreen):
                for x in self.onChangedEntry:
                        try:
                                x()
-                       except:
+                       except Exception:
                                pass
 
        def getCurrentEntry(self):
@@ -909,16 +932,16 @@ class AutoTimerFilterEditor(Screen, ConfigListScreen):
 class AutoTimerServiceEditor(Screen, ConfigListScreen):
        """Edit allowed Services of a AutoTimer"""
 
-       skin = """<screen name="AutoTimerServiceEditor" title="Edit AutoTimer Services" position="75,150" size="565,245">
-               <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
-               <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
-               <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
-               <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
-               <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
-               <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+       skin = """<screen name="AutoTimerServiceEditor" title="Edit AutoTimer Services" position="center,center" size="565,280">
+               <widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
+               <ePixmap position="0,235" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+               <ePixmap position="140,235" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+               <ePixmap position="280,235" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+               <ePixmap position="420,235" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+               <widget source="key_red" render="Label" position="0,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_green" render="Label" position="140,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_yellow" render="Label" position="280,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget source="key_blue" render="Label" position="420,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
        </screen>"""
 
        def __init__(self, session, servicerestriction, servicelist, bouquetlist):
@@ -945,10 +968,10 @@ class AutoTimerServiceEditor(Screen, ConfigListScreen):
                ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
 
                # Initialize Buttons
-               self["key_red"] = Button(_("Cancel"))
-               self["key_green"] = Button(_("OK"))
-               self["key_yellow"] = Button(_("delete"))
-               self["key_blue"] = Button(_("New"))
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("OK"))
+               self["key_yellow"] = StaticText(_("delete"))
+               self["key_blue"] = StaticText(_("New"))
 
                # Define Actions
                self["actions"] = ActionMap(["SetupActions", "ColorActions"],
@@ -1005,7 +1028,7 @@ class AutoTimerServiceEditor(Screen, ConfigListScreen):
                for x in self.onChangedEntry:
                        try:
                                x()
-                       except:
+                       except Exception:
                                pass
 
        def getCurrentEntry(self):
@@ -1038,14 +1061,16 @@ class AutoTimerServiceEditor(Screen, ConfigListScreen):
                        )
 
        def finishedServiceSelection(self, *args):
-               if len(args):
+               if args:
                        list = self["config"].getList()
                        sname = args[0].toString()
 
-                       if self.typeSelection.value == "channels":
-                               # strip all after last : when adding a channel
+                       if self.typeSelection.value == "channels" and not (args[0].flags & eServiceReference.isGroup):
+                               # strip all after last : when adding a (non alternative) channel
                                pos = sname.rfind(':')
                                if pos != -1:
+                                       if sname[pos-1] == ':'
+                                               pos -= 1
                                        sname = sname[:pos+1]
 
                        list.append(getConfigListEntry(_("Record on"), NoSave(ConfigSelection(choices = [(sname, ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))))
@@ -1073,6 +1098,37 @@ class AutoTimerServiceEditor(Screen, ConfigListScreen):
                        self.services
                ))
 
+def addAutotimerFromSearchString(session, match):
+       from AutoTimerComponent import AutoTimerComponent
+       from AutoTimerImporter import AutoTimerImporter
+       from plugin import autotimer
+
+       # Create instance if needed
+       if autotimer is None:
+               from AutoTimer import AutoTimer
+               autotimer = AutoTimer()
+               autotimer.readXml()
+
+       session.openWithCallback(
+               importerCallback,
+               AutoTimerImporter,
+               AutoTimerComponent(
+                       autotimer.getUniqueId(),
+                       match,
+                       '',             # Match
+                       True    # Enabled
+               ),
+               match,          # Proposed Match
+               None,           # Proposed Begin
+               None,           # Proposed End
+               None,           # Proposed Disabled
+               None,           # Proposed ServiceReference
+               None,           # Proposed afterEvent
+               None,           # Proposed justplay
+               None,           # Proposed dirname, can we get anything useful here?
+               []                      # Proposed tags
+       )
+
 def addAutotimerFromEvent(session, evt = None, service = None):
        from AutoTimerComponent import AutoTimerComponent
        from AutoTimerImporter import AutoTimerImporter
@@ -1089,12 +1145,16 @@ def addAutotimerFromEvent(session, evt = None, service = None):
        sref = None
        if service is not None:
                service = str(service)
-               # strip all after last :
-               pos = service.rfind(':')
-               if pos != -1:
-                       service = service[:pos+1]
-
-               sref = ServiceReference(service)
+               myref = eServiceReference(service)
+               if not (myref.flags & eServiceReference.isGroup):
+                       # strip all after last :
+                       pos = service.rfind(':')
+                       if pos != -1:
+                               if service[pos-1] == ':'
+                                       pos -= 1
+                               service = service[:pos+1]
+
+               sref = ServiceReference(myref)
        if evt:
                # timespan defaults to +- 1h
                begin = evt.getBeginTime()-3600
@@ -1145,6 +1205,8 @@ def addAutotimerFromService(session, service = None):
                # strip all after last :
                pos = sref.rfind(':')
                if pos != -1:
+                       if sref[pos-1] == ':'
+                               pos -= 1
                        sref = sref[:pos+1]
 
                sref = ServiceReference(sref)