Support duo4k.
[vuplus_dvbapp] / lib / python / Components / UsageConfig.py
1 from Components.Harddisk import harddiskmanager
2 from Components.NimManager import nimmanager
3 from config import ConfigSubsection, ConfigYesNo, config, ConfigSelection, ConfigText, ConfigNumber, ConfigSet, ConfigLocations, ConfigSelectionNumber
4 from Tools.Directories import defaultRecordingLocation
5 from Tools.Directories import resolveFilename, SCOPE_HDD
6 from enigma import Misc_Options, eEnv, setTunerTypePriorityOrder, setPreferredTuner, eServiceEvent
7 from SystemInfo import SystemInfo
8 import os
9
10 def InitUsageConfig():
11         config.usage = ConfigSubsection();
12         config.usage.showdish = ConfigYesNo(default = True)
13         config.usage.multibouquet = ConfigYesNo(default = False)
14         config.usage.multiepg_ask_bouquet = ConfigYesNo(default = False)
15
16         config.usage.quickzap_bouquet_change = ConfigYesNo(default = False)
17         config.usage.e1like_radio_mode = ConfigYesNo(default = False)
18         config.usage.infobar_timeout = ConfigSelection(default = "5", choices = [
19                 ("0", _("no timeout")), ("1", "1 " + _("second")), ("2", "2 " + _("seconds")), ("3", "3 " + _("seconds")),
20                 ("4", "4 " + _("seconds")), ("5", "5 " + _("seconds")), ("6", "6 " + _("seconds")), ("7", "7 " + _("seconds")),
21                 ("8", "8 " + _("seconds")), ("9", "9 " + _("seconds")), ("10", "10 " + _("seconds"))])
22         config.usage.show_infobar_on_zap = ConfigYesNo(default = True)
23         config.usage.show_infobar_on_skip = ConfigYesNo(default = True)
24         config.usage.show_infobar_on_event_change = ConfigYesNo(default = True)
25         config.usage.hdd_standby = ConfigSelection(default = "600", choices = [
26                 ("0", _("no standby")), ("10", "10 " + _("seconds")), ("30", "30 " + _("seconds")),
27                 ("60", "1 " + _("minute")), ("120", "2 " + _("minutes")),
28                 ("300", "5 " + _("minutes")), ("600", "10 " + _("minutes")), ("1200", "20 " + _("minutes")),
29                 ("1800", "30 " + _("minutes")), ("3600", "1 " + _("hour")), ("7200", "2 " + _("hours")),
30                 ("14400", "4 " + _("hours")) ])
31         config.usage.output_12V = ConfigSelection(default = "do not change", choices = [
32                 ("do not change", _("do not change")), ("off", _("off")), ("on", _("on")) ])
33
34         config.usage.pip_zero_button = ConfigSelection(default = "standard", choices = [
35                 ("standard", _("standard")), ("swap", _("swap PiP and main picture")),
36                 ("swapstop", _("move PiP to main picture")), ("stop", _("stop PiP")) ])
37
38         config.usage.default_path = ConfigText(default = "")
39         config.usage.timer_path = ConfigText(default = "<default>")
40         config.usage.instantrec_path = ConfigText(default = "<default>")
41         config.usage.timeshift_path = ConfigText(default = "/media/hdd/")
42         config.usage.allowed_timeshift_paths = ConfigLocations(default = ["/media/hdd/"])
43
44         config.usage.on_movie_start = ConfigSelection(default = "ask", choices = [
45                 ("ask", _("Ask user")), ("resume", _("Resume from last position")), ("beginning", _("Start from the beginning")) ])
46         config.usage.on_movie_stop = ConfigSelection(default = "ask", choices = [
47                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")) ])
48         config.usage.on_movie_eof = ConfigSelection(default = "ask", choices = [
49                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")), ("pause", _("Pause movie at end")) ])
50
51         config.usage.setup_level = ConfigSelection(default = "intermediate", choices = [
52                 ("simple", _("Simple")),
53                 ("intermediate", _("Intermediate")),
54                 ("expert", _("Expert")) ])
55
56         config.usage.on_long_powerpress = ConfigSelection(default = "show_menu", choices = [
57                 ("show_menu", _("show shutdown menu")),
58                 ("shutdown", _("immediate shutdown")),
59                 ("standby", _("Standby")) ] )
60         
61         config.usage.on_short_powerpress = ConfigSelection(default = "standby", choices = [
62                 ("show_menu", _("show shutdown menu")),
63                 ("shutdown", _("immediate shutdown")),
64                 ("standby", _("Standby")) ] )
65
66
67         config.usage.alternatives_priority = ConfigSelection(default = "0", choices = [
68                 ("0", "DVB-S/-C/-T"),
69                 ("1", "DVB-S/-T/-C"),
70                 ("2", "DVB-C/-S/-T"),
71                 ("3", "DVB-C/-T/-S"),
72                 ("4", "DVB-T/-C/-S"),
73                 ("5", "DVB-T/-S/-C") ])
74
75         nims = [ ("-1", _("auto")) ]
76         for x in nimmanager.nim_slots:
77                 nims.append( (str(x.slot), x.getSlotName()) )
78         config.usage.frontend_priority = ConfigSelection(default = "-1", choices = nims)
79
80         config.usage.show_event_progress_in_servicelist = ConfigYesNo(default = False)
81
82         config.usage.blinking_display_clock_during_recording = ConfigYesNo(default = False)
83
84         config.usage.show_message_when_recording_starts = ConfigYesNo(default = True)
85
86         config.usage.load_length_of_movies_in_moviellist = ConfigYesNo(default = True)
87         
88         def TunerTypePriorityOrderChanged(configElement):
89                 setTunerTypePriorityOrder(int(configElement.value))
90         config.usage.alternatives_priority.addNotifier(TunerTypePriorityOrderChanged, immediate_feedback=False)
91
92         def PreferredTunerChanged(configElement):
93                 setPreferredTuner(int(configElement.value))
94         config.usage.frontend_priority.addNotifier(PreferredTunerChanged)
95
96         config.epg = ConfigSubsection()
97         config.epg.eit = ConfigYesNo(default = True)
98         config.epg.mhw = ConfigYesNo(default = False)
99         config.epg.freesat = ConfigYesNo(default = True)
100         config.epg.viasat = ConfigYesNo(default = True)
101         config.epg.netmed = ConfigYesNo(default = True)
102         config.epg.virgin = ConfigYesNo(default = False)
103         def EpgSettingsChanged(configElement):
104                 from enigma import eEPGCache
105                 mask = 0xffffffff
106                 if not config.epg.eit.value:
107                         mask &= ~(eEPGCache.NOWNEXT | eEPGCache.SCHEDULE | eEPGCache.SCHEDULE_OTHER)
108                 if not config.epg.mhw.value:
109                         mask &= ~eEPGCache.MHW
110                 if not config.epg.freesat.value:
111                         mask &= ~(eEPGCache.FREESAT_NOWNEXT | eEPGCache.FREESAT_SCHEDULE | eEPGCache.FREESAT_SCHEDULE_OTHER)
112                 if not config.epg.viasat.value:
113                         mask &= ~eEPGCache.VIASAT
114                 #if not config.epg.netmed.value:
115                 #       mask &= ~(eEPGCache.NETMED_SCHEDULE | eEPGCache.NETMED_SCHEDULE_OTHER)
116                 #if not config.epg.virgin.value:
117                 #       mask &= ~(eEPGCache.VIRGIN_NOWNEXT | eEPGCache.VIRGIN_SCHEDULE)
118                 eEPGCache.getInstance().setEpgSources(mask)
119         config.epg.eit.addNotifier(EpgSettingsChanged)
120         config.epg.mhw.addNotifier(EpgSettingsChanged)
121         config.epg.freesat.addNotifier(EpgSettingsChanged)
122         config.epg.viasat.addNotifier(EpgSettingsChanged)
123         config.epg.netmed.addNotifier(EpgSettingsChanged)
124         config.epg.virgin.addNotifier(EpgSettingsChanged)
125
126         config.epg.histminutes = ConfigSelectionNumber(min = 0, max = 120, stepwidth = 15, default = 0, wraparound = True)
127         def EpgHistorySecondsChanged(configElement):
128                 from enigma import eEPGCache
129                 eEPGCache.getInstance().setEpgHistorySeconds(config.epg.histminutes.getValue()*60)
130         config.epg.histminutes.addNotifier(EpgHistorySecondsChanged)
131
132         def setHDDStandby(configElement):
133                 for hdd in harddiskmanager.HDDList():
134                         hdd[1].setIdleTime(int(configElement.value))
135         config.usage.hdd_standby.addNotifier(setHDDStandby, immediate_feedback=False)
136
137         def set12VOutput(configElement):
138                 if configElement.value == "on":
139                         Misc_Options.getInstance().set_12V_output(1)
140                 elif configElement.value == "off":
141                         Misc_Options.getInstance().set_12V_output(0)
142         config.usage.output_12V.addNotifier(set12VOutput, immediate_feedback=False)
143
144         SystemInfo["12V_Output"] = Misc_Options.getInstance().detected_12V_output()
145
146         config.usage.keymap = ConfigText(default = eEnv.resolve("${datadir}/enigma2/keymap.xml"))
147
148         config.seek = ConfigSubsection()
149         config.seek.selfdefined_13 = ConfigNumber(default=15)
150         config.seek.selfdefined_46 = ConfigNumber(default=60)
151         config.seek.selfdefined_79 = ConfigNumber(default=300)
152
153         config.seek.speeds_forward = ConfigSet(default=[2, 4, 8, 16, 32, 64, 128], choices=[2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128])
154         config.seek.speeds_backward = ConfigSet(default=[2, 4, 8, 16, 32, 64, 128], choices=[1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128])
155         config.seek.speeds_slowmotion = ConfigSet(default=[2, 4, 8], choices=[2, 4, 6, 8, 12, 16, 25])
156
157         config.seek.enter_forward = ConfigSelection(default = "2", choices = ["2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
158         config.seek.enter_backward = ConfigSelection(default = "1", choices = ["1", "2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
159
160         config.seek.on_pause = ConfigSelection(default = "play", choices = [
161                 ("play", _("Play")),
162                 ("step", _("Singlestep (GOP)")),
163                 ("last", _("Last speed")) ])
164
165         config.usage.timerlist_finished_timer_position = ConfigSelection(default = "beginning", choices = [("beginning", _("at beginning")), ("end", _("at end"))])
166
167         def updateEnterForward(configElement):
168                 if not configElement.value:
169                         configElement.value = [2]
170                 updateChoices(config.seek.enter_forward, configElement.value)
171
172         config.seek.speeds_forward.addNotifier(updateEnterForward, immediate_feedback = False)
173
174         def updateEnterBackward(configElement):
175                 if not configElement.value:
176                         configElement.value = [2]
177                 updateChoices(config.seek.enter_backward, configElement.value)
178
179         config.seek.speeds_backward.addNotifier(updateEnterBackward, immediate_feedback = False)
180
181         config.subtitles = ConfigSubsection()
182         config.subtitles.subtitle_fontcolor = ConfigSelection(default = "0", choices = [
183                 ("0", _("default")),
184                 ("1", _("white")),
185                 ("2", _("yellow")),
186                 ("3", _("green")),
187                 ("4", _("cyan")),
188                 ("5", _("blue")),
189                 ("6", _("magneta")),
190                 ("7", _("red")),
191                 ("8", _("black")) ])
192         config.subtitles.subtitle_fontsize  = ConfigSelection(choices = ["%d" % x for x in range(16,101) if not x % 2], default = "20")
193         config.subtitles.subtitle_bgcolor = ConfigSelection(default = "0", choices = [
194                 ("0", _("black")),
195                 ("1", _("red")),
196                 ("2", _("magneta")),
197                 ("3", _("blue")),
198                 ("4", _("cyan")),
199                 ("5", _("green")),
200                 ("6", _("yellow")),
201                 ("7", _("white"))])
202         config.subtitles.subtitle_bgopacity = ConfigSelection(default = "225", choices = [
203                 ("0", _("No transparency")),
204                 ("25", "10%"),
205                 ("50", "20%"),
206                 ("75", "30%"),
207                 ("100", "40%"),
208                 ("125", "50%"),
209                 ("150", "60%"),
210                 ("175", "70%"),
211                 ("200", "80%"),
212                 ("225", "90%"),
213                 ("255", _("Full transparency"))])
214         config.subtitles.subtitle_edgestyle = ConfigSelection(default = "2", choices = [
215                 ("0", "None"),
216                 ("1", "Raised"),
217                 ("2", "Depressed"),
218                 ("3", "Uniform")])
219         config.subtitles.subtitle_edgestyle_level = ConfigSelection(choices = ["0", "1", "2", "3", "4", "5"], default = "3")
220         config.subtitles.subtitle_opacity = ConfigSelection(default = "0", choices = [
221                 ("0", _("No transparency")),
222                 ("75", "25%"),
223                 ("150", "50%")])
224         config.subtitles.subtitle_original_position = ConfigYesNo(default = True)
225         config.subtitles.subtitle_alignment = ConfigSelection(choices = [("left", _("left")), ("center", _("center")), ("right", _("right"))], default = "center")
226         config.subtitles.subtitle_position = ConfigSelection( choices = ["0", "50", "100", "150", "200", "250", "300", "350", "400", "450", "500", "550", "600"], default = "100")
227
228         config.subtitles.dvb_subtitles_centered = ConfigYesNo(default = False)
229
230         subtitle_delay_choicelist = []
231         for i in range(-900000, 1845000, 45000):
232                 if i == 0:
233                         subtitle_delay_choicelist.append(("0", _("No delay")))
234                 else:
235                         subtitle_delay_choicelist.append((str(i), "%2.1f sec" % (i / 90000.)))
236         config.subtitles.subtitle_noPTSrecordingdelay = ConfigSelection(default = "315000", choices = subtitle_delay_choicelist)
237         config.subtitles.subtitle_bad_timing_delay = ConfigSelection(default = "0", choices = subtitle_delay_choicelist)
238         config.subtitles.subtitle_rewrap = ConfigYesNo(default = False)
239         config.subtitles.colourise_dialogs = ConfigYesNo(default = False)
240         config.subtitles.pango_subtitle_fontswitch = ConfigYesNo(default = True)
241         config.subtitles.pango_subtitles_delay = ConfigSelection(default = "0", choices = subtitle_delay_choicelist)
242         config.subtitles.pango_subtitles_fps = ConfigSelection(default = "1", choices = [
243                 ("1", _("Original")),
244                 ("23976", _("23.976")),
245                 ("24000", _("24")),
246                 ("25000", _("25")),
247                 ("29970", _("29.97")),
248                 ("30000", _("30"))])
249         config.subtitles.pango_autoturnon = ConfigYesNo(default = True)
250
251         config.autolanguage = ConfigSubsection()
252         epg_language_choices=[
253                 ("---", _("None")),
254                 ("eng qaa", _("English")),
255                 ("deu ger", _("German")),
256                 ("ara", _("Arabic")),
257                 ("eus baq", _("Basque")),
258                 ("bul", _("Bulgarian")),
259                 ("hrv", _("Croatian")),
260                 ("ces cze", _("Czech")),
261                 ("dan", _("Danish")),
262                 ("dut ndl nld", _("Dutch")),
263                 ("est", _("Estonian")),
264                 ("fin", _("Finnish")),
265                 ("fra fre", _("French")),
266                 ("ell gre", _("Greek")),
267                 ("heb", _("Hebrew")),
268                 ("hun", _("Hungarian")),
269                 ("ita", _("Italian")),
270                 ("lav", _("Latvian")),
271                 ("lit", _("Lithuanian")),
272                 ("ltz", _("Luxembourgish")),
273                 ("nor", _("Norwegian")),
274                 ("fas per fa pes", _("Persian")),
275                 ("pol", _("Polish")),
276                 ("por dub Dub DUB ud1", _("Portuguese")),
277                 ("ron rum", _("Romanian")),
278                 ("rus", _("Russian")),
279                 ("srp", _("Serbian")),
280                 ("slk slo", _("Slovak")),
281                 ("slv", _("Slovenian")),
282                 ("spa", _("Spanish")),
283                 ("swe", _("Swedish")),
284                 ("tha", _("Thai")),
285                 ("tur Audio_TUR", _("Turkish")),
286                 ("ukr Ukr", _("Ukrainian"))]
287
288         def setEpgLanguage(configElement):
289                 eServiceEvent.setEPGLanguage(configElement.value)
290         config.autolanguage.epglanguage = ConfigSelection(epg_language_choices, default="---")
291         config.autolanguage.epglanguage.addNotifier(setEpgLanguage)
292
293         def setEpgLanguageAlternative(configElement):
294                 eServiceEvent.setEPGLanguageAlternative(configElement.value)
295         config.autolanguage.epglanguage_alternative = ConfigSelection(epg_language_choices, default="---")
296         config.autolanguage.epglanguage_alternative.addNotifier(setEpgLanguageAlternative)
297
298 def updateChoices(sel, choices):
299         if choices:
300                 defval = None
301                 val = int(sel.value)
302                 if not val in choices:
303                         tmp = choices[:]
304                         tmp.reverse()
305                         for x in tmp:
306                                 if x < val:
307                                         defval = str(x)
308                                         break
309                 sel.setChoices(map(str, choices), defval)
310
311 def preferredPath(path):
312         if config.usage.setup_level.index < 2 or path == "<default>" or not path:
313                 return None  # config.usage.default_path.value, but delay lookup until usage
314         elif path == "<current>":
315                 return config.movielist.last_videodir.value
316         elif path == "<timer>":
317                 return config.movielist.last_timer_videodir.value
318         else:
319                 return path
320
321 def preferredTimerPath():
322         return preferredPath(config.usage.timer_path.value)
323
324 def preferredInstantRecordPath():
325         return preferredPath(config.usage.instantrec_path.value)
326
327 def defaultMoviePath():
328         return defaultRecordingLocation(config.usage.default_path.value)
329