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