1 from Screen import Screen
2 from LocationBox import LocationBox
3 import ChannelSelection
4 from ServiceReference import ServiceReference
5 from Components.config import config, ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
6 from Components.ActionMap import NumberActionMap
7 from Components.ConfigList import ConfigListScreen
8 from Components.MenuList import MenuList
9 from Components.Button import Button
10 from Components.Label import Label
11 from Components.Pixmap import Pixmap
12 from Screens.ChoiceBox import ChoiceBox
13 from RecordTimer import AFTEREVENT
14 from enigma import eEPGCache
18 class TimerEntry(Screen, ConfigListScreen):
19 def __init__(self, session, timer):
20 Screen.__init__(self, session)
23 self.entryStartDate = None
24 self.entryEndDate = None
25 self.entryService = None
27 self["oktext"] = Label(_("OK"))
28 self["canceltext"] = Label(_("Cancel"))
29 self["locationtext"] = Label(_("Choose Location"))
31 self["cancel"] = Pixmap()
32 self["location"] = Pixmap()
36 self["actions"] = NumberActionMap(["SetupActions", "ColorActions"],
40 "cancel": self.keyCancel,
41 "yellow": self.selectPath,
45 ConfigListScreen.__init__(self, self.list, session = session)
46 self.createSetup("config")
48 self.onLayoutFinish.append(self.handleLocation)
50 def handleLocation(self):
51 if config.usage.setup_level.index < 2: # -expert
52 self["locationtext"].hide()
53 self["location"].hide()
55 def createConfig(self):
56 justplay = self.timer.justplay
58 afterevent = { AFTEREVENT.NONE: "nothing", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.STANDBY: "standby"}[self.timer.afterEvent]
60 weekday_table = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
62 # calculate default values
67 if self.timer.repeated: # repeated
69 if (self.timer.repeated == 31): # Mon-Fri
71 elif (self.timer.repeated == 127): # daily
74 flags = self.timer.repeated
78 if flags == 1: # weekly
79 print "Set to weekday " + str(x)
81 if flags & 1 == 1: # set user defined flags
92 weekday = (int(time.strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
95 self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
96 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby"))], default = afterevent)
97 self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
98 self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False)
99 self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False)
101 self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("daily", _("daily")), ("weekly", _("weekly")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))])
103 self.timerentry_startdate = ConfigDateTime(default = self.timer.begin, formatstring = _("%d.%B %Y"), increment = 86400)
104 self.timerentry_starttime = ConfigClock(default = self.timer.begin)
106 self.timerentry_enddate = ConfigDateTime(default = self.timer.end, formatstring = _("%d.%B %Y"), increment = 86400)
107 self.timerentry_endtime = ConfigClock(default = self.timer.end)
109 self.timerentry_dirname = ConfigSelection(choices = [self.timer.dirname or "/hdd/movie/"])
111 self.timerentry_repeatedbegindate = ConfigDateTime(default = self.timer.repeatedbegindate, formatstring = _("%d.%B %Y"), increment = 86400)
113 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
115 self.timerentry_day = ConfigSubList()
117 self.timerentry_day.append(ConfigYesNo(default = day[x]))
119 # FIXME some service-chooser needed here
121 try: # no current service available?
122 servicename = str(self.timer.service_ref.getServiceName())
125 self.timerentry_service_ref = self.timer.service_ref
126 self.timerentry_service = ConfigSelection([servicename])
128 self.timerentry_startdate.addNotifier(self.checkDate)
129 self.timerentry_enddate.addNotifier(self.checkDate)
131 def checkDate(self, configElement):
132 if configElement is self.timerentry_startdate:
133 if self.timerentry_enddate.value < self.timerentry_startdate.value:
134 self.timerentry_enddate.value = self.timerentry_startdate.value
135 self["config"].invalidate(self.entryEndDate)
136 if configElement is self.timerentry_enddate:
137 if (self.timerentry_enddate.value < self.timerentry_startdate.value):
138 self.timerentry_startdate.value = self.timerentry_enddate.value
139 self["config"].invalidate(self.entryStartDate)
141 def createSetup(self, widget):
143 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
144 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
145 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
146 self.list.append(self.timerJustplayEntry)
147 self.timerTypeEntry = getConfigListEntry(_("Repeat Type"), self.timerentry_type)
148 self.list.append(self.timerTypeEntry)
150 if self.timerentry_type.value == "once":
151 self.frequencyEntry = None
153 self.frequencyEntry = getConfigListEntry(_("Repeats"), self.timerentry_repeated)
154 self.list.append(self.frequencyEntry)
155 self.repeatedbegindateEntry = getConfigListEntry(_("Starting on"), self.timerentry_repeatedbegindate)
156 self.list.append(self.repeatedbegindateEntry)
157 if self.timerentry_repeated.value == "daily":
159 if self.timerentry_repeated.value == "weekdays":
161 if self.timerentry_repeated.value == "weekly":
162 self.list.append(getConfigListEntry(_("Weekday"), self.timerentry_weekday))
164 if self.timerentry_repeated.value == "user":
165 self.list.append(getConfigListEntry(_("Monday"), self.timerentry_day[0]))
166 self.list.append(getConfigListEntry(_("Tuesday"), self.timerentry_day[1]))
167 self.list.append(getConfigListEntry(_("Wednesday"), self.timerentry_day[2]))
168 self.list.append(getConfigListEntry(_("Thursday"), self.timerentry_day[3]))
169 self.list.append(getConfigListEntry(_("Friday"), self.timerentry_day[4]))
170 self.list.append(getConfigListEntry(_("Saturday"), self.timerentry_day[5]))
171 self.list.append(getConfigListEntry(_("Sunday"), self.timerentry_day[6]))
173 #self.list.append(getConfigListEntry("StartDate", self.timerentry_startdate))
174 # self.list.append(getConfigListEntry("Weekday", self.timerentry_weekday))
176 self.entryStartDate = getConfigListEntry(_("Start"), self.timerentry_startdate)
177 if self.timerentry_type.value == "once":
178 self.list.append(self.entryStartDate)
179 self.list.append(getConfigListEntry(" ", self.timerentry_starttime))
181 self.list.append(getConfigListEntry(_("StartTime"), self.timerentry_starttime))
183 self.entryEndDate = getConfigListEntry(_("End"), self.timerentry_enddate)
184 if self.timerentry_type.value == "once":
185 if self.timerentry_justplay.value != "zap":
186 self.list.append(self.entryEndDate)
187 self.list.append(getConfigListEntry(" ", self.timerentry_endtime))
189 if self.timerentry_justplay.value != "zap":
190 self.list.append(getConfigListEntry(_("EndTime"), self.timerentry_endtime))
192 if self.timerentry_justplay.value != "zap":
193 if config.usage.setup_level.index >= 2: # expert+
194 self.list.append(getConfigListEntry(_("Location"), self.timerentry_dirname))
195 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
197 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
198 self.list.append(self.channelEntry)
200 self[widget].list = self.list
201 self[widget].l.setList(self.list)
204 print "newConfig", self["config"].getCurrent()
205 if self["config"].getCurrent() == self.timerTypeEntry:
206 self.createSetup("config")
207 if self["config"].getCurrent() == self.timerJustplayEntry:
208 self.createSetup("config")
209 if self["config"].getCurrent() == self.frequencyEntry:
210 self.createSetup("config")
213 if self["config"].getCurrent() is self.channelEntry:
216 ConfigListScreen.keyLeft(self)
220 if self["config"].getCurrent() is self.channelEntry:
223 ConfigListScreen.keyRight(self)
227 if self["config"].getCurrent() == self.channelEntry:
228 self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
232 def finishedChannelSelection(self, *args):
234 self.timerentry_service_ref = ServiceReference(args[0])
235 self.timerentry_service.setCurrentText(self.timerentry_service_ref.getServiceName())
236 self["config"].invalidate(self.channelEntry)
238 def getTimestamp(self, date, mytime):
239 d = time.localtime(date)
240 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
241 return int(time.mktime(dt.timetuple()))
243 def buildRepeatedBegin(self, rep_time, start_time):
244 d = time.localtime(rep_time)
245 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, start_time[0], start_time[1])
246 return int(time.mktime(dt.timetuple()))
248 def getBeginEnd(self):
249 enddate = self.timerentry_enddate.value
250 endtime = self.timerentry_endtime.value
252 startdate = self.timerentry_startdate.value
253 starttime = self.timerentry_starttime.value
255 begin = self.getTimestamp(startdate, starttime)
256 end = self.getTimestamp(enddate, endtime)
258 # because of the dateChecks, startdate can't be < enddate.
259 # however, the endtime can be less than the starttime.
260 # in this case, add 1 day.
266 self.timer.name = self.timerentry_name.value
267 self.timer.description = self.timerentry_description.value
268 self.timer.justplay = self.timerentry_justplay.value == "zap"
269 self.timer.resetRepeated()
270 self.timer.afterEvent = {"nothing": AFTEREVENT.NONE, "deepstandby": AFTEREVENT.DEEPSTANDBY, "standby": AFTEREVENT.STANDBY}[self.timerentry_afterevent.value]
271 self.timer.service_ref = self.timerentry_service_ref
273 # TODO: fix that thing with none (this might as well just be ignored)
274 if self.timerentry_dirname.value == "/hdd/movie/":
275 self.timer.dirname = None
277 self.timer.dirname = self.timerentry_dirname.value
279 if self.timerentry_type.value == "once":
280 self.timer.begin, self.timer.end = self.getBeginEnd()
281 if self.timerentry_type.value == "repeated":
282 if self.timerentry_repeated.value == "daily":
284 self.timer.setRepeated(x)
286 if self.timerentry_repeated.value == "weekly":
287 self.timer.setRepeated(self.timerentry_weekday.index)
289 if self.timerentry_repeated.value == "weekdays":
291 self.timer.setRepeated(x)
293 if self.timerentry_repeated.value == "user":
295 if self.timerentry_day[x].value:
296 self.timer.setRepeated(x)
298 self.timer.repeatedbegindate = self.buildRepeatedBegin(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
299 self.timer.begin = self.getTimestamp(time.time(), self.timerentry_starttime.value)
300 self.timer.end = self.getTimestamp(time.time(), self.timerentry_endtime.value)
302 # when a timer end is set before the start, add 1 day
303 if self.timer.end < self.timer.begin:
304 self.timer.end += 86400
306 if self.timer.eit is not None:
307 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
308 if event is not None:
309 n = event.getNumOfLinkageServices()
312 ref = self.session.nav.getCurrentlyPlayingServiceReference()
313 parent = self.timer.service_ref.ref
316 i = event.getLinkageService(parent, x)
317 if i.toString() == ref.toString():
319 tlist.append((i.getName(), i))
320 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice to record..."), list = tlist, selection = selection)
324 self.close((True, self.timer))
326 def subserviceSelected(self, service):
327 if not service is None:
328 self.timer.service_ref = ServiceReference(service[1])
330 self.close((True, self.timer))
333 self.session.nav.RecordTimer.saveTimer()
338 def selectPath(self):
339 if config.usage.setup_level.index < 2: #-expert
341 self.session.openWithCallback(
344 text = _("Choose target folder"),
346 currDir = None, # TODO: fix FileList to correctly determine mountpoint
350 def pathSelected(self, res):
352 self.timerentry_dirname.choices.append(res)
353 self.timerentry_dirname.description[res] = res
354 self.timerentry_dirname.value = res
356 class TimerLog(Screen):
357 def __init__(self, session, timer):
358 Screen.__init__(self, session)
360 self.log_entries = self.timer.log_entries[:]
364 self["loglist"] = MenuList(self.list)
365 self["logentry"] = Label()
367 self["key_red"] = Button(_("Delete entry"))
368 self["key_green"] = Button()
369 self["key_yellow"] = Button("")
370 self["key_blue"] = Button(_("Clear log"))
372 self.onShown.append(self.updateText)
374 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
377 "cancel": self.keyClose,
382 "red": self.deleteEntry,
383 "blue": self.clearLog
386 def deleteEntry(self):
387 cur = self["loglist"].getCurrent()
390 self.log_entries.remove(cur[1])
392 self["loglist"].l.setList(self.list)
395 def fillLogList(self):
397 for x in self.log_entries:
398 self.list.append((str(time.strftime("%Y-%m-%d %H-%M", time.localtime(x[0])) + " - " + x[2]), x))
401 self.log_entries = []
403 self["loglist"].l.setList(self.list)
407 if self.timer.log_entries != self.log_entries:
408 self.timer.log_entries = self.log_entries
409 self.close((True, self.timer))
414 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
418 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
422 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
426 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
429 def updateText(self):
430 if len(self.list) > 0:
431 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
433 self["logentry"].setText("")