added a sanity check for timer editor (no functionality until now except building...
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Wed, 25 Jan 2006 08:16:11 +0000 (08:16 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Wed, 25 Jan 2006 08:16:11 +0000 (08:16 +0000)
lib/python/Components/Makefile.am
lib/python/Components/TimerSanityCheck.py [new file with mode: 0644]
lib/python/Components/__init__.py
lib/python/Screens/TimerEdit.py

index 945946d..7416ea3 100644 (file)
@@ -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 (file)
index 0000000..a5b81ff
--- /dev/null
@@ -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
index 0582a90..38be156 100644 (file)
@@ -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"]
index da80f5b..36502ca 100644 (file)
@@ -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()