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