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