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