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