servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / python / Components / ServiceList.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from skin import parseColor, parseFont
4
5 from enigma import eListboxServiceContent, eListbox, eServiceCenter, eServiceReference, gFont, eRect
6 from Tools.LoadPixmap import LoadPixmap
7
8 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
9
10 from Components.config import config
11
12 class ServiceList(HTMLComponent, GUIComponent):
13         MODE_NORMAL = 0
14         MODE_FAVOURITES = 1
15
16         def __init__(self):
17                 GUIComponent.__init__(self)
18                 self.l = eListboxServiceContent()
19
20                 pic = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/folder.png"))
21                 if pic:
22                         self.l.setPixmap(self.l.picFolder, pic)
23
24                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/marker.png"))
25                 if pic:
26                         self.l.setPixmap(self.l.picMarker, pic)
27
28                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_s-fs8.png"))
29                 if pic:
30                         self.l.setPixmap(self.l.picDVB_S, pic)
31
32                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_c-fs8.png"))
33                 if pic:
34                         self.l.setPixmap(self.l.picDVB_C, pic)
35
36                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_t-fs8.png"))
37                 if pic:
38                         self.l.setPixmap(self.l.picDVB_T, pic)
39
40                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_service_group-fs8.png"))
41                 if pic:
42                         self.l.setPixmap(self.l.picServiceGroup, pic)
43
44                 self.root = None
45                 self.mode = self.MODE_NORMAL
46                 self.ItemHeight = 28
47                 self.ServiceNameFont = parseFont("Regular;22", ((1,1),(1,1)))
48                 self.ServiceInfoFont = parseFont("Regular;18", ((1,1),(1,1)))
49                 self.ServiceNumberFont = parseFont("Regular;20", ((1,1),(1,1)))
50                 self.onSelectionChanged = [ ]
51
52         def applySkin(self, desktop, parent):
53                 attribs = [ ]
54                 if self.skinAttributes is not None:
55                         attribs = [ ]
56                         for (attrib, value) in self.skinAttributes:
57                                 if attrib == "foregroundColorMarked":
58                                         self.l.setColor(eListboxServiceContent.markedForeground, parseColor(value))
59                                 elif attrib == "foregroundColorMarkedSelected":
60                                         self.l.setColor(eListboxServiceContent.markedForegroundSelected, parseColor(value))
61                                 elif attrib == "backgroundColorMarked":
62                                         self.l.setColor(eListboxServiceContent.markedBackground, parseColor(value))
63                                 elif attrib == "backgroundColorMarkedSelected":
64                                         self.l.setColor(eListboxServiceContent.markedBackgroundSelected, parseColor(value))
65                                 elif attrib == "foregroundColorServiceNotAvail":
66                                         self.l.setColor(eListboxServiceContent.serviceNotAvail, parseColor(value))
67                                 elif attrib == "colorEventProgressbar":
68                                         self.l.setColor(eListboxServiceContent.serviceEventProgressbarColor, parseColor(value))
69                                 elif attrib == "colorEventProgressbarSelected":
70                                         self.l.setColor(eListboxServiceContent.serviceEventProgressbarColorSelected, parseColor(value))
71                                 elif attrib == "colorEventProgressbarBorder":
72                                         self.l.setColor(eListboxServiceContent.serviceEventProgressbarBorderColor, parseColor(value))
73                                 elif attrib == "colorEventProgressbarBorderSelected":
74                                         self.l.setColor(eListboxServiceContent.serviceEventProgressbarBorderColorSelected, parseColor(value))
75                                 elif attrib == "colorServiceDescription":
76                                         self.l.setColor(eListboxServiceContent.serviceDescriptionColor, parseColor(value))
77                                 elif attrib == "colorServiceDescriptionSelected":
78                                         self.l.setColor(eListboxServiceContent.serviceDescriptionColorSelected, parseColor(value))
79                                 elif attrib == "picServiceEventProgressbar":
80                                         pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, value))
81                                         if pic:
82                                                 self.l.setPixmap(self.l.picServiceEventProgressbar, pic)
83                                 elif attrib == "serviceItemHeight":
84                                         self.ItemHeight = int(value)
85                                 elif attrib == "serviceNameFont":
86                                         self.ServiceNameFont = parseFont(value, ((1,1),(1,1)))
87                                 elif attrib == "serviceInfoFont":
88                                         self.ServiceInfoFont = parseFont(value, ((1,1),(1,1)))
89                                 elif attrib == "serviceNumberFont":
90                                         self.ServiceNumberFont = parseFont(value, ((1,1),(1,1)))
91                                 else:
92                                         attribs.append((attrib, value))
93                 self.skinAttributes = attribs
94                 return GUIComponent.applySkin(self, desktop, parent)
95
96         def connectSelChanged(self, fnc):
97                 if not fnc in self.onSelectionChanged:
98                         self.onSelectionChanged.append(fnc)
99
100         def disconnectSelChanged(self, fnc):
101                 if fnc in self.onSelectionChanged:
102                         self.onSelectionChanged.remove(fnc)
103
104         def selectionChanged(self):
105                 for x in self.onSelectionChanged:
106                         x()
107
108         def setCurrent(self, ref):
109                 self.l.setCurrent(ref)
110
111         def getCurrent(self):
112                 r = eServiceReference()
113                 self.l.getCurrent(r)
114                 return r
115
116         def atBegin(self):
117                 return self.instance.atBegin()
118
119         def atEnd(self):
120                 return self.instance.atEnd()
121
122         def moveUp(self):
123                 self.instance.moveSelection(self.instance.moveUp)
124
125         def moveDown(self):
126                 self.instance.moveSelection(self.instance.moveDown)
127
128         def moveToChar(self, char):
129                 # TODO fill with life
130                 print "Next char: "
131                 index = self.l.getNextBeginningWithChar(char)
132                 indexup = self.l.getNextBeginningWithChar(char.upper())
133                 if indexup != 0:
134                         if (index > indexup or index == 0):
135                                 index = indexup
136
137                 self.instance.moveSelectionTo(index)
138                 print "Moving to character " + str(char)
139
140         def moveToNextMarker(self):
141                 idx = self.l.getNextMarkerPos()
142                 self.instance.moveSelectionTo(idx)
143
144         def moveToPrevMarker(self):
145                 idx = self.l.getPrevMarkerPos()
146                 self.instance.moveSelectionTo(idx)
147
148         def moveToIndex(self, index):
149                 self.instance.moveSelectionTo(index)
150
151         def getCurrentIndex(self):
152                 return self.instance.getCurrentIndex()
153
154         GUI_WIDGET = eListbox
155         
156         def postWidgetCreate(self, instance):
157                 instance.setWrapAround(True)
158                 instance.setContent(self.l)
159                 instance.selectionChanged.get().append(self.selectionChanged)
160                 self.setMode(self.mode)
161
162         def preWidgetRemove(self, instance):
163                 instance.setContent(None)
164                 instance.selectionChanged.get().remove(self.selectionChanged)
165
166         def getRoot(self):
167                 return self.root
168
169         def getRootServices(self):
170                 serviceHandler = eServiceCenter.getInstance()
171                 list = serviceHandler.list(self.root)
172                 dest = [ ]
173                 if list is not None:
174                         while 1:
175                                 s = list.getNext()
176                                 if s.valid():
177                                         dest.append(s.toString())
178                                 else:
179                                         break
180                 return dest
181
182         def setNumberOffset(self, offset):
183                 self.l.setNumberOffset(offset)
184
185         def setPlayableIgnoreService(self, ref):
186                 self.l.setIgnoreService(ref)
187
188         def setRoot(self, root, justSet=False):
189                 self.root = root
190                 self.l.setRoot(root, justSet)
191                 if not justSet:
192                         self.l.sort()
193                 self.selectionChanged()
194
195         def removeCurrent(self):
196                 self.l.removeCurrent()
197
198         def addService(self, service, beforeCurrent=False):
199                 self.l.addService(service, beforeCurrent)
200
201         def finishFill(self):
202                 self.l.FillFinished()
203                 self.l.sort()
204
205 # stuff for multiple marks (edit mode / later multiepg)
206         def clearMarks(self):
207                 self.l.initMarked()
208
209         def isMarked(self, ref):
210                 return self.l.isMarked(ref)
211
212         def addMarked(self, ref):
213                 self.l.addMarked(ref)
214
215         def removeMarked(self, ref):
216                 self.l.removeMarked(ref)
217
218         def getMarked(self):
219                 i = self.l
220                 i.markedQueryStart()
221                 ref = eServiceReference()
222                 marked = [ ]
223                 while i.markedQueryNext(ref) == 0:
224                         marked.append(ref.toString())
225                         ref = eServiceReference()
226                 return marked
227
228 #just for movemode.. only one marked entry..
229         def setCurrentMarked(self, state):
230                 self.l.setCurrentMarked(state)
231
232         def setMode(self, mode):
233                 self.mode = mode
234                 self.l.setItemHeight(self.ItemHeight)
235                 self.l.setVisualMode(eListboxServiceContent.visModeComplex)
236                 if mode == self.MODE_NORMAL:
237                         if config.usage.show_event_progress_in_servicelist.value:
238                                 self.l.setElementPosition(self.l.celServiceEventProgressbar, eRect(0, 0, 52, self.ItemHeight))
239                         else:
240                                 self.l.setElementPosition(self.l.celServiceEventProgressbar, eRect(0, 0, 0, 0))
241                         self.l.setElementFont(self.l.celServiceName, self.ServiceNameFont)
242                         self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), self.ItemHeight))
243                         self.l.setElementFont(self.l.celServiceInfo, self.ServiceInfoFont)
244                 else:
245                         if config.usage.show_event_progress_in_servicelist.value:
246                                 self.l.setElementPosition(self.l.celServiceEventProgressbar, eRect(60, 0, 52, self.ItemHeight))
247                         else:
248                                 self.l.setElementPosition(self.l.celServiceEventProgressbar, eRect(60, 0, 0, 0))
249                         self.l.setElementFont(self.l.celServiceNumber, self.ServiceNumberFont)
250                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 50, self.ItemHeight))
251                         self.l.setElementFont(self.l.celServiceName, self.ServiceNameFont)
252                         self.l.setElementPosition(self.l.celServiceName, eRect(60, 0, self.instance.size().width()-60, self.ItemHeight))
253                         self.l.setElementFont(self.l.celServiceInfo, self.ServiceInfoFont)
254