AFTEREVENT changed
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / Timer.py
1 from enigma import *
2 from enigma import eServiceReference 
3
4 from Components.Sources.Source import Source
5 from ServiceReference import ServiceReference
6 from RecordTimer import RecordTimerEntry, RecordTimer, AFTEREVENT,parseEvent
7
8 import time
9
10 class Timer( Source):
11     LIST = 0
12     ADDBYID = 1
13     ADD = 2
14     def __init__(self, session,func = LIST):
15         self.func = func
16         Source.__init__(self)        
17         self.session = session
18         self.recordtimer = session.nav.RecordTimer
19         
20     def handleCommand(self,cmd):
21         print "Timer.handleCommand()",cmd
22         if self.func is self.ADDBYID:
23             self.resultText = self.addTimerByEventID(cmd)
24         elif self.func is self.ADD:
25             self.resultText = self.addTimer(cmd)
26         else:
27             self.resultText = "unknown command"
28     
29     def addTimer(self,param):
30         # is there an easier and better way? :\ 
31         print "addTimerByEventID",param
32         if param['serviceref'] is None:
33             return "ServiceReference missing"
34         else: 
35             serviceref = ServiceReference(param['serviceref'])
36         
37         if param['begin'] is None:
38            return "begin missing"
39         elif time.time() <= float(param['begin']):
40             begin = float(param['begin'])
41         else:
42             return "incorrect time begin"
43             
44         
45         if param['end'] is None:
46             return "end missing"
47         elif begin < float(param['end']):
48             end = float(param['end'])
49         else:
50              return "incorrect time end"
51                 
52         if param['name'] is None:
53             return "name is missing"
54         else:
55             name = param['name']
56             
57         if param['description'] is not None:
58             description = param['description']
59         else: 
60             description = ""
61             
62         if param['disabled'] =="0":
63             disabled = False
64         elif param['disabled'] =="1":
65             disabled = True
66         else:
67             return "disabled incorrect"
68         
69         if param['disabled'] == "0":
70             disabled = False
71         elif param['disabled'] == "1":
72             disabled = True
73         else:
74             return "disabled incorrect"
75
76         if param['justplay'] == "0":
77             justplay = False
78         elif param['justplay'] == "1":
79             justplay = True
80         else:
81             return "justplay incorrect"
82             
83         if param['afterevent'] == "0":
84             afterevent = 0
85         elif param['afterevent'] == "1":
86             afterevent = 1
87         elif param['afterevent'] == "2":
88             afterevent = 2
89         else:
90             return "afterevent incorrect"
91             
92         newtimer = RecordTimerEntry(serviceref, begin, end, name, description, 0, disabled, justplay, afterevent)
93         self.session.nav.RecordTimer.record(newtimer)
94         #self.session.nav.RecordTimer.saveTimer()
95         return "Timer added"        
96
97     def addTimerByEventID(self,param):
98         print "addTimerByEventID",param['serviceref'],param['eventid']
99         epgcache = eEPGCache.getInstance()
100         event = epgcache.lookupEventId(eServiceReference(param['serviceref']),int(param['eventid']))
101         if event is None:
102             return "Eventid not found"
103         (begin, end, name, description, eit) =parseEvent(event)
104         newtimer = RecordTimerEntry(ServiceReference(param['serviceref']), begin, end, name, description, eit, False, False, AFTEREVENT.NONE)
105         self.session.nav.RecordTimer.record(newtimer)
106         return "Timer added"    
107             
108     def getText(self):    
109         return self.resultText
110     
111     text = property(getText)    
112     
113     ## part for listfiller requests
114     def command(self):
115         timerlist = []
116         for item in self.recordtimer.timer_list+self.recordtimer.processed_timers:
117             timer = []
118             timer.append(item.service_ref)
119             timer.append(item.service_ref.getServiceName())
120             timer.append(item.eit)
121             timer.append(item.name)
122             timer.append(item.description)
123             timer.append(item.disabled)
124             timer.append(item.begin)
125             timer.append(item.end)
126             timer.append(item.end-item.begin)
127             timer.append(item.start_prepare)
128             timer.append(item.justplay)
129             timer.append(item.afterEvent)
130             timer.append(item.log_entries)
131             try: 
132                 timer.append(item.Filename)
133             except AttributeError:
134                 timer.append("")
135             
136             timer.append(item.backoff)       
137             try:
138                 timer.append(item.next_activation)
139             except AttributeError:
140                 timer.append("")
141             timer.append(item.first_try_prepare)  
142             timer.append(item.state)  
143             timer.append(item.repeated)
144             timer.append(item.dontSave)
145             timer.append(item.cancelled)
146             timerlist.append(timer) 
147             
148         return timerlist
149     
150     list = property(command)
151     lut = {"ServiceReference": 0
152            ,"ServiceName": 1
153            ,"EIT":2
154            ,"Name":3
155            ,"Description":4
156            ,"Disabled":5
157            ,"TimeBegin":6
158            ,"TimeEnd":7
159            ,"Duration":8
160            ,"startPrepare":9
161            ,"justPlay":10
162            ,"afterEvent":11
163            ,"LogEntries":12
164            ,"Filename":13
165            ,"Backoff":14
166            ,"nextActivation":15
167            ,"firstTryPrepare":16
168            ,"State":17
169            ,"Repeated":18
170            ,"dontSave":19
171            ,"Cancled":20
172            }
173