sorry, i REALLY don't know, how to fix it other than using a try/except block
[enigma2.git] / RecordTimer.py
index cf49df2..18cc64a 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
@@ -85,9 +86,12 @@ def createTimer(xml):
        end = int(xml.getAttribute("end"))
        serviceref = ServiceReference(str(xml.getAttribute("serviceref")))
        description = xml.getAttribute("description")
+       repeated = xml.getAttribute("repeated")
        epgdata = xml.getAttribute("epgdata")
        #filename = xml.getAttribute("filename")
-       return RecordTimerEntry(begin, end, serviceref, epgdata, description)
+       entry = RecordTimerEntry(begin, end, serviceref, epgdata, description)
+       entry.repeated = int(repeated)
+       return entry
 
 class RecordTimer(timer.Timer):
        def __init__(self):
@@ -99,9 +103,15 @@ class RecordTimer(timer.Timer):
                        self.loadTimer()
                except:
                        print "unable to load timers from file!"
+                       
+       def isRecording(self):
+               isRunning = False
+               for timer in self.timer_list:
+                       if timer.isRunning():
+                               isRunning = True
+               return isRunning
        
        def loadTimer(self):
-               
                # TODO: PATH!
                doc = xml.dom.minidom.parse(self.Filename)
                
@@ -116,39 +126,61 @@ 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')
                        t.setAttribute("begin", str(timer.begin))
                        t.setAttribute("end", str(timer.end))
                        t.setAttribute("serviceref", str(timer.service_ref))
+                       t.setAttribute("repeated", str(timer.repeated))                 
                        #t.setAttribute("epgdata", timer.)
                        t.setAttribute("description", timer.description)
                        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):
+               print "[Timer] Record " + str(entry)
                entry.Timer = self
                self.addTimerEntry(entry)
 
        def removeEntry(self, entry):
+               print "[Timer] Remove " + str(entry)
+
                if entry.state == timer.TimerEntry.StateRunning:
+                       print "remove running timer."
                        entry.end = time.time()
                        self.timeChanged(entry)
                elif entry.state != timer.TimerEntry.StateEnded:
                        entry.activate(timer.TimerEntry.EventAbort)
-                       self.timer_list.remove(entry)
+                       try: # FIXME: is needed, because after loading the timers, every timer (even already ended ones)
+                                # have the state EventWaiting..
+                               self.timer_list.remove(entry)
+                       except:
+                               pass
+                               
+                       self.calcNextActivation()
                        print "timer did not yet start - removing"
                else:
                        print "timer did already end - doing nothing."
-
-               self.calcNextActivation()
-
+               
+               print "state: ", entry.state
+               print "in processed: ", entry in self.processed_timers
+               print "in running: ", entry in self.timer_list
+               # now the timer should be in the processed_timers list. remove it from there.
+               try:
+                       self.processed_timers.remove(entry)
+               except:
+                       pass
 
        def shutdown(self):
                self.saveTimer()