fix typo
[enigma2.git] / lib / python / Screens / TimerEdit.py
index bd4b64d3c0800d44303387dfe435b46e736c38a0..5a7109f2784346f35ac6c8fc72590f6ae6e7fbc3 100644 (file)
@@ -1,18 +1,16 @@
-from Screen import Screen
-from Components.TimerList import TimerList, TimerEntryComponent
-from Components.ConfigList import ConfigList
-from Components.MenuList import MenuList
 from Components.ActionMap import ActionMap
-from Components.TimeInput import TimeInput
-from Components.Label import Label
 from Components.Button import Button
+from Components.MenuList import MenuList
+from Components.TimerList import TimerList
+from Components.TimerSanityCheck import TimerSanityCheck
+from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
+from Screen import Screen
+from Screens.ChoiceBox import ChoiceBox
 from Screens.MessageBox import MessageBox
-from TimerEntry import TimerEntry, TimerLog
-from RecordTimer import RecordTimerEntry, parseEvent
-from time import *
 from ServiceReference import ServiceReference
-from Components.config import *
-from Components.TimerSanityCheck import TimerSanityCheck
+from TimerEntry import TimerEntry, TimerLog
+from Tools.BoundFunction import boundFunction
+from time import time
 
 class TimerEditList(Screen):
        def __init__(self, session):
@@ -33,7 +31,7 @@ class TimerEditList(Screen):
                        {
                                "ok": self.openEdit,
                                "cancel": self.leave,
-                               "red": self.removeTimer,
+                               "red": self.removeTimerQuestion,
                                "green": self.addCurrentTimer,
                                "blue": self.cleanupQuestion,
                                "yellow": self.toggleDisabledState,
@@ -63,14 +61,43 @@ class TimerEditList(Screen):
                self.updateState()
                
        def toggleDisabledState(self):
-               self["timerlist"].getCurrent()[0].disabled = not self["timerlist"].getCurrent()[0].disabled
-               self.session.nav.RecordTimer.timeChanged(self["timerlist"].getCurrent()[0])
-               self.updateState()
-               self.refill()
+               cur=self["timerlist"].getCurrent()
+               if cur:
+                       t = cur
+               
+                       if t.disabled:
+                               t.enable()
+                               self.session.nav.RecordTimer.timeChanged(t)
+
+                       else:
+                               if t.isRunning() and t.repeated:
+                                       list = []
+                                       list.append((_("Stop current event but not coming events"), "stoponlycurrent"))
+                                       list.append((_("Stop current event and disable coming events"), "stopall"))
+                                       list.append((_("Don't stop current event but disable coming events"), "stoponlycoming"))
+                                       self.session.openWithCallback(boundFunction(self.runningEventCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = list)
+                               else:
+                                       t.disable()
+                                       self.session.nav.RecordTimer.timeChanged(t)
+                       self.updateState()
+                       self.refill()
+
+       def runningEventCallback(self, t, result):
+               if result is not None:
+                       if result[1] == "stoponlycurrent" or result[1] == "stopall":
+                               t.enable()
+                               t.processRepeated(findRunningEvent = False)
+                               self.session.nav.RecordTimer.doActivate(t)
+                       if result[1] == "stoponlycoming" or result[1] == "stopall":
+                               t.disable()
+                       self.session.nav.RecordTimer.timeChanged(t)
+
+                       self.updateState()
+                       self.refill()
                
        def updateState(self):
                if len(self.list) > 0:
-                       if self["timerlist"].getCurrent()[0].disabled:
+                       if self["timerlist"].getCurrent().disabled:
                                self["key_yellow"].setText(_("Enable"))
                        else:
                                self["key_yellow"].setText(_("Disable"))
@@ -80,19 +107,22 @@ class TimerEditList(Screen):
                del self.list[:]
                
                for timer in self.session.nav.RecordTimer.timer_list:
-                       self.list.append(TimerEntryComponent(timer, processed=False))
+                       self.list.append((timer, False))
                
                for timer in self.session.nav.RecordTimer.processed_timers:
-                       self.list.append(TimerEntryComponent(timer, processed=True))
+                       self.list.append((timer, True))
                self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
 
        def showLog(self):
-               self.session.openWithCallback(self.finishedEdit, TimerLog, self["timerlist"].getCurrent()[0])
+               cur=self["timerlist"].getCurrent()
+               if cur:
+                       self.session.openWithCallback(self.finishedEdit, TimerLog, cur)
 
        def openEdit(self):
-               self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
-               #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
-               
+               cur=self["timerlist"].getCurrent()
+               if cur:
+                       self.session.openWithCallback(self.finishedEdit, TimerEntry, cur)
+
        def cleanupQuestion(self):
                self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
        
@@ -100,21 +130,33 @@ class TimerEditList(Screen):
                if delete:
                        self.session.nav.RecordTimer.cleanup()
                        self.refill()
-               
-       def removeTimer(self):
+
+       def removeTimerQuestion(self):
+               if not self["timerlist"].getCurrent():
+                       return
+               self.session.openWithCallback(self.removeTimer, MessageBox, _("Really delete this timer?"))
+
+       def removeTimer(self, result):
+               if not result:
+                       return
                list = self["timerlist"]
-               timer = list.getCurrent()[0]
-               currentIndex = list.getCurrentIndex()
-               self.session.nav.RecordTimer.removeEntry(timer)
-               list.moveDown()
-               if list.getCurrentIndex() == currentIndex:
-                       currentIndex -= 1
-               self.refill()
-               list.moveToIndex(currentIndex)
+               cur = list.getCurrent()
+               if cur:
+                       timer = cur
+                       timer.afterEvent = AFTEREVENT.NONE
+                       self.session.nav.RecordTimer.removeEntry(timer)
+                       self.refill()
        
        def refill(self):
+               oldsize = len(self.list)
                self.fillTimerList()
-               self["timerlist"].invalidate()
+               lst = self["timerlist"]
+               newsize = len(self.list)
+               if oldsize and oldsize != newsize:
+                       idx = lst.getCurrentIndex()
+                       lst.entryRemoved(idx)
+               else:
+                       lst.invalidate()
        
        def addCurrentTimer(self):
                event = None
@@ -128,11 +170,11 @@ class TimerEditList(Screen):
                serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
                
                if event is None:       
-                       data = (int(time()), int(time() + 60), "unknown event", "", None)
+                       data = (int(time()), int(time() + 60), "", "", None)
                else:
-                       data = parseEvent(event)
+                       data = parseEvent(event, description = False)
 
-               self.addTimer(RecordTimerEntry(serviceref, *data))
+               self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, *data))
                
        def addTimer(self, timer):
                self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
@@ -171,24 +213,23 @@ class TimerEditList(Screen):
                self.finishedAdd(answer)
 
        def leave(self):
-               self.session.nav.RecordTimer.saveTimer()
                self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
                self.close()
 
        def onStateChange(self, entry):
                self.refill()
-               
+
 class TimerSanityConflict(Screen):
        def __init__(self, session, timer):
                Screen.__init__(self, session)
                self.timer = timer
-               print timer
+               print "TimerSanityConflict", timer
                        
                self["timer1"] = TimerList(self.getTimerList(timer[0]))
                if len(timer) > 1:
                        self["timer2"] = TimerList(self.getTimerList(timer[1]))
                else:
-                       self["timer2"] = Button("No conflict")
+                       self["timer2"] = TimerList([])
                
                self.list = []
                count = 0
@@ -220,10 +261,10 @@ class TimerSanityConflict(Screen):
                        }, -1)
 
        def getTimerList(self, timer):
-               return [TimerEntryComponent(timer, processed=False)]
+               return [(timer, False)]
 
        def editTimer1(self):
-               self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0])
+               self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent())
 
        def disableTimer1(self):
                self.timer[0].disabled = True
@@ -234,10 +275,8 @@ class TimerSanityConflict(Screen):
 
        def up(self):
                self["list"].instance.moveSelection(self["list"].instance.moveUp)
-               self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
+               self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()))
                
        def down(self):
                self["list"].instance.moveSelection(self["list"].instance.moveDown)
-               self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
-                       
-               
\ No newline at end of file
+               self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()))