intial commit of autotimer, epgrefresh and werbezapper to enigma2-plugins
[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                 # -
43                 self.servicelist = epgrefresh.services
44
45                 self.list = [
46                         getConfigListEntry(_("Refresh automatically"), config.plugins.epgrefresh.enabled),
47                         getConfigListEntry(_("Time to stay on service (in m)"), config.plugins.epgrefresh.interval),
48                         getConfigListEntry(_("Refresh EPG after"), config.plugins.epgrefresh.begin),
49                         getConfigListEntry(_("Refresh EPG before"), config.plugins.epgrefresh.end),
50                         getConfigListEntry(_("Delay when not in Timespan (in m)"), config.plugins.epgrefresh.delay_timespan),
51                         getConfigListEntry(_("Delay when not in Standby (in m)"), config.plugins.epgrefresh.delay_standby),
52                         getConfigListEntry(_("Force scan even if not in Standby or Recording"), config.plugins.epgrefresh.force),
53                         getConfigListEntry(_("Inherit Services from AutoTimer if available"), config.plugins.epgrefresh.inherit_autotimer),
54                         getConfigListEntry(_("Shutdown after refresh"), config.plugins.epgrefresh.afterevent),
55                 ]
56
57                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
58
59                 # Initialize Buttons
60                 self["key_red"] = Button(_("Cancel"))
61                 self["key_green"] = Button(_("OK"))
62                 self["key_yellow"] = Button(_("Refresh now"))
63                 self["key_blue"] = Button(_("Edit Channels"))
64
65                 # Define Actions
66                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
67                         {
68                                 "cancel": self.keyCancel,
69                                 "save": self.keySave,
70                                 "yellow": self.forceRefresh,
71                                 "blue": self.editChannels
72                         }
73                 )
74
75                 # Trigger change
76                 self.changed()
77
78         def forceRefresh(self):
79                 epgrefresh.services = Set(self.servicelist)
80                 # TODO: maybe we need to save the configuration here...
81                 epgrefresh.refresh(self.session)
82
83         def editChannels(self):
84                 self.session.openWithCallback(
85                         self.editChannelsCallback,
86                         EPGRefreshChannelEditor,
87                         self.servicelist
88                 )
89
90         def editChannelsCallback(self, ret):
91                 if ret:
92                         self.servicelist = ret
93
94         def changed(self):
95                 for x in self.onChangedEntry:
96                         try:
97                                 x()
98                         except:
99                                 pass
100
101         def getCurrentEntry(self):
102                 return self["config"].getCurrent()[0]
103
104         def getCurrentValue(self):
105                 return str(self["config"].getCurrent()[1].getText())
106
107         def createSummary(self):
108                 return SetupSummary
109
110         def cancelConfirm(self, result):
111                 if not result:
112                         return
113
114                 for x in self["config"].list:
115                         x[1].cancel()
116
117                 self.close(self.session)
118
119         def keyCancel(self):
120                 if self["config"].isChanged():
121                         self.session.openWithCallback(
122                                 self.cancelConfirm,
123                                 MessageBox,
124                                 _("Really close without saving settings?")
125                         )
126                 else:
127                         self.close(self.session)
128
129         def keySave(self):
130                 epgrefresh.services = Set(self.servicelist)
131                 try:
132                         epgrefresh.saveConfiguration()
133                 except Exception, e:
134                         print "[EPGRefresh] Error occured while saving configuration:", e
135                 
136                 for x in self["config"].list:
137                         x[1].save()
138
139                 self.close(self.session)