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