Changed e-mail addy
[enigma2-plugins.git] / webinterface / src / WebIfConfig.py
1 Version = '$Header$';
2
3 from enigma import  eListboxPythonMultiContent, gFont
4 from Screens.Screen import Screen
5 from Screens.MessageBox import MessageBox
6
7 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigInteger,ConfigYesNo,ConfigText
8 from Components.ConfigList import ConfigListScreen
9 from Components.Label import Label
10 from Components.Button import Button
11 from Components.MenuList import MenuList
12 from Components.MultiContent import MultiContentEntryText
13
14 from Components.ActionMap import ActionMap
15 from Plugins.Extensions.WebInterface import addInterfaceConfig
16
17 class WebIfConfigScreen(ConfigListScreen,Screen):
18     skin = """
19         <screen position="100,100" size="550,400" title="Webinterface: Main Setup" >
20             <widget name="config" position="0,0" size="550,360" scrollbarMode="showOnDemand" />
21             
22             <widget name="key_red" position="0,360" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;18"/> 
23             <widget name="key_green" position="140,360" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;18"/> 
24             <widget name="key_yellow" position="280,360" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;18"/>
25             
26             <ePixmap name="red"    position="0,360"   zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
27             <ePixmap name="green"  position="140,360" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
28             <ePixmap name="yellow" position="280,360" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" /> 
29         </screen>"""
30     def __init__(self, session, args = 0):
31         self.session = session
32         Screen.__init__(self, session)
33         self.list = []
34         self.list.append(getConfigListEntry(_("start Webinterface"), config.plugins.Webinterface.enable))
35         self.list.append(getConfigListEntry(_("enable /hdd"), config.plugins.Webinterface.includehdd))
36         self.list.append(getConfigListEntry(_("allow zapping via webif"), config.plugins.Webinterface.allowzapping))
37         self.list.append(getConfigListEntry(_("autowrite timer"), config.plugins.Webinterface.autowritetimer))
38         self.list.append(getConfigListEntry(_("load movie-length"), config.plugins.Webinterface.loadmovielength))
39         
40         for i in range(0, config.plugins.Webinterface.interfacecount.value):
41             c = config.plugins.Webinterface.interfaces[i]
42             
43         ConfigListScreen.__init__(self, self.list)
44         self["key_red"] = Button(_("Cancel"))
45         self["key_green"] = Button(_("Ok"))
46         self["key_yellow"] = Button(_("Interfaces"))
47         self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
48         {
49             "red": self.cancel,
50             "green": self.save,
51             "yellow": self.openIfacesConfig,
52             "save": self.save,
53             "cancel": self.cancel,
54             "ok": self.save,
55         }, -2)
56         
57     def openIfacesConfig(self):
58         print "yellow"
59         self.session.open(WebIfInterfaceListConfigScreen)
60         
61     def save(self):
62         print "saving"
63         for x in self["config"].list:
64             x[1].save()
65         self.close(True,self.session)
66
67     def cancel(self):
68         print "cancel"
69         for x in self["config"].list:
70             x[1].cancel()
71         self.close(False,self.session)
72
73 class WebIfInterfaceListConfigScreen(Screen):
74     skin = """
75         <screen position="100,100" size="550,400" title="Webinterface: list of configured Interfaces" >
76             <widget name="adress" position="5,0" size="150,50"   font="Regular;20" halign="left"/>
77             <widget name="port" position="120,0" size="50,50"   font="Regular;20" halign="left"/>
78             <widget name="ssl" position="170,0" size="50,50"   font="Regular;20" halign="left"/>
79             <widget name="auth" position="230,0" size="200,50"   font="Regular;20" halign="left"/>
80             <widget name="disabled" position="430,0" size="130,50"   font="Regular;20" halign="left"/>
81             <widget name="ifacelist" position="0,50" size="550,300"  scrollbarMode="showOnDemand"/>
82             
83             <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" />
84                 <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" />
85             
86             <ePixmap name="red"    position="0,350"   zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
87             <ePixmap name="yellow" position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />    
88         </screen>"""
89     def __init__(self, session):
90         
91         Screen.__init__(self, session)
92         self["adress"] = Button(_("Adress"))
93         self["port"] = Button(_("Port"))
94         self["auth"] = Button(_("use Authorization"))
95         self["ssl"] = Button(_("use SSL"))
96         self["disabled"] = Button(_("disabled"))
97         self["key_red"] = Button(_("add"))
98         self["key_yellow"] = Button(_("change"))
99         self["ifacelist"] = WebIfInterfaceList([])
100         self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
101             {
102              "ok"       :       self.keyGreen,
103              "back"     :       self.close,
104              "red"      :       self.keyRed,
105              "green"    :       self.keyGreen,
106              "yellow"   :       self.keyYellow,
107              "up"       :       self.up,
108              "down"     :       self.down,
109              "left"     :       self.left,
110              "right"    :       self.right,
111              }, -1)
112         self.updateList()
113         
114     def updateList(self):
115         ifaceguilist = []
116         for i in range(0, config.plugins.Webinterface.interfacecount.value):
117             c= config.plugins.Webinterface.interfaces[i]
118             res = [ i ] #550,400
119             res.append(MultiContentEntryText(pos=(5, 0), size=(150, 25), font=0, text=c.adress.value))
120             res.append(MultiContentEntryText(pos=(120, 0),size=(50, 25), font=0,text=str(c.port.value)))
121             
122             if c.usessl.value:
123                 res.append(MultiContentEntryText(pos=(170, 0),size=(200, 25), font=0,text=_("yes"),color=0x0000FF00))
124             else:
125                 res.append(MultiContentEntryText(pos=(170, 0),size=(200, 25), font=0,text=_("no"),color=0x00FF0000))
126             
127             if c.useauth.value:
128                 res.append(MultiContentEntryText(pos=(230, 0),size=(200, 25), font=0,text=_("yes"),color=0x0000FF00))
129             else:
130                 res.append(MultiContentEntryText(pos=(230, 0),size=(200, 25), font=0,text=_("no"),color=0x00FF0000))
131                 
132             if c.disabled.value:
133                 res.append(MultiContentEntryText(pos=(430, 0),size=(130, 25), font=0,text=_("yes"),color=0x0000FF00))
134             else:
135                 res.append(MultiContentEntryText(pos=(430, 0),size=(130, 25), font=0,text=_("no"),color=0x00FF0000))
136             ifaceguilist.append(res)
137         ifaceguilist.sort()
138         self["ifacelist"].l.setList(ifaceguilist)
139
140     
141     def keyRed(self):
142         print "KEYRED"
143         self.session.openWithCallback(self.updateList,WebIfInterfaceConfigScreen,None)
144         
145     def keyGreen(self):
146         print "KEYGREEN"
147         
148     def keyYellow(self):
149         x = self["ifacelist"].getCurrent()[0]
150         print "current list index",x
151         self.session.openWithCallback(self.updateList,WebIfInterfaceConfigScreen,int(x))
152
153     def up(self):
154         self["ifacelist"].up()
155
156     def down(self):
157         self["ifacelist"].down()
158
159     def left(self):
160         self["ifacelist"].pageUp()
161
162     def right(self):
163         self["ifacelist"].pageDown()
164
165
166 class WebIfInterfaceList(MenuList):
167     def __init__(self, list, enableWrapAround = False):
168         MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
169         self.l.setFont(0, gFont("Regular", 20))
170         #self.l.setFont(1, gFont("Regular", 25))
171
172     def postWidgetCreate(self, instance):
173         MenuList.postWidgetCreate(self, instance)
174         instance.setItemHeight(25)
175     
176         
177 class WebIfInterfaceConfigScreen(Screen, ConfigListScreen):
178     skin = """
179         <screen name="Interface Config" position="80,148" size="560,280" title="Webinterface: edit Interface">
180             <widget name="config" position="10,10" size="520,210" scrollbarMode="showOnDemand" />
181             <ePixmap name="red"    position="0,240"   zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
182             <ePixmap name="green"  position="140,240" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />            
183             <ePixmap name="blue"   position="420,240" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
184             
185             <widget name="key_red" position="0,240" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
186             <widget name="key_green" position="140,240" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
187             <widget name="key_blue" position="420,240" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
188         </screen>"""
189     
190     def __init__(self, session, ifacenum):
191         Screen.__init__(self, session)
192         self["actions"] = ActionMap(["SetupActions", "ColorActions"],
193         {
194             "green": self.keySave,
195             "red": self.keyCancel,
196             "blue": self.keyDelete,
197             "cancel": self.keyCancel
198         }, -2)
199
200         self["key_red"] = Button(_("Cancel"))
201         self["key_green"] = Button(_("OK"))
202         #self["key_yellow"] = Button("")
203         self["key_blue"] = Button(_("Delete"))
204
205         if ifacenum is None:
206             i = addInterfaceConfig()
207         else:
208             i = ifacenum
209         cfglist = []
210         try:
211             current = config.plugins.Webinterface.interfaces[i]
212         except IndexError,e:
213             print "[WebIf] iface config %i not found, adding it and setting default values"%i
214             addInterfaceConfig()
215             current = config.plugins.Webinterface.interfaces[ifacenum]
216             
217         cfglist.append(getConfigListEntry(_("disabled"), current.disabled))
218         cfglist.append(getConfigListEntry(_("Adress"), current.adress))
219         cfglist.append(getConfigListEntry(_("Port"), current.port))
220         cfglist.append(getConfigListEntry(_("use Authorization"), current.useauth))
221         cfglist.append(getConfigListEntry(_("use SSL Encryption"), current.usessl))
222         ConfigListScreen.__init__(self, cfglist, session)
223         self.ifacenum = i
224
225     def keySave(self):
226         config.plugins.Webinterface.interfacecount.save()
227         for x in self["config"].list:
228             if isinstance(x[1].value, str):
229                 x[1].value = x[1].value.strip()
230             x[1].save()
231         self.close()
232         config.save()
233
234     def cancelConfirm(self, result):
235         if result:
236             config.plugins.Webinterface.interfacecount.cancel()
237         self.callback = None
238         ConfigListScreen.cancelConfirm(self, result)
239
240     def keyDelete(self):
241         self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this Interface?"))
242
243     def deleteConfirm(self, result):
244         if not result:
245             return
246         del(config.plugins.Webinterface.interfaces[self.ifacenum])
247         config.plugins.Webinterface.interfaces.save()
248         config.plugins.Webinterface.interfacecount.value = config.plugins.Webinterface.interfacecount.value - 1;
249         config.plugins.Webinterface.interfacecount.save()
250         config.save()
251         self.close()
252