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