7 import NavigationInstance
9 from Tools.XMLTools import elementsWithTag
10 from ServiceReference import ServiceReference
12 class RecordTimerEntry(TimerEntry):
13 def __init__(self, begin, end, serviceref, epg, description):
14 TimerEntry.__init__(self, int(begin), int(end))
16 assert isinstance(serviceref, ServiceReference)
18 self.service_ref = serviceref
20 print self.service_ref.getServiceName()
22 self.description = description
24 self.record_service = None
26 # build filename from epg
28 # pff das geht noch nicht...
30 # self.Filename = "recording.ts"
32 # self.Filename = "record_" + str(epg.m_event_name) + ".ts"
34 # print "------------ record filename: %s" % (self.Filename)
36 def activate(self, event):
37 if event == self.EventPrepare:
38 self.record_service = NavigationInstance.instance.recordService(self.service_ref)
39 if self.record_service == None:
40 print "timer record failed."
42 self.record_service.prepare()
43 elif self.record_service == None:
44 if event != self.EventAbort:
45 print "timer record start failed, can't finish recording."
46 elif event == self.EventStart:
47 self.record_service.start()
48 print "timer started!"
49 elif event == self.EventEnd or event == self.EventAbort:
50 self.record_service.stop()
51 self.record_service = None
52 print "Timer successfully ended"
56 begin = int(xml.getAttribute("begin"))
57 end = int(xml.getAttribute("end"))
58 serviceref = ServiceReference(str(xml.getAttribute("serviceref")))
59 description = xml.getAttribute("description")
60 epgdata = xml.getAttribute("epgdata")
61 #filename = xml.getAttribute("filename")
62 return RecordTimerEntry(begin, end, serviceref, epgdata, description)
64 class RecordTimer(Timer):
68 self.Filename = "timers.xml"
73 print "unable to load timers from file!"
78 doc = xml.dom.minidom.parse(self.Filename)
80 root = doc.childNodes[0]
81 for timer in elementsWithTag(root.childNodes, "timer"):
82 self.record(createTimer(timer))
85 doc = xml.dom.minidom.Document()
86 root_element = doc.createElement('timers')
87 doc.appendChild(root_element)
88 root_element.appendChild(doc.createTextNode("\n"))
90 for timer in self.timer_list + self.processed_timers:
91 t = doc.createTextNode("\t")
92 root_element.appendChild(t)
93 t = doc.createElement('timer')
94 t.setAttribute("begin", str(timer.begin))
95 t.setAttribute("end", str(timer.end))
96 t.setAttribute("serviceref", str(timer.service_ref))
97 #t.setAttribute("epgdata", timer.)
98 t.setAttribute("description", timer.description)
99 root_element.appendChild(t)
100 t = doc.createTextNode("\n")
101 root_element.appendChild(t)
103 file = open(self.Filename, "w")
104 doc.writexml(codecs.getwriter('UTF-8')(file))
107 def record(self, entry):
109 self.addTimerEntry(entry)
111 def removeEntry(self, entry):
112 if entry.state == TimerEntry.StateRunning:
113 entry.End = time.time()
114 print "aborting timer"
115 elif entry.state != TimerEntry.StateEnded:
116 entry.activate(TimerEntry.EventAbort)
117 self.timer_list.remove(entry)
118 print "timer did not yet start - removing"
120 print "timer did already end - doing nothing."
122 self.calcNextActivation()