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