timer-add-support
[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
13 class TimerEdit(Screen):
14         def __init__(self, session, entry):
15                 Screen.__init__(self, session)
16
17                 self["actions"] = ActionMap(["OkCancelActions"], 
18                         {
19                                 "ok": self.apply,
20                                 "cancel": self.close
21                         })
22                 
23                 self["shortcuts"] = ActionMap(["ShortcutActions"],
24                         {
25                                 "red": self.beginFocus,
26                                 "yellow": self.endFocus,
27                                 "green": self.descFocus
28                         })
29                 
30                 self.entry = entry
31                 # begin, end, description, service
32                 self["begin"] = TimeInput()
33                 self["end"] = TimeInput()
34                 
35                 self["lbegin"] = Label("Begin")
36                 self["lend"] = Label("End")
37                 
38                 self["description"] = TextInput()
39                 self["apply"] = Button("Apply")
40                 self["service"] = Button()
41                 
42                 self["description"].setText(entry.description);
43         
44         def beginFocus(self):
45                 self.setFocus(self["begin"])
46         
47         def endFocus(self):
48                 self.setFocus(self["end"])
49         
50         def descFocus(self):
51                 self.setFocus(self["description"])
52         
53         def apply(self):
54                 print "applied!"
55         
56 class TimerEditList(Screen):
57         def __init__(self, session):
58                 Screen.__init__(self, session)
59                 
60                 list = [ ]
61                 for timer in session.nav.RecordTimer.timer_list:
62                         list.append(TimerEntryComponent(timer, 0))
63                 
64                 for timer in session.nav.RecordTimer.processed_timers:
65                         list.append(TimerEntryComponent(timer, 1))
66                 
67                 self["timerlist"] = TimerList(list)
68                 
69                 self["key_red"] = Button("Delete")
70                 self["key_green"] = Button("Add")
71                 self["key_yellow"] = Button("")
72                 self["key_blue"] = Button("")
73
74                 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], 
75                         {
76                                 "ok": self.openEdit,
77                                 "cancel": self.close,
78                                 "red": self.removeTimer,
79                                 "green": self.addTimer
80                         })
81
82         def openEdit(self):
83                 self.session.open(TimerEntry, self["timerlist"].getCurrent()[0])
84                 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
85                 
86         def removeTimer(self):
87                 self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0])
88         
89         def addTimer(self):
90                 begin = time()
91                 end = time() + 60
92                 
93                 epg = None
94                 try:
95                         service = self.session.nav.getCurrentService()
96                         info = service.info()
97                         ev = info.getEvent(0)
98                         epg = ev
99                 except:
100                         pass
101                 
102                 if (epg == None):
103                         description = "unknown event"
104                 else:
105                         description = ev.getEventName()
106                         # FIXME we need a timestamp here:
107                         begin = ev.getBeginTime()
108                         
109                         print begin
110                         print ev.getDuration()
111                         end = begin + ev.getDuration()
112
113
114                 # FIXME only works if already playing a service
115                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
116                 
117                 newEntry = RecordTimerEntry(begin, end, serviceref, epg, description)
118                 self.session.open(TimerEntry, newEntry)
119