1 # -*- coding: UTF-8 -*-
2 # for localized messages
6 from Screens.Screen import Screen
7 from Components.ConfigList import ConfigListScreen
8 from Screens.ChannelSelection import SimpleChannelSelection
9 from Screens.EpgSelection import EPGSelection
10 from Screens.MessageBox import MessageBox
11 from Screens.ChoiceBox import ChoiceBox
14 from Screens.Setup import SetupSummary
17 from Components.ActionMap import ActionMap
18 from Components.Button import Button
21 from Components.config import getConfigListEntry, ConfigEnableDisable, \
22 ConfigYesNo, ConfigText, ConfigClock, ConfigNumber, ConfigSelection, \
26 from RecordTimer import AFTEREVENT
28 # Needed to convert our timestamp back and forth
29 from time import localtime, mktime
31 # Show ServiceName instead of ServiceReference
32 from ServiceReference import ServiceReference
34 # addAutotimerFromService
35 from enigma import eServiceCenter, iServiceInformation
37 # Default Record Directory
38 from Tools import Directories
41 from Screens.MovieSelection import getPreferredTagEditor
46 ("2", _("Wednesday")),
51 ("weekend", _("Weekend")),
52 ("weekday", _("Weekday"))
55 class ExtendedConfigText(ConfigText):
56 def __init__(self, default = "", fixed_size = True, visible_width = False):
57 ConfigText.__init__(self, default = default, fixed_size = fixed_size, visible_width = visible_width)
59 # Workaround some characters currently not "typeable" using NumericalTextInput
60 mapping = self.mapping
62 if "&" not in mapping[0]:
64 if ";" not in mapping[0]:
66 if "%" not in mapping[0]:
69 class SimpleBouquetSelection(SimpleChannelSelection):
70 def __init__(self, session, title):
71 SimpleChannelSelection.__init__(self, session, title)
72 self.skinName = "SimpleChannelSelection"
74 def channelSelected(self): # just return selected service
75 ref = self.getCurrentSelection()
76 if (ref.flags & 7) == 7:
79 # We return the currently active path here
80 # Asking the user if this is what he wants might be better though
81 self.close(self.servicePath[-1])
83 class AutoTimerEPGSelection(EPGSelection):
84 def __init__(self, *args):
85 EPGSelection.__init__(self, *args)
86 self.skinName = "EPGSelection"
88 def infoKeyPressed(self):
92 cur = self["list"].getCurrent()
98 addAutotimerFromEvent(self.session, evt = evt, service = sref)
100 def onSelectionChanged(self):
103 class AutoTimerEditorBase:
104 """ Base Class for all Editors """
105 def __init__(self, timer, editingDefaults = False):
108 self.editingDefaults = editingDefaults
110 # See if we are filtering some strings
112 timer.getExcludedTitle(),
113 timer.getExcludedShort(),
114 timer.getExcludedDescription(),
115 timer.getExcludedDays()
118 timer.getIncludedTitle(),
119 timer.getIncludedShort(),
120 timer.getIncludedDescription(),
121 timer.getIncludedDays()
123 if len(self.excludes[0]) or len(self.excludes[1]) \
124 or len(self.excludes[2]) or len(self.excludes[3]) \
125 or len(self.includes[0]) or len(self.includes[1]) \
126 or len(self.includes[2]) or len(self.includes[3]):
127 self.filterSet = True
129 self.filterSet = False
131 # See if services are restricted
132 self.services = timer.services
133 self.bouquets = timer.bouquets
134 if len(self.services) or len(self.bouquets):
135 self.serviceRestriction = True
137 self.serviceRestriction = False
139 self.createSetup(timer)
141 def createSetup(self, timer):
143 self.name = ExtendedConfigText(default = timer.name, fixed_size = False)
146 self.match = ExtendedConfigText(default = timer.match, fixed_size = False)
149 default = timer.encoding
150 selection = ['UTF-8', 'ISO8859-15']
151 if default not in selection:
152 selection.append(default)
153 self.encoding = ConfigSelection(choices = selection, default = default)
156 self.searchType = ConfigSelection(choices = [("partial", _("partial match")), ("exact", _("exact match"))], default = timer.searchType)
157 self.searchCase = ConfigSelection(choices = [("sensitive", _("case-sensitive search")), ("insensitive", _("case-insensitive search"))], default = timer.searchCase)
160 self.justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[int(timer.justplay)])
163 now = [x for x in localtime()]
164 if timer.hasTimespan():
166 now[3] = timer.timespan[0][0]
167 now[4] = timer.timespan[0][1]
169 now[3] = timer.timespan[1][0]
170 now[4] = timer.timespan[1][1]
180 self.timespan = ConfigEnableDisable(default = default)
181 self.timespanbegin = ConfigClock(default = begin)
182 self.timespanend = ConfigClock(default = end)
184 # Services have their own Screen
187 if timer.hasOffset():
189 begin = timer.getOffsetBegin()
190 end = timer.getOffsetEnd()
195 self.offset = ConfigEnableDisable(default = default)
196 self.offsetbegin = ConfigNumber(default = begin)
197 self.offsetend = ConfigNumber(default = end)
200 if timer.hasAfterEvent():
203 AFTEREVENT.NONE: "nothing",
204 AFTEREVENT.DEEPSTANDBY: "deepstandby",
205 AFTEREVENT.STANDBY: "standby",
206 AFTEREVENT.AUTO: "auto"
207 }[timer.afterevent[0][0]]
209 afterevent = "default"
210 self.afterevent = ConfigSelection(choices = [("default", _("standard")), ("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
212 # AfterEvent (Timespan)
213 if timer.hasAfterEvent() and timer.afterevent[0][1][0] is not None:
215 now[3] = timer.afterevent[0][1][0][0]
216 now[4] = timer.afterevent[0][1][0][1]
218 now[3] = timer.afterevent[0][1][1][0]
219 now[4] = timer.afterevent[0][1][1][1]
229 self.afterevent_timespan = ConfigEnableDisable(default = default)
230 self.afterevent_timespanbegin = ConfigClock(default = begin)
231 self.afterevent_timespanend = ConfigClock(default = end)
234 self.enabled = ConfigYesNo(default = timer.enabled)
237 if timer.hasDuration():
239 duration = timer.getDuration()
243 self.duration = ConfigEnableDisable(default = default)
244 self.durationlength = ConfigNumber(default = duration)
247 if timer.hasCounter():
248 default = timer.matchCount
251 self.counter = ConfigNumber(default = default)
252 self.counterLeft = ConfigNumber(default = timer.matchLeft)
253 default = timer.getCounterFormatString()
254 selection = [("", _("Never")), ("%m", _("Monthly")), ("%U", _("Weekly (Sunday)")), ("%W", _("Weekly (Monday)"))]
255 if default not in ('', '%m', '%U', '%W'):
256 selection.append((default, _("Custom (%s)") % (default)))
257 self.counterFormatString = ConfigSelection(selection, default = default)
259 # Avoid Duplicate Description
260 self.avoidDuplicateDescription = ConfigSelection([
262 ("1", _("On same service")),
263 ("2", _("On any service")),
265 default = str(timer.getAvoidDuplicateDescription())
269 if timer.hasDestination():
274 self.useDestination = ConfigYesNo(default = default)
276 default = timer.destination or Directories.resolveFilename(Directories.SCOPE_HDD)
277 choices = config.movielist.videodirs.value
279 if default not in choices:
280 choices.append(default)
281 self.destination = ConfigSelection(default = default, choices = choices)
284 self.timerentry_tags = timer.tags
285 self.tags = ConfigSelection(choices = [len(self.timerentry_tags) == 0 and _("None") or ' '.join(self.timerentry_tags)])
287 def pathSelected(self, res):
289 if res not in self.destination.choices:
290 self.destination.choices.append(res)
291 self.destination.description[res] = res
292 self.destination.value = res
294 def chooseDestination(self):
295 from Screens.LocationBox import MovieLocationBox
297 self.session.openWithCallback(
300 _("Choose target folder"),
301 self.destination.value,
302 minFree = 100 # Same requirement as in Screens.TimerEntry
305 def tagEditFinished(self, ret):
307 self.timerentry_tags = ret
308 self.tags.setChoices([len(ret) == 0 and _("None") or ' '.join(ret)])
310 def chooseTags(self):
311 preferredTagEditor = getPreferredTagEditor()
312 if preferredTagEditor:
313 self.session.openWithCallback(
314 self.tagEditFinished,
319 class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
322 skin = """<screen name="AutoTimerEdit" title="Edit AutoTimer" position="75,155" size="565,280">
323 <widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
324 <ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
325 <ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
326 <ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
327 <ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
328 <widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
329 <widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
330 <widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
331 <widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
334 def __init__(self, session, timer, editingDefaults = False):
335 Screen.__init__(self, session)
337 AutoTimerEditorBase.__init__(self, timer, editingDefaults)
340 self.setup_title = _("AutoTimer Editor")
341 self.onChangedEntry = []
343 # We might need to change shown items, so add some notifiers
344 self.timespan.addNotifier(self.reloadList, initial_call = False)
345 self.offset.addNotifier(self.reloadList, initial_call = False)
346 self.duration.addNotifier(self.reloadList, initial_call = False)
347 self.afterevent.addNotifier(self.reloadList, initial_call = False)
348 self.afterevent_timespan.addNotifier(self.reloadList, initial_call = False)
349 self.counter.addNotifier(self.reloadList, initial_call = False)
350 self.useDestination.addNotifier(self.reloadList, initial_call = False)
354 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
357 self["key_red"] = Button(_("Cancel"))
358 self["key_green"] = Button(_("OK"))
359 self["key_yellow"] = Button()
360 self["key_blue"] = Button()
363 self.renameServiceButton()
364 self.renameFilterButton()
367 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
369 "cancel": self.cancel,
370 "save": self.maybeSave,
372 "yellow": self.editFilter,
373 "blue": self.editServices
380 self.onLayoutFinish.append(self.setCustomTitle)
382 def setCustomTitle(self):
383 self.setTitle(_("Edit AutoTimer"))
385 def renameFilterButton(self):
387 self["key_yellow"].setText(_("Edit Filters"))
389 self["key_yellow"].setText(_("Add Filters"))
391 def renameServiceButton(self):
392 if self.serviceRestriction:
393 self["key_blue"].setText(_("Edit Services"))
395 self["key_blue"].setText(_("Add Services"))
398 for x in self.onChangedEntry:
404 def getCurrentEntry(self):
405 return self["config"].getCurrent()[0]
407 def getCurrentValue(self):
408 return str(self["config"].getCurrent()[1].getText())
410 def createSummary(self):
414 # First three entries are only showed when not editing defaults
416 if not self.editingDefaults:
418 getConfigListEntry(_("Enabled"), self.enabled),
419 getConfigListEntry(_("Description"), self.name),
420 getConfigListEntry(_("Match Title"), self.match),
424 getConfigListEntry(_("EPG Encoding"), self.encoding),
425 getConfigListEntry(_("Search Type"), self.searchType),
426 getConfigListEntry(_("Search strictness"), self.searchCase),
427 getConfigListEntry(_("Timer Type"), self.justplay),
428 getConfigListEntry(_("Only match during Timespan"), self.timespan)
431 # Only allow editing timespan when it's enabled
432 if self.timespan.value:
434 getConfigListEntry(_("Begin of Timespan"), self.timespanbegin),
435 getConfigListEntry(_("End of Timespan"), self.timespanend)
438 self.list.append(getConfigListEntry(_("Custom offset"), self.offset))
440 # Only allow editing offsets when it's enabled
441 if self.offset.value:
443 getConfigListEntry(_("Offset before recording (in m)"), self.offsetbegin),
444 getConfigListEntry(_("Offset after recording (in m)"), self.offsetend)
447 self.list.append(getConfigListEntry(_("Set maximum Duration"), self.duration))
449 # Only allow editing maxduration when it's enabled
450 if self.duration.value:
451 self.list.append(getConfigListEntry(_("Maximum Duration (in m)"), self.durationlength))
453 self.list.append(getConfigListEntry(_("After event"), self.afterevent))
455 # Only allow setting afterevent timespan when afterevent is active
456 if self.afterevent.value != "default":
457 self.list.append(getConfigListEntry(_("Execute after Event during Timespan"), self.afterevent_timespan))
459 # Only allow editing timespan when it's enabled
460 if self.afterevent_timespan.value:
462 getConfigListEntry(_("Begin of after Event Timespan"), self.afterevent_timespanbegin),
463 getConfigListEntry(_("End of after Event Timespan"), self.afterevent_timespanend)
466 self.list.append(getConfigListEntry(_("Record a maximum of x times"), self.counter))
468 # Only allow setting matchLeft when counting hits
469 if self.counter.value:
470 if not self.editingDefaults:
471 self.list.append(getConfigListEntry(_("Ammount of recordings left"), self.counterLeft))
472 self.list.append(getConfigListEntry(_("Reset Count"), self.counterFormatString))
474 self.list.append(getConfigListEntry(_("Require Description to be unique"), self.avoidDuplicateDescription))
476 # We always add this option though its expert only in enigma2
477 self.list.append(getConfigListEntry(_("Use a custom location"), self.useDestination))
478 if self.useDestination.value:
479 self.list.append(getConfigListEntry(_("Custom Location"), self.destination))
481 self.list.append(getConfigListEntry(_("Tags"), self.tags))
483 def reloadList(self, value):
485 self["config"].setList(self.list)
487 def editFilter(self):
488 self.session.openWithCallback(
489 self.editFilterCallback,
490 AutoTimerFilterEditor,
496 def editFilterCallback(self, ret):
498 self.filterSet = ret[0]
499 self.excludes = ret[1]
500 self.includes = ret[2]
501 self.renameFilterButton()
503 def editServices(self):
504 self.session.openWithCallback(
505 self.editServicesCallback,
506 AutoTimerServiceEditor,
507 self.serviceRestriction,
512 def editServicesCallback(self, ret):
514 self.serviceRestriction = ret[0]
515 self.services = ret[1][0]
516 self.bouquets = ret[1][1]
517 self.renameServiceButton()
520 cur = self["config"].getCurrent()
522 if cur == self.destination:
523 self.chooseDestination()
524 elif cur == self.tags:
527 ConfigListScreen.keyOK(self)
530 if self["config"].isChanged():
531 self.session.openWithCallback(
534 _("Really close without saving settings?")
539 def cancelConfirm(self, ret):
544 if self.editingDefaults:
547 # Check if any match is set
548 if not self.match.value.strip():
551 _("The match attribute is mandatory."),
552 type = MessageBox.TYPE_ERROR,
555 # Check if we have a trailing whitespace
556 elif self.match.value[-1:] == " ":
557 self.session.openWithCallback(
560 _('You entered "%s" as Text to match.\nDo you want to remove trailing whitespaces?') % (self.match.value)
566 def saveCallback(self, ret):
569 self.match.value = self.match.value.rstrip()
571 # Don't to anything if MessageBox was canceled!
575 self.timer.match = self.match.value
578 self.timer.name = self.name.value.strip() or self.timer.match
581 self.timer.encoding = self.encoding.value
584 self.timer.searchType = self.searchType.value
585 self.timer.searchCase = self.searchCase.value
588 self.timer.enabled = self.enabled.value
591 self.timer.justplay = self.justplay.value == "zap"
594 if self.timespan.value:
595 start = self.timespanbegin.value
596 end = self.timespanend.value
597 self.timer.timespan = (start, end)
599 self.timer.timespan = None
602 if self.serviceRestriction:
603 self.timer.services = self.services
604 self.timer.bouquets = self.bouquets
606 self.timer.services = None
607 self.timer.bouquets = None
610 if self.offset.value:
611 self.timer.offset = (self.offsetbegin.value*60, self.offsetend.value*60)
613 self.timer.offset = None
616 if self.afterevent.value == "default":
617 self.timer.afterevent = []
620 "nothing": AFTEREVENT.NONE,
621 "deepstandby": AFTEREVENT.DEEPSTANDBY,
622 "standby": AFTEREVENT.STANDBY,
623 "auto": AFTEREVENT.AUTO
624 }[self.afterevent.value]
625 # AfterEvent Timespan
626 if self.afterevent_timespan.value:
627 start = self.afterevent_timespanbegin.value
628 end = self.afterevent_timespanend.value
629 self.timer.afterevent = [(afterevent, (start, end))]
631 self.timer.afterevent = [(afterevent, None)]
634 if self.duration.value:
635 self.timer.maxduration = self.durationlength.value*60
637 self.timer.maxduration = None
641 self.timer.exclude = self.excludes
642 self.timer.include = self.includes
644 self.timer.exclude = None
645 self.timer.include = None
648 if self.counter.value:
649 self.timer.matchCount = self.counter.value
650 if self.counterLeft.value <= self.counter.value:
651 self.timer.matchLeft = self.counterLeft.value
653 self.timer.matchLeft = self.counter.value
654 if self.counterFormatString.value:
655 self.timer.matchFormatString = self.counterFormatString.value
657 self.timer.matchFormatString = ''
659 self.timer.matchCount = 0
660 self.timer.matchLeft = 0
661 self.timer.matchFormatString = ''
663 self.timer.avoidDuplicateDescription = int(self.avoidDuplicateDescription.value)
665 if self.useDestination.value:
666 self.timer.destination = self.destination.value
668 self.timer.destination = None
670 self.timer.tags = self.timerentry_tags
673 self.close(self.timer)
675 class AutoTimerFilterEditor(Screen, ConfigListScreen):
676 """Edit AutoTimer Filter"""
678 skin = """<screen name="AutoFilterEditor" title="Edit AutoTimer Filters" position="75,150" size="565,245">
679 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
680 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
681 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
682 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
683 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
684 <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
685 <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
686 <widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
687 <widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
690 def __init__(self, session, filterset, excludes, includes):
691 Screen.__init__(self, session)
694 self.setup_title = _("AutoTimer Filters")
695 self.onChangedEntry = []
697 self.typeSelection = ConfigSelection(choices = [("title", _("in Title")), ("short", _("in Shortdescription")), ("desc", _("in Description")), ("day", _("on Weekday"))])
698 self.typeSelection.addNotifier(self.refresh, initial_call = False)
700 self.enabled = ConfigEnableDisable(default = filterset)
702 self.excludes = excludes
703 self.includes = includes
707 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
710 self["key_red"] = Button(_("Cancel"))
711 self["key_green"] = Button(_("Save"))
712 self["key_yellow"] = Button(_("delete"))
713 self["key_blue"] = Button(_("New"))
716 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
718 "cancel": self.cancel,
720 "yellow": self.remove,
728 self.onLayoutFinish.append(self.setCustomTitle)
730 def setCustomTitle(self):
731 self.setTitle(_("Edit AutoTimer Filters"))
735 for x in self.onChangedEntry:
741 def getCurrentEntry(self):
742 return self["config"].getCurrent()[0]
744 def getCurrentValue(self):
745 return str(self["config"].getCurrent()[1].getText())
747 def createSummary(self):
750 def saveCurrent(self):
751 del self.excludes[self.idx][:]
752 del self.includes[self.idx][:]
754 # Warning, accessing a ConfigListEntry directly might be considered evil!
757 for item in self["config"].getList()[:]:
759 # Skip empty entries (and those which are no filters)
760 if item[1].value == "" or idx < 2:
762 elif idx < self.lenExcludes:
763 self.excludes[self.idx].append(item[1].value.encode("UTF-8"))
765 self.includes[self.idx].append(item[1].value.encode("UTF-8"))
767 def refresh(self, *args, **kwargs):
771 self["config"].setList(self.list)
773 def reloadList(self):
775 getConfigListEntry(_("Enable Filtering"), self.enabled),
776 getConfigListEntry(_("Filter"), self.typeSelection)
779 if self.typeSelection.value == "day":
782 # Weekdays are presented as ConfigSelection
784 getConfigListEntry(_("Exclude"), ConfigSelection(choices = weekdays, default = x))
785 for x in self.excludes[3]
787 self.lenExcludes = len(self.list)
789 getConfigListEntry(_("Include"), ConfigSelection(choices = weekdays, default = x))
790 for x in self.includes[3]
793 elif self.typeSelection.value == "title":
795 elif self.typeSelection.value == "short":
797 else: # self.typeSelection.value == "desc":
801 getConfigListEntry(_("Exclude"), ExtendedConfigText(default = x, fixed_size = False))
802 for x in self.excludes[self.idx]
804 self.lenExcludes = len(self.list)
806 getConfigListEntry(_("Include"), ExtendedConfigText(default = x, fixed_size = False))
807 for x in self.includes[self.idx]
811 idx = self["config"].getCurrentIndex()
813 if idx < self.lenExcludes:
814 self.lenExcludes -= 1
816 list = self["config"].getList()
817 list.remove(self["config"].getCurrent())
818 self["config"].setList(list)
821 self.session.openWithCallback(
824 _("Select type of Filter"),
831 def typeSelected(self, ret):
833 list = self["config"].getList()
836 pos = self.lenExcludes
837 self.lenExcludes += 1
843 if self.typeSelection.value == "day":
844 entry = getConfigListEntry(text, ConfigSelection(choices = weekdays))
846 entry = getConfigListEntry(text, ExtendedConfigText(fixed_size = False))
848 list.insert(pos, entry)
849 self["config"].setList(list)
852 if self["config"].isChanged():
853 self.session.openWithCallback(
856 _("Really close without saving settings?")
861 def cancelConfirm(self, ret):
874 class AutoTimerServiceEditor(Screen, ConfigListScreen):
875 """Edit allowed Services of a AutoTimer"""
877 skin = """<screen name="AutoTimerServiceEditor" title="Edit AutoTimer Services" position="75,150" size="565,245">
878 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
879 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
880 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
881 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
882 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
883 <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
884 <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
885 <widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
886 <widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
889 def __init__(self, session, servicerestriction, servicelist, bouquetlist):
890 Screen.__init__(self, session)
893 self.setup_title = _("AutoTimer Services")
894 self.onChangedEntry = []
901 self.enabled = ConfigEnableDisable(default = servicerestriction)
902 self.typeSelection = ConfigSelection(choices = [("channels", _("Channels")), ("bouquets", _("Bouquets"))])
903 self.typeSelection.addNotifier(self.refresh, initial_call = False)
907 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
910 self["key_red"] = Button(_("Cancel"))
911 self["key_green"] = Button(_("OK"))
912 self["key_yellow"] = Button(_("delete"))
913 self["key_blue"] = Button(_("New"))
916 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
918 "cancel": self.cancel,
920 "yellow": self.remove,
928 self.onLayoutFinish.append(self.setCustomTitle)
930 def setCustomTitle(self):
931 self.setTitle(_("Edit AutoTimer Services"))
933 def saveCurrent(self):
934 del self.services[self.idx][:]
936 # Warning, accessing a ConfigListEntry directly might be considered evil!
938 myl = self["config"].getList()[:]
942 self.services[self.idx].append(item[1].value)
944 def refresh(self, *args, **kwargs):
948 self["config"].setList(self.list)
950 def reloadList(self):
952 getConfigListEntry(_("Enable Service Restriction"), self.enabled),
953 getConfigListEntry(_("Editing"), self.typeSelection)
956 if self.typeSelection.value == "channels":
958 else: # self.typeSelection.value == "bouquets":
962 getConfigListEntry(_("Record on"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
963 for x in self.services[self.idx]
967 for x in self.onChangedEntry:
973 def getCurrentEntry(self):
974 return self["config"].getCurrent()[0]
976 def getCurrentValue(self):
977 return str(self["config"].getCurrent()[1].getText())
979 def createSummary(self):
983 if self["config"].getCurrentIndex() != 0:
984 list = self["config"].getList()
985 list.remove(self["config"].getCurrent())
986 self["config"].setList(list)
989 if self.typeSelection.value == "channels":
990 self.session.openWithCallback(
991 self.finishedServiceSelection,
992 SimpleChannelSelection,
993 _("Select channel to record on")
995 else: # self.typeSelection.value == "bouquets":
996 self.session.openWithCallback(
997 self.finishedServiceSelection,
998 SimpleBouquetSelection,
999 _("Select bouquet to record on")
1002 def finishedServiceSelection(self, *args):
1004 list = self["config"].getList()
1005 sname = args[0].toString()
1007 if self.typeSelection.value == "channels":
1008 # strip all after last : when adding a channel
1009 pos = sname.rfind(':')
1011 sname = sname[:pos+1]
1013 list.append(getConfigListEntry(_("Record on"), ConfigSelection(choices = [(sname, ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])))
1014 self["config"].setList(list)
1017 if self["config"].isChanged():
1018 self.session.openWithCallback(
1021 _("Really close without saving settings?")
1026 def cancelConfirm(self, ret):
1038 def addAutotimerFromEvent(session, evt = None, service = None):
1039 from AutoTimerComponent import AutoTimerComponent
1040 from AutoTimerImporter import AutoTimerImporter
1041 from plugin import autotimer
1043 # Create instance if needed
1044 if autotimer is None:
1045 from AutoTimer import AutoTimer
1046 autotimer = AutoTimer()
1049 match = evt and evt.getEventName() or ""
1050 name = match or "New AutoTimer"
1052 if service is not None:
1053 service = str(service)
1054 # strip all after last :
1055 pos = service.rfind(':')
1057 service = service[:pos+1]
1059 sref = ServiceReference(service)
1061 # timespan defaults to +- 1h
1062 begin = evt.getBeginTime()-3600
1063 end = begin + evt.getDuration()+7200
1067 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-)
1069 session.openWithCallback(
1073 autotimer.getUniqueId(), # Id
1078 match, # Proposed Match
1079 begin, # Proposed Begin
1081 None, # Proposed Disabled
1082 sref, # Proposed ServiceReference
1083 None, # Proposed afterEvent
1084 None, # Proposed justplay
1085 None, # Proposed dirname, can we get anything useful here?
1089 def addAutotimerFromService(session, service = None):
1090 from AutoTimerComponent import AutoTimerComponent
1091 from AutoTimerImporter import AutoTimerImporter
1092 from plugin import autotimer
1094 # Create instance if needed
1095 if autotimer is None:
1096 from AutoTimer import AutoTimer
1097 autotimer = AutoTimer()
1100 serviceHandler = eServiceCenter.getInstance()
1101 info = serviceHandler.info(service)
1103 match = info and info.getName(service) or ""
1104 name = match or "New AutoTimer"
1105 sref = info and info.getInfoString(service, iServiceInformation.sServiceref)
1107 # strip all after last :
1108 pos = sref.rfind(':')
1112 sref = ServiceReference(sref)
1114 begin = info.getInfo(service, iServiceInformation.sTimeCreate)
1115 end = begin + info.getLength(service)
1119 from os.path import dirname
1120 path = dirname(service.getPath())
1124 tags = info.getInfoString(service, iServiceInformation.sTags)
1125 tags = tags and tags.split(' ') or []
1127 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-)
1129 session.openWithCallback(
1133 autotimer.getUniqueId(), # Id
1138 match, # Proposed Match
1139 begin, # Proposed Begin
1141 None, # Proposed Disabled
1142 sref, # Proposed ServiceReference
1143 None, # Proposed afterEvent
1144 None, # Proposed justplay
1145 path, # Proposed dirname
1146 tags # Proposed tags
1149 def importerCallback(ret):
1153 session.openWithCallback(
1159 # Remove instance if not running in background
1160 if not config.plugins.autotimer.autopoll.value:
1161 from plugin import autotimer
1164 def editorCallback(ret):
1166 from plugin import autotimer
1168 # Create instance if needed (should have been created by addAutotimerFrom* above though)
1169 if autotimer is None:
1170 from AutoTimer import AutoTimer
1171 autotimer = AutoTimer()
1177 autotimer.writeXml()
1179 # Remove instance if not running in background
1180 if not config.plugins.autotimer.autopoll.value: