speedup opening of long movielists
[enigma2.git] / lib / python / Components / TimerList.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from Tools.FuzzyDate import FuzzyTime
5 import time
6
7 from enigma import eListboxPythonMultiContent, eListbox, gFont, loadPNG
8 from timer import TimerEntry
9 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
10
11 RT_HALIGN_LEFT = 0
12 RT_HALIGN_RIGHT = 1
13 RT_HALIGN_CENTER = 2
14 RT_HALIGN_BLOCK = 4
15
16 RT_VALIGN_TOP = 0
17 RT_VALIGN_CENTER = 8
18 RT_VALIGN_BOTTOM = 16
19
20 RT_WRAP = 32
21
22
23 #
24 #  | <Service>     <Name of the Timer>  |
25 #  | <start, end>              <state>  |
26 #
27 def TimerEntryComponent(timer, processed):
28         res = [ timer ]
29         
30         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 560, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.service_ref.getServiceName()))
31         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 560, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.name))
32         
33         repeatedtext = ""
34         days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
35         if timer.repeated:
36                 flags = timer.repeated
37                 count = 0
38                 for x in range(0, 7):
39                                 if (flags & 1 == 1):
40                                         if (count != 0):
41                                                 repeatedtext += ", "
42                                         repeatedtext += days[x]
43                                         count += 1
44                                 flags = flags >> 1
45                 if timer.justplay:
46                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s "+ _("(ZAP)")) % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1]))))
47                 else:
48                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1], (timer.end - timer.begin) / 60))))
49         else:
50                 if timer.justplay:
51                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s " + _("(ZAP)")) % (FuzzyTime(timer.begin)))))
52                 else:
53                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:] + ((timer.end - timer.begin) / 60,)))))
54
55         if not processed:
56                 if timer.state == TimerEntry.StateWaiting:
57                         state = _("waiting")
58                 elif timer.state == TimerEntry.StatePrepared:
59                         state = _("about to start")
60                 elif timer.state == TimerEntry.StateRunning:
61                         if timer.justplay:
62                                 state = _("zapped")
63                         else:
64                                 state = _("recording...")
65                 else:
66                         state = _("<unknown>")
67         else:
68                 state = _("done!")
69         
70         res.append((eListboxPythonMultiContent.TYPE_TEXT, 320, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, state))
71
72         if timer.disabled:
73                 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "redx.png"))
74                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 490, 5, 40, 40, png))
75         
76         return res
77
78 class TimerList(HTMLComponent, GUIComponent):
79         def __init__(self, list):
80                 GUIComponent.__init__(self)
81                 self.l = eListboxPythonMultiContent()
82                 self.l.setList(list)
83                 self.l.setFont(0, gFont("Regular", 20))
84                 self.l.setFont(1, gFont("Regular", 18))
85         
86         def getCurrent(self):
87                 return self.l.getCurrentSelection()
88         
89         def GUIcreate(self, parent):
90                 self.instance = eListbox(parent)
91                 self.instance.setContent(self.l)
92                 self.instance.setItemHeight(70)
93
94         def moveToIndex(self, index):
95                 self.instance.moveSelectionTo(index)
96
97         def getCurrentIndex(self):
98                 return self.instance.getCurrentIndex()
99
100         def moveDown(self):
101                 self.instance.moveSelection(self.instance.moveDown)
102
103         def GUIdelete(self):
104                 self.instance.setContent(None)
105                 self.instance = None
106
107         def invalidate(self):
108                 self.l.invalidate()
109