Merge branch 'bug_351_softwaremanager_save_config_before_backup'
[enigma2.git] / lib / python / Components / UsageConfig.py
1 from Components.Harddisk import harddiskmanager
2 from config import ConfigSubsection, ConfigYesNo, config, ConfigSelection, ConfigText, ConfigNumber, ConfigSet, ConfigLocations
3 from Tools.Directories import resolveFilename, SCOPE_HDD
4 from enigma import Misc_Options, setTunerTypePriorityOrder;
5 from SystemInfo import SystemInfo
6 import os
7
8 def InitUsageConfig():
9         config.usage = ConfigSubsection();
10         config.usage.showdish = ConfigYesNo(default = False)
11         config.usage.multibouquet = ConfigYesNo(default = False)
12         config.usage.quickzap_bouquet_change = ConfigYesNo(default = False)
13         config.usage.e1like_radio_mode = ConfigYesNo(default = False)
14         config.usage.infobar_timeout = ConfigSelection(default = "5", choices = [
15                 ("0", _("no timeout")), ("1", "1 " + _("second")), ("2", "2 " + _("seconds")), ("3", "3 " + _("seconds")),
16                 ("4", "4 " + _("seconds")), ("5", "5 " + _("seconds")), ("6", "6 " + _("seconds")), ("7", "7 " + _("seconds")),
17                 ("8", "8 " + _("seconds")), ("9", "9 " + _("seconds")), ("10", "10 " + _("seconds"))])
18         config.usage.show_infobar_on_zap = ConfigYesNo(default = True)
19         config.usage.show_infobar_on_skip = ConfigYesNo(default = True)
20         config.usage.show_infobar_on_event_change = ConfigYesNo(default = True)
21         config.usage.hdd_standby = ConfigSelection(default = "600", choices = [
22                 ("0", _("no standby")), ("10", "10 " + _("seconds")), ("30", "30 " + _("seconds")),
23                 ("60", "1 " + _("minute")), ("120", "2 " + _("minutes")),
24                 ("300", "5 " + _("minutes")), ("600", "10 " + _("minutes")), ("1200", "20 " + _("minutes")),
25                 ("1800", "30 " + _("minutes")), ("3600", "1 " + _("hour")), ("7200", "2 " + _("hours")),
26                 ("14400", "4 " + _("hours")) ])
27         config.usage.output_12V = ConfigSelection(default = "do not change", choices = [
28                 ("do not change", _("do not change")), ("off", _("off")), ("on", _("on")) ])
29
30         config.usage.pip_zero_button = ConfigSelection(default = "standard", choices = [
31                 ("standard", _("standard")), ("swap", _("swap PiP and main picture")),
32                 ("swapstop", _("move PiP to main picture")), ("stop", _("stop PiP")) ])
33
34         config.usage.default_path = ConfigText(default = resolveFilename(SCOPE_HDD))
35         config.usage.timer_path = ConfigText(default = "<default>")
36         config.usage.instantrec_path = ConfigText(default = "<default>")
37         config.usage.timeshift_path = ConfigText(default = "/media/hdd/")
38         config.usage.allowed_timeshift_paths = ConfigLocations(default = ["/media/hdd/"])
39
40         config.usage.on_movie_start = ConfigSelection(default = "ask", choices = [
41                 ("ask", _("Ask user")), ("resume", _("Resume from last position")), ("beginning", _("Start from the beginning")) ])
42         config.usage.on_movie_stop = ConfigSelection(default = "ask", choices = [
43                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")) ])
44         config.usage.on_movie_eof = ConfigSelection(default = "ask", choices = [
45                 ("ask", _("Ask user")), ("movielist", _("Return to movie list")), ("quit", _("Return to previous service")), ("pause", _("Pause movie at end")) ])
46
47         config.usage.setup_level = ConfigSelection(default = "intermediate", choices = [
48                 ("simple", _("Simple")),
49                 ("intermediate", _("Intermediate")),
50                 ("expert", _("Expert")) ])
51
52         config.usage.on_long_powerpress = ConfigSelection(default = "show_menu", choices = [
53                 ("show_menu", _("show shutdown menu")),
54                 ("shutdown", _("immediate shutdown")) ] )
55
56         config.usage.alternatives_priority = ConfigSelection(default = "0", choices = [
57                 ("0", "DVB-S/-C/-T"),
58                 ("1", "DVB-S/-T/-C"),
59                 ("2", "DVB-C/-S/-T"),
60                 ("3", "DVB-C/-T/-S"),
61                 ("4", "DVB-T/-C/-S"),
62                 ("5", "DVB-T/-S/-C") ])
63
64         config.usage.blinking_display_clock_during_recording = ConfigYesNo(default = False)
65
66         config.usage.show_message_when_recording_starts = ConfigYesNo(default = True)
67
68         config.usage.load_length_of_movies_in_moviellist = ConfigYesNo(default = True)
69         
70         def TunerTypePriorityOrderChanged(configElement):
71                 setTunerTypePriorityOrder(int(configElement.value))
72         config.usage.alternatives_priority.addNotifier(TunerTypePriorityOrderChanged, immediate_feedback=False)
73
74         def setHDDStandby(configElement):
75                 for hdd in harddiskmanager.HDDList():
76                         hdd[1].setIdleTime(int(configElement.value))
77         config.usage.hdd_standby.addNotifier(setHDDStandby, immediate_feedback=False)
78
79         def set12VOutput(configElement):
80                 if configElement.value == "on":
81                         Misc_Options.getInstance().set_12V_output(1)
82                 elif configElement.value == "off":
83                         Misc_Options.getInstance().set_12V_output(0)
84         config.usage.output_12V.addNotifier(set12VOutput, immediate_feedback=False)
85
86         SystemInfo["12V_Output"] = Misc_Options.getInstance().detected_12V_output()
87
88         config.usage.keymap = ConfigText(default = "/usr/share/enigma2/keymap.xml")
89
90         config.seek = ConfigSubsection()
91         config.seek.selfdefined_13 = ConfigNumber(default=15)
92         config.seek.selfdefined_46 = ConfigNumber(default=60)
93         config.seek.selfdefined_79 = ConfigNumber(default=300)
94
95         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])
96         config.seek.speeds_backward = ConfigSet(default=[8, 16, 32, 64, 128], choices=[1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128])
97         config.seek.speeds_slowmotion = ConfigSet(default=[2, 4, 8], choices=[2, 4, 6, 8, 12, 16, 25])
98
99         config.seek.enter_forward = ConfigSelection(default = "2", choices = ["2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
100         config.seek.enter_backward = ConfigSelection(default = "1", choices = ["1", "2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
101         config.seek.stepwise_minspeed = ConfigSelection(default = "16", choices = ["Never", "2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"])
102         config.seek.stepwise_repeat = ConfigSelection(default = "3", choices = ["2", "3", "4", "5", "6"])
103
104         config.seek.on_pause = ConfigSelection(default = "play", choices = [
105                 ("play", _("Play")),
106                 ("step", _("Singlestep (GOP)")),
107                 ("last", _("Last speed")) ])
108
109         def updateEnterForward(configElement):
110                 if not configElement.value:
111                         configElement.value = [2]
112                 updateChoices(config.seek.enter_forward, configElement.value)
113
114         config.seek.speeds_forward.addNotifier(updateEnterForward, immediate_feedback = False)
115
116         def updateEnterBackward(configElement):
117                 if not configElement.value:
118                         configElement.value = [2]
119                 updateChoices(config.seek.enter_backward, configElement.value)
120
121         config.seek.speeds_backward.addNotifier(updateEnterBackward, immediate_feedback = False)
122
123 def updateChoices(sel, choices):
124         if choices:
125                 defval = None
126                 val = int(sel.value)
127                 if not val in choices:
128                         tmp = choices[:]
129                         tmp.reverse()
130                         for x in tmp:
131                                 if x < val:
132                                         defval = str(x)
133                                         break
134                 sel.setChoices(map(str, choices), defval)
135
136 def preferredPath(path):
137         if config.usage.setup_level.index < 2 or path == "<default>":
138                 return None  # config.usage.default_path.value, but delay lookup until usage
139         elif path == "<current>":
140                 return config.movielist.last_videodir.value
141         elif path == "<timer>":
142                 return config.movielist.last_timer_videodir.value
143         else:
144                 return path
145
146 def preferredTimerPath():
147         return preferredPath(config.usage.timer_path.value)
148
149 def preferredInstantRecordPath():
150         return preferredPath(config.usage.instantrec_path.value)
151
152 def defaultMoviePath():
153         return config.usage.default_path.value
154