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