only show pip option in contextmenu when the hardware can handle pip
[enigma2.git] / lib / python / Screens / RecordPaths.py
1 from Screens.Screen import Screen
2 from Screens.LocationBox import MovieLocationBox, TimeshiftLocationBox
3 from Screens.MessageBox import MessageBox
4 from Components.Label import Label
5 from Components.config import config, ConfigSelection, getConfigListEntry, configfile
6 from Components.ConfigList import ConfigListScreen
7 from Components.ActionMap import ActionMap
8 from Tools.Directories import fileExists
9
10
11 class RecordPathsSettings(Screen,ConfigListScreen):
12         skin = """
13                 <screen name="RecordPathsSettings" position="160,150" size="450,200" title="Recording paths">
14                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,0" size="140,40" alphatest="on" />
15                         <ePixmap pixmap="skin_default/buttons/green.png" position="300,0" size="140,40" alphatest="on" />
16                         <widget source="key_red" render="Label" position="10,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
17                         <widget source="key_green" render="Label" position="300,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
18                         <widget name="config" position="10,44" size="430,146" />
19                 </screen>"""
20
21         def __init__(self, session):
22                 from Components.Sources.StaticText import StaticText
23                 Screen.__init__(self, session)
24                 self["key_red"] = StaticText(_("Cancel"))
25                 self["key_green"] = StaticText(_("Save"))
26
27                 ConfigListScreen.__init__(self, [])
28                 self.initConfigList()
29
30                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
31                 {
32                     "green": self.save,
33                     "red": self.cancel,
34                     "cancel": self.cancel,
35                     "ok": self.ok,
36                 }, -2)
37
38         def checkReadWriteDir(self, configele):
39                 print "checkReadWrite: ", configele.value
40                 if configele.value in [x[0] for x in self.styles] or fileExists(configele.value, "w"):
41                         configele.last_value = configele.value
42                         return True
43                 else:
44                         dir = configele.value
45                         configele.value = configele.last_value
46                         self.session.open(
47                                 MessageBox,
48                                 _("The directory %s is not writable.\nMake sure you select a writable directory instead.")%dir,
49                                 type = MessageBox.TYPE_ERROR
50                                 )
51                         return False
52
53         def initConfigList(self):
54                 self.styles = [ ("<default>", _("<Default movie location>")), ("<current>", _("<Current movielist location>")), ("<timer>", _("<Last timer location>")) ]
55                 styles_keys = [x[0] for x in self.styles]
56                 tmp = config.movielist.videodirs.value
57                 default = config.usage.default_path.value
58                 if default not in tmp:
59                         tmp = tmp[:]
60                         tmp.append(default)
61                 print "DefaultPath: ", default, tmp
62                 self.default_dirname = ConfigSelection(default = default, choices = tmp)
63                 tmp = config.movielist.videodirs.value
64                 default = config.usage.timer_path.value
65                 if default not in tmp and default not in styles_keys:
66                         tmp = tmp[:]
67                         tmp.append(default)
68                 print "TimerPath: ", default, tmp
69                 self.timer_dirname = ConfigSelection(default = default, choices = self.styles+tmp)
70                 tmp = config.movielist.videodirs.value
71                 default = config.usage.instantrec_path.value
72                 if default not in tmp and default not in styles_keys:
73                         tmp = tmp[:]
74                         tmp.append(default)
75                 print "InstantrecPath: ", default, tmp
76                 self.instantrec_dirname = ConfigSelection(default = default, choices = self.styles+tmp)
77                 default = config.usage.timeshift_path.value
78                 tmp = config.usage.allowed_timeshift_paths.value
79                 if default not in tmp:
80                         tmp = tmp[:]
81                         tmp.append(default)
82                 print "TimeshiftPath: ", default, tmp
83                 self.timeshift_dirname = ConfigSelection(default = default, choices = tmp)
84                 self.default_dirname.addNotifier(self.checkReadWriteDir, initial_call=False, immediate_feedback=False)
85                 self.timer_dirname.addNotifier(self.checkReadWriteDir, initial_call=False, immediate_feedback=False)
86                 self.instantrec_dirname.addNotifier(self.checkReadWriteDir, initial_call=False, immediate_feedback=False)
87                 self.timeshift_dirname.addNotifier(self.checkReadWriteDir, initial_call=False, immediate_feedback=False)
88
89                 self.list = []
90                 if config.usage.setup_level.index >= 2:
91                         self.default_entry = getConfigListEntry(_("Default movie location"), self.default_dirname)
92                         self.list.append(self.default_entry)
93                         self.timer_entry = getConfigListEntry(_("Timer record location"), self.timer_dirname)
94                         self.list.append(self.timer_entry)
95                         self.instantrec_entry = getConfigListEntry(_("Instant record location"), self.instantrec_dirname)
96                         self.list.append(self.instantrec_entry)
97                 else:
98                         self.default_entry = getConfigListEntry(_("Movie location"), self.default_dirname)
99                         self.list.append(self.default_entry)
100                 self.timeshift_entry = getConfigListEntry(_("Timeshift location"), self.timeshift_dirname)
101                 self.list.append(self.timeshift_entry)
102                 self["config"].setList(self.list)
103
104         def ok(self):
105                 currentry = self["config"].getCurrent()
106                 self.lastvideodirs = config.movielist.videodirs.value
107                 self.lasttimeshiftdirs = config.usage.allowed_timeshift_paths.value
108                 if config.usage.setup_level.index >= 2:
109                         txt = _("Default movie location")
110                 else:
111                         txt = _("Movie location")
112                 if currentry == self.default_entry:
113                         self.entrydirname = self.default_dirname
114                         self.session.openWithCallback(
115                                 self.dirnameSelected,
116                                 MovieLocationBox,
117                                 txt,
118                                 self.default_dirname.value
119                         )
120                 elif currentry == self.timer_entry:
121                         self.entrydirname = self.timer_dirname
122                         self.session.openWithCallback(
123                                 self.dirnameSelected,
124                                 MovieLocationBox,
125                                 _("Initial location in new timers"),
126                                 self.timer_dirname.value
127                         )
128                 elif currentry == self.instantrec_entry:
129                         self.entrydirname = self.instantrec_dirname
130                         self.session.openWithCallback(
131                                 self.dirnameSelected,
132                                 MovieLocationBox,
133                                 _("Location for instant recordings"),
134                                 self.instantrec_dirname.value
135                         )
136                 elif currentry == self.timeshift_entry:
137                         self.entrydirname = self.timeshift_dirname
138                         config.usage.timeshift_path.value = self.timeshift_dirname.value
139                         self.session.openWithCallback(
140                                 self.dirnameSelected,
141                                 TimeshiftLocationBox
142                         )
143
144         def dirnameSelected(self, res):
145                 if res is not None:
146                         self.entrydirname.value = res
147                         if config.movielist.videodirs.value != self.lastvideodirs:
148                                 styles_keys = [x[0] for x in self.styles]
149                                 tmp = config.movielist.videodirs.value
150                                 default = self.default_dirname.value
151                                 if default not in tmp:
152                                         tmp = tmp[:]
153                                         tmp.append(default)
154                                 self.default_dirname.setChoices(tmp, default=default)
155                                 tmp = config.movielist.videodirs.value
156                                 default = self.timer_dirname.value
157                                 if default not in tmp and default not in styles_keys:
158                                         tmp = tmp[:]
159                                         tmp.append(default)
160                                 self.timer_dirname.setChoices(self.styles+tmp, default=default)
161                                 tmp = config.movielist.videodirs.value
162                                 default = self.instantrec_dirname.value
163                                 if default not in tmp and default not in styles_keys:
164                                         tmp = tmp[:]
165                                         tmp.append(default)
166                                 self.instantrec_dirname.setChoices(self.styles+tmp, default=default)
167                                 self.entrydirname.value = res
168                         if config.usage.allowed_timeshift_paths.value != self.lasttimeshiftdirs:
169                                 tmp = config.usage.allowed_timeshift_paths.value
170                                 default = self.instantrec_dirname.value
171                                 if default not in tmp:
172                                         tmp = tmp[:]
173                                         tmp.append(default)
174                                 self.timeshift_dirname.setChoices(tmp, default=default)
175                                 self.entrydirname.value = res
176                         if self.entrydirname.last_value != res:
177                                 self.checkReadWriteDir(self.entrydirname)
178
179         def save(self):
180                 currentry = self["config"].getCurrent()
181                 if self.checkReadWriteDir(currentry[1]):
182                         config.usage.default_path.value = self.default_dirname.value
183                         config.usage.timer_path.value = self.timer_dirname.value
184                         config.usage.instantrec_path.value = self.instantrec_dirname.value 
185                         config.usage.timeshift_path.value = self.timeshift_dirname.value
186                         config.usage.default_path.save()
187                         config.usage.timer_path.save()
188                         config.usage.instantrec_path.save()
189                         config.usage.timeshift_path.save()
190                         self.close()
191
192         def cancel(self):
193                 self.close()
194