add bouquet support
[enigma2.git] / lib / python / Screens / ChannelSelection.py
1 from Screen import Screen
2 from Components.Button import Button
3 from Components.ServiceList import ServiceList
4 from Components.ActionMap import ActionMap
5
6 from enigma import eServiceReference
7
8 from Screens.FixedMenu import FixedMenu
9
10 import xml.dom.minidom
11
12 class ChannelContextMenu(FixedMenu):
13         def __init__(self, session, csel):
14                 self.csel = csel
15                 
16                 menu = [("back", self.close)]
17                 
18                 if csel.movemode:
19                         menu.append(("disable move mode", self.moveMode))
20                 else:
21                         menu.append(("enable move mode", self.moveMode))
22
23                 if csel.bouquet_mark_edit:
24                         menu.append(("end bouquet edit", self.bouquetMarkEnd))
25                         menu.append(("abort bouquet edit", self.bouquetMarkAbort))
26                 else:
27                         menu.append(("edit bouquet...", self.bouquetMarkStart))
28                 
29                 FixedMenu.__init__(self, session, "Channel Selection", menu)
30                 self.skinName = "Menu"
31
32         def moveMode(self):
33                 self.csel.setMoveMode(self.csel.movemode)
34                 self.close()
35         
36         def bouquetMarkStart(self):
37                 self.csel.startMarkedEdit()
38                 self.close()
39         
40         def bouquetMarkEnd(self):
41                 self.csel.endMarkedEdit(abort=False)
42                 self.close()
43
44         def bouquetMarkAbort(self):
45                 self.csel.endMarkedEdit(abort=True)
46                 self.close()
47  
48 class ChannelSelection(Screen):
49         def __init__(self, session):
50                 Screen.__init__(self, session)
51                 
52                 self.entry_marked = False
53                 self.movemode = False
54                 self.bouquet_mark_edit = False
55                 
56                 ## FIXME
57                 self.__marked = [ ]
58                 
59                 self["key_red"] = Button("All")
60                 self["key_green"] = Button("Provider")
61                 self["key_yellow"] = Button("Satellite")
62                 self["key_blue"] = Button("Favourites")
63                 
64                 self["list"] = ServiceList()
65                 self["list"].setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
66                 
67                 #self["okbutton"] = Button("ok", [self.channelSelected])
68                 
69                 class ChannelActionMap(ActionMap):
70                         def action(self, contexts, action):
71                                 if action[:7] == "bouquet":
72                                         print "setting root to " + action[8:]
73                                         l = self.csel["list"]
74                                         l.setMode(l.MODE_NORMAL)
75                                         l.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
76                                 else:
77                                         ActionMap.action(self, contexts, action)
78
79                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions"], 
80                         {
81                                 "cancel": self.close,
82                                 "ok": self.channelSelected,
83                                 "mark": self.doMark,
84                                 "contextMenu": self.doContext,
85                                 "showFavourites": self.showFavourites
86                         })
87                 self["actions"].csel = self
88
89         #  marked edit mode
90         
91         def startMarkedEdit(self):
92                 self.bouquet_mark_edit = True
93                 self.clearMarks()
94                 
95                 # TODO
96                 marked = self.__marked
97                 
98                 l = self["list"]
99                 for x in marked:
100                         print "mark: " + str(x)
101                         l.addMarked(x)
102                 
103         def endMarkedEdit(self, abort):
104                 self.bouquet_mark_edit = True
105                 new_marked = self["list"].getMarked()
106                 self.__marked = new_marked
107                 self.clearMarks()
108                 self.bouquet_mark_edit = False
109
110         def clearMarks(self):
111                 self["list"].clearMarks()
112         
113         def doMark(self):
114                 if not self.bouquet_mark_edit:
115                         return
116                 
117                 ref = self["list"].getCurrent()
118                 if self["list"].isMarked(ref):
119                         self["list"].removeMarked(ref)
120                 else:
121                         self["list"].addMarked(ref)
122         
123         # ...
124         def channelSelected(self):
125                 ref = self["list"].getCurrent()
126                 if self.movemode:
127                         if self.entry_marked:
128                                 self["list"].setCurrentMarked(False)
129                                 self.entry_marked = False
130                         else:
131                                 self["list"].setCurrentMarked(True)
132                                 self.entry_marked = True
133                 elif (ref.flags & 7) == 7:
134                         l = self["list"]
135                         l.setMode(l.MODE_NORMAL)
136                         l.setRoot(ref)
137                 else:
138                         self.session.nav.playService(ref)
139                         print "current: " + ref.toString()
140                         self.close()
141
142         #called from infoBar
143         def zap(self):
144                 self.session.nav.playService(self["list"].getCurrent())
145
146         def moveUp(self):
147                 self["list"].moveUp()
148
149         def moveDown(self):
150                 self["list"].moveDown()
151
152         def doContext(self):
153                 self.session.open(ChannelContextMenu, self)
154
155         def setMoveMode(self, mode):
156                 if mode:
157                         self.movemode = False
158                 else:
159                         self.movemode = True
160         
161         def showFavourites(self):
162                 l = self["list" ]
163                 l.setRoot(eServiceReference('1:0:1:0:0:0:0:0:0:0:(provider == "fav")'))
164                 l.setMode(l.MODE_FAVOURITES)