1 from Screen import Screen
2 import ChannelSelection
3 from ServiceReference import ServiceReference
4 from Components.config import config, ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
5 from Components.ActionMap import NumberActionMap
6 from Components.ConfigList import ConfigListScreen
7 from Components.MenuList import MenuList
8 from Components.Button import Button
9 from Components.Label import Label
10 from Components.Pixmap import Pixmap
11 from Components.SystemInfo import SystemInfo
12 from Components.UsageConfig import defaultMoviePath
13 from Screens.MovieSelection import getPreferredTagEditor
14 from Screens.LocationBox import MovieLocationBox
15 from Screens.ChoiceBox import ChoiceBox
16 from Screens.MessageBox import MessageBox
17 from RecordTimer import AFTEREVENT
18 from enigma import eEPGCache, eServiceReference
19 from time import localtime, mktime, time, strftime
20 from datetime import datetime
22 class TimerEntry(Screen, ConfigListScreen):
23 def __init__(self, session, timer):
24 Screen.__init__(self, session)
28 self.entryService = None
30 self["oktext"] = Label(_("OK"))
31 self["canceltext"] = Label(_("Cancel"))
33 self["cancel"] = Pixmap()
37 self["actions"] = NumberActionMap(["SetupActions", "GlobalActions", "PiPSetupActions"],
41 "cancel": self.keyCancel,
42 "volumeUp": self.incrementStart,
43 "volumeDown": self.decrementStart,
44 "size+": self.incrementEnd,
45 "size-": self.decrementEnd
49 ConfigListScreen.__init__(self, self.list, session = session)
50 self.createSetup("config")
52 def createConfig(self):
53 justplay = self.timer.justplay
56 AFTEREVENT.NONE: "nothing",
57 AFTEREVENT.DEEPSTANDBY: "deepstandby",
58 AFTEREVENT.STANDBY: "standby",
59 AFTEREVENT.AUTO: "auto"
60 }[self.timer.afterEvent]
62 weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
64 # calculate default values
67 for x in (0, 1, 2, 3, 4, 5, 6):
69 if self.timer.repeated: # repeated
71 if (self.timer.repeated == 31): # Mon-Fri
73 elif (self.timer.repeated == 127): # daily
76 flags = self.timer.repeated
79 for x in (0, 1, 2, 3, 4, 5, 6):
80 if flags == 1: # weekly
81 print "Set to weekday " + str(x)
83 if flags & 1 == 1: # set user defined flags
94 weekday = (int(strftime("%w", localtime(self.timer.begin))) - 1) % 7
97 timer_choices = [("zap", _("zap"))]
99 if SystemInfo["PVRSupport"]:
100 timer_choices.append(("record", _("record")))
101 default = {0: "record", 1: "zap"}[justplay]
102 self.timerentry_justplay = ConfigSelection(choices = timer_choices, default = default)
103 if SystemInfo["DeepstandbySupport"]:
104 shutdownString = _("go to deep standby")
106 shutdownString = _("shut down")
107 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", shutdownString), ("auto", _("auto"))], default = afterevent)
108 self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
109 self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False)
110 self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False)
111 self.timerentry_tags = self.timer.tags[:]
112 self.timerentry_tagsset = ConfigSelection(choices = [not self.timerentry_tags and "None" or " ".join(self.timerentry_tags)])
114 self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("daily", _("daily")), ("weekly", _("weekly")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))])
116 self.timerentry_date = ConfigDateTime(default = self.timer.begin, formatstring = _("%d.%B %Y"), increment = 86400)
117 self.timerentry_starttime = ConfigClock(default = self.timer.begin)
118 self.timerentry_endtime = ConfigClock(default = self.timer.end)
119 self.timerentry_showendtime = ConfigSelection(default = ((self.timer.end - self.timer.begin) > 4), choices = [(True, _("yes")), (False, _("no"))])
121 default = self.timer.dirname or defaultMoviePath()
122 tmp = config.movielist.videodirs.value
123 if default not in tmp:
125 self.timerentry_dirname = ConfigSelection(default = default, choices = tmp)
127 self.timerentry_repeatedbegindate = ConfigDateTime(default = self.timer.repeatedbegindate, formatstring = _("%d.%B %Y"), increment = 86400)
129 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
131 self.timerentry_day = ConfigSubList()
132 for x in (0, 1, 2, 3, 4, 5, 6):
133 self.timerentry_day.append(ConfigYesNo(default = day[x]))
135 # FIXME some service-chooser needed here
137 try: # no current service available?
138 servicename = str(self.timer.service_ref.getServiceName())
141 self.timerentry_service_ref = self.timer.service_ref
142 self.timerentry_service = ConfigSelection([servicename])
144 def createSetup(self, widget):
146 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
147 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
148 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
149 self.list.append(self.timerJustplayEntry)
150 self.timerTypeEntry = getConfigListEntry(_("Repeat Type"), self.timerentry_type)
151 self.list.append(self.timerTypeEntry)
153 if self.timerentry_type.value == "once":
154 self.frequencyEntry = None
156 self.frequencyEntry = getConfigListEntry(_("Repeats"), self.timerentry_repeated)
157 self.list.append(self.frequencyEntry)
158 self.repeatedbegindateEntry = getConfigListEntry(_("Starting on"), self.timerentry_repeatedbegindate)
159 self.list.append(self.repeatedbegindateEntry)
160 if self.timerentry_repeated.value == "daily":
162 if self.timerentry_repeated.value == "weekdays":
164 if self.timerentry_repeated.value == "weekly":
165 self.list.append(getConfigListEntry(_("Weekday"), self.timerentry_weekday))
167 if self.timerentry_repeated.value == "user":
168 self.list.append(getConfigListEntry(_("Monday"), self.timerentry_day[0]))
169 self.list.append(getConfigListEntry(_("Tuesday"), self.timerentry_day[1]))
170 self.list.append(getConfigListEntry(_("Wednesday"), self.timerentry_day[2]))
171 self.list.append(getConfigListEntry(_("Thursday"), self.timerentry_day[3]))
172 self.list.append(getConfigListEntry(_("Friday"), self.timerentry_day[4]))
173 self.list.append(getConfigListEntry(_("Saturday"), self.timerentry_day[5]))
174 self.list.append(getConfigListEntry(_("Sunday"), self.timerentry_day[6]))
176 self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
177 if self.timerentry_type.value == "once":
178 self.list.append(self.entryDate)
180 self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
181 self.list.append(self.entryStartTime)
183 self.entryShowEndTime = getConfigListEntry(_("Set End Time"), self.timerentry_showendtime)
184 if self.timerentry_justplay.value == "zap":
185 self.list.append(self.entryShowEndTime)
186 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
187 if self.timerentry_justplay.value != "zap" or self.timerentry_showendtime.value:
188 self.list.append(self.entryEndTime)
190 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
191 self.list.append(self.channelEntry)
193 self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
194 self.tagsSet = getConfigListEntry(_("Tags"), self.timerentry_tagsset)
195 if self.timerentry_justplay.value != "zap":
196 if config.usage.setup_level.index >= 2: # expert+
197 self.list.append(self.dirname)
198 if getPreferredTagEditor():
199 self.list.append(self.tagsSet)
200 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
202 self[widget].list = self.list
203 self[widget].l.setList(self.list)
206 print "newConfig", self["config"].getCurrent()
207 if self["config"].getCurrent() in (self.timerTypeEntry, self.timerJustplayEntry, self.frequencyEntry, self.entryShowEndTime):
208 self.createSetup("config")
211 if self["config"].getCurrent() in (self.channelEntry, self.tagsSet):
214 ConfigListScreen.keyLeft(self)
218 if self["config"].getCurrent() in (self.channelEntry, self.tagsSet):
221 ConfigListScreen.keyRight(self)
225 cur = self["config"].getCurrent()
226 if cur == self.channelEntry:
227 self.session.openWithCallback(
228 self.finishedChannelSelection,
229 ChannelSelection.SimpleChannelSelection,
230 _("Select channel to record from")
232 elif config.usage.setup_level.index >= 2 and cur == self.dirname:
233 self.session.openWithCallback(
236 _("Choose target folder"),
237 self.timerentry_dirname.value,
238 minFree = 100 # We require at least 100MB free space
240 elif getPreferredTagEditor() and cur == self.tagsSet:
241 self.session.openWithCallback(
242 self.tagEditFinished,
243 getPreferredTagEditor(),
249 def finishedChannelSelection(self, *args):
251 self.timerentry_service_ref = ServiceReference(args[0])
252 self.timerentry_service.setCurrentText(self.timerentry_service_ref.getServiceName())
253 self["config"].invalidate(self.channelEntry)
255 def getTimestamp(self, date, mytime):
257 dt = datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
258 return int(mktime(dt.timetuple()))
260 def getBeginEnd(self):
261 date = self.timerentry_date.value
262 endtime = self.timerentry_endtime.value
263 starttime = self.timerentry_starttime.value
265 begin = self.getTimestamp(date, starttime)
266 end = self.getTimestamp(date, endtime)
268 # if the endtime is less than the starttime, add 1 day.
273 def selectChannelSelector(self, *args):
274 self.session.openWithCallback(
275 self.finishedChannelSelectionCorrection,
276 ChannelSelection.SimpleChannelSelection,
277 _("Select channel to record from")
280 def finishedChannelSelectionCorrection(self, *args):
282 self.finishedChannelSelection(*args)
285 def keyGo(self, result = None):
286 if not self.timerentry_service_ref.isRecordable():
287 self.session.openWithCallback(self.selectChannelSelector, MessageBox, _("You didn't select a channel to record from."), MessageBox.TYPE_ERROR)
289 self.timer.name = self.timerentry_name.value
290 self.timer.description = self.timerentry_description.value
291 self.timer.justplay = self.timerentry_justplay.value == "zap"
292 if self.timerentry_justplay.value == "zap":
293 if not self.timerentry_showendtime.value:
294 self.timerentry_endtime.value = self.timerentry_starttime.value
295 self.timer.resetRepeated()
296 self.timer.afterEvent = {
297 "nothing": AFTEREVENT.NONE,
298 "deepstandby": AFTEREVENT.DEEPSTANDBY,
299 "standby": AFTEREVENT.STANDBY,
300 "auto": AFTEREVENT.AUTO
301 }[self.timerentry_afterevent.value]
302 self.timer.service_ref = self.timerentry_service_ref
303 self.timer.tags = self.timerentry_tags
305 if self.timer.dirname or self.timerentry_dirname.value != defaultMoviePath():
306 self.timer.dirname = self.timerentry_dirname.value
307 config.movielist.last_timer_videodir.value = self.timer.dirname
308 config.movielist.last_timer_videodir.save()
310 if self.timerentry_type.value == "once":
311 self.timer.begin, self.timer.end = self.getBeginEnd()
312 if self.timerentry_type.value == "repeated":
313 if self.timerentry_repeated.value == "daily":
314 for x in (0, 1, 2, 3, 4, 5, 6):
315 self.timer.setRepeated(x)
317 if self.timerentry_repeated.value == "weekly":
318 self.timer.setRepeated(self.timerentry_weekday.index)
320 if self.timerentry_repeated.value == "weekdays":
321 for x in (0, 1, 2, 3, 4):
322 self.timer.setRepeated(x)
324 if self.timerentry_repeated.value == "user":
325 for x in (0, 1, 2, 3, 4, 5, 6):
326 if self.timerentry_day[x].value:
327 self.timer.setRepeated(x)
329 self.timer.repeatedbegindate = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
330 if self.timer.repeated:
331 self.timer.begin = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
332 self.timer.end = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_endtime.value)
334 self.timer.begin = self.getTimestamp(time.time(), self.timerentry_starttime.value)
335 self.timer.end = self.getTimestamp(time.time(), self.timerentry_endtime.value)
337 # when a timer end is set before the start, add 1 day
338 if self.timer.end < self.timer.begin:
339 self.timer.end += 86400
341 if self.timer.eit is not None:
342 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
344 n = event.getNumOfLinkageServices()
347 ref = self.session.nav.getCurrentlyPlayingServiceReference()
348 parent = self.timer.service_ref.ref
351 i = event.getLinkageService(parent, x)
352 if i.toString() == ref.toString():
354 tlist.append((i.getName(), i))
355 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice to record..."), list = tlist, selection = selection)
358 parent = self.timer.service_ref.ref
359 self.timer.service_ref = ServiceReference(event.getLinkageService(parent, 0))
361 self.close((True, self.timer))
363 def incrementStart(self):
364 self.timerentry_starttime.increment()
365 self["config"].invalidate(self.entryStartTime)
367 def decrementStart(self):
368 self.timerentry_starttime.decrement()
369 self["config"].invalidate(self.entryStartTime)
371 def incrementEnd(self):
372 if self.entryEndTime is not None:
373 self.timerentry_endtime.increment()
374 self["config"].invalidate(self.entryEndTime)
376 def decrementEnd(self):
377 if self.entryEndTime is not None:
378 self.timerentry_endtime.decrement()
379 self["config"].invalidate(self.entryEndTime)
381 def subserviceSelected(self, service):
382 if not service is None:
383 self.timer.service_ref = ServiceReference(service[1])
385 self.close((True, self.timer))
388 self.session.nav.RecordTimer.saveTimer()
393 def pathSelected(self, res):
395 if config.movielist.videodirs.value != self.timerentry_dirname.choices:
396 self.timerentry_dirname.setChoices(config.movielist.videodirs.value, default=res)
397 self.timerentry_dirname.value = res
399 def tagEditFinished(self, ret):
401 self.timerentry_tags = ret
402 self.timerentry_tagsset.setChoices([not ret and "None" or " ".join(ret)])
403 self["config"].invalidate(self.tagsSet)
405 class TimerLog(Screen):
406 def __init__(self, session, timer):
407 Screen.__init__(self, session)
409 self.log_entries = self.timer.log_entries[:]
413 self["loglist"] = MenuList(self.list)
414 self["logentry"] = Label()
416 self["key_red"] = Button(_("Delete entry"))
417 self["key_green"] = Button()
418 self["key_yellow"] = Button("")
419 self["key_blue"] = Button(_("Clear log"))
421 self.onShown.append(self.updateText)
423 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
426 "cancel": self.keyClose,
431 "red": self.deleteEntry,
432 "blue": self.clearLog
435 def deleteEntry(self):
436 cur = self["loglist"].getCurrent()
439 self.log_entries.remove(cur[1])
441 self["loglist"].l.setList(self.list)
444 def fillLogList(self):
445 self.list = [(str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x) for x in self.log_entries]
448 self.log_entries = []
450 self["loglist"].l.setList(self.list)
454 if self.timer.log_entries != self.log_entries:
455 self.timer.log_entries = self.log_entries
456 self.close((True, self.timer))
461 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
465 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
469 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
473 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
476 def updateText(self):
478 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
480 self["logentry"].setText("")