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