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