working on move, edit mode and add remove service to context menu
[enigma2.git] / lib / python / Screens / TimerEdit.py
index 2fe389e..4f5039e 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
+                               "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()
+               for timer in self.session.nav.RecordTimer.timer_list:
+                       self.list.append(TimerEntryComponent(timer, 0))
                
-               self["lbegin"] = Label("Begin")
-               self["lend"] = Label("End")
+               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"] = Label("bla")
-# TextInput()
-               self["apply"] = Button("Apply")
-               self["service"] = Button()
-       
-       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 apply(self):
-               print "applied!"
-       
-class TimerEditList(Screen):
-       def __init__(self, session):
-               Screen.__init__(self, session)
+       def addCurrentTimer(self):
+               begin = time()
+               end = time() + 60
                
-               list = [ ]
-               for timer in session.nav.RecordTimer.timer_list:
-                       list.append(TimerEntry(timer, 0))
-               
-               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())
+               # 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.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"