smaller fixes, bump required e2 version, add sample for custom destination path
[enigma2-plugins.git] / autotimer / src / AutoTimerOverview.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Screens.ChoiceBox import ChoiceBox
5 from AutoTimerEditor import AutoTimerEditor
6 from AutoTimerConfiguration import AutoTimerConfiguration
7 from AutoTimerPreview import AutoTimerPreview
8 from AutoTimerImporter import AutoTimerImportSelector
9
10 # GUI (Components)
11 from AutoTimerList import AutoTimerList
12 from Components.ActionMap import ActionMap
13 from Components.Button import Button
14
15 # Plugin
16 from AutoTimerComponent import AutoTimerComponent
17
18 class AutoTimerOverview(Screen):
19         """Overview of AutoTimers"""
20
21         skin = """<screen name="AutoTimerOverview" position="140,148" size="460,265" title="AutoTimer Overview">
22                         <widget name="entries" position="5,5" size="450,200" scrollbarMode="showOnDemand" />
23                         <ePixmap position="0,220" zPosition="1" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
24                         <ePixmap position="140,220" zPosition="1" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
25                         <ePixmap position="280,220" zPosition="1" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
26                         <ePixmap position="422,230" zPosition="1" size="36,20" pixmap="key_menu-fs8.png" transparent="1" alphatest="on" />
27                         <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" />
28                         <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" />
29                         <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" />
30                 </screen>"""
31
32         def __init__(self, session, autotimer):
33                 Screen.__init__(self, session)
34
35                 # Save autotimer
36                 self.autotimer = autotimer
37
38                 self.changed = False
39
40                 # Button Labels
41                 self["key_green"] = Button(_("Save"))
42                 self["key_yellow"] = Button(_("Delete"))
43                 self["key_blue"] = Button(_("Add"))
44
45                 # Create List of Timers
46                 self["entries"] = AutoTimerList(self.autotimer.getTupleTimerList())
47
48                 # Define Actions
49                 self["actions"] = ActionMap(["OkCancelActions", "MenuActions", "ColorActions"],
50                         {
51                                 "ok": self.ok,
52                                 "cancel": self.cancel,
53                                 "green": self.save,
54                                 "yellow": self.remove,
55                                 "blue": self.add,
56                                 "menu": self.menu
57                         }
58                 )
59
60         def add(self):
61                 self.session.openWithCallback(
62                         self.addCallback,
63                         AutoTimerEditor,
64                         # TODO: implement setting a default?
65                         AutoTimerComponent(
66                                 self.autotimer.getUniqueId(),   # Id
67                                 "",                                                             # Name
68                                 "",                                                             # Match
69                                 True                                                    # Enabled
70                         )
71                 )
72
73         def editCallback(self, ret):
74                 if ret:
75                         self.changed = True
76                         self.refresh()
77
78         def addCallback(self, ret):
79                 if ret:
80                         self.changed = True
81                         self.autotimer.add(ret)
82                         self.refresh()
83
84         def refresh(self, res = None):
85                 # Re-assign List
86                 self["entries"].setList(self.autotimer.getTupleTimerList())
87
88         def ok(self):
89                 # Edit selected Timer
90                 current = self["entries"].getCurrent()
91                 if current is not None:
92                         self.session.openWithCallback(
93                                 self.editCallback,
94                                 AutoTimerEditor,
95                                 current[0]
96                         )
97
98         def remove(self):
99                 # Remove selected Timer
100                 cur = self["entries"].getCurrent()
101                 if cur is not None:
102                         self.session.openWithCallback(
103                                 self.removeCallback,
104                                 MessageBox,
105                                 _("Do you really want to delete %s?") % (cur[0].name),
106                         )
107
108         def removeCallback(self, ret):
109                 cur = self["entries"].getCurrent()
110                 if ret and cur:
111                         self.autotimer.remove(cur[0].id)
112                         self.refresh()
113
114         def cancel(self):
115                 if self.changed:
116                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
117                 else:
118                         self.close(None)
119
120         def cancelConfirm(self, ret):
121                 if ret:
122                         # Invalidate config mtime to force re-read on next run
123                         self.autotimer.configMtime = -1
124
125                         # Close and indicated that we canceled by returning None
126                         self.close(None)
127
128         def menu(self):
129                 self.session.openWithCallback(
130                         self.menuCallback,
131                         ChoiceBox,
132                         list = [
133                                 (_("Preview"), "preview"),
134                                 (_("Import"), "import"),
135                                 (_("Setup"), "setup"),
136                         ],
137                 )
138
139         def menuCallback(self, ret):
140                 if ret:
141                         if ret[1] == "preview":
142                                 total, new, modified, timers = self.autotimer.parseEPG(simulateOnly = True)
143                                 self.session.open(
144                                         AutoTimerPreview,
145                                         timers
146                                 )
147                         elif ret[1] == "import":
148                                 self.session.openWithCallback(
149                                         self.addCallback,
150                                         AutoTimerImportSelector,
151                                         AutoTimerComponent(
152                                                 self.autotimer.getUniqueId(),   # Id
153                                                 "",                                                             # Name
154                                                 "",                                                             # Match
155                                                 True                                                    # Enabled
156                                         )
157                                 )
158                         elif ret[1] == "setup":
159                                 self.session.open(
160                                         AutoTimerConfiguration
161                                 )
162
163         def save(self):
164                 # Just close here, saving will be done by cb
165                 self.close(self.session)