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