uncomment necessary line
[enigma2.git] / lib / python / Components / TimerSanityCheck.py
index 5fa213084853461e5a2869791313b134992c875d..e793cdcd4aa5533cd5307668d243b2a55895a784 100644 (file)
@@ -13,8 +13,8 @@ class TimerSanityCheck:
                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"
@@ -50,8 +50,8 @@ class TimerSanityCheck:
                #with special service for external plugins
                # Entries in eventlist
                # timeindex
+               # BeginEndFlag 1 for begin, -1 for end
                # index -1 for the new Timer, 0..n index of the existing timers
-               # BeginEndFlag -1 for begin, +1 for end
                # count of running timers
 
                print "checkTimerlist"
@@ -77,7 +77,7 @@ class TimerSanityCheck:
                                        begin += 86400
                                        rflags >>= 1
                        else:
-                               self.nrep_eventlist.extend([(self.newtimer.begin,-1,self.bflag),(self.newtimer.end,-1,self.eflag)])
+                               self.nrep_eventlist.extend([(self.newtimer.begin,self.bflag,-1),(self.newtimer.end,self.eflag,-1)])
 
 ##################################################################################
 # now process existing timers
@@ -94,12 +94,12 @@ class TimerSanityCheck:
                                                begin += 86400
                                                rflags >>= 1
                                else:
-                                       self.nrep_eventlist.extend([(timer.begin,idx,self.bflag),(timer.end,idx,self.eflag)])
+                                       self.nrep_eventlist.extend([(timer.begin,self.bflag,idx),(timer.end,self.eflag,idx)])
                        idx += 1
 
 ################################################################################
 # journalize timer repeations
-               if len(self.nrep_eventlist):
+               if self.nrep_eventlist:
                        interval_begin = min(self.nrep_eventlist)[0]
                        interval_end = max(self.nrep_eventlist)[0]
                        offset_0 = interval_begin - (interval_begin % 604800)
@@ -121,10 +121,10 @@ class TimerSanityCheck:
                                        new_event_end = new_event_begin + (event_end - event_begin)
                                        if event[1] == -1:
                                                if new_event_begin >= self.newtimer.begin: # is the soap already running?
-                                                       self.nrep_eventlist.extend([(new_event_begin, event[1], self.bflag),(new_event_end, event[1], self.eflag)])
+                                                       self.nrep_eventlist.extend([(new_event_begin, self.bflag, event[1]),(new_event_end, self.eflag, event[1])])
                                        else:
                                                if new_event_begin >= self.timerlist[event[1]].begin: # is the soap already running?
-                                                       self.nrep_eventlist.extend([(new_event_begin, event[1], self.bflag),(new_event_end, event[1], self.eflag)])
+                                                       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
@@ -138,7 +138,7 @@ class TimerSanityCheck:
                                                event_end = self.timerlist[event[1]].end
                                        new_event_begin = event[0] + offset_0 + (cnt * 604800)
                                        new_event_end = new_event_begin + (event_end - event_begin)
-                                       self.nrep_eventlist.extend([(new_event_begin, event[1], self.bflag),(new_event_end, event[1], self.eflag)])
+                                       self.nrep_eventlist.extend([(new_event_begin, self.bflag, event[1]),(new_event_end, self.eflag, event[1])])
 
 ################################################################################
 # order list chronological
@@ -156,43 +156,41 @@ class TimerSanityCheck:
                idx = 0
                overlaplist = []
                for event in self.nrep_eventlist:
-                       cnt -= event[2]
-                       if event[1] == -1: # new timer
+                       cnt += event[1]
+                       if event[2] == -1: # new timer
                                timer = self.newtimer
                        else:
-                               timer = self.timerlist[event[1]]
-                       if event[2] == self.bflag:
+                               timer = self.timerlist[event[2]]
+                       if event[1] == self.bflag:
                                fakeRecService = NavigationInstance.instance.recordService(timer.service_ref)
+                               fakeRecResult = fakeRecService.start(True)
                                feinfo = fakeRecService.frontendInfo().getFrontendData()
                                tunerType = feinfo.get("tuner_type")
                                tunerSlot = feinfo.get("tuner_number")
-                               if event[1] == -1: # new timer
+                               if event[2] == -1: # new timer
                                        newTimerTunerType = tunerType
                                        newTimerTunerSlot = tunerSlot
-                               fakeRecResult = fakeRecService.start(True)
                                overlaplist.append((fakeRecResult, timer, tunerType, tunerSlot))
                                fakeRecList.append((timer, fakeRecService))
                                if fakeRecResult:
                                        if ConflictTimer is None: # just take care of the first conflict
                                                ConflictTimer = timer
                                                ConflictTunerType = tunerType
-                                               ConflictSlot = tunerSlot
-                       elif event[2] == self.eflag:
+                                               ConflictTunerSlot = tunerSlot
+                       elif event[1] == self.eflag:
                                for fakeRec in fakeRecList:
                                        if timer == fakeRec[0]:
                                                NavigationInstance.instance.stopRecordService(fakeRec[1])
                                                fakeRecList.remove(fakeRec)
                                del fakeRec
-                               if overlaplist.count(timer):
-                                       overlaplist.remove(timer)
+                               for entry in overlaplist:
+                                       if entry[1] == timer:
+                                               overlaplist.remove(entry)
                        else:
                                print "Bug: unknown flag!"
                        self.nrep_eventlist[idx] = (event[0],event[1],event[2],cnt,overlaplist[:]) # insert a duplicate into current overlaplist
                        idx += 1
 
-               for fakeRec in fakeRecList:
-                       NavigationInstance.instance.stopRecordService(fakeRec[1])
-
                if ConflictTimer is None: # no conflict found :)
                        return True