2e010ab6964897ad640c62739ddc5e2db1591702
[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 getCurrent(self):
67                 return self.l.getCurrentSelection()
68         
69         def GUIcreate(self, parent):
70                 self.instance = eListbox(parent)
71                 self.instance.setContent(self.l)
72                 self.instance.setItemHeight(75)
73         
74         def GUIdelete(self):
75                 self.instance.setContent(None)
76                 self.instance = None
77
78         def load(self, root):
79                 # this lists our root service, then building a 
80                 # nice list
81                 
82                 self.list = [ ]
83                 self.root = root
84                 
85                 serviceHandler = eServiceCenter.getInstance()
86                 list = serviceHandler.list(root)
87                 
88                 if list is None:
89                         raise "listing of movies failed"
90
91                 movieList = [ ]
92                 while 1:
93                         s = list.getNext()
94                         if not s.valid():
95                                 del list
96                                 break
97                         movieList.append(s)
98                 
99                 # now process them...
100                 for ref in movieList:
101                         self.list.append(MovieListEntry(ref, serviceHandler))
102
103         def reload(self):
104                 self.load(self.root)
105                 self.l.setList(self.list)