X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/223c807af74a9a402fa5a649c3e7acafb8caa8e3..c3c343dab84378de4e68065497e0115a422bf045:/lib/python/Screens/TimerEdit.py diff --git a/lib/python/Screens/TimerEdit.py b/lib/python/Screens/TimerEdit.py index b64fb116..761b2b48 100644 --- a/lib/python/Screens/TimerEdit.py +++ b/lib/python/Screens/TimerEdit.py @@ -1,91 +1,243 @@ 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.TextInput import TextInput -from TimerEntry import TimerEntry -from RecordTimer import RecordTimerEntry +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 class TimerEditList(Screen): def __init__(self, session): Screen.__init__(self, session) list = [ ] - for timer in session.nav.RecordTimer.timer_list: - list.append(TimerEntryComponent(timer, 0)) - - for timer in session.nav.RecordTimer.processed_timers: - list.append(TimerEntryComponent(timer, 1)) - + self.list = list + self.fillTimerList() + self["timerlist"] = TimerList(list) - self["key_red"] = Button("Delete") - self["key_green"] = Button("Add") + self["key_red"] = Button(_("Delete")) + self["key_green"] = Button(_("Add")) self["key_yellow"] = Button("") - self["key_blue"] = Button("") + self["key_blue"] = Button(_("Cleanup")) - self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], + self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"], { "ok": self.openEdit, - "cancel": self.close, + "cancel": self.leave, "red": self.removeTimer, - "green": self.addCurrentTimer - }) + "green": self.addCurrentTimer, + "blue": self.cleanupQuestion, + "yellow": self.toggleDisabledState, + "log": self.showLog, + "left": self.left, + "right": self.right, + "up": self.up, + "down": self.down + }, -1) + self.session.nav.RecordTimer.on_state_change.append(self.onStateChange) + self.onShown.append(self.updateState) + + def up(self): + self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveUp) + self.updateState() + + def down(self): + self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveDown) + self.updateState() + + def left(self): + self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageUp) + self.updateState() + + def right(self): + self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageDown) + 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() + + def updateState(self): + if len(self.list) > 0: + if self["timerlist"].getCurrent()[0].disabled: + self["key_yellow"].setText(_("Enable")) + else: + self["key_yellow"].setText(_("Disable")) + self["key_yellow"].instance.invalidate() + + def fillTimerList(self): + del self.list[:] + + for timer in self.session.nav.RecordTimer.timer_list: + self.list.append(TimerEntryComponent(timer, processed=False)) + + for timer in self.session.nav.RecordTimer.processed_timers: + self.list.append(TimerEntryComponent(timer, processed=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]) def openEdit(self): self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0]) #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0]) + def cleanupQuestion(self): + self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?")) + + def cleanupTimer(self, delete): + if delete: + self.session.nav.RecordTimer.cleanup() + self.refill() + def removeTimer(self): - # FIXME doesn't work... - self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0]) + 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) + + def refill(self): + self.fillTimerList() + self["timerlist"].invalidate() def addCurrentTimer(self): - begin = time() - end = time() + 60 - - epg = None - try: - service = self.session.nav.getCurrentService() + event = None + service = self.session.nav.getCurrentService() + if service is not None: info = service.info() - ev = info.getEvent(0) - epg = ev - except: - pass - - if (epg == None): - description = "unknown event" - else: - description = ev.getEventName() - # FIXME we need a timestamp here: - begin = ev.getBeginTime() - - print begin - print ev.getDuration() - end = begin + ev.getDuration() - + if info is not None: + event = info.getEvent(0) # FIXME only works if already playing a service serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()) - self.addTimer(RecordTimerEntry(begin, end, serviceref, epg, description)) + if event is None: + data = (int(time()), int(time() + 60), "unknown event", "", None) + else: + data = parseEvent(event) + + self.addTimer(RecordTimerEntry(serviceref, *data)) def addTimer(self, timer): self.session.openWithCallback(self.finishedAdd, TimerEntry, timer) def finishedEdit(self, answer): - if (answer[0]): + print "finished edit" + + if answer[0]: print "Edited timer" + timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1]) + if not timersanitycheck.check(): + print "Sanity check failed" + else: + print "Sanity check passed" + self.session.nav.RecordTimer.timeChanged(answer[1]) + self.fillTimerList() else: print "Timeredit aborted" def finishedAdd(self, answer): - if (answer[0]): - self.session.nav.RecordTimer.record(answer[1]) + print "finished add" + if answer[0]: + timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1]) + if not timersanitycheck.check(): + print "Sanity check failed" + self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList()) + else: + print "Sanity check passed" + entry = answer[1] + self.session.nav.RecordTimer.record(entry) + self.fillTimerList() else: - print "Timeredit aborted" \ No newline at end of file + print "Timeredit aborted" + + def finishSanityCorrection(self, answer): + 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 "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.list = [] + count = 0 + for x in timer: + if count != 0: + self.list.append((_("Conflicting timer") + " " + str(count), x)) + count += 1 + + self["list"] = MenuList(self.list) + + self["key_red"] = Button("Edit") + self["key_green"] = Button("Disable") + self["key_yellow"] = Button("Edit") + self["key_blue"] = Button("Disable") + + self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"], + { + "ok": self.close, + #"cancel": self.leave, + "red": self.editTimer1, + "green": self.disableTimer1, +# "yellow": self.editTimer2, +# "blue": self.disableTimer2, + #"log": self.showLog, + #"left": self.left, + #"right": self.right, + "up": self.up, + "down": self.down + }, -1) + + def getTimerList(self, timer): + return [TimerEntryComponent(timer, processed=False)] + + def editTimer1(self): + self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0]) + + def disableTimer1(self): + self.timer[0].disabled = True + self.finishedEdit((True, self.timer[0])) + + def finishedEdit(self, answer): + self.close((True, self.timer[0])) + + def up(self): + self["list"].instance.moveSelection(self["list"].instance.moveUp) + self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1])) + + 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