fixed repeated timers
[enigma2.git] / lib / python / Screens / TimerEdit.py
index f8c9f20797c5df37132841347368a3ac955e4c55..0f902679e1d49a061282cd5d116b0946e3e6b143 100644 (file)
 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
+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.close,
+                               "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)
-               
-               list = [ ]
-               for timer in session.nav.RecordTimer.timer_list:
-                       list.append(TimerEntry(timer, 0))
+       def addCurrentTimer(self):
+               begin = time()
+               end = time() + 60
                
-               for timer in session.nav.RecordTimer.processed_timers:
-                       list.append(TimerEntry(timer, 1))
+               epg = None
+               try:
+                       service = self.session.nav.getCurrentService()
+                       info = service.info()
+                       ev = info.getEvent(0)
+                       epg = ev
+               except:
+                       pass
                
-               self["timerlist"] = TimerList(list)
+               if (epg == None):
+                       description = "unknown event"
+               else:
+                       description = ev.getEventName()
+                       # FIXME we need a timestamp here:
+                       begin = ev.getBeginTime()
+                       
+                       print begin
+                       print ev.getDuration()
+                       end = begin + ev.getDuration()
 
-               self["actions"] = ActionMap(["OkCancelActions"], 
-                       {
-                               "ok": self.openEdit,
-                               "cancel": self.close
-                       })
 
-       def openEdit(self):
-               self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
+               # FIXME only works if already playing a service
+               serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
+               
+               self.addTimer(RecordTimerEntry(begin, end, serviceref, epg, description))
+               
+       def addTimer(self, timer):
+               self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
+               
+       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"