7121772c69922e5c471cd3cffd1f6094a1b033e2
[enigma2.git] / lib / python / Components / MovieList.py
1 from HTMLComponent import *
2 from GUIComponent import *
3 from Tools.FuzzyDate import FuzzyTime
4
5 from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation
6
7 from enigma import eServiceReference, eServiceCenter, \
8         eServiceCenterPtr, iListableServicePtr, \
9         iStaticServiceInformationPtr
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 # | name of movie              |
25 #
26 def MovieListEntry(serviceref, serviceHandler):
27         res = [ serviceref ]
28
29         info = serviceHandler.info(serviceref)
30         
31         if info is None:
32                 # ignore service which refuse to info
33                 return
34         
35         len = info.getLength(serviceref)
36         if len:
37                 len = "%d:%02d" % (len / 60, len % 60)
38         else:
39                 len = "?:??"
40         
41         res.append((0, 0, 400, 30, 0, RT_HALIGN_LEFT, info.getName(serviceref)))
42         
43         description = info.getInfoString(serviceref, iServiceInformation.sDescription)
44         begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
45         
46         begin_string = ""
47         if begin > 0:
48                 t = FuzzyTime(begin)
49                 begin_string = t[0] + ", " + t[1]
50         
51         res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, description))
52         res.append((0, 50, 200, 20, 1, RT_HALIGN_LEFT, begin_string))
53         res.append((200, 50, 200, 20, 1, RT_HALIGN_RIGHT, len))
54         
55         return res
56
57 class MovieList(HTMLComponent, GUIComponent):
58         def __init__(self, root):
59                 GUIComponent.__init__(self)
60                 self.l = eListboxPythonMultiContent()
61                 self.load(root)
62                 self.l.setList(self.list)
63                 self.l.setFont(0, gFont("Arial", 30))
64                 self.l.setFont(1, gFont("Arial", 18))
65
66         def moveToIndex(self, index):
67                 self.instance.moveSelectionTo(index)
68
69         def getCurrentIndex(self):
70                 return self.instance.getCurrentIndex()
71
72         def getCurrent(self):
73                 return self.l.getCurrentSelection()
74         
75         def GUIcreate(self, parent):
76                 self.instance = eListbox(parent)
77                 self.instance.setContent(self.l)
78                 self.instance.setItemHeight(75)
79         
80         def GUIdelete(self):
81                 self.instance.setContent(None)
82                 self.instance = None
83
84         def load(self, root):
85                 # this lists our root service, then building a 
86                 # nice list
87                 
88                 self.list = [ ]
89                 self.root = root
90                 
91                 serviceHandler = eServiceCenter.getInstance()
92                 list = serviceHandler.list(root)
93                 
94                 if list is None:
95                         raise "listing of movies failed"
96
97                 movieList = [ ]
98                 while 1:
99                         s = list.getNext()
100                         if not s.valid():
101                                 del list
102                                 break
103                         movieList.append(s)
104                 
105                 # now process them...
106                 for ref in movieList:
107                         self.list.append(MovieListEntry(ref, serviceHandler))
108
109         def reload(self):
110                 self.load(self.root)
111                 self.l.setList(self.list)
112
113         def moveDown(self):
114                 self.instance.moveSelection(self.instance.moveDown)