everthing should fit one page now
[vuplus_dvbapp-plugin] / autotimer / src / AutoTimerImporter.py
index edc91a0..ccec3c1 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: UTF-8 -*-
 # for localized messages
 from . import _
 
@@ -9,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
@@ -18,7 +20,14 @@ from RecordTimer import AFTEREVENT
 # Needed to convert our timestamp back and forth
 from time import localtime
 
-afterevent = { AFTEREVENT.NONE: _("do nothing"), AFTEREVENT.DEEPSTANDBY: _("go to deep standby"), AFTEREVENT.STANDBY: _("go to standby")}
+from enigma import eServiceReference
+
+afterevent = {
+       AFTEREVENT.NONE: _("do nothing"),
+       AFTEREVENT.DEEPSTANDBY: _("go to deep standby"),
+       AFTEREVENT.STANDBY: _("go to standby"),
+       AFTEREVENT.AUTO: _("auto")
+}
 
 class AutoTimerImportSelector(Screen):
        def __init__(self, session, autotimer):
@@ -47,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[:]
-
-               for timer in self.session.nav.RecordTimer.timer_list:
-                       self.list.append((timer, False))
+               l = self.list
+               del l[:]
 
-               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]
@@ -79,7 +86,8 @@ class AutoTimerImportSelector(Screen):
                                cur.service_ref,
                                cur.afterEvent,
                                cur.justplay,
-                               cur.dirname
+                               cur.dirname,
+                               cur.tags
                        )
 
        def cancel(self):
@@ -88,50 +96,57 @@ 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):
+       def __init__(self, session, autotimer, name, begin, end, disabled, sref, afterEvent, justplay, dirname, tags):
                Screen.__init__(self, session)
 
                # Keep AutoTimer
                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)
@@ -142,7 +157,7 @@ class AutoTimerImporter(Screen):
                                        2,
                                        True
                        ))
-               
+
                if sref:
                        list.append(
                                SelectionEntryComponent(
@@ -151,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
@@ -173,16 +188,25 @@ 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
                        ))
 
+               if tags:
+                       list.append(
+                               SelectionEntryComponent(
+                                       ': '.join((_("Tags"), ', '.join(tags))),
+                                       tags,
+                                       7,
+                                       True
+                       ))
+
                self["list"] = SelectionList(list)
 
                # Define Actions
-               self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], 
+               self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
                {
                        "ok": self["list"].toggleSelection,
                        "cancel": self.cancel,
@@ -190,6 +214,11 @@ class AutoTimerImporter(Screen):
                        "green": self.accept
                }, -1)
 
+               self.onLayoutFinish.append(self.setCustomTitle)
+
+       def setCustomTitle(self):
+               self.setTitle(_("Import AutoTimer"))
+
        def cancel(self):
                self.session.openWithCallback(
                        self.cancelConfirm,
@@ -229,31 +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]
-
-               if self.autotimer.match == "":
+                               autotimer.destination = item[1]
+                       elif item[2] == 7: # Tags
+                               autotimer.tags = item[1]
+                       elif item[2] == 8: # Exact match
+                               autotimer.searchType = "exact"
+                               autotimer.searchCase = "sensitive"
+
+               if autotimer.match == "":
                        self.session.openWithCallback(
                                        self.gotCustomMatch,
                                        InputBox,
@@ -261,6 +300,7 @@ class AutoTimerImporter(Screen):
                        )
                else:
                        self.close((
-                               self.autotimer,
+                               autotimer,
                                self.session
                        ))
+