Merge branch 'bug_570_playback_skip_fixes_and_cleanup_ml_aholst' into experimental
[enigma2.git] / lib / python / Components / TimerSanityCheck.py
index 99b2fba52cebc151c8afbf1a3b575084f26fd105..b472a19e130c305512a5a5eeee931d5a103d11c9 100644 (file)
@@ -1,18 +1,19 @@
 import NavigationInstance
 import NavigationInstance
-from time import localtime
+from time import localtime, mktime, gmtime
 from ServiceReference import ServiceReference
 from enigma import iServiceInformation, eServiceCenter, eServiceReference
 
 class TimerSanityCheck:
        def __init__(self, timerlist, newtimer=None):
                print "sanitycheck"
 from ServiceReference import ServiceReference
 from enigma import iServiceInformation, eServiceCenter, eServiceReference
 
 class TimerSanityCheck:
        def __init__(self, timerlist, newtimer=None):
                print "sanitycheck"
+               self.localtimediff = 25*3600 - mktime(gmtime(25*3600))
                self.timerlist = timerlist
                self.newtimer = newtimer
                self.simultimer = []
                self.rep_eventlist = []
                self.nrep_eventlist = []
                self.timerlist = timerlist
                self.newtimer = newtimer
                self.simultimer = []
                self.rep_eventlist = []
                self.nrep_eventlist = []
-               self.bflag = 1
-               self.eflag = -1
+               self.bflag = -1
+               self.eflag = 1
 
        def check(self, ext_timer=1):
                print "check"
 
        def check(self, ext_timer=1):
                print "check"
@@ -35,9 +36,15 @@ class TimerSanityCheck:
                                        return True
                                else:
                                        if timer.begin == self.newtimer.begin:
                                        return True
                                else:
                                        if timer.begin == self.newtimer.begin:
+                                               fl1 = timer.service_ref.ref.flags & eServiceReference.isGroup
+                                               fl2 = self.newtimer.service_ref.ref.flags & eServiceReference.isGroup
+                                               if fl1 != fl2:
+                                                       return False
+                                               if fl1: #is group
+                                                       return timer.service_ref.ref.getPath() == self.newtimer.service_ref.ref.getPath()
                                                getUnsignedDataRef1 = timer.service_ref.ref.getUnsignedData
                                                getUnsignedDataRef2 = self.newtimer.service_ref.ref.getUnsignedData
                                                getUnsignedDataRef1 = timer.service_ref.ref.getUnsignedData
                                                getUnsignedDataRef2 = self.newtimer.service_ref.ref.getUnsignedData
-                                               for x in range(1,5):
+                                               for x in (1, 2, 3, 4):
                                                        if getUnsignedDataRef1(x) != getUnsignedDataRef2(x):
                                                                break;
                                                else:
                                                        if getUnsignedDataRef1(x) != getUnsignedDataRef2(x):
                                                                break;
                                                else:
@@ -70,6 +77,10 @@ class TimerSanityCheck:
                        rflags = ((rflags & 0x7F)>> 3)|((rflags & 0x07)<<4)
                        if rflags:
                                begin = self.newtimer.begin % 86400 # map to first day
                        rflags = ((rflags & 0x7F)>> 3)|((rflags & 0x07)<<4)
                        if rflags:
                                begin = self.newtimer.begin % 86400 # map to first day
+                               if (self.localtimediff > 0) and ((begin + self.localtimediff) > 86400):
+                                       rflags = ((rflags >> 1)& 0x3F)|((rflags << 6)& 0x40)
+                               elif (self.localtimediff < 0) and (begin < self.localtimediff):
+                                       rflags = ((rflags << 1)& 0x7E)|((rflags >> 6)& 0x01)
                                while rflags: # then arrange on the week
                                        if rflags & 1:
                                                self.rep_eventlist.append((begin, -1))
                                while rflags: # then arrange on the week
                                        if rflags & 1:
                                                self.rep_eventlist.append((begin, -1))
@@ -87,6 +98,10 @@ class TimerSanityCheck:
                                        rflags = timer.repeated
                                        rflags = ((rflags & 0x7F)>> 3)|((rflags & 0x07)<<4)
                                        begin = timer.begin % 86400 # map all to first day
                                        rflags = timer.repeated
                                        rflags = ((rflags & 0x7F)>> 3)|((rflags & 0x07)<<4)
                                        begin = timer.begin % 86400 # map all to first day
+                                       if (self.localtimediff > 0) and ((begin + self.localtimediff) > 86400):
+                                               rflags = ((rflags >> 1)& 0x3F)|((rflags << 6)& 0x40)
+                                       elif (self.localtimediff < 0) and (begin < self.localtimediff):
+                                               rflags = ((rflags << 1)& 0x7E)|((rflags >> 6)& 0x01)
                                        while rflags:
                                                if rflags & 1:
                                                        self.rep_eventlist.append((begin, idx))
                                        while rflags:
                                                if rflags & 1:
                                                        self.rep_eventlist.append((begin, idx))
@@ -126,8 +141,7 @@ class TimerSanityCheck:
                                                        self.nrep_eventlist.extend([(new_event_begin, self.bflag, event[1]),(new_event_end, self.eflag, event[1])])
                else:
                        offset_0 = 345600 # the Epoch begins on Thursday
                                                        self.nrep_eventlist.extend([(new_event_begin, self.bflag, event[1]),(new_event_end, self.eflag, event[1])])
                else:
                        offset_0 = 345600 # the Epoch begins on Thursday
-                       weeks = 2 # test two weeks to take care of Sunday-Monday transitions
-                       for cnt in range(weeks):
+                       for cnt in (0, 1): # test two weeks to take care of Sunday-Monday transitions
                                for event in self.rep_eventlist:
                                        if event[1] == -1: # -1 is the identifier of the changed timer
                                                event_begin = self.newtimer.begin
                                for event in self.rep_eventlist:
                                        if event[1] == -1: # -1 is the identifier of the changed timer
                                                event_begin = self.newtimer.begin