Fix default recording path and usb recording.
[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
4 from Tools.Directories import defaultRecordingLocation
5 from Tools.Directories import resolveFilename, SCOPE_HDD
6 from enigma import Misc_Options, eEnv
7 from enigma import setTunerTypePriorityOrder, setPreferredTuner
8 from SystemInfo import SystemInfo
9 import os
10
11 def InitUsageConfig():
12         config.usage = ConfigSubsection();
13         config.usage.showdish = ConfigYesNo(default = True)
14         config.usage.multibouquet = ConfigYesNo(default = False)
15         config.usage.multiepg_ask_bouquet = ConfigYesNo(default = False)
16
17         config.usage.quickzap_bouquet_change = ConfigYesNo(default = False)
18         config.usage.e1like_radio_mode = ConfigYesNo(default = False)
19         config.usage.infobar_timeout = ConfigSelection(default = "5", choices = [
20                 ("0", _("no timeout")), ("1", "1 " + _("second")), ("2", "2 " + _("seconds")), ("3", "3 " + _("seconds")),
21                 ("4", "4 " + _("seconds")), ("5", "5 " + _("seconds")), ("6", "6 " + _("seconds")), ("7", "7 " + _("seconds")),
22                 ("8", "8 " + _("seconds")), ("9", "9 " + _("seconds")), ("10", "10 " + _("seconds"))])
23         config.usage.show_infobar_on_zap = ConfigYesNo(default = True)
24         config.usage.show_infobar_on_skip = ConfigYesNo(default = True)
25         config.usage.show_infobar_on_event_change = ConfigYesNo(default = True)
26         config.usage.hdd_standby = ConfigSelection(default = "600", choices = [
27                 ("0", _("no standby")), ("10", "10 " + _("seconds")), ("30", "30 " + _("seconds")),
28                 ("60", "1 " + _("minute")), ("120", "2 " + _("minutes")),
29                 ("300", "5 " + _("minutes")), ("600", "10 " + _("minutes")), ("1200", "20 " + _("minutes")),
30                 ("1800", "30 " + _("minutes")), ("3600", "1 " + _("hour")), ("7200", "2 " + _("hours")),
31                 ("14400", "4 " + _("hours")) ])
32         config.usage.output_12V = ConfigSelection(default = "do not change", choices = [
33                 ("do not change", _("do not change")), ("off", _("off")), ("on", _("on")) ])
34
35         config.usage.pip_zero_button = ConfigSelection(default = "standard", choices = [
36                 ("standard", _("standard")), ("swap", _("swap PiP and main picture")),
37                 ("swapstop", _("move PiP to main picture")), ("stop", _("stop PiP")) ])
38
39         config.usage.default_path = ConfigText(default = "")
40         config.usage.timer_path = ConfigText(default = "<default>")
41         config.usage.instantrec_path = ConfigText(default = "<default>")
42         config.usage.timeshift_path = ConfigText(default = "/media/hdd/")
43         config.usage.allowed_timeshift_paths = ConfigLocations(default = ["/media/hdd/"])
44
45         config.usage.on_movie_start = ConfigSelection(default = "ask", choices = [
46                 ("ask", _("Ask user")), ("resume", _("Resume from last position")), ("beginning", _("Start from the beginning")) ])
47         config.usage.on_movie_stop = ConfigSelection(default = "ask", choices = [
48                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")) ])
49         config.usage.on_movie_eof = ConfigSelection(default = "ask", choices = [
50                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")), ("pause", _("Pause movie at end")) ])
51
52         config.usage.setup_level = ConfigSelection(default = "intermediate", choices = [
53                 ("simple", _("Simple")),
54                 ("intermediate", _("Intermediate")),
55                 ("expert", _("Expert")) ])
56
57         config.usage.on_long_powerpress = ConfigSelection(default = "show_menu", choices = [
58                 ("show_menu", _("show shutdown menu")),
59                 ("shutdown", _("immediate shutdown")),
60                 ("standby", _("Standby")) ] )
61         
62         config.usage.on_short_powerpress = ConfigSelection(default = "standby", choices = [
63                 ("show_menu", _("show shutdown menu")),
64                 ("shutdown", _("immediate shutdown")),
65                 ("standby", _("Standby")) ] )
66
67
68         config.usage.alternatives_priority = ConfigSelection(default = "0", choices = [
69                 ("0", "DVB-S/-C/-T"),
70                 ("1", "DVB-S/-T/-C"),
71                 ("2", "DVB-C/-S/-T"),
72                 ("3", "DVB-C/-T/-S"),
73                 ("4", "DVB-T/-C/-S"),
74                 ("5", "DVB-T/-S/-C") ])
75
76         nims = [ ("-1", _("auto")) ]
77         for x in nimmanager.nim_slots:
78                 nims.append( (str(x.slot), x.getSlotName()) )
79         config.usage.frontend_priority = ConfigSelection(default = "-1", choices = nims)
80
81         config.usage.show_event_progress_in_servicelist = ConfigYesNo(default = False)
82
83         config.usage.blinking_display_clock_during_recording = ConfigYesNo(default = False)
84
85         config.usage.show_message_when_recording_starts = ConfigYesNo(default = True)
86
87         config.usage.load_length_of_movies_in_moviellist = ConfigYesNo(default = True)
88         
89         def TunerTypePriorityOrderChanged(configElement):
90                 setTunerTypePriorityOrder(int(configElement.value))
91         config.usage.alternatives_priority.addNotifier(TunerTypePriorityOrderChanged, immediate_feedback=False)
92
93         def PreferredTunerChanged(configElement):
94                 setPreferredTuner(int(configElement.value))
95         config.usage.frontend_priority.addNotifier(PreferredTunerChanged)
96
97         def setHDDStandby(configElement):
98                 for hdd in harddiskmanager.HDDList():
99                         hdd[1].setIdleTime(int(configElement.value))
100         config.usage.hdd_standby.addNotifier(setHDDStandby, immediate_feedback=False)
101
102         def set12VOutput(configElement):
103                 if configElement.value == "on":
104                         Misc_Options.getInstance().set_12V_output(1)
105                 elif configElement.value == "off":
106                         Misc_Options.getInstance().set_12V_output(0)
107         config.usage.output_12V.addNotifier(set12VOutput, immediate_feedback=False)
108
109         SystemInfo["12V_Output"] = Misc_Options.getInstance().detected_12V_output()
110
111         config.usage.keymap = ConfigText(default = eEnv.resolve("${datadir}/enigma2/keymap.xml"))
112
113         config.seek = ConfigSubsection()
114         config.seek.selfdefined_13 = ConfigNumber(default=15)
115         config.seek.selfdefined_46 = ConfigNumber(default=60)
116         config.seek.selfdefined_79 = ConfigNumber(default=300)
117
118         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])
119         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])
120         config.seek.speeds_slowmotion = ConfigSet(default=[2, 4, 8], choices=[2, 4, 6, 8, 12, 16, 25])
121
122         config.seek.enter_forward = ConfigSelection(default = "2", choices = ["2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
123         config.seek.enter_backward = ConfigSelection(default = "1", choices = ["1", "2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
124
125         config.seek.on_pause = ConfigSelection(default = "play", choices = [
126                 ("play", _("Play")),
127                 ("step", _("Singlestep (GOP)")),
128                 ("last", _("Last speed")) ])
129
130         config.usage.timerlist_finished_timer_position = ConfigSelection(default = "beginning", choices = [("beginning", _("at beginning")), ("end", _("at end"))])
131
132         def updateEnterForward(configElement):
133                 if not configElement.value:
134                         configElement.value = [2]
135                 updateChoices(config.seek.enter_forward, configElement.value)
136
137         config.seek.speeds_forward.addNotifier(updateEnterForward, immediate_feedback = False)
138
139         def updateEnterBackward(configElement):
140                 if not configElement.value:
141                         configElement.value = [2]
142                 updateChoices(config.seek.enter_backward, configElement.value)
143
144         config.seek.speeds_backward.addNotifier(updateEnterBackward, immediate_feedback = False)
145
146         config.subtitles = ConfigSubsection()
147         config.subtitles.subtitle_fontcolor = ConfigSelection(default = "0", choices = [
148                 ("0", _("default")),
149                 ("1", _("white")),
150                 ("2", _("yellow")),
151                 ("3", _("green")),
152                 ("4", _("cyan")),
153                 ("5", _("blue")),
154                 ("6", _("magneta")),
155                 ("7", _("red")),
156                 ("8", _("black")) ])
157         config.subtitles.subtitle_fontsize  = ConfigSelection(choices = ["%d" % x for x in range(16,101) if not x % 2], default = "20")
158         config.subtitles.subtitle_bgcolor = ConfigSelection(default = "0", choices = [
159                 ("0", _("black")),
160                 ("1", _("red")),
161                 ("2", _("magneta")),
162                 ("3", _("blue")),
163                 ("4", _("cyan")),
164                 ("5", _("green")),
165                 ("6", _("yellow")),
166                 ("7", _("white"))])
167         config.subtitles.subtitle_bgopacity = ConfigSelection(default = "225", choices = [
168                 ("0", _("No transparency")),
169                 ("25", "10%"),
170                 ("50", "20%"),
171                 ("75", "30%"),
172                 ("100", "40%"),
173                 ("125", "50%"),
174                 ("150", "60%"),
175                 ("175", "70%"),
176                 ("200", "80%"),
177                 ("225", "90%"),
178                 ("255", _("Full transparency"))])
179         config.subtitles.subtitle_edgestyle = ConfigSelection(default = "2", choices = [
180                 ("0", "None"),
181                 ("1", "Raised"),
182                 ("2", "Depressed"),
183                 ("3", "Uniform")])
184         config.subtitles.subtitle_edgestyle_level = ConfigSelection(choices = ["0", "1", "2", "3", "4", "5"], default = "3")
185         config.subtitles.subtitle_opacity = ConfigSelection(default = "0", choices = [
186                 ("0", _("No transparency")),
187                 ("75", "25%"),
188                 ("150", "50%")])
189         config.subtitles.subtitle_original_position = ConfigYesNo(default = True)
190         config.subtitles.subtitle_alignment = ConfigSelection(choices = [("left", _("left")), ("center", _("center")), ("right", _("right"))], default = "center")
191         config.subtitles.subtitle_position = ConfigSelection( choices = ["0", "50", "100", "150", "200", "250", "300", "350", "400", "450", "500", "550", "600"], default = "100")
192
193         config.subtitles.dvb_subtitles_centered = ConfigYesNo(default = False)
194
195         subtitle_delay_choicelist = []
196         for i in range(-900000, 1845000, 45000):
197                 if i == 0:
198                         subtitle_delay_choicelist.append(("0", _("No delay")))
199                 else:
200                         subtitle_delay_choicelist.append((str(i), "%2.1f sec" % (i / 90000.)))
201         config.subtitles.subtitle_noPTSrecordingdelay = ConfigSelection(default = "315000", choices = subtitle_delay_choicelist)
202         config.subtitles.subtitle_bad_timing_delay = ConfigSelection(default = "0", choices = subtitle_delay_choicelist)
203         config.subtitles.subtitle_rewrap = ConfigYesNo(default = False)
204         config.subtitles.colourise_dialogs = ConfigYesNo(default = False)
205         config.subtitles.pango_subtitle_fontswitch = ConfigYesNo(default = True)
206         config.subtitles.pango_subtitles_delay = ConfigSelection(default = "0", choices = subtitle_delay_choicelist)
207         config.subtitles.pango_subtitles_fps = ConfigSelection(default = "1", choices = [
208                 ("1", _("Original")),
209                 ("23976", _("23.976")),
210                 ("24000", _("24")),
211                 ("25000", _("25")),
212                 ("29970", _("29.97")),
213                 ("30000", _("30"))])
214         config.subtitles.pango_autoturnon = ConfigYesNo(default = True)
215
216 def updateChoices(sel, choices):
217         if choices:
218                 defval = None
219                 val = int(sel.value)
220                 if not val in choices:
221                         tmp = choices[:]
222                         tmp.reverse()
223                         for x in tmp:
224                                 if x < val:
225                                         defval = str(x)
226                                         break
227                 sel.setChoices(map(str, choices), defval)
228
229 def preferredPath(path):
230         if config.usage.setup_level.index < 2 or path == "<default>" or not path:
231                 return None  # config.usage.default_path.value, but delay lookup until usage
232         elif path == "<current>":
233                 return config.movielist.last_videodir.value
234         elif path == "<timer>":
235                 return config.movielist.last_timer_videodir.value
236         else:
237                 return path
238
239 def preferredTimerPath():
240         return preferredPath(config.usage.timer_path.value)
241
242 def preferredInstantRecordPath():
243         return preferredPath(config.usage.instantrec_path.value)
244
245 def defaultMoviePath():
246         return defaultRecordingLocation(config.usage.default_path.value)
247