everthing should fit one page now
[vuplus_dvbapp-plugin] / autotimer / src / AutoTimerImporter.py
index c92458f..ccec3c1 100644 (file)
@@ -10,8 +10,9 @@ from Screens.InputBox import InputBox
 # GUI (Components)
 from Components.ActionMap import ActionMap
 from Components.Button import Button
-from Components.TimerList import TimerList
 from Components.SelectionList import SelectionList, SelectionEntryComponent
+from Components.Sources.StaticText import StaticText
+from Components.TimerList import TimerList
 
 # Timer
 from RecordTimer import AFTEREVENT
@@ -19,6 +20,8 @@ from RecordTimer import AFTEREVENT
 # Needed to convert our timestamp back and forth
 from time import localtime
 
+from enigma import eServiceReference
+
 afterevent = {
        AFTEREVENT.NONE: _("do nothing"),
        AFTEREVENT.DEEPSTANDBY: _("go to deep standby"),
@@ -53,17 +56,15 @@ class AutoTimerImportSelector(Screen):
                self.onLayoutFinish.append(self.setCustomTitle)
 
        def setCustomTitle(self):
-               self.setTitle(_("Select a Timer to Import"))
+               self.setTitle(_("Select a timer to import"))
 
        def fillTimerList(self):
-               del self.list[:]
+               l = self.list
+               del l[:]
 
-               for timer in self.session.nav.RecordTimer.timer_list:
-                       self.list.append((timer, False))
-
-               for timer in self.session.nav.RecordTimer.processed_timers:
-                       self.list.append((timer, True))
-               self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
+               l.extend([(timer, False) for timer in self.session.nav.RecordTimer.timer_list])
+               l.extend([(timer, True) for timer in self.session.nav.RecordTimer.processed_timers])
+               l.sort(key = lambda x: x[0].begin)
 
        def importerClosed(self, ret):
                ret = ret and ret[0]
@@ -95,16 +96,16 @@ class AutoTimerImportSelector(Screen):
 class AutoTimerImporter(Screen):
        """Import AutoTimer from Timer"""
 
-       skin = """<screen name="AutoTimerImporter" title="Import AutoTimer" position="75,155" size="565,280">
-               <widget name="list" 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" />
+       skin = """<screen name="AutoTimerImporter" title="Import AutoTimer" position="center,center" size="565,290">
+               <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+               <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+               <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+               <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+               <widget source="key_red" render="Label" position="0,0" 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,0" 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,0" 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,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget name="list" position="5,45" size="555,240" scrollbarMode="showOnDemand" />
        </screen>"""
 
        def __init__(self, session, autotimer, name, begin, end, disabled, sref, afterEvent, justplay, dirname, tags):
@@ -114,31 +115,38 @@ class AutoTimerImporter(Screen):
                self.autotimer = autotimer
 
                # 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()
 
                list = []
 
                if disabled is not None:
                        list.append(
                                SelectionEntryComponent(
-                                       ': '.join([_("Enabled"), {True: _("disable"), False: _("enable")}[bool(disabled)]]),
+                                       ': '.join((_("Enabled"), {True: _("disable"), False: _("enable")}[bool(disabled)])),
                                        not disabled,
                                        0,
                                        True
                        ))
 
                if name != "":
-                       list.append(
+                       list.extend([
                                SelectionEntryComponent(
                                        _("Match title: %s") % (name),
                                        name,
                                        1,
                                        True
-                       ))
-               
+                               ),
+                               SelectionEntryComponent(
+                                       _("Exact match"),
+                                       True,
+                                       8,
+                                       True
+                               )
+                       ])
+
                if begin and end:
                        begin = localtime(begin)
                        end = localtime(end)
@@ -149,7 +157,7 @@ class AutoTimerImporter(Screen):
                                        2,
                                        True
                        ))
-               
+
                if sref:
                        list.append(
                                SelectionEntryComponent(
@@ -158,20 +166,20 @@ class AutoTimerImporter(Screen):
                                        3,
                                        True
                        ))
-               
+
                if afterEvent is not None:
                        list.append(
                                SelectionEntryComponent(
-                                       ': '.join([_("After event"), afterevent[afterEvent]]),
+                                       ': '.join((_("After event"), afterevent[afterEvent])),
                                        afterEvent,
                                        4,
                                        True
                        ))
-                       
+
                if justplay is not None:
                        list.append(
                                SelectionEntryComponent(
-                                       ': '.join([_("Timer Type"), {0: _("record"), 1: _("zap")}[int(justplay)]]),
+                                       ': '.join((_("Timer type"), {0: _("record"), 1: _("zap")}[int(justplay)])),
                                        int(justplay),
                                        5,
                                        True
@@ -180,7 +188,7 @@ class AutoTimerImporter(Screen):
                if dirname is not None:
                        list.append(
                                SelectionEntryComponent(
-                                       ': '.join([_("Location"), dirname or "/hdd/movie/"]),
+                                       ': '.join((_("Location"), dirname or "/hdd/movie/")),
                                        dirname,
                                        6,
                                        True
@@ -189,7 +197,7 @@ class AutoTimerImporter(Screen):
                if tags:
                        list.append(
                                SelectionEntryComponent(
-                                       ': '.join([_("Tags"), ', '.join(tags)]),
+                                       ': '.join((_("Tags"), ', '.join(tags))),
                                        tags,
                                        7,
                                        True
@@ -198,7 +206,7 @@ class AutoTimerImporter(Screen):
                self["list"] = SelectionList(list)
 
                # Define Actions
-               self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], 
+               self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
                {
                        "ok": self["list"].toggleSelection,
                        "cancel": self.cancel,
@@ -250,33 +258,41 @@ class AutoTimerImporter(Screen):
 
        def accept(self):
                list = self["list"].getSelectionsList()
+               autotimer = self.autotimer
 
                for item in list:
                        if item[2] == 0: # Enable
-                               self.autotimer.enabled = item[1]
+                               autotimer.enabled = item[1]
                        elif item[2] == 1: # Match
-                               self.autotimer.match = item[1]
+                               autotimer.match = item[1]
                        elif item[2] == 2: # Timespan
-                               self.autotimer.timespan = item[1]
+                               autotimer.timespan = item[1]
                        elif item[2] == 3: # Service
                                value = item[1]
 
-                               # strip all after last :
-                               pos = value.rfind(':')
-                               if pos != -1:
-                                       value = value[:pos+1]
+                               myref = eServiceReference(value)
+                               if not (myref.flags & eServiceReference.isGroup):
+                                       # strip all after last :
+                                       pos = value.rfind(':')
+                                       if pos != -1:
+                                               if value[pos-1] == ':':
+                                                       pos -= 1
+                                               value = value[:pos+1]
 
-                               self.autotimer.services = [value]
+                               autotimer.services = [value]
                        elif item[2] == 4: # AfterEvent
-                               self.autotimer.afterevent = [(item[1], None)]
+                               autotimer.afterevent = [(item[1], None)]
                        elif item[2] == 5: # Justplay
-                               self.autotimer.justplay = item[1]
+                               autotimer.justplay = item[1]
                        elif item[2] == 6: # Location
-                               self.autotimer.destination = item[1]
+                               autotimer.destination = item[1]
                        elif item[2] == 7: # Tags
-                               self.autotimer.tags = item[1]
+                               autotimer.tags = item[1]
+                       elif item[2] == 8: # Exact match
+                               autotimer.searchType = "exact"
+                               autotimer.searchCase = "sensitive"
 
-               if self.autotimer.match == "":
+               if autotimer.match == "":
                        self.session.openWithCallback(
                                        self.gotCustomMatch,
                                        InputBox,
@@ -284,7 +300,7 @@ class AutoTimerImporter(Screen):
                        )
                else:
                        self.close((
-                               self.autotimer,
+                               autotimer,
                                self.session
                        ))