5233da9b759eb099ab5c05e821053a82091b5a94
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / TimerEdit.py
1 from Screen import Screen
2 from Components.TimerList import TimerList, TimerEntryComponent
3 from Components.ActionMap import ActionMap
4 from Components.TimeInput import TimeInput
5 from Components.Label import Label
6 from Components.Button import Button
7 from Components.TextInput import TextInput
8 from TimerEntry import TimerEntry
9 from RecordTimer import RecordTimerEntry
10 from time import *
11 from ServiceReference import ServiceReference
12 from Components.config import *
13
14 class TimerEditList(Screen):
15         def __init__(self, session):
16                 Screen.__init__(self, session)
17                 
18                 list = [ ]
19                 self.list = list
20                 self.fillTimerList()
21
22                 self["timerlist"] = TimerList(list)
23                 
24                 self["key_red"] = Button(_("Delete"))
25                 self["key_green"] = Button(_("Add"))
26                 self["key_yellow"] = Button("")
27                 self["key_blue"] = Button("")
28
29                 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], 
30                         {
31                                 "ok": self.openEdit,
32                                 "cancel": self.leave,
33                                 "red": self.removeTimer,
34                                 "green": self.addCurrentTimer
35                         })
36
37         def fillTimerList(self):
38                 del self.list[:]
39                 
40                 for timer in self.session.nav.RecordTimer.timer_list:
41                         self.list.append(TimerEntryComponent(timer, 0))
42                 
43                 for timer in self.session.nav.RecordTimer.processed_timers:
44                         self.list.append(TimerEntryComponent(timer, 1))
45
46         def openEdit(self):
47                 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
48                 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
49                 
50         def removeTimer(self):
51                 # FIXME doesn't work...
52                 self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0])
53                 self.fillTimerList()
54                 self["timerlist"].invalidate()
55         
56         def addCurrentTimer(self):
57                 begin = time()
58                 end = time() + 60
59                 
60                 epg = None
61                 try:
62                         service = self.session.nav.getCurrentService()
63                         info = service.info()
64                         ev = info.getEvent(0)
65                         epg = ev
66                 except:
67                         pass
68                 
69                 if (epg == None):
70                         description = "unknown event"
71                 else:
72                         description = ev.getEventName()
73                         # FIXME we need a timestamp here:
74                         begin = ev.getBeginTime()
75                         
76                         print begin
77                         print ev.getDuration()
78                         end = begin + ev.getDuration()
79
80
81                 # FIXME only works if already playing a service
82                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
83                 
84                 self.addTimer(RecordTimerEntry(begin, end, serviceref, epg, description))
85                 
86         def addTimer(self, timer):
87                 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
88                 
89         def finishedEdit(self, answer):
90                 if (answer[0]):
91                         print "Edited timer"
92                         self.session.nav.RecordTimer.timeChanged(answer[1])
93                         self.fillTimerList()
94                 else:
95                         print "Timeredit aborted"
96                         
97         def finishedAdd(self, answer):
98                 if (answer[0]):
99                         self.session.nav.RecordTimer.record(answer[1])
100                         self.fillTimerList()
101                 else:
102                         print "Timeredit aborted"               
103
104         def leave(self):
105                 self.session.nav.RecordTimer.saveTimer()
106                 self.close()