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