enigma2 20140214 (master) -> 20140219 (master)
[enigma2.git] / usr / lib / enigma2 / python / Components / UsageConfig.py
1 from Components.Harddisk import harddiskmanager
2 from config import ConfigSubsection, ConfigYesNo, config, ConfigSelection, ConfigText, ConfigNumber, ConfigSet, ConfigLocations, ConfigInteger
3 from Tools.Directories import resolveFilename, SCOPE_HDD
4 from enigma import Misc_Options, setTunerTypePriorityOrder, eEnv
5 from SystemInfo import SystemInfo
6
7 def BaseInitUsageConfig():
8         config.usage = ConfigSubsection();
9
10         config.usage.keymap = ConfigText(default = eEnv.resolve("${datadir}/enigma2/keymap.xml"))
11
12         config.usage.setup_level = ConfigSelection(default = "intermediate", choices = [
13                 ("simple", _("Simple")),
14                 ("intermediate", _("Intermediate")),
15                 ("expert", _("Expert")) ])
16
17         config.seek = ConfigSubsection()
18         config.seek.selfdefined_13 = ConfigNumber(default=15)
19         config.seek.selfdefined_46 = ConfigNumber(default=60)
20         config.seek.selfdefined_79 = ConfigNumber(default=300)
21
22         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])
23         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])
24         config.seek.speeds_slowmotion = ConfigSet(default=[2, 4, 8], choices=[2, 4, 6, 8, 12, 16, 25])
25
26         config.seek.enter_forward = ConfigSelection(default = "2", choices = ["2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
27         config.seek.enter_backward = ConfigSelection(default = "1", choices = ["1", "2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
28
29         def updateEnterForward(configElement):
30                 if not configElement.value:
31                         configElement.value = [2]
32                 updateChoices(config.seek.enter_forward, configElement.value)
33         config.seek.speeds_forward.addNotifier(updateEnterForward, immediate_feedback = False)
34
35         def updateEnterBackward(configElement):
36                 if not configElement.value:
37                         configElement.value = [2]
38                 updateChoices(config.seek.enter_backward, configElement.value)
39         config.seek.speeds_backward.addNotifier(updateEnterBackward, immediate_feedback = False)
40
41
42 def FinalInitUsageConfig():
43         try:
44                 usage_old = config.usage.dict().copy()
45         except KeyError:
46                 usage_old = { }
47
48         try:
49                 seek_old = config.seek.dict().copy()
50         except KeyError:
51                 seek_old = { }
52
53         config.seek.on_pause = ConfigSelection(default = "play", choices = [
54                 ("play", _("Play")),
55                 ("step", _("Singlestep (GOP)")),
56                 ("last", _("Last speed")) ])
57
58         inactivity_shutdown_choices = [ ("never", _("disabled")) ]
59         for i in range(1,6):
60                 inactivity_shutdown_choices.extend([("%d" % i, ngettext("%(num)d hour", "%(num)d hours",i) % {"num" : i})])
61         config.usage.inactivity_shutdown = ConfigSelection(default = "3", choices = inactivity_shutdown_choices)
62         config.usage.inactivity_shutdown_initialized = ConfigYesNo(default = False)
63         config.usage.showdish = ConfigYesNo(default = True)
64         config.usage.multibouquet = ConfigYesNo(default = False)
65         config.usage.multiepg_ask_bouquet = ConfigYesNo(default = False)
66
67         config.usage.quickzap_bouquet_change = ConfigYesNo(default = False)
68         config.usage.e1like_radio_mode = ConfigYesNo(default = False)
69         config.usage.infobar_timeout = ConfigSelection(default = "5", choices = [
70                 ("0", _("no timeout")), ("1", "1 " + _("second")), ("2", "2 " + _("seconds")), ("3", "3 " + _("seconds")),
71                 ("4", "4 " + _("seconds")), ("5", "5 " + _("seconds")), ("6", "6 " + _("seconds")), ("7", "7 " + _("seconds")),
72                 ("8", "8 " + _("seconds")), ("9", "9 " + _("seconds")), ("10", "10 " + _("seconds"))])
73         config.usage.show_infobar_on_zap = ConfigYesNo(default = True)
74         config.usage.show_infobar_on_skip = ConfigYesNo(default = True)
75         config.usage.show_infobar_on_event_change = ConfigYesNo(default = True)
76         config.usage.hdd_standby = ConfigSelection(default = "600", choices = [
77                 ("0", _("no standby")), ("10", "10 " + _("seconds")), ("30", "30 " + _("seconds")),
78                 ("60", "1 " + _("minute")), ("120", "2 " + _("minutes")),
79                 ("300", "5 " + _("minutes")), ("600", "10 " + _("minutes")), ("1200", "20 " + _("minutes")),
80                 ("1800", "30 " + _("minutes")), ("3600", "1 " + _("hour")), ("7200", "2 " + _("hours")),
81                 ("14400", "4 " + _("hours")) ])
82         config.usage.output_12V = ConfigSelection(default = "do not change", choices = [
83                 ("do not change", _("do not change")), ("off", _("off")), ("on", _("on")) ])
84
85         config.usage.pip_zero_button = ConfigSelection(default = "standard", choices = [
86                 ("standard", _("standard")), ("swap", _("swap PiP and main picture")),
87                 ("swapstop", _("move PiP to main picture")), ("stop", _("stop PiP")) ])
88
89         config.usage.default_path = ConfigText(default = resolveFilename(SCOPE_HDD))
90         config.usage.timer_path = ConfigText(default = "<default>")
91         config.usage.instantrec_path = ConfigText(default = "<default>")
92         config.usage.timeshift_path = ConfigText(default = "/media/hdd/")
93         config.usage.allowed_timeshift_paths = ConfigLocations(default = ["/media/hdd/"])
94
95         config.usage.on_movie_start = ConfigSelection(default = "ask", choices = [
96                 ("ask", _("Ask user")), ("resume", _("Resume from last position")), ("beginning", _("Start from the beginning")) ])
97         config.usage.on_movie_stop = ConfigSelection(default = "ask", choices = [
98                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")) ])
99         config.usage.on_movie_eof = ConfigSelection(default = "ask", choices = [
100                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")), ("pause", _("Pause movie at end")) ])
101
102         config.usage.on_long_powerpress = ConfigSelection(default = "show_menu", choices = [
103                 ("show_menu", _("show shutdown menu")),
104                 ("shutdown", _("immediate shutdown")),
105                 ("standby", _("Idle Mode")) ] )
106
107         config.usage.on_short_powerpress = ConfigSelection(default = "standby", choices = [
108                 ("show_menu", _("show shutdown menu")),
109                 ("shutdown", _("immediate shutdown")),
110                 ("standby", _("Idle Mode")) ] )
111
112         config.usage.alternatives_priority = ConfigSelection(default = "0", choices = [
113                 ("0", "DVB-S/-C/-T"),
114                 ("1", "DVB-S/-T/-C"),
115                 ("2", "DVB-C/-S/-T"),
116                 ("3", "DVB-C/-T/-S"),
117                 ("4", "DVB-T/-C/-S"),
118                 ("5", "DVB-T/-S/-C") ])
119
120         config.usage.show_event_progress_in_servicelist = ConfigYesNo(default = False)
121
122         config.usage.blinking_display_clock_during_recording = ConfigYesNo(default = False)
123
124         config.usage.show_message_when_recording_starts = ConfigYesNo(default = True)
125
126         config.usage.load_length_of_movies_in_moviellist = ConfigYesNo(default = True)
127
128         SystemInfo["12V_Output"] = Misc_Options.getInstance().detected_12V_output()
129
130         config.usage.timerlist_finished_timer_position = ConfigSelection(default = "beginning", choices = [("beginning", _("at beginning")), ("end", _("at end"))])
131
132         config.usage.text_subtitle_presentation = ConfigSelection(default = "black box", choices = [("black box", _("black box")), ("drop-shadow", _("drop-shadow"))])
133         config.usage.ttx_subtitle_prefer_pmt_language_code = ConfigYesNo(default=True)
134
135         # Channelselection settings
136         config.usage.configselection_showsettingsincontextmenu = ConfigYesNo(default=True)
137         config.usage.configselection_showlistnumbers = ConfigYesNo(default=True)
138         config.usage.configselection_showservicename = ConfigYesNo(default=True)
139         config.usage.configselection_progressbarposition = ConfigSelection(default = "0", choices = [("0",_("After servicenumber")),("1",_("After servicename")), ("2",_("After servicedescription"))])
140         config.usage.configselection_servicenamecolwidth = ConfigInteger(200, limits =(100,400))
141         config.usage.configselection_columnstyle = ConfigYesNo(default=False)
142         config.usage.configselection_additionaltimedisplayposition = ConfigSelection(default = "1", choices = [("0",_("ahead")),("1",_("behind"))])
143         config.usage.configselection_showadditionaltimedisplay = ConfigSelection(default = "0",choices = [("0", _("Off")), ("1", _("Percent")), ("2", _("Remain")),("3", _("Remain / duration")), ("4", _("Elapsed")), ("5", _("Elapsed / duration")), ("6", _("Elapsed / remain / duration")),("7", _("Time"))])
144         config.usage.configselection_showpicons = ConfigYesNo(default=False)
145         config.usage.configselection_bigpicons = ConfigYesNo(default=False)
146         config.usage.configselection_secondlineinfo =  ConfigSelection(default = "0", choices = [("0",_("nothing")),("1",_("short description")), ("2",_("upcoming event"))])
147
148         config.usage.configselection_piconspath = ConfigSelection(default = eEnv.resolve('${datadir}/enigma2/picon_50x30/'), choices = [
149                                 (eEnv.resolve('${datadir}/enigma2/picon_50x30/'), eEnv.resolve('${datadir}/enigma2/picon_50x30')),
150                                 ('/media/cf/picon_50x30/', '/media/cf/picon_50x30'),
151                                 ('/media/usb/picon_50x30/', '/media/usb/picon_50x30'),
152                                 (eEnv.resolve('${datadir}/enigma2/picon/'), eEnv.resolve('${datadir}/enigma2/picon')),
153                                 ('/media/cf/picon/', '/media/cf/picon'),
154                                 ('/media/usb/picon/', '/media/usb/picon'),
155                                 ])
156
157         config.usage.configselection_showrecordings = ConfigYesNo(default=False)
158         config.usage.standby_zaptimer_wakeup = ConfigYesNo(default=True)
159
160         seek = config.seek.dict()
161         for (key, value) in seek_old.items():
162                 value_old = value.value
163                 configEntry = seek[key]
164                 value_new = configEntry.value
165                 if value_old != value_new:
166                         configEntry.value = value_old
167                 configEntry._ConfigElement__notifiers = value._ConfigElement__notifiers
168                 configEntry._ConfigElement__notifiers_final = value._ConfigElement__notifiers_final
169
170         usage = config.usage.dict()
171         for (key, value) in usage_old.items():
172                 value_old = value.value
173                 configEntry = usage[key]
174                 value_new = configEntry.value
175                 if value_old != value_new:
176                         configEntry.value = value_old
177                 configEntry._ConfigElement__notifiers = value._ConfigElement__notifiers
178                 configEntry._ConfigElement__notifiers_final = value._ConfigElement__notifiers_final
179
180         if usage_old.get("alternatives_priority", None) == None:
181                 def TunerTypePriorityOrderChanged(configElement):
182                         setTunerTypePriorityOrder(int(configElement.value))
183                 config.usage.alternatives_priority.addNotifier(TunerTypePriorityOrderChanged, immediate_feedback=False)
184
185         if usage_old.get("hdd_standby", None) == None:
186                 def setHDDStandby(configElement):
187                         for hdd in harddiskmanager.HDDList():
188                                 hdd[1].setIdleTime(int(configElement.value))
189                 config.usage.hdd_standby.addNotifier(setHDDStandby, immediate_feedback=False)
190
191         if usage_old.get("output_12V", None) == None:
192                 def set12VOutput(configElement):
193                         if configElement.value == "on":
194                                 Misc_Options.getInstance().set_12V_output(1)
195                         elif configElement.value == "off":
196                                 Misc_Options.getInstance().set_12V_output(0)
197                 config.usage.output_12V.addNotifier(set12VOutput, immediate_feedback=False)
198
199 def updateChoices(sel, choices):
200         if choices:
201                 defval = None
202                 val = int(sel.value)
203                 if not val in choices:
204                         tmp = choices[:]
205                         tmp.reverse()
206                         for x in tmp:
207                                 if x < val:
208                                         defval = str(x)
209                                         break
210                 sel.setChoices(map(str, choices), defval)
211
212 def preferredPath(path):
213         if config.usage.setup_level.index < 2 or path == "<default>":
214                 return None  # config.usage.default_path.value, but delay lookup until usage
215         elif path == "<current>":
216                 return config.movielist.last_videodir.value
217         elif path == "<timer>":
218                 return config.movielist.last_timer_videodir.value
219         else:
220                 return path
221
222 def preferredTimerPath():
223         return preferredPath(config.usage.timer_path.value)
224
225 def preferredInstantRecordPath():
226         return preferredPath(config.usage.instantrec_path.value)
227
228 def defaultMoviePath():
229         return config.usage.default_path.value
230
231 def defaultStorageDevice():
232         return config.storage_options.default_device.value