dont hide recording widget onShown.. use onLayoutFinish
[enigma2.git] / lib / python / Screens / TimerEntry.py
index 966bbab485b8a29ee12f88933ef3fb7ecd07b9b8..fef525f0be945d10ae692725b824290cf680bd4e 100644 (file)
@@ -2,20 +2,28 @@ from Screen import Screen
 import ChannelSelection
 from ServiceReference import ServiceReference
 from Components.config import *
-from Components.ActionMap import NumberActionMap
+from Components.ActionMap import ActionMap, NumberActionMap
 from Components.ConfigList import ConfigList
+from Components.MenuList import MenuList
+from Components.Button import Button
 from Components.NimManager import nimmanager
 from Components.Label import Label
+from Components.Pixmap import Pixmap
+from Screens.SubserviceSelection import SubserviceSelection
+from Screens.MessageBox import MessageBox
+from enigma import eEPGCache
 import time
 import datetime
 
 class TimerEntry(Screen):
        def __init__(self, session, timer):
                Screen.__init__(self, session)
-               self.timer = timer;
+               self.timer = timer
                
-               self["ok"] = Label("OK")
-               self["cancel"] = Label("Cancel")
+               self["oktext"] = Label(_("OK"))
+               self["canceltext"] = Label(_("Cancel"))
+               self["ok"] = Pixmap()
+               self["cancel"] = Pixmap()
 
                self.createConfig()
 
@@ -41,7 +49,7 @@ class TimerEntry(Screen):
 
                self.list = []
                self["config"] = ConfigList(self.list)
-               self.createSetup()
+               self.createSetup("config")
 
        def createConfig(self):
                        config.timerentry = ConfigSubsection()
@@ -76,6 +84,8 @@ class TimerEntry(Screen):
                        else: # once
                                type = 0
                                repeated = 0
+                               weekday = (int(strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
+                               day[weekday] = 0
                        
                        config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, type, (_("once"), _("repeated")))
                        config.timerentry.name = configElement_nonSave("config.timerentry.name", configText, self.timer.name, (configText.extendableSize, self.keyRightCallback))
@@ -125,7 +135,7 @@ class TimerEntry(Screen):
                                except:
                                        pass
 
-       def createSetup(self):
+       def createSetup(self, widget):
                self.list = []
                self.list.append(getConfigListEntry(_("Name"), config.timerentry.name))
                self.list.append(getConfigListEntry(_("Description"), config.timerentry.description))
@@ -133,7 +143,7 @@ class TimerEntry(Screen):
                self.list.append(self.timerTypeEntry)
 
                if (config.timerentry.type.value == 0): # once
-                       pass
+                       self.frequencyEntry = None
                else: # repeated
                        self.frequencyEntry = getConfigListEntry(_("Frequency"), config.timerentry.repeated)
                        self.list.append(self.frequencyEntry)
@@ -158,27 +168,27 @@ class TimerEntry(Screen):
 
                if (config.timerentry.type.value == 0): # once
                        self.list.append(getConfigListEntry(_("Start"), config.timerentry.startdate))
-                       self.list.append(getConfigListEntry("", config.timerentry.starttime))
+                       self.list.append(getConfigListEntry(" ", config.timerentry.starttime))
                else:
                        self.list.append(getConfigListEntry(_("StartTime"), config.timerentry.starttime))
                if (config.timerentry.type.value == 0): # once
                        self.list.append(getConfigListEntry(_("End"), config.timerentry.enddate))
-                       self.list.append(getConfigListEntry("", config.timerentry.endtime))
+                       self.list.append(getConfigListEntry(" ", config.timerentry.endtime))
                else:
                        self.list.append(getConfigListEntry(_("EndTime"), config.timerentry.endtime))
 
                self.channelEntry = getConfigListEntry(_("Channel"), config.timerentry.service)
                self.list.append(self.channelEntry)
 
-               self["config"].list = self.list
-               self["config"].l.setList(self.list)
+               self[widget].list = self.list
+               self[widget].l.setList(self.list)
 
        def newConfig(self):
                print self["config"].getCurrent()
                if self["config"].getCurrent() == self.timerTypeEntry:
-                       self.createSetup()
+                       self.createSetup("config")
                if self["config"].getCurrent() == self.frequencyEntry:
-                       self.createSetup()
+                       self.createSetup("config")
 
        def keyLeft(self):
                if self["config"].getCurrent() == self.channelEntry:
@@ -206,6 +216,8 @@ class TimerEntry(Screen):
        def keySelect(self):
                if self["config"].getCurrent() == self.channelEntry:
                        self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
+               else:
+                       self.keyGo()
 
        def finishedChannelSelection(self, args):
                oldref = self.timer.service_ref
@@ -253,9 +265,96 @@ class TimerEntry(Screen):
                                        if (config.timerentry.day[x].value == 0): self.timer.setRepeated(x)
 
                        self.timer.begin = self.getTimestamp(time.time(), config.timerentry.starttime.value)
-                       self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)                                
+                       self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)
+
+               if self.timer.eit is not None:
+                       event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
+                       if event is not None:
+                               if event.getNumOfLinkageServices() > 0:
+                                       self.session.openWithCallback(self.subserviceSelected, SubserviceSelection, event, self.timer.service_ref.ref)
+                                       return
+               self.close((True, self.timer))
 
+       def subserviceSelected(self, service):
+               if not service is None:
+                       self.timer.service_ref = ServiceReference(service)
                self.close((True, self.timer))
 
        def keyCancel(self):
                self.close((False,))
+               
+class TimerLog(Screen):
+       def __init__(self, session, timer):
+               Screen.__init__(self, session)
+               self.timer = timer;
+               self.log_entries = self.timer.log_entries[:]
+               
+               self.fillLogList()
+               
+               self["loglist"] = MenuList(self.list)
+               self["logentry"] = Label()
+               
+               self["key_red"] = Button(_("Delete entry"))
+               self["key_green"] = Button()
+               self["key_yellow"] = Button("")
+               self["key_blue"] = Button(_("Clear log"))
+               
+               self.onShown.append(self.updateText)
+
+               self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
+               {
+                       "ok": self.keyClose,
+                       "cancel": self.keyClose,
+                       "up": self.up,
+                       "down": self.down,
+                       "left": self.left,
+                       "right": self.right,
+                       "red": self.deleteEntry,
+                       "blue": self.clearLog
+               }, -1)
+
+       def deleteEntry(self):
+               self.log_entries.remove(self["loglist"].getCurrent()[1])
+               self.fillLogList()
+               self["loglist"].l.setList(self.list)
+               self.updateText()
+
+       def fillLogList(self):
+               self.list = [ ]
+               for x in self.log_entries:
+                       self.list.append((str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x))
+       
+       def clearLog(self):             
+               self.log_entries = []
+               self.fillLogList()
+               self["loglist"].l.setList(self.list)
+               self.updateText()
+               
+       def keyClose(self):
+               if self.timer.log_entries != self.log_entries:
+                       self.timer.log_entries = self.log_entries
+                       self.close((True, self.timer))
+               else:
+                       self.close((False,))
+               
+       def up(self):
+               self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
+               self.updateText()
+               
+       def down(self):
+               self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
+               self.updateText()
+
+       def left(self):
+               self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
+               self.updateText()
+               
+       def right(self):
+               self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
+               self.updateText()
+
+       def updateText(self):
+               if len(self.list) > 0:
+                       self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
+               else:
+                       self["logentry"].setText("")