timer: fix displayed state. Don't save instant records. properly remove timerentries.
authorFelix Domke <tmbinc@elitedvb.net>
Wed, 16 Nov 2005 11:15:24 +0000 (11:15 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Wed, 16 Nov 2005 11:15:24 +0000 (11:15 +0000)
RecordTimer.py
lib/python/Components/TimerList.py
lib/python/Screens/InfoBarGenerics.py
timer.py

index cf49df2..aa48415 100644 (file)
@@ -25,6 +25,7 @@ class RecordTimerEntry(timer.TimerEntry):
                else:
                        self.epg_data = ""
                
+               self.dontSave = False
                self.description = description
                self.timer = None
                self.record_service = None
@@ -101,7 +102,6 @@ class RecordTimer(timer.Timer):
                        print "unable to load timers from file!"
        
        def loadTimer(self):
-               
                # TODO: PATH!
                doc = xml.dom.minidom.parse(self.Filename)
                
@@ -116,6 +116,10 @@ class RecordTimer(timer.Timer):
                root_element.appendChild(doc.createTextNode("\n"))
                
                for timer in self.timer_list + self.processed_timers:
+                       # some timers (instant records) don't want to be saved.
+                       # skip them
+                       if timer.dontSave:
+                               continue
                        t = doc.createTextNode("\t")
                        root_element.appendChild(t)
                        t = doc.createElement('timer')
@@ -127,9 +131,10 @@ class RecordTimer(timer.Timer):
                        root_element.appendChild(t)
                        t = doc.createTextNode("\n")
                        root_element.appendChild(t)
-               
+
                file = open(self.Filename, "w")
                doc.writexml(codecs.getwriter('UTF-8')(file))
+               file.write("\n")
                file.close()
        
        def record(self, entry):
@@ -143,12 +148,13 @@ class RecordTimer(timer.Timer):
                elif entry.state != timer.TimerEntry.StateEnded:
                        entry.activate(timer.TimerEntry.EventAbort)
                        self.timer_list.remove(entry)
+                       self.calcNextActivation()
                        print "timer did not yet start - removing"
                else:
                        print "timer did already end - doing nothing."
-
-               self.calcNextActivation()
-
+               
+               # now the timer should be in the processed_timers list. remove it from there.
+               self.processed_timers.remove(entry)
 
        def shutdown(self):
                self.saveTimer()
index 078210b..43a55fd 100644 (file)
@@ -4,7 +4,7 @@ from GUIComponent import *
 from Tools.FuzzyDate import FuzzyTime
 
 from enigma import eListboxPythonMultiContent, eListbox, gFont
-
+from timer import TimerEntry
 
 RT_HALIGN_LEFT = 0
 RT_HALIGN_RIGHT = 1
@@ -20,20 +20,31 @@ RT_WRAP = 32
 
 #
 #  | <Service>     <Name of the Timer>  |
-#  | <start>                     <end>  |
+#  | <start, end>              <state>  |
 #
 def TimerEntryComponent(timer, processed):
        res = [ timer ]
        
 
        res.append((0, 0, 400, 30, 0, RT_HALIGN_LEFT, timer.service_ref.getServiceName()))
-       res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, "%s, %s" % FuzzyTime(timer.begin)))
+       res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, "%s, %s ... %s" % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:])))
 
-       res.append((300, 0, 200, 20, 1, RT_HALIGN_RIGHT, timer.description))    
-       if processed:
-               res.append((300, 30, 200, 20, 1, RT_HALIGN_RIGHT, FuzzyTime(timer.end)[1]))
+       res.append((300, 0, 200, 20, 1, RT_HALIGN_RIGHT, timer.description))
+       
+       if not processed:
+               if timer.state == TimerEntry.StateWait:
+                       state = "waiting"
+               elif timer.state == TimerEntry.StatePrepare:
+                       state = "about to start"
+               elif timer.state == TimerEntry.StateRunning:
+                       state = "recording..."
+               else:
+                       state = "<unknown>"
        else:
-               res.append((300, 30, 200, 20, 1, RT_HALIGN_RIGHT, "done"))
+               state = "done!"
+       
+       res.append((300, 30, 200, 20, 1, RT_HALIGN_RIGHT, state))
+       
        return res
 
 class TimerList(HTMLComponent, GUIComponent):
index 1ef3998..3af52ae 100644 (file)
@@ -362,6 +362,7 @@ class InfoBarInstantRecord:
                
                # fix me, description. 
                self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
+               self.recording.dontSave = True
 
        def recordQuestionCallback(self, answer):
                if answer == False:
index 1679a9b..a230545 100644 (file)
--- a/timer.py
+++ b/timer.py
@@ -52,15 +52,17 @@ class Timer:
                
                self.timer = eTimer()
                self.timer.timeout.get().append(self.calcNextActivation)
+               self.lastActivation = time.time()
                
                self.calcNextActivation()
        
-       def addTimerEntry(self, entry):
+       def addTimerEntry(self, entry, noRecalc=0):
                # we either go trough Prepare/Start/End-state if the timer is still running,
                # or skip it when it's alrady past the end.
                if entry.end > time.time():
                        bisect.insort(self.timer_list, entry)
-                       self.calcNextActivation()
+                       if not noRecalc:
+                               self.calcNextActivation()
                else:
                        bisect.insort(self.processed_timers, entry)
        
@@ -72,7 +74,15 @@ class Timer:
                self.next = when
 
        def calcNextActivation(self):
+               if self.lastActivation > time.time():
+                       print "[timer.py] timewarp - re-evaluating all processed timers."
+                       tl = self.processed_timers
+                       self.processed_timers = [ ]
+                       for x in tl:
+                               self.addTimerEntry(x, noRecalc=1)
+               
                self.processActivation()
+               self.lastActivation = time.time()
        
                min = int(time.time()) + self.MaxWaitTime
                
@@ -86,7 +96,7 @@ class Timer:
        
        def timeChanged(self, timer):
                self.timer_list.remove(timer)
-               bisect.insort(self.timer_list, timer)
+               self.addTimerEntry(timer)
        
        def doActivate(self, w):
                w.activate(w.state)