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