check for success e2state in xml-result instead of e2statetext after adding a timer
[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 == "None": default = "/hdd/movie/"
141                         if default not in self.Locations:
142                                 self.Locations.append(default)
143                         self.timerentry_dirname = ConfigSelection(default = default, choices = self.Locations)
144                 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
145                 self.timerentry_day = ConfigSubList()
146                 for x in (0, 1, 2, 3, 4, 5, 6):
147                         self.timerentry_day.append(ConfigYesNo(default = day[x]))
148                 servicename = self.timer.servicename
149                 self.timerentry_service = ConfigSelection([servicename])
150
151         def createSetup(self, widget):
152                 self.list = []
153                 if self.timer.type == 0:
154                         self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
155                 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
156                 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
157                 self.list.append(self.timerJustplayEntry)
158                 self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
159                 self.list.append(self.entryDate)
160                 self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
161                 self.list.append(self.entryStartTime)
162                 if self.timer.type == 0:
163                         if int(self.timerentry_justplay.value) != 1:
164                                 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
165                                 self.list.append(self.entryEndTime)
166                         else:
167                                 self.entryEndTime = None
168                 else:
169                         self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
170                         self.list.append(self.entryEndTime)
171                 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
172                 self.list.append(self.channelEntry)
173                 if self.timer.type == 0:
174                         self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
175                         if int(self.timerentry_justplay.value) != 1:
176                                 self.list.append(self.dirname)
177                                 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
178                 else:
179                         self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
180                 self[widget].list = self.list
181                 self[widget].l.setList(self.list)
182                 
183         def newConfig(self):
184                 if self["config"].getCurrent() == self.timerJustplayEntry:
185                         self.createSetup("config")
186                         
187         def keyLeft(self):
188                 ConfigListScreen.keyLeft(self)
189                 self.newConfig()
190
191         def keyRight(self):
192                 ConfigListScreen.keyRight(self)
193                 self.newConfig()
194                 
195         def getTimestamp(self, date, mytime):
196                 d = localtime(date)
197                 dt = datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
198                 return int(mktime(dt.timetuple()))
199
200         def getBeginEnd(self):
201                 date = self.timerentry_date.value
202                 endtime = self.timerentry_endtime.value
203                 starttime = self.timerentry_starttime.value
204                 begin = self.getTimestamp(date, starttime)
205                 end = self.getTimestamp(date, endtime)
206                 if end < begin:
207                         end += 86400
208                 return begin, end
209
210         def keyCancel(self):
211                 self.close((False,))
212                 
213         def keyGo(self):
214                 if self.timer.type == 0:
215                         self.timer.name = self.timerentry_name.value
216                         self.timer.dirname = self.timerentry_dirname.value
217                         self.timer.afterevent = {
218                         "nothing": 0,
219                         "deepstandby": 2,
220                         "standby": 1,
221                         "auto": 3
222                         }[self.timerentry_afterevent.value]
223                 else:
224                         self.timer.afterevent = int(self.timerentry_afterevent.value)
225                 self.timer.description = self.timerentry_description.value
226                 self.timer.justplay = int(self.timerentry_justplay.value)
227                 
228                 self.timer.timebegin, self.timer.timeend = self.getBeginEnd()
229                 self.close((True, self.timer))
230
231         def incrementStart(self):
232                 self.timerentry_starttime.increment()
233                 self["config"].invalidate(self.entryStartTime)
234
235         def decrementStart(self):
236                 self.timerentry_starttime.decrement()
237                 self["config"].invalidate(self.entryStartTime)
238
239         def incrementEnd(self):
240                 if self.entryEndTime is not None:
241                         self.timerentry_endtime.increment()
242                         self["config"].invalidate(self.entryEndTime)
243
244         def decrementEnd(self):
245                 if self.entryEndTime is not None:
246                         self.timerentry_endtime.decrement()
247                         self["config"].invalidate(self.entryEndTime)
248                         
249                         
250                         
251 # ##########################################
252 # TimerEntry
253 # ##########################################
254 baseTimerEntrySetup = None
255 baseTimerEntryGo = None
256 baseTimerEntrynewConfig = None
257 baseTimerkeyLeft = None
258 baseTimerkeyRight = None
259 baseTimerkeySelect = None
260 baseTimercreateConfig = None
261
262 def RemoteTimerInit():
263         global baseTimerEntrySetup, baseTimerEntryGo, baseTimerEntrynewConfig, baseTimerkeyLeft, baseTimerkeyRight, baseTimerkeySelect, baseTimercreateConfig
264         if baseTimerEntrySetup is None:
265                 baseTimerEntrySetup = TimerEntry.createSetup
266         if baseTimerEntryGo is None:
267                 baseTimerEntryGo = TimerEntry.keyGo
268         if baseTimerEntrynewConfig is None:
269                 baseTimerEntrynewConfig = TimerEntry.newConfig
270         if baseTimerkeyLeft is None:
271                 baseTimerkeyLeft = TimerEntry.keyLeft
272         if baseTimerkeyRight is None:
273                 baseTimerkeyRight = TimerEntry.keyRight
274         if baseTimerkeySelect is None:
275                 baseTimerkeySelect = TimerEntry.keySelect
276         if baseTimercreateConfig is None:
277                 baseTimercreateConfig  = TimerEntry.createConfig
278         
279         TimerEntry.createConfig = RemoteTimerConfig
280         TimerEntry.keyLeft = RemoteTimerkeyLeft 
281         TimerEntry.keyRight = RemoteTimerkeyRight
282         TimerEntry.keySelect = RemoteTimerkeySelect
283         TimerEntry.createSetup = createRemoteTimerSetup
284         TimerEntry.keyGo = RemoteTimerGo
285         TimerEntry.newConfig = RemoteTimernewConfig
286         
287 def RemoteTimerConfig(self):
288         self.Locations = []
289         self.entryguilist = []
290         self.entryguilist.append(("0",_("No"),None))
291         index = 1
292         for c in config.plugins.Partnerbox.Entries:
293                 self.entryguilist.append((str(index),str(c.name.value),c))
294                 index = index + 1
295         self.timerentry_remote = ConfigSelection(default = "0", choices = self.entryguilist)
296         baseTimercreateConfig(self)
297
298 #def getLocationsError(self, error):
299 #       RemoteTimercreateConfig(self)
300 #       RemoteTimerCreateSetup(self,"config")
301         
302 def getLocationsCallback(self, xmlstring):
303         self.Locations = []
304         try: root = xml.etree.cElementTree.fromstring(xmlstring)
305         except: return 
306         for location in root.findall("e2location"):
307                 self.Locations.append(location.text.encode("utf-8", 'ignore'))
308         for location in root.findall("e2simplexmlitem"):  # vorerst Kompatibilitaet zum alten Webinterface-Api aufrecht erhalten (e2simplexmlitem)
309                 self.Locations.append(location.text.encode("utf-8", 'ignore'))
310                 
311 def createRemoteTimerSetup(self, widget):
312         baseTimerEntrySetup(self, widget)
313         self.display = _("Remote Timer")
314         self.timerRemoteEntry = getConfigListEntry(self.display, self.timerentry_remote)
315         self.list.insert(0, self.timerRemoteEntry)
316         self[widget].list = self.list
317         
318 def RemoteTimerkeyLeft(self):
319         if int(self.timerentry_remote.value) != 0:
320                 ConfigListScreen.keyLeft(self)
321                 RemoteTimernewConfig(self)
322         else:
323                 baseTimerkeyLeft(self)
324
325 def RemoteTimerkeyRight(self):
326         if int(self.timerentry_remote.value) != 0:
327                 ConfigListScreen.keyRight(self)
328                 RemoteTimernewConfig(self)
329         else:
330                 baseTimerkeyRight(self)
331
332 def RemoteTimerkeySelect(self):
333         if int(self.timerentry_remote.value) != 0:
334                 RemoteTimerGo(self)
335         else:
336                 baseTimerkeySelect(self)
337         
338         
339 def RemoteTimernewConfig(self):
340         if self["config"].getCurrent() == self.timerRemoteEntry:
341                 if int(self.timerentry_remote.value) != 0:
342                         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 1: # E1
343                                 self.timertype = PlaylistEntry.RecTimerEntry|PlaylistEntry.recDVR
344                         else: # E2
345                                 self.timertype = 0
346                                 ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
347                                 port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
348                                 http_ = "%s:%d" % (ip,port)
349                                 sCommand = "http://root:" + self.entryguilist[int(self.timerentry_remote.value)][2].password.value + "@" + http_ + "/web/getlocations"
350                                 #sCommand = self.http + "/web/getlocations"
351                                 #sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(boundFunction(getLocationsCallback,self)).addErrback(boundFunction(getLocationsError,self))
352                                 # ich mach das besser synchron, falls die Partnerbox aus ist ( dann koennte man hier schon abbrechen und eine Meldung bringen...)
353                                 try:
354                                         f = urllib.urlopen(sCommand)
355                                         sxml = f.read()
356                                         getLocationsCallback(self,sxml)
357                                 except: pass
358                         RemoteTimercreateConfig(self)
359                         RemoteTimerCreateSetup(self,"config")
360                 else:
361                         baseTimercreateConfig(self)
362                         createRemoteTimerSetup(self, "config")
363         elif self["config"].getCurrent() == self.timerJustplayEntry:
364                 if int(self.timerentry_remote.value) != 0:
365                         RemoteTimerCreateSetup(self,"config")
366                 else:
367                         baseTimerEntrynewConfig(self)
368         else:
369                         if int(self.timerentry_remote.value) == 0:
370                                 baseTimerEntrynewConfig(self)
371         
372 def  RemoteTimercreateConfig(self):
373         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
374                 justplay = self.timer.justplay
375                 afterevent = {
376                         AFTEREVENT.NONE: "nothing",
377                         AFTEREVENT.DEEPSTANDBY: "deepstandby",
378                          AFTEREVENT.STANDBY: "standby",
379                          AFTEREVENT.AUTO: "auto"
380                         }[self.timer.afterEvent]
381         else:
382                 if self.timertype & PlaylistEntry.doShutdown:
383                         afterevent = PlaylistEntry.doShutdown
384                 elif self.timertype & PlaylistEntry.doGoSleep:
385                         afterevent = PlaylistEntry.doGoSleep
386                 else:
387                         afterevent = 0
388                 if self.timertype & PlaylistEntry.RecTimerEntry:
389                         if self.timertype & PlaylistEntry.recDVR:
390                                 justplay = PlaylistEntry.recDVR
391                         elif self.timertype & PlaylistEntry.recNgrab:
392                                 justplay = PlaylistEntry.recNgrab
393                 elif self.timertype & PlaylistEntry.SwitchTimerEntry:
394                         justplay = PlaylistEntry.SwitchTimerEntry
395         weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
396         day = []
397         weekday = 0
398         for x in (0, 1, 2, 3, 4, 5, 6):
399                 day.append(0)
400         begin = self.timer.begin
401         end = self.timer.end
402         weekday = (int(strftime("%w", localtime(begin))) - 1) % 7
403         day[weekday] = 1
404         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
405                 name = self.timer.name 
406                 description = self.timer.description
407                 self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
408                 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
409                 self.timerentry_name = ConfigText(default = name, visible_width = 50, fixed_size = False)
410         else:
411                 description = self.timer.name 
412                 self.timerentry_justplay = ConfigSelection(choices = [(str(PlaylistEntry.SwitchTimerEntry), _("zap")), (str(PlaylistEntry.recNgrab), _("NGRAB")),(str(PlaylistEntry.recDVR), _("DVR"))], default = str(justplay))
413                 self.timerentry_afterevent = ConfigSelection(choices = [("0", _("do nothing")), (str(PlaylistEntry.doGoSleep), _("go to standby")), (str(PlaylistEntry.doShutdown), _("go to deep standby"))], default = str(afterevent))
414         self.timerentry_description = ConfigText(default = description, visible_width = 50, fixed_size = False)
415         self.timerentry_date = ConfigDateTime(default = begin, formatstring = _("%d.%B %Y"), increment = 86400)
416         self.timerentry_starttime = ConfigClock(default = begin)
417         self.timerentry_endtime = ConfigClock(default = end)
418         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
419                 default = "/hdd/movie/"
420                 if default not in self.Locations:
421                         self.Locations.append(default)
422                 self.timerentry_dirname = ConfigSelection(default = default, choices = self.Locations)
423         self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
424         self.timerentry_day = ConfigSubList()
425         for x in (0, 1, 2, 3, 4, 5, 6):
426                 self.timerentry_day.append(ConfigYesNo(default = day[x]))
427         # FIXME some service-chooser needed here
428         servicename = "N/A"
429         try: # no current service available?
430                 servicename = str(self.timer.service_ref.getServiceName())
431         except:
432                 pass
433         self.timerentry_service_ref = self.timer.service_ref
434         self.timerentry_service = ConfigSelection([servicename])
435
436 def RemoteTimerCreateSetup(self, widget):
437         self.list = []
438         self.timerRemoteEntry = getConfigListEntry(self.display, self.timerentry_remote)
439         self.list.append(self.timerRemoteEntry)
440         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
441                 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
442         self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
443         self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
444         self.list.append(self.timerJustplayEntry)
445         self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
446         self.list.append(self.entryDate)
447         self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
448         self.list.append(self.entryStartTime)
449         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
450                 if self.timerentry_justplay.value != "zap":
451                         self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
452                         self.list.append(self.entryEndTime)
453                 else:
454                         self.entryEndTime = None
455         else:
456                 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
457                 self.list.append(self.entryEndTime)
458         self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
459         self.list.append(self.channelEntry)
460         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
461                 self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
462                 if self.timerentry_justplay.value != "zap":
463                         self.list.append(self.dirname)
464                         self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
465         else:
466                 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
467         self[widget].list = self.list
468         self[widget].l.setList(self.list)
469
470 def RemoteTimerGo(self):
471         if int(self.timerentry_remote.value) == 0:
472                 baseTimerEntryGo(self)
473         else:
474                 service_ref = self.timerentry_service_ref
475                 descr = urllib.quote(self.timerentry_description.value)
476                 begin, end = self.getBeginEnd()
477                 ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
478                 port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
479                 http = "http://%s:%d" % (ip,port)
480                 if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 1:
481                         # E1
482                         afterevent = self.timerentry_afterevent.value
483                         justplay = int(self.timerentry_justplay.value)
484                         if justplay & PlaylistEntry.SwitchTimerEntry:
485                                 action = "zap"
486                         elif justplay & PlaylistEntry.recNgrab:
487                                 action = "ngrab"
488                         else:
489                                 action = ""
490                         # FIXME some service-chooser needed here
491                         servicename = "N/A"
492                         try: # no current service available?
493                                 servicename = str(service_ref .getServiceName())
494                         except:
495                                 pass
496                         channel = urllib.quote(servicename)
497                         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)
498                         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))
499                 else:
500                         # E2
501                         name = urllib.quote(self.timerentry_name.value)
502                         self.timer.tags = self.timerentry_tags
503                         if self.timerentry_justplay.value == "zap":
504                                 justplay = 1
505                                 dirname = ""
506                         else:
507                                 justplay = 0
508                                 dirname = urllib.quote(self.timerentry_dirname.value)
509                         afterevent = {
510                         "deepstandby": AFTEREVENT.DEEPSTANDBY,
511                         "standby": AFTEREVENT.STANDBY,
512                         }.get(self.timerentry_afterevent.value, AFTEREVENT.NONE)
513                         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)
514                         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))
515
516 def AddTimerE2Callback(self, session, answer):
517         text = ""
518         try: root = xml.etree.cElementTree.fromstring(answer)
519         except: pass
520         statetext = root.findtext("e2statetext")
521         state = root.findtext("e2state")
522         if statetext:
523                 text =  statetext.encode("utf-8", 'ignore')
524         ok = state == "True"
525         session.open(MessageBox,_("Partnerbox Answer: \n%s") % (text),MessageBox.TYPE_INFO, timeout = 3)
526         if ok:
527                 if (config.plugins.Partnerbox.enablepartnerboxepglist.value): 
528                         # Timerlist der Partnerbox neu laden --> Anzeige fuer EPGList, aber nur, wenn die gleiche IP in EPGList auch angezeigt wird
529                         if partnerboxfunctions.CurrentIP == self.entryguilist[int(self.timerentry_remote.value)][2].ip.value:
530                                 SetPartnerboxTimerlist(self.entryguilist[int(self.timerentry_remote.value)][2])
531                 self.keyCancel()
532
533 def AddTimerE1Callback(self, session, answer):
534         ok = answer == "Timer event was created successfully."
535         session.open(MessageBox,_("Partnerbox Answer: \n%s") % (answer),MessageBox.TYPE_INFO, timeout = 3)
536         if ok:
537                 if (config.plugins.Partnerbox.enablepartnerboxepglist.value): 
538                         # Timerlist der Partnerbox neu laden --> Anzeige fuer EPGList, aber nur, wenn die gleiche IP in EPGList auch angezeigt wird
539                         if partnerboxfunctions.CurrentIP == self.entryguilist[int(self.timerentry_remote.value)][2].ip.value:
540                                 SetPartnerboxTimerlist(self.entryguilist[int(self.timerentry_remote.value)][2])
541                 self.keyCancel()
542                 
543 def AddTimerError(self, session, error):
544         session.open(MessageBox,str(error.getErrorMessage()),MessageBox.TYPE_INFO)
545