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