remove obsolete HTMLComponent
[enigma2.git] / lib / python / Components / MovieList.py
1 from GUIComponent import *
2 from Tools.FuzzyDate import FuzzyTime
3 from ServiceReference import ServiceReference
4 from Components.MultiContent import MultiContentEntryText, RT_HALIGN_LEFT, RT_HALIGN_RIGHT
5
6 from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation
7
8 from enigma import eServiceReference, eServiceCenter, \
9         eServiceCenterPtr, iListableServicePtr, \
10         iStaticServiceInformationPtr
11
12 class MovieList(GUIComponent):
13         def __init__(self, root):
14                 GUIComponent.__init__(self)
15                 self.l = eListboxPythonMultiContent()
16                 self.tags = set()
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 getCurrentEvent(self):
63                 l = self.l.getCurrentSelection()
64                 return l and l[0] and l[1] and l[1].getEvent(l[0])
65
66         def getCurrent(self):
67                 l = self.l.getCurrentSelection()
68                 return l and l[0]
69
70         GUI_WIDGET = eListbox
71         
72         def postWidgetCreate(self, instance):
73                 instance.setContent(self.l)
74                 instance.setItemHeight(75)
75         
76         def reload(self, root = None, filter_tags = None):
77                 if root is not None:
78                         self.load(root, filter_tags)
79                 else:
80                         self.load(self.root, filter_tags)
81                 self.l.setList(self.list)
82
83         def removeService(self, service):
84                 for l in self.list[:]:
85                         if l[0] == service:
86                                 self.list.remove(l)
87                 self.l.setList(self.list)
88
89         def __len__(self):
90                 return len(self.list)
91
92         def updateLengthOfIndex(self, index):
93                 if len(self.list) > index:
94                         x = self.list[index]
95                         self.list[index] = (x[0], x[1], x[2], x[1].getLength(x[0]))
96                         self.l.invalidateEntry(index)
97
98         def load(self, root, filter_tags):
99                 # this lists our root service, then building a 
100                 # nice list
101                 
102                 self.list = [ ]
103                 self.root = root
104                 
105                 self.serviceHandler = eServiceCenter.getInstance()
106                 list = self.serviceHandler.list(root)
107                 
108                 tags = set()
109                 
110                 if list is None:
111                         raise "listing of movies failed"
112
113                 while 1:
114                         serviceref = list.getNext()
115                         if not serviceref.valid():
116                                 break
117                         if serviceref.flags & eServiceReference.mustDescent:
118                                 continue
119                         info = self.serviceHandler.info(serviceref)
120                         if info is None:
121                                 continue
122                         begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
123                         
124                         # convert space-seperated list of tags into a set
125                         this_tags = info.getInfoString(serviceref, iServiceInformation.sTags).split(' ')
126                         if this_tags == ['']:
127                                 this_tags = []
128                         this_tags = set(this_tags)
129                         
130                         # filter_tags is either None (which means no filter at all), or 
131                         # a set. In this case, all elements of filter_tags must be present,
132                         # otherwise the entry will be dropped.                  
133                         if filter_tags is not None and not this_tags.issuperset(filter_tags):
134                                 continue
135                         
136                         tags |= this_tags
137                         self.list.append((serviceref, info, begin, -1))
138                 
139                 # sort: key is 'begin'
140                 self.list.sort(key=lambda x: -x[2])
141                 
142                 # finally, store a list of all tags which were found. these can be presented
143                 # to the user to filter the list
144                 self.tags = tags
145
146         def moveTo(self, serviceref):
147                 found = 0
148                 count = 0
149                 for x in self.list:
150                         if x[0] == serviceref:
151                                 found = count
152                         count += 1
153                 self.instance.moveSelectionTo(found)
154
155         def moveDown(self):
156                 self.instance.moveSelection(self.instance.moveDown)