- copy list in channel editor so abort does what its supposed to,
[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 EPGRefreshServiceEditor
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                 # Although EPGRefresh keeps services in a Set we prefer a list
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.editServices
74                         }
75                 )
76
77                 # Trigger change
78                 self.changed()
79
80         def forceRefresh(self):
81                 epgrefresh.services = (Set(self.services[0]), Set(self.services[1]))
82                 epgrefresh.forceRefresh(self.session)
83
84         def editServices(self):
85                 self.session.openWithCallback(
86                         self.editServicesCallback,
87                         EPGRefreshServiceEditor,
88                         self.services
89                 )
90
91         def editServicesCallback(self, ret):
92                 if ret:
93                         self.services = ret
94
95         def changed(self):
96                 for x in self.onChangedEntry:
97                         try:
98                                 x()
99                         except:
100                                 pass
101
102         def getCurrentEntry(self):
103                 return self["config"].getCurrent()[0]
104
105         def getCurrentValue(self):
106                 return str(self["config"].getCurrent()[1].getText())
107
108         def createSummary(self):
109                 return SetupSummary
110
111         def cancelConfirm(self, result):
112                 if not result:
113                         return
114
115                 for x in self["config"].list:
116                         x[1].cancel()
117
118                 self.close(self.session)
119
120         def keyCancel(self):
121                 if self["config"].isChanged():
122                         self.session.openWithCallback(
123                                 self.cancelConfirm,
124                                 MessageBox,
125                                 _("Really close without saving settings?")
126                         )
127                 else:
128                         self.close(self.session)
129
130         def keySave(self):
131                 epgrefresh.services = (Set(self.services[0]), Set(self.services[1]))
132                 try:
133                         epgrefresh.saveConfiguration()
134                 except Exception, e:
135                         print "[EPGRefresh] Error occured while saving configuration:", e
136                 
137                 for x in self["config"].list:
138                         x[1].save()
139
140                 self.close(self.session)