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