make next/prev repeatable
[enigma2.git] / RecordTimer.py
index e375c9f273faee81a30e86b27aadc3614dc5233d..bb42efc901f850d206ddb5912a494a987a859002 100644 (file)
@@ -32,7 +32,7 @@ def parseEvent(ev):
 
 # please do not translate log messages
 class RecordTimerEntry(timer.TimerEntry):
-       def __init__(self, serviceref, begin, end, name, description, eit):
+       def __init__(self, serviceref, begin, end, name, description, eit, disabled = False):
                timer.TimerEntry.__init__(self, int(begin), int(end))
                
                assert isinstance(serviceref, ServiceReference)
@@ -42,8 +42,10 @@ class RecordTimerEntry(timer.TimerEntry):
                self.dontSave = False
                self.name = name
                self.description = description
+               self.disabled = disabled
                self.timer = None
                self.record_service = None
+               self.start_prepare = 0
                
                self.log_entries = []
                self.resetState()
@@ -168,9 +170,12 @@ class RecordTimerEntry(timer.TimerEntry):
                        self.log(14, "user didn't want to zap away, record will probably fail")
 
        def timeChanged(self):
+               old_prepare = self.start_prepare
                self.start_prepare = self.begin - self.prepare_time
                self.backoff = 0
-               self.log(15, "record time changed, start prepare is now: %s" % time.ctime(self.start_prepare))
+               
+               if old_prepare != self.start_prepare:
+                       self.log(15, "record time changed, start prepare is now: %s" % time.ctime(self.start_prepare))
 
 def createTimer(xml):
        begin = int(xml.getAttribute("begin"))
@@ -178,10 +183,17 @@ def createTimer(xml):
        serviceref = ServiceReference(str(xml.getAttribute("serviceref")))
        description = xml.getAttribute("description").encode("utf-8")
        repeated = xml.getAttribute("repeated").encode("utf-8")
-       eit = xml.getAttribute("eit").encode("utf-8")
+       try:
+               disabled = eval(xml.getAttribute("disabled"))
+       except:
+               disabled = False
+       try:
+               eit = long(xml.getAttribute("eit").encode("utf-8"))
+       except:
+               eit = None
        name = xml.getAttribute("name").encode("utf-8")
        #filename = xml.getAttribute("filename").encode("utf-8")
-       entry = RecordTimerEntry(serviceref, begin, end, name, description, eit)
+       entry = RecordTimerEntry(serviceref, begin, end, name, description, eit, disabled)
        entry.repeated = int(repeated)
        
        for l in elementsWithTag(xml.childNodes, "log"):
@@ -217,45 +229,87 @@ class RecordTimer(timer.Timer):
                root = doc.childNodes[0]
                for timer in elementsWithTag(root.childNodes, "timer"):
                        self.record(createTimer(timer))
-       
+
+       def strToXML(self, str):
+               return str.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace("'", '&apos;'). replace('"', '&qout;')
+
        def saveTimer(self):
-               doc = xml.dom.minidom.Document()
-               root_element = doc.createElement('timers')
-               doc.appendChild(root_element)
-               root_element.appendChild(doc.createTextNode("\n"))
+               #doc = xml.dom.minidom.Document()
+               #root_element = doc.createElement('timers')
+               #doc.appendChild(root_element)
+               #root_element.appendChild(doc.createTextNode("\n"))
                
-               for timer in self.timer_list + self.processed_timers:
+               #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(int(timer.begin)))
+                       #t.setAttribute("end", str(int(timer.end)))
+                       #t.setAttribute("serviceref", str(timer.service_ref))
+                       #t.setAttribute("repeated", str(timer.repeated))                        
+                       #t.setAttribute("name", timer.name)
+                       #t.setAttribute("description", timer.description)
+                       #t.setAttribute("eit", str(timer.eit))
+                       
+                       #for time, code, msg in timer.log_entries:
+                               #t.appendChild(doc.createTextNode("\t\t"))
+                               #l = doc.createElement('log')
+                               #l.setAttribute("time", str(time))
+                               #l.setAttribute("code", str(code))
+                               #l.appendChild(doc.createTextNode(msg))
+                               #t.appendChild(l)
+                               #t.appendChild(doc.createTextNode("\n"))
+
+                       #root_element.appendChild(t)
+                       #t = doc.createTextNode("\n")
+                       #root_element.appendChild(t)
+
+
+               #file = open(self.Filename, "w")
+               #doc.writexml(file)
+               #file.write("\n")
+               #file.close()
+
+               list = []
+
+               list.append('<?xml version="1.0" ?>\n')
+               list.append('<timers>\n')
+               
+               for timer in self.timer_list + self.processed_timers:
                        if timer.dontSave:
                                continue
-                       t = doc.createTextNode("\t")
-                       root_element.appendChild(t)
-                       t = doc.createElement('timer')
-                       t.setAttribute("begin", str(int(timer.begin)))
-                       t.setAttribute("end", str(int(timer.end)))
-                       t.setAttribute("serviceref", str(timer.service_ref))
-                       t.setAttribute("repeated", str(timer.repeated))                 
-                       t.setAttribute("name", timer.name)
-                       t.setAttribute("description", timer.description)
-                       t.setAttribute("eit", str(timer.eit))
+
+                       list.append('<timer')
+                       list.append(' begin="' + str(int(timer.begin)) + '"')
+                       list.append(' end="' + str(int(timer.end)) + '"')
+                       list.append(' serviceref="' + str(timer.service_ref) + '"')
+                       list.append(' repeated="' + str(int(timer.repeated)) + '"')
+                       list.append(' name="' + str(self.strToXML(timer.name)) + '"')
+                       list.append(' description="' + str(self.strToXML(timer.description)) + '"')
+                       list.append(' eit="' + str(timer.eit) + '"')
+                       list.append(' disabled="' + str(int(timer.disabled)) + '"')
+                       list.append('>\n')
                        
                        for time, code, msg in timer.log_entries:
-                               t.appendChild(doc.createTextNode("\t\t"))
-                               l = doc.createElement('log')
-                               l.setAttribute("time", str(time))
-                               l.setAttribute("code", str(code))
-                               l.appendChild(doc.createTextNode(msg))
-                               t.appendChild(l)
-                               t.appendChild(doc.createTextNode("\n"))
-
-                       root_element.appendChild(t)
-                       t = doc.createTextNode("\n")
-                       root_element.appendChild(t)
+                               list.append('<log')
+                               list.append(' code="' + str(code) + '"')
+                               list.append(' time="' + str(time) + '"')
+                               list.append('>')
+                               list.append(str(msg))
+                               list.append('</log>\n')
+
+                       
+                       list.append('</timer>\n')
+
+               list.append('</timers>\n')
 
                file = open(self.Filename, "w")
-               doc.writexml(file)
-               file.write("\n")
+               for x in list:
+                       file.write(x)
                file.close()
 
        def record(self, entry):