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