add GetText for showing config entries, update summary values when changed
[enigma2.git] / lib / python / Components / TimerSanityCheck.py
1 from Components.NimManager import nimmanager
2 from time import localtime
3
4 class TimerSanityCheck:
5         def __init__(self, timerlist, newtimer):
6                 self.timerlist = timerlist
7                 self.newtimer = newtimer
8                 self.simultimer = []
9                                 
10         def check(self):
11                 self.simultimer = [ self.newtimer ]
12                 for timer in self.timerlist:
13                         if self.isSimultaneous(timer, self.newtimer):
14                                 self.simultimer.append(timer)
15                 
16                 if len(self.simultimer) > 1:
17                         return self.checkRecordable(self.simultimer)
18                 
19                 return True
20
21         def getSimulTimerList(self):
22                 return self.simultimer
23         
24         def isSimultaneous(self, timer1, timer2):
25                 # both timers are repeated
26                 if (timer1.repeated & timer2.repeated):
27                         return self.timeEquals(timer1, timer2)
28
29                 # one timer is repeated
30                 if not timer1.repeated:
31                         tmp = timer1
32                         timer1 = timer2
33                         timer2 = tmp
34
35                 if timer1.repeated:
36                         dow2 = (localtime(timer2.begin).tm_wday - 1) % 7
37                         
38                         if timer1.repeated & (2 ** dow2):
39                                 return self.timeEquals(timer1, timer2)
40                 else:
41                         if (timer1.begin <= timer2.begin < timer1.end) or (timer2.begin <= timer1.begin < timer2.end):
42                                 return True
43
44                 return False
45
46         def timeEquals(self, timer1, timer2):
47                 ltb1 = localtime(timer1.begin)
48                 ltb2 = localtime(timer2.begin)
49                                 
50                 begin1 = ltb1.tm_hour * 3600 + ltb1.tm_min * 60 + ltb1.tm_sec
51                 begin2 = ltb2.tm_hour * 3600 + ltb2.tm_min * 60 + ltb2.tm_sec
52                 
53                 end1 = begin1 + timer1.end - timer1.begin
54                 end2 = begin2 + timer2.end - timer2.begin
55                 
56                 return (begin1 <= begin2 < end1) or (begin2 <= begin1 < end2)
57         
58         def checkRecordable(self, timerlist):
59                 # TODO: Add code here
60                 return True