-multiple partnerboxes support
[enigma2-plugins.git] / partnerbox / src / RemoteTimerEntry.py
1 #
2 #  Partnerbox E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2009
7 #  Support: www.dreambox-tools.info
8 #
9 #  This program is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU General Public License
11 #  as published by the Free Software Foundation; either version 2
12 #  of the License, or (at your option) any later version.
13 #
14 #  This program is distributed in the hope that it will be useful,
15 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #  GNU General Public License for more details.
18 #
19
20 from Screens.Screen import Screen
21 import Screens.ChannelSelection
22 from ServiceReference import ServiceReference
23 from Components.config import config, ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
24 from Components.ActionMap import NumberActionMap
25 from Components.ConfigList import ConfigListScreen
26 from Components.MenuList import MenuList
27 from Components.Button import Button
28 from Components.Label import Label
29 from Components.Pixmap import Pixmap
30 from Screens.MovieSelection import getPreferredTagEditor
31 from Screens.LocationBox import MovieLocationBox
32 from Screens.ChoiceBox import ChoiceBox
33 from RecordTimer import AFTEREVENT
34 from Tools.Directories import resolveFilename, SCOPE_HDD
35 from enigma import eEPGCache
36 from time import localtime, mktime, time, strftime
37 from datetime import datetime
38 from Screens.TimerEntry import TimerEntry
39 from Screens.MessageBox import MessageBox
40 from Tools.BoundFunction import boundFunction
41 import urllib
42
43 from twisted.internet import reactor
44 from twisted.web import client
45 from twisted.web.client import HTTPClientFactory
46 from base64 import encodestring
47 import xml.dom.minidom
48
49 from Components.EpgList import EPGList
50 from enigma import eListboxPythonMultiContent, eListbox, gFont, \
51         RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_CENTER, RT_HALIGN_CENTER
52 import xml.dom.minidom
53 from Tools.LoadPixmap import LoadPixmap
54 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
55
56 remote_timer_list = None
57
58
59 class E2Timer:
60         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):
61                 self.servicereference = servicereference
62                 self.servicename = servicename
63                 self.name = name
64                 self.disabled = disabled
65                 self.timebegin = timebegin
66                 self.timeend = timeend
67                 self.duration = duration
68                 self.startprepare = startprepare
69                 self.state = state
70                 self.repeated = repeated
71                 self.justplay = justplay
72                 self.eventId = eventId
73                 self.afterevent = afterevent
74                 self.dirname = dirname
75                 self.description = description
76                 self.type = type
77                 if type != 0: # E1 Timerlist
78                         self.timeend = timebegin + duration
79                         self.name = description
80                         if type & PlaylistEntry.isRepeating:
81                                 self.repeated = 1
82                         self.dirname = "/hdd/movie/"
83
84 def FillE2TimerList(xmlstring):
85         E2TimerList = []
86         dom = xml.dom.minidom.parseString(xmlstring)
87         for node in dom.firstChild.childNodes:
88                 servicereference = ""
89                 servicename = ""
90                 name = ""
91                 disabled = 0
92                 timebegin = 0
93                 timeend = 0
94                 duration = 0
95                 startprepare = 0
96                 state = 0
97                 repeated = 0
98                 justplay = 0
99                 eventId = -1
100                 afterevent = 0
101                 dirname = ""
102                 description = ""
103                 if node.nodeName == "e2timer":
104                         for node2 in node.childNodes:
105                                 if node2.nodeName == "e2servicereference": servicereference = str(node2.firstChild.data.strip().encode("utf-8"))
106                                 if node2.nodeName == "e2servicename":
107                                         try:servicename = str(node2.firstChild.data.strip().encode("utf-8"))
108                                         except:servicename = "n/a"
109                                 if node2.nodeName == "e2eit": 
110                                         try: eventId = int(node2.firstChild.data.strip())
111                                         except: pass
112                                 if node2.nodeName == "e2name":
113                                         try:name = str(node2.firstChild.data.strip().encode("utf-8"))
114                                         except:name = ""
115                                 if node2.nodeName == "e2description":
116                                         try:description = str(node2.firstChild.data.strip().encode("utf-8"))
117                                         except:description = ""
118                                 if node2.nodeName == "e2dirname" or node2.nodeName == "e2location": # vorerst Kompatibilitaet zum alten Webinterface-Api aufrecht erhalten (e2dirname)
119                                         try:dirname = str(node2.firstChild.data.strip().encode("utf-8"))
120                                         except:dirname = ""
121                                 if node2.nodeName == "e2afterevent": afterevent = int(node2.firstChild.data.strip())
122                                 if node2.nodeName == "e2disabled": disabled = int(node2.firstChild.data.strip())
123                                 if node2.nodeName == "e2timebegin": timebegin = int(node2.firstChild.data.strip())
124                                 if node2.nodeName == "e2timeend": timeend = int(node2.firstChild.data.strip())
125                                 if node2.nodeName == "e2duration": duration = int(node2.firstChild.data.strip())
126                                 if node2.nodeName == "e2startprepare": startprepare = int(node2.firstChild.data.strip())
127                                 if node2.nodeName == "e2state":  state= int(node2.firstChild.data.strip())
128                                 if node2.nodeName == "e2justplay":  justplay= int(node2.firstChild.data.strip())
129                                 if node2.nodeName == "e2repeated":
130                                         repeated= int(node2.firstChild.data.strip())
131                                         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 ))
132         return E2TimerList
133
134
135 def FillE1TimerList(xmlstring):
136         E1TimerList = []
137         dom = xml.dom.minidom.parseString(xmlstring)
138         for node in dom.firstChild.childNodes:
139                 type = 0
140                 servicereference = ""
141                 servicename = ""
142                 name = ""
143                 disabled = 0
144                 timebegin = 0
145                 timeend = 0
146                 duration = 0
147                 startprepare = 0
148                 state = 0
149                 repeated = 0
150                 justplay = 0
151                 eventId = -1
152                 afterevent = 0
153                 dirname = ""
154                 description = ""
155                 if node.nodeName == "timer":
156                         for node2 in node.childNodes:
157                                 if node2.nodeName == "typedata": type = int(node2.firstChild.data.strip())
158                                 if node2.nodeName == "service":
159                                         for node3 in node2.childNodes:
160                                                 if node3.nodeName == "reference": servicereference = str(node3.firstChild.data.strip().encode("utf-8"))
161                                                 if node3.nodeName == "name":
162                                                         try:servicename = str(node3.firstChild.data.strip().encode("utf-8"))
163                                                         except:servicename = "n/a"
164                                 if node2.nodeName == "event":
165                                         for node3 in node2.childNodes:
166                                                 if node3.nodeName == "start": timebegin = int(node3.firstChild.data.strip())
167                                                 if node3.nodeName == "duration": duration = int(node3.firstChild.data.strip())
168                                                 if node3.nodeName == "description":
169                                                         try:description = str(node3.firstChild.data.strip().encode("utf-8"))
170                                                         except:description = ""
171                                                         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 ))
172         return E1TimerList
173
174 class myHTTPClientFactory(HTTPClientFactory):
175         def __init__(self, url, method='GET', postdata=None, headers=None,
176         agent="Twisted Remotetimer", timeout=0, cookies=None,
177         followRedirect=1, lastModified=None, etag=None):
178                 HTTPClientFactory.__init__(self, url, method=method, postdata=postdata,
179                 headers=headers, agent=agent, timeout=timeout, cookies=cookies,followRedirect=followRedirect)
180
181
182 def sendPartnerBoxWebCommand(url, contextFactory=None, timeout=60, username = "root", password = "", *args, **kwargs):
183         scheme, host, port, path = client._parse(url)
184         basicAuth = encodestring(("%s:%s")%(username,password))
185         authHeader = "Basic " + basicAuth.strip()
186         AuthHeaders = {"Authorization": authHeader}
187         if kwargs.has_key("headers"):
188                 kwargs["headers"].update(AuthHeaders)
189         else:
190                 kwargs["headers"] = AuthHeaders
191         factory = myHTTPClientFactory(url, *args, **kwargs)
192         reactor.connectTCP(host, port, factory, timeout=timeout)
193         return factory.deferred
194
195 class PlaylistEntry:
196
197         PlaylistEntry=1                 # normal PlaylistEntry (no Timerlist entry)
198         SwitchTimerEntry=2              #simple service switch timer
199         RecTimerEntry=4                 #timer do recording
200         
201         recDVR=8                                #timer do DVR recording
202         recVCR=16                               #timer do VCR recording (LIRC) not used yet
203         recNgrab=131072                 #timer do record via Ngrab Server
204
205         stateWaiting=32                 #timer is waiting
206         stateRunning=64                 #timer is running
207         statePaused=128                 #timer is paused
208         stateFinished=256               #timer is finished
209         stateError=512                  #timer has error state(s)
210
211         errorNoSpaceLeft=1024   #HDD no space Left ( recDVR )
212         errorUserAborted=2048   #User Action aborts this event
213         errorZapFailed=4096             #Zap to service failed
214         errorOutdated=8192              #Outdated event
215
216         boundFile=16384                 #Playlistentry have an bounded file
217         isSmartTimer=32768              #this is a smart timer (EIT related) not uses Yet
218         isRepeating=262144              #this timer is repeating
219         doFinishOnly=65536              #Finish an running event/action
220
221         doShutdown=67108864             #timer shutdown the box
222         doGoSleep=134217728             #timer set box to standby
223
224         Su=524288
225         Mo=1048576
226         Tue=2097152
227         Wed=4194304
228         Thu=8388608
229         Fr=16777216
230         Sa=33554432
231
232 class RemoteTimerEntry(Screen, ConfigListScreen):
233         skin = """
234                 <screen name="RemoteTimerEntry" position="90,95" size="560,430" title="Timer entry">
235                         <widget name="cancel" pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
236                         <widget name="ok" pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
237                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
238                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
239                         <widget name="canceltext" position="0,0" zPosition="2" size="140,40" halign="center" valign="center" font="Regular;21" backgroundColor="#9f1313" transparent="1" />
240                         <widget name="oktext" position="140,0" zPosition="2" size="140,40" halign="center" valign="center" font="Regular;21" backgroundColor="#1f771f" transparent="1" />
241                         <widget name="config" position="10,45" size="540,385" scrollbarMode="showOnDemand" />
242                 </screen>"""
243
244         def __init__(self, session, timer, Locations):
245                 self.session = session
246                 Screen.__init__(self, session)
247                 self.timer = timer
248                 self.Locations = Locations
249                 self.entryDate = None
250                 self.entryService = None
251                 self["oktext"] = Label(_("OK"))
252                 self["canceltext"] = Label(_("Cancel"))
253                 self["ok"] = Pixmap()
254                 self["cancel"] = Pixmap()
255                 self.createConfig()
256                 self["actions"] = NumberActionMap(["SetupActions", "GlobalActions", "PiPSetupActions"],
257                 {
258                         "save": self.keyGo,
259                         "cancel": self.keyCancel,
260                         "volumeUp": self.incrementStart,
261                         "volumeDown": self.decrementStart,
262                         "size+": self.incrementEnd,
263                         "size-": self.decrementEnd
264                 }, -2)
265                 self.list = []
266                 ConfigListScreen.__init__(self, self.list, session = session)
267                 self.createSetup("config")
268
269         def createConfig(self):
270                 
271                 if self.timer.type == 0:
272                         justplay = self.timer.justplay
273                         afterevent = {
274                                 0: "nothing",
275                                 2: "deepstandby",
276                                 1: "standby",
277                                 3: "auto"
278                                 }[self.timer.afterevent]
279                 else:
280                         if self.timer.type & PlaylistEntry.doShutdown:
281                                 afterevent = PlaylistEntry.doShutdown
282                         elif self.timer.type & PlaylistEntry.doGoSleep:
283                                 afterevent = PlaylistEntry.doGoSleep
284                         else:
285                                 afterevent = 0
286                 
287                         if self.timer.type & PlaylistEntry.RecTimerEntry:
288                                 if self.timer.type & PlaylistEntry.recDVR:
289                                         justplay = PlaylistEntry.recDVR
290                                 elif self.timer.type & PlaylistEntry.recNgrab:
291                                         justplay = PlaylistEntry.recNgrab
292                         elif self.timer.type & PlaylistEntry.SwitchTimerEntry:
293                                 justplay = PlaylistEntry.SwitchTimerEntry
294                 
295                 weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
296                 day = []
297                 weekday = 0
298                 for x in (0, 1, 2, 3, 4, 5, 6):
299                         day.append(0)
300                 begin = self.timer.timebegin
301                 end = self.timer.timeend
302                 weekday = (int(strftime("%w", localtime(begin))) - 1) % 7
303                 day[weekday] = 1
304                 name = self.timer.name 
305                 description = self.timer.description
306                 if self.timer.type == 0:
307                         self.timerentry_justplay = ConfigSelection(choices = [("1", _("zap")), ("0", _("record"))], default = str(justplay))
308                         self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
309                         self.timerentry_name = ConfigText(default = name, visible_width = 50, fixed_size = False)
310                 else:
311                         self.timerentry_justplay = ConfigSelection(choices = [(str(PlaylistEntry.SwitchTimerEntry), _("zap")), (str(PlaylistEntry.recNgrab), _("NGRAB")),(str(PlaylistEntry.recDVR), _("DVR"))], default = str(justplay))
312                         self.timerentry_afterevent = ConfigSelection(choices = [("0", _("do nothing")), (str(PlaylistEntry.doGoSleep), _("go to standby")), (str(PlaylistEntry.doShutdown), _("go to deep standby"))], default = str(afterevent))
313                 self.timerentry_description = ConfigText(default = description, visible_width = 50, fixed_size = False)
314                 self.timerentry_date = ConfigDateTime(default = begin, formatstring = _("%d.%B %Y"), increment = 86400)
315                 self.timerentry_starttime = ConfigClock(default = begin)
316                 self.timerentry_endtime = ConfigClock(default = end)
317                 if self.timer.type == 0:
318                         default = self.timer.dirname
319                         if default not in self.Locations:
320                                 self.Locations.append(default)
321                         self.timerentry_dirname = ConfigSelection(default = default, choices = self.Locations)
322                 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
323                 self.timerentry_day = ConfigSubList()
324                 for x in (0, 1, 2, 3, 4, 5, 6):
325                         self.timerentry_day.append(ConfigYesNo(default = day[x]))
326                 servicename = self.timer.servicename
327                 self.timerentry_service = ConfigSelection([servicename])
328
329         def createSetup(self, widget):
330                 self.list = []
331                 if self.timer.type == 0:
332                         self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
333                 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
334                 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
335                 self.list.append(self.timerJustplayEntry)
336                 self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
337                 self.list.append(self.entryDate)
338                 self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
339                 self.list.append(self.entryStartTime)
340                 if self.timer.type == 0:
341                         if int(self.timerentry_justplay.value) != 1:
342                                 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
343                                 self.list.append(self.entryEndTime)
344                         else:
345                                 self.entryEndTime = None
346                 else:
347                         self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
348                         self.list.append(self.entryEndTime)
349                 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
350                 self.list.append(self.channelEntry)
351                 if self.timer.type == 0:
352                         self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
353                         if int(self.timerentry_justplay.value) != 1:
354                                 self.list.append(self.dirname)
355                                 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
356                 else:
357                         self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
358                 self[widget].list = self.list
359                 self[widget].l.setList(self.list)
360                 
361         def newConfig(self):
362                 if self["config"].getCurrent() == self.timerJustplayEntry:
363                         self.createSetup("config")
364                         
365         def keyLeft(self):
366                 ConfigListScreen.keyLeft(self)
367                 self.newConfig()
368
369         def keyRight(self):
370                 ConfigListScreen.keyRight(self)
371                 self.newConfig()
372                 
373         def getTimestamp(self, date, mytime):
374                 d = localtime(date)
375                 dt = datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
376                 return int(mktime(dt.timetuple()))
377
378         def getBeginEnd(self):
379                 date = self.timerentry_date.value
380                 endtime = self.timerentry_endtime.value
381                 starttime = self.timerentry_starttime.value
382                 begin = self.getTimestamp(date, starttime)
383                 end = self.getTimestamp(date, endtime)
384                 if end < begin:
385                         end += 86400
386                 return begin, end
387
388         def keyCancel(self):
389                 self.close((False,))
390                 
391         def keyGo(self):
392                 if self.timer.type == 0:
393                         self.timer.name = self.timerentry_name.value
394                         self.timer.dirname = self.timerentry_dirname.value
395                         self.timer.afterevent = {
396                         "nothing": 0,
397                         "deepstandby": 2,
398                         "standby": 1,
399                         "auto": 3
400                         }[self.timerentry_afterevent.value]
401                 else:
402                         self.timer.afterevent = int(self.timerentry_afterevent.value)
403                 self.timer.description = self.timerentry_description.value
404                 self.timer.justplay = int(self.timerentry_justplay.value)
405                 
406                 self.timer.timebegin, self.timer.timeend = self.getBeginEnd()
407                 self.close((True, self.timer))
408
409         def incrementStart(self):
410                 self.timerentry_starttime.increment()
411                 self["config"].invalidate(self.entryStartTime)
412
413         def decrementStart(self):
414                 self.timerentry_starttime.decrement()
415                 self["config"].invalidate(self.entryStartTime)
416
417         def incrementEnd(self):
418                 if self.entryEndTime is not None:
419                         self.timerentry_endtime.increment()
420                         self["config"].invalidate(self.entryEndTime)
421
422         def decrementEnd(self):
423                 if self.entryEndTime is not None:
424                         self.timerentry_endtime.decrement()
425                         self["config"].invalidate(self.entryEndTime)
426                         
427                         
428                         
429 # ##########################################
430 # TimerEntry
431 # ##########################################
432 baseTimerEntrySetup = None
433 baseTimerEntryGo = None
434 baseTimerEntrynewConfig = None
435 baseTimerkeyLeft = None
436 baseTimerkeyRight = None
437 baseTimerkeySelect = None
438 baseTimercreateConfig = None
439
440 def RemoteTimerInit():
441         global baseTimerEntrySetup, baseTimerEntryGo, baseTimerEntrynewConfig, baseTimerkeyLeft, baseTimerkeyRight, baseTimerkeySelect, baseTimercreateConfig
442         if baseTimerEntrySetup is None:
443                 baseTimerEntrySetup = TimerEntry.createSetup
444         if baseTimerEntryGo is None:
445                 baseTimerEntryGo = TimerEntry.keyGo
446         if baseTimerEntrynewConfig is None:
447                 baseTimerEntrynewConfig = TimerEntry.newConfig
448         if baseTimerkeyLeft is None:
449                 baseTimerkeyLeft = TimerEntry.keyLeft
450         if baseTimerkeyRight is None:
451                 baseTimerkeyRight = TimerEntry.keyRight
452         if baseTimerkeySelect is None:
453                 baseTimerkeySelect = TimerEntry.keySelect
454         if baseTimercreateConfig is None:
455                 baseTimercreateConfig  = TimerEntry.createConfig
456         
457         TimerEntry.createConfig = RemoteTimerConfig
458         TimerEntry.keyLeft = RemoteTimerkeyLeft 
459         TimerEntry.keyRight = RemoteTimerkeyRight
460         TimerEntry.keySelect = RemoteTimerkeySelect
461         TimerEntry.createSetup = createRemoteTimerSetup
462         TimerEntry.keyGo = RemoteTimerGo
463         TimerEntry.newConfig = RemoteTimernewConfig
464         
465 def RemoteTimerConfig(self):
466         self.Locations = []
467         self.entryguilist = []
468         self.entryguilist.append(("0",_("Nein"),None))
469         index = 1
470         for c in config.plugins.Partnerbox.Entries:
471                 self.entryguilist.append((str(index),str(c.name.value),c))
472                 index = index + 1
473         self.timerentry_remote = ConfigSelection(default = "0", choices = self.entryguilist)
474         baseTimercreateConfig(self)
475
476 #def getLocationsError(self, error):
477 #       RemoteTimercreateConfig(self)
478 #       RemoteTimerCreateSetup(self,"config")
479         
480 def getLocationsCallback(self, xmlstring):
481         self.Locations = []
482         dom = xml.dom.minidom.parseString(xmlstring)
483         for node in dom.firstChild.childNodes:
484                 dirname = ""
485                 if node.nodeName == "e2simplexmlitem" or node.nodeName == "e2location": # vorerst Kompatibilitaet zum alten Webinterface-Api aufrecht erhalten (e2simplexmlitem)
486                         dirname = str(node.firstChild.data.strip().encode("utf-8"))
487                         self.Locations.append(dirname)
488                 
489 def createRemoteTimerSetup(self, widget):
490         baseTimerEntrySetup(self, widget)
491         self.display = _("Remote Timer")
492         self.timerRemoteEntry = getConfigListEntry(self.display, self.timerentry_remote)
493         self.list.insert(0, self.timerRemoteEntry)
494         self[widget].list = self.list
495         
496 def RemoteTimerkeyLeft(self):
497         if int(self.timerentry_remote.value) != 0:
498                 ConfigListScreen.keyLeft(self)
499                 RemoteTimernewConfig(self)
500         else:
501                 baseTimerkeyLeft(self)
502
503 def RemoteTimerkeyRight(self):
504         if int(self.timerentry_remote.value) != 0:
505                 ConfigListScreen.keyRight(self)
506                 RemoteTimernewConfig(self)
507         else:
508                 baseTimerkeyRight(self)
509
510 def RemoteTimerkeySelect(self):
511         if int(self.timerentry_remote.value) != 0:
512                 RemoteTimerGo(self)
513         else:
514                 baseTimerkeySelect(self)
515         
516         
517 def RemoteTimernewConfig(self):
518         if self["config"].getCurrent() == self.timerRemoteEntry:
519                 if int(self.timerentry_remote.value) != 0:
520                         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 1: # E1
521                                 self.timertype = PlaylistEntry.RecTimerEntry|PlaylistEntry.recDVR
522                         else: # E2
523                                 self.timertype = 0
524                                 ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
525                                 port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
526                                 http_ = "%s:%d" % (ip,port)
527                                 sCommand = "http://root:" + self.entryguilist[int(self.timerentry_remote.value)][2].password.value + "@" + http_ + "/web/getlocations"
528                                 #sCommand = self.http + "/web/getlocations"
529                                 #sendPartnerBoxWebCommand(sCommand, None,3, self.username, self.password).addCallback(boundFunction(getLocationsCallback,self)).addErrback(boundFunction(getLocationsError,self))
530                                 # ich mach das besser synchron, falls die Partnerbox aus ist ( dann koennte man hier schon abbrechen und eine Meldung bringen...)
531                                 try:
532                                         f = urllib.urlopen(sCommand)
533                                         sxml = f.read()
534                                         getLocationsCallback(self,sxml)
535                                 except: pass
536                         RemoteTimercreateConfig(self)
537                         RemoteTimerCreateSetup(self,"config")
538                 else:
539                         baseTimercreateConfig(self)
540                         createRemoteTimerSetup(self, "config")
541         elif self["config"].getCurrent() == self.timerJustplayEntry:
542                 if int(self.timerentry_remote.value) != 0:
543                         RemoteTimerCreateSetup(self,"config")
544                 else:
545                         baseTimerEntrynewConfig(self)
546         else:
547                         if int(self.timerentry_remote.value) == 0:
548                                 baseTimerEntrynewConfig(self)
549         
550 def  RemoteTimercreateConfig(self):
551         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
552                 justplay = self.timer.justplay
553                 afterevent = {
554                         AFTEREVENT.NONE: "nothing",
555                         AFTEREVENT.DEEPSTANDBY: "deepstandby",
556                          AFTEREVENT.STANDBY: "standby",
557                          AFTEREVENT.AUTO: "auto"
558                         }[self.timer.afterEvent]
559         else:
560                 if self.timertype & PlaylistEntry.doShutdown:
561                         afterevent = PlaylistEntry.doShutdown
562                 elif self.timertype & PlaylistEntry.doGoSleep:
563                         afterevent = PlaylistEntry.doGoSleep
564                 else:
565                         afterevent = 0
566                 if self.timertype & PlaylistEntry.RecTimerEntry:
567                         if self.timertype & PlaylistEntry.recDVR:
568                                 justplay = PlaylistEntry.recDVR
569                         elif self.timertype & PlaylistEntry.recNgrab:
570                                 justplay = PlaylistEntry.recNgrab
571                 elif self.timertype & PlaylistEntry.SwitchTimerEntry:
572                         justplay = PlaylistEntry.SwitchTimerEntry
573         weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
574         day = []
575         weekday = 0
576         for x in (0, 1, 2, 3, 4, 5, 6):
577                 day.append(0)
578         begin = self.timer.begin
579         end = self.timer.end
580         weekday = (int(strftime("%w", localtime(begin))) - 1) % 7
581         day[weekday] = 1
582         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
583                 name = self.timer.name 
584                 description = self.timer.description
585                 self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
586                 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
587                 self.timerentry_name = ConfigText(default = name, visible_width = 50, fixed_size = False)
588         else:
589                 description = self.timer.name 
590                 self.timerentry_justplay = ConfigSelection(choices = [(str(PlaylistEntry.SwitchTimerEntry), _("zap")), (str(PlaylistEntry.recNgrab), _("NGRAB")),(str(PlaylistEntry.recDVR), _("DVR"))], default = str(justplay))
591                 self.timerentry_afterevent = ConfigSelection(choices = [("0", _("do nothing")), (str(PlaylistEntry.doGoSleep), _("go to standby")), (str(PlaylistEntry.doShutdown), _("go to deep standby"))], default = str(afterevent))
592         self.timerentry_description = ConfigText(default = description, visible_width = 50, fixed_size = False)
593         self.timerentry_date = ConfigDateTime(default = begin, formatstring = _("%d.%B %Y"), increment = 86400)
594         self.timerentry_starttime = ConfigClock(default = begin)
595         self.timerentry_endtime = ConfigClock(default = end)
596         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
597                 default = "/hdd/movie/"
598                 if default not in self.Locations:
599                         self.Locations.append(default)
600                 self.timerentry_dirname = ConfigSelection(default = default, choices = self.Locations)
601         self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
602         self.timerentry_day = ConfigSubList()
603         for x in (0, 1, 2, 3, 4, 5, 6):
604                 self.timerentry_day.append(ConfigYesNo(default = day[x]))
605         # FIXME some service-chooser needed here
606         servicename = "N/A"
607         try: # no current service available?
608                 servicename = str(self.timer.service_ref.getServiceName())
609         except:
610                 pass
611         self.timerentry_service_ref = self.timer.service_ref
612         self.timerentry_service = ConfigSelection([servicename])
613
614 def RemoteTimerCreateSetup(self, widget):
615         self.list = []
616         self.timerRemoteEntry = getConfigListEntry(self.display, self.timerentry_remote)
617         self.list.append(self.timerRemoteEntry)
618         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
619                 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
620         self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
621         self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
622         self.list.append(self.timerJustplayEntry)
623         self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
624         self.list.append(self.entryDate)
625         self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
626         self.list.append(self.entryStartTime)
627         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
628                 if self.timerentry_justplay.value != "zap":
629                         self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
630                         self.list.append(self.entryEndTime)
631                 else:
632                         self.entryEndTime = None
633         else:
634                 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
635                 self.list.append(self.entryEndTime)
636         self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
637         self.list.append(self.channelEntry)
638         if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 0:
639                 self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
640                 if self.timerentry_justplay.value != "zap":
641                         self.list.append(self.dirname)
642                         self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
643         else:
644                 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
645         self[widget].list = self.list
646         self[widget].l.setList(self.list)
647
648 def RemoteTimerGo(self):
649         if int(self.timerentry_remote.value) == 0:
650                 baseTimerEntryGo(self)
651         else:
652                 service_ref = self.timerentry_service_ref
653                 descr = urllib.quote(self.timerentry_description.value)
654                 begin, end = self.getBeginEnd()
655                 ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
656                 port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
657                 http = "http://%s:%d" % (ip,port)
658                 if int(self.entryguilist[int(self.timerentry_remote.value)][2].enigma.value) == 1:
659                         # E1
660                         afterevent = self.timerentry_afterevent.value
661                         justplay = int(self.timerentry_justplay.value)
662                         if justplay & PlaylistEntry.SwitchTimerEntry:
663                                 action = "zap"
664                         elif justplay & PlaylistEntry.recNgrab:
665                                 action = "ngrab"
666                         else:
667                                 action = ""
668                         # FIXME some service-chooser needed here
669                         servicename = "N/A"
670                         try: # no current service available?
671                                 servicename = str(service_ref .getServiceName())
672                         except:
673                                 pass
674                         channel = urllib.quote(servicename)
675                         sCommand = "%s/addTimerEvent?ref=%s&start=%d&duration=%d&descr=%s&channel=%s&after_event=%s&action=%s" % (http, service_ref , begin, end - begin, descr, channel, afterevent, action)
676                         sendPartnerBoxWebCommand(sCommand, None,3, "root", str(self.entryguilist[int(self.timerentry_remote.value)][2].password.value)).addCallback(boundFunction(AddTimerE1Callback,self, self.session)).addErrback(boundFunction(AddTimerError,self, self.session))
677                 else:
678                         # E2
679                         name = urllib.quote(self.timerentry_name.value)
680                         self.timer.tags = self.timerentry_tags
681                         if self.timerentry_justplay.value == "zap":
682                                 justplay = 1
683                                 dirname = ""
684                         else:
685                                 justplay = 0
686                                 dirname = urllib.quote(self.timerentry_dirname.value)
687                         afterevent = {
688                         "deepstandby": AFTEREVENT.DEEPSTANDBY,
689                         "standby": AFTEREVENT.STANDBY,
690                         }.get(self.timerentry_afterevent.value, AFTEREVENT.NONE)
691                         sCommand = "%s/web/timeradd?sRef=%s&begin=%d&end=%d&name=%s&description=%s&dirname=%s&eit=0&justplay=%d&afterevent=%s" % (http, service_ref,begin,end,name,descr,dirname,justplay,afterevent)
692                         sendPartnerBoxWebCommand(sCommand, None,3, "root", str(self.entryguilist[int(self.timerentry_remote.value)][2].password.value)).addCallback(boundFunction(AddTimerE2Callback,self, self.session)).addErrback(boundFunction(AddTimerError,self,self.session))
693
694 def AddTimerE2Callback(self, session, answer):
695         text = ""
696         dom = xml.dom.minidom.parseString(answer)
697         for node in dom.firstChild.childNodes:
698                 dirname = ""
699                 if node.nodeName == "e2statetext":
700                         text = str(node.firstChild.data.strip().encode("utf-8"))
701         ok = text == "Timer added successfully!"
702         session.open(MessageBox,_("Partnerbox Answer: \n%s") % (text),MessageBox.TYPE_INFO, timeout = 3)
703         if ok:
704                 if (int(self.timerentry_remote.value) == 1 and config.plugins.Partnerbox.enablepartnerboxepglist.value): # nur, wenn Partnerbox1 gewaehlt wurde
705                         # Timerlist der Partnerbox neu laden --> Anzeige fuer EPGList
706                         global remote_timer_list
707                         remote_timer_list = [] 
708                         password = self.entryguilist[int(self.timerentry_remote.value)][2].password.value
709                         username = "root"
710                         ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
711                         port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
712                         sCommand = "http://%s:%s@%s:%d/web/timerlist" % (username, password, ip,port)
713                         print "[RemoteTimer] Getting timerlist data from %s..."%ip
714                         try:
715                                 f = urllib.urlopen(sCommand)
716                                 sxml = f.read()
717                                 remote_timer_list = FillE2TimerList(sxml)
718                         except: pass
719                 self.keyCancel()
720
721 def AddTimerE1Callback(self, session, answer):
722         ok = answer == "Timer event was created successfully."
723         session.open(MessageBox,_("Partnerbox Answer: \n%s") % (answer),MessageBox.TYPE_INFO, timeout = 3)
724         if ok:
725                 
726                 if (int(self.timerentry_remote.value) == 1 and config.plugins.Partnerbox.enablepartnerboxepglist.value): # nur, wenn Partnerbox1 gewaehlt wurde
727                         # Timerlist der Partnerbox neu laden --> Anzeige fuer EPGList
728                         global remote_timer_list
729                         remote_timer_list = []
730                         password = self.entryguilist[int(self.timerentry_remote.value)][2].password.value
731                         username = "root"
732                         ip = "%d.%d.%d.%d" % tuple(self.entryguilist[int(self.timerentry_remote.value)][2].ip.value)
733                         port = self.entryguilist[int(self.timerentry_remote.value)][2].port.value
734                         sCommand = "http://%s:%s@%s:%d/xml/timers" % (username, password, ip,port)
735                         print "[RemoteTimer] Getting timerlist data from %s..."%ip
736                         try:
737                                 f = urllib.urlopen(sCommand)
738                                 sxml = f.read()
739                                 remote_timer_list = FillE1TimerList(sxml)
740                         except: pass
741                 self.keyCancel()
742                 
743 def AddTimerError(self, session, error):
744         session.open(MessageBox,str(error.getErrorMessage()),MessageBox.TYPE_INFO)
745         
746
747
748 # ##########################################
749 # EPGList
750 # ##########################################
751 baseEPGList__init__ = None
752 basebuildSingleEntry = None
753 basebuildSimilarEntry = None
754 basebuildMultiEntry = None
755
756 def Partnerbox_EPGListInit():
757         global baseEPGList__init__, basebuildSingleEntry, basebuildSimilarEntry, basebuildMultiEntry, remote_timer_list
758         if baseEPGList__init__ is None:
759                 baseEPGList__init__ = EPGList.__init__
760         if basebuildSingleEntry is None:
761                 basebuildSingleEntry = EPGList.buildSingleEntry
762         if basebuildSimilarEntry is None:
763                 basebuildSimilarEntry = EPGList.buildSimilarEntry
764         if basebuildMultiEntry is None:
765                 basebuildMultiEntry = EPGList.buildMultiEntry
766         if remote_timer_list is None:
767                 remote_timer_list = []
768         EPGList.__init__ = Partnerbox_EPGList__init__
769         EPGList.buildSingleEntry = Partnerbox_SingleEntry
770         EPGList.buildSimilarEntry = Partnerbox_SimilarEntry
771         EPGList.buildMultiEntry = Partnerbox_MultiEntry
772
773 def Partnerbox_EPGList__init__(self, type=0, selChangedCB=None, timer = None):
774         global remote_timer_list
775         remote_timer_list = []
776         if int(config.plugins.Partnerbox.entriescount.value) >= 1:
777                 try:
778                         partnerboxentry = config.plugins.Partnerbox.Entries[0]
779                         password = partnerboxentry.password.value
780                         username = "root"
781                         ip = "%d.%d.%d.%d" % tuple(partnerboxentry.ip.value)
782                         port = partnerboxentry.port.value
783                         if int(partnerboxentry.enigma.value) == 0:
784                                 sCommand = "http://%s:%s@%s:%d/web/timerlist" % (username, password, ip,port)
785                         else:
786                                 sCommand = "http://%s:%s@%s:%d/xml/timers" % (username, password, ip,port)
787                         print "[RemoteEPGList] Getting timerlist data from %s..."%ip
788                         f = urllib.urlopen(sCommand)
789                         sxml = f.read()
790                         if int(partnerboxentry.enigma.value) == 0:
791                                 remote_timer_list = FillE2TimerList(sxml)
792                         else:
793                                 remote_timer_list = FillE1TimerList(sxml)
794                 except: pass
795         # Partnerbox Clock Icons
796         self.remote_clock_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock.png')
797         self.remote_clock_add_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_add.png')
798         self.remote_clock_pre_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_pre.png')
799         self.remote_clock_post_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_post.png')
800         self.remote_clock_prepost_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_prepost.png')
801         baseEPGList__init__(self, type, selChangedCB, timer)
802
803 def Partnerbox_SingleEntry(self, service, eventId, beginTime, duration, EventName):
804         rec1=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service))
805         rec2=beginTime and (isInRemoteTimer(self,beginTime, duration, service))
806         r1=self.weekday_rect
807         r2=self.datetime_rect
808         r3=self.descr_rect
809         t = localtime(beginTime)
810         res = [
811                 None, # no private data needed
812                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
813                 (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]))
814         ]
815         if rec1 or rec2:
816                 if rec1:                        
817                         clock_pic = self.getClockPixmap(service, beginTime, duration, eventId)
818                         #eventuell auch in der Partnerbox
819                         if rec2:
820                                 clock_pic_partnerbox = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
821                 else:
822                         clock_pic = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
823                 if rec1 and rec2:
824                         # wenn sowohl lokal als auch auf Partnerbox
825                         res.extend((
826                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
827                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left() + 25, r3.top(), 21, 21, clock_pic_partnerbox),
828                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 50, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)))
829                 else:
830                         res.extend((
831                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
832                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)))
833         else:
834                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
835         return res
836
837
838 def Partnerbox_SimilarEntry(self, service, eventId, beginTime, service_name, duration):
839         rec1=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service))
840         rec2=beginTime and (isInRemoteTimer(self,beginTime, duration, service))
841         r1=self.weekday_rect
842         r2=self.datetime_rect
843         r3=self.service_rect
844         t = localtime(beginTime)
845         res = [
846                 None,  # no private data needed
847                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
848                 (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]))
849         ]
850         if rec1 or rec2:
851                 if rec1:                        
852                         clock_pic = self.getClockPixmap(service, beginTime, duration, eventId)
853                         #eventuell auch in der Partnerbox
854                         if rec2:
855                                 clock_pic_partnerbox = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
856                 else:
857                         clock_pic = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
858                 if rec1 and rec2:
859                         # wenn sowohl lokal als auch auf Partnerbox
860                         res.extend((
861                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
862                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left() + 25, r3.top(), 21, 21, clock_pic_partnerbox),
863                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 50, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)
864                         ))
865                 else:
866                         res.extend((
867                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
868                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)
869                         ))
870         else:
871                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
872         return res
873
874 def Partnerbox_MultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
875         # so wie es aussieht wird der MultiEPG ueber ein Plugin angefahren...lasse den Code dennoch mal drinnen...
876         rec1=begTime and (self.timer.isInTimer(eventId, begTime, duration, service))
877         rec2=begTime and (isInRemoteTimer(self,begTime, duration, service))
878         r1=self.service_rect
879         r2=self.progress_rect
880         r3=self.descr_rect
881         r4=self.start_end_rect
882         res = [ None ] # no private data needed
883         if rec1 or rec2:
884                 if rec1:                        
885                         clock_pic = self.getClockPixmap(service, begTime, duration, eventId)
886                         #eventuell auch in der Partnerbox
887                         if rec2:
888                                 clock_pic_partnerbox = getRemoteClockPixmap(self,service, begTime, duration, eventId)
889                 else:
890                         clock_pic = getRemoteClockPixmap(self,service, begTime, duration, eventId)
891                 if rec1 and rec2:
892                         # wenn sowohl lokal als auch auf Partnerbox
893                         res.extend((
894                                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-41, r1.height(), 0, RT_HALIGN_LEFT, service_name),
895                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-32, r1.top(), 21, 21, clock_pic),
896                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic_partnerbox)
897                         ))
898                 else:
899                         res.extend((
900                                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name),
901                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic)
902                         ))
903         else:
904                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
905         if begTime is not None:
906                 if nowTime < begTime:
907                         begin = localtime(begTime)
908                         end = localtime(begTime+duration)
909                         res.extend((
910                                 (eListboxPythonMultiContent.TYPE_TEXT, r4.left(), r4.top(), r4.width(), r4.height(), 1, RT_HALIGN_CENTER|RT_VALIGN_CENTER, "%02d.%02d - %02d.%02d"%(begin[3],begin[4],end[3],end[4])),
911                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
912                         ))
913                 else:
914                         percent = (nowTime - begTime) * 100 / duration
915                         res.extend((
916                                 (eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent),
917                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
918                         ))
919         return res
920
921
922
923 def isInRemoteTimer(self, begin, duration, service):
924         global remote_timer_list
925         time_match = 0
926         chktime = None
927         chktimecmp = None
928         chktimecmp_end = None
929         end = begin + duration
930         for x in remote_timer_list:
931                 print "------------>begin = %d,  x.timebegin = %d, end = %d" % (begin, x.timebegin, end)
932                 print "------------>service = %s, x.servicereference = %s" % (service, x.servicereference)
933                 if x.servicereference.upper() == service.upper():
934                         if x.repeated != 0:
935                                 if chktime is None:
936                                         chktime = localtime(begin)
937                                         chktimecmp = chktime.tm_wday * 1440 + chktime.tm_hour * 60 + chktime.tm_min
938                                         chktimecmp_end = chktimecmp + (duration / 60)
939                                 time = localtime(x.timebegin)
940                                 for y in range(7):
941                                         if x.repeated & (2 ** y):
942                                                 timecmp = y * 1440 + time.tm_hour * 60 + time.tm_min
943                                                 if timecmp <= chktimecmp < (timecmp + ((x.timeend - x.timebegin) / 60)):
944                                                         time_match = ((timecmp + ((x.timeend - x.timebegin) / 60)) - chktimecmp) * 60
945                                                 elif chktimecmp <= timecmp < chktimecmp_end:
946                                                         time_match = (chktimecmp_end - timecmp) * 60
947                         else:
948                                 if begin <= x.timebegin <= end:
949                                         diff = end - x.timebegin
950                                         if time_match < diff:
951                                                 time_match = diff
952                                 elif x.timebegin <= begin <= x.timeend:
953                                         diff = x.timeend - begin
954                                         if time_match < diff:
955                                                 time_match = diff
956                         if time_match:
957                                 break
958         return time_match
959
960
961 def getRemoteClockPixmap(self, refstr, beginTime, duration, eventId):
962         global remote_timer_list
963         pre_clock = 1
964         post_clock = 2
965         clock_type = 0
966         endTime = beginTime + duration
967         for x in remote_timer_list:
968                 if x.servicereference.upper() == refstr.upper():
969                         if x.eventId == eventId:
970                                 return self.remote_clock_pixmap
971                         beg = x.timebegin
972                         end = x.timeend
973                         if beginTime > beg and beginTime < end and endTime > end:
974                                 clock_type |= pre_clock
975                         elif beginTime < beg and endTime > beg and endTime < end:
976                                 clock_type |= post_clock
977         if clock_type == 0:
978                 return self.remote_clock_add_pixmap
979         elif clock_type == pre_clock:
980                 return self.remote_clock_pre_pixmap
981         elif clock_type == post_clock:
982                 return self.remote_clock_post_pixmap
983         else:
984                 return self.remote_clock_prepost_pixmap