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