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