working on move, edit mode and add remove service to context menu
[enigma2.git] / lib / python / Components / ServiceList.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from enigma import *
5
6 class ServiceList(HTMLComponent, GUIComponent):
7
8         MODE_NORMAL = 0
9         MODE_FAVOURITES = 1
10
11         def __init__(self):
12                 GUIComponent.__init__(self)
13                 self.l = eListboxServiceContent()
14                 self.root = None
15
16         def getCurrent(self):
17                 r = eServiceReference()
18                 self.l.getCurrent(r)
19                 return r
20
21         def moveUp(self):
22                 self.instance.moveSelection(self.instance.moveUp)
23
24         def moveDown(self):
25                 self.instance.moveSelection(self.instance.moveDown)
26
27         def GUIcreate(self, parent):
28                 self.instance = eListbox(parent)
29                 self.instance.setContent(self.l)
30         
31         def GUIdelete(self):
32                 self.instance = None
33
34         def getRoot(self):
35                 return self.root
36
37         def getRootServices(self):
38                 serviceHandler = eServiceCenter.getInstance()
39                 list = serviceHandler.list(self.root)
40                 dest = [ ]
41                 if list is not None:
42                         while 1:
43                                 s = list.getNext()
44                                 if s.valid():
45                                         dest.append(s.toString())
46                                 else:
47                                         break
48                 return dest
49
50         def setRoot(self, root):
51                 self.root = root
52                 self.l.setRoot(root)
53                 self.l.sort()
54
55         def cursorGet(self):
56                 return self.l.cursorGet()
57
58         def cursorSet(self, val):
59                 self.l.cursorSet(val)
60
61 # stuff for multiple marks (edit mode / later multiepg)
62         def clearMarks(self):
63                 self.l.initMarked()
64
65         def isMarked(self, ref):
66                 return self.l.isMarked(ref)
67
68         def addMarked(self, ref):
69                 self.l.addMarked(ref)
70
71         def removeMarked(self, ref):
72                 self.l.removeMarked(ref)
73
74         def getMarked(self):
75                 i = self.l
76                 i.markedQueryStart()
77                 ref = eServiceReference()
78                 marked = [ ]
79                 while i.markedQueryNext(ref) == 0:
80                         marked.append(ref.toString())
81                         ref = eServiceReference()
82                 return marked
83
84 #just for movemode.. only one marked entry..
85         def setCurrentMarked(self, state):
86                 self.l.setCurrentMarked(state)
87
88         def setMode(self, mode):
89                 if mode == self.MODE_NORMAL:
90                         self.instance.setItemHeight(25)
91                         self.l.setVisualMode(eListboxServiceContent.visModeSimple)
92                 else:
93                         self.instance.setItemHeight(40)
94                         self.l.setElementFont(self.l.celServiceName, gFont("Arial", 30))
95                         self.l.setElementPosition(self.l.celServiceName, eRect(40, 0, self.instance.size().width(), 40))
96                         self.l.setElementFont(self.l.celServiceNumber, gFont("Arial", 20))
97                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 10, 40, 30))
98                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)