- save service names in xml,
[enigma2-plugins.git] / epgrefresh / src / EPGRefreshConfiguration.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Components.ConfigList import ConfigListScreen
4 from EPGRefreshChannelEditor import EPGRefreshChannelEditor
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 config, getConfigListEntry
15
16 from EPGRefresh import epgrefresh
17
18 from sets import Set
19
20 class EPGRefreshConfiguration(Screen, ConfigListScreen):
21         """Configuration of EPGRefresh"""
22
23         skin = """<screen name="EPGRefreshConfiguration" title="Configure EPGRefresh" position="75,155" size="565,280">
24                 <widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
25                 <ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
26                 <ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
27                 <ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
28                 <ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
29                 <widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
30                 <widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
31                 <widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
32                 <widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
33         </screen>"""
34
35         def __init__(self, session):
36                 Screen.__init__(self, session)
37
38                 # Summary
39                 self.setup_title = "EPGRefresh Configuration"
40                 self.onChangedEntry = []
41
42                 # Entries are saved internally as a set, but we might need item deletion later on
43                 self.services = (
44                         [x for x in epgrefresh.services[0]],
45                         [x for x in epgrefresh.services[1]]
46                 )
47
48                 self.list = [
49                         getConfigListEntry(_("Refresh automatically"), config.plugins.epgrefresh.enabled),
50                         getConfigListEntry(_("Time to stay on service (in m)"), config.plugins.epgrefresh.interval),
51                         getConfigListEntry(_("Refresh EPG after"), config.plugins.epgrefresh.begin),
52                         getConfigListEntry(_("Refresh EPG before"), config.plugins.epgrefresh.end),
53                         getConfigListEntry(_("Delay when not in Standby (in m)"), config.plugins.epgrefresh.delay_standby),
54                         getConfigListEntry(_("Force scan even if not in Standby or Recording"), config.plugins.epgrefresh.force),
55                         getConfigListEntry(_("Inherit Services from AutoTimer if available"), config.plugins.epgrefresh.inherit_autotimer),
56                         getConfigListEntry(_("Shutdown after refresh"), config.plugins.epgrefresh.afterevent),
57                 ]
58
59                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
60
61                 # Initialize Buttons
62                 self["key_red"] = Button(_("Cancel"))
63                 self["key_green"] = Button(_("OK"))
64                 self["key_yellow"] = Button(_("Refresh now"))
65                 self["key_blue"] = Button(_("Edit Services"))
66
67                 # Define Actions
68                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
69                         {
70                                 "cancel": self.keyCancel,
71                                 "save": self.keySave,
72                                 "yellow": self.forceRefresh,
73                                 "blue": self.editChannels
74                         }
75                 )
76
77                 # Trigger change
78                 self.changed()
79
80         def forceRefresh(self):
81                 # TODO: fix this :-)
82                 epgrefresh.services = (Set(self.services[0]), Set(self.services[1]))
83                 # TODO: maybe we need to save the configuration here...
84                 epgrefresh.forceRefresh(self.session)
85
86         def editChannels(self):
87                 self.session.openWithCallback(
88                         self.editChannelsCallback,
89                         EPGRefreshChannelEditor,
90                         self.services
91                 )
92
93         def editChannelsCallback(self, ret):
94                 if ret:
95                         self.services = ret
96
97         def changed(self):
98                 for x in self.onChangedEntry:
99                         try:
100                                 x()
101                         except:
102                                 pass
103
104         def getCurrentEntry(self):
105                 return self["config"].getCurrent()[0]
106
107         def getCurrentValue(self):
108                 return str(self["config"].getCurrent()[1].getText())
109
110         def createSummary(self):
111                 return SetupSummary
112
113         def cancelConfirm(self, result):
114                 if not result:
115                         return
116
117                 for x in self["config"].list:
118                         x[1].cancel()
119
120                 self.close(self.session)
121
122         def keyCancel(self):
123                 if self["config"].isChanged():
124                         self.session.openWithCallback(
125                                 self.cancelConfirm,
126                                 MessageBox,
127                                 _("Really close without saving settings?")
128                         )
129                 else:
130                         self.close(self.session)
131
132         def keySave(self):
133                 epgrefresh.services = (Set(self.services[0]), Set(self.services[1]))
134                 try:
135                         epgrefresh.saveConfiguration()
136                 except Exception, e:
137                         print "[EPGRefresh] Error occured while saving configuration:", e
138                 
139                 for x in self["config"].list:
140                         x[1].save()
141
142                 self.close(self.session)