- save service names in xml,
[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 EPGRefreshChannelEditor(Screen, ConfigListScreen):
33         """Edit Services to be refreshed by EPGRefresh"""
34
35         skin = """<screen name="EPGRefreshChannelEditor" 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                 self.services = services
55
56                 self.typeSelection = ConfigSelection(choices = [("channels", _("Channels")), ("bouquets", _("Bouquets"))])
57                 self.typeSelection.addNotifier(self.refresh, initial_call = False)
58
59                 self.reloadList()
60
61                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
62
63                 # Initialize Buttons
64                 self["key_red"] = Button(_("Cancel"))
65                 self["key_green"] = Button(_("OK"))
66                 self["key_yellow"] = Button(_("delete"))
67                 self["key_blue"] = Button(_("New"))
68
69                 # Define Actions
70                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
71                         {
72                                 "cancel": self.cancel,
73                                 "save": self.save,
74                                 "yellow": self.removeChannel,
75                                 "blue": self.newChannel
76                         }
77                 )
78
79                 # Trigger change
80                 self.changed()
81
82         def saveCurrent(self):
83                 del self.services[self.idx][:]
84                 
85                 # Warning, accessing a ConfigListEntry directly might be considered evil!
86
87                 myl = self["config"].getList()
88                 myl.pop(0)
89                 for item in myl:
90                         self.services[self.idx].append(item[1].value)
91
92         def refresh(self, value):
93                 self.saveCurrent()
94
95                 self.reloadList()
96                 self["config"].setList(self.list)
97
98         def reloadList(self):
99                 self.list = [
100                         getConfigListEntry(_("Editing"), self.typeSelection)
101                 ]
102                 
103                 if self.typeSelection.value == "channels":
104                         self.idx = 0
105                         self.list.extend([
106                                 getConfigListEntry(_("Refreshing"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
107                                         for x in self.services[0]
108                         ])
109                 else: # self.typeSelection.value == "bouquets":
110                         self.idx = 1
111                         self.list.extend([
112                                 getConfigListEntry(_("Refreshing"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
113                                         for x in self.services[1]
114                         ])
115
116         def changed(self):
117                 for x in self.onChangedEntry:
118                         try:
119                                 x()
120                         except:
121                                 pass
122
123         def getCurrentEntry(self):
124                 cur = self["config"].getCurrent()
125                 if cur:
126                         return cur[0]
127                 return ""
128
129         def getCurrentValue(self):
130                 cur = self["config"].getCurrent()
131                 if cur:
132                         return str(cur[1].getText())
133                 return ""
134
135         def createSummary(self):
136                 return SetupSummary
137
138         def removeChannel(self):
139                 cur = self["config"].getCurrent()
140                 if cur:
141                         list = self["config"].getList()
142                         list.remove(cur)
143                         self["config"].setList(list)
144
145         def newChannel(self):
146                 if self.typeSelection.value == "channels":
147                         self.session.openWithCallback(
148                                 self.finishedChannelSelection,
149                                 SimpleChannelSelection,
150                                 _("Select channel to refresh")
151                         )
152                 else: # self.typeSelection.value == "bouquets":
153                         self.session.openWithCallback(
154                                 self.finishedChannelSelection,
155                                 SimpleBouquetSelection,
156                                 _("Select bouquet to refresh")
157                         )
158
159         def finishedChannelSelection(self, *args):
160                 if len(args):
161                         list = self["config"].getList()
162                         list.append(getConfigListEntry(_("Refreshing"), ConfigSelection(choices = [(args[0].toString(), ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])))
163                         self["config"].setList(list)
164
165         def cancel(self):
166                 self.close(None)
167
168         def save(self):
169                 self.saveCurrent()
170
171                 self.close(self.services)