61c670389fcba38c9637b0e9e82a08a647564dd4
[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 from EpgSelection import EPGSelection
6 from enigma import eServiceReference, eEPGCache, eEPGCachePtr
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                                         l = self.csel["list"]
73                                         l.setMode(l.MODE_NORMAL)
74                                         l.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
75                                 else:
76                                         ActionMap.action(self, contexts, action)
77
78                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"], 
79                         {
80                                 "cancel": self.close,
81                                 "ok": self.channelSelected,
82                                 "mark": self.doMark,
83                                 "contextMenu": self.doContext,
84                                 "showFavourites": self.showFavourites,
85                                 "showEPGList": self.showEPGList
86                         })
87                 self["actions"].csel = self
88
89         def showEPGList(self):
90                 ref=self["list"].getCurrent()
91                 ptr=eEPGCache.getInstance()
92                 if ptr.startTimeQuery(ref) != -1:
93                         self.session.open(EPGSelection, ref)
94                 else:
95                         print 'no epg for service', ref.toString()
96
97         #  marked edit mode
98         def startMarkedEdit(self):
99                 self.bouquet_mark_edit = True
100                 self.clearMarks()
101                 
102                 # TODO
103                 marked = self.__marked
104                 
105                 l = self["list"]
106                 for x in marked:
107                         l.addMarked(x)
108                 
109         def endMarkedEdit(self, abort):
110                 self.bouquet_mark_edit = True
111                 new_marked = self["list"].getMarked()
112                 self.__marked = new_marked
113                 self.clearMarks()
114                 self.bouquet_mark_edit = False
115
116         def clearMarks(self):
117                 self["list"].clearMarks()
118         
119         def doMark(self):
120                 if not self.bouquet_mark_edit:
121                         return
122                 
123                 ref = self["list"].getCurrent()
124                 if self["list"].isMarked(ref):
125                         self["list"].removeMarked(ref)
126                 else:
127                         self["list"].addMarked(ref)
128         
129         # ...
130         def channelSelected(self):
131                 ref = self["list"].getCurrent()
132                 if self.movemode:
133                         if self.entry_marked:
134                                 self["list"].setCurrentMarked(False)
135                                 self.entry_marked = False
136                         else:
137                                 self["list"].setCurrentMarked(True)
138                                 self.entry_marked = True
139                 elif (ref.flags & 7) == 7:
140                         l = self["list"]
141                         l.setMode(l.MODE_NORMAL)
142                         l.setRoot(ref)
143                 else:
144                         self.session.nav.playService(ref)
145                         self.close()
146
147         #called from infoBar
148         def zap(self):
149                 self.session.nav.playService(self["list"].getCurrent())
150
151         def moveUp(self):
152                 self["list"].moveUp()
153
154         def moveDown(self):
155                 self["list"].moveDown()
156
157         def doContext(self):
158                 self.session.open(ChannelContextMenu, self)
159
160         def setMoveMode(self, mode):
161                 if mode:
162                         self.movemode = False
163                 else:
164                         self.movemode = True
165
166         def showFavourites(self):
167                 l = self["list" ]
168                 l.setRoot(eServiceReference('1:0:1:0:0:0:0:0:0:0:(provider == "fav")'))
169                 l.setMode(l.MODE_FAVOURITES)