add possible todo regarding mounted/ismount
[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         RT_HALIGN_CENTER, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_CENTER
9 from timer import TimerEntry
10 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
11
12 #
13 #  | <Service>     <Name of the Timer>  |
14 #  | <start, end>              <state>  |
15 #
16 def TimerEntryComponent(timer, processed):
17         res = [ timer ]
18         
19         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 560, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.service_ref.getServiceName()))
20         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 560, 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         res.append((eListboxPythonMultiContent.TYPE_TEXT, 320, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, state))
60
61         if timer.disabled:
62                 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "redx.png"))
63                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 490, 5, 40, 40, png))
64         
65         return res
66
67 class TimerList(HTMLComponent, GUIComponent, object):
68         def __init__(self, list):
69                 GUIComponent.__init__(self)
70                 self.l = eListboxPythonMultiContent()
71                 self.l.setList(list)
72                 self.l.setFont(0, gFont("Regular", 20))
73                 self.l.setFont(1, gFont("Regular", 18))
74         
75         def getCurrent(self):
76                 return self.l.getCurrentSelection()
77         
78         GUI_WIDGET = eListbox
79         
80         def postWidgetCreate(self, instance):
81                 instance.setContent(self.l)
82                 instance.setItemHeight(70)
83
84         def moveToIndex(self, index):
85                 self.instance.moveSelectionTo(index)
86
87         def getCurrentIndex(self):
88                 return self.instance.getCurrentIndex()
89
90         currentIndex = property(moveToIndex, getCurrentIndex)
91         currentSelection = property(getCurrent)
92
93         def moveDown(self):
94                 self.instance.moveSelection(self.instance.moveDown)
95
96         def invalidate(self):
97                 self.l.invalidate()