- fixed left/right in language selection (updates language on the fly)
[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 TimerEntry import TimerEntry, TimerLog
8 from RecordTimer import RecordTimerEntry, parseEvent
9 from time import *
10 from ServiceReference import ServiceReference
11 from Components.config import *
12
13 class TimerEditList(Screen):
14         def __init__(self, session):
15                 Screen.__init__(self, session)
16                 
17                 list = [ ]
18                 self.list = list
19                 self.fillTimerList()
20
21                 self["timerlist"] = TimerList(list)
22                 
23                 self["key_red"] = Button(_("Delete"))
24                 self["key_green"] = Button(_("Add"))
25                 self["key_yellow"] = Button("")
26                 self["key_blue"] = Button("")
27
28                 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "TimerEditActions"], 
29                         {
30                                 "ok": self.openEdit,
31                                 "cancel": self.leave,
32                                 "red": self.removeTimer,
33                                 "green": self.addCurrentTimer,
34                                 "log": self.showLog
35                         })
36                 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
37
38         def fillTimerList(self):
39                 del self.list[:]
40                 
41                 for timer in self.session.nav.RecordTimer.timer_list:
42                         self.list.append(TimerEntryComponent(timer, processed=False))
43                 
44                 for timer in self.session.nav.RecordTimer.processed_timers:
45                         self.list.append(TimerEntryComponent(timer, processed=True))
46
47         def showLog(self):
48                 self.session.openWithCallback(self.finishedEdit, TimerLog, self["timerlist"].getCurrent()[0])
49
50         def openEdit(self):
51                 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
52                 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
53                 
54         def removeTimer(self):
55                 list = self["timerlist"]
56                 currentIndex = list.getCurrentIndex()
57                 list.moveDown()
58                 if list.getCurrentIndex() == currentIndex:
59                         currentIndex -= 1
60                         list.moveToIndex(currentIndex)
61                 self.session.nav.RecordTimer.removeEntry(list.getCurrent()[0])
62                 self.refill()
63         
64         def refill(self):
65                 self.fillTimerList()
66                 self["timerlist"].invalidate()
67         
68         def addCurrentTimer(self):
69                 event = None
70                 service = self.session.nav.getCurrentService()
71                 if service is not None:
72                         info = service.info()
73                         if info is not None:
74                                 event = info.getEvent(0)
75
76                 # FIXME only works if already playing a service
77                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
78                 
79                 if event is None:       
80                         data = (int(time()), int(time() + 60), "unknown event", "", None)
81                 else:
82                         data = parseEvent(event)
83
84                 self.addTimer(RecordTimerEntry(serviceref, *data))
85                 
86         def addTimer(self, timer):
87                 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
88                 
89         def finishedEdit(self, answer):
90                 print "finished edit"
91                 if answer[0]:
92                         print "Edited timer"
93                         self.session.nav.RecordTimer.timeChanged(answer[1])
94                         self.fillTimerList()
95                 else:
96                         print "Timeredit aborted"
97
98         def finishedAdd(self, answer):
99                 print "finished add"
100                 if answer[0]:
101                         entry = answer[1]
102                         self.session.nav.RecordTimer.record(entry)
103                         self.fillTimerList()
104                 else:
105                         print "Timeredit aborted"               
106
107         def leave(self):
108                 self.session.nav.RecordTimer.saveTimer()
109                 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
110                 self.close()
111
112         def onStateChange(self, entry):
113                 self.refill()