extend latitude/longitude range to 359.99 degrees
[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 class MovieList(HTMLComponent, GUIComponent):
14         def __init__(self, root):
15                 GUIComponent.__init__(self)
16                 self.l = eListboxPythonMultiContent()
17                 if root is not None:
18                         self.reload(root)
19                 self.l.setFont(0, gFont("Regular", 22))
20                 self.l.setFont(1, gFont("Regular", 18))
21                 self.l.setFont(2, gFont("Regular", 16))
22                 self.l.setBuildFunc(self.buildMovieListEntry)
23
24         #
25         # | name of movie              |
26         #
27         def buildMovieListEntry(self, serviceref, info, begin, len):
28                 if serviceref.flags & eServiceReference.mustDescent:
29                         return None
30
31                 if len > 0:
32                         len = "%d:%02d" % (len / 60, len % 60)
33                 else:
34                         len = "?:??"
35
36                 res = [ None ]
37
38                 res.append(MultiContentEntryText(pos=(0, 0), size=(420, 30), font = 0, flags = RT_HALIGN_LEFT, text = info.getName(serviceref)))
39                 service = ServiceReference(info.getInfoString(serviceref, iServiceInformation.sServiceref))
40                 if service is not None:
41                         res.append(MultiContentEntryText(pos=(420, 0), size=(140, 30), font = 2, flags = RT_HALIGN_RIGHT, text = service.getServiceName()))
42
43                 description = info.getInfoString(serviceref, iServiceInformation.sDescription)
44
45                 begin_string = ""
46                 if begin > 0:
47                         t = FuzzyTime(begin)
48                         begin_string = t[0] + ", " + t[1]
49
50                 res.append(MultiContentEntryText(pos=(0, 30), size=(560, 20), font=1, flags=RT_HALIGN_LEFT, text=description))
51                 res.append(MultiContentEntryText(pos=(0, 50), size=(270, 20), font=1, flags=RT_HALIGN_LEFT, text=begin_string))
52                 res.append(MultiContentEntryText(pos=(290, 50), size=(270, 20), font=1, flags=RT_HALIGN_RIGHT, text=len))
53
54                 return res
55
56         def moveToIndex(self, index):
57                 self.instance.moveSelectionTo(index)
58
59         def getCurrentIndex(self):
60                 return self.instance.getCurrentIndex()
61
62         def getCurrent(self):
63                 l = self.l.getCurrentSelection()
64                 return l and l[0]
65
66         GUI_WIDGET = eListbox
67         
68         def postWidgetCreate(self, instance):
69                 instance.setContent(self.l)
70                 instance.setItemHeight(75)
71         
72         def reload(self, root = None):
73                 if root is not None:
74                         self.load(root)
75                 else:
76                         self.load(self.root)
77                 self.l.setList(self.list)
78
79         def removeService(self, service):
80                 for l in self.list[:]:
81                         if l[0] == service:
82                                 self.list.remove(l)
83                 self.l.setList(self.list)
84
85         def __len__(self):
86                 return len(self.list)
87
88         def updateLengthOfIndex(self, index):
89                 if len(self.list) > index:
90                         x = self.list[index]
91                         self.list[index] = (x[0], x[1], x[2], x[1].getLength(x[0]))
92                         self.l.invalidateEntry(index)
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                 self.serviceHandler = eServiceCenter.getInstance()
102                 list = self.serviceHandler.list(root)
103                 
104                 if list is None:
105                         raise "listing of movies failed"
106
107                 while 1:
108                         serviceref = list.getNext()
109                         if not serviceref.valid():
110                                 break
111                         if serviceref.flags & eServiceReference.mustDescent:
112                                 continue
113                         info = self.serviceHandler.info(serviceref)
114                         if info is None:
115                                 continue
116                         begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
117                         self.list.append((serviceref, info, begin, -1))
118                 
119                 self.list.sort(key=lambda x: -x[2])
120
121         def moveTo(self, serviceref):
122                 found = 0
123                 count = 0
124                 for x in self.list:
125                         if x[0] == serviceref:
126                                 found = count
127                         count += 1
128                 self.instance.moveSelectionTo(found)
129
130         def moveDown(self):
131                 self.instance.moveSelection(self.instance.moveDown)