Get timerlist from Partnerbox in a non-blocking way when opening EPGList (now it...
[enigma2-plugins.git] / partnerbox / src / PartnerboxSetup.py
1 #
2 #  Partnerbox E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2009
7 #  Support: www.dreambox-tools.info
8 #
9 #  This program is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU General Public License
11 #  as published by the Free Software Foundation; either version 2
12 #  of the License, or (at your option) any later version.
13 #
14 #  This program is distributed in the hope that it will be useful,
15 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #  GNU General Public License for more details.
18 #
19
20 from enigma import eListboxPythonMultiContent, eListbox, gFont, \
21         RT_HALIGN_LEFT, RT_VALIGN_CENTER
22 from Screens.Screen import Screen
23 from Screens.MessageBox import MessageBox
24 from Components.MenuList import MenuList
25 from Components.Button import Button
26 from Components.config import config
27 from Components.ActionMap import ActionMap, NumberActionMap
28 from Components.ConfigList import ConfigList, ConfigListScreen
29 from Components.config import ConfigSubsection, ConfigSubList, ConfigIP, ConfigInteger, ConfigSelection, ConfigText, ConfigYesNo, getConfigListEntry, configfile
30
31 def initPartnerboxEntryConfig():
32         config.plugins.Partnerbox.Entries.append(ConfigSubsection())
33         i = len(config.plugins.Partnerbox.Entries) -1
34         config.plugins.Partnerbox.Entries[i].name = ConfigText(default = "dreambox", visible_width = 50, fixed_size = False)
35         config.plugins.Partnerbox.Entries[i].ip = ConfigIP(default = [192,168,0,98])
36         config.plugins.Partnerbox.Entries[i].port = ConfigInteger(default=80, limits=(1, 65555))
37         config.plugins.Partnerbox.Entries[i].enigma = ConfigSelection(default="0", choices = [("0", _("Enigma 2")),("1", _("Enigma 1"))])
38         config.plugins.Partnerbox.Entries[i].password = ConfigText(default = "dreambox", visible_width = 50, fixed_size = False)
39         config.plugins.Partnerbox.Entries[i].useinternal = ConfigSelection(default="1", choices = [("0", _("use external")),("1", _("use internal"))])
40         return config.plugins.Partnerbox.Entries[i]
41
42 def initConfig():
43         count = config.plugins.Partnerbox.entriescount.value
44         if count != 0:
45                 i = 0
46                 while i < count:
47                         initPartnerboxEntryConfig()
48                         i += 1
49
50 class PartnerboxSetup(ConfigListScreen, Screen):
51         skin = """
52                 <screen position="100,100" size="550,400" title="Partnerbox Setup" >
53                         <widget name="config" position="20,10" size="510,330" scrollbarMode="showOnDemand" />
54                         <widget name="key_red" position="0,350" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
55                         <widget name="key_green" position="140,350" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
56                         <widget name="key_yellow" position="280,350" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
57                         <ePixmap name="red" pixmap="skin_default/buttons/red.png" position="0,350" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
58                         <ePixmap name="green" pixmap="skin_default/buttons/green.png" position="140,350" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
59                         <ePixmap name="yellow" pixmap="skin_default/buttons/yellow.png" position="280,350" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
60                 </screen>"""
61
62         def __init__(self, session, args = None):
63                 Screen.__init__(self, session)
64
65                 self["key_red"] = Button(_("Cancel"))
66                 self["key_green"] = Button(_("OK"))
67                 self["key_yellow"] = Button(_("Partnerbox Entries"))
68
69
70                 self.list = [ ]
71                 self.list.append(getConfigListEntry(_("Show 'RemoteTimer' in E-Menu"), config.plugins.Partnerbox.showremotetimerinextensionsmenu))
72                 self.list.append(getConfigListEntry(_("Show 'RemoteTV Player' in E-Menu"), config.plugins.Partnerbox.showremotetvinextensionsmenu))
73                 self.list.append(getConfigListEntry(_("Show 'Stream current Service' in E-Menu"), config.plugins.Partnerbox.showcurrentstreaminextensionsmenu))
74                 self.list.append(getConfigListEntry(_("Enable Partnerbox-Function in TimerEvent"), config.plugins.Partnerbox.enablepartnerboxintimerevent))
75                 self.list.append(getConfigListEntry(_("Enable Partnerbox-Function in EPGList"), config.plugins.Partnerbox.enablepartnerboxepglist))
76                 ConfigListScreen.__init__(self, self.list, session)
77                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
78                 {
79                         "green": self.keySave,
80                         "cancel": self.keyClose,
81                         "ok": self.keySave,
82                         "yellow": self.PartnerboxEntries,
83                 }, -2)
84
85         def keySave(self):
86                 for x in self["config"].list:
87                         x[1].save()
88                 configfile.save()
89                 self.close(self.session, True)
90
91         def keyClose(self):
92                 for x in self["config"].list:
93                         x[1].cancel()
94                 self.close(self.session, False)
95
96         def PartnerboxEntries(self):
97                 self.session.open(PartnerboxEntriesListConfigScreen)
98
99
100 class PartnerboxEntriesListConfigScreen(Screen):
101         skin = """
102                 <screen position="100,100" size="550,400" title="%s" >
103                         <widget name="name" position="5,0" size="150,50" font="Regular;20" halign="left"/>
104                         <widget name="ip" position="120,0" size="50,50" font="Regular;20" halign="left"/>
105                         <widget name="port" position="270,0" size="100,50" font="Regular;20" halign="left"/>
106                         <widget name="type" position="410,0" size="160,50" font="Regular;20" halign="left"/>
107                         <widget name="entrylist" position="0,50" size="550,300" scrollbarMode="showOnDemand"/>
108
109                         <widget name="key_red" position="0,350" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
110                         <widget name="key_yellow" position="280,350" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="yellow" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
111                         <widget name="key_blue" position="420,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
112                         <ePixmap name="red" position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
113                         <ePixmap name="yellow" position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
114                         <ePixmap name="blue" position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
115                 </screen>""" % _("Partnerbox: List of Entries")
116
117         def __init__(self, session, what = None):
118                 Screen.__init__(self, session)
119                 self.session = session
120                 self["name"] = Button(_("Name"))
121                 self["ip"] = Button(_("IP"))
122                 self["port"] = Button(_("Port"))
123                 self["type"] = Button(_("Enigma Type"))
124                 self["key_red"] = Button(_("Add"))
125                 self["key_yellow"] = Button(_("Edit"))
126                 self["key_blue"] = Button(_("Delete"))
127                 self["entrylist"] = PartnerboxEntryList([])
128                 self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
129                         {
130                          "ok"   :       self.keyOK,
131                          "back" :       self.keyClose,
132                          "red"  :       self.keyRed,
133                          "yellow":      self.keyYellow,
134                          "blue":        self.keyDelete,
135                          }, -1)
136                 self.what = what
137                 self.updateList()
138
139         def updateList(self):
140                 self["entrylist"].buildList()
141
142         def keyClose(self):
143                 self.close(self.session, self.what, None)
144
145         def keyRed(self):
146                 self.session.openWithCallback(self.updateList,PartnerboxEntryConfigScreen,None)
147
148         def keyOK(self):
149                 try:sel = self["entrylist"].l.getCurrentSelection()[0]
150                 except: sel = None
151                 self.close(self.session, self.what, sel)
152
153         def keyYellow(self):
154                 try:sel = self["entrylist"].l.getCurrentSelection()[0]
155                 except: sel = None
156                 if sel is None:
157                         return
158                 self.session.openWithCallback(self.updateList,PartnerboxEntryConfigScreen,sel)
159
160         def keyDelete(self):
161                 try:sel = self["entrylist"].l.getCurrentSelection()[0]
162                 except: sel = None
163                 if sel is None:
164                         return
165                 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this Partnerbox Entry?"))
166
167         def deleteConfirm(self, result):
168                 if not result:
169                         return
170                 sel = self["entrylist"].l.getCurrentSelection()[0]
171                 config.plugins.Partnerbox.entriescount.value = config.plugins.Partnerbox.entriescount.value - 1
172                 config.plugins.Partnerbox.entriescount.save()
173                 config.plugins.Partnerbox.Entries.remove(sel)
174                 config.plugins.Partnerbox.Entries.save()
175                 config.plugins.Partnerbox.save()
176                 configfile.save()
177                 self.updateList()
178
179 class PartnerboxEntryList(MenuList):
180         def __init__(self, list, enableWrapAround = True):
181                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
182                 self.l.setFont(0, gFont("Regular", 20))
183                 self.l.setFont(1, gFont("Regular", 18))
184         def postWidgetCreate(self, instance):
185                 MenuList.postWidgetCreate(self, instance)
186                 instance.setItemHeight(20)
187
188         def buildList(self):
189                 self.list=[]
190                 for c in config.plugins.Partnerbox.Entries:
191                         res = [c]
192                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.name.value)))
193                         ip = "%d.%d.%d.%d" % tuple(c.ip.value)
194                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 120, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(ip)))
195                         port = "%d"%(c.port.value)
196                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 270, 0, 100, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(port)))
197                         if int(c.enigma.value) == 0:
198                                 e_type = "Enigma2"
199                         else:
200                                 e_type = "Enigma1"
201                         res.append((eListboxPythonMultiContent.TYPE_TEXT, 410, 0, 100, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(e_type)))
202                         self.list.append(res)
203                 self.l.setList(self.list)
204                 self.moveToIndex(0)
205
206 class PartnerboxEntryConfigScreen(ConfigListScreen, Screen):
207         skin = """
208                 <screen name="PartnerboxEntryConfigScreen" position="100,100" size="550,400" title="%s">
209                         <widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
210                         <ePixmap name="red"     position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
211                         <ePixmap name="green" position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
212                         <ePixmap name="blue" position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
213
214                         <widget name="key_red" position="0,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
215                         <widget name="key_green" position="140,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
216                         <widget name="key_blue" position="420,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
217                 </screen>""" % _("Partnerbox: Edit Entry")
218
219         def __init__(self, session, entry):
220                 self.session = session
221                 Screen.__init__(self, session)
222
223                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
224                 {
225                         "green": self.keySave,
226                         "red": self.keyCancel,
227                         "blue": self.keyDelete,
228                         "cancel": self.keyCancel
229                 }, -2)
230
231                 self["key_red"] = Button(_("Cancel"))
232                 self["key_green"] = Button(_("OK"))
233                 self["key_blue"] = Button(_("Delete"))
234
235                 if entry is None:
236                         self.newmode = 1
237                         self.current = initPartnerboxEntryConfig()
238                 else:
239                         self.newmode = 0
240                         self.current = entry
241
242                 cfglist = [
243                         getConfigListEntry(_("Name"), self.current.name),
244                         getConfigListEntry(_("IP"), self.current.ip),
245                         getConfigListEntry(_("Port"), self.current.port),
246                         getConfigListEntry(_("Enigma Type"), self.current.enigma),
247                         getConfigListEntry(_("Password"), self.current.password),
248                         getConfigListEntry(_("Servicelists/EPG"), self.current.useinternal)
249                 ]
250
251                 ConfigListScreen.__init__(self, cfglist, session)
252
253         def keySave(self):
254                 if self.newmode == 1:
255                         config.plugins.Partnerbox.entriescount.value = config.plugins.Partnerbox.entriescount.value + 1
256                         config.plugins.Partnerbox.entriescount.save()
257                 ConfigListScreen.keySave(self)
258                 config.plugins.Partnerbox.save()
259                 configfile.save()
260                 self.close()
261
262         def keyCancel(self):
263                 if self.newmode == 1:
264                         config.plugins.Partnerbox.Entries.remove(self.current)
265                 ConfigListScreen.cancelConfirm(self, True)
266
267         def keyDelete(self):
268                 if self.newmode == 1:
269                         self.keyCancel()
270                 else:           
271                         self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this Partnerbox Entry?"))
272
273         def deleteConfirm(self, result):
274                 if not result:
275                         return
276                 config.plugins.Partnerbox.entriescount.value = config.plugins.Partnerbox.entriescount.value - 1
277                 config.plugins.Partnerbox.entriescount.save()
278                 config.plugins.Partnerbox.Entries.remove(self.current)
279                 config.plugins.Partnerbox.Entries.save()
280                 config.plugins.Partnerbox.save()
281                 configfile.save()
282                 self.close()