retry the waiting message
[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, 0, 560, 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((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 560, 20, 1, RT_HALIGN_LEFT, description))
53         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 270, 20, 1, RT_HALIGN_LEFT, begin_string))
54         res.append((eListboxPythonMultiContent.TYPE_TEXT, 290, 50, 270, 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                 if root is not None:
63                         self.reload(root)
64                 self.l.setFont(0, gFont("Regular", 30))
65                 self.l.setFont(1, gFont("Regular", 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 reload(self, root = None):
86                 if root is not None:
87                         self.load(root)
88                 else:
89                         self.load(self.root)
90                 self.l.setList(self.list)
91
92         def load(self, root):
93                 # this lists our root service, then building a 
94                 # nice list
95                 
96                 self.list = [ ]
97                 self.root = root
98                 
99                 serviceHandler = eServiceCenter.getInstance()
100                 list = serviceHandler.list(root)
101                 
102                 if list is None:
103                         raise "listing of movies failed"
104
105                 movieList = [ ]
106                 while 1:
107                         s = list.getNext()
108                         if not s.valid():
109                                 del list
110                                 break
111                         movieList.append(s)
112                 
113                 # now process them...
114                 for ref in movieList:
115                         self.list.append(MovieListEntry(ref, serviceHandler))
116                         
117         def moveTo(self, serviceref):
118                 found = 0
119                 count = 0
120                 for x in self.list:
121                         if str(ServiceReference(x[0])) == str(ServiceReference(serviceref)):
122                                 found = count
123                         count += 1
124                 self.instance.moveSelectionTo(found)
125
126         def moveDown(self):
127                 self.instance.moveSelection(self.instance.moveDown)