fix fix...
[enigma2-plugins.git] / partnerbox / src / PartnerboxEPGList.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 Components.EpgList import EPGList
21 from enigma import eListboxPythonMultiContent, \
22         RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_CENTER, RT_HALIGN_CENTER
23
24 from time import localtime
25
26 from Tools.LoadPixmap import LoadPixmap
27 import PartnerboxFunctions as partnerboxfunctions
28
29 baseEPGList__init__ = None
30 basebuildSingleEntry = None
31 basebuildSimilarEntry = None
32 basebuildMultiEntry = None
33
34 def Partnerbox_EPGListInit():
35         global baseEPGList__init__, basebuildSingleEntry, basebuildSimilarEntry, basebuildMultiEntry
36         if baseEPGList__init__ is None:
37                 baseEPGList__init__ = EPGList.__init__
38         if basebuildSingleEntry is None:
39                 basebuildSingleEntry = EPGList.buildSingleEntry
40         if basebuildSimilarEntry is None:
41                 basebuildSimilarEntry = EPGList.buildSimilarEntry
42         if basebuildMultiEntry is None:
43                 basebuildMultiEntry = EPGList.buildMultiEntry
44         if partnerboxfunctions.remote_timer_list is None:
45                 partnerboxfunctions.remote_timer_list = []
46         EPGList.__init__ = Partnerbox_EPGList__init__
47         EPGList.buildSingleEntry = Partnerbox_SingleEntry
48         EPGList.buildSimilarEntry = Partnerbox_SimilarEntry
49         EPGList.buildMultiEntry = Partnerbox_MultiEntry
50
51 def Partnerbox_EPGList__init__(self, type=0, selChangedCB=None, timer = None):
52         baseEPGList__init__(self, type, selChangedCB, timer)
53         # Partnerbox Clock Icons
54         self.remote_clock_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock.png')
55         self.remote_clock_add_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_add.png')
56         self.remote_clock_pre_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_pre.png')
57         self.remote_clock_post_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_post.png')
58         self.remote_clock_prepost_pixmap = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox/icons/remote_epgclock_prepost.png')
59
60 def Partnerbox_SingleEntry(self, service, eventId, beginTime, duration, EventName):
61         rec1=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service))
62         rec2=beginTime and (isInRemoteTimer(self,beginTime, duration, service))
63         r1=self.weekday_rect
64         r2=self.datetime_rect
65         r3=self.descr_rect
66         t = localtime(beginTime)
67         res = [
68                 None, # no private data needed
69                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
70                 (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]))
71         ]
72         if rec1 or rec2:
73                 if rec1:                        
74                         clock_pic = self.getClockPixmap(service, beginTime, duration, eventId)
75                         #eventuell auch in der Partnerbox
76                         if rec2:
77                                 clock_pic_partnerbox = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
78                 else:
79                         clock_pic = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
80                 if rec1 and rec2:
81                         # wenn sowohl lokal als auch auf Partnerbox
82                         res.extend((
83                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
84                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left() + 25, r3.top(), 21, 21, clock_pic_partnerbox),
85                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 50, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)))
86                 else:
87                         res.extend((
88                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
89                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)))
90         else:
91                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
92         return res
93
94
95 def Partnerbox_SimilarEntry(self, service, eventId, beginTime, service_name, duration):
96         rec1=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service))
97         rec2=beginTime and (isInRemoteTimer(self,beginTime, duration, service))
98         r1=self.weekday_rect
99         r2=self.datetime_rect
100         r3=self.service_rect
101         t = localtime(beginTime)
102         res = [
103                 None,  # no private data needed
104                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
105                 (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]))
106         ]
107         if rec1 or rec2:
108                 if rec1:                        
109                         clock_pic = self.getClockPixmap(service, beginTime, duration, eventId)
110                         #eventuell auch in der Partnerbox
111                         if rec2:
112                                 clock_pic_partnerbox = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
113                 else:
114                         clock_pic = getRemoteClockPixmap(self,service, beginTime, duration, eventId)
115                 if rec1 and rec2:
116                         # wenn sowohl lokal als auch auf Partnerbox
117                         res.extend((
118                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
119                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left() + 25, r3.top(), 21, 21, clock_pic_partnerbox),
120                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 50, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)
121                         ))
122                 else:
123                         res.extend((
124                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
125                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)
126                         ))
127         else:
128                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
129         return res
130
131 def Partnerbox_MultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
132         # so wie es aussieht wird der MultiEPG ueber ein Plugin angefahren...lasse den Code dennoch mal drinnen...
133         rec1=begTime and (self.timer.isInTimer(eventId, begTime, duration, service))
134         rec2=begTime and (isInRemoteTimer(self,begTime, duration, service))
135         r1=self.service_rect
136         r2=self.progress_rect
137         r3=self.descr_rect
138         r4=self.start_end_rect
139         res = [ None ] # no private data needed
140         if rec1 or rec2:
141                 if rec1:                        
142                         clock_pic = self.getClockPixmap(service, begTime, duration, eventId)
143                         #eventuell auch in der Partnerbox
144                         if rec2:
145                                 clock_pic_partnerbox = getRemoteClockPixmap(self,service, begTime, duration, eventId)
146                 else:
147                         clock_pic = getRemoteClockPixmap(self,service, begTime, duration, eventId)
148                 if rec1 and rec2:
149                         # wenn sowohl lokal als auch auf Partnerbox
150                         res.extend((
151                                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-41, r1.height(), 0, RT_HALIGN_LEFT, service_name),
152                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-32, r1.top(), 21, 21, clock_pic),
153                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic_partnerbox)
154                         ))
155                 else:
156                         res.extend((
157                                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name),
158                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic)
159                         ))
160         else:
161                 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
162         if begTime is not None:
163                 if nowTime < begTime:
164                         begin = localtime(begTime)
165                         end = localtime(begTime+duration)
166                         res.extend((
167                                 (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])),
168                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
169                         ))
170                 else:
171                         percent = (nowTime - begTime) * 100 / duration
172                         res.extend((
173                                 (eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent),
174                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
175                         ))
176         return res
177
178
179
180 def isInRemoteTimer(self, begin, duration, service):
181         time_match = 0
182         chktime = None
183         chktimecmp = None
184         chktimecmp_end = None
185         end = begin + duration
186         for x in partnerboxfunctions.remote_timer_list:
187                 if x.servicereference.upper() == service.upper():
188                         if x.repeated != 0:
189                                 if chktime is None:
190                                         chktime = localtime(begin)
191                                         chktimecmp = chktime.tm_wday * 1440 + chktime.tm_hour * 60 + chktime.tm_min
192                                         chktimecmp_end = chktimecmp + (duration / 60)
193                                 time = localtime(x.timebegin)
194                                 for y in range(7):
195                                         if x.repeated & (2 ** y):
196                                                 timecmp = y * 1440 + time.tm_hour * 60 + time.tm_min
197                                                 if timecmp <= chktimecmp < (timecmp + ((x.timeend - x.timebegin) / 60)):
198                                                         time_match = ((timecmp + ((x.timeend - x.timebegin) / 60)) - chktimecmp) * 60
199                                                 elif chktimecmp <= timecmp < chktimecmp_end:
200                                                         time_match = (chktimecmp_end - timecmp) * 60
201                         else:
202                                 if begin <= x.timebegin <= end:
203                                         diff = end - x.timebegin
204                                         if time_match < diff:
205                                                 time_match = diff
206                                 elif x.timebegin <= begin <= x.timeend:
207                                         diff = x.timeend - begin
208                                         if time_match < diff:
209                                                 time_match = diff
210                         if time_match:
211                                 break
212         return time_match
213
214
215 def getRemoteClockPixmap(self, refstr, beginTime, duration, eventId):
216         pre_clock = 1
217         post_clock = 2
218         clock_type = 0
219         endTime = beginTime + duration
220         for x in partnerboxfunctions.remote_timer_list:
221                 if x.servicereference.upper() == refstr.upper():
222                         if x.eventId == eventId:
223                                 return self.remote_clock_pixmap
224                         beg = x.timebegin
225                         end = x.timeend
226                         if beginTime > beg and beginTime < end and endTime > end:
227                                 clock_type |= pre_clock
228                         elif beginTime < beg and endTime > beg and endTime < end:
229                                 clock_type |= post_clock
230         if clock_type == 0:
231                 return self.remote_clock_add_pixmap
232         elif clock_type == pre_clock:
233                 return self.remote_clock_pre_pixmap
234         elif clock_type == post_clock:
235                 return self.remote_clock_post_pixmap
236         else:
237                 return self.remote_clock_prepost_pixmap
238