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