center screens
[enigma2-plugins.git] / partnerbox / src / RemoteTimerEntry.py
1 #
2 #  Partnerbox E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2009
7 #  Support: www.dreambox-tools.info
8 #
9 #  This program is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU General Public License
11 #  as published by the Free Software Foundation; either version 2
12 #  of the License, or (at your option) any later version.
13 #
14 #  This program is distributed in the hope that it will be useful,
15 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #  GNU General Public License for more details.
18 #
19
20 from Screens.Screen import Screen
21 import Screens.ChannelSelection
22 from ServiceReference import ServiceReference
23 from Components.config import config, ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
24 from Components.ActionMap import NumberActionMap
25 from Components.ConfigList import ConfigListScreen
26 from Components.MenuList import MenuList
27 from Components.Button import Button
28 from Components.Label import Label
29 from Components.Pixmap import Pixmap
30 from Screens.MovieSelection import getPreferredTagEditor
31 from Screens.LocationBox import MovieLocationBox
32 from Screens.ChoiceBox import ChoiceBox
33 from RecordTimer import AFTEREVENT
34 from Tools.Directories import resolveFilename, SCOPE_HDD
35 from enigma import eEPGCache
36 from time import localtime, mktime, time, strftime
37 from datetime import datetime
38 from Screens.TimerEntry import TimerEntry
39 from Screens.MessageBox import MessageBox
40 from Tools.BoundFunction import boundFunction
41 import urllib
42
43 import xml.etree.cElementTree
44 from Components.ActionMap import ActionMap
45
46 from PartnerboxFunctions import PlaylistEntry, SetPartnerboxTimerlist, sendPartnerBoxWebCommand
47 import PartnerboxFunctions as partnerboxfunctions
48
49 # for localized messages
50 from . import _
51
52
53 class RemoteTimerEntry(Screen, ConfigListScreen):
54         skin = """
55                 <screen name="RemoteTimerEntry" position="center,center" size="560,430" title="Timer entry">
56                         <widget name="cancel" pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
57                         <widget name="ok" pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
58                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
59                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
60                         <widget name="canceltext" position="0,0" zPosition="2" size="140,40" halign="center" valign="center" font="Regular;21" backgroundColor="#9f1313" transparent="1" />
61                         <widget name="oktext" position="140,0" zPosition="2" size="140,40" halign="center" valign="center" font="Regular;21" backgroundColor="#1f771f" transparent="1" />
62                         <widget name="config" position="10,45" size="540,385" scrollbarMode="showOnDemand" />
63                 </screen>"""
64
65         def __init__(self, session, timer, Locations):
66                 self.session = session
67                 Screen.__init__(self, session)
68                 self.timer = timer
69                 self.Locations = Locations
70                 self.entryDate = None
71                 self.entryService = None
72                 self["oktext"] = Label(_("OK"))
73                 self["canceltext"] = Label(_("Cancel"))
74                 self["ok"] = Pixmap()
75                 self["cancel"] = Pixmap()
76                 self.createConfig()
77                 self["actions"] = NumberActionMap(["SetupActions", "GlobalActions", "PiPSetupActions"],
78                 {
79                         "save": self.keyGo,
80                         "cancel": self.keyCancel,
81                         "volumeUp": self.incrementStart,
82                         "volumeDown": self.decrementStart,
83                         "size+": self.incrementEnd,
84                         "size-": self.decrementEnd
85                 }, -2)
86                 self.list = []
87                 ConfigListScreen.__init__(self, self.list, session = session)
88                 self.createSetup("config")
89
90         def createConfig(self):
91                 
92                 if self.timer.type == 0:
93                         justplay = self.timer.justplay
94                         afterevent = {
95                                 0: "nothing",
96                                 2: "deepstandby",
97                                 1: "standby",
98                                 3: "auto"
99                                 }[self.timer.afterevent]
100                 else:
101                         if self.timer.type & PlaylistEntry.doShutdown:
102                                 afterevent = PlaylistEntry.doShutdown
103                         elif self.timer.type & PlaylistEntry.doGoSleep:
104                                 afterevent = PlaylistEntry.doGoSleep
105                         else:
106                                 afterevent = 0
107                 
108                         if self.timer.type & PlaylistEntry.RecTimerEntry:
109                                 if self.timer.type & PlaylistEntry.recDVR:
110                                         justplay = PlaylistEntry.recDVR
111                                 elif self.timer.type & PlaylistEntry.recNgrab:
112                                         justplay = PlaylistEntry.recNgrab
113                         elif self.timer.type & PlaylistEntry.SwitchTimerEntry:
114                                 justplay = PlaylistEntry.SwitchTimerEntry
115                 
116                 weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
117                 day = []
118                 weekday = 0
119                 for x in (0, 1, 2, 3, 4, 5, 6):
120                         day.append(0)
121                 begin = self.timer.timebegin
122                 end = self.timer.timeend
123                 weekday = (int(strftime("%w", localtime(begin))) - 1) % 7
124                 day[weekday] = 1
125                 name = self.timer.name 
126                 description = self.timer.description
127                 if self.timer.type == 0:
128                         self.timerentry_justplay = ConfigSelection(choices = [("1", _("zap")), ("0", _("record"))], default = str(justplay))
129                         self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
130                         self.timerentry_name = ConfigText(default = name, visible_width = 50, fixed_size = False)
131                 else:
132                         self.timerentry_justplay = ConfigSelection(choices = [(str(PlaylistEntry.SwitchTimerEntry), _("zap")), (str(PlaylistEntry.recNgrab), _("NGRAB")),(str(PlaylistEntry.recDVR), _("DVR"))], default = str(justplay))
133                         self.timerentry_afterevent = ConfigSelection(choices = [("0", _("do nothing")), (str(PlaylistEntry.doGoSleep), _("go to standby")), (str(PlaylistEntry.doShutdown), _("go to deep standby"))], default = str(afterevent))
134                 self.timerentry_description = ConfigText(default = description, visible_width = 50, fixed_size = False)
135                 self.timerentry_date = ConfigDateTime(default = begin, formatstring = _("%d.%B %Y"), increment = 86400)
136                 self.timerentry_starttime = ConfigClock(default = begin)
137                 self.timerentry_endtime = ConfigClock(default = end)
138                 if self.timer.type == 0:
139                         default = self.timer.dirname
140                         if default not in self.Locations:
141                                 self.Locations.append(default)
142                         self.timerentry_dirname = ConfigSelection(default = default, choices = self.Locations)
143                 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
144                 self.timerentry_day = ConfigSubList()
145                 for x in (0, 1, 2, 3, 4, 5, 6):
146                         self.timerentry_day.append(ConfigYesNo(default = day[x]))
147                 servicename = self.timer.servicename
148                 self.timerentry_service = ConfigSelection([servicename])
149
150         def createSetup(self, widget):
151                 self.list = []
152                 if self.timer.type == 0:
153                         self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
154                 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
155                 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
156                 self.list.append(self.timerJustplayEntry)
157                 self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
158                 self.list.append(self.entryDate)
159                 self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
160                 self.list.append(self.entryStartTime)
161                 if self.timer.type == 0:
162                         if int(self.timerentry_justplay.value) != 1:
163                                 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
164                                 self.list.append(self.entryEndTime)
165                         else:
166                                 self.entryEndTime = None
167                 else:
168                         self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
169                         self.list.append(self.entryEndTime)
170                 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
171                 self.list.append(self.channelEntry)
172                 if self.timer.type == 0:
173                         self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
174                         if int(self.timerentry_justplay.value) != 1:
175                                 self.list.append(self.dirname)
176                                 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
177                 else:
178                         self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
179                 self[widget].list = self.list
180                 self[widget].l.setList(self.list)
181                 
182         def newConfig(self):
183                 if self["config"].getCurrent() == self.timerJustplayEntry:
184                         self.createSetup("config")
185                         
186         def keyLeft(self):
187                 ConfigListScreen.keyLeft(self)
188                 self.newConfig()
189
190         def keyRight(self):
191                 ConfigListScreen.keyRight(self)
192                 self.newConfig()
193                 
194         def getTimestamp(self, date, mytime):
195                 d = localtime(date)
196                 dt = datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
197                 return int(mktime(dt.timetuple()))
198
199         def getBeginEnd(self):
200                 date = self.timerentry_date.value
201                 endtime = self.timerentry_endtime.value
202                 starttime = self.timerentry_starttime.value
203                 begin = self.getTimestamp(date, starttime)
204                 end = self.getTimestamp(date, endtime)
205                 if end < begin:
206                         end += 86400
207                 return begin, end
208
209         def keyCancel(self):
210                 self.close((False,))
211                 
212         def keyGo(self):
213                 if self.timer.type == 0:
214                         self.timer.name = self.timerentry_name.value
215                         self.timer.dirname = self.timerentry_dirname.value
216                         self.timer.afterevent = {
217                         "nothing": 0,
218                         "deepstandby": 2,
219                         "standby": 1,
220                         "auto": 3
221                         }[self.timerentry_afterevent.value]
222                 else:
223                         self.timer.afterevent = int(self.timerentry_afterevent.value)
224                 self.timer.description = self.timerentry_description.value
225                 self.timer.justplay = int(self.timerentry_justplay.value)
226                 
227                 self.timer.timebegin, self.timer.timeend = self.getBeginEnd()
228                 self.close((True, self.timer))
229
230         def incrementStart(self):
231                 self.timerentry_starttime.increment()
232                 self["config"].invalidate(self.entryStartTime)
233
234         def decrementStart(self):
235                 self.timerentry_starttime.decrement()
236                 self["config"].invalidate(self.entryStartTime)
237
238         def incrementEnd(self):
239                 if self.entryEndTime is not None:
240                         self.timerentry_endtime.increment()
241                         self["config"].invalidate(self.entryEndTime)
242
243         def decrementEnd(self):
244                 if self.entryEndTime is not None:
245                         self.timerentry_endtime.decrement()
246                         self["config"].invalidate(self.entryEndTime)
247                         
248                         
249                         
250 # ##########################################
251 # TimerEntry
252 # ##########################################
253 baseTimerEntrySetup = None
254 baseTimerEntryGo = None
255 baseTimerEntrynewConfig = None
256 baseTimerkeyLeft = None
257 baseTimerkeyRight = None
258 baseTimerkeySelect = None
259 baseTimercreateConfig = None
260
261 def RemoteTimerInit():
262         global baseTimerEntrySetup, baseTimerEntryGo, baseTimerEntrynewConfig, baseTimerkeyLeft, baseTimerkeyRight, baseTimerkeySelect, baseTimercreateConfig
263         if baseTimerEntrySetup is None:
264                 baseTimerEntrySetup = TimerEntry.createSetup
265         if baseTimerEntryGo is None:
266                 baseTimerEntryGo = TimerEntry.keyGo
267         if baseTimerEntrynewConfig is None:
268                 baseTimerEntrynewConfig = TimerEntry.newConfig
269         if baseTimerkeyLeft is None:
270                 baseTimerkeyLeft = TimerEntry.keyLeft
271         if baseTimerkeyRight is None:
272                 baseTimerkeyRight = TimerEntry.keyRight
273         if baseTimerkeySelect is None:
274                 baseTimerkeySelect = TimerEntry.keySelect
275         if baseTimercreateConfig is None:
276                 baseTimercreateConfig  = TimerEntry.createConfig
277         
278         TimerEntry.createConfig = RemoteTimerConfig
279         TimerEntry.keyLeft = RemoteTimerkeyLeft 
280         TimerEntry.keyRight = RemoteTimerkeyRight
281         TimerEntry.keySelect = RemoteTimerkeySelect
282         TimerEntry.createSetup = createRemoteTimerSetup
283         TimerEntry.keyGo = RemoteTimerGo
284         TimerEntry.newConfig = RemoteTimernewConfig
285         
286 def RemoteTimerConfig(self):
287         self.Locations = []
288         self.entryguilist = []
289         self.entryguilist.append(("0",_("No"),None))
290         index = 1
291         for c in config.plugins.Partnerbox.Entries:
292                 self.entryguilist.append((str(index),str(c.name.value),c))
293                 index = index + 1
294         self.timerentry_remote = ConfigSelection(default = "0", choices = self.entryguilist)
295         baseTimercreateConfig(self)
296
297 #def getLocationsError(self, error):
298 #       RemoteTimercreateConfig(self)
299 #       RemoteTimerCreateSetup(self,"config")
300         
301 def getLocationsCallback(self, xmlstring):
302         self.Locations = []
303         try: root = xml.etree.cElementTree.fromstring(xmlstring)
304         except: return 
305         for location in root.findall("e2location"):
306                 self.Locations.append(location.text.encode("utf-8", 'ignore'))
307         for location in root.findall("e2simplexmlitem"):  # vorerst Kompatibilitaet zum alten Webinterface-Api aufrecht erhalten (e2simplexmlitem)
308                 self.Locations.append(location.text.encode("utf-8", 'ignore'))
309                 
310 def createRemoteTimerSetup(self, widget):
311         baseTimerEntrySetup(self, widget)
312         self.display = _("Remote Timer")
313         self.timerRemoteEntry = getConfigListEntry(self.display, self.timerentry_remote)
314         self.list.insert(0, self.timerRemoteEntry)
315         self[widget].list = self.list
316         
317 def RemoteTimerkeyLeft(self):
318         if int(self.timerentry_remote.value) != 0:
319                 ConfigListScreen.keyLeft(self)
320                 RemoteTimernewConfig(self)
321         else:
322                 baseTimerkeyLeft(self)
323
324 def RemoteTimerkeyRight(self):
325         if int(self.timerentry_remote.value) != 0:
326                 ConfigListScreen.keyRight(self)
327                 RemoteTimernewConfig(self)
328         else:
329                 baseTimerkeyRight(self)
330
331 def RemoteTimerkeySelect(self):
332         if int(self.timerentry_remote.value) != 0:
333                 RemoteTimerGo(self)
334         else:
335                 baseTimerkeySelect(self)
336         
337         
338 def RemoteTimernewConfig(self):
339         if self["config"].getCurrent() == self.timerRemoteEntry:
340                 if int(self.timerentry_remote.value) != 0:
341                         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 1: # E1
342                                 self.timertype = PlaylistEntry.RecTimerEntry|PlaylistEntry.recDVR
343                         else: # E2
344                                 self.timertype = 0
345                                 ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
346                                 port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
347                                 http_ = "%s:%d" % (ip,port)
348                                 sCommand = "http://root:" + self.entryguilist[int(self.timerentry_remote.value)][2].password.value + "@" + http_ + "/web/getlocations"
349                                 #sCommand = self.http + "/web/getlocations"
350                                 #sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(boundFunction(getLocationsCallback,self)).addErrback(boundFunction(getLocationsError,self))
351                                 # ich mach das besser synchron, falls die Partnerbox aus ist ( dann koennte man hier schon abbrechen und eine Meldung bringen...)
352                                 try:
353                                         f = urllib.urlopen(sCommand)
354                                         sxml = f.read()
355                                         getLocationsCallback(self,sxml)
356                                 except: pass
357                         RemoteTimercreateConfig(self)
358                         RemoteTimerCreateSetup(self,"config")
359                 else:
360                         baseTimercreateConfig(self)
361                         createRemoteTimerSetup(self, "config")
362         elif self["config"].getCurrent() == self.timerJustplayEntry:
363                 if int(self.timerentry_remote.value) != 0:
364                         RemoteTimerCreateSetup(self,"config")
365                 else:
366                         baseTimerEntrynewConfig(self)
367         else:
368                         if int(self.timerentry_remote.value) == 0:
369                                 baseTimerEntrynewConfig(self)
370         
371 def  RemoteTimercreateConfig(self):
372         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
373                 justplay = self.timer.justplay
374                 afterevent = {
375                         AFTEREVENT.NONE: "nothing",
376                         AFTEREVENT.DEEPSTANDBY: "deepstandby",
377                          AFTEREVENT.STANDBY: "standby",
378                          AFTEREVENT.AUTO: "auto"
379                         }[self.timer.afterEvent]
380         else:
381                 if self.timertype & PlaylistEntry.doShutdown:
382                         afterevent = PlaylistEntry.doShutdown
383                 elif self.timertype & PlaylistEntry.doGoSleep:
384                         afterevent = PlaylistEntry.doGoSleep
385                 else:
386                         afterevent = 0
387                 if self.timertype & PlaylistEntry.RecTimerEntry:
388                         if self.timertype & PlaylistEntry.recDVR:
389                                 justplay = PlaylistEntry.recDVR
390                         elif self.timertype & PlaylistEntry.recNgrab:
391                                 justplay = PlaylistEntry.recNgrab
392                 elif self.timertype & PlaylistEntry.SwitchTimerEntry:
393                         justplay = PlaylistEntry.SwitchTimerEntry
394         weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
395         day = []
396         weekday = 0
397         for x in (0, 1, 2, 3, 4, 5, 6):
398                 day.append(0)
399         begin = self.timer.begin
400         end = self.timer.end
401         weekday = (int(strftime("%w", localtime(begin))) - 1) % 7
402         day[weekday] = 1
403         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
404                 name = self.timer.name 
405                 description = self.timer.description
406                 self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
407                 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
408                 self.timerentry_name = ConfigText(default = name, visible_width = 50, fixed_size = False)
409         else:
410                 description = self.timer.name 
411                 self.timerentry_justplay = ConfigSelection(choices = [(str(PlaylistEntry.SwitchTimerEntry), _("zap")), (str(PlaylistEntry.recNgrab), _("NGRAB")),(str(PlaylistEntry.recDVR), _("DVR"))], default = str(justplay))
412                 self.timerentry_afterevent = ConfigSelection(choices = [("0", _("do nothing")), (str(PlaylistEntry.doGoSleep), _("go to standby")), (str(PlaylistEntry.doShutdown), _("go to deep standby"))], default = str(afterevent))
413         self.timerentry_description = ConfigText(default = description, visible_width = 50, fixed_size = False)
414         self.timerentry_date = ConfigDateTime(default = begin, formatstring = _("%d.%B %Y"), increment = 86400)
415         self.timerentry_starttime = ConfigClock(default = begin)
416         self.timerentry_endtime = ConfigClock(default = end)
417         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
418                 default = "/hdd/movie/"
419                 if default not in self.Locations:
420                         self.Locations.append(default)
421                 self.timerentry_dirname = ConfigSelection(default = default, choices = self.Locations)
422         self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
423         self.timerentry_day = ConfigSubList()
424         for x in (0, 1, 2, 3, 4, 5, 6):
425                 self.timerentry_day.append(ConfigYesNo(default = day[x]))
426         # FIXME some service-chooser needed here
427         servicename = "N/A"
428         try: # no current service available?
429                 servicename = str(self.timer.service_ref.getServiceName())
430         except:
431                 pass
432         self.timerentry_service_ref = self.timer.service_ref
433         self.timerentry_service = ConfigSelection([servicename])
434
435 def RemoteTimerCreateSetup(self, widget):
436         self.list = []
437         self.timerRemoteEntry = getConfigListEntry(self.display, self.timerentry_remote)
438         self.list.append(self.timerRemoteEntry)
439         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
440                 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
441         self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
442         self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
443         self.list.append(self.timerJustplayEntry)
444         self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
445         self.list.append(self.entryDate)
446         self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
447         self.list.append(self.entryStartTime)
448         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
449                 if self.timerentry_justplay.value != "zap":
450                         self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
451                         self.list.append(self.entryEndTime)
452                 else:
453                         self.entryEndTime = None
454         else:
455                 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
456                 self.list.append(self.entryEndTime)
457         self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
458         self.list.append(self.channelEntry)
459         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
460                 self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
461                 if self.timerentry_justplay.value != "zap":
462                         self.list.append(self.dirname)
463                         self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
464         else:
465                 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
466         self[widget].list = self.list
467         self[widget].l.setList(self.list)
468
469 def RemoteTimerGo(self):
470         if int(self.timerentry_remote.value) == 0:
471                 baseTimerEntryGo(self)
472         else:
473                 service_ref = self.timerentry_service_ref
474                 descr = urllib.quote(self.timerentry_description.value)
475                 begin, end = self.getBeginEnd()
476                 ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
477                 port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
478                 http = "http://%s:%d" % (ip,port)
479                 if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 1:
480                         # E1
481                         afterevent = self.timerentry_afterevent.value
482                         justplay = int(self.timerentry_justplay.value)
483                         if justplay & PlaylistEntry.SwitchTimerEntry:
484                                 action = "zap"
485                         elif justplay & PlaylistEntry.recNgrab:
486                                 action = "ngrab"
487                         else:
488                                 action = ""
489                         # FIXME some service-chooser needed here
490                         servicename = "N/A"
491                         try: # no current service available?
492                                 servicename = str(service_ref .getServiceName())
493                         except:
494                                 pass
495                         channel = urllib.quote(servicename)
496                         sCommand = "%s/addTimerEvent?ref=%s&start=%d&duration=%d&descr=%s&channel=%s&after_event=%s&action=%s" % (http, service_ref , begin, end - begin, descr, channel, afterevent, action)
497                         sendPartnerBoxWebCommand(sCommand, None,3, "root", str(self.entryguilist[int(self.timerentry_remote.value)][2].password.value)).addCallback(boundFunction(AddTimerE1Callback,self, self.session)).addErrback(boundFunction(AddTimerError,self, self.session))
498                 else:
499                         # E2
500                         name = urllib.quote(self.timerentry_name.value)
501                         self.timer.tags = self.timerentry_tags
502                         if self.timerentry_justplay.value == "zap":
503                                 justplay = 1
504                                 dirname = ""
505                         else:
506                                 justplay = 0
507                                 dirname = urllib.quote(self.timerentry_dirname.value)
508                         afterevent = {
509                         "deepstandby": AFTEREVENT.DEEPSTANDBY,
510                         "standby": AFTEREVENT.STANDBY,
511                         }.get(self.timerentry_afterevent.value, AFTEREVENT.NONE)
512                         sCommand = "%s/web/timeradd?sRef=%s&begin=%d&end=%d&name=%s&description=%s&dirname=%s&eit=0&justplay=%d&afterevent=%s" % (http, service_ref,begin,end,name,descr,dirname,justplay,afterevent)
513                         sendPartnerBoxWebCommand(sCommand, None,3, "root", str(self.entryguilist[int(self.timerentry_remote.value)][2].password.value)).addCallback(boundFunction(AddTimerE2Callback,self, self.session)).addErrback(boundFunction(AddTimerError,self,self.session))
514
515 def AddTimerE2Callback(self, session, answer):
516         text = ""
517         try: root = xml.etree.cElementTree.fromstring(answer)
518         except: pass
519         statetext = root.findtext("e2statetext")
520         if statetext:
521                 text =  statetext.encode("utf-8", 'ignore')
522         ok = text == "Timer added successfully!"
523         session.open(MessageBox,_("Partnerbox Answer: \n%s") % (text),MessageBox.TYPE_INFO, timeout = 3)
524         if ok:
525                 if (config.plugins.Partnerbox.enablepartnerboxepglist.value): 
526                         # Timerlist der Partnerbox neu laden --> Anzeige fuer EPGList, aber nur, wenn die gleiche IP in EPGList auch angezeigt wird
527                         if partnerboxfunctions.CurrentIP == self.entryguilist[int(self.timerentry_remote.value)][2].ip.value:
528                                 SetPartnerboxTimerlist(self.entryguilist[int(self.timerentry_remote.value)][2])
529                 self.keyCancel()
530
531 def AddTimerE1Callback(self, session, answer):
532         ok = answer == "Timer event was created successfully."
533         session.open(MessageBox,_("Partnerbox Answer: \n%s") % (answer),MessageBox.TYPE_INFO, timeout = 3)
534         if ok:
535                 if (config.plugins.Partnerbox.enablepartnerboxepglist.value): 
536                         # Timerlist der Partnerbox neu laden --> Anzeige fuer EPGList, aber nur, wenn die gleiche IP in EPGList auch angezeigt wird
537                         if partnerboxfunctions.CurrentIP == self.entryguilist[int(self.timerentry_remote.value)][2].ip.value:
538                                 SetPartnerboxTimerlist(self.entryguilist[int(self.timerentry_remote.value)][2])
539                 self.keyCancel()
540                 
541 def AddTimerError(self, session, error):
542         session.open(MessageBox,str(error.getErrorMessage()),MessageBox.TYPE_INFO)
543