From 738adbb747be92f19cd7864490c982cac558358c Mon Sep 17 00:00:00 2001 From: Stefan Pluecken Date: Wed, 25 Jan 2006 08:16:11 +0000 Subject: [PATCH] added a sanity check for timer editor (no functionality until now except building a list of simultanious timers) --- lib/python/Components/Makefile.am | 2 +- lib/python/Components/TimerSanityCheck.py | 45 +++++++++++++++++++++++ lib/python/Components/__init__.py | 2 +- lib/python/Screens/TimerEdit.py | 10 +++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 lib/python/Components/TimerSanityCheck.py diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am index 945946dc..7416ea35 100644 --- a/lib/python/Components/Makefile.am +++ b/lib/python/Components/Makefile.am @@ -12,5 +12,5 @@ install_PYTHON = \ EpgList.py ScrollLabel.py Timezones.py Language.py HelpMenuList.py \ BlinkingPixmap.py Pixmap.py ConditionalWidget.py Slider.py LanguageList.py \ PluginList.py PluginComponent.py RecordingConfig.py About.py UsageConfig.py \ - FIFOList.py ServiceEventTracker.py Input.py + FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py diff --git a/lib/python/Components/TimerSanityCheck.py b/lib/python/Components/TimerSanityCheck.py new file mode 100644 index 00000000..a5b81ffc --- /dev/null +++ b/lib/python/Components/TimerSanityCheck.py @@ -0,0 +1,45 @@ +from Components.config import config +from Components.NimManager import nimmanager +from time import localtime + +class TimerSanityCheck: + def __init__(self, timerlist, newtimer): + self.timerlist = timerlist + self.newtimer = newtimer + + def check(self): + simultimer = [ self.newtimer ] + for timer in self.timerlist: + if self.isSimultaneous(timer, self.newtimer): + simultimer.append(timer) + + if len(simultimer) > 1: + return self.checkRecordable(simultimer) + + return True + + def isSimultaneous(self, timer1, timer2): + # both timers are repeated + if (timer1.repeated & timer2.repeated): + return True + + # one timer is repeated + if not timer1.repeated: + tmp = timer1 + timer1 = timer2 + timer2 = tmp + + if timer1.repeated: + dow2 = (localtime(timer2.begin).tm_wday - 1) % 7 + + if timer1.repeated & (2 ** dow2): + return True + else: + if (timer1.begin < timer2.begin < timer1.end) or (timer2.begin < timer1.begin < timer2.end): + return True + + return False + + def checkRecordable(self, timerlist): + # TODO: Add code here + return True \ No newline at end of file diff --git a/lib/python/Components/__init__.py b/lib/python/Components/__init__.py index 0582a908..38be156e 100644 --- a/lib/python/Components/__init__.py +++ b/lib/python/Components/__init__.py @@ -6,4 +6,4 @@ __all__ = ["ActionMap", "Button", "Clock", "ConfigList", "EventInfo", "components", "config", "TimerList", "TimeInput", "MovieList", "InputDevice", "ServicePosition", "IPAddress", "VariableIP", "IPGateway", "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry", - "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList"] + "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList", "TimerSanityCheck"] diff --git a/lib/python/Screens/TimerEdit.py b/lib/python/Screens/TimerEdit.py index da80f5bc..36502ca0 100644 --- a/lib/python/Screens/TimerEdit.py +++ b/lib/python/Screens/TimerEdit.py @@ -10,6 +10,7 @@ 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): @@ -133,8 +134,13 @@ class TimerEditList(Screen): def finishedEdit(self, answer): print "finished edit" + if answer[0]: print "Edited timer" + if not TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1]).check(): + print "Sanity check failed" + else: + print "Sanity check passed" self.session.nav.RecordTimer.timeChanged(answer[1]) self.fillTimerList() else: @@ -143,6 +149,10 @@ class TimerEditList(Screen): def finishedAdd(self, answer): print "finished add" if answer[0]: + if not TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1]).check(): + print "Sanity check failed" + else: + print "Sanity check passed" entry = answer[1] self.session.nav.RecordTimer.record(entry) self.fillTimerList() -- 2.30.2