bug "invalid literal for int() with base 10: 'None'" fixed...
[enigma2-plugins.git] / partnerbox / src / plugin.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 Plugins.Plugin import PluginDescriptor
21 from Screens.Screen import Screen
22 from Screens.MessageBox import MessageBox
23 from Screens.ChoiceBox import ChoiceBox
24 from Components.config import config
25 from Components.ScrollLabel import ScrollLabel
26 from Components.ActionMap import ActionMap, NumberActionMap
27 from Components.MenuList import MenuList
28 from Components.Label import Label
29 from Components.EpgList import Rect
30 from enigma import eServiceReference
31 from enigma import eListboxPythonMultiContent, eListbox, gFont, \
32         RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_CENTER
33 from Tools.LoadPixmap import LoadPixmap
34 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
35 from Tools.FuzzyDate import FuzzyTime
36 from timer import TimerEntry
37 from enigma import eTimer
38 from time import localtime
39 import time
40 import xml.dom.minidom
41 import urllib
42 import SocketServer
43 import servicewebts
44 ENIGMA_WEBSERVICE_ID = 0x1012
45 from Screens.InfoBarGenerics import InfoBarAudioSelection
46 from RemoteTimerEntry import RemoteTimerEntry, PlaylistEntry, RemoteTimerInit, sendPartnerBoxWebCommand
47 import time
48
49 from Services import Services, E2EPGListAllData, E2ServiceList
50 from Screens.ChannelSelection import service_types_tv
51
52 from Components.ConfigList import ConfigList, ConfigListScreen
53 from Components.config import ConfigSubsection, ConfigIP, ConfigInteger, ConfigSelection, ConfigText, ConfigYesNo, getConfigListEntry, configfile
54
55 config.plugins.partnerbox = ConfigSubsection()
56 config.plugins.partnerbox.ip = ConfigIP(default = [192,168,0,98])
57 config.plugins.partnerbox.port = ConfigInteger(default=80, limits=(1, 65555))
58 config.plugins.partnerbox.enigma = ConfigSelection(default="0", choices = [("0", _("Enigma 2")),("1", _("Enigma 1"))])
59 config.plugins.partnerbox.password = ConfigText(default = "dreambox", visible_width = 50, fixed_size = False)
60 config.plugins.partnerbox.useinternal = ConfigSelection(default="1", choices = [("0", _("use external")),("1", _("use internal"))])
61 config.plugins.partnerbox.showremotetvinextensionsmenu= ConfigYesNo(default = True)
62 config.plugins.partnerbox.showcurrentstreaminextensionsmenu= ConfigYesNo(default = True)
63 config.plugins.partnerbox.showremotetimerinextensionsmenu= ConfigYesNo(default = True)
64 config.plugins.partnerbox.enablepartnerboxintimerevent = ConfigYesNo(default = False)
65
66 def autostart(reason, **kwargs):
67         if "session" in kwargs:
68                 session = kwargs["session"]
69                 try:
70                         RemoteTimerInit()
71                 except: pass
72
73 def main(session,**kwargs):
74         session.open(RemoteTimer)
75
76 def setup(session,**kwargs):
77         session.open(PartnerboxSetup)
78
79 def currentremotetv(session,**kwargs):
80         session.open(CurrentRemoteTV)
81         
82 def remotetvplayer(session,**kwargs):
83
84         useinternal = int(config.plugins.partnerbox.useinternal.value)
85         password = config.plugins.partnerbox.password.value
86         username = "root"
87         ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
88         port = config.plugins.partnerbox.port.value
89         http = "http://%s:%d" % (ip,port)
90         enigma_type = int(config.plugins.partnerbox.enigma.value)
91         E2TimerList = []
92         session.open(RemoteTimerBouquetList, E2TimerList, username,password, http, enigma_type, useinternal, 1)
93
94 def Plugins(**kwargs):
95         list = [PluginDescriptor(name="Partnerbox: RemoteTimer", description=_("Manage timer for other dreamboxes in network"), 
96                 where = [PluginDescriptor.WHERE_EVENTINFO ], fnc=main)]
97         if config.plugins.partnerbox.enablepartnerboxintimerevent.value:
98                 list.append(PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = autostart))
99         list.append(PluginDescriptor(name="Setup Partnerbox", description=_("setup for partnerbox"), where = [PluginDescriptor.WHERE_PLUGINMENU], fnc=setup))
100         if config.plugins.partnerbox.showremotetimerinextensionsmenu:
101                 list.append(PluginDescriptor(name="Partnerbox: RemoteTimer", description=_("Manage timer for other dreamboxes in network"), 
102                 where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc=main))
103         if config.plugins.partnerbox.showremotetvinextensionsmenu.value:
104                 list.append(PluginDescriptor(name="Partnerbox: RemoteTV Player", description=_("Stream TV from your Partnerbox"), where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc=remotetvplayer))
105         if config.plugins.partnerbox.showcurrentstreaminextensionsmenu.value:
106                 list.append(PluginDescriptor(name="Stream current Service from Partnerbox", description=_("Stream current service from partnerbox"), where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc=currentremotetv))
107         
108         return list
109                         
110 def getTimerType(refstr, beginTime, duration, eventId, timer_list):
111         pre = 1
112         post = 2
113         type = 0
114         endTime = beginTime + duration
115         for x in timer_list:
116                 if x.servicereference.upper() == refstr.upper():
117                         if x.eventId == eventId:
118                                 return True
119                         beg = x.timebegin
120                         end = x.timeend
121                         if beginTime > beg and beginTime < end and endTime > end:
122                                 type |= pre
123                         elif beginTime < beg and endTime > beg and endTime < end:
124                                 type |= post
125         if type == 0:
126                 return True
127         elif type == pre:
128                 return False
129         elif type == post:
130                 return False
131         else:
132                 return True
133
134 def isInTimerList(begin, duration, service, eventid, timer_list):
135         time_match = 0
136         chktime = None
137         chktimecmp = None
138         chktimecmp_end = None
139         end = begin + duration
140         timerentry = None
141         for x in timer_list:
142                 if x.servicereference.upper() == service.upper():
143                         if x.repeated != 0:
144                                 if chktime is None:
145                                         chktime = localtime(begin)
146                                         chktimecmp = chktime.tm_wday * 1440 + chktime.tm_hour * 60 + chktime.tm_min
147                                         chktimecmp_end = chktimecmp + (duration / 60)
148                                 time = localtime(x.timebegin)
149                                 for y in range(7):
150                                         if x.repeated & (2 ** y):
151                                                 timecmp = y * 1440 + time.tm_hour * 60 + time.tm_min
152                                                 if timecmp <= chktimecmp < (timecmp + ((x.timeend - x.timebegin) / 60)):
153                                                         time_match = ((timecmp + ((x.timeend - x.timebegin) / 60)) - chktimecmp) * 60
154                                                 elif chktimecmp <= timecmp < chktimecmp_end:
155                                                         time_match = (chktimecmp_end - timecmp) * 60
156                         else: 
157                                 if begin <= x.timebegin <= end:
158                                         diff = end - x.timebegin
159                                         if time_match < diff:
160                                                 time_match = diff
161                                 elif x.timebegin <= begin <= x.timeend:
162                                         diff = x.timeend - begin
163                                         if time_match < diff:
164                                                 time_match = diff
165                         if time_match:
166                                 if getTimerType(service, begin, duration, eventid, timer_list):
167                                         timerentry = x
168                                 break
169         return timerentry
170
171 def FillE2TimerList(xmlstring):
172         E2TimerList = []
173         dom = xml.dom.minidom.parseString(xmlstring)
174         for node in dom.firstChild.childNodes:
175                 servicereference = ""
176                 servicename = ""
177                 name = ""
178                 disabled = 0
179                 timebegin = 0
180                 timeend = 0
181                 duration = 0
182                 startprepare = 0
183                 state = 0
184                 repeated = 0
185                 justplay = 0
186                 eventId = -1
187                 afterevent = 0
188                 dirname = ""
189                 description = ""
190                 if node.nodeName == "e2timer":
191                         for node2 in node.childNodes:
192                                 if node2.nodeName == "e2servicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
193                                 if node2.nodeName == "e2servicename":
194                                         try:servicename = str(node2.firstChild.data.strip().encode("utf-8"))
195                                         except:servicename = "n/a"
196                                 if node2.nodeName == "e2eit": eventId = int(node2.firstChild.data.strip())
197                                 if node2.nodeName == "e2name":
198                                         try:name = str(node2.firstChild.data.strip().encode("utf-8"))
199                                         except:name = ""
200                                 if node2.nodeName == "e2description":
201                                         try:description = str(node2.firstChild.data.strip().encode("utf-8"))
202                                         except:description = ""
203                                 if node2.nodeName == "e2dirname":
204                                         try:dirname = str(node2.firstChild.data.strip().encode("utf-8"))
205                                         except:dirname = ""
206                                 if node2.nodeName == "e2afterevent": afterevent = int(node2.firstChild.data.strip())
207                                 if node2.nodeName == "e2disabled": disabled = int(node2.firstChild.data.strip())
208                                 if node2.nodeName == "e2timebegin": timebegin = int(node2.firstChild.data.strip())
209                                 if node2.nodeName == "e2timeend": timeend = int(node2.firstChild.data.strip())
210                                 if node2.nodeName == "e2duration": duration = int(node2.firstChild.data.strip())
211                                 if node2.nodeName == "e2startprepare": startprepare = int(node2.firstChild.data.strip())
212                                 if node2.nodeName == "e2state":  state= int(node2.firstChild.data.strip())
213                                 if node2.nodeName == "e2justplay":  justplay= int(node2.firstChild.data.strip())
214                                 if node2.nodeName == "e2repeated":
215                                         repeated= int(node2.firstChild.data.strip())
216                                         E2TimerList.append(E2Timer(servicereference = servicereference, servicename = servicename, name = name, disabled = disabled, timebegin = timebegin, timeend = timeend, duration = duration, startprepare = startprepare, state = state , repeated = repeated, justplay= justplay, eventId = eventId, afterevent = afterevent, dirname = dirname, description = description, type = 0 ))
217         return E2TimerList
218
219 def FillE1TimerList(xmlstring):
220         E1TimerList = []
221         dom = xml.dom.minidom.parseString(xmlstring)
222         for node in dom.firstChild.childNodes:
223                 type = 0
224                 servicereference = ""
225                 servicename = ""
226                 name = ""
227                 disabled = 0
228                 timebegin = 0
229                 timeend = 0
230                 duration = 0
231                 startprepare = 0
232                 state = 0
233                 repeated = 0
234                 justplay = 0
235                 eventId = -1
236                 afterevent = 0
237                 dirname = ""
238                 description = ""
239                 if node.nodeName == "timer":
240                         for node2 in node.childNodes:
241                                 if node2.nodeName == "typedata": type = int(node2.firstChild.data.strip())
242                                 if node2.nodeName == "service":
243                                         for node3 in node2.childNodes:
244                                                 if node3.nodeName == "reference": servicereference = str(node3.firstChild.data.strip().encode("utf-8"))
245                                                 if node3.nodeName == "name":
246                                                         try:servicename = str(node3.firstChild.data.strip().encode("utf-8"))
247                                                         except:servicename = "n/a"
248                                 if node2.nodeName == "event":
249                                         for node3 in node2.childNodes:
250                                                 if node3.nodeName == "start": timebegin = int(node3.firstChild.data.strip())
251                                                 if node3.nodeName == "duration": duration = int(node3.firstChild.data.strip())
252                                                 if node3.nodeName == "description":
253                                                         try:description = str(node3.firstChild.data.strip().encode("utf-8"))
254                                                         except:description = ""
255                                                         E1TimerList.append(E2Timer(servicereference = servicereference, servicename = servicename, name = name, disabled = disabled, timebegin = timebegin, timeend = timeend, duration = duration, startprepare = startprepare, state = state , repeated = repeated, justplay= justplay, eventId = eventId, afterevent = afterevent, dirname = dirname, description = description, type = type ))
256         return E1TimerList
257
258 class E2Timer:
259         def __init__(self, servicereference = "", servicename = "", name = "", disabled = 0, timebegin = 0, timeend = 0, duration = 0, startprepare = 0, state = 0, repeated = 0, justplay = 0, eventId = 0, afterevent = 0, dirname = "", description = "", type = 0):
260                 self.servicereference = servicereference
261                 self.servicename = servicename
262                 self.name = name
263                 self.disabled = disabled
264                 self.timebegin = timebegin
265                 self.timeend = timeend
266                 self.duration = duration
267                 self.startprepare = startprepare
268                 self.state = state
269                 self.repeated = repeated
270                 self.justplay = justplay
271                 self.eventId = eventId
272                 self.afterevent = afterevent
273                 self.dirname = dirname
274                 self.description = description
275                 self.type = type
276                 if type != 0: # E1 Timerlist
277                         self.timeend = timebegin + duration
278                         self.name = description
279                         if type & PlaylistEntry.isRepeating:
280                                 self.repeated = 1
281                         self.dirname = "/hdd/movie/"
282                 
283 def FillLocationList(xmlstring):
284         Locations = []
285         dom = xml.dom.minidom.parseString(xmlstring)
286         for node in dom.firstChild.childNodes:
287                 dirname = ""
288                 if node.nodeName == "e2simplexmlitem":
289                         dirname = str(node.firstChild.data.strip().encode("utf-8"))
290                         Locations.append(dirname)
291         return Locations
292                 
293
294 class PartnerboxSetup(ConfigListScreen, Screen):
295         skin = """
296                 <screen position="100,100" size="550,400" title="Partnerbox Setup" >
297                 <widget name="config" position="20,10" size="510,380" scrollbarMode="showOnDemand" />
298                 </screen>"""
299
300         def __init__(self, session, args = None):
301                 Screen.__init__(self, session)
302                 self.list = [ ]
303                 self.list.append(getConfigListEntry(_("IP:"), config.plugins.partnerbox.ip))
304                 self.list.append(getConfigListEntry(_("Port:"), config.plugins.partnerbox.port))
305                 self.list.append(getConfigListEntry(_("Enigma Type:"), config.plugins.partnerbox.enigma))
306                 self.list.append(getConfigListEntry(_("Password:"), config.plugins.partnerbox.password))
307                 self.list.append(getConfigListEntry(_("Servicelists/EPG:"), config.plugins.partnerbox.useinternal))
308                 self.list.append(getConfigListEntry(_("Show 'RemoteTimer' in E-Menu:"), config.plugins.partnerbox.showremotetimerinextensionsmenu))
309                 self.list.append(getConfigListEntry(_("Show 'RemoteTV Player' in E-Menu:"), config.plugins.partnerbox.showremotetvinextensionsmenu))
310                 self.list.append(getConfigListEntry(_("Show 'Stream current Service' in E-Menu:"), config.plugins.partnerbox.showcurrentstreaminextensionsmenu))
311                 self.list.append(getConfigListEntry(_("Enable Partnerbox-Function in TimerEvent:"), config.plugins.partnerbox.enablepartnerboxintimerevent))
312                 ConfigListScreen.__init__(self, self.list, session)
313                 self["setupActions"] = ActionMap(["SetupActions"],
314                 {
315                         "save": self.save,
316                         "cancel": self.close,
317                         "ok": self.save,
318                 }, -2)
319
320         def save(self):
321                 ConfigListScreen.keySave(self)
322                 configfile.save()
323                 
324 class CurrentRemoteTV(Screen):
325         skin = """
326                 <screen name="CurrentRemoteTV" position="210,160" size="300,240" title="Remote Player">
327                 <widget name="text" position="10,10" zPosition="1" size="290,225" font="Regular;20" halign="center" valign="center" />
328         </screen>"""
329         def __init__(self, session, args = 0):
330                 self.session = session
331                 Screen.__init__(self, session)
332                 self.CurrentService = self.session.nav.getCurrentlyPlayingServiceReference()
333                 self.useinternal = int(config.plugins.partnerbox.useinternal.value)
334                 self.password = config.plugins.partnerbox.password.value
335                 self.username = "root"
336                 self.ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
337                 port = config.plugins.partnerbox.port.value
338                 self.http = "http://%s:%d" % (self.ip,port)
339                 self.enigma_type = int(config.plugins.partnerbox.enigma.value)
340                 if self.enigma_type == 1:
341                         self.url = self.http + "/video.m3u"
342                 else:
343                         self.url = self.http + "/web/getcurrent"
344                         
345                 tt = "Starting Remote Player (IP = %s)" % (self.ip)
346                 self["text"] = Label(tt)
347                 self.onLayoutFinish.append(self.startRun)
348         
349         def startRun(self):
350                 sendPartnerBoxWebCommand(self.url, None,10, self.username, self.password).addCallback(self.Callback).addErrback(self.Error)
351
352         def Callback(self, xmlstring):
353                 url = ""
354                 servicereference = ""
355                 if self.enigma_type == 0:
356                         dom = xml.dom.minidom.parseString(xmlstring)
357                         for node in dom.firstChild.childNodes:
358                                 if node.nodeName == "e2service":
359                                         for node2 in node.childNodes:
360                                                 if node2.nodeName == "e2servicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
361                         
362                         if len(servicereference) > 0:
363                                 url = "http://" + self.ip + ":8001/" + servicereference
364                         else:
365                                 self.close()
366                 else:
367                         url = xmlstring
368                 if len(url) > 0:
369                         self.session.nav.stopService()
370                         sref = eServiceReference(ENIGMA_WEBSERVICE_ID, 0, url)
371                         self.session.nav.playService(sref)
372                         self.session.openWithCallback(self.RemotePlayerFinished, RemotePlayer,"" ,"", 0, 0, self.password,self.username, servicereference, self.http , self.enigma_type, self.useinternal)
373                 else:
374                         self.close()
375                 
376         def RemotePlayerFinished(self):
377                 self.session.nav.playService(self.CurrentService)
378                 self.close()
379                 
380         def Error(self, error = None):
381                 self.close()
382
383 class RemoteTimer(Screen):
384         skin = """
385                 <screen name="RemoteTimer" position="90,95" size="560,430" title="RemoteTimer Editor">
386                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on"/>
387                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on"/>
388                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on"/>
389                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on"/>
390                         <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1"/>
391                         <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1"/>
392                         <widget name="key_yellow" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1"/>
393                         <widget name="key_blue" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1"/>
394                         <widget name="text" position="0,60" zPosition="1" size="560,350" font="Regular;20" halign="center" valign="center" />
395                         <widget name="timerlist" position="0,60" zPosition="2" size="560,350" scrollbarMode="showOnDemand"/>
396                 </screen>"""
397         
398         timerlist = []
399         def __init__(self, session, args = 0):
400                 self.session = session
401                 Screen.__init__(self, session)
402                 self["timerlist"] = E2TimerMenu([])
403                 self["key_red"] = Label(_("Delete"))
404                 self["key_green"] = Label() # Dummy, kommt eventuell noch was
405                 self["key_yellow"] = Label(_("EPG Selection")) 
406                 self["key_blue"] = Label(_("Clean up"))
407                 self["text"] = Label(_("Getting Partnerbox Information..."))
408                 self.onLayoutFinish.append(self.startRun)
409                 self.E2TimerList = []
410                 self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions", "EPGSelectActions"],
411                 {
412                         "ok": self.getLocations,
413                         "back": self.close,
414                         "yellow": self.EPGList,
415                         "blue": self.cleanupTimer,
416                         "red": self.deleteTimer,
417                         "input_date_time": self.configmenu,
418                 }, -1)
419
420                 self.password = config.plugins.partnerbox.password.value
421                 self.username = "root"
422                 ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
423                 port = config.plugins.partnerbox.port.value
424                 self.http = "http://%s:%d" % (ip,port)
425                 self.enigma_type = int(config.plugins.partnerbox.enigma.value)
426                 self.useinternal = int(config.plugins.partnerbox.useinternal.value)
427
428                 self.oldstart = 0
429                 self.oldend = 0
430                 self.oldtype = 0
431                 self.Locations = []
432                 
433         def getLocations(self):
434                 if self.enigma_type == 0:
435                         sCommand = self.http + "/web/getlocations"
436                         sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(self.getLocationsCallback).addErrback(self.deleteTimerError)
437                 else:
438                         self.addTimer()
439         
440         def getLocationsCallback(self, xmlstring):
441                 self.Locations = []
442                 self.Locations = FillLocationList(xmlstring)
443                 self.addTimer()
444
445         def addTimer(self):
446                 cur = self["timerlist"].getCurrent()
447                 if cur is None:
448                                 return
449                 if cur[0].repeated == 0:
450                         self.oldstart = cur[0].timebegin
451                         self.oldend = cur[0].timeend
452                         self.oldtype = cur[0].type
453                         self.session.openWithCallback(self.RemoteTimerEntryFinished, RemoteTimerEntry,cur[0], self.Locations)
454                 else:
455                         text = "Repeated Timer are not supported!"
456                         self.session.open(MessageBox,text,  MessageBox.TYPE_INFO)
457         
458         def RemoteTimerEntryFinished(self, answer):
459                 if answer[0]:
460                         entry = answer[1]
461                         self["timerlist"].instance.hide()
462                         if self.enigma_type == 0:
463                                 ref_old = "&channelOld=" + urllib.quote(entry.servicereference.decode('utf8').encode('latin-1','ignore')) + "&beginOld=" + ("%s"%(self.oldstart)) + "&endOld=" + ("%s"%(self.oldend))  + "&deleteOldOnSave=1"
464                                 ref = urllib.quote(entry.servicereference.decode('utf8').encode('latin-1','ignore')) + "&begin=" + ("%s"%(entry.timebegin)) + "&end=" + ("%s"%(entry.timeend))  + "&name=" + urllib.quote(entry.name) + "&description=" + urllib.quote(entry.description) + "&dirname=" + urllib.quote(entry.dirname) + "&eit=0&justplay=" + ("%s"%(entry.justplay)) + "&afterevent=" + ("%s"%(entry.afterevent))
465                                 sCommand = self.http + "/web/timerchange?sRef=" + ref + ref_old
466                                 sendPartnerBoxWebCommand(sCommand, None,10, self.username, self.password).addCallback(self.deleteTimerCallback).addErrback(self.downloadError)
467                         else:
468                                 if entry.justplay & PlaylistEntry.SwitchTimerEntry:
469                                         action = "zap"
470                                 elif entry.justplay & PlaylistEntry.recNgrab:
471                                         action = "ngrab"
472                                 else:
473                                         action = ""
474                                 tstart = time.localtime(entry.timebegin)
475                                 tend = time.localtime(entry.timeend)
476                                 ref_time_start = "&sday=" + ("%s"%(tstart.tm_mday)) + "&smonth=" + ("%s"%(tstart.tm_mon)) + "&syear=" + ("%s"%(tstart.tm_year)) + "&shour=" + ("%s"%(tstart.tm_hour)) + "&smin=" + ("%s"%(tstart.tm_min))
477                                 ref_time_end = "&eday=" + ("%s"%(tend.tm_mday)) + "&emonth=" + ("%s"%(tend.tm_mon)) + "&eyear=" + ("%s"%(tend.tm_year)) + "&ehour=" + ("%s"%(tend.tm_hour)) + "&emin=" + ("%s"%(tend.tm_min))
478                                 ref_old = "&old_type=" + ("%s"%(self.oldtype)) + "&old_stime=" + ("%s"%(self.oldstart)) + "&force=yes"
479                                 ref = urllib.quote(entry.servicereference.decode('utf8').encode('latin-1','ignore')) + "&descr=" + urllib.quote(entry.description) + "&channel=" + urllib.quote(entry.servicename) + "&after_event=" + ("%s"%(entry.afterevent)) + "&action=" + ("%s"%(action))
480                                 sCommand = self.http + "/changeTimerEvent?ref=" + ref + ref_old + ref_time_start + ref_time_end
481                                 sendPartnerBoxWebCommand(sCommand, None,10, self.username, self.password).addCallback(self.deleteTimerCallback).addErrback(self.downloadError)
482         
483         def configmenu(self):
484                 self.session.openWithCallback(self.PartnerboxSetupFinished, PartnerboxSetup)
485         
486         def PartnerboxSetupFinished(self):
487                 if config.plugins.partnerbox.enablepartnerboxintimerevent.value:
488                         RemoteTimerInit()
489                 self.E2TimerList = []
490                 self.password = config.plugins.partnerbox.password.value
491                 self.username = "root"
492                 ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
493                 port = config.plugins.partnerbox.port.value
494                 self.http = "http://%s:%d" % (ip,port)
495                 self.enigma_type = int(config.plugins.partnerbox.enigma.value)
496                 self.useinternal = int(config.plugins.partnerbox.useinternal.value)
497                 self["text"] = Label(_("Getting Partnerbox Information..."))
498                 self.startRun()
499         
500         def startRun(self):
501                 self["timerlist"].instance.hide()
502                 self.action()
503                 
504         def cleanupTimer(self):
505                 self["timerlist"].instance.hide()
506                 self["text"].setText(_("Cleaning up finished timer entries..."))
507                 if self.enigma_type == 0:
508                         self.cleanupTimerCallback()
509                 else:
510                         sCommand = self.http + "/cleanupTimerList"
511                         sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(self.cleanupTimerlistE1Callback).addErrback(self.cleanupTimerlistE1Callback)
512                         
513         def cleanupTimerlistE1Callback(self, answer):
514                 self.action()
515                 
516         def cleanupTimerCallback(self, callback = None):
517                 ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
518                 for Timerentry in self["timerlist"].list:
519                         if Timerentry[0].state == TimerEntry.StateEnded:
520                                 temp = "http://" + self.username + ":" + self.password + "@" + ip + "/web/timerdelete?sRef="
521                                 ref = Timerentry[0].servicereference + "&begin=" + ("%s"%(Timerentry[0].timebegin)) + "&end=" +("%s"%(Timerentry[0].timeend))
522                                 urllib.quote(ref.decode('utf8').encode('latin-1','ignore'))
523                                 url = temp + ref
524                                 f = urllib.urlopen(url)
525                                 sxml = f.read()
526                 self.action()
527                 
528         def deleteTimer(self):
529                 try:
530                         sel = self["timerlist"].l.getCurrentSelection()[0]
531                         if sel is None:
532                                 return
533                         if self.enigma_type == 0:
534                                 name = sel.name
535                         else:
536                                 name = sel.description
537                         self.session.openWithCallback(self.deleteTimerConfirmed, MessageBox, _("Do you really want to delete the timer \n%s ?") % name)
538                 except: return
539
540         def deleteTimerConfirmed(self, val):
541                 if val:
542                         sel = self["timerlist"].l.getCurrentSelection()[0]
543                         if sel is None:
544                                 return
545                         if self.enigma_type == 0:
546                                 sCommand = self.http + "/web/timerdelete?sRef=" + sel.servicereference + "&begin=" + ("%s"%(sel.timebegin)) + "&end=" +("%s"%(sel.timeend))
547                         else:
548                                 sCommand = self.http + "/deleteTimerEvent?ref=" + sel.servicereference + "&start=" + ("%s"%(sel.timebegin)) + "&type=" +("%s"%(sel.type)) + "&force=yes"
549                         sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(self.deleteTimerCallback).addErrback(self.deleteTimerError)
550         
551         def deleteTimerCallback(self, callback = None):
552                 self.action()
553                 
554         def deleteTimerError(self, error = None):
555                 if error is not None:
556                         self["timerlist"].instance.hide()
557                         self["text"].setText(str(error.getErrorMessage()))
558         
559         def downloadCallback(self, callback = None):
560                 self.readXML(callback)
561                 self["timerlist"].instance.show()
562
563         def downloadError(self, error = None):
564                 if error is not None:
565                         self["text"].setText(str(error.getErrorMessage()))
566
567         def action(self):
568                 if self.enigma_type == 0:
569                         url = self.http + "/web/timerlist"
570                 else:
571                         url = self.http + "/xml/timers"
572                 sendPartnerBoxWebCommand(url, None,10, self.username, self.password).addCallback(self.downloadCallback).addErrback(self.downloadError)
573
574         def readXML(self, xmlstring):
575                 self.E2TimerList = []
576                 if self.enigma_type == 0:
577                         self.E2TimerList = FillE2TimerList(xmlstring)
578                         self["timerlist"].buildList(self.E2TimerList)
579                 else:
580                         self.E2TimerList = FillE1TimerList(xmlstring)
581                         self["timerlist"].buildE1List(self.E2TimerList)
582
583         def EPGList(self):
584                 self.session.openWithCallback(self.CallbackEPGList, RemoteTimerBouquetList, self.E2TimerList, self.username, self.password, self.http, self.enigma_type, self.useinternal, 0)
585                 
586         def CallbackEPGList(self):
587                 self.startRun()
588
589 class RemoteTimerBouquetList(Screen):
590         skin = """
591                 <screen name="RemoteTimerBouquetList" position="210,160" size="300,240" title="Choose bouquet">
592                 <widget name="text" position="10,10" zPosition="1" size="290,225" font="Regular;20" halign="center" valign="center" />
593                 <widget name="bouquetlist" position="10,10" zPosition="2" size="290,225" scrollbarMode="showOnDemand" />
594         </screen>"""
595         
596         def __init__(self, session, E2Timerlist, User, Pass, http, enigma_type, useinternal, playeronly):
597                 self.session = session
598                 Screen.__init__(self, session)
599                 self["bouquetlist"] = E2BouquetList([])
600                 self["text"] = Label(_("Getting Partnerbox Bouquet Information..."))
601                 self.onLayoutFinish.append(self.startRun)
602                 self.E2TimerList = E2Timerlist
603                 self["actions"] = ActionMap(["WizardActions", "DirectionActions"],
604                 {
605                         "ok": self.action,
606                         "back": self.close,
607                 }, -1)
608
609                 self.password = Pass
610                 self.username = User
611                 self.http = http
612                 self.enigma_type = enigma_type
613                 self.useinternal = useinternal
614                 self.playeronly = playeronly
615                 if self.enigma_type == 0:
616                         self.url = self.http + "/web/getservices"
617                 else:
618                         self.url = self.http + "/xml/services?mode=0&submode=4"
619                 self.E1XMLString = ""
620                 self.password = Pass
621                 self.username = User
622                 
623                 
624         def action(self):
625                 try:
626                         sel = self["bouquetlist"].l.getCurrentSelection()[0]
627                         if sel is None:
628                                 return
629                         self.session.openWithCallback(self.CallbackEPGList, RemoteTimerChannelList, self.E2TimerList, sel.servicereference, sel.servicename, self.username, self.password, self.E1XMLString, self.http, self.enigma_type, self.useinternal, self.playeronly)
630                 except: return
631                 
632         def CallbackEPGList(self):
633                 pass
634         
635         def startRun(self):
636                 if self.useinternal == 1 :
637                         BouquetList = []
638                         a = Services(self.session)
639                         ref = eServiceReference( service_types_tv + ' FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
640                         BouquetList = a.buildList(ref, False)
641                         self["bouquetlist"].buildList(BouquetList)
642                 else:
643                         self["bouquetlist"].instance.hide()
644                         self.getBouquetList()
645         
646         def getBouquetList(self):
647                 sendPartnerBoxWebCommand(self.url, None,10, self.username, self.password).addCallback(self.downloadCallback).addErrback(self.downloadError)
648                 
649         def downloadCallback(self, callback = None):
650                 if self.enigma_type == 0:
651                         self.readXML(callback)
652                 else:
653                         self.readXMLE1(callback)
654                 self["bouquetlist"].instance.show()
655
656         def downloadError(self, error = None):
657                 if error is not None:
658                         self["text"].setText(str(error.getErrorMessage()))
659
660         def readXMLE1(self,xmlstring):
661                 self.E1XMLString = xmlstring
662                 BouquetList = []
663                 dom = xml.dom.minidom.parseString(xmlstring)
664                 for node in dom.firstChild.childNodes:
665                         if node.nodeName == "bouquet":
666                                 servicereference = ""
667                                 servicename = ""
668                                 for node2 in node.childNodes:
669                                         if node2.nodeName == "reference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
670                                         if node2.nodeName == "name":
671                                                 try:servicename = str(node2.firstChild.data.strip().encode("utf-8"))
672                                                 except:servicename = "n/a"
673                                                 BouquetList.append(E2ServiceList(servicereference = servicereference, servicename = servicename))
674                 self["bouquetlist"].buildList(BouquetList)
675                         
676                         
677         def readXML(self, xmlstring):
678                 BouquetList = []
679                 dom = xml.dom.minidom.parseString(xmlstring)
680                 for node in dom.firstChild.childNodes:
681                         servicereference = ""
682                         servicename = ""
683                         if node.nodeName == "e2service":
684                                 for node2 in node.childNodes:
685                                         if node2.nodeName == "e2servicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
686                                         if node2.nodeName == "e2servicename":
687                                                 try:servicename = str(node2.firstChild.data.strip().encode("utf-8"))
688                                                 except:servicename = "n/a"
689                                                 BouquetList.append(E2ServiceList(servicereference = servicereference, servicename = servicename))
690                 self["bouquetlist"].buildList(BouquetList)
691
692 class RemoteTimerChannelList(Screen):
693         EMPTY = 0
694         ADD_TIMER = 1
695         REMOVE_TIMER = 2
696         REMOTE_TIMER_MODE = 0
697         REMOTE_TV_MODE = 1
698         skin = """
699                 <screen name="RemoteTimerChannelList" position="90,95" size="560,430" title ="Bouquet List">
700                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
701                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
702                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
703                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
704                         <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
705                         <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
706                         <widget name="key_yellow" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
707                         <widget name="key_blue" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
708                         <widget name="text" position="0,40" zPosition="1" size="560,375" font="Regular;20" halign="center" valign="center" />
709                         <widget name="channellist" position="0,40" zPosition="2" size="560,375" scrollbarMode="showOnDemand" />
710                 </screen>"""
711         
712         def __init__(self, session, E2Timerlist, ServiceReference, ServiceName, User, Pass, E1XMLString, http, enigma_type, useinternal, playeronly):
713                 self.session = session
714                 Screen.__init__(self, session)
715                 self["channellist"] = E2ChannelList([], selChangedCB = self.onSelectionChanged)
716                 self.playeronly = playeronly
717                 self["key_red"] = Label(_("Zap"))
718                 self["key_green"] = Label()
719                 if self.playeronly == 0:
720                                 self["key_yellow"] = Label(_("EPG Selection"))
721                 else:
722                         self["key_yellow"] = Label()
723                 self["key_blue"] = Label(_("Info"))
724                 
725                 self["text"] = Label(_("Getting Channel Information..."))
726                 self.onLayoutFinish.append(self.startRun)
727                 self.E2TimerList = E2Timerlist
728                 self.E2ChannelList = []
729                 self.servicereference = ServiceReference
730                 self.E1XMLString = E1XMLString
731                 self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions"],
732                 {
733                         "ok": self.PlayRemoteStream,
734                         "back": self.close,
735                         "yellow": self.EPGSelection,
736                         "blue": self.EPGEvent,
737                         "red": self.Zap,
738                 }, -1)
739                 
740                 self.http = http
741                 self.enigma_type = enigma_type
742                 self.useinternal = useinternal
743                 self.password = Pass
744                 self.username = User
745                 self.key_green_choice = self.ADD_TIMER
746                 self.zapTimer = eTimer()
747                 self.zapTimer.timeout.get().append(self.zapTimerTimeout)
748                 self.onClose.append(self.__onClose)
749                 self.ChannelListCurrentIndex = 0
750                 self.mode = self.REMOTE_TIMER_MODE
751                 self.CurrentService = self.session.nav.getCurrentlyPlayingServiceReference()
752                 
753         def __onClose(self):
754                 if self.zapTimer.isActive():
755                         self.zapTimer.stop()
756                         
757         def startRun(self):
758                 if self.useinternal == 1 :
759                         ChannelList = []
760                         a = Services(self.session)
761                         Channelref = eServiceReference(self.servicereference)
762                         ChannelList = a.buildList(Channelref, True)
763                         self["channellist"].buildList(ChannelList)
764                         self["channellist"].instance.show()
765                         if self.ChannelListCurrentIndex !=0:
766                                 sel = self["channellist"].moveSelectionTo(self.ChannelListCurrentIndex)
767                                 self.ChannelListCurrentIndex = 0
768                 else:
769                         self["channellist"].instance.hide()
770                         self.getChannelList()
771         
772         def PlayRemoteStream(self):
773                 if self.playeronly == 1:
774                         if self.mode == self.REMOTE_TIMER_MODE:
775                                 self.mode = self.REMOTE_TV_MODE
776                                 self.Zap()
777                         else:
778                                 self.session.nav.playService(self.CurrentService)
779                                 self.mode = self.REMOTE_TIMER_MODE
780                                 self["channellist"].instance.show()
781                 else:
782                         self.EPGSelection()
783                         
784         def Zap(self):
785                 sel = self["channellist"].l.getCurrentSelection()[0]
786                 if sel is None:
787                         return
788                 self["channellist"].instance.hide()
789                 self.ChannelListCurrentIndex = self["channellist"].getCurrentIndex()
790                 self["text"].setText("Zapping to " + sel.servicename)
791         
792                 if self.useinternal == 1 and self.mode == self.REMOTE_TIMER_MODE:
793                         self.session.nav.playService(eServiceReference(sel.servicereference))
794                         self.ZapCallback(None)
795                 else:
796                         if self.enigma_type == 0:
797                                 url = self.http + "/web/zap?sRef=" + urllib.quote(sel.servicereference.decode('utf8').encode('latin-1','ignore'))
798                         else:
799                                 url = self.http + "/cgi-bin/zapTo?path=" + urllib.quote(sel.servicereference.decode('utf8').encode('latin-1','ignore'))
800                         sendPartnerBoxWebCommand(url, None,10, self.username, self.password).addCallback(self.ZapCallback).addErrback(self.DoNotCareError)
801         
802         def DoNotCareError(self, dnce = None):
803                 # Jesses, E1 sendet 204 nach umschalten, kommt hier also immer rein...
804                 self.ZapCallback(dnce)
805         
806         def ZapCallback(self, callback = None):
807                 if self.mode == self.REMOTE_TIMER_MODE:
808                         self["text"].setText("Give Enigma time to fill epg cache...")
809                         self.zapTimer.start(10000) # 10 Sekunden
810                 else:
811                         self.zapTimer.start(3000) # 3 Sekunden REMOTE_TV
812                 
813         def zapTimerTimeout(self):
814                 if self.zapTimer.isActive():
815                         self.zapTimer.stop()
816                 if self.mode == self.REMOTE_TIMER_MODE:
817                         self.startRun()
818                 else:
819                         self.GetStreamInfosCallback()
820         
821         def GetStreamInfosCallback(self):
822                 if self.enigma_type == 0:
823                         ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
824                         url = "http://" + ip + ":8001/" + self["channellist"].l.getCurrentSelection()[0].servicereference 
825                         self.StreamTV(url)
826                 else:
827                         url = self.http + "/video.m3u"
828                         sendPartnerBoxWebCommand(url, None,10, self.username, self.password).addCallback(self.StreamTV).addErrback(self.ChannelListDownloadError)
829         
830         def StreamTV(self, connectstring):
831                         self.session.nav.stopService()
832                         sref = eServiceReference(ENIGMA_WEBSERVICE_ID, 0, connectstring)
833                         self.session.nav.playService(sref)
834                         self.session.openWithCallback(self.PlayRemoteStream, RemotePlayer, self["channellist"].l.getCurrentSelection()[0].servicename,self["channellist"].l.getCurrentSelection()[0].eventtitle, self["channellist"].l.getCurrentSelection()[0].eventstart, self["channellist"].l.getCurrentSelection()[0].eventduration, self.password,self.username, self["channellist"].l.getCurrentSelection()[0].servicereference, self.http , self.enigma_type, self.useinternal)
835         
836         def EPGEvent(self):
837                 sel = self["channellist"].l.getCurrentSelection()[0]
838                 if sel is None:
839                         return
840                 self.session.openWithCallback(self.CallbackEPGEvent, RemoteTimerEventView, self.E2TimerList, sel, self.username, self.password, self.http, self.enigma_type, self.useinternal)
841
842         def CallbackEPGEvent(self):
843                 pass
844                 
845         def onSelectionChanged(self):
846                 cur = self["channellist"].getCurrent()
847                 if cur is None:
848                         self["key_green"].setText("")
849                         self.key_green_choice = self.EMPTY
850                         self["key_yellow"].setText("")
851                         self["key_blue"].setText("")
852                         return
853                 eventid = cur[0].eventid
854                 if eventid ==0:
855                         self["key_green"].setText("")
856                         self.key_green_choice = self.EMPTY
857                         self["key_yellow"].setText("")
858                         self["key_blue"].setText("")
859                         return
860                 if self.playeronly == 0:
861                         self["key_yellow"].setText(_("EPG Selection"))
862                 self["key_blue"].setText(_("Info"))
863                 serviceref = cur[0].servicereference
864                 
865 #               isRecordEvent = False
866 #               for timer in self.E2TimerList:
867 #                       if timer.eventId == eventid and timer.servicereference == serviceref:
868 #                               isRecordEvent = True
869 #                               break
870 #               if isRecordEvent and self.key_green_choice != self.REMOVE_TIMER:
871 #                       self["key_green"].setText(_("Remove timer"))
872 #                       self.key_green_choice = self.REMOVE_TIMER
873 #               elif not isRecordEvent and self.key_green_choice != self.ADD_TIMER:
874 #                       self["key_green"].setText(_("Add timer"))
875 #                       self.key_green_choice = self.ADD_TIMER
876                 
877         def ChannelListDownloadCallback(self, callback = None):
878                 self.readXMLServiceList(callback)
879         
880         def ChannelListDataDownloadCallback(self, callback = None):
881                 self.readXMLEPGList(callback)
882                 if self.ChannelListCurrentIndex !=0:
883                         sel = self["channellist"].moveSelectionTo(self.ChannelListCurrentIndex)
884                         self.ChannelListCurrentIndex = 0
885                 self["channellist"].instance.show()
886
887         def ChannelListDownloadError(self, error = None):
888                 if error is not None:
889                         self["text"].setText(str(error.getErrorMessage()))
890                         self.mode = REMOTE_TIMER_MODE
891                         
892         def getChannelList(self):
893                 if self.enigma_type == 0:
894                         ref = urllib.quote(self.servicereference.decode('utf8').encode('latin-1','ignore'))
895                         url = self.http + "/web/getservices?sRef=" + ref
896                         sendPartnerBoxWebCommand(url, None,10, self.username, self.password).addCallback(self.ChannelListDownloadCallback).addErrback(self.ChannelListDownloadError)
897                 else:
898                         self.readXMLServiceListE1()
899                         if self.ChannelListCurrentIndex !=0:
900                                 sel = self["channellist"].moveSelectionTo(self.ChannelListCurrentIndex)
901                                 self.ChannelListCurrentIndex = 0
902                         self["channellist"].instance.show()
903         def readXMLServiceListE1(self):
904                 self.E2ChannelList = []
905                 dom = xml.dom.minidom.parseString(self.E1XMLString)
906                 for node in dom.firstChild.childNodes:
907                         if node.nodeName == "bouquet":
908                                 for node2 in node.childNodes:
909                                         if node2.nodeName == "reference": 
910                                                 if self.servicereference  == str(node2.firstChild.data.strip().encode("utf-8")):
911                                                         proceed = True
912                                                 else:
913                                                         proceed = False
914                                         if node2.nodeName == "service":
915                                                 if proceed:
916                                                         servicereference = ""
917                                                         servicename = ""
918                                                         eventstart = 0
919                                                         eventduration = 0
920                                                         eventtitle = ""
921                                                         eventdescriptionextended = ""
922                                                         eventdescription = ""
923                                                         for node3 in node2.childNodes:
924                                                                 if node3.nodeName == "reference": servicereference = str(node3.firstChild.data.strip().encode("utf-8"))
925                                                                 if node3.nodeName == "name":
926                                                                         try:servicename = str(node3.firstChild.data.strip().encode("utf-8"))
927                                                                         except:servicename = "n/a"
928                                                                         ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
929                                                                         url = "http://" + self.username + ":" + self.password + "@" + ip + "/xml/serviceepg?ref=" + servicereference + "&entries=1"
930                                                                         f = urllib.urlopen(url)
931                                                                         sxml = f.read()
932                                                                         eventstart, eventduration, eventtitle, eventdescriptionextended, eventdescription = self.XMLReadEPGDataE1(sxml)
933                                                                         self.E2ChannelList.append(E2EPGListAllData(servicereference = servicereference, servicename = servicename, eventstart = eventstart, eventduration = eventduration, eventtitle = eventtitle, eventid = 1, eventdescription= eventdescription, eventdescriptionextended = eventdescriptionextended))
934                 self["channellist"].buildList(self.E2ChannelList)
935                 
936         def XMLReadEPGDataE1(self,xmlstring):
937                 eventstart = 0
938                 eventduration = 0
939                 eventtitle = ""
940                 eventdescriptionextended = ""
941                 eventdescription = ""
942                 xmlstring = xmlstring.replace("""<?xml-stylesheet type="text/xsl" href="/xml/serviceepg.xsl"?>""","")
943                 dom = xml.dom.minidom.parseString(xmlstring)
944                 for node in dom.firstChild.childNodes:
945                         servicereference = ""
946                         servicename = ""
947                         if node.nodeName == "event":
948                                 for node2 in node.childNodes:
949                                         if node2.nodeName == "description":
950                                                 try:eventtitle = str(node2.firstChild.data.strip().encode("utf-8"))
951                                                 except:pass
952                                         if node2.nodeName == "details":
953                                                 try:eventdescriptionextended = str(node2.firstChild.data.strip().encode("utf-8"))
954                                                 except:pass
955                                         if node2.nodeName == "genre":
956                                                 try:eventdescription = str(node2.firstChild.data.strip().encode("utf-8"))
957                                                 except:pass
958                                         if node2.nodeName == "duration": eventduration = int(node2.firstChild.data.strip())
959                                         if node2.nodeName == "start": eventstart = int(node2.firstChild.data.strip())
960                 return eventstart, eventduration, eventtitle, eventdescriptionextended, eventdescription
961
962         def readXMLServiceList(self, xmlstring):
963                 self.E2ChannelList = []
964                 dom = xml.dom.minidom.parseString(xmlstring)
965                 for node in dom.firstChild.childNodes:
966                         servicereference = ""
967                         servicename = ""
968                         if node.nodeName == "e2service":
969                                 for node2 in node.childNodes:
970                                         if node2.nodeName == "e2servicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
971                                         if node2.nodeName == "e2servicename":
972                                                 try:servicename = str(node2.firstChild.data.strip().encode("utf-8"))
973                                                 except:servicename = "n/a"
974                                                 self.E2ChannelList.append(E2EPGListAllData(servicereference = servicereference, servicename = servicename))
975                 
976                 ref = urllib.quote(self.servicereference.decode('utf8').encode('latin-1','ignore'))
977                 url = self.http + "/web/epgnow?bRef=" + ref
978                 sendPartnerBoxWebCommand(url, None,10, self.username, self.password).addCallback(self.ChannelListDataDownloadCallback).addErrback(self.ChannelListDownloadError)
979                 
980         def readXMLEPGList(self, xmlstring):
981                 dom = xml.dom.minidom.parseString(xmlstring)
982                 for node in dom.firstChild.childNodes:
983                         servicereference = ""
984                         servicename = ""
985                         eventid = 0
986                         eventstart = 0
987                         eventduration = 0
988                         eventtitle = ""
989                         eventdescription = ""
990                         eventdescriptionextended = ""
991                         if node.nodeName == "e2event":
992                                 for node2 in node.childNodes:
993                                         if node2.nodeName == "e2eventid": 
994                                                 try:eventid= int(node2.firstChild.data.strip())
995                                                 except:pass
996                                         if node2.nodeName == "e2eventstart": 
997                                                 try:eventstart = int(node2.firstChild.data.strip())
998                                                 except:pass
999                                         if node2.nodeName == "e2eventduration": 
1000                                                 try:eventduration = int(node2.firstChild.data.strip())
1001                                                 except:pass
1002                                         if node2.nodeName == "e2eventtitle":
1003                                                 try:eventtitle = str(node2.firstChild.data.strip().encode("utf-8"))
1004                                                 except:eventtitle = ""
1005                                         if node2.nodeName == "e2eventdescription":
1006                                                 try:eventdescription = str(node2.firstChild.data.strip().encode("utf-8"))
1007                                                 except:eventdescription = ""
1008                                         if node2.nodeName == "e2eventdescriptionextended":
1009                                                 try:eventdescriptionextended = str(node2.firstChild.data.strip().encode("utf-8"))
1010                                                 except:eventdescriptionextended = "n/a"
1011                                         if node2.nodeName == "e2eventservicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
1012                                         if node2.nodeName == "e2eventservicename":
1013                                                 try:
1014                                                         servicename = str(node2.firstChild.data.strip().encode("utf-8"))
1015                                                         for epgdata in self.E2ChannelList:
1016                                                                 if epgdata.servicereference == servicereference:
1017                                                                         epgdata.eventid = eventid
1018                                                                         epgdata.eventstart = eventstart
1019                                                                         epgdata.eventduration = eventduration
1020                                                                         epgdata.eventtitle = eventtitle
1021                                                                         epgdata.eventdescription = eventdescription
1022                                                                         epgdata.eventdescriptionextended = eventdescriptionextended
1023                                                                         break
1024                                                 except:pass
1025                 self["channellist"].buildList(self.E2ChannelList)
1026
1027         def EPGSelection(self):
1028                 if self.playeronly == 0:
1029                         try:
1030                                 sel = self["channellist"].l.getCurrentSelection()[0]
1031                                 if sel is None:
1032                                         return
1033                                 if sel.eventid != 0:
1034                                         self.session.openWithCallback(self.CallbackEPGSelection, RemoteTimerEPGList, self.E2TimerList, sel.servicereference, sel.servicename, self.username, self.password, self.http, self.enigma_type, self.useinternal)
1035                         except: return
1036                 
1037         def CallbackEPGSelection(self):
1038                 pass
1039
1040 class RemotePlayer(Screen, InfoBarAudioSelection):
1041         
1042         
1043         HDSkn = False
1044         try:
1045                 sz_w = getDesktop(0).size().width()
1046                 if sz_w == 1280:
1047                         HDSkn = True
1048                 else:
1049                         HDSkn = False
1050         except:
1051                 HDSkn = False
1052         if HDSkn:
1053                 skin="""
1054                 <screen name="RemotePlayer" flags="wfNoBorder" position="283,102" size="720,576" title="Partnerbox - RemotePlayer" backgroundColor="#FFFFFFFF">
1055                         <ePixmap position="41,388" zPosition="-1" size="630,130" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/ExPlayer.png" alphatest="off" transparent="1"/>
1056                         <widget name="ServiceName" zPosition="1" position="50,404" size="610,59" valign="center" halign="center" font="Regular;21" foregroundColor="#F0F0F0" backgroundColor="#302C2C39" />
1057                         <widget name="DateTime" zPosition="1" position="52,473" size="500,30" halign="left" font="Regular;16" foregroundColor="#F0F0F0" backgroundColor="#302C2C39" transparent="1" />
1058                         <widget name="IP" zPosition="2" position="361,473" size="300,30" halign="right" font="Regular;16" foregroundColor="#F0F0F0" backgroundColor="#302C2C39" transparent="1" />
1059                 </screen>"""
1060         else:
1061                 skin="""
1062                 <screen name="RemotePlayer" flags="wfNoBorder" position="3,30" size="720,576" title="Partnerbox - RemotePlayer" backgroundColor="#FFFFFFFF">
1063                         <ePixmap position="41,388" zPosition="-1" size="630,130" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/ExPlayer.png" alphatest="off" transparent="1"/>
1064                         <widget name="ServiceName" zPosition="1" position="50,404" size="610,59" valign="center" halign="center" font="Regular;21" foregroundColor="#F0F0F0" backgroundColor="#302C2C39" />
1065                         <widget name="DateTime" zPosition="1" position="52,473" size="500,30" halign="left" font="Regular;16" foregroundColor="#F0F0F0" backgroundColor="#302C2C39" transparent="1" />
1066                         <widget name="IP" zPosition="2" position="361,473" size="300,30" halign="right" font="Regular;16" foregroundColor="#F0F0F0" backgroundColor="#302C2C39" transparent="1" />
1067                 </screen>"""
1068         
1069         def __init__(self, session, ServiceName, EventTitle, eventstart, eventduration, password, username, servicereference, http, enigma_type, useinternal):
1070                 self.session = session
1071                 Screen.__init__(self, session)
1072                 InfoBarAudioSelection.__init__(self)
1073                 self.http = http
1074                 self.enigma_type = enigma_type
1075                 self.useinternal = useinternal
1076                 endtime = int(eventstart + eventduration)
1077                 tt = ((" %s ... %s (+%d " + _("mins") + ")") % (FuzzyTime(eventstart)[1], FuzzyTime(endtime)[1], (endtime - time.time()) / 60)) 
1078                 self["ServiceName"] = Label(EventTitle)
1079                 ip = "%d.%d.%d.%d" % tuple(config.plugins.partnerbox.ip.value)
1080                 self["IP"] = Label(ip)
1081                 self["DateTime"] = Label(ServiceName + ": " + tt)
1082                 self.isVisible = True
1083                 self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions"],
1084                 {
1085                         "ok": self.Infobar,
1086                         "back": self.close,
1087                 }, -1)
1088                 self.password = password
1089                 self.username = username
1090                 self.servicereference = servicereference
1091                 self.onLayoutFinish.append(self.startRun)
1092                 self.onClose.append(self.__onClose)
1093                 
1094                 self.Timer = eTimer()
1095                 self.Timer.timeout.get().append(self.TimerTimeout)
1096                 
1097         def TimerTimeout(self):
1098                 if self.Timer.isActive():
1099                         self.Timer.stop()
1100                 self.Infobar()
1101         
1102         def startRun(self):
1103                 idx = config.usage.infobar_timeout.index
1104                 if idx:
1105                         self.Timer.start(idx * 1000)
1106                 else:
1107                         self.Timer.start(6 * 1000)
1108                 if self.enigma_type == 0:
1109                         url = self.http + "/web/epgservicenow?sRef=" + self.servicereference
1110                 else:
1111                         url = self.http + "/xml/serviceepg?ref=" + self.servicereference + "&entries=1"
1112                 sendPartnerBoxWebCommand(url, None,10, self.username, self.password).addCallback(self.CurrentEPGCallback).addErrback(self.CurrentEPGCallbackError)
1113
1114         def CurrentEPGCallback(self, xmlstring):
1115                 xmlstring = xmlstring.replace("""<?xml-stylesheet type="text/xsl" href="/xml/serviceepg.xsl"?>""","")
1116                 dom = xml.dom.minidom.parseString(xmlstring)
1117                 e2eventtitle = ""
1118                 e2eventservicename = ""
1119                 e2eventstart = 0
1120                 e2eventduration = 0
1121                 if self.enigma_type == 0:
1122                         for node in dom.firstChild.childNodes:
1123                                 if node.nodeName == "e2event":
1124                                         for node2 in node.childNodes:
1125                                                 if node2.nodeName == "e2eventservicename":
1126                                                         try:e2eventservicename = str(node2.firstChild.data.strip().encode("utf-8"))
1127                                                         except:e2eventservicename = "n/a"
1128                                                 if node2.nodeName == "e2eventtitle":
1129                                                         try:e2eventtitle = str(node2.firstChild.data.strip().encode("utf-8"))
1130                                                         except:e2eventtitle = "n/a"
1131                                                 if node2.nodeName == "e2eventstart": 
1132                                                         try:e2eventstart = int(node2.firstChild.data.strip())
1133                                                         except:pass
1134                                                 if node2.nodeName == "e2eventduration": 
1135                                                         try:e2eventduration = int(node2.firstChild.data.strip())
1136                                                         except:pass
1137                 else:
1138                         for node in dom.firstChild.childNodes:
1139                                 if node.nodeName == "service":
1140                                         for node2 in node.childNodes:
1141                                                 if node2.nodeName == "name":
1142                                                         try:e2eventservicename = str(node2.firstChild.data.strip().encode("utf-8"))
1143                                                         except:e2eventservicename = "n/a"
1144                                 if node.nodeName == "event":
1145                                         for node2 in node.childNodes:
1146                                                 if node2.nodeName == "description":
1147                                                         try:e2eventtitle = str(node2.firstChild.data.strip().encode("utf-8"))
1148                                                         except:pass
1149                                                 if node2.nodeName == "duration":
1150                                                         try:e2eventduration = int(node2.firstChild.data.strip())
1151                                                         except:pass
1152                                                 if node2.nodeName == "start": 
1153                                                         try:e2eventstart = int(node2.firstChild.data.strip())
1154                                                         except:pass
1155                 endtime = int(e2eventstart + e2eventduration)
1156                 if endtime != 0:
1157                         tt = ((": %s ... %s (+%d " + _("mins") + ")") % (FuzzyTime(e2eventstart)[1], FuzzyTime(endtime)[1], (endtime - time.time()) / 60))
1158                 else:
1159                         tt = ""
1160                 self["ServiceName"].setText(e2eventtitle)
1161                 self["DateTime"].setText(e2eventservicename + tt)
1162
1163         def CurrentEPGCallbackError(self, error = None):
1164                 print "[RemotePlayer] Error: ",error.getErrorMessage()
1165                 
1166         def readXMSubChanelList(self, xmlstring):
1167                 BouquetList = []
1168                 counter = 0
1169                 dom = xml.dom.minidom.parseString(xmlstring)
1170                 for node in dom.firstChild.childNodes:
1171                         servicereference = ""
1172                         servicename = ""
1173                         if node.nodeName == "e2service":
1174                                 for node2 in node.childNodes:
1175                                         if node2.nodeName == "e2servicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
1176                                         if node2.nodeName == "e2servicename":
1177                                                 try:servicename = str(node2.firstChild.data.strip().encode("utf-8"))
1178                                                 except:servicename = "n/a"
1179                                                 if counter != 0: # erster Eintrag ist der aktuelle Sedner, nicht aufnehmen
1180                                                         BouquetList.append(E2ServiceList(servicereference = servicereference, servicename = servicename))
1181                                                 counter += 1
1182         
1183         def Infobar(self):
1184                 if self.isVisible:
1185                         if self.Timer.isActive():
1186                                 self.Timer.stop()
1187                         self.hide()
1188                         self.isVisible = False
1189                 else:
1190                         self.startRun()
1191                         self.show()
1192                         self.isVisible = True
1193                         
1194         def __onClose(self):
1195                 if self.Timer.isActive():
1196                         self.Timer.stop()
1197                 
1198 class RemoteTimerEPGList(Screen):
1199         EMPTY = 0
1200         ADD_TIMER = 1
1201         REMOVE_TIMER = 2
1202         skin = """
1203                 <screen name="RemoteTimerEPGList" position="90,95" size="560,430" title ="EPG Selection">
1204                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
1205                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
1206                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
1207                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
1208                         <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
1209                         <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
1210                         <widget name="key_yellow" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
1211                         <widget name="key_blue" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
1212                         <widget name="text" position="0,40" zPosition="1" size="560,375" font="Regular;20" halign="center" valign="center" />
1213                         <widget name="epglist" position="0,40" zPosition="2" size="560,375" scrollbarMode="showOnDemand" />
1214                 </screen>"""
1215         
1216         def __init__(self, session, E2Timerlist, ServiceReference, ServiceName, User, Pass, http, enigma_type, useinternal):
1217                 self.session = session
1218                 Screen.__init__(self, session)
1219                 self.E2TimerList = E2Timerlist
1220                 self["epglist"] = E2EPGList([],selChangedCB = self.onSelectionChanged)
1221                 self["key_red"] = Label()# Dummy, kommt eventuell noch was
1222                 self["key_green"] = Label(_("Add timer"))
1223                 self.key_green_choice = self.ADD_TIMER
1224                 self["key_yellow"] = Label() # Dummy, kommt eventuell noch was
1225                 self["key_blue"] = Label(_("Info"))
1226                 self["text"] = Label(_("Getting EPG Information..."))
1227                 self.onLayoutFinish.append(self.startRun)
1228                 self.servicereference = ServiceReference
1229                 self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions"],
1230                 {
1231                         "back": self.close,
1232                         "green": self.GreenPressed,
1233                         "blue": self.EPGEvent,
1234                 }, -1)
1235                 
1236                 self.http = http
1237                 self.enigma_type = enigma_type
1238                 self.useinternal = useinternal
1239                 
1240                 if self.enigma_type == 0:
1241                         self.url = self.http + "/web/epgservice?sRef=" + urllib.quote(self.servicereference.decode('utf8').encode('latin-1','ignore'))
1242                 else:
1243                         self.url = self.http + "/xml/serviceepg?ref=" + urllib.quote(self.servicereference.decode('utf8').encode('latin-1','ignore'))
1244                 self.password = Pass
1245                 self.username = User
1246                 self.ListCurrentIndex = 0
1247                 self.Locations = []
1248                 
1249         def EPGEvent(self):
1250                 
1251                 sel = self["epglist"].l.getCurrentSelection()[0]
1252                 if sel is None:
1253                         return
1254                 self.session.openWithCallback(self.CallbackEPGEvent, RemoteTimerEventView, self.E2TimerList, sel, self.username, self.password, self.http, self.enigma_type, self.useinternal)
1255                 
1256         def CallbackEPGEvent(self):
1257                 pass
1258                 
1259         def onSelectionChanged(self):
1260                 cur = self["epglist"].getCurrent()
1261                 if cur is None:
1262                         self["key_green"].setText("")
1263                         self.key_green_choice = self.EMPTY
1264                         self["key_blue"].setText("")
1265                         return
1266                 serviceref = cur[0].servicereference
1267                 eventid = cur[0].eventid
1268                 if eventid ==0:
1269                         self["key_green"].setText("")
1270                         self.key_green_choice = self.EMPTY
1271                         self["key_blue"].setText("")
1272                         return
1273                 self["key_blue"].setText(_("Info"))
1274                 
1275                 timerentry = isInTimerList(cur[0].eventstart,cur[0].eventduration, cur[0].servicereference, cur[0].eventid, self.E2TimerList)
1276                 if timerentry is None:
1277                         if self.key_green_choice != self.ADD_TIMER:
1278                                 self["key_green"].setText(_("Add timer"))
1279                                 self.key_green_choice = self.ADD_TIMER
1280                 else:
1281                         if self.key_green_choice != self.REMOVE_TIMER:
1282                                 self["key_green"].setText(_("Remove timer"))
1283                                 self.key_green_choice = self.REMOVE_TIMER
1284         
1285         def startRun(self):
1286                 if self.useinternal == 1:
1287                         EPGList = []
1288                         a = Services(self.session)
1289                         EPGList = a.buildEPGList(self.servicereference)
1290                         self["epglist"].buildList(EPGList, self.E2TimerList)
1291                         if self.ListCurrentIndex != 0:
1292                                 sel = self["epglist"].moveSelectionTo(self.ListCurrentIndex)
1293                                 self.ListCurrentIndex = 0
1294                 else:
1295                         self["epglist"].instance.hide()
1296                         self.getEPGList()
1297         
1298         def getEPGList(self):
1299                         sendPartnerBoxWebCommand(self.url, None,10, self.username, self.password).addCallback(self.EPGListDownloadCallback).addErrback(self.EPGListDownloadError)
1300                 
1301         def EPGListDownloadCallback(self, callback = None):
1302                 if self.enigma_type == 0:
1303                         self.readXMLEPGList(callback)
1304                 else:
1305                         self.readXMLEPGListE1(callback)
1306                 self["epglist"].instance.show()
1307         
1308         def EPGListDownloadError(self, error = None):
1309                 if error is not None:
1310                         self["text"].setText(str(error.getErrorMessage()))
1311         
1312         def readXMLEPGListE1(self, xmlstring):
1313                 E1ListEPG = []
1314                 xmlstring = xmlstring.replace("""<?xml-stylesheet type="text/xsl" href="/xml/serviceepg.xsl"?>""","")
1315                 dom = xml.dom.minidom.parseString(xmlstring)
1316                 servicereference = ""
1317                 servicename = ""
1318                 for node in dom.firstChild.childNodes:
1319                         eventstart = 0
1320                         eventduration = 0
1321                         eventtitle = ""
1322                         eventdescriptionextended = ""
1323                         eventdescription = ""
1324                         if node.nodeName == "service":
1325                                 for node2 in node.childNodes:
1326                                         if node2.nodeName == "reference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
1327                                         if node2.nodeName == "name":
1328                                                 try:servicename = str(node2.firstChild.data.strip().encode("utf-8"))
1329                                                 except:servicename = "n/a"
1330                         if node.nodeName == "event":
1331                                 for node2 in node.childNodes:
1332                                         if node2.nodeName == "description":
1333                                                 try:eventtitle = str(node2.firstChild.data.strip().encode("utf-8"))
1334                                                 except:pass
1335                                         if node2.nodeName == "duration": eventduration = int(node2.firstChild.data.strip())
1336                                         if node2.nodeName == "start": eventstart = int(node2.firstChild.data.strip())
1337                                         if node2.nodeName == "genre":
1338                                                 try:eventdescription = str(node2.firstChild.data.strip().encode("utf-8"))
1339                                                 except:pass
1340                                         if node2.nodeName == "details":
1341                                                 try:eventdescriptionextended = str(node2.firstChild.data.strip().encode("utf-8"))
1342                                                 except:pass
1343                                                 E1ListEPG.append(E2EPGListAllData(servicereference = servicereference, servicename = servicename, eventid = 1, eventstart = eventstart, eventduration = eventduration, eventtitle = eventtitle, eventdescription = eventdescription, eventdescriptionextended = eventdescriptionextended  ))
1344                 self["epglist"].buildList(E1ListEPG, self.E2TimerList)
1345                 if self.ListCurrentIndex != 0:
1346                         sel = self["epglist"].moveSelectionTo(self.ListCurrentIndex)
1347                         self.ListCurrentIndex = 0
1348         
1349         def readXMLEPGList(self, xmlstring):
1350                 E2ListEPG = []
1351                 dom = xml.dom.minidom.parseString(xmlstring)
1352                 for node in dom.firstChild.childNodes:
1353                         servicereference = ""
1354                         servicename = ""
1355                         eventid = 0
1356                         eventstart = 0
1357                         eventduration = 0
1358                         eventtitle = ""
1359                         eventdescription = ""
1360                         eventdescriptionextended = ""
1361                         if node.nodeName == "e2event":
1362                                 for node2 in node.childNodes:
1363                                         if node2.nodeName == "e2eventid": 
1364                                                 try:eventid= int(node2.firstChild.data.strip())
1365                                                 except:pass
1366                                         if node2.nodeName == "e2eventstart": 
1367                                                 try:eventstart = int(node2.firstChild.data.strip())
1368                                                 except:pass
1369                                         if node2.nodeName == "e2eventduration": 
1370                                                 try:eventduration = int(node2.firstChild.data.strip())
1371                                                 except:pass
1372                                         if node2.nodeName == "e2eventtitle":
1373                                                 try:eventtitle = str(node2.firstChild.data.strip().encode("utf-8"))
1374                                                 except:eventtitle = ""
1375                                         if node2.nodeName == "e2eventdescription":
1376                                                 try:eventdescription = str(node2.firstChild.data.strip().encode("utf-8"))
1377                                                 except:eventdescription = ""
1378                                         if node2.nodeName == "e2eventdescriptionextended":
1379                                                 try:eventdescriptionextended = str(node2.firstChild.data.strip().encode("utf-8"))
1380                                                 except:eventdescriptionextended = "n/a"
1381                                         if node2.nodeName == "e2eventservicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
1382                                         if node2.nodeName == "e2eventservicename":
1383                                                 try:
1384                                                         servicename = str(node2.firstChild.data.strip().encode("utf-8"))
1385                                                         E2ListEPG.append(E2EPGListAllData(servicereference = servicereference, servicename = servicename, eventid = eventid, eventstart = eventstart, eventduration = eventduration, eventtitle = eventtitle, eventdescription = eventdescription, eventdescriptionextended = eventdescriptionextended  ))
1386                                                 except:pass
1387                 self["epglist"].buildList(E2ListEPG, self.E2TimerList)
1388                 if self.ListCurrentIndex != 0:
1389                         sel = self["epglist"].moveSelectionTo(self.ListCurrentIndex)
1390                         self.ListCurrentIndex = 0
1391                 
1392         def GreenPressed(self):
1393                 if self.key_green_choice == self.ADD_TIMER:
1394                         if self.enigma_type == 0:
1395                                 self.getLocations()
1396                         else:
1397                                 self.addTimerEvent()
1398                 elif self.key_green_choice == self.REMOVE_TIMER:
1399                         print "removetimer"
1400                         self.deleteTimer()
1401         
1402         def LocationsError(self, error = None):
1403                 if error is not None:
1404                         self["epglist"].instance.hide()
1405                         self["text"].setText(str(error.getErrorMessage()))
1406         
1407         def getLocations(self):
1408                 sCommand = self.http + "/web/getlocations"
1409                 sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(self.getLocationsCallback).addErrback(self.LocationsError)
1410         
1411         def getLocationsCallback(self, xmlstring):
1412                 self.Locations = []
1413                 self.Locations = FillLocationList(xmlstring)
1414                 self.addTimerEvent()
1415                         
1416         def addTimerEvent(self):
1417                 cur = self["epglist"].getCurrent()
1418                 if cur is None:
1419                         return
1420                 if self.enigma_type == 0:
1421                         description = cur[0].eventdescription
1422                         type = 0
1423                         dirname = "/hdd/movie/"
1424                 else:
1425                         dirname = ""
1426                         type = PlaylistEntry.RecTimerEntry|PlaylistEntry.recDVR
1427                         description = cur[0].eventtitle
1428                 timerentry = E2Timer(servicereference = cur[0].servicereference, servicename = cur[0].servicename, name = cur[0].eventtitle, disabled = 0, timebegin = cur[0].eventstart, timeend = cur[0].eventstart + cur[0].eventduration, duration = cur[0].eventduration, startprepare = 0, state = 0 , repeated = 0, justplay= 0, eventId = 0, afterevent = 0, dirname = dirname, description = description, type = type )
1429                 self.session.openWithCallback(self.RemoteTimerEntryFinished, RemoteTimerEntry,timerentry, self.Locations)
1430
1431         def RemoteTimerEntryFinished(self, answer):
1432                 if answer[0]:
1433                         self.ListCurrentIndex = self["epglist"].getCurrentIndex()
1434                         entry = answer[1]
1435                         self["epglist"].instance.hide()
1436                         if self.enigma_type == 0:
1437                                 ref = urllib.quote(entry.servicereference.decode('utf8').encode('latin-1','ignore')) + "&begin=" + ("%s"%(entry.timebegin)) + "&end=" + ("%s"%(entry.timeend))  + "&name=" + urllib.quote(entry.name) + "&description=" + urllib.quote(entry.description) + "&dirname=" + urllib.quote(entry.dirname) + "&eit=0&justplay=" + ("%s"%(entry.justplay)) + "&afterevent=" + ("%s"%(entry.afterevent))
1438                                 sCommand = self.http + "/web/timeradd?sRef=" + ref
1439                                 sendPartnerBoxWebCommand(sCommand, None,10, self.username, self.password).addCallback(self.deleteTimerCallback).addErrback(self.EPGListDownloadError)
1440                         else:
1441                                 if entry.justplay & PlaylistEntry.SwitchTimerEntry:
1442                                         action = "zap"
1443                                 elif entry.justplay & PlaylistEntry.recNgrab:
1444                                         action = "ngrab"
1445                                 else:
1446                                         action = ""
1447                                 ref = urllib.quote(entry.servicereference.decode('utf8').encode('latin-1','ignore')) + "&start=" + ("%s"%(entry.timebegin)) + "&duration=" + ("%s"%(entry.timeend - entry.timebegin))  + "&descr=" + urllib.quote(entry.description) + "&channel=" + urllib.quote(entry.servicename) + "&after_event=" + ("%s"%(entry.afterevent)) + "&action=" + ("%s"%(action))
1448                                 sCommand = self.http + "/addTimerEvent?ref=" + ref
1449                                 sendPartnerBoxWebCommand(sCommand, None,10, self.username, self.password).addCallback(self.deleteTimerCallback).addErrback(self.EPGListDownloadError)
1450         
1451         def deleteTimer(self):
1452                 cur = self["epglist"].getCurrent()
1453                 if cur is None:
1454                         return
1455                 timerentry = isInTimerList(cur[0].eventstart,cur[0].eventduration, cur[0].servicereference, cur[0].eventid, self.E2TimerList)
1456                 if timerentry is None:
1457                         return
1458                 else:
1459                         self.session.openWithCallback(self.deleteTimerConfirmed, MessageBox, _("Do you really want to delete the timer \n%s ?") % timerentry.name)
1460
1461         def deleteTimerConfirmed(self, val):
1462                 if val:
1463                         cur = self["epglist"].getCurrent()
1464                         if cur is None:
1465                                 return
1466                         self.ListCurrentIndex = self["epglist"].getCurrentIndex()
1467                         timerentry = isInTimerList(cur[0].eventstart,cur[0].eventduration, cur[0].servicereference, cur[0].eventid, self.E2TimerList)
1468                         if timerentry is None:
1469                                 return
1470                         else:
1471                                 self["epglist"].instance.hide()
1472                                 if self.enigma_type == 0:
1473                                         sCommand = self.http + "/web/timerdelete?sRef=" + timerentry.servicereference + "&begin=" + ("%s"%(timerentry.timebegin)) + "&end=" +("%s"%(timerentry.timeend))
1474                                 else:
1475                                         sCommand = self.http + "/deleteTimerEvent?ref=" + timerentry.servicereference + "&start=" + ("%s"%(timerentry.timebegin)) + "&type=" +("%s"%(timerentry.type)) + "&force=yes"
1476                                 sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(self.deleteTimerCallback).addErrback(self.EPGListDownloadError)
1477         
1478         def deleteTimerCallback(self, callback = None):
1479                 if self.enigma_type == 0:
1480                         url = self.http + "/web/timerlist"
1481                 else:
1482                         if callback.find("Timer event deleted successfully.") != -1:
1483                                 msg = "Timer event deleted successfully."
1484                         else:
1485                                 msg = callback
1486                         self.session.open(MessageBox,msg,  MessageBox.TYPE_INFO, timeout = 3)
1487                         url = self.http + "/xml/timers"
1488                 sendPartnerBoxWebCommand(url, None,10, self.username, self.password).addCallback(self.readXML).addErrback(self.EPGListDownloadError)
1489
1490         def readXML(self, xmlstring = None):
1491                 if xmlstring is not None:
1492                         self["text"].setText("Getting timerlist data...")
1493                         self.E2TimerList = []
1494                         if self.enigma_type == 0:
1495                                 self.E2TimerList = FillE2TimerList(xmlstring)
1496                         else:
1497                                 self.E2TimerList = FillE1TimerList(xmlstring)
1498                         self["text"].setText("Getting EPG data...")
1499                         if self.useinternal == 1:
1500                                 EPGList = []
1501                                 a = Services(self.session)
1502                                 EPGList = a.buildEPGList(self.servicereference)
1503                                 self["epglist"].buildList(EPGList, self.E2TimerList)
1504                                 self["epglist"].instance.show()
1505                                 if self.ListCurrentIndex != 0:
1506                                         sel = self["epglist"].moveSelectionTo(self.ListCurrentIndex)
1507                                         self.ListCurrentIndex = 0
1508                         else:
1509                                 self.getEPGList()
1510                         
1511 class E2TimerMenu(MenuList):
1512         def __init__(self, list, enableWrapAround = True):
1513                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
1514                 self.l.setFont(0, gFont("Regular", 20))
1515                 self.l.setFont(1, gFont("Regular", 18))
1516         def postWidgetCreate(self, instance):
1517                 MenuList.postWidgetCreate(self, instance)
1518                 instance.setItemHeight(70)
1519
1520         def buildList(self,listnew):
1521                 self.list=[]
1522                 width = self.l.getItemSize().width()
1523                 for timer in listnew:
1524                         res = [ timer ]
1525                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.servicename))
1526                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.name))
1527
1528                         repeatedtext = ""
1529                         days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
1530                         if timer.repeated:
1531                                 flags = timer.repeated
1532                                 count = 0
1533                                 for x in range(0, 7):
1534                                                 if (flags & 1 == 1):
1535                                                         if (count != 0):
1536                                                                 repeatedtext += ", "
1537                                                         repeatedtext += days[x]
1538                                                         count += 1
1539                                                 flags = flags >> 1
1540                                 if timer.justplay:
1541                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s "+ _("(ZAP)")) % (FuzzyTime(timer.timebegin)[1]))))
1542                                 else:
1543                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.timebegin)[1], FuzzyTime(timer.timeend)[1], (timer.timeend - timer.timebegin) / 60))))
1544                         else:
1545                                 if timer.justplay:
1546                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s " + _("(ZAP)")) % (FuzzyTime(timer.timebegin)))))
1547                                 else:
1548                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.timebegin) + FuzzyTime(timer.timeend)[1:] + ((timer.timeend - timer.timebegin) / 60,)))))
1549                         
1550                         if timer.state == TimerEntry.StateWaiting:
1551                                 state = _("waiting")
1552                         elif timer.state == TimerEntry.StatePrepared:
1553                                 state = _("about to start")
1554                         elif timer.state == TimerEntry.StateRunning:
1555                                 if timer.justplay:
1556                                         state = _("zapped")
1557                                 else:
1558                                         state = _("recording...")
1559                         elif timer.state == TimerEntry.StateEnded:
1560                                 state = _("done!")
1561                         else:
1562                                 state = _("<unknown>")
1563
1564                         if timer.disabled:
1565                                 state = _("disabled")
1566
1567                         res.append((eListboxPythonMultiContent.TYPE_TEXT, width-150, 50, 150, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, state))
1568
1569                         if timer.disabled:
1570                                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/redx.png"))
1571                                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 490, 5, 40, 40, png))
1572
1573                         self.list.append(res)
1574                 self.l.setList(self.list)
1575                 self.moveToIndex(0)
1576                 
1577         def buildE1List(self,listnew):
1578                 self.list=[]
1579                 width = self.l.getItemSize().width()
1580                 for timer in listnew:
1581                         res = [ timer ]
1582                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.servicename))
1583                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.description))
1584
1585                         repeatedtext = ""
1586                         days = [ _("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat") ]
1587                         if timer.type & PlaylistEntry.isRepeating :
1588                                 mask = PlaylistEntry.Su
1589                                 count = 0
1590                                 for x in range(0, 7):
1591                                         if timer.type & mask:
1592                                                 if (count != 0):
1593                                                         repeatedtext += ", "
1594                                                 repeatedtext += days[x]
1595                                                 count += 1
1596                                         mask *= 2
1597                                 if timer.type & PlaylistEntry.SwitchTimerEntry:
1598                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-170, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s "+ _("(ZAP)")) % (FuzzyTime(timer.timebegin)[1]))))
1599                                 elif timer.type & PlaylistEntry.RecTimerEntry:
1600                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-170, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.timebegin)[1], FuzzyTime(timer.timeend)[1], (timer.timeend - timer.timebegin) / 60))))
1601                         else:
1602                                 if timer.type & PlaylistEntry.SwitchTimerEntry:
1603                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-170, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s ... %s (%d " + _("mins") + ") ") % (FuzzyTime(timer.timebegin) + FuzzyTime(timer.timeend)[1:] + ((timer.timeend - timer.timebegin) / 60,))) + _("(ZAP)")))
1604                                 elif timer.type & PlaylistEntry.RecTimerEntry:
1605                                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-170, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.timebegin) + FuzzyTime(timer.timeend)[1:] + ((timer.timeend - timer.timebegin) / 60,)))))
1606                         
1607                         if timer.type & PlaylistEntry.stateWaiting:
1608                                 state = _("waiting")
1609                         elif timer.type & PlaylistEntry.stateRunning:
1610                                 if timer.type & PlaylistEntry.SwitchTimerEntry:
1611                                         state = _("zapped")
1612                                 elif timer.type & PlaylistEntry.RecTimerEntry:
1613                                         state = _("recording...")
1614                         elif timer.type & PlaylistEntry.stateFinished:
1615                                 state = _("done!")
1616                         elif timer.type & PlaylistEntry.stateError:
1617                                 if timer.type & PlaylistEntry.errorNoSpaceLeft:
1618                                         state = _("Error: No space left")
1619                                 elif timer.type & PlaylistEntry.errorUserAborted:
1620                                         state = _("Error: User aborted")
1621                                 elif timer.type & PlaylistEntry.errorZapFailed:
1622                                         state = _("Error: Zap failed")
1623                                 elif timer.type & PlaylistEntry.errorOutdated:
1624                                         state = _("Error: Outdated")
1625                                 else:
1626                                         state = "Error: " + _("<unknown>")
1627                         else:
1628                                 state = _("<unknown>")
1629                         res.append((eListboxPythonMultiContent.TYPE_TEXT, width-170, 50, 170, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, state))
1630                         self.list.append(res)
1631                 self.l.setList(self.list)
1632                 self.moveToIndex(0)
1633                 
1634 class E2BouquetList(MenuList):
1635         def __init__(self, list, enableWrapAround = True):
1636                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
1637                 self.l.setFont(0, gFont("Regular", 20))
1638                 self.l.setFont(1, gFont("Regular", 18))
1639         def postWidgetCreate(self, instance):
1640                 MenuList.postWidgetCreate(self, instance)
1641                 instance.setItemHeight(30)
1642
1643         def buildList(self,listnew):
1644                 self.list=[]
1645                 width = self.l.getItemSize().width()
1646                 for bouquets in listnew:
1647                         res = [ bouquets ]
1648                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, bouquets.servicename))
1649                         self.list.append(res)
1650                 self.l.setList(self.list)
1651                 self.moveToIndex(0)
1652
1653 class E2ChannelList(MenuList):
1654         def __init__(self, list, selChangedCB=None, enableWrapAround = True):
1655                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
1656                 self.onSelChanged = [ ]
1657                 if selChangedCB is not None:
1658                         self.onSelChanged.append(selChangedCB)
1659                 self.l.setFont(0, gFont("Regular", 20))
1660                 self.l.setFont(1, gFont("Regular", 18))
1661         def postWidgetCreate(self, instance):
1662                 MenuList.postWidgetCreate(self, instance)
1663                 instance.setItemHeight(70)
1664                 instance.selectionChanged.get().append(self.selectionChanged)
1665         
1666         def preWidgetRemove(self, instance):
1667                 instance.selectionChanged.get().remove(self.selectionChanged)
1668                 
1669         def selectionChanged(self):
1670                 for x in self.onSelChanged:
1671                         if x is not None:
1672                                 x()
1673                                 
1674         def getCurrentIndex(self):
1675                 return self.instance.getCurrentIndex()
1676                 
1677         def moveSelectionTo(self,index):
1678                 self.moveToIndex(index)
1679         
1680         def buildList(self,listnew):
1681                 self.list=[]
1682                 width = self.l.getItemSize().width()
1683                 for epgdata in listnew:
1684                         res = [ epgdata ]
1685                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, epgdata.servicename))
1686                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, epgdata.eventtitle))
1687                         if epgdata.eventstart != 0:
1688                                 endtime = int(epgdata.eventstart + epgdata.eventduration)
1689                                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, width-150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, (("%s ... %s (%d " + _("mins") + ")") % (FuzzyTime(epgdata.eventstart)[1], FuzzyTime(endtime)[1], (endtime - epgdata.eventstart) / 60))))
1690                         self.list.append(res)
1691                 self.l.setList(self.list)
1692                 self.moveToIndex(0)
1693
1694 class E2EPGList(MenuList):
1695         def __init__(self, list, selChangedCB=None, enableWrapAround = True):
1696                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
1697                 self.onSelChanged = [ ]
1698                 if selChangedCB is not None:
1699                         self.onSelChanged.append(selChangedCB)
1700                 self.l.setFont(0, gFont("Regular", 22))
1701                 self.l.setFont(1, gFont("Regular", 16))
1702                 self.days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
1703                 self.timer_list = []
1704                 self.clock_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock.png'))
1705                 self.clock_add_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_add.png'))
1706                 self.clock_pre_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_pre.png'))
1707                 self.clock_post_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_post.png'))
1708                 self.clock_prepost_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_prepost.png'))
1709                 
1710         def postWidgetCreate(self, instance):
1711                 MenuList.postWidgetCreate(self, instance)
1712                 instance.setItemHeight(30)
1713                 instance.selectionChanged.get().append(self.selectionChanged)
1714         
1715         def preWidgetRemove(self, instance):
1716                 instance.selectionChanged.get().remove(self.selectionChanged)
1717         
1718         def getCurrentIndex(self):
1719                 return self.instance.getCurrentIndex()
1720                 
1721         def moveSelectionTo(self,index):
1722                 self.moveToIndex(index)
1723                 
1724         def selectionChanged(self):
1725                 for x in self.onSelChanged:
1726                         if x is not None:
1727                                 x()
1728         
1729         def buildList(self,listnew, timerlist):
1730                 self.list=[]
1731                 self.timer_list = timerlist
1732                 for epgdata in listnew:
1733                         res = [ epgdata ]
1734                         rec=epgdata.eventstart and (self.isInTimer(epgdata.eventstart, epgdata.eventduration, epgdata.servicereference))
1735                         esize = self.l.getItemSize()
1736                         width = esize.width()
1737                         height = esize.height()
1738                         r1 = Rect(0, 0, width/20*2-10, height)
1739                         r2 = Rect(width/20*2, 0, width/20*5-15, height)
1740                         r3 = Rect(width/20*7, 0, width/20*13, height)
1741                         t = localtime(epgdata.eventstart)
1742                         res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
1743                         res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_RIGHT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4])))
1744                         if rec:
1745                                 clock_pic = self.getClockPixmap(epgdata.servicereference, epgdata.eventstart, epgdata.eventduration, epgdata.eventid)
1746                                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic))
1747                                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, epgdata.eventtitle))
1748                         else:
1749                                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, epgdata.eventtitle))
1750                         
1751                         self.list.append(res)
1752                 self.l.setList(self.list)
1753                 self.moveToIndex(0)
1754                 
1755         def isInTimer(self, begin, duration, service):
1756                 time_match = 0
1757                 chktime = None
1758                 chktimecmp = None
1759                 chktimecmp_end = None
1760                 end = begin + duration
1761                 for x in self.timer_list:
1762                         if x.servicereference.upper() == service.upper():
1763                                 if x.repeated != 0:
1764                                         if chktime is None:
1765                                                 chktime = localtime(begin)
1766                                                 chktimecmp = chktime.tm_wday * 1440 + chktime.tm_hour * 60 + chktime.tm_min
1767                                                 chktimecmp_end = chktimecmp + (duration / 60)
1768                                         time = localtime(x.timebegin)
1769                                         for y in range(7):
1770                                                 if x.repeated & (2 ** y):
1771                                                         timecmp = y * 1440 + time.tm_hour * 60 + time.tm_min
1772                                                         if timecmp <= chktimecmp < (timecmp + ((x.timeend - x.timebegin) / 60)):
1773                                                                 time_match = ((timecmp + ((x.timeend - x.timebegin) / 60)) - chktimecmp) * 60
1774                                                         elif chktimecmp <= timecmp < chktimecmp_end:
1775                                                                 time_match = (chktimecmp_end - timecmp) * 60
1776                                 else: 
1777                                         if begin <= x.timebegin <= end:
1778                                                 diff = end - x.timebegin
1779                                                 if time_match < diff:
1780                                                         time_match = diff
1781                                         elif x.timebegin <= begin <= x.timeend:
1782                                                 diff = x.timeend - begin
1783                                                 if time_match < diff:
1784                                                         time_match = diff
1785                                 if time_match:
1786                                         break
1787                 return time_match
1788         
1789         def getClockPixmap(self, refstr, beginTime, duration, eventId):
1790
1791                 pre_clock = 1
1792                 post_clock = 2
1793                 clock_type = 0
1794                 endTime = beginTime + duration
1795                 for x in self.timer_list:
1796                         if x.servicereference.upper() == refstr.upper():
1797                                 if x.eventId == eventId:
1798                                         return self.clock_pixmap
1799                                 beg = x.timebegin
1800                                 end = x.timeend
1801                                 if beginTime > beg and beginTime < end and endTime > end:
1802                                         clock_type |= pre_clock
1803                                 elif beginTime < beg and endTime > beg and endTime < end:
1804                                         clock_type |= post_clock
1805                 if clock_type == 0:
1806                         return self.clock_add_pixmap
1807                 elif clock_type == pre_clock:
1808                         return self.clock_pre_pixmap
1809                 elif clock_type == post_clock:
1810                         return self.clock_post_pixmap
1811                 else:
1812                         return self.clock_prepost_pixmap
1813
1814 class RemoteTimerEventView(Screen):
1815         EMPTY = 0
1816         ADD_TIMER = 1
1817         REMOVE_TIMER = 2
1818         skin = """
1819                 <screen name="RemoteTimerEventView" position="90,95" size="560,430" title="Eventview">
1820                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
1821                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
1822                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
1823                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
1824                         <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
1825                         <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
1826                         <widget name="key_yellow" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
1827                         <widget name="key_blue" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
1828                         <widget name="epg_description" position="10,50" size="540,330" font="Regular;22" />
1829                         <widget name="datetime" position="10,395" size="130,25" font="Regular;22" />
1830                         <widget name="duration" position="140,395" size="100,25" font="Regular;22" />
1831                         <widget name="channel" position="240,395" size="305,25" font="Regular;22" halign="right" />
1832                 </screen>"""
1833         
1834         def __init__(self, session, E2Timerlist, epgdata , User, Pass, http, enigma_type, useinternal):
1835                 self.session = session
1836                 Screen.__init__(self, session)
1837                 self["epg_description"] = ScrollLabel()
1838                 self["datetime"] = Label()
1839                 self["channel"] = Label()
1840                 self["duration"] = Label()
1841                 self["key_red"] = Label() # Dummy, kommt eventuell noch was
1842                 self["key_green"] = Label() # Dummy, kommt eventuell noch was
1843                 self["key_yellow"] = Label() # Dummy, kommt eventuell noch was
1844                 self["key_blue"] = Label() # Dummy, kommt eventuell noch was
1845                 self.key_green_choice = self.ADD_TIMER
1846                 self.onLayoutFinish.append(self.startRun)
1847                 self.E2TimerList = E2Timerlist
1848                 self.epgdata = epgdata
1849                 
1850                 self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions", "EventViewActions"],
1851                 {
1852                         "back": self.close,
1853                         "pageUp": self.pageUp,
1854                         "pageDown": self.pageDown,
1855                 }, -1)
1856                 self.password = Pass
1857                 self.username = User
1858                 self.http = http
1859                 self.enigma_type = enigma_type
1860                 self.useinternal = useinternal
1861         
1862         def startRun(self):
1863                 name = self.epgdata.servicename
1864                 if name != "n/a":
1865                         self["channel"].setText(name)
1866                 else:
1867                         self["channel"].setText(_("unknown service"))
1868                 text = self.epgdata.eventtitle
1869                 short = self.epgdata.eventdescription
1870                 ext = self.epgdata.eventdescriptionextended
1871                 if len(short) > 0 and short != text:
1872                         text = text + '\n\n' + short
1873                 if len(ext) > 0:
1874                         if len(text) > 0:
1875                                 text = text + '\n\n'
1876                         text = text + ext
1877                 self.setTitle(self.epgdata.eventtitle)
1878                 self["epg_description"].setText(text)
1879                 endtime = int(self.epgdata.eventstart + self.epgdata.eventduration)
1880                 t = localtime(self.epgdata.eventstart)
1881                 datetime = ("%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4]))
1882                 duration = (" (%d " + _("mins")+")") % ((self.epgdata.eventduration ) / 60)
1883                 self["datetime"].setText(datetime)
1884                 self["duration"].setText(duration)
1885                 self["key_red"].setText("")     
1886
1887         def pageUp(self):
1888                 self["epg_description"].pageUp()
1889
1890         def pageDown(self):
1891                 self["epg_description"].pageDown()