show service name in movielist
[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 from Components.MultiContent import MultiContentEntryText, RT_HALIGN_LEFT, RT_HALIGN_RIGHT
6
7 from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation
8
9 from enigma import eServiceReference, eServiceCenter, \
10         eServiceCenterPtr, iListableServicePtr, \
11         iStaticServiceInformationPtr
12
13 #
14 # | name of movie              |
15 #
16 def MovieListEntry(serviceref, serviceHandler):
17         if serviceref.flags & eServiceReference.mustDescent:
18                 return None
19
20         info = serviceHandler.info(serviceref)
21         
22         if info is None:
23                 # ignore service which refuse to info
24                 return None
25         
26         len = info.getLength(serviceref)
27         if len > 0:
28                 len = "%d:%02d" % (len / 60, len % 60)
29         else:
30                 len = "?:??"
31         
32         begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
33         res = [ (serviceref, begin) ]
34
35         res.append(MultiContentEntryText(pos=(0, 0), size=(420, 30), font = 0, flags = RT_HALIGN_LEFT, text = info.getName(serviceref)))
36         service = ServiceReference(info.getInfoString(serviceref, iServiceInformation.sServiceref))
37         if service is not None:
38                 res.append(MultiContentEntryText(pos=(420, 0), size=(140, 30), font = 0, flags = RT_HALIGN_RIGHT, text = service.getServiceName()))
39         
40         description = info.getInfoString(serviceref, iServiceInformation.sDescription)
41
42         begin_string = ""
43         if begin > 0:
44                 t = FuzzyTime(begin)
45                 begin_string = t[0] + ", " + t[1]
46         
47         res.append(MultiContentEntryText(pos=(0, 30), size=(560, 20), font=1, flags=RT_HALIGN_LEFT, text=description))
48         res.append(MultiContentEntryText(pos=(0, 50), size=(270, 20), font=1, flags=RT_HALIGN_LEFT, text=begin_string))
49         res.append(MultiContentEntryText(pos=(290, 50), size=(270, 20), font=1, flags=RT_HALIGN_RIGHT, text=len))
50         
51         return res
52
53 class MovieList(HTMLComponent, GUIComponent):
54         def __init__(self, root):
55                 GUIComponent.__init__(self)
56                 self.l = eListboxPythonMultiContent()
57                 if root is not None:
58                         self.reload(root)
59                 self.l.setFont(0, gFont("Regular", 22))
60                 self.l.setFont(1, gFont("Regular", 18))
61                 
62         def moveToIndex(self, index):
63                 self.instance.moveSelectionTo(index)
64
65         def getCurrentIndex(self):
66                 return self.instance.getCurrentIndex()
67
68         def getCurrent(self):
69                 l = self.l.getCurrentSelection()
70                 return l and l[0]
71         
72         def GUIcreate(self, parent):
73                 self.instance = eListbox(parent)
74                 self.instance.setContent(self.l)
75                 self.instance.setItemHeight(75)
76         
77         def GUIdelete(self):
78                 self.instance.setContent(None)
79                 self.instance = None
80
81         def reload(self, root = None):
82                 if root is not None:
83                         self.load(root)
84                 else:
85                         self.load(self.root)
86                 self.l.setList(self.list)
87
88         def removeService(self, service):
89                 for l in self.list[:]:
90                         if l[0][0] == service:
91                                 self.list.remove(l)
92                 self.l.setList(self.list)
93
94         def load(self, root):
95                 # this lists our root service, then building a 
96                 # nice list
97                 
98                 self.list = [ ]
99                 self.root = root
100                 
101                 serviceHandler = eServiceCenter.getInstance()
102                 list = serviceHandler.list(root)
103                 
104                 if list is None:
105                         raise "listing of movies failed"
106
107                 movieList = [ ]
108                 while 1:
109                         s = list.getNext()
110                         if not s.valid():
111                                 del list
112                                 break
113                         movieList.append(s)
114                 
115                 # now process them...
116                 for ref in movieList:
117                         a = MovieListEntry(ref, serviceHandler)
118                         if a is not None:
119                                 self.list.append(a)
120                 
121                 self.list.sort(key=lambda x: -x[0][1])
122
123         def moveTo(self, serviceref):
124                 found = 0
125                 count = 0
126                 for x in self.list:
127                         if str(ServiceReference(x[0][0])) == str(ServiceReference(serviceref)):
128                                 found = count
129                         count += 1
130                 self.instance.moveSelectionTo(found)
131
132         def moveDown(self):
133                 self.instance.moveSelection(self.instance.moveDown)