VPS-Plugin: initial checkin
[enigma2-plugins.git] / vps / src_py / Modifications.py
1 # -*- coding: utf-8 -*-
2
3 from . import _
4 from RecordTimer import RecordTimerEntry, RecordTimer
5 from Screens.TimerEntry import TimerEntry
6 from Components.config import config, ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
7 from Tools import Directories
8 from Tools.XMLTools import stringToXML
9 from Tools import Notifications
10 from Screens.MessageBox import MessageBox
11 import xml.etree.cElementTree
12 from Vps_setup import VPS_show_info
13 from Vps_check import VPS_check_PDC
14
15 vps_already_registered = False
16
17
18
19 def new_RecordTimer_saveTimer(self):
20         self._saveTimer_old_rn_vps()
21         
22         # added by VPS-Plugin
23         list = []
24         list.append('<?xml version="1.0" ?>\n')
25         list.append('<vps_timers>\n')
26         
27         try:    
28                 for timer in self.timer_list:
29                         if timer.dontSave or timer.vpsplugin_enabled is None or timer.vpsplugin_enabled == False:
30                                 continue
31                         
32                         list.append('<timer')
33                         list.append(' begin="' + str(int(timer.begin)) + '"')
34                         list.append(' end="' + str(int(timer.end)) + '"')
35                         list.append(' serviceref="' + stringToXML(str(timer.service_ref)) + '"')
36                         list.append(' vps_enabled="1"')
37                         
38                         if timer.vpsplugin_overwrite is not None:
39                                 list.append(' vps_overwrite="' + str(int(timer.vpsplugin_overwrite)) + '"')
40                         else:
41                                 list.append(' vps_overwrite="0"')
42                         
43                         if timer.vpsplugin_time is not None:
44                                 list.append(' vps_time="' + str(timer.vpsplugin_time) + '"')
45                         else:
46                                 list.append(' vps_time="0"')
47                         
48                         list.append('>\n')
49                         list.append('</timer>\n')
50                 
51                 list.append('</vps_timers>\n')
52                 
53                 file = open(Directories.resolveFilename(Directories.SCOPE_CONFIG, "timers_vps.xml"), "w")
54                 for x in list:
55                         file.write(x)
56                 file.close()
57         except:
58          pass
59         # added by VPS-Plugin
60
61
62 def new_RecordTimer_loadTimer(self):
63         # added by VPS-Plugin
64         xmlroot = None
65         try:
66                 global xml
67                 doc = xml.etree.cElementTree.parse(Directories.resolveFilename(Directories.SCOPE_CONFIG, "timers_vps.xml"))
68                 xmlroot = doc.getroot()
69         except:
70                 pass
71         # added by VPS-Plugin
72         
73         self._loadTimer_old_rn_vps()
74         
75         # added by VPS-Plugin
76         try:
77                 vps_timers = { }
78                 
79                 if xmlroot is not None:
80                         for xml in xmlroot.findall("timer"):
81                                 begin = xml.get("begin")
82                                 end = xml.get("end")
83                                 serviceref = xml.get("serviceref").encode("utf-8")
84                                 
85                                 vps_timers[serviceref + begin + end] = { }
86                                 vps_overwrite = xml.get("vps_overwrite")
87                                 if vps_overwrite and vps_overwrite == "1":
88                                         vps_timers[serviceref + begin + end]["overwrite"] = True
89                                 else:
90                                         vps_timers[serviceref + begin + end]["overwrite"] = False
91                                 
92                                 vps_time = xml.get("vps_time")
93                                 if vps_time and vps_time != "None":
94                                         vps_timers[serviceref + begin + end]["time"] = int(vps_time)
95                                 else:
96                                         vps_timers[serviceref + begin + end]["time"] = 0
97                         
98                         for timer in self.timer_list:
99                                 begin = str(timer.begin)
100                                 end = str(timer.end)
101                                 serviceref = str(timer.service_ref)
102                                 
103                                 if vps_timers.get(serviceref + begin + end, None) is not None:
104                                         timer.vpsplugin_enabled = True
105                                         timer.vpsplugin_overwrite = vps_timers[serviceref + begin + end]["overwrite"]
106                                         if vps_timers[serviceref + begin + end]["time"] != 0:
107                                                 timer.vpsplugin_time = vps_timers[serviceref + begin + end]["time"]
108                                 else:
109                                         timer.vpsplugin_enabled = False
110                                         timer.vpsplugin_overwrite = False
111         except:
112                 pass
113         # added by VPS-Plugin
114
115 def new_TimerEntry_createConfig(self):
116         self._createConfig_old_rn_vps()
117         
118         # added by VPS-Plugin
119         try:
120                 if self.timer.vpsplugin_enabled is not None:
121                         self.timerentry_vpsplugin_enabled = ConfigYesNo(default = self.timer.vpsplugin_enabled)
122                 elif self.timer.eit is not None and self.timer.name != "" and self.timer not in self.session.nav.RecordTimer.timer_list and self.timer not in self.session.nav.RecordTimer.processed_timers:
123                         self.timerentry_vpsplugin_enabled = ConfigYesNo(default = config.plugins.vps.default_vps.value)
124                 else:
125                         self.timerentry_vpsplugin_enabled = ConfigYesNo(default = False)
126
127                 if self.timer.vpsplugin_overwrite is not None:
128                         self.timerentry_vpsplugin_overwrite = ConfigYesNo(default = self.timer.vpsplugin_overwrite)
129                 elif config.plugins.vps.allow_overwrite.value == True:
130                         self.timerentry_vpsplugin_overwrite = ConfigYesNo(default = config.plugins.vps.default_overwrite.value)
131                 else:
132                         self.timerentry_vpsplugin_overwrite = ConfigYesNo(default = False)
133
134                 if self.timer.vpsplugin_time is not None:
135                         self.timerentry_vpsplugin_time_date = ConfigDateTime(default = self.timer.vpsplugin_time, formatstring = _("%d.%B %Y"), increment = 86400)
136                         self.timerentry_vpsplugin_time_clock = ConfigClock(default = self.timer.vpsplugin_time)
137                 else:
138                         self.timerentry_vpsplugin_time_date = ConfigDateTime(default = self.timer.begin, formatstring = _("%d.%B %Y"), increment = 86400)
139                         self.timerentry_vpsplugin_time_clock = ConfigClock(default = self.timer.begin)
140         except:
141                 pass
142         # added by VPS-Plugin
143
144
145 def new_TimerEntry_createSetup(self, widget):
146         self._createSetup_old_rn_vps(widget)
147         
148         # added by VPS-Plugin
149         self.timerVps_enabled_Entry = None
150         try:
151                 if self.timerentry_justplay.value != "zap" and self.timerentry_type.value == "once" and config.plugins.vps.enabled.value == True:
152                         self.timerVps_enabled_Entry = getConfigListEntry(_("Enable VPS"), self.timerentry_vpsplugin_enabled)
153                         self.list.append(self.timerVps_enabled_Entry)
154                         if config.plugins.vps.allow_overwrite.value == True and self.timerentry_vpsplugin_enabled.value == True:
155                                 self.list.append(getConfigListEntry(_("Recording controlled by channel"), self.timerentry_vpsplugin_overwrite))
156                         if self.timerentry_vpsplugin_enabled.value == True and (self.timer.eit is None or self.timer.name == ""):
157                                 self.session.open(VPS_check_PDC, self.timerentry_service_ref, self)
158                                 
159                                 self.list.append(getConfigListEntry(_("VPS-Time (date)"), self.timerentry_vpsplugin_time_date))
160                                 self.list.append(getConfigListEntry(_("VPS-Time (time)"), self.timerentry_vpsplugin_time_clock))
161                         
162                         # Hilfetext
163                         elif self.timerentry_vpsplugin_enabled.value == True and config.plugins.vps.infotext.value != 2:
164                                 config.plugins.vps.infotext.value = 2
165                                 config.plugins.vps.infotext.save()
166                                 VPS_show_info(self.session)
167         except:
168                 pass
169         # added by VPS-Plugin
170         self[widget].list = self.list
171         self[widget].l.setList(self.list)
172         
173
174 def new_TimerEntry_newConfig(self):
175         self._newConfig_old_rn_vps()
176         
177         # added by VPS-Plugin
178         if self["config"].getCurrent() == self.timerVps_enabled_Entry:
179                 self.createSetup("config")
180                 self["config"].setCurrentIndex(self["config"].getCurrentIndex() + 1)
181         # added by VPS-Plugin
182
183
184 def new_TimerEntry_keyGo(self):
185         # added by VPS-Plugin
186         try:
187                 self.timer.vpsplugin_enabled = self.timerentry_vpsplugin_enabled.value
188                 self.timer.vpsplugin_overwrite = self.timerentry_vpsplugin_overwrite.value
189                 if self.timer.vpsplugin_enabled == True and self.timer.name == "":
190                         self.timer.vpsplugin_time = self.getTimestamp(self.timerentry_vpsplugin_time_date.value, self.timerentry_vpsplugin_time_clock.value)
191                 if self.timer.vpsplugin_enabled == True:
192                         from Plugins.SystemPlugins.vps.Vps import vps_timers
193                         vps_timers.checksoon()
194         except:
195                 pass
196         # added by VPS-Plugin
197         
198         self._keyGo_old_rn_vps()
199
200
201
202
203 # VPS-Plugin in Enigma-Klassen einhängen
204 def register_vps():
205         global vps_already_registered
206         
207         if vps_already_registered == False:
208                 RecordTimerEntry.vpsplugin_enabled = None
209                 RecordTimerEntry.vpsplugin_overwrite = None
210                 RecordTimerEntry.vpsplugin_time = None
211                 
212                 RecordTimer._saveTimer_old_rn_vps = RecordTimer.saveTimer
213                 RecordTimer.saveTimer = new_RecordTimer_saveTimer
214                 
215                 RecordTimer._loadTimer_old_rn_vps = RecordTimer.loadTimer
216                 RecordTimer.loadTimer = new_RecordTimer_loadTimer
217                 
218                 
219                 TimerEntry._createConfig_old_rn_vps = TimerEntry.createConfig
220                 TimerEntry.createConfig = new_TimerEntry_createConfig
221                 
222                 TimerEntry._createSetup_old_rn_vps = TimerEntry.createSetup
223                 TimerEntry.createSetup = new_TimerEntry_createSetup
224                 
225                 TimerEntry._newConfig_old_rn_vps = TimerEntry.newConfig
226                 TimerEntry.newConfig = new_TimerEntry_newConfig
227                 
228                 TimerEntry._keyGo_old_rn_vps = TimerEntry.keyGo
229                 TimerEntry.keyGo = new_TimerEntry_keyGo
230                 
231                 vps_already_registered = True