Check zap-history position after changing the zap-history
[enigma2-plugins.git] / epgrefresh / src / EPGRefreshChannelEditor.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Components.ConfigList import ConfigListScreen
4 from Screens.ChannelSelection import SimpleChannelSelection
5
6 # GUI (Summary)
7 from Screens.Setup import SetupSummary
8
9 # GUI (Components)
10 from Components.ActionMap import ActionMap
11 from Components.Button import Button
12
13 # Configuration
14 from Components.config import getConfigListEntry, ConfigSelection
15
16 # Show ServiceName instead of ServiceReference
17 from ServiceReference import ServiceReference
18
19 class SimpleBouquetSelection(SimpleChannelSelection):
20         def __init__(self, session, title):
21                 SimpleChannelSelection.__init__(self, session, title)
22                 self.skinName = "SimpleChannelSelection"
23
24         def channelSelected(self): # just return selected service
25                 ref = self.getCurrentSelection()
26                 if (ref.flags & 7) == 7:
27                         self.close(ref)
28                 else:
29                         # We return the currently active path here
30                         # Asking the user if this is what he wants might be better though
31                         self.close(self.servicePath[-1])
32
33 class EPGRefreshServiceEditor(Screen, ConfigListScreen):
34         """Edit Services to be refreshed by EPGRefresh"""
35
36         skin = """<screen name="EPGRefreshServiceEditor" title="Edit Services to refresh" position="75,150" size="565,245">
37                 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
38                 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
39                 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
40                 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
41                 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
42                 <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
43                 <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
44                 <widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
45                 <widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
46         </screen>"""
47
48         def __init__(self, session, services):
49                 Screen.__init__(self, session)
50
51                 # Summary
52                 self.setup_title = "EPGRefresh Services"
53                 self.onChangedEntry = []
54
55                 # We need to copy the list to be able to ignore changes
56                 self.services = (
57                         services[0][:],
58                         services[1][:]
59                 )
60
61                 self.typeSelection = ConfigSelection(choices = [("channels", _("Channels")), ("bouquets", _("Bouquets"))])
62                 self.typeSelection.addNotifier(self.refresh, initial_call = False)
63
64                 self.reloadList()
65
66                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
67
68                 # Initialize Buttons
69                 self["key_red"] = Button(_("Cancel"))
70                 self["key_green"] = Button(_("OK"))
71                 self["key_yellow"] = Button(_("delete"))
72                 self["key_blue"] = Button(_("New"))
73
74                 # Define Actions
75                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
76                         {
77                                 "cancel": self.cancel,
78                                 "save": self.save,
79                                 "yellow": self.removeService,
80                                 "blue": self.newService
81                         }
82                 )
83
84                 # Trigger change
85                 self.changed()
86
87         def saveCurrent(self):
88                 del self.services[self.idx][:]
89                 
90                 # Warning, accessing a ConfigListEntry directly might be considered evil!
91
92                 myl = self["config"].getList()
93                 myl.pop(0)
94                 for item in myl:
95                         self.services[self.idx].append(item[1].value)
96
97         def refresh(self, value):
98                 self.saveCurrent()
99
100                 self.reloadList()
101                 self["config"].setList(self.list)
102
103         def reloadList(self):
104                 self.list = [
105                         getConfigListEntry(_("Editing"), self.typeSelection)
106                 ]
107                 
108                 if self.typeSelection.value == "channels":
109                         self.idx = 0
110                 else: # self.typeSelection.value == "bouquets":
111                         self.idx = 1
112
113                 self.list.extend([
114                         getConfigListEntry(_("Refreshing"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
115                                 for x in self.services[self.idx]
116                 ])
117
118         def changed(self):
119                 for x in self.onChangedEntry:
120                         try:
121                                 x()
122                         except:
123                                 pass
124
125         def getCurrentEntry(self):
126                 cur = self["config"].getCurrent()
127                 if cur:
128                         return cur[0]
129                 return ""
130
131         def getCurrentValue(self):
132                 cur = self["config"].getCurrent()
133                 if cur:
134                         return str(cur[1].getText())
135                 return ""
136
137         def createSummary(self):
138                 return SetupSummary
139
140         def removeService(self):
141                 cur = self["config"].getCurrent()
142                 if cur:
143                         list = self["config"].getList()
144                         list.remove(cur)
145                         self["config"].setList(list)
146
147         def newService(self):
148                 if self.typeSelection.value == "channels":
149                         self.session.openWithCallback(
150                                 self.finishedServiceSelection,
151                                 SimpleChannelSelection,
152                                 _("Select channel to refresh")
153                         )
154                 else: # self.typeSelection.value == "bouquets":
155                         self.session.openWithCallback(
156                                 self.finishedServiceSelection,
157                                 SimpleBouquetSelection,
158                                 _("Select bouquet to refresh")
159                         )
160
161         def finishedServiceSelection(self, *args):
162                 if len(args):
163                         list = self["config"].getList()
164                         list.append(getConfigListEntry(
165                                 _("Refreshing"),
166                                 ConfigSelection(choices = [(args[0].toString(), ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])
167                         ))
168                         self["config"].setList(list)
169
170         def cancel(self):
171                 self.close(None)
172
173         def save(self):
174                 self.saveCurrent()
175
176                 self.close(self.services)