EPGRefreshConfiguration.py: show last refresh date/time on info pressed
[enigma2-plugins.git] / epgrefresh / src / EPGRefreshConfiguration.py
1 # for localized messages
2 from . import _
3
4 # GUI (Screens)
5 from Screens.Screen import Screen
6 from Components.ConfigList import ConfigListScreen
7 from EPGRefreshChannelEditor import EPGRefreshServiceEditor
8
9 # GUI (Summary)
10 from Screens.Setup import SetupSummary
11
12 # GUI (Components)
13 from Components.ActionMap import ActionMap
14 from Components.Sources.StaticText import StaticText
15
16 # Configuration
17 from Components.config import config, getConfigListEntry
18
19 from EPGRefresh import epgrefresh
20 from Components.SystemInfo import SystemInfo
21
22 class EPGRefreshConfiguration(Screen, ConfigListScreen):
23         """Configuration of EPGRefresh"""
24
25         skin = """<screen name="EPGRefreshConfiguration" title="Configure EPGRefresh" position="center,center" size="565,370">
26                 <ePixmap position="0,5" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
27                 <ePixmap position="140,5" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
28                 <ePixmap position="280,5" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
29                 <ePixmap position="420,5" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
30                 <widget source="key_red" render="Label" position="0,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
31                 <widget source="key_green" render="Label" position="140,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
32                 <widget source="key_yellow" render="Label" position="280,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
33                 <widget source="key_blue" render="Label" position="420,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
34                 <widget name="config" position="5,50" size="555,250" scrollbarMode="showOnDemand" />
35                 <ePixmap pixmap="skin_default/div-h.png" position="0,301" zPosition="1" size="565,2" />
36                 <widget source="help" render="Label" position="5,305" size="555,63" font="Regular;21" />
37         </screen>"""
38
39         def __init__(self, session):
40                 Screen.__init__(self, session)
41
42                 # Summary
43                 self.setup_title = _("EPGRefresh Configuration")
44                 self.onChangedEntry = []
45
46                 # Although EPGRefresh keeps services in a Set we prefer a list
47                 self.services = (
48                         [x for x in epgrefresh.services[0]],
49                         [x for x in epgrefresh.services[1]]
50                 )
51
52                 self.list = [
53                         getConfigListEntry(_("Refresh automatically"), config.plugins.epgrefresh.enabled, _("Unless this is enabled EPGRefresh won't automatically run but has to be explicitely started through the yellow button from this menu.")),
54                         getConfigListEntry(_("Wakeup from Deep-Standby to refresh EPG"), config.plugins.epgrefresh.wakeup, _("If this is enabled, the plugin will wake the receiver up from deep-standby if possible. Otherwise it has to be turned on already.")),
55                         getConfigListEntry(_("Time to stay on service (in m)"), config.plugins.epgrefresh.interval, _("This is the ammount of time a channel will be active during a refresh.")),
56                         getConfigListEntry(_("Refresh EPG after"), config.plugins.epgrefresh.begin, _("An automated refresh will happen after this time of day, but before the next setting.")),
57                         getConfigListEntry(_("Refresh EPG before"), config.plugins.epgrefresh.end, _("An automated refresh will happen before this time of day, but after the previous setting.")),
58                         getConfigListEntry(_("Delay when not in Standby (in m)"), config.plugins.epgrefresh.delay_standby, _("If the receiver is currently not in standby this is the amount of time EPGRefresh will wait before trying again.")),
59                         getConfigListEntry(_("Force scan even if receiver is in use"), config.plugins.epgrefresh.force, _("This setting controls whether or not the refresh will also be initiated when the receiver is being used (namely not in standby or currently recording).")),
60                         getConfigListEntry(_("Inherit Services from AutoTimer if available"), config.plugins.epgrefresh.inherit_autotimer, _("If you're also using the AutoTimer plugin this allows to extend the list of services to refresh by the services your AutoTimers are restricted to.")),
61                         getConfigListEntry(_("Make AutoTimer parse EPG if available"), config.plugins.epgrefresh.parse_autotimer, _("If you're also using the AutoTimer plugin this will initiate a scan of the EPG after a completed refresh.")),
62                         getConfigListEntry(_("Shutdown after refresh"), config.plugins.epgrefresh.afterevent, _("This setting controls if the receiver should be sent to deep-standby after a completed refresh.")),
63                 ]
64                 if SystemInfo.get("NumVideoDecoders", 1) > 1:
65                         self.list.insert(1, getConfigListEntry(_("Refresh in Background"), config.plugins.epgrefresh.background, _("Use Picture In Picture to refresh EPG?")))
66
67                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
68                 def selectionChanged():
69                         if self["config"].current:
70                                 self["config"].current[1].onDeselect(self.session)
71                         self["config"].current = self["config"].getCurrent()
72                         if self["config"].current:
73                                 self["config"].current[1].onSelect(self.session)
74                         for x in self["config"].onSelectionChanged:
75                                 x()
76                 self["config"].selectionChanged = selectionChanged
77                 self["config"].onSelectionChanged.append(self.updateHelp)
78
79                 # Initialize Buttons
80                 self["key_red"] = StaticText(_("Cancel"))
81                 self["key_green"] = StaticText(_("OK"))
82                 self["key_yellow"] = StaticText(_("Refresh now"))
83                 self["key_blue"] = StaticText(_("Edit Services"))
84
85                 self["help"] = StaticText()
86
87                 # Define Actions
88                 self["actions"] = ActionMap(["SetupActions", "ColorActions", "ChannelSelectEPGActions"],
89                         {
90                                 "cancel": self.keyCancel,
91                                 "save": self.keySave,
92                                 "yellow": self.forceRefresh,
93                                 "blue": self.editServices,
94                                 "showEPGList": self.keyInfo,
95                         }
96                 )
97
98                 # Trigger change
99                 self.changed()
100
101                 self.onLayoutFinish.append(self.setCustomTitle)
102
103         def setCustomTitle(self):
104                 self.setTitle(_("Configure EPGRefresh"))
105
106         def updateHelp(self):
107                 cur = self["config"].getCurrent()
108                 if cur:
109                         self["help"].text = cur[2]
110
111         def forceRefresh(self):
112                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
113                 epgrefresh.forceRefresh(self.session)
114
115         def editServices(self):
116                 self.session.openWithCallback(
117                         self.editServicesCallback,
118                         EPGRefreshServiceEditor,
119                         self.services
120                 )
121
122         def editServicesCallback(self, ret):
123                 if ret:
124                         self.services = ret
125
126         def changed(self):
127                 for x in self.onChangedEntry:
128                         try:
129                                 x()
130                         except Exception:
131                                 pass
132
133         def getCurrentEntry(self):
134                 return self["config"].getCurrent()[0]
135
136         def getCurrentValue(self):
137                 return str(self["config"].getCurrent()[1].getText())
138
139         def createSummary(self):
140                 return SetupSummary
141
142         def cancelConfirm(self, result):
143                 if not result:
144                         return
145
146                 for x in self["config"].list:
147                         x[1].cancel()
148
149                 self.close(self.session)
150
151         def keyInfo(self):
152                 from Screens.MessageBox import MessageBox
153
154                 lastscan = config.plugins.epgrefresh.lastscan.value
155                 if lastscan:
156                         from Tools.FuzzyDate import FuzzyTime
157                         scanDate = ', '.join(FuzzyTime(lastscan))
158                 else:
159                         scanDate = _("never")
160
161                 self.session.open(
162                                 MessageBox,
163                                 _("Last refresh was %s") % (scanDate,),
164                                 type=MessageBox.TYPE_INFO
165                 )
166
167         def keyCancel(self):
168                 if self["config"].isChanged():
169                         from Screens.MessageBox import MessageBox
170
171                         self.session.openWithCallback(
172                                 self.cancelConfirm,
173                                 MessageBox,
174                                 _("Really close without saving settings?")
175                         )
176                 else:
177                         self.close(self.session)
178
179         def keySave(self):
180                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
181                 epgrefresh.saveConfiguration()
182
183                 for x in self["config"].list:
184                         x[1].save()
185
186                 self.close(self.session)