added maintainer.info
[enigma2-plugins.git] / autotimer / src / AutoTimerOverview.py
1 # for localized messages
2 from . import _
3
4 # GUI (Screens)
5 from Screens.Screen import Screen
6 from Screens.HelpMenu import HelpableScreen
7 from Screens.MessageBox import MessageBox
8 from Screens.ChoiceBox import ChoiceBox
9 from AutoTimerEditor import AutoTimerEditor
10 from AutoTimerSettings import AutoTimerSettings
11 from AutoTimerPreview import AutoTimerPreview
12 from AutoTimerImporter import AutoTimerImportSelector
13 from AutoTimerWizard import AutoTimerWizard
14
15 # GUI (Components)
16 from AutoTimerList import AutoTimerList
17 from Components.ActionMap import HelpableActionMap
18 from Components.Button import Button
19 from Components.config import config
20
21 # Plugin
22 from AutoTimerComponent import AutoTimerComponent
23
24 class AutoTimerOverview(Screen, HelpableScreen):
25         """Overview of AutoTimers"""
26
27         skin = """<screen name="AutoTimerOverview" position="140,148" size="460,265" title="AutoTimer Overview">
28                         <widget name="entries" position="5,5" size="450,200" scrollbarMode="showOnDemand" />
29                         <ePixmap position="0,220" zPosition="1" size="140,40" pixmap="skin_default/buttons/green.png" alphatest="on" />
30                         <ePixmap position="140,220" zPosition="1" size="140,40" pixmap="skin_default/buttons/yellow.png" alphatest="on" />
31                         <ePixmap position="280,220" zPosition="1" size="140,40" pixmap="skin_default/buttons/blue.png" alphatest="on" />
32                         <ePixmap position="422,230" zPosition="1" size="35,25" pixmap="skin_default/buttons/key_menu.png" alphatest="on" />
33                         <widget name="key_green" position="0,220" zPosition="2" size="140,40" halign="center" valign="center" font="Regular;21" transparent="1" shadowColor="black" shadowOffset="-1,-1" />
34                         <widget name="key_yellow" position="140,220" zPosition="2" size="140,40" halign="center" valign="center" font="Regular;21" transparent="1" shadowColor="black" shadowOffset="-1,-1" />
35                         <widget name="key_blue" position="280,220" zPosition="2" size="140,40" halign="center" valign="center" font="Regular;21" transparent="1" shadowColor="black" shadowOffset="-1,-1" />
36                 </screen>"""
37
38         def __init__(self, session, autotimer):
39                 Screen.__init__(self, session)
40                 HelpableScreen.__init__(self)
41
42                 # Save autotimer
43                 self.autotimer = autotimer
44
45                 self.changed = False
46
47                 # Button Labels
48                 self["key_green"] = Button(_("Save"))
49                 self["key_yellow"] = Button(_("Delete"))
50                 self["key_blue"] = Button(_("Add"))
51
52                 # Create List of Timers
53                 self["entries"] = AutoTimerList(self.autotimer.getTupleTimerList())
54
55                 # Define Actions
56                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
57                         {
58                                 "ok": (self.ok, _("Edit selected AutoTimer")),
59                                 "cancel": (self.cancel, _("Close and forget changes")),
60                         }
61                 )
62
63                 self["MenuActions"] = HelpableActionMap(self, "MenuActions",
64                         {
65                                 "menu": (self.menu, _("Open Context Menu"))
66                         }
67                 )
68
69                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
70                         {
71                                 "green": (self.save, _("Close and save changes")),
72                                 "yellow": (self.remove, _("Remove selected AutoTimer")),
73                                 "blue": (self.add, _("Add new AutoTimer")),
74                         }
75                 )
76
77         def add(self):
78                 newTimer = self.autotimer.defaultTimer.clone()
79                 newTimer.id = self.autotimer.getUniqueId()
80
81                 if config.plugins.autotimer.editor.value == "wizard":
82                         self.session.openWithCallback(
83                                 self.addCallback,
84                                 AutoTimerWizard,
85                                 newTimer
86                         )
87                 else:
88                         self.session.openWithCallback(
89                                 self.addCallback,
90                                 AutoTimerEditor,
91                                 newTimer
92                         )
93
94         def editCallback(self, ret):
95                 if ret:
96                         self.changed = True
97                         self.refresh()
98
99         def addCallback(self, ret):
100                 if ret:
101                         self.changed = True
102                         self.autotimer.add(ret)
103                         self.refresh()
104
105         def importCallback(self, ret):
106                 if ret:
107                         self.session.openWithCallback(
108                                 self.addCallback,
109                                 AutoTimerEditor,
110                                 ret
111                         )
112
113         def refresh(self, res = None):
114                 # Re-assign List
115                 cur = self["entries"].getCurrent()
116                 self["entries"].setList(self.autotimer.getSortedTupleTimerList())
117                 self["entries"].moveToEntry(cur)
118
119         def ok(self):
120                 # Edit selected Timer
121                 current = self["entries"].getCurrent()
122                 if current is not None:
123                         self.session.openWithCallback(
124                                 self.editCallback,
125                                 AutoTimerEditor,
126                                 current
127                         )
128
129         def remove(self):
130                 # Remove selected Timer
131                 cur = self["entries"].getCurrent()
132                 if cur is not None:
133                         self.session.openWithCallback(
134                                 self.removeCallback,
135                                 MessageBox,
136                                 _("Do you really want to delete %s?") % (cur.name),
137                         )
138
139         def removeCallback(self, ret):
140                 cur = self["entries"].getCurrent()
141                 if ret and cur:
142                         self.autotimer.remove(cur.id)
143                         self.refresh()
144
145         def cancel(self):
146                 if self.changed:
147                         self.session.openWithCallback(
148                                 self.cancelConfirm,
149                                 MessageBox,
150                                 _("Really close without saving settings?")
151                         )
152                 else:
153                         self.close(None)
154
155         def cancelConfirm(self, ret):
156                 if ret:
157                         # Invalidate config mtime to force re-read on next run
158                         self.autotimer.configMtime = -1
159
160                         # Close and indicated that we canceled by returning None
161                         self.close(None)
162
163         def menu(self):
164                 list = [
165                         (_("Preview"), "preview"),
166                         (_("Import"), "import"),
167                         (_("Setup"), "setup"),
168                         (_("Edit new timer defaults"), "defaults"),
169                 ]
170
171                 if config.plugins.autotimer.editor.value == "wizard":
172                         list.append((_("Create a new timer using the classic editor"), "newplain"))
173                 else:
174                         list.append((_("Create a new timer using the wizard"), "newwizard"))
175
176                 self.session.openWithCallback(
177                         self.menuCallback,
178                         ChoiceBox,
179                         list = list,
180                 )
181
182         def menuCallback(self, ret):
183                 ret = ret and ret[1]
184                 if ret:
185                         if ret == "preview":
186                                 total, new, modified, timers = self.autotimer.parseEPG(simulateOnly = True)
187                                 self.session.open(
188                                         AutoTimerPreview,
189                                         timers
190                                 )
191                         elif ret == "import":
192                                 newTimer = self.autotimer.defaultTimer.clone()
193                                 newTimer.id = self.autotimer.getUniqueId()
194
195                                 self.session.openWithCallback(
196                                         self.importCallback,
197                                         AutoTimerImportSelector,
198                                         newTimer
199                                 )
200                         elif ret == "setup":
201                                 self.session.open(
202                                         AutoTimerSettings
203                                 )
204                         elif ret == "defaults":
205                                 self.session.open(
206                                         AutoTimerEditor,
207                                         self.autotimer.defaultTimer,
208                                         editingDefaults = True
209                                 )
210                         elif ret == "newwizard":
211                                 newTimer = self.autotimer.defaultTimer.clone()
212                                 newTimer.id = self.autotimer.getUniqueId()
213
214                                 self.session.openWithCallback(
215                                         self.addCallback, # XXX: we could also use importCallback... dunno what seems more natural
216                                         AutoTimerWizard,
217                                         newTimer
218                                 )
219                         elif ret == "newplain":
220                                 newTimer = self.autotimer.defaultTimer.clone()
221                                 newTimer.id = self.autotimer.getUniqueId()
222
223                                 self.session.openWithCallback(
224                                         self.addCallback,
225                                         AutoTimerEditor,
226                                         newTimer
227                                 )
228
229         def save(self):
230                 # Just close here, saving will be done by cb
231                 self.close(self.session)
232