- add timer, RecordTimer
[enigma2.git] / RecordTimer.py
1 from timer import *
2 import time
3
4 class RecordTimerEntry(TimerEntry):
5         def __init__(self, begin, end, nav, serviceref, epg):
6                 TimerEntry.__init__(self, begin, end)
7                 self.ServiceRef = serviceref
8                 self.EpgData = epg
9                 self.Timer = None
10                 self.Nav = nav
11                 self.RecordService = None
12                 
13                 # build filename from epg
14                 
15                 # pff das geht noch nicht...
16                 if epg == None:
17                         self.Filename = "recording.ts"
18                 else:
19                         self.Filename = "record_" + str(epg.m_event_name) + ".ts"
20                 
21                 print "------------ record filename: %s" % (self.Filename)
22                 
23         def activate(self, event):
24                 if event == self.EventPrepare:
25                         self.RecordService = self.Nav.recordService(self.ServiceRef)
26                         if self.RecordService == None:
27                                 print "timer record failed."
28                         else:   
29                                 self.RecordService.prepare()
30                 elif self.RecordService == None:
31                         if event != self.EventAbort:
32                                 print "timer record start failed, can't finish recording."
33                 elif event == self.EventStart:
34                         self.RecordService.start()
35                         print "timer started!"
36                 elif event == self.EventEnd or event == self.EventAbort:
37                         self.RecordService.stop()
38                         self.RecordService = None
39                         print "Timer successfully ended"
40
41 class RecordTimer(Timer):
42         def __init__(self):
43                 Timer.__init__(self)
44                 
45         def loadTimer(self):
46                 print "TODO: load timers from xml"
47         
48         def saveTimer(self):
49                 print "TODO: save timers to xml"
50         
51         def record(self, entry):
52                 entry.Timer = self
53                 self.addTimerEntry(entry)
54
55         def removeEntry(self, entry):
56                 if entry.State == TimerEntry.StateRunning:
57                         entry.End = time.time()
58                         print "aborting timer"
59                 elif entry.State != TimerEntry.StateEnded:
60                         entry.activate(TimerEntry.EventAbort)
61                         self.TimerList.remove(entry)
62                         print "timer did not yet start - removing"
63                 else:
64                         print "timer did already end - doing nothing."
65
66                 self.calcNextActivation()