Merge remote branch 'remotes/origin/fantempplugin'
[vuplus_dvbapp] / lib / python / Screens / TimerEdit.py
index 81836fd..5435498 100644 (file)
@@ -4,6 +4,7 @@ from Components.config import config
 from Components.MenuList import MenuList
 from Components.TimerList import TimerList
 from Components.TimerSanityCheck import TimerSanityCheck
 from Components.MenuList import MenuList
 from Components.TimerList import TimerList
 from Components.TimerSanityCheck import TimerSanityCheck
+from Components.UsageConfig import preferredTimerPath
 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
 from Screen import Screen
 from Screens.ChoiceBox import ChoiceBox
 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
 from Screen import Screen
 from Screens.ChoiceBox import ChoiceBox
@@ -14,28 +15,43 @@ from Tools.BoundFunction import boundFunction
 from time import time
 
 class TimerEditList(Screen):
 from time import time
 
 class TimerEditList(Screen):
+       EMPTY = 0
+       ENABLE = 1
+       DISABLE = 2
+       CLEANUP = 3
+       DELETE = 4
+       
        def __init__(self, session):
                Screen.__init__(self, session)
                
                list = [ ]
                self.list = list
                self.fillTimerList()
        def __init__(self, session):
                Screen.__init__(self, session)
                
                list = [ ]
                self.list = list
                self.fillTimerList()
+               
+               print "EMPTY:",self.EMPTY
+               print "ENABLE:",self.ENABLE
+               print "DISABLE:",self.DISABLE
+               print "CLEANUP:",self.CLEANUP
+               print "DELETE:",self.DELETE
 
                self["timerlist"] = TimerList(list)
                
 
                self["timerlist"] = TimerList(list)
                
-               self["key_red"] = Button(_("Delete"))
+               self.key_red_choice = self.EMPTY
+               self.key_yellow_choice = self.EMPTY
+               self.key_blue_choice = self.EMPTY
+               
+               self["key_red"] = Button(" ")
                self["key_green"] = Button(_("Add"))
                self["key_green"] = Button(_("Add"))
-               self["key_yellow"] = Button("")
-               self["key_blue"] = Button(_("Cleanup"))
+               self["key_yellow"] = Button(" ")
+               self["key_blue"] = Button(" ")
+
+               print "key_red_choice:",self.key_red_choice
 
                self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"], 
                        {
                                "ok": self.openEdit,
                                "cancel": self.leave,
 
                self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"], 
                        {
                                "ok": self.openEdit,
                                "cancel": self.leave,
-                               "red": self.removeTimerQuestion,
                                "green": self.addCurrentTimer,
                                "green": self.addCurrentTimer,
-                               "blue": self.cleanupQuestion,
-                               "yellow": self.toggleDisabledState,
                                "log": self.showLog,
                                "left": self.left,
                                "right": self.right,
                                "log": self.showLog,
                                "left": self.left,
                                "right": self.right,
@@ -66,7 +82,7 @@ class TimerEditList(Screen):
                if cur:
                        t = cur
                        if t.disabled:
                if cur:
                        t = cur
                        if t.disabled:
-                               print "try to enable timer"
+                               print "try to ENABLE timer"
                                t.enable()
                                timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, cur)
                                if not timersanitycheck.check():
                                t.enable()
                                timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, cur)
                                if not timersanitycheck.check():
@@ -80,10 +96,11 @@ class TimerEditList(Screen):
                        else:
                                if t.isRunning():
                                        if t.repeated:
                        else:
                                if t.isRunning():
                                        if 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"))
+                                               list = (
+                                                       (_("Stop current event but not coming events"), "stoponlycurrent"),
+                                                       (_("Stop current event and disable coming events"), "stopall"),
+                                                       (_("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.openWithCallback(boundFunction(self.runningEventCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = list)
                                else:
                                        t.disable()
@@ -102,36 +119,41 @@ class TimerEditList(Screen):
                        self.session.nav.RecordTimer.timeChanged(t)
                        self.refill()
                        self.updateState()
                        self.session.nav.RecordTimer.timeChanged(t)
                        self.refill()
                        self.updateState()
-               
+
+       def removeAction(self, descr):
+               actions = self["actions"].actions
+               if descr in actions:
+                       del actions[descr]
+
        def updateState(self):
                cur = self["timerlist"].getCurrent()
                if cur:
        def updateState(self):
                cur = self["timerlist"].getCurrent()
                if cur:
-                       if self["key_red"].getText()!=(_("Delete")):
+                       if self.key_red_choice != self.DELETE:
                                self["actions"].actions.update({"red":self.removeTimerQuestion})
                                self["key_red"].setText(_("Delete"))
                                self["actions"].actions.update({"red":self.removeTimerQuestion})
                                self["key_red"].setText(_("Delete"))
-                               self["key_red"].instance.invalidate()
+                               self.key_red_choice = self.DELETE
                        
                        
-                       if cur.disabled and (self["key_yellow"].getText()!=(_("Enable"))):
+                       if cur.disabled and (self.key_yellow_choice != self.ENABLE):
                                self["actions"].actions.update({"yellow":self.toggleDisabledState})
                                self["key_yellow"].setText(_("Enable"))
                                self["actions"].actions.update({"yellow":self.toggleDisabledState})
                                self["key_yellow"].setText(_("Enable"))
-                               self["key_yellow"].instance.invalidate()
-                       elif cur.isRunning() and (self["key_yellow"].getText()!=(_(" "))):
-                               del self["actions"].actions["yellow"]
-                               self["key_yellow"].setText(_(" "))
-                               self["key_yellow"].instance.invalidate()
-                       elif (not cur.isRunning()) and (not cur.disabled) and (self["key_yellow"].getText()!=(_("Disable"))):
+                               self.key_yellow_choice = self.ENABLE
+                       elif cur.isRunning() and not cur.repeated and (self.key_yellow_choice != self.EMPTY):
+                               self.removeAction("yellow")
+                               self["key_yellow"].setText(" ")
+                               self.key_yellow_choice = self.EMPTY
+                       elif ((not cur.isRunning())or cur.repeated ) and (not cur.disabled) and (self.key_yellow_choice != self.DISABLE):
                                self["actions"].actions.update({"yellow":self.toggleDisabledState})
                                self["key_yellow"].setText(_("Disable"))
                                self["actions"].actions.update({"yellow":self.toggleDisabledState})
                                self["key_yellow"].setText(_("Disable"))
-                               self["key_yellow"].instance.invalidate()
+                               self.key_yellow_choice = self.DISABLE
                else:
                else:
-                       if self["key_red"].getText()!=(_(" ")):
-                               del self["actions"].actions["red"]
-                               self["key_red"].setText(_(" "))
-                               self["key_red"].instance.invalidate()
-                       if self["key_yellow"].getText()!=(_(" ")):
-                               del self["actions"].actions["yellow"]
-                               self["key_yellow"].setText(_(" "))
-                               self["key_yellow"].instance.invalidate()
+                       if self.key_red_choice != self.EMPTY:
+                               self.removeAction("red")
+                               self["key_red"].setText(" ")
+                               self.key_red_choice = self.EMPTY
+                       if self.key_yellow_choice != self.EMPTY:
+                               self.removeAction("yellow")
+                               self["key_yellow"].setText(" ")
+                               self.key_yellow_choice = self.EMPTY
                
                showCleanup = True
                for x in self.list:
                
                showCleanup = True
                for x in self.list:
@@ -140,25 +162,21 @@ class TimerEditList(Screen):
                else:
                        showCleanup = False
                
                else:
                        showCleanup = False
                
-               if showCleanup and (self["key_blue"].getText()!=(_("Cleanup"))):
+               if showCleanup and (self.key_blue_choice != self.CLEANUP):
                        self["actions"].actions.update({"blue":self.cleanupQuestion})
                        self["key_blue"].setText(_("Cleanup"))
                        self["actions"].actions.update({"blue":self.cleanupQuestion})
                        self["key_blue"].setText(_("Cleanup"))
-                       self["key_blue"].instance.invalidate()
-               elif (not showCleanup) and (self["key_blue"].getText()!=(_(" "))):
-                       del self["actions"].actions["blue"]
-                       self["key_blue"].setText(_(" "))
-                       self["key_blue"].instance.invalidate()
-
+                       self.key_blue_choice = self.CLEANUP
+               elif (not showCleanup) and (self.key_blue_choice != self.EMPTY):
+                       self.removeAction("blue")
+                       self["key_blue"].setText(" ")
+                       self.key_blue_choice = self.EMPTY
 
        def fillTimerList(self):
 
        def fillTimerList(self):
-               del self.list[:]
-               
-               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)
+               list = self.list
+               del list[:]
+               list.extend([(timer, False) for timer in self.session.nav.RecordTimer.timer_list])
+               list.extend([(timer, True) for timer in self.session.nav.RecordTimer.processed_timers])
+               list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
 
        def showLog(self):
                cur=self["timerlist"].getCurrent()
 
        def showLog(self):
                cur=self["timerlist"].getCurrent()
@@ -180,9 +198,11 @@ class TimerEditList(Screen):
                        self.updateState()
 
        def removeTimerQuestion(self):
                        self.updateState()
 
        def removeTimerQuestion(self):
-               if not self["timerlist"].getCurrent():
+               cur = self["timerlist"].getCurrent()
+               if not cur:
                        return
                        return
-               self.session.openWithCallback(self.removeTimer, MessageBox, _("Really delete this timer?"))
+
+               self.session.openWithCallback(self.removeTimer, MessageBox, _("Do you really want to delete %s?") % (cur.name))
 
        def removeTimer(self, result):
                if not result:
 
        def removeTimer(self, result):
                if not result:
@@ -193,18 +213,6 @@ class TimerEditList(Screen):
                        timer = cur
                        timer.afterEvent = AFTEREVENT.NONE
                        self.session.nav.RecordTimer.removeEntry(timer)
                        timer = cur
                        timer.afterEvent = AFTEREVENT.NONE
                        self.session.nav.RecordTimer.removeEntry(timer)
-                       if not timer.dontSave:
-                               for timer in self.session.nav.RecordTimer.timer_list:
-                                       if timer.dontSave and timer.autoincrease:
-                                               timer.end = timer.begin + (3600 * 24 * 356 * 1)
-                                               self.session.nav.RecordTimer.timeChanged(timer)
-                                               timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list,timer)
-                                               if not timersanitycheck.check():
-                                                       tsc_list = timersanitycheck.getSimulTimerList()
-                                                       if len(tsc_list) > 1:
-                                                               timer.end = tsc_list[1].begin - 30
-                                                               self.session.nav.RecordTimer.timeChanged(timer)
-
                        self.refill()
                        self.updateState()
 
                        self.refill()
                        self.updateState()
 
@@ -236,10 +244,11 @@ class TimerEditList(Screen):
                else:
                        data = parseEvent(event, description = False)
 
                else:
                        data = parseEvent(event, description = False)
 
-               self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, dirname = config.movielist.last_timer_videodir.value, *data))
+               self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, dirname = preferredTimerPath(), *data))
                
        def addTimer(self, timer):
                self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
                
        def addTimer(self, timer):
                self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
+                       
                
        def finishedEdit(self, answer):
                print "finished edit"
                
        def finishedEdit(self, answer):
                print "finished edit"
@@ -248,19 +257,25 @@ class TimerEditList(Screen):
                        print "Edited timer"
                        entry = answer[1]
                        timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, entry)
                        print "Edited timer"
                        entry = answer[1]
                        timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, entry)
+                       success = False
                        if not timersanitycheck.check():
                                simulTimerList = timersanitycheck.getSimulTimerList()
                        if not timersanitycheck.check():
                                simulTimerList = timersanitycheck.getSimulTimerList()
-                               if (len(simulTimerList) == 2) and (simulTimerList[1].dontSave) and (simulTimerList[1].autoincrease):
-                                       simulTimerList[1].end = entry.begin - 30
-                                       self.session.nav.RecordTimer.timeChanged(simulTimerList[1])
-                                       self.session.nav.RecordTimer.timeChanged(entry)
-                               else:
-                                       print "Sanity check failed"
-                                       self.session.openWithCallback(self.finishedEdit, TimerSanityConflict, timersanitycheck.getSimulTimerList())
+                               if simulTimerList is not None:
+                                       for x in simulTimerList:
+                                               if x.setAutoincreaseEnd(entry):
+                                                       self.session.nav.RecordTimer.timeChanged(x)
+                                       if not timersanitycheck.check():
+                                               simulTimerList = timersanitycheck.getSimulTimerList()
+                                               if simulTimerList is not None:
+                                                       self.session.openWithCallback(self.finishedEdit, TimerSanityConflict, timersanitycheck.getSimulTimerList())
+                                       else:
+                                               success = True
                        else:
                        else:
+                               success = True
+                       if success:
                                print "Sanity check passed"
                                print "Sanity check passed"
-                               if not timersanitycheck.doubleCheck():
-                                       self.session.nav.RecordTimer.timeChanged(entry)
+                               self.session.nav.RecordTimer.timeChanged(entry)
+                       
                        self.fillTimerList()
                        self.updateState()
                else:
                        self.fillTimerList()
                        self.updateState()
                else:
@@ -272,11 +287,11 @@ class TimerEditList(Screen):
                        entry = answer[1]
                        simulTimerList = self.session.nav.RecordTimer.record(entry)
                        if simulTimerList is not None:
                        entry = answer[1]
                        simulTimerList = self.session.nav.RecordTimer.record(entry)
                        if simulTimerList is not None:
-                               if (len(simulTimerList) == 2) and (simulTimerList[1].dontSave) and (simulTimerList[1].autoincrease):
-                                       simulTimerList[1].end = entry.begin - 30
-                                       self.session.nav.RecordTimer.timeChanged(simulTimerList[1])
-                                       self.session.nav.RecordTimer.record(entry)
-                               else:
+                               for x in simulTimerList:
+                                       if x.setAutoincreaseEnd(entry):
+                                               self.session.nav.RecordTimer.timeChanged(x)
+                               simulTimerList = self.session.nav.RecordTimer.record(entry)
+                               if simulTimerList is not None:
                                        self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
                        self.fillTimerList()
                        self.updateState()
                                        self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
                        self.fillTimerList()
                        self.updateState()
@@ -295,6 +310,11 @@ class TimerEditList(Screen):
                self.updateState()
 
 class TimerSanityConflict(Screen):
                self.updateState()
 
 class TimerSanityConflict(Screen):
+       EMPTY = 0
+       ENABLE = 1
+       DISABLE = 2
+       EDIT = 3
+       
        def __init__(self, session, timer):
                Screen.__init__(self, session)
                self.timer = timer
        def __init__(self, session, timer):
                Screen.__init__(self, session)
                self.timer = timer
@@ -309,26 +329,26 @@ class TimerSanityConflict(Screen):
                                self.list.append((_("Conflicting timer") + " " + str(count), x))
                                self.list2.append((timer[count], False))
                        count += 1
                                self.list.append((_("Conflicting timer") + " " + str(count), x))
                                self.list2.append((timer[count], False))
                        count += 1
+               if count == 1:
+                       self.list.append((_("Channel not in services list")))
 
                self["list"] = MenuList(self.list)
                self["timer2"] = TimerList(self.list2)
 
                self["key_red"] = Button("Edit")
 
                self["list"] = MenuList(self.list)
                self["timer2"] = TimerList(self.list2)
 
                self["key_red"] = Button("Edit")
-               self["key_green"] = Button("")
-               self["key_yellow"] = Button("Edit")
-               self["key_blue"] = Button("")
+               self["key_green"] = Button(" ")
+               self["key_yellow"] = Button(" ")
+               self["key_blue"] = Button(" ")
+
+               self.key_green_choice = self.EMPTY
+               self.key_yellow_choice = self.EMPTY
+               self.key_blue_choice = self.EMPTY
 
                self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"], 
                        {
                                "ok": self.leave_ok,
                                "cancel": self.leave_cancel,
                                "red": self.editTimer1,
 
                self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"], 
                        {
                                "ok": self.leave_ok,
                                "cancel": self.leave_cancel,
                                "red": self.editTimer1,
-                               "green": self.toggleTimer1,
-                               "yellow": self.editTimer2,
-                               "blue": self.toggleTimer2,
-                               #"log": self.showLog,
-                               #"left": self.left,
-                               #"right": self.right,
                                "up": self.up,
                                "down": self.down
                        }, -1)
                                "up": self.up,
                                "down": self.down
                        }, -1)
@@ -375,47 +395,53 @@ class TimerSanityConflict(Screen):
        def down(self):
                self["list"].instance.moveSelection(self["list"].instance.moveDown)
                self["timer2"].moveToIndex(self["list"].getSelectedIndex())
        def down(self):
                self["list"].instance.moveSelection(self["list"].instance.moveDown)
                self["timer2"].moveToIndex(self["list"].getSelectedIndex())
-       
+
+       def removeAction(self, descr):
+               actions = self["actions"].actions
+               if descr in actions:
+                       del actions[descr]
+
        def updateState(self):
                if self.timer[0] is not None:
        def updateState(self):
                if self.timer[0] is not None:
-                       green_text = self["key_green"].getText()
-                       print "green_text '%s'" %(green_text)
-                       if self.timer[0].disabled and green_text != _("Enable"):
+                       if self.timer[0].disabled and self.key_green_choice != self.ENABLE:
                                self["actions"].actions.update({"green":self.toggleTimer1})
                                self["key_green"].setText(_("Enable"))
                                self["actions"].actions.update({"green":self.toggleTimer1})
                                self["key_green"].setText(_("Enable"))
-                               self["key_green"].instance.invalidate()
-                       elif self.timer[0].isRunning() and green_text != "":
-                               del self["actions"].actions["green"]
-                               self["key_green"].setText("")
-                               self["key_green"].instance.invalidate()
-                       elif not self.timer[0].disabled and green_text != _("Disable"):
+                               self.key_green_choice = self.ENABLE
+                       elif self.timer[0].isRunning() and not self.timer[0].repeated and self.key_green_choice != self.EMPTY:
+                               self.removeAction("green")
+                               self["key_green"].setText(" ")
+                               self.key_green_choice = self.EMPTY
+                       elif (not self.timer[0].isRunning() or self.timer[0].repeated ) and self.key_green_choice != self.DISABLE:
                                self["actions"].actions.update({"green":self.toggleTimer1})
                                self["key_green"].setText(_("Disable"))
                                self["actions"].actions.update({"green":self.toggleTimer1})
                                self["key_green"].setText(_("Disable"))
-                               self["key_green"].instance.invalidate()
+                               self.key_green_choice = self.DISABLE
+               
                if len(self.timer) > 1:
                        x = self["list"].getSelectedIndex()
                if len(self.timer) > 1:
                        x = self["list"].getSelectedIndex()
-                       print "x: ",x
-                       print "timer[x]: ", self.timer[x]
                        if self.timer[x] is not None:
                        if self.timer[x] is not None:
-                               blue_text = self["key_blue"].getText()
-                               print "blue_text '%s'" %(blue_text)
-                               if self.timer[x].disabled and blue_text != _("Enable"):
+                               if self.key_yellow_choice == self.EMPTY:
+                                       self["actions"].actions.update({"yellow":self.editTimer2})
+                                       self["key_yellow"].setText(_("Edit"))
+                                       self.key_yellow_choice = self.EDIT
+                               if self.timer[x].disabled and self.key_blue_choice != self.ENABLE:
                                        self["actions"].actions.update({"blue":self.toggleTimer2})
                                        self["key_blue"].setText(_("Enable"))
                                        self["actions"].actions.update({"blue":self.toggleTimer2})
                                        self["key_blue"].setText(_("Enable"))
-                                       self["key_blue"].instance.invalidate()
-                               elif self.timer[x].isRunning() and blue_text != "":
-                                       del self["actions"].actions["blue"]
-                                       self["key_blue"].setText("")
-                                       self["key_blue"].instance.invalidate()
-                               elif not self.timer[x].disabled and blue_text != _("Disable"):
+                                       self.key_blue_choice = self.ENABLE
+                               elif self.timer[x].isRunning() and not self.timer[x].repeated and self.key_blue_choice != self.EMPTY:
+                                       self.removeAction("blue")
+                                       self["key_blue"].setText(" ")
+                                       self.key_blue_choice = self.EMPTY
+                               elif (not self.timer[x].isRunning() or self.timer[x].repeated ) and self.key_blue_choice != self.DISABLE:
                                        self["actions"].actions.update({"blue":self.toggleTimer2})
                                        self["key_blue"].setText(_("Disable"))
                                        self["actions"].actions.update({"blue":self.toggleTimer2})
                                        self["key_blue"].setText(_("Disable"))
-                                       self["key_blue"].instance.invalidate()
+                                       self.key_blue_choice = self.DISABLE
                else:
 #FIXME.... this doesnt hide the buttons self.... just the text
                else:
 #FIXME.... this doesnt hide the buttons self.... just the text
-                       del self["actions"].actions["yellow"]
-                       self["key_yellow"].setText("")
-                       self["key_yellow"].instance.invalidate()
-                       del self["actions"].actions["blue"]
-                       self["key_blue"].setText("")
-                       self["key_blue"].instance.invalidate()
+                       if self.key_yellow_choice != self.EMPTY:
+                               self.removeAction("yellow")
+                               self["key_yellow"].setText(" ")
+                               self.key_yellow_choice = self.EMPTY
+                       if self.key_blue_choice != self.EMPTY:
+                               self.removeAction("blue")
+                               self["key_blue"].setText(" ")
+                               self.key_blue_choice = self.EMPTY