- add "ok" to the configMenu's actionlist again
[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                 for timer in session.nav.RecordTimer.timer_list:
20                         list.append(TimerEntryComponent(timer, 0))
21                 
22                 for timer in session.nav.RecordTimer.processed_timers:
23                         list.append(TimerEntryComponent(timer, 1))
24                 
25                 self["timerlist"] = TimerList(list)
26                 
27                 self["key_red"] = Button("Delete")
28                 self["key_green"] = Button("Add")
29                 self["key_yellow"] = Button("")
30                 self["key_blue"] = Button("")
31
32                 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], 
33                         {
34                                 "ok": self.openEdit,
35                                 "cancel": self.close,
36                                 "red": self.removeTimer,
37                                 "green": self.addCurrentTimer
38                         })
39
40         def openEdit(self):
41                 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
42                 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
43                 
44         def removeTimer(self):
45                 # FIXME doesn't work...
46                 self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0])
47         
48         def addCurrentTimer(self):
49                 begin = time()
50                 end = time() + 60
51                 
52                 epg = None
53                 try:
54                         service = self.session.nav.getCurrentService()
55                         info = service.info()
56                         ev = info.getEvent(0)
57                         epg = ev
58                 except:
59                         pass
60                 
61                 if (epg == None):
62                         description = "unknown event"
63                 else:
64                         description = ev.getEventName()
65                         # FIXME we need a timestamp here:
66                         begin = ev.getBeginTime()
67                         
68                         print begin
69                         print ev.getDuration()
70                         end = begin + ev.getDuration()
71
72
73                 # FIXME only works if already playing a service
74                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
75                 
76                 self.addTimer(begin, end, serviceref, epg, description)
77                 
78         def addTimer(self, begin, end, serviceref, epg, description):
79                 newEntry = RecordTimerEntry(begin, end, serviceref, epg, description)
80                 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
81                 
82         def finishedEdit(self, answer):
83                 if (answer[0]):
84                         print "Edited timer"
85                 else:
86                         print "Timeredit aborted"
87
88         def finishedAdd(self, answer):
89                 if (answer[0]):
90                         print "Added timer"
91                 else:
92                         print "Timeredit aborted"