- copy list in channel editor so abort does what its supposed to,
[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                         # TODO: we could just accept the current path here....
30                         print "[BouquetSelector] Dunno what to do, no directory selected:", ref," :-/"
31
32 class EPGRefreshServiceEditor(Screen, ConfigListScreen):
33         """Edit Services to be refreshed by EPGRefresh"""
34
35         skin = """<screen name="EPGRefreshServiceEditor" title="Edit Services to refresh" position="75,150" size="565,245">
36                 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
37                 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
38                 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
39                 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
40                 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
41                 <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" />
42                 <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" />
43                 <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" />
44                 <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" />
45         </screen>"""
46
47         def __init__(self, session, services):
48                 Screen.__init__(self, session)
49
50                 # Summary
51                 self.setup_title = "EPGRefresh Services"
52                 self.onChangedEntry = []
53
54                 # We need to copy the list to be able to ignore changes
55                 self.services = (
56                         services[0][:],
57                         services[1][:]
58                 )
59
60                 self.typeSelection = ConfigSelection(choices = [("channels", _("Channels")), ("bouquets", _("Bouquets"))])
61                 self.typeSelection.addNotifier(self.refresh, initial_call = False)
62
63                 self.reloadList()
64
65                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
66
67                 # Initialize Buttons
68                 self["key_red"] = Button(_("Cancel"))
69                 self["key_green"] = Button(_("OK"))
70                 self["key_yellow"] = Button(_("delete"))
71                 self["key_blue"] = Button(_("New"))
72
73                 # Define Actions
74                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
75                         {
76                                 "cancel": self.cancel,
77                                 "save": self.save,
78                                 "yellow": self.removeService,
79                                 "blue": self.newService
80                         }
81                 )
82
83                 # Trigger change
84                 self.changed()
85
86         def saveCurrent(self):
87                 del self.services[self.idx][:]
88                 
89                 # Warning, accessing a ConfigListEntry directly might be considered evil!
90
91                 myl = self["config"].getList()
92                 myl.pop(0)
93                 for item in myl:
94                         self.services[self.idx].append(item[1].value)
95
96         def refresh(self, value):
97                 self.saveCurrent()
98
99                 self.reloadList()
100                 self["config"].setList(self.list)
101
102         def reloadList(self):
103                 self.list = [
104                         getConfigListEntry(_("Editing"), self.typeSelection)
105                 ]
106                 
107                 if self.typeSelection.value == "channels":
108                         self.idx = 0
109                 else: # self.typeSelection.value == "bouquets":
110                         self.idx = 1
111
112                 self.list.extend([
113                         getConfigListEntry(_("Refreshing"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
114                                 for x in self.services[self.idx]
115                 ])
116
117         def changed(self):
118                 for x in self.onChangedEntry:
119                         try:
120                                 x()
121                         except:
122                                 pass
123
124         def getCurrentEntry(self):
125                 cur = self["config"].getCurrent()
126                 if cur:
127                         return cur[0]
128                 return ""
129
130         def getCurrentValue(self):
131                 cur = self["config"].getCurrent()
132                 if cur:
133                         return str(cur[1].getText())
134                 return ""
135
136         def createSummary(self):
137                 return SetupSummary
138
139         def removeService(self):
140                 cur = self["config"].getCurrent()
141                 if cur:
142                         list = self["config"].getList()
143                         list.remove(cur)
144                         self["config"].setList(list)
145
146         def newService(self):
147                 if self.typeSelection.value == "channels":
148                         self.session.openWithCallback(
149                                 self.finishedServiceSelection,
150                                 SimpleChannelSelection,
151                                 _("Select channel to refresh")
152                         )
153                 else: # self.typeSelection.value == "bouquets":
154                         self.session.openWithCallback(
155                                 self.finishedServiceSelection,
156                                 SimpleBouquetSelection,
157                                 _("Select bouquet to refresh")
158                         )
159
160         def finishedServiceSelection(self, *args):
161                 if len(args):
162                         list = self["config"].getList()
163                         list.append(getConfigListEntry(
164                                 _("Refreshing"),
165                                 ConfigSelection(choices = [(args[0].toString(), ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])
166                         ))
167                         self["config"].setList(list)
168
169         def cancel(self):
170                 self.close(None)
171
172         def save(self):
173                 self.saveCurrent()
174
175                 self.close(self.services)