show movieSelection on up/down keys in movie player
[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, parseEvent
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                 event = None
58                 service = self.session.nav.getCurrentService()
59                 if service is not None:
60                         info = service.info()
61                         if info is not None:
62                                 event = info.getEvent(0)
63
64                 # FIXME only works if already playing a service
65                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
66                 
67                 if event is None:       
68                         data = (int(time()), int(time() + 60), "unknown event", "", None)
69                 else:
70                         data = parseEvent(event)
71
72                 self.addTimer(RecordTimerEntry(serviceref, *data))
73                 
74         def addTimer(self, timer):
75                 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
76                 
77         def finishedEdit(self, answer):
78                 if (answer[0]):
79                         print "Edited timer"
80                         self.session.nav.RecordTimer.timeChanged(answer[1])
81                         self.fillTimerList()
82                 else:
83                         print "Timeredit aborted"
84                         
85         def finishedAdd(self, answer):
86                 if (answer[0]):
87                         self.session.nav.RecordTimer.record(answer[1])
88                         self.fillTimerList()
89                 else:
90                         print "Timeredit aborted"               
91
92         def leave(self):
93                 self.session.nav.RecordTimer.saveTimer()
94                 self.close()