Add German Translation for the GUI-Part (please test and report)
[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,ConfigSelection
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,getCofiguredAndSpecialNetworkinterfaces
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="5,5" size="540,360" scrollbarMode="showOnDemand" zPosition="1"/>
21             
22             <widget name="key_red" position="0,360" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/> 
23             <widget name="key_green" position="140,360" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/> 
24             <widget name="key_yellow" position="280,360" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
25             
26             <ePixmap name="red" pixmap="skin_default/buttons/red.png" position="0,360" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
27             <ePixmap name="green" pixmap="skin_default/buttons/green.png" position="140,360" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
28             <ePixmap name="yellow"  pixmap="skin_default/buttons/yellow.png" position="280,360" size="140,40" zPosition="4" 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 Webinterface"), 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="address" 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="170,50" font="Regular;20" halign="left"/>
80             <widget name="disabled" position="400,0" size="160,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             <ePixmap name="red" position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
86             <ePixmap name="yellow" position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />    
87         </screen>"""
88         
89     def __init__(self, session):
90         Screen.__init__(self, session)
91         self["address"] = Button(_("Address"))
92         self["port"] = Button(_("Port"))
93         self["auth"] = Button(_("Authorization"))
94         self["ssl"] = Button(_("SSL"))
95         self["disabled"] = Button(_("Disabled"))
96         self["key_red"] = Button(_("Add"))
97         self["key_yellow"] = Button(_("Change"))
98         self["ifacelist"] = WebIfInterfaceList([])
99         self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
100             {
101              "ok"       :       self.keyGreen,
102              "back"     :       self.close,
103              "red"      :       self.keyRed,
104              "green":   self.keyGreen,
105              "yellow":  self.keyYellow,
106              "up"       :       self.up,
107              "down"     :       self.down,
108              "left"     :       self.left,
109              "right":   self.right,
110              }, -1)
111         self.updateList()
112         
113     def updateList(self):
114         ifaceguilist = []
115         for i in range(0, config.plugins.Webinterface.interfacecount.value):
116             c= config.plugins.Webinterface.interfaces[i]
117             res = [ i ] #550,400
118             res.append(MultiContentEntryText(pos=(5, 0), size=(150, 25), font=0, text=c.address.value))
119             res.append(MultiContentEntryText(pos=(120, 0),size=(50, 25), font=0,text=str(c.port.value)))
120             
121             if c.usessl.value:
122                 res.append(MultiContentEntryText(pos=(170, 0),size=(200, 25), font=0,text=_("yes"),color=0x0000FF00))
123             else:
124                 res.append(MultiContentEntryText(pos=(170, 0),size=(200, 25), font=0,text=_("no"),color=0x00FF0000))
125             
126             if c.useauth.value:
127                 res.append(MultiContentEntryText(pos=(230, 0),size=(170, 25), font=0,text=_("yes"),color=0x0000FF00))
128             else:
129                 res.append(MultiContentEntryText(pos=(230, 0),size=(170, 25), font=0,text=_("no"),color=0x00FF0000))
130                 
131             if c.disabled.value:
132                 res.append(MultiContentEntryText(pos=(400, 0),size=(160, 25), font=0,text=_("yes"),color=0x0000FF00))
133             else:
134                 res.append(MultiContentEntryText(pos=(400, 0),size=(160, 25), font=0,text=_("no"),color=0x00FF0000))
135             ifaceguilist.append(res)
136         ifaceguilist.sort()
137         self["ifacelist"].l.setList(ifaceguilist)
138
139     
140     def keyRed(self):
141         print "KEYRED"
142         self.session.openWithCallback(self.updateList,WebIfInterfaceConfigScreen,None)
143         
144     def keyGreen(self):
145         print "KEYGREEN"
146         
147     def keyYellow(self):
148         x = self["ifacelist"].getCurrent()[0]
149         print "current list index",x
150         self.session.openWithCallback(self.updateList,WebIfInterfaceConfigScreen,int(x))
151
152     def up(self):
153         self["ifacelist"].up()
154
155     def down(self):
156         self["ifacelist"].down()
157
158     def left(self):
159         self["ifacelist"].pageUp()
160
161     def right(self):
162         self["ifacelist"].pageDown()
163
164
165 class WebIfInterfaceList(MenuList):
166     def __init__(self, list, enableWrapAround = False):
167         MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
168         self.l.setFont(0, gFont("Regular", 20))
169         #self.l.setFont(1, gFont("Regular", 25))
170
171     def postWidgetCreate(self, instance):
172         MenuList.postWidgetCreate(self, instance)
173         instance.setItemHeight(25)
174     
175         
176 class WebIfInterfaceConfigScreen(Screen, ConfigListScreen):
177     skin = """
178         <screen name="Interface Config" position="80,148" size="560,280" title="Webinterface: edit Interface">
179             <widget name="config" position="10,10" size="520,210" scrollbarMode="showOnDemand" />
180             <ePixmap name="red"    position="0,240"   zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
181             <ePixmap name="green"  position="140,240" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />            
182             <ePixmap name="blue"   position="420,240" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
183             
184             <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" />
185             <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" />
186             <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" />
187         </screen>"""
188     
189     def __init__(self, session, ifacenum):
190         Screen.__init__(self, session)
191         self["actions"] = ActionMap(["SetupActions", "ColorActions"],
192         {
193             "green": self.keySave,
194             "red": self.keyCancel,
195             "blue": self.keyDelete,
196             "cancel": self.keyCancel
197         }, -2)
198
199         self["key_red"] = Button(_("Cancel"))
200         self["key_green"] = Button(_("OK"))
201         #self["key_yellow"] = Button("")
202         self["key_blue"] = Button(_("Delete"))
203
204         if ifacenum is None:
205             i = addInterfaceConfig()
206         else:
207             i = ifacenum
208         cfglist = []
209         try:
210             current = config.plugins.Webinterface.interfaces[i]
211         except IndexError,e:
212             print "[WebIf] iface config %i not found, adding it and setting default values"%i
213             addInterfaceConfig()
214             current = config.plugins.Webinterface.interfaces[ifacenum]
215         
216         #reloading current network devices
217         current.address = ConfigSelection(getCofiguredAndSpecialNetworkinterfaces(),default=current.address.value)
218         
219         cfglist.append(getConfigListEntry(_("Disabled"), current.disabled))
220         cfglist.append(getConfigListEntry(_("Address"), current.address))
221         cfglist.append(getConfigListEntry(_("Port"), current.port))
222         cfglist.append(getConfigListEntry(_("Require Authorization"), current.useauth))
223         cfglist.append(getConfigListEntry(_("SSL Encryption"), current.usessl))
224         ConfigListScreen.__init__(self, cfglist, session)
225         self.ifacenum = i
226
227     def keySave(self):
228         config.plugins.Webinterface.interfacecount.save()
229         for x in self["config"].list:
230             if isinstance(x[1].value, str):
231                 x[1].value = x[1].value.strip()
232             x[1].save()
233         self.close()
234         config.save()
235
236     def cancelConfirm(self, result):
237         if result:
238             config.plugins.Webinterface.interfacecount.cancel()
239         self.callback = None
240         ConfigListScreen.cancelConfirm(self, result)
241
242     def keyDelete(self):
243         self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this Interface?"))
244
245     def deleteConfirm(self, result):
246         if not result:
247             return
248         del(config.plugins.Webinterface.interfaces[self.ifacenum])
249         config.plugins.Webinterface.interfaces.save()
250         config.plugins.Webinterface.interfacecount.value = config.plugins.Webinterface.interfacecount.value - 1;
251         config.plugins.Webinterface.interfacecount.save()
252         config.save()
253         self.close()
254