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