use default service types for filtering in bouquets
[enigma2.git] / lib / python / Screens / TimerEdit.py
index 173b1ba20b336fd071a757594861c93748f21012..7373391349ba42790de80b3fa20258d75100955c 100644 (file)
@@ -1,72 +1,94 @@
 from Screen import Screen
-from Components.TimerList import TimerList, TimerEntry
+from Components.TimerList import TimerList, TimerEntryComponent
 from Components.ActionMap import ActionMap
 from Components.TimeInput import TimeInput
 from Components.Label import Label
 from Components.Button import Button
 from Components.TextInput import TextInput
+from TimerEntry import TimerEntry
+from RecordTimer import RecordTimerEntry, parseEvent
+from time import *
+from ServiceReference import ServiceReference
+from Components.config import *
 
-class TimerEdit(Screen):
-       def __init__(self, session, entry):
+class TimerEditList(Screen):
+       def __init__(self, session):
                Screen.__init__(self, session)
+               
+               list = [ ]
+               self.list = list
+               self.fillTimerList()
 
-               self["actions"] = ActionMap(["OkCancelActions"], 
-                       {
-                               "ok": self.apply,
-                               "cancel": self.close
-                       })
+               self["timerlist"] = TimerList(list)
                
-               self["shortcuts"] = ActionMap(["ShortcutActions"],
+               self["key_red"] = Button(_("Delete"))
+               self["key_green"] = Button(_("Add"))
+               self["key_yellow"] = Button("")
+               self["key_blue"] = Button("")
+
+               self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], 
                        {
-                               "red": self.beginFocus,
-                               "yellow": self.endFocus,
-                               "green": self.descFocus
+                               "ok": self.openEdit,
+                               "cancel": self.leave,
+                               "red": self.removeTimer,
+                               "green": self.addCurrentTimer
                        })
+
+       def fillTimerList(self):
+               del self.list[:]
                
-               self.entry = entry
-               # begin, end, description, service
-               self["begin"] = TimeInput()
-               self["end"] = TimeInput()
-               
-               self["lbegin"] = Label("Begin")
-               self["lend"] = Label("End")
+               for timer in self.session.nav.RecordTimer.timer_list:
+                       self.list.append(TimerEntryComponent(timer, 0))
                
-               self["description"] = TextInput()
-               self["apply"] = Button("Apply")
-               self["service"] = Button()
+               for timer in self.session.nav.RecordTimer.processed_timers:
+                       self.list.append(TimerEntryComponent(timer, 1))
+
+       def openEdit(self):
+               self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
+               #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
                
-               self["description"].setText(entry.description);
-       
-       def beginFocus(self):
-               self.setFocus(self["begin"])
-       
-       def endFocus(self):
-               self.setFocus(self["end"])
+       def removeTimer(self):
+               # FIXME doesn't work...
+               self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0])
+               self.fillTimerList()
+               self["timerlist"].invalidate()
        
-       def descFocus(self):
-               self.setFocus(self["description"])
-       
-       def apply(self):
-               print "applied!"
-       
-class TimerEditList(Screen):
-       def __init__(self, session):
-               Screen.__init__(self, session)
+       def addCurrentTimer(self):
+               event = None
+               service = self.session.nav.getCurrentService()
+               if service is not None:
+                       info = service.info()
+                       if info is not None:
+                               event = info.getEvent(0)
+
+               # FIXME only works if already playing a service
+               serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
                
-               list = [ ]
-               for timer in session.nav.RecordTimer.timer_list:
-                       list.append(TimerEntry(timer, 0))
+               if event is None:       
+                       data = (int(time()), int(time() + 60), "unknown event", "", None)
+               else:
+                       data = parseEvent(event)
+
+               self.addTimer(RecordTimerEntry(serviceref, *data))
                
-               for timer in session.nav.RecordTimer.processed_timers:
-                       list.append(TimerEntry(timer, 1))
+       def addTimer(self, timer):
+               self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
                
-               self["timerlist"] = TimerList(list)
-
-               self["actions"] = ActionMap(["OkCancelActions"], 
-                       {
-#                              "ok": self.openEdit,
-                               "cancel": self.close
-                       })
+       def finishedEdit(self, answer):
+               if (answer[0]):
+                       print "Edited timer"
+                       self.session.nav.RecordTimer.timeChanged(answer[1])
+                       self.fillTimerList()
+               else:
+                       print "Timeredit aborted"
+                       
+       def finishedAdd(self, answer):
+               if (answer[0]):
+                       self.session.nav.RecordTimer.record(answer[1])
+                       self.fillTimerList()
+               else:
+                       print "Timeredit aborted"               
 
-       def openEdit(self):
-               self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
+       def leave(self):
+               self.session.nav.RecordTimer.saveTimer()
+               self.close()